Browse Source

Merge "Add reviewers on upload"

tags/1.0.0
Jenkins 4 years ago
parent
commit
d1266ee0a5
4 changed files with 62 additions and 0 deletions
  1. 4
    0
      doc/source/usage.rst
  2. 5
    0
      git-review.1
  3. 21
    0
      git_review/cmd.py
  4. 32
    0
      git_review/tests/test_git_review.py

+ 4
- 0
doc/source/usage.rst View File

@@ -18,6 +18,10 @@ If you want to supply a review topic::
18 18
 
19 19
     git review -t topic/awesome-feature
20 20
 
21
+If you want to subscribe some reviewers::
22
+
23
+    git review --reviewers a@example.com b@example.com
24
+
21 25
 If you want to disable autogenerated topic::
22 26
 
23 27
     git review -T

+ 5
- 0
git-review.1 View File

@@ -41,6 +41,7 @@
41 41
 .Op Fl fnuvDRT
42 42
 .Op Fl r Ar remote
43 43
 .Op Fl t Ar topic
44
+.Op Fl \-reviewers Ar reviewer ...
44 45
 .Op Ar branch
45 46
 .Nm
46 47
 .Fl \-version
@@ -140,6 +141,8 @@ Sets the target topic for this change on the gerrit server.
140 141
 If not specified, a bug number from the commit summary will be used. Alternatively, the local branch name will be used if different from remote branch.
141 142
 .It Fl T , Fl \-no\-topic
142 143
 Submit review without topic.
144
+.It Fl \-reviewers Ar reviewer ...
145
+Subscribe one or more reviewers to the uploaded patch sets.  Reviewers should be identifiable by Gerrit (usually use their Gerrit username or email address).
143 146
 .It Fl u , Fl \-update
144 147
 Skip cached local copies and force updates from network resources.
145 148
 .It Fl l , Fl \-list
@@ -337,6 +340,8 @@ specific error codes are available:
337 340
 Gerrit
338 341
 .Ar commit\-msg
339 342
 hook could not be successfully installed.
343
+.It 3
344
+Could not parse malformed argument value or user input.
340 345
 .It 32
341 346
 Cannot fetch list of open changesets from Gerrit.
342 347
 .It 33

+ 21
- 0
git_review/cmd.py View File

@@ -1237,6 +1237,20 @@ def convert_bool(one_or_zero):
1237 1237
     return str(one_or_zero) in ["1", "true", "True"]
1238 1238
 
1239 1239
 
1240
+class MalformedInput(GitReviewException):
1241
+    EXIT_CODE = 3
1242
+
1243
+
1244
+def assert_valid_reviewers(reviewers):
1245
+    """Ensure no whitespace is found in reviewer names, as it will result
1246
+    in an invalid refspec.
1247
+    """
1248
+    for reviewer in reviewers:
1249
+        if re.search(r'\s', reviewer):
1250
+            raise MalformedInput(
1251
+                "Whitespace not allowed in reviewer: '%s'" % reviewer)
1252
+
1253
+
1240 1254
 def _main():
1241 1255
     usage = "git review [OPTIONS] ... [BRANCH]"
1242 1256
 
@@ -1257,6 +1271,8 @@ def _main():
1257 1271
                                  action="store_true",
1258 1272
                                  help="No topic except if explicitly provided")
1259 1273
 
1274
+    parser.add_argument("--reviewers", nargs="+",
1275
+                        help="Add reviewers to uploaded patch sets.")
1260 1276
     parser.add_argument("-D", "--draft", dest="draft", action="store_true",
1261 1277
                         help="Submit review as a draft")
1262 1278
     parser.add_argument("-c", "--compatible", dest="compatible",
@@ -1468,6 +1484,11 @@ def _main():
1468 1484
         topic = None if options.notopic else get_topic(branch)
1469 1485
     if topic and topic != branch:
1470 1486
         cmd += "/%s" % topic
1487
+
1488
+    if options.reviewers:
1489
+        assert_valid_reviewers(options.reviewers)
1490
+        cmd += "%" + ",".join("r=%s" % r for r in options.reviewers)
1491
+
1471 1492
     if options.regenerate:
1472 1493
         print("Amending the commit to regenerate the change id\n")
1473 1494
         regenerate_cmd = "git commit --amend"

+ 32
- 0
git_review/tests/test_git_review.py View File

@@ -15,6 +15,7 @@
15 15
 # See the License for the specific language governing permissions and
16 16
 # limitations under the License.
17 17
 
18
+import json
18 19
 import os
19 20
 import shutil
20 21
 
@@ -128,6 +129,37 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase):
128 129
         review_res = self._run_git_review('-y')
129 130
         self.assertIn("Processing changes: new: 2", review_res)
130 131
 
132
+    def test_git_review_re(self):
133
+        """Test git-review adding reviewers to changes."""
134
+        self._run_git_review('-s')
135
+
136
+        # Create users to add as reviewers
137
+        self._run_gerrit_cli('create-account', '--email',
138
+                             'reviewer1@example.com', 'reviewer1')
139
+        self._run_gerrit_cli('create-account', '--email',
140
+                             'reviewer2@example.com', 'reviewer2')
141
+
142
+        self._simple_change('test file', 'test commit message')
143
+
144
+        review_res = self._run_git_review('--reviewers', 'reviewer1',
145
+                                          'reviewer2')
146
+        self.assertIn("Processing changes: new: 1", review_res)
147
+
148
+        # verify both reviewers are on patch set
149
+        head = self._run_git('rev-parse', 'HEAD')
150
+        change = self._run_gerrit_cli('query', '--format=JSON',
151
+                                      '--all-reviewers', head)
152
+        # The first result should be the one we want
153
+        change = json.loads(change.split('\n')[0])
154
+
155
+        self.assertEqual(2, len(change['allReviewers']))
156
+
157
+        reviewers = set()
158
+        for reviewer in change['allReviewers']:
159
+            reviewers.add(reviewer['username'])
160
+
161
+        self.assertEqual(set(['reviewer1', 'reviewer2']), reviewers)
162
+
131 163
     def test_rebase_no_remote_branch_msg(self):
132 164
         """Test message displayed where no remote branch exists."""
133 165
         self._run_git_review('-s')

Loading…
Cancel
Save