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>
This commit is contained in:
Mike Frysinger
2025-01-15 17:01:01 -08:00
committed by LUCI CQ
parent ce28e377d6
commit c9552ffad5
4 changed files with 44 additions and 5 deletions

View File

@@ -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(

View File

@@ -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@@@"

View File

@@ -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')