فهرست منبع

recipes: gerrit: expose new attention set control

Allow recipes to post messages without changing attention set.

Change-Id: I36cab074850e2bbc6f7d12ec080fccd1fd947505
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6172487
Auto-Submit: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Yiwei Zhang <yiwzhang@google.com>
Mike Frysinger 7 ماه پیش
والد
کامیت
c9552ffad5

+ 4 - 3
recipes/README.recipes.md

@@ -285,7 +285,7 @@ Wrapper for easy calling of gerrit_utils steps.
 
 &mdash; **def [abandon\_change](/recipes/recipe_modules/gerrit/api.py#262)(self, host, change, message=None, name=None, step_test_data=None):**
 
-&mdash; **def [add\_message](/recipes/recipe_modules/gerrit/api.py#320)(self, host: str, change: int, message: str, revision: (str | int)='current', step_name: str=None, step_test_data: (Callable[([], StepTestData)] | None)=None):**
+&mdash; **def [add\_message](/recipes/recipe_modules/gerrit/api.py#320)(self, host: str, change: int, message: str, revision: (str | int)='current', automatic_attention_set_update: Optional[bool]=None, step_name: str=None, step_test_data: (Callable[([], StepTestData)] | None)=None):**
 
 Add a message to a change at given revision.
 
@@ -298,6 +298,7 @@ Args:
       documented here:
       https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#revision-id
       This defaults to current, which names the most recent patchset.
+  * automatic_attention_set_update: Whether to update the attention set.
   * step_name: Optional step name.
   * step_test_data: Optional mock test data for the underlying gerrit
       client.
@@ -393,13 +394,13 @@ Returns:
   A dict for the target revision as documented here:
       https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes
 
-&mdash; **def [move\_changes](/recipes/recipe_modules/gerrit/api.py#357)(self, host, project, from_branch, to_branch, step_test_data=None):**
+&mdash; **def [move\_changes](/recipes/recipe_modules/gerrit/api.py#364)(self, host, project, from_branch, to_branch, step_test_data=None):**
 
 &mdash; **def [restore\_change](/recipes/recipe_modules/gerrit/api.py#282)(self, host, change, message=None, name=None, step_test_data=None):**
 
 &mdash; **def [set\_change\_label](/recipes/recipe_modules/gerrit/api.py#302)(self, host, change, label_name, label_value, name=None, step_test_data=None):**
 
-&mdash; **def [update\_files](/recipes/recipe_modules/gerrit/api.py#381)(self, host, project, branch, new_contents_by_file_path, commit_msg, params=frozenset(['status=NEW']), cc_list=frozenset([]), submit=False, submit_later=False, step_test_data_create_change=None, step_test_data_submit_change=None):**
+&mdash; **def [update\_files](/recipes/recipe_modules/gerrit/api.py#388)(self, host, project, branch, new_contents_by_file_path, commit_msg, params=frozenset(['status=NEW']), cc_list=frozenset([]), submit=False, submit_later=False, step_test_data_create_change=None, step_test_data_submit_change=None):**
 
 Update a set of files by creating and submitting a Gerrit CL.
 

+ 8 - 1
recipes/recipe_modules/gerrit/api.py

@@ -4,7 +4,7 @@
 
 from recipe_engine import recipe_api
 from recipe_engine.recipe_test_api import StepTestData
-from typing import Callable
+from typing import Callable, Optional
 
 class GerritApi(recipe_api.RecipeApi):
   """Module for interact with Gerrit endpoints"""
@@ -323,6 +323,7 @@ class GerritApi(recipe_api.RecipeApi):
       change: int,
       message: str,
       revision: str | int = 'current',
+      automatic_attention_set_update: Optional[bool] = None,
       step_name: str = None,
       step_test_data: Callable[[], StepTestData] | None = None) -> None:
     """Add a message to a change at given revision.
@@ -336,6 +337,7 @@ class GerritApi(recipe_api.RecipeApi):
           documented here:
           https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#revision-id
           This defaults to current, which names the most recent patchset.
+      * automatic_attention_set_update: Whether to update the attention set.
       * step_name: Optional step name.
       * step_test_data: Optional mock test data for the underlying gerrit
           client.
@@ -346,6 +348,11 @@ class GerritApi(recipe_api.RecipeApi):
         str(revision), '--message', message, '--json_file',
         self.m.json.output()
     ]
+    if automatic_attention_set_update is not None:
+      args += [
+          '--automatic-attention-set-update' if automatic_attention_set_update
+          else '--no-automatic-attention-set-update'
+      ]
     if not step_test_data:
       step_test_data = lambda: self.m.json.test_api.output({})
     return self(

+ 28 - 1
recipes/recipe_modules/gerrit/examples/full.expected/basic.json

@@ -652,6 +652,33 @@
       "@@@STEP_LOG_END@json.output (exception)@@@"
     ]
   },
+  {
+    "cmd": [
+      "vpython3",
+      "RECIPE_REPO[depot_tools]/gerrit_client.py",
+      "addmessage",
+      "--host",
+      "https://chromium-review.googlesource.com",
+      "--change",
+      "123",
+      "--revision",
+      "current",
+      "--message",
+      "This is a non-attention message",
+      "--json_file",
+      "/path/to/tmp/json",
+      "--no-automatic-attention-set-update"
+    ],
+    "env": {
+      "PATH": "<PATH>:RECIPE_REPO[depot_tools]"
+    },
+    "infra_step": true,
+    "name": "gerrit add message",
+    "~followup_annotations": [
+      "@@@STEP_LOG_LINE@json.output@{}@@@",
+      "@@@STEP_LOG_END@json.output@@@"
+    ]
+  },
   {
     "cmd": [
       "vpython3",
@@ -672,7 +699,7 @@
       "PATH": "<PATH>:RECIPE_REPO[depot_tools]"
     },
     "infra_step": true,
-    "name": "gerrit add message",
+    "name": "gerrit add message (2)",
     "~followup_annotations": [
       "@@@STEP_LOG_LINE@json.output@{}@@@",
       "@@@STEP_LOG_END@json.output@@@"

+ 4 - 0
recipes/recipe_modules/gerrit/examples/full.py

@@ -88,6 +88,10 @@ def RunSteps(api):
   api.gerrit.set_change_label(host, 123, 'code-review', -1)
   api.gerrit.set_change_label(host, 123, 'commit-queue', 1)
 
+  api.gerrit.add_message(host,
+                         123,
+                         'This is a non-attention message',
+                         automatic_attention_set_update=False)
   api.gerrit.add_message(host, 123, 'This is a comment message')
 
   api.gerrit.abandon_change(host, 123, 'bad roll')