#245 Add explicit option --repo for request-branch
Merged 6 years ago by cqi. Opened 6 years ago by cqi.

file modified
+12 -5
@@ -199,11 +199,11 @@ 

  

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

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

              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,

file modified
+33
@@ -1044,6 +1044,39 @@ 

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

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 cqi@redhat.com

Pull-Request has been merged by cqi

6 years ago