Commit f9d9909c authored by Xinan Lin's avatar Xinan Lin Committed by LUCI CQ

Return changeinfo from update_files method

Users may need more info from a created/submitted change,
e.g. revision hash, change status(submitted or not) etc.

BUG=1236658
TEST=train
Recipe-Nontrivial-Roll: chrome_release
Change-Id: I1db57e5c6a4e58ea320526ef5f5cbb83e1b0bb60
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3102579
Commit-Queue: Xinan Lin <linxinan@chromium.org>
Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@google.com>
Reviewed-by: 's avatarMichael Moss <mmoss@chromium.org>
parent 21a20d68
......@@ -462,7 +462,10 @@ Args:
* submit: Should land this CL instantly.
Returns:
Integer change number.
A ChangeInfo dictionary as documented here:
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#create-change
Or if the change is submitted, here:
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#submit-change
### *recipe_modules* / [git](/recipes/recipe_modules/git)
[DEPS](/recipes/recipe_modules/git/__init__.py#1): [recipe\_engine/buildbucket][recipe_engine/recipe_modules/buildbucket], [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/platform][recipe_engine/recipe_modules/platform], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/python][recipe_engine/recipe_modules/python], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/runtime][recipe_engine/recipe_modules/runtime], [recipe\_engine/step][recipe_engine/recipe_modules/step]
......
......@@ -272,7 +272,10 @@ class GerritApi(recipe_api.RecipeApi):
* submit: Should land this CL instantly.
Returns:
Integer change number.
A ChangeInfo dictionary as documented here:
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#create-change
Or if the change is submitted, here:
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#submit-change
"""
assert len(new_contents_by_file_path
) > 0, 'The dict of file paths should not be empty.'
......@@ -329,11 +332,14 @@ class GerritApi(recipe_api.RecipeApi):
'--change',
change,
])
self('submit change %d' % change, [
submit_cmd = [
'submitchange',
'--host',
host,
'--change',
change,
])
return change
'--json_file',
self.m.json.output(),
]
step_result = self('submit change %d' % change, submit_cmd)
return step_result.json.output
......@@ -138,6 +138,14 @@
"@@@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@ \"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@}@@@",
......@@ -235,13 +243,36 @@
"--host",
"https://chromium-review.googlesource.com",
"--change",
"91827"
"91827",
"--json_file",
"/path/to/tmp/json"
],
"env": {
"PATH": "<PATH>:RECIPE_REPO[depot_tools]"
},
"infra_step": true,
"name": "gerrit submit change 91827"
"name": "gerrit submit change 91827",
"~followup_annotations": [
"@@@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@ \"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\": \"MERGED\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"subject\": \"Change title\"@@@",
"@@@STEP_LOG_LINE@json.output@}@@@",
"@@@STEP_LOG_END@json.output@@@"
]
},
{
"cmd": [
......
......@@ -23,12 +23,14 @@ def RunSteps(api):
api.gerrit.move_changes(host, project, 'master', 'main')
change = api.gerrit.update_files(host,
project,
'main', {'chrome/VERSION': '99.99.99.99'},
'Dummy CL.',
submit=True)
assert change == 91827, change
change_info = api.gerrit.update_files(host,
project,
'main',
{'chrome/VERSION': '99.99.99.99'},
'Dummy CL.',
submit=True)
assert int(change_info['_number']) == 91827, change_info
assert change_info['status'] == 'MERGED'
# Query for changes in Chromium's CQ.
api.gerrit.get_changes(
......@@ -72,17 +74,18 @@ def RunSteps(api):
def GenTests(api):
yield (
api.test('basic') +
api.step_data('gerrit create_gerrit_branch (v8/v8 test)',
api.gerrit.make_gerrit_create_branch_response_data()) +
api.step_data('gerrit create change at (v8/v8 main)',
api.gerrit.update_files_response_data()) +
api.step_data('gerrit get_gerrit_branch (v8/v8 main)',
api.gerrit.make_gerrit_get_branch_response_data()) +
api.step_data('gerrit move changes',
api.gerrit.get_move_change_response_data(branch='main')) +
api.step_data('gerrit relatedchanges',
api.gerrit.get_related_changes_response_data()) +
api.step_data('gerrit changes empty query',
api.gerrit.get_empty_changes_response_data()))
yield (api.test('basic') +
api.step_data('gerrit create_gerrit_branch (v8/v8 test)',
api.gerrit.make_gerrit_create_branch_response_data()) +
api.step_data('gerrit create change at (v8/v8 main)',
api.gerrit.update_files_response_data()) +
api.step_data('gerrit submit change 91827',
api.gerrit.update_files_response_data(status='MERGED')) +
api.step_data('gerrit get_gerrit_branch (v8/v8 main)',
api.gerrit.make_gerrit_get_branch_response_data()) +
api.step_data('gerrit move changes',
api.gerrit.get_move_change_response_data(branch='main'))
+ api.step_data('gerrit relatedchanges',
api.gerrit.get_related_changes_response_data()) +
api.step_data('gerrit changes empty query',
api.gerrit.get_empty_changes_response_data()))
......@@ -80,9 +80,7 @@ class GerritTestApi(recipe_test_api.RecipeTestApi):
return self._make_gerrit_response_json([self._gerrit_change_data(**kwargs)])
def update_files_response_data(self, **kwargs):
data = self._gerrit_change_data(**kwargs)
data.pop('revisions')
return self._make_gerrit_response_json(data)
return self._make_gerrit_response_json(self._gerrit_change_data(**kwargs))
def get_empty_changes_response_data(self):
return self._make_gerrit_response_json([])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment