From 6ca3419636f93e7b53a9b190fdbb7bb176c2b6a4 Mon Sep 17 00:00:00 2001 From: Michel Alexandre Salim Date: Mar 30 2022 21:51:48 +0000 Subject: Add --dry-run mode to request-branch Signed-off-by: Michel Alexandre Salim --- diff --git a/fedpkg/cli.py b/fedpkg/cli.py index 58fabbe..f148100 100644 --- a/fedpkg/cli.py +++ b/fedpkg/cli.py @@ -453,6 +453,10 @@ class fedpkgClient(cliClient): 'branch argument has to be placed before --sl.') ) request_branch_parser.add_argument( + '--dry-run', default=False, action='store_true', + help='Don\'t create Pagure issue, just perform eligibility checks' + ) + request_branch_parser.add_argument( '--no-git-branch', default=False, action='store_true', help='Don\'t create the branch in git but still create it in PDC' ) @@ -1043,6 +1047,7 @@ class fedpkgClient(cliClient): active_branch=active_branch, repo_name=self.cmd.repo_name, ns=self.cmd.ns, + dry_run=self.args.dry_run, no_git_branch=self.args.no_git_branch, no_auto_module=self.args.no_auto_module, name=self.name, @@ -1051,7 +1056,7 @@ class fedpkgClient(cliClient): @staticmethod def _request_branch(logger, service_levels, all_releases, branch, - active_branch, repo_name, ns, no_git_branch, + active_branch, repo_name, ns, dry_run, no_git_branch, no_auto_module, name, config): """ Implementation of `request_branch`. @@ -1069,6 +1074,8 @@ class fedpkgClient(cliClient): value of `self.cmd.repo_name`. :param ns: The repository namespace string, i.e. 'rpms' or 'modules'. Typically takes the value of `self.cmd.ns`. + :param dry_run: A boolean flag. If True, no branch is actually created, + but all eligibility checks are performed. :param no_git_branch: A boolean flag. If True, the SCM admins should create the git branch in PDC, but not in pagure.io. :param no_auto_module: A boolean flag. If True, requests for @@ -1163,9 +1170,14 @@ class fedpkgClient(cliClient): ticket_title = 'New Branch "{0}" for "{1}/{2}"'.format( b, ns, repo_name) - print(new_pagure_issue( - logger, pagure_url, pagure_token, ticket_title, ticket_body, - name)) + if dry_run: + print('Would have filed: {0}'.format(ticket_title)) + print(ticket_body) + print() + else: + print(new_pagure_issue( + logger, pagure_url, pagure_token, ticket_title, ticket_body, + name)) # For non-standard rpm branch requests, also request a matching new # module repo with a matching branch. @@ -1179,33 +1191,38 @@ class fedpkgClient(cliClient): if auto_module: summary = ('Automatically requested module for ' 'rpms/%s:%s.' % (repo_name, b)) - fedpkgClient._request_repo( - logger=logger, - repo_name=repo_name, - ns='modules', - branch='rawhide', - summary=summary, - description=summary, - upstreamurl=None, - monitor='no-monitoring', - bug=None, - exception=True, - name=name, - config=config, - ) - fedpkgClient._request_branch( - logger=logger, - service_levels=service_levels, - all_releases=all_releases, - branch=b, - active_branch=active_branch, - repo_name=repo_name, - ns='modules', - no_git_branch=no_git_branch, - no_auto_module=True, # Avoid infinite recursion. - name=name, - config=config, - ) + + if dry_run: + print(summary) + else: + fedpkgClient._request_repo( + logger=logger, + repo_name=repo_name, + ns='modules', + branch='rawhide', + summary=summary, + description=summary, + upstreamurl=None, + monitor='no-monitoring', + bug=None, + exception=True, + name=name, + config=config, + ) + fedpkgClient._request_branch( + logger=logger, + service_levels=service_levels, + all_releases=all_releases, + branch=b, + active_branch=active_branch, + repo_name=repo_name, + ns='modules', + dry_run=dry_run, + no_git_branch=no_git_branch, + no_auto_module=True, # Avoid infinite recursion. + name=name, + config=config, + ) def do_distgit_fork(self): """create fork of the distgit repository