Repository: VirtusLab/git-machete
Pull request #1169 (2024-02-08 11:18:43)

Print out `Checking for open GitHub PRs` message when determining PR chain for PR description


Patch:
diff --git a/git_machete/client.py b/git_machete/client.py
index 631d811..02935a2 100644
--- a/git_machete/client.py
+++ b/git_machete/client.py
@@ -2048,7 +2048,6 @@ class MacheteClient:
         domain = self.__derive_github_domain()
         org_repo_remote = self.__derive_org_repo_and_remote(domain=domain)
         github_client = GitHubClient(domain=domain, organization=org_repo_remote.organization, repository=org_repo_remote.repository)
-        print('Checking for open GitHub PRs... ', end='', flush=True)
 
         current_user: Optional[str] = github_client.get_current_user_login()
         if not current_user and mine:
@@ -2059,6 +2058,7 @@ class MacheteClient:
             else:
                 warn(msg)
                 return
+        print('Checking for open GitHub PRs... ', end='', flush=True)
         all_open_prs: List[GitHubPullRequest] = github_client.get_open_pull_requests()
         print(fmt('<green><b>OK</b></green>'))
 
@@ -2452,7 +2452,9 @@ class MacheteClient:
         # We could just fetch them straight away... but this list can be quite long for commercial monorepos,
         # esp. given that GitHub limits the single page to 100 PRs (so multiple HTTP requests would be needed).
         # As a slight optimization, let's fetch the full PR list only if the current PR has a base PR at all.
+        print('Checking for open GitHub PRs (to determine PR chain)... ', end='', flush=True)
         all_open_prs: List[GitHubPullRequest] = github_client.get_open_pull_requests()
+        print(fmt('<green><b>OK</b></green>'))
         pr_path = self.__get_path_from_pr_chain(pr, all_open_prs)
 
         prepend = f'{self.START_GIT_MACHETE_GENERATED_COMMENT}\n\n'
@@ -2539,8 +2541,8 @@ class MacheteClient:
                                                                   description=description, draft=opt_draft)
         print(fmt(f'{ok_str}, see `{pr.html_url}`'))
 
-        # If base branch has not originally been found on the remote,
-        # we can be sure that a longer chain of PRs above the newly-created PR doesn't exist
+        # If base branch has NOT originally been found on the remote,
+        # we can be sure that a longer chain of PRs above the newly-created PR does NOT exist
         if base_branch_found_on_remote:
             # As the description may include the reference to this PR itself (in case of a chain of >=2 PRs),
             # let's update the PR description after it's already created (so that we know the current PR's number).


Test patch:
diff --git a/tests/test_clean.py b/tests/test_clean.py
index d7d2703..d143171 100644
--- a/tests/test_clean.py
+++ b/tests/test_clean.py
@@ -75,7 +75,7 @@ class TestClean(BaseTest):
         assert_success(
             ["clean", "--checkout-my-github-prs"],
             """
-            Checking for open GitHub PRs... Warn: Could not determine current user name, please check that the GitHub API token provided by one of the:
+            Warn: Could not determine current user name, please check that the GitHub API token provided by one of the:
             \t1. GITHUB_TOKEN environment variable
             \t2. Content of the ~/.github-token file
             \t3. Current auth token from the gh GitHub CLI
diff --git a/tests/test_github_create_pr.py b/tests/test_github_create_pr.py
index 56326a6..e3158d4 100644
--- a/tests/test_github_create_pr.py
+++ b/tests/test_github_create_pr.py
@@ -144,6 +144,7 @@ class TestGitHubCreatePR(BaseTest):
 
             Fetching origin...
             Creating a draft PR from chore/fields to ignore-trailing... OK, see www.github.com
+            Checking for open GitHub PRs (to determine PR chain)... OK
             Updating description of PR #5 to include the chain of PRs... OK
             Setting milestone of PR #5 to #42... OK
             Adding github_user as assignee to PR #5... OK
@@ -564,6 +565,7 @@ class TestGitHubCreatePR(BaseTest):
 
         Fetching origin_1...
         Creating a PR from feature to branch-1... OK, see www.github.com
+        Checking for open GitHub PRs (to determine PR chain)... OK
         Updating description of PR #16 to include the chain of PRs... OK
         """  # noqa: E501
 
@@ -613,6 +615,7 @@ class TestGitHubCreatePR(BaseTest):
         Added branch feature_1 onto feature
         Fetching origin_2...
         Creating a PR from feature_1 to feature... OK, see www.github.com
+        Checking for open GitHub PRs (to determine PR chain)... OK
         Updating description of PR #17 to include the chain of PRs... OK
         """
         assert_success(
@@ -650,6 +653,7 @@ class TestGitHubCreatePR(BaseTest):
 
         Fetching origin_1...
         Creating a PR from feature_2 to feature... OK, see www.github.com
+        Checking for open GitHub PRs (to determine PR chain)... OK
         Updating description of PR #18 to include the chain of PRs... OK
         """
         assert_success(
@@ -671,6 +675,7 @@ class TestGitHubCreatePR(BaseTest):
         Added branch feature_3 onto feature_2
         Fetching origin_1...
         Creating a PR from feature_3 to feature_2... OK, see www.github.com
+        Checking for open GitHub PRs (to determine PR chain)... OK
         Updating description of PR #19 to include the chain of PRs... OK
         """  # noqa: E501
         assert_success(
diff --git a/tests/test_github_retarget_pr.py b/tests/test_github_retarget_pr.py
index 4c20057..e909d68 100644
--- a/tests/test_github_retarget_pr.py
+++ b/tests/test_github_retarget_pr.py
@@ -257,6 +257,7 @@ class TestGitHubRetargetPR(BaseTest):
         assert_success(
             ['github', 'retarget-pr'],
             'Base branch of PR #20 has been switched to feature\n'
+            'Checking for open GitHub PRs (to determine PR chain)... OK\n'
             'Description of PR #20 has been updated\n'
         )
         pr20 = github_api_state.get_pull_by_number(20)
@@ -306,6 +307,7 @@ class TestGitHubRetargetPR(BaseTest):
         assert_success(
             ['github', 'retarget-pr'],
             'Base branch of PR #25 has been switched to feature\n'
+            'Checking for open GitHub PRs (to determine PR chain)... OK\n'
             'Description of PR #25 has been updated\n'
         )
         pr25 = github_api_state.get_pull_by_number(25)
@@ -346,6 +348,7 @@ class TestGitHubRetargetPR(BaseTest):
         assert_success(
             ['github', 'retarget-pr'],
             'Base branch of PR #30 has been switched to feature_2\n'
+            'Checking for open GitHub PRs (to determine PR chain)... OK\n'
             'Description of PR #30 has been updated\n'
         )
         pr30 = github_api_state.get_pull_by_number(30)
@@ -380,6 +383,7 @@ class TestGitHubRetargetPR(BaseTest):
         assert_success(
             ['github', 'retarget-pr'],
             'Base branch of PR #30 has been switched to feature\n'
+            'Checking for open GitHub PRs (to determine PR chain)... OK\n'
             'Description of PR #30 has been updated\n'
         )
         pr30 = github_api_state.get_pull_by_number(30)