Forráskód Böngészése

gerrit: addmessage: support attention set control

Sometimes I want to add a message without touching the attention set.
The default review call will automatically update it regardless.  Add
a flag to explicitly control behavior.

Test:
	# No attention set option.
	$ ./gerrit_client.py ...
	-> ignore_automatic_attention_set_rules not included in body of request
	$ ./gerrit_client.py ... --automatic-attention
	-> body has {'ignore_automatic_attention_set_rules': False}
	$ ./gerrit_client.py ... --no-automatic-attention
	-> body has {'ignore_automatic_attention_set_rules': True}

Change-Id: Idcf7975ba691942cfe385a2156ef3a3ec064a0b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6172486
Commit-Queue: Yiwei Zhang <yiwzhang@google.com>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Auto-Submit: Mike Frysinger <vapier@chromium.org>
Mike Frysinger 7 hónapja
szülő
commit
232ffd8df3
3 módosított fájl, 25 hozzáadás és 7 törlés
  1. 14 4
      gerrit_client.py
  2. 9 2
      gerrit_util.py
  3. 2 1
      tests/gerrit_client_test.py

+ 14 - 4
gerrit_client.py

@@ -421,15 +421,25 @@ def CMDaddMessage(parser, args):
         'https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#revision-id '  # pylint: disable=line-too-long
         'for acceptable format')
     parser.add_option('-m', '--message', type=str, help='message to add')
+    # This default matches the Gerrit REST API & web UI defaults.
+    parser.add_option('--automatic-attention-set-update',
+                      action='store_true',
+                      help='Update the attention set (default)')
+    parser.add_option('--no-automatic-attention-set-update',
+                      dest='automatic_attention_set_update',
+                      action='store_false',
+                      help='Do not update the attention set')
     (opt, args) = parser.parse_args(args)
     if not opt.change:
         parser.error('--change is required')
     if not opt.message:
         parser.error('--message is required')
-    result = gerrit_util.SetReview(urllib.parse.urlparse(opt.host).netloc,
-                                   opt.change,
-                                   revision=opt.revision,
-                                   msg=opt.message)
+    result = gerrit_util.SetReview(
+        urllib.parse.urlparse(opt.host).netloc,
+        opt.change,
+        revision=opt.revision,
+        msg=opt.message,
+        automatic_attention_set_update=opt.automatic_attention_set_update)
     logging.info(result)
     write_result(result, opt)
 

+ 9 - 2
gerrit_util.py

@@ -1706,8 +1706,12 @@ def SetReview(host,
               msg=None,
               labels=None,
               notify=None,
-              ready=None):
-    """Sets labels and/or adds a message to a code review."""
+              ready=None,
+              automatic_attention_set_update: Optional[bool] = None):
+    """Sets labels and/or adds a message to a code review.
+
+    https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#set-review
+    """
     if not msg and not labels:
         return
     path = f'changes/{change}/revisions/{revision}/review'
@@ -1720,6 +1724,9 @@ def SetReview(host,
         body['notify'] = 'ALL' if notify else 'NONE'
     if ready:
         body['ready'] = True
+    if automatic_attention_set_update is not None:
+        body[
+            'ignore_automatic_attention_set_rules'] = not automatic_attention_set_update
     conn = CreateHttpConn(host, path, reqtype='POST', body=body)
     response = ReadHttpJsonResponse(conn)
     if labels:

+ 2 - 1
tests/gerrit_client_test.py

@@ -174,7 +174,8 @@ class TestGerritClient(unittest.TestCase):
         util_mock.assert_called_once_with('example.org',
                                           1,
                                           revision='2',
-                                          msg='This is a message')
+                                          msg='This is a message',
+                                          automatic_attention_set_update=None)
 
 if __name__ == '__main__':
     logging.basicConfig(