Add CC similarly to reviewers

This adds a --cc option to support the Cc feature in Gerrit 3.4 and
newer, similar in design to the --reviewers option.

Change-Id: I5c01c71d9adff631cff50d113b7255038ccc185d
This commit is contained in:
Mark Fedorov
2022-07-11 13:27:25 +00:00
committed by Jeremy Stanley
parent a3f1e11b85
commit ce0842aefd
5 changed files with 47 additions and 0 deletions

View File

@@ -22,6 +22,10 @@ If you want to subscribe some reviewers::
git review --reviewers a@example.com b@example.com
If you want to subscribe some CCs::
git review --cc a@example.com b@example.com
If you want to submit a branch for review and then remove the local branch::
git review -f

View File

@@ -171,6 +171,8 @@ Send patch which already in private state to normal patch. Gerrit versions >= 2.
Send patch as work in progress for Gerrit versions >= 2.15
.It Fl W , Fl \-ready
Send patch that is already work in progress as ready for review. Gerrit versions >= 2.15
.It Fl \-cc Ar reviewer ...
Carbon copy one or more reviewers to the uploaded patchsets. Reviewers should be identifiable by Gerrit (usually use their Gerrit username or email address).
.It Fl \-reviewers Ar reviewer ...
Subscribe one or more reviewers to the uploaded patchsets. Reviewers should be identifiable by Gerrit (usually use their Gerrit username or email address).
.It Fl \-notify Ar type

View File

@@ -1575,6 +1575,8 @@ additional information:
help="Hashtags to submit branch to")
parser.add_argument("--reviewers", nargs="+",
help="Add reviewers to uploaded patchsets.")
parser.add_argument("--cc", nargs="+",
help="Add CC to uploaded patchsets.")
parser.add_argument("-n", "--dry-run", dest="dry", action="store_true",
help="Don't actually submit the branch for review")
parser.add_argument("-i", "--new-changeid", dest="regenerate",
@@ -1873,6 +1875,10 @@ additional information:
assert_valid_reviewers(options.reviewers)
push_options += ["r=%s" % r for r in options.reviewers]
if options.cc:
assert_valid_reviewers(options.cc)
push_options += ["cc=%s" % cc for cc in options.cc]
if options.regenerate:
print("Amending the commit to regenerate the change id\n")
regenerate_cmd = "git commit --amend"

View File

@@ -315,6 +315,36 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase):
self.assertEqual(set(['reviewer1', 'reviewer2']), reviewers)
def test_git_review_cc(self):
"""Test git-review adding CC to changes."""
self._run_git_review('-s')
# Create users to add as CC
self._run_gerrit_cli('create-account', '--email',
'cc1@example.com', 'cc1')
self._run_gerrit_cli('create-account', '--email',
'cc2@example.com', 'cc2')
self._simple_change('test file', 'test commit message')
review_ccs = self._run_git_review('--cc', 'cc1', 'cc2')
self.assertIn("new: 1", review_ccs)
# verify both CCs are on patchset
head = self._run_git('rev-parse', 'HEAD')
change = self._run_gerrit_cli('query', '--format=JSON',
'--all-reviewers', head)
# The first result should be the one we want
change = json.loads(change.split('\n')[0])
self.assertEqual(2, len(change['allReviewers']))
ccs = set()
for cc in change['allReviewers']:
ccs.add(cc['username'])
self.assertEqual(set(['cc1', 'cc2']), ccs)
def test_rebase_unstaged_changes_msg(self):
"""Test message displayed when unstaged changes are present."""
self._run_git_review('-s')

View File

@@ -0,0 +1,5 @@
---
features:
- |
Added the ``--cc`` option, which can be used to carbon copy specific
Gerrit users on upload (via Gerrit's "Cc" feature).