diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md index 97785ea39f..c2a5d542b2 100644 --- a/recipes/README.recipes.md +++ b/recipes/README.recipes.md @@ -418,6 +418,8 @@ Args: Returns: A dict for the target revision as documented here: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes + +— **def [move\_changes](/recipes/recipe_modules/gerrit/api.py#177)(self, host, project, from_branch, to_branch, step_test_data=None):** ### *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 6539cdf67f..e076d599ec 100644 --- a/recipes/recipe_modules/gerrit/api.py +++ b/recipes/recipe_modules/gerrit/api.py @@ -173,3 +173,27 @@ class GerritApi(recipe_api.RecipeApi): args, step_test_data=step_test_data, ).json.output + + def move_changes(self, + host, + project, + from_branch, + to_branch, + step_test_data=None): + args = [ + 'movechanges', '--host', host, '-p', + 'project=%s' % project, '-p', + 'branch=%s' % from_branch, '-p', 'status=open', '--destination_branch', + to_branch, '--json_file', + self.m.json.output() + ] + + if not step_test_data: + step_test_data = lambda: self.test_api.get_one_change_response_data( + branch=to_branch) + + return self( + 'move changes', + args, + step_test_data=step_test_data, + ).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 02ad3eb53c..13524233f3 100644 --- a/recipes/recipe_modules/gerrit/examples/full.expected/basic.json +++ b/recipes/recipe_modules/gerrit/examples/full.expected/basic.json @@ -58,6 +58,54 @@ "@@@STEP_LOG_END@json.output@@@" ] }, + { + "cmd": [ + "vpython", + "-u", + "RECIPE_REPO[depot_tools]/gerrit_client.py", + "movechanges", + "--host", + "https://chromium-review.googlesource.com", + "-p", + "project=v8/v8", + "-p", + "branch=master", + "-p", + "status=open", + "--destination_branch", + "main", + "--json_file", + "/path/to/tmp/json" + ], + "env": { + "PATH": ":RECIPE_REPO[depot_tools]" + }, + "infra_step": true, + "name": "gerrit move changes", + "~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@ \"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": [ "vpython", diff --git a/recipes/recipe_modules/gerrit/examples/full.py b/recipes/recipe_modules/gerrit/examples/full.py index 9b8eb24b96..a9d5ead02f 100644 --- a/recipes/recipe_modules/gerrit/examples/full.py +++ b/recipes/recipe_modules/gerrit/examples/full.py @@ -21,6 +21,8 @@ def RunSteps(api): data = api.gerrit.get_gerrit_branch(host, project, 'master') assert data == '67ebf73496383c6777035e374d2d664009e2aa5c' + api.gerrit.move_changes(host, project, 'master', 'main') + # Query for changes in Chromium's CQ. api.gerrit.get_changes( host, @@ -57,17 +59,12 @@ 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 get_gerrit_branch (v8/v8 master)', - api.gerrit.make_gerrit_get_branch_response_data() - ) - + api.step_data( - 'gerrit changes empty query', - api.gerrit.get_empty_changes_response_data() - ) - ) + 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 get_gerrit_branch (v8/v8 master)', + 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 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 b709bd0976..6844daf071 100644 --- a/recipes/recipe_modules/gerrit/test_api.py +++ b/recipes/recipe_modules/gerrit/test_api.py @@ -51,3 +51,8 @@ class GerritTestApi(recipe_test_api.RecipeTestApi): def get_empty_changes_response_data(self): return self._make_gerrit_response_json([]) + + def get_move_change_response_data(self, **kwargs): + change = EXAMPLE_CHANGE.copy() + change.update(kwargs) + return self._make_gerrit_response_json([change])