Add a 'setlabel' command to gerrit_client.py

And add a hook for it in the gerrit recipe_module.

This will allow invocations of gerrit_client to set votes like
"code-review-1" or "commit-queue+1" on CLs. This will be used by bots
to control CLs they just created with update_files().

Bug: 1250084
Change-Id: I888458983165fed5882e5c37cba4a69dbfb9b810
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3207266
Commit-Queue: Ben Pastene <bpastene@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
This commit is contained in:
Ben Pastene
2021-10-06 01:23:24 +00:00
committed by LUCI CQ
parent 4940cc4b8f
commit 281edf7577
6 changed files with 111 additions and 2 deletions

View File

@@ -226,6 +226,24 @@ class GerritApi(recipe_api.RecipeApi):
step_test_data=step_test_data,
).json.output
def set_change_label(self,
host,
change,
label_name,
label_value,
name=None,
step_test_data=None):
args = [
'setlabel', '--host', host, '--change',
int(change), '--json_file',
self.m.json.output(), '-l', label_name, label_value
]
return self(
name or 'setlabel',
args,
step_test_data=step_test_data,
).json.output
def move_changes(self,
host,
project,

View File

@@ -450,6 +450,60 @@
"@@@STEP_LOG_END@json.output@@@"
]
},
{
"cmd": [
"vpython",
"-u",
"RECIPE_REPO[depot_tools]/gerrit_client.py",
"setlabel",
"--host",
"https://chromium-review.googlesource.com",
"--change",
"123",
"--json_file",
"/path/to/tmp/json",
"-l",
"code-review",
"-1"
],
"env": {
"PATH": "<PATH>:RECIPE_REPO[depot_tools]"
},
"infra_step": true,
"name": "gerrit setlabel",
"~followup_annotations": [
"@@@STEP_LOG_END@json.output (invalid)@@@",
"@@@STEP_LOG_LINE@json.output (exception)@No JSON object could be decoded@@@",
"@@@STEP_LOG_END@json.output (exception)@@@"
]
},
{
"cmd": [
"vpython",
"-u",
"RECIPE_REPO[depot_tools]/gerrit_client.py",
"setlabel",
"--host",
"https://chromium-review.googlesource.com",
"--change",
"123",
"--json_file",
"/path/to/tmp/json",
"-l",
"commit-queue",
"1"
],
"env": {
"PATH": "<PATH>:RECIPE_REPO[depot_tools]"
},
"infra_step": true,
"name": "gerrit setlabel (2)",
"~followup_annotations": [
"@@@STEP_LOG_END@json.output (invalid)@@@",
"@@@STEP_LOG_LINE@json.output (exception)@No JSON object could be decoded@@@",
"@@@STEP_LOG_END@json.output (exception)@@@"
]
},
{
"cmd": [
"vpython",

View File

@@ -65,6 +65,9 @@ def RunSteps(api):
api.gerrit.get_change_description(
host, change=123, patchset=1)
api.gerrit.set_change_label(host, 123, 'code-review', -1)
api.gerrit.set_change_label(host, 123, 'commit-queue', 1)
api.gerrit.abandon_change(host, 123, 'bad roll')
with api.step.defer_results():