From ce0842aefd2f37dbc25d4ea480e7b119de567982 Mon Sep 17 00:00:00 2001 From: Mark Fedorov Date: Mon, 11 Jul 2022 13:27:25 +0000 Subject: [PATCH] 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 --- doc/source/usage.rst | 4 +++ git-review.1 | 2 ++ git_review/cmd.py | 6 ++++ git_review/tests/test_git_review.py | 30 +++++++++++++++++++ .../notes/cc-option-596f62632418f13f.yaml | 5 ++++ 5 files changed, 47 insertions(+) create mode 100644 releasenotes/notes/cc-option-596f62632418f13f.yaml diff --git a/doc/source/usage.rst b/doc/source/usage.rst index 6b76cf86..cba536ac 100644 --- a/doc/source/usage.rst +++ b/doc/source/usage.rst @@ -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 diff --git a/git-review.1 b/git-review.1 index 76b671ef..2217bfa8 100644 --- a/git-review.1 +++ b/git-review.1 @@ -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 diff --git a/git_review/cmd.py b/git_review/cmd.py index 7a74da97..deaa380a 100644 --- a/git_review/cmd.py +++ b/git_review/cmd.py @@ -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" diff --git a/git_review/tests/test_git_review.py b/git_review/tests/test_git_review.py index 12ebabb8..028b0bd7 100644 --- a/git_review/tests/test_git_review.py +++ b/git_review/tests/test_git_review.py @@ -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') diff --git a/releasenotes/notes/cc-option-596f62632418f13f.yaml b/releasenotes/notes/cc-option-596f62632418f13f.yaml new file mode 100644 index 00000000..6e2febb7 --- /dev/null +++ b/releasenotes/notes/cc-option-596f62632418f13f.yaml @@ -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).