Repository: VirtusLab/git-machete (python)

Issue:
`checkout_github_prs()` should NOT fail if no PRs for the given criteria are found

Pull request:
Issue #462: `checkout_github_prs()` returns empty list when no PRs for the given criteria are found
closes #462 

Patch:
diff --git a/git_machete/client.py b/git_machete/client.py
index b8a55b1..0e44ae6 100644
--- a/git_machete/client.py
+++ b/git_machete/client.py
@@ -1947,28 +1947,27 @@ class MacheteClient:
                     if pr_from_github:
                         result.append(pr_from_github)
                     else:
-                        if len(prs_list) > 1:
-                            warn(f"PR #{pr_no} is not found in repository `{org}/{repo}`, skipping.")
-                        else:
-                            raise MacheteException(f"PR #{pr_no} is not found in repository `{org}/{repo}`")
+                        raise MacheteException(f"PR #{pr_no} is not found in repository `{org}/{repo}`")
             if not result:
                 raise MacheteException(
                     f"Given PRs: {', '.join(map(str, prs_list))} are not found in repository `{org}/{repo}`")
             return result
         if all:
             if not all_opened_prs_from_github:
-                raise MacheteException(f"Currently there is not any pull request opened in repository `{org}/{repo}`")
+                warn(f"Currently there are no pull requests opened in repository `{org}/{repo}`")
+                return []
             return all_opened_prs_from_github
         elif my and user:
             result = [pr for pr in all_opened_prs_from_github if pr.user == user]
             if not result:
-                raise MacheteException(
-                    f"Current user {user} has no open pull request in repository `{org}/{repo}`")
+                warn(f"Current user `{user}` has no open pull request in repository `{org}/{repo}`")
+                return []
             return result
         elif by:
             result = [pr for pr in all_opened_prs_from_github if pr.user == by]
             if not result:
-                raise MacheteException(f"User {by} has no open pull request in repository `{org}/{repo}`")
+                warn(f"User `{by}` has no open pull request in repository `{org}/{repo}`")
+                return []
             return result
         return []
 


Test patch:
diff --git a/git_machete/tests/functional/test_machete.py b/git_machete/tests/functional/test_machete.py
index fc4d788..7718ce8 100644
--- a/git_machete/tests/functional/test_machete.py
+++ b/git_machete/tests/functional/test_machete.py
@@ -2220,6 +2220,7 @@ class MacheteTester(unittest.TestCase):
     @mock.patch('git_machete.github.GITHUB_REMOTE_PATTERNS', FAKE_GITHUB_REMOTE_PATTERNS)
     @mock.patch('git_machete.options.CommandLineOptions', FakeCommandLineOptions)
     @mock.patch('git_machete.utils.run_cmd', mock_run_cmd)  # to hide git outputs in tests
+    @mock.patch('git_machete.github.__get_github_token', mock__get_github_token)
     @mock.patch('urllib.request.Request', git_api_state_for_test_checkout_prs.new_request())
     @mock.patch('urllib.request.urlopen', MockContextManager)
     def test_github_checkout_prs(self) -> None:
@@ -2416,6 +2417,16 @@ class MacheteTester(unittest.TestCase):
             self.assertEqual(e.exception.parameter, expected_error_message,
                              'Verify that expected error message has appeared when given pull request to checkout does not exists.')
 
+        with self.assertRaises(MacheteException) as e:
+            self.launch_command('github', 'checkout-prs', '19', '100')
+        if e:
+            self.assertEqual(e.exception.parameter, expected_error_message,
+                             'Verify that expected error message has appeared when one of the given pull requests to checkout does not exists.')
+
+        # check against user with no open pull requests
+        expected_msg = f"Warn: User `tester` has no open pull request in repository `{org}/{repo}`\n"
+        self.assert_command(['github', 'checkout-prs', '--by', 'tester'], expected_msg, strip_indentation=False)
+
         # Check against closed pull request with head branch deleted from remote
         local_path = popen("mktemp -d")
         self.repo_sandbox.new_repo(GitRepositorySandbox.second_remote_path)