From 29080de8a328344c33b5f1199c72c9734c485a3e Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Jul 15 2018 01:53:23 +0000 Subject: Add option --namespace to command request-branch This patch adds option --namespace to command request-branch, which could be used with --repo together. Previously, packagers could request a branch with global option --module-name in either form name or namespace/name. --module-name has been replaced with options --name and --namespace which should also be usable for request-branch as well. As a result, packagers could request a branch with either global options: fedpkg --name name [--namespace namespace] request-branch branch or command level options fedpkg request-branch --repo name [--namespace namespace] branch The first form is for backwards compatibility in a way and the second form is the recommended way to use in practice which would be more straightforward. Signed-off-by: Chenxiong Qi --- diff --git a/fedpkg/cli.py b/fedpkg/cli.py index dd76a7c..13d64b9 100644 --- a/fedpkg/cli.py +++ b/fedpkg/cli.py @@ -99,6 +99,14 @@ class fedpkgClient(cliClient): ) update_parser.set_defaults(command=self.update) + def get_distgit_namespaces(self): + dg_namespaced = self._get_bool_opt('distgit_namespaced') + if dg_namespaced and self.config.has_option( + self.name, 'distgit_namespaces'): + return self.config.get(self.name, 'distgit_namespaces').split() + else: + return None + def register_request_repo(self): help_msg = 'Request a new dist-git repository' description = '''Request a new dist-git repository @@ -122,14 +130,6 @@ Request a module with namespace explicitly: '''.format(self.name, urlparse(self.config.get( '{0}.pagure'.format(self.name), 'url')).netloc) - dg_namespaced = self._get_bool_opt('distgit_namespaced') - if dg_namespaced and self.config.has_option( - self.name, 'distgit_namespaces'): - ns_choices = self.config.get( - self.name, 'distgit_namespaces').split() - else: - ns_choices = None - request_repo_parser = self.subparsers.add_parser( 'request-repo', formatter_class=argparse.RawDescriptionHelpFormatter, @@ -146,7 +146,7 @@ Request a module with namespace explicitly: '--namespace', required=False, default='rpms', - choices=ns_choices, + choices=self.get_distgit_namespaces(), dest='new_repo_namespace', help='Namespace of repository. If omitted, default to rpms.') request_repo_parser.add_argument( @@ -241,6 +241,13 @@ directory to package repository: help='Repository name the new branch is requested for.' ) request_branch_parser.add_argument( + '--namespace', + required=False, + dest='repo_ns_for_branch', + choices=self.get_distgit_namespaces(), + 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 ' @@ -618,6 +625,10 @@ suggest_reboot=False pagure_url, pagure_token, ticket_title, ticket_body)) def request_branch(self): + if self.args.repo_name_for_branch: + self.cmd.repo_name = self.args.repo_name_for_branch + self.cmd.ns = self.args.repo_ns_for_branch or 'rpms' + try: active_branch = self.cmd.repo.active_branch.name except rpkgError: @@ -627,7 +638,7 @@ suggest_reboot=False all_releases=self.args.all_releases, branch=self.args.branch, active_branch=active_branch, - repo_name=self.args.repo_name_for_branch or self.cmd.repo_name, + repo_name=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 1ecefe2..feb5c76 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -701,7 +701,7 @@ class TestRequestBranch(CliTestCase): mock_request_post.return_value = mock_rv cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path, - '--name', 'nethack', 'request-branch', 'f27'] + 'request-branch', '--repo', 'nethack', 'f27'] cli = self.get_cli(cli_cmd) cli.request_branch() @@ -734,8 +734,8 @@ class TestRequestBranch(CliTestCase): mock_request_post.return_value = mock_rv cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path, - '--name', 'nethack', '--namespace', 'modules', - 'request-branch', 'f27'] + 'request-branch', + '--repo', 'nethack', '--namespace', 'modules', 'f27'] cli = self.get_cli(cli_cmd) cli.request_branch() @@ -758,8 +758,7 @@ class TestRequestBranch(CliTestCase): @patch('requests.post') @patch('fedpkg.cli.get_release_branches') - @patch('sys.stdout', new=StringIO()) - def test_request_branch_container(self, mock_grb, mock_request_post): + def assert_request_branch_container(self, cli_cmd, mock_grb, mock_request_post): """Tests request-branch for a new container branch""" mock_grb.return_value = set(['el6', 'epel7', 'f25', 'f26', 'f27']) mock_rv = Mock() @@ -767,9 +766,6 @@ class TestRequestBranch(CliTestCase): mock_rv.json.return_value = {'issue': {'id': 2}} mock_request_post.return_value = mock_rv - cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path, - '--name', 'nethack', '--namespace', 'container', - 'request-branch', 'f27'] cli = self.get_cli(cli_cmd) cli.request_branch() @@ -790,6 +786,20 @@ class TestRequestBranch(CliTestCase): 'fedora-scm-requests/issue/2') self.assertEqual(output, expected_output) + @patch('sys.stdout', new=StringIO()) + def test_request_branch_with_global_option_name_and_namespace(self): + cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path, + '--name', 'nethack', '--namespace', 'container', + 'request-branch', 'f27'] + self.assert_request_branch_container(cli_cmd) + + @patch('sys.stdout', new=StringIO()) + def test_request_branch_with_its_own_option_repo_and_namespace(self): + cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path, + 'request-branch', + '--repo', 'nethack', '--namespace', 'container', 'f27'] + self.assert_request_branch_container(cli_cmd) + @patch('requests.post') @patch('fedpkg.cli.get_release_branches') @patch('fedpkg.cli.verify_sls')