diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md index 5c6c3602a..70ccfec13 100644 --- a/recipes/README.recipes.md +++ b/recipes/README.recipes.md @@ -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] diff --git a/recipes/recipe_modules/gerrit/api.py b/recipes/recipe_modules/gerrit/api.py index 93e9b5d40..d11c51086 100644 --- a/recipes/recipe_modules/gerrit/api.py +++ b/recipes/recipe_modules/gerrit/api.py @@ -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 diff --git a/recipes/recipe_modules/gerrit/examples/full.expected/basic.json b/recipes/recipe_modules/gerrit/examples/full.expected/basic.json index 4103928ce..449d7ac5b 100644 --- a/recipes/recipe_modules/gerrit/examples/full.expected/basic.json +++ b/recipes/recipe_modules/gerrit/examples/full.expected/basic.json @@ -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": ":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": [ diff --git a/recipes/recipe_modules/gerrit/examples/full.py b/recipes/recipe_modules/gerrit/examples/full.py index 1effa1709..b36b7fea3 100644 --- a/recipes/recipe_modules/gerrit/examples/full.py +++ b/recipes/recipe_modules/gerrit/examples/full.py @@ -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())) diff --git a/recipes/recipe_modules/gerrit/test_api.py b/recipes/recipe_modules/gerrit/test_api.py index 5fdd76ffd..fc11a86de 100644 --- a/recipes/recipe_modules/gerrit/test_api.py +++ b/recipes/recipe_modules/gerrit/test_api.py @@ -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([])