From c4a348b7e4c59c3aa964d03e731e79eb6839b5d4 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Jul 05 2018 04:00:34 +0000 Subject: Add explicit option --repo for request-branch This patch fixes a similar problem introduced to request-repo. A command option is added for convenience. The global --name still works. So, when packagers read request-branch help text with `fedpkg request-branch -h`, they can easily know how to specify repository name directly without additional step to look up global option --name. Fixes #244 Signed-off-by: Chenxiong Qi --- diff --git a/fedpkg/cli.py b/fedpkg/cli.py index 58a1c44..6cd7c60 100644 --- a/fedpkg/cli.py +++ b/fedpkg/cli.py @@ -199,11 +199,11 @@ Request a branch inside a cloned package repository: fedpkg request-branch f27 -Request a branch without waiting for the requested repository to be approved -and created: - - fedpkg --name foo request-branch f27 +Request a branch outside package repository, which could apply to cases of +requested repository has not been approved and created, or just not change +directory to package repository: + fedpkg request-branch --repo foo f27 ''' request_branch_parser = self.subparsers.add_parser( 'request-branch', @@ -213,6 +213,13 @@ and created: request_branch_parser.add_argument( 'branch', nargs='?', help='The branch to request') request_branch_parser.add_argument( + '--repo', + required=False, + dest='repo_name_for_branch', + metavar='NAME', + help='Repository name the new branch is requested for.' + ) + request_branch_parser.add_argument( '--sl', nargs='*', help=('The service levels (SLs) tied to the branch. This must be ' 'in the format of "sl_name:2020-12-01". This is only for ' @@ -599,7 +606,7 @@ suggest_reboot=False all_releases=self.args.all_releases, branch=self.args.branch, active_branch=active_branch, - repo_name=self.cmd.repo_name, + repo_name=self.args.repo_name_for_branch or self.cmd.repo_name, ns=self.cmd.ns, no_git_branch=self.args.no_git_branch, no_auto_module=self.args.no_auto_module, diff --git a/test/test_cli.py b/test/test_cli.py index 3003eb0..d70ceb2 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -1044,6 +1044,39 @@ https://pagure.stg.example.com/releng/fedora-scm-requests/issue/3""" with six.assertRaisesRegex(self, rpkgError, expected_error): cli.request_branch() + @patch('requests.post') + @patch('fedpkg.cli.get_release_branches') + @patch('sys.stdout', new=StringIO()) + def test_request_with_repo_option(self, mock_grb, mock_request_post): + """Test request branch with option --repo""" + mock_grb.return_value = set(['el6', 'epel7', 'f25', 'f26', 'f27']) + mock_rv = Mock() + mock_rv.ok = True + mock_rv.json.return_value = {'issue': {'id': 2}} + mock_request_post.return_value = mock_rv + + cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path, + 'request-branch', '--repo', 'foo', 'f27'] + cli = self.get_cli(cli_cmd) + cli.request_branch() + + expected_issue_content = { + 'action': 'new_branch', + 'repo': 'foo', + 'namespace': 'rpms', + 'branch': 'f27', + 'create_git_branch': True + } + # Get the data that was submitted to Pagure + post_data = mock_request_post.call_args_list[0][1]['data'] + actual_issue_content = json.loads(json.loads( + post_data)['issue_content'].strip('```')) + self.assertEqual(expected_issue_content, actual_issue_content) + output = sys.stdout.getvalue().strip() + expected_output = ('https://pagure.stg.example.com/releng/' + 'fedora-scm-requests/issue/2') + self.assertEqual(output, expected_output) + class TestRequestTestsRepo(CliTestCase): """Test the request-tests-repo command"""