From 7e61dc6b1508131505532411cf4caf63b67f649d Mon Sep 17 00:00:00 2001 From: Ondrej Nosek Date: May 12 2020 22:09:48 +0000 Subject: Make it easier to opt-out from the playground When 'fedpkg request-branch' requests for an 'epel8' (or higher), Fedora SCM will create also 'epel8-playground' branch and place initial commit containing 'package.cfg' into 'epel8'. This allows avoiding the creation of the extra 'epel8-playground' branch and the commit. New argument '--without-playground' was added. JIRA: RHELCMP-589 Resolves: rhbz#1746314 Signed-off-by: Ondrej Nosek --- diff --git a/fedpkg/cli.py b/fedpkg/cli.py index ae83965..4a7c599 100644 --- a/fedpkg/cli.py +++ b/fedpkg/cli.py @@ -412,7 +412,8 @@ class fedpkgClient(cliClient): required=False, dest='repo_ns_for_branch', choices=self.get_distgit_namespaces(), - help='Repository name the new branch is requested for.' + help=("Repository name the new branch is requested for. Requires " + "filling the '--repo' argument") ) request_branch_parser.add_argument( '--sl', nargs='*', @@ -436,6 +437,13 @@ class fedpkgClient(cliClient): '--all-releases', default=False, action='store_true', help='Make a new branch request for every active Fedora release' ) + request_branch_parser.add_argument( + '--without-playground', default=False, action='store_true', + help=("In case of requesting 'epelX' branch (where X is >7), " + "'epelX-playground' branch will not be automatically " + "requested. Branch will be created in pdc; user has to " + "create git branch manually afterwards.") + ) request_branch_parser.set_defaults(command=self.request_branch) def register_do_fork(self): @@ -927,8 +935,10 @@ class fedpkgClient(cliClient): active_branch=active_branch, repo_name=self.cmd.repo_name, ns=self.cmd.ns, - no_git_branch=self.args.no_git_branch, + # 'without_playground' option also disables creating git branch + no_git_branch=self.args.without_playground or self.args.no_git_branch, no_auto_module=self.args.no_auto_module, + without_playground=self.args.without_playground, name=self.name, config=self.config, ) @@ -936,7 +946,7 @@ class fedpkgClient(cliClient): @staticmethod def _request_branch(service_levels, all_releases, branch, active_branch, repo_name, ns, no_git_branch, no_auto_module, - name, config): + without_playground, name, config): """ Implementation of `request_branch`. Submits a request for a new branch of a given dist-git repo. @@ -957,6 +967,8 @@ class fedpkgClient(cliClient): :param no_auto_module: A boolean flag. If True, requests for non-standard branches should not automatically result in additional requests for matching modules. + :param without_playground: A boolean flag. If True, 'epelX-playground' + branch will not be requested together with epelX in SCM. :param name: A string representing which section of the config should be used. Typically the value of `self.name`. :param config: A dict containing the configuration, loaded from file. @@ -987,7 +999,8 @@ class fedpkgClient(cliClient): # Check if the requested branch is an epel branch match = re.match(r'^epel(?P\d+)$', branch) if match: - epel_playground = True + # do not request playground branch when without_playground is active + epel_playground = not without_playground epel_version = int(match.groupdict()["epel_version"]) if is_epel(branch): @@ -1093,6 +1106,7 @@ class fedpkgClient(cliClient): ns='modules', no_git_branch=no_git_branch, no_auto_module=True, # Avoid infinite recursion. + without_playground=without_playground, name=name, config=config, ) diff --git a/test/test_cli.py b/test/test_cli.py index c22eefd..2367802 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -1002,6 +1002,58 @@ class TestRequestBranch(CliTestCase): 'fedora-scm-requests/issue/2'])) self.assertEqual(output, expected_output) + @patch('requests.get') + @patch('requests.post') + @patch('fedpkg.cli.get_release_branches') + @patch('sys.stdout', new=StringIO()) + def test_request_epel_branch_override_without_playground( + self, mock_grb, mock_request_post, mock_request_get + ): + """Tests request-epel-branch-override-without-playground + + epel8 branch operation (with 'without_playground' argument) generates + only one request. It doesn't request for epel8-playground branch. + It won't create git branch either. + """ + mock_grb.return_value = {'fedora': ['f25', 'f26', 'f27'], + 'epel': ['el6', 'epel7', 'epel8']} + mock_rv = Mock() + mock_rv.ok = True + mock_rv.json.return_value = {'issue': {'id': 2}} + mock_request_post.return_value = mock_rv + + mock_rv = Mock() + mock_rv.ok = True + mock_rv.json.return_value = {"arches": [], "packages": {}} + mock_request_get.return_value = mock_rv + # Checkout the epel7 branch + self.run_cmd(['git', 'checkout', 'epel8'], cwd=self.cloned_repo_path) + + cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path, + 'request-branch', '--repo', 'sudoku', 'epel8', + '--without-playground'] + cli = self.get_cli(cli_cmd) + cli.request_branch() + + expected_issue_content = { + 'action': 'new_branch', + 'repo': 'sudoku', + 'namespace': 'rpms', + 'branch': 'epel8', + 'create_git_branch': False + } + self.assertEqual(len(mock_request_post.call_args_list), 1) + + # 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) + @patch('requests.post') @patch('fedpkg.cli.get_release_branches') @patch('sys.stdout', new=StringIO())