diff --git a/gerrit_client.py b/gerrit_client.py index 6295b0a79..bd9b15192 100755 --- a/gerrit_client.py +++ b/gerrit_client.py @@ -393,6 +393,23 @@ def CMDsetlabel(parser, args): write_result(result, opt) +@subcommand.usage('') +def CMDrestore(parser, args): + """Restores a Gerrit change.""" + parser.add_option('-c', '--change', type=str, help='change number') + parser.add_option('-m', + '--message', + default='', + help='reason for restoring') + + (opt, args) = parser.parse_args(args) + assert opt.change, "-c not defined" + result = gerrit_util.RestoreChange( + urllib.parse.urlparse(opt.host).netloc, opt.change, opt.message) + logging.info(result) + write_result(result, opt) + + @subcommand.usage('') def CMDabandon(parser, args): """Abandons a Gerrit change.""" diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md index d08b217be..1ee52bf42 100644 --- a/recipes/README.recipes.md +++ b/recipes/README.recipes.md @@ -370,11 +370,13 @@ 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#298)(self, host, project, from_branch, to_branch, step_test_data=None):** +— **def [move\_changes](/recipes/recipe_modules/gerrit/api.py#318)(self, host, project, from_branch, to_branch, step_test_data=None):** -— **def [set\_change\_label](/recipes/recipe_modules/gerrit/api.py#280)(self, host, change, label_name, label_value, name=None, step_test_data=None):** +— **def [restore\_change](/recipes/recipe_modules/gerrit/api.py#280)(self, host, change, message=None, name=None, step_test_data=None):** -— **def [update\_files](/recipes/recipe_modules/gerrit/api.py#322)(self, host, project, branch, new_contents_by_file_path, commit_msg, params=frozenset(['status=NEW']), cc_list=frozenset([]), submit=False, submit_later=False, step_test_data_create_change=None, step_test_data_submit_change=None):** +— **def [set\_change\_label](/recipes/recipe_modules/gerrit/api.py#300)(self, host, change, label_name, label_value, name=None, step_test_data=None):** + +— **def [update\_files](/recipes/recipe_modules/gerrit/api.py#342)(self, host, project, branch, new_contents_by_file_path, commit_msg, params=frozenset(['status=NEW']), cc_list=frozenset([]), submit=False, submit_later=False, step_test_data_create_change=None, step_test_data_submit_change=None):** Update a set of files by creating and submitting a Gerrit CL. diff --git a/recipes/recipe_modules/gerrit/api.py b/recipes/recipe_modules/gerrit/api.py index 11764a570..76ffc78b7 100644 --- a/recipes/recipe_modules/gerrit/api.py +++ b/recipes/recipe_modules/gerrit/api.py @@ -277,6 +277,26 @@ class GerritApi(recipe_api.RecipeApi): step_test_data=step_test_data, ).json.output + def restore_change(self, host, change, message=None, name=None, + step_test_data=None): + args = [ + 'restore', + '--host', host, + '--change', change, + '--json_file', self.m.json.output(), + ] + if message: + args.extend(('--message', message)) + if not step_test_data: + step_test_data = lambda: self.test_api.get_one_change_response_data( + status='NEW', _number=str(change)) + + return self( + name or 'restore', + args, + step_test_data=step_test_data, + ).json.output + def set_change_label(self, host, change, diff --git a/recipes/recipe_modules/gerrit/examples/full.expected/basic.json b/recipes/recipe_modules/gerrit/examples/full.expected/basic.json index 21ec778cd..fe05d8795 100644 --- a/recipes/recipe_modules/gerrit/examples/full.expected/basic.json +++ b/recipes/recipe_modules/gerrit/examples/full.expected/basic.json @@ -696,6 +696,50 @@ "@@@STEP_LOG_END@json.output@@@" ] }, + { + "cmd": [ + "vpython3", + "RECIPE_REPO[depot_tools]/gerrit_client.py", + "restore", + "--host", + "https://chromium-review.googlesource.com", + "--change", + "123", + "--json_file", + "/path/to/tmp/json", + "--message", + "nevermind" + ], + "env": { + "PATH": ":RECIPE_REPO[depot_tools]" + }, + "infra_step": true, + "name": "gerrit restore", + "~followup_annotations": [ + "@@@STEP_LOG_LINE@json.output@[@@@", + "@@@STEP_LOG_LINE@json.output@ {@@@", + "@@@STEP_LOG_LINE@json.output@ \"_number\": \"123\",@@@", + "@@@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": [ "vpython3", diff --git a/recipes/recipe_modules/gerrit/examples/full.py b/recipes/recipe_modules/gerrit/examples/full.py index 93ba13205..c0f0e99bd 100644 --- a/recipes/recipe_modules/gerrit/examples/full.py +++ b/recipes/recipe_modules/gerrit/examples/full.py @@ -88,6 +88,7 @@ def RunSteps(api): api.gerrit.set_change_label(host, 123, 'commit-queue', 1) api.gerrit.abandon_change(host, 123, 'bad roll') + api.gerrit.restore_change(host, 123, 'nevermind') api.gerrit.get_change_description( host,