Add CL description getter

For context crrev.com/c/4450427.

R=gbeaty@google.com

Change-Id: Ic0a7847009be274010daeaf3181242ae34477a39
Bug: b/214597409
Recipe-Nontrivial-Roll: build
Recipe-Nontrivial-Roll: build_limited
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4451469
Commit-Queue: Ariel Zhang <arielzhang@google.com>
Reviewed-by: Garrett Beaty <gbeaty@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
changes/69/4451469/6
Ariel Zhang 3 years ago committed by LUCI CQ
parent 6b62f42578
commit 2d1c655c2c

@ -42,6 +42,7 @@
* [tryserver:tests/gerrit_change_fetch_ref_timeout](#recipes-tryserver_tests_gerrit_change_fetch_ref_timeout) (Python3 ✅)
* [tryserver:tests/gerrit_change_owner](#recipes-tryserver_tests_gerrit_change_owner) (Python3 ✅)
* [tryserver:tests/gerrit_change_target_ref](#recipes-tryserver_tests_gerrit_change_target_ref) (Python3 ✅)
* [tryserver:tests/get_change_description](#recipes-tryserver_tests_get_change_description) (Python3 ✅)
* [tryserver:tests/get_files_affected_by_patch](#recipes-tryserver_tests_get_files_affected_by_patch) (Python3 ✅)
* [tryserver:tests/get_footers](#recipes-tryserver_tests_get_footers) (Python3 ✅)
* [tryserver:tests/require_is_tryserver](#recipes-tryserver_tests_require_is_tryserver) (Python3 ✅)
@ -867,6 +868,10 @@ Returns gerrit change patchset, e.g. 6 for a patch ref of
Populated iff gerrit_change is populated Returns None if not populated..
&mdash; **def [get\_change\_description](/recipes/recipe_modules/tryserver/api.py#388)(self):**
Gets the CL description.
&mdash; **def [get\_files\_affected\_by\_patch](/recipes/recipe_modules/tryserver/api.py#234)(self, patch_root, report_files_via_property=None, \*\*kwargs):**
Returns list of paths to files affected by the patch.
@ -879,7 +884,7 @@ Args:
Returned paths will be relative to to api.path['root'].
&mdash; **def [get\_footer](/recipes/recipe_modules/tryserver/api.py#374)(self, tag, patch_text=None):**
&mdash; **def [get\_footer](/recipes/recipe_modules/tryserver/api.py#377)(self, tag, patch_text=None):**
Gets a specific tag from a CL description
@ -902,11 +907,11 @@ Returns true iff the properties exist to match a Gerrit issue.
Returns true iff we have a change to check out.
&mdash; **def [normalize\_footer\_name](/recipes/recipe_modules/tryserver/api.py#382)(self, footer):**
&mdash; **def [normalize\_footer\_name](/recipes/recipe_modules/tryserver/api.py#385)(self, footer):**
&mdash; **def [require\_is\_tryserver](/recipes/recipe_modules/tryserver/api.py#221)(self):**
&mdash; **def [set\_change](/recipes/recipe_modules/tryserver/api.py#385)(self, change):**
&mdash; **def [set\_change](/recipes/recipe_modules/tryserver/api.py#393)(self, change):**
Set the gerrit change for this module.
@ -1178,6 +1183,13 @@ PYTHON_VERSION_COMPATIBILITY: PY3
PYTHON_VERSION_COMPATIBILITY: PY3
&mdash; **def [RunSteps](/recipes/recipe_modules/tryserver/tests/gerrit_change_target_ref.py#18)(api):**
### *recipes* / [tryserver:tests/get\_change\_description](/recipes/recipe_modules/tryserver/tests/get_change_description.py)
[DEPS](/recipes/recipe_modules/tryserver/tests/get_change_description.py#10): [tryserver](#recipe_modules-tryserver), [recipe\_engine/buildbucket][recipe_engine/recipe_modules/buildbucket], [recipe\_engine/step][recipe_engine/recipe_modules/step]
PYTHON_VERSION_COMPATIBILITY: PY3
&mdash; **def [RunSteps](/recipes/recipe_modules/tryserver/tests/get_change_description.py#17)(api):**
### *recipes* / [tryserver:tests/get\_files\_affected\_by\_patch](/recipes/recipe_modules/tryserver/tests/get_files_affected_by_patch.py)
[DEPS](/recipes/recipe_modules/tryserver/tests/get_files_affected_by_patch.py#9): [tryserver](#recipe_modules-tryserver), [recipe\_engine/assertions][recipe_engine/recipe_modules/assertions], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/platform][recipe_engine/recipe_modules/platform], [recipe\_engine/properties][recipe_engine/recipe_modules/properties]

@ -343,6 +343,9 @@ class TryserverApi(recipe_api.RecipeApi):
def _ensure_gerrit_commit_message(self):
"""Fetch full commit message for Gerrit change."""
if self._gerrit_commit_message:
return
self._ensure_gerrit_change_info()
self._gerrit_commit_message = self.m.gerrit.get_change_description(
'https://%s' % self.gerrit_change.host,
@ -382,6 +385,11 @@ class TryserverApi(recipe_api.RecipeApi):
def normalize_footer_name(self, footer):
return '-'.join([ word.title() for word in footer.strip().split('-') ])
def get_change_description(self):
"""Gets the CL description."""
self._ensure_gerrit_commit_message()
return self._gerrit_commit_message
def set_change(self, change):
"""Set the gerrit change for this module.

@ -143,68 +143,6 @@
"@@@STEP_LOG_END@json.output (exception)@@@"
]
},
{
"cmd": [
"vpython3",
"RECIPE_REPO[depot_tools]/gerrit_client.py",
"changes",
"--verbose",
"--host",
"https://chromium-review.googlesource.com",
"--json_file",
"/path/to/tmp/json",
"--limit",
"1",
"-p",
"change=91827",
"-o",
"ALL_REVISIONS",
"-o",
"ALL_COMMITS"
],
"env": {
"PATH": "<PATH>:RECIPE_REPO[depot_tools]"
},
"infra_step": true,
"luci_context": {
"realm": {
"name": "chromium:linux"
},
"resultdb": {
"current_invocation": {
"name": "invocations/build:8945511751514863184",
"update_token": "token"
},
"hostname": "rdbhost"
}
},
"name": "gerrit changes (2)",
"timeout": 480,
"~followup_annotations": [
"@@@STEP_LOG_LINE@json.output@[@@@",
"@@@STEP_LOG_LINE@json.output@ {@@@",
"@@@STEP_LOG_LINE@json.output@ \"_number\": \"91827\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"branch\": \"main\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"id\": \"fully~qualified~changeid\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"_number\": \"1\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"commit\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"message\": \"Change commit message\"@@@",
"@@@STEP_LOG_LINE@json.output@ }@@@",
"@@@STEP_LOG_LINE@json.output@ }@@@",
"@@@STEP_LOG_LINE@json.output@ }, @@@",
"@@@STEP_LOG_LINE@json.output@ \"status\": \"NEW\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"subject\": \"Change title\"@@@",
"@@@STEP_LOG_LINE@json.output@ }@@@",
"@@@STEP_LOG_LINE@json.output@]@@@",
"@@@STEP_LOG_END@json.output@@@"
]
},
{
"cmd": [
"python3",

@ -143,68 +143,6 @@
"@@@STEP_LOG_END@json.output (exception)@@@"
]
},
{
"cmd": [
"vpython3",
"RECIPE_REPO[depot_tools]/gerrit_client.py",
"changes",
"--verbose",
"--host",
"https://chromium-review.googlesource.com",
"--json_file",
"/path/to/tmp/json",
"--limit",
"1",
"-p",
"change=91827",
"-o",
"ALL_REVISIONS",
"-o",
"ALL_COMMITS"
],
"env": {
"PATH": "<PATH>:RECIPE_REPO[depot_tools]"
},
"infra_step": true,
"luci_context": {
"realm": {
"name": "chromium:linux"
},
"resultdb": {
"current_invocation": {
"name": "invocations/build:8945511751514863184",
"update_token": "token"
},
"hostname": "rdbhost"
}
},
"name": "gerrit changes (2)",
"timeout": 480,
"~followup_annotations": [
"@@@STEP_LOG_LINE@json.output@[@@@",
"@@@STEP_LOG_LINE@json.output@ {@@@",
"@@@STEP_LOG_LINE@json.output@ \"_number\": \"91827\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"branch\": \"main\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"id\": \"fully~qualified~changeid\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"_number\": \"1\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"commit\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"message\": \"Change commit message\"@@@",
"@@@STEP_LOG_LINE@json.output@ }@@@",
"@@@STEP_LOG_LINE@json.output@ }@@@",
"@@@STEP_LOG_LINE@json.output@ }, @@@",
"@@@STEP_LOG_LINE@json.output@ \"status\": \"NEW\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"subject\": \"Change title\"@@@",
"@@@STEP_LOG_LINE@json.output@ }@@@",
"@@@STEP_LOG_LINE@json.output@]@@@",
"@@@STEP_LOG_END@json.output@@@"
]
},
{
"cmd": [
"python3",

@ -0,0 +1,30 @@
# Copyright 2023 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from recipe_engine.post_process import (DropExpectation, StatusSuccess, MustRun,
DoesNotRun)
PYTHON_VERSION_COMPATIBILITY = 'PY2+3'
DEPS = [
'tryserver',
'recipe_engine/buildbucket',
'recipe_engine/step',
]
def RunSteps(api):
api.tryserver.get_change_description()
api.tryserver.get_change_description()
def GenTests(api):
yield api.test(
'basic',
api.buildbucket.try_build(),
api.post_process(MustRun, 'gerrit changes'),
api.post_process(DoesNotRun, 'gerrit changes (2)'),
api.post_process(StatusSuccess),
api.post_process(DropExpectation),
)
Loading…
Cancel
Save