#473 Add --dry-run mode to request-branch
Opened 2 years ago by salimma. Modified 2 years ago
salimma/fedpkg dry-run  into  master

Add --dry-run mode to request-branch
Michel Alexandre Salim • 2 years ago  
file modified
+48 -31
@@ -453,6 +453,10 @@ 

                    'branch argument has to be placed before --sl.')

          )

          request_branch_parser.add_argument(

+             '--dry-run', default=False, action='store_true',

Hello,

You don't have to create a new parameter --dry-run for argument request-branch, instead we prefer using the top-level optional argument --dry-run which is inherited from rpkg. This will give you access to self.args.dry_run (since fedpkgClient inherits from cliClient) too.

The only difference will be that instead of calling fedpkg request-branch --dry-run ... you would call it like fedpkg --dry-run request-branch ....

+             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 @@ 

              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 @@ 

  

      @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 @@ 

              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 @@ 

              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 @@ 

              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

This would enable someone filing a bz to request a branch to quickly verify if such a branch request is valid or not

Signed-off-by: Michel Alexandre Salim salimma@fedoraproject.org

Tested by building a patched RPM locally:

fedpkg on  dry-run took 2s
❯ fedpkg request-branch --dry-run --repo luajit epel9
Would have filed: New Branch "epel9" for "rpms/luajit"
 ```
{
 "action": "new_branch",
 "branch": "epel9",
 "namespace": "rpms",
 "repo": "luajit",
 "create_git_branch": true
}
 ```

Hello,

You don't have to create a new parameter --dry-run for argument request-branch, instead we prefer using the top-level optional argument --dry-run which is inherited from rpkg. This will give you access to self.args.dry_run (since fedpkgClient inherits from cliClient) too.

The only difference will be that instead of calling fedpkg request-branch --dry-run ... you would call it like fedpkg --dry-run request-branch ....

Metadata