From fe34723a55ec71b235512eac5ad561faf3151d6e Mon Sep 17 00:00:00 2001 From: Sergiy Belozorov Date: Wed, 27 Feb 2019 15:07:33 +0000 Subject: [PATCH] Add gerrit.abandon_change command R=tandrii@chromium.org Bug: 935715 Change-Id: Ia7b8e2b187b59680270d694b24edf82493d1ed5c Reviewed-on: https://chromium-review.googlesource.com/c/1487212 Reviewed-by: Andrii Shyshkalov Commit-Queue: Sergiy Belozorov --- gerrit_client.py | 13 ++++++ recipes/README.recipes.md | 2 + recipes/recipe_modules/gerrit/api.py | 20 +++++++++ .../gerrit/examples/full.expected/basic.json | 44 +++++++++++++++++++ .../recipe_modules/gerrit/examples/full.py | 2 + 5 files changed, 81 insertions(+) diff --git a/gerrit_client.py b/gerrit_client.py index f2501f1ed8..aecb921fd4 100755 --- a/gerrit_client.py +++ b/gerrit_client.py @@ -88,6 +88,19 @@ def CMDchanges(parser, args): write_result(result, opt) +@subcommand.usage('') +def CMDabandon(parser, args): + parser.add_option('-c', '--change', type=int, help='change number') + parser.add_option('-m', '--message', default='', help='reason for abandoning') + + (opt, args) = parser.parse_args(args) + result = gerrit_util.AbandonChange( + urlparse.urlparse(opt.host).netloc, + opt.change, opt.message) + logging.info(result) + write_result(result, opt) + + class OptionParser(optparse.OptionParser): """Creates the option parse and add --verbose support.""" def __init__(self, *args, **kwargs): diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md index ce657dcb74..8b36d981ad 100644 --- a/recipes/README.recipes.md +++ b/recipes/README.recipes.md @@ -325,6 +325,8 @@ Module for interact with gerrit endpoints Wrapper for easy calling of gerrit_utils steps. +— **def [abandon\_change](/recipes/recipe_modules/gerrit/api.py#159)(self, host, change, message=None, name=None, step_test_data=None):** + — **def [create\_gerrit\_branch](/recipes/recipe_modules/gerrit/api.py#31)(self, host, project, branch, commit, \*\*kwargs):** Create a new branch from given project and commit diff --git a/recipes/recipe_modules/gerrit/api.py b/recipes/recipe_modules/gerrit/api.py index 17f7e6aa6d..c331a090c2 100644 --- a/recipes/recipe_modules/gerrit/api.py +++ b/recipes/recipe_modules/gerrit/api.py @@ -155,3 +155,23 @@ class GerritApi(recipe_api.RecipeApi): step_test_data=step_test_data, **kwargs ).json.output + + def abandon_change(self, host, change, message=None, name=None, + step_test_data=None): + args = [ + 'abandon', + '--host', host, + '--change', int(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='ABANDONED', _number=str(change)) + + return self( + name or 'abandon', + 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 b406f1453e..74229b0a0d 100644 --- a/recipes/recipe_modules/gerrit/examples/full.expected/basic.json +++ b/recipes/recipe_modules/gerrit/examples/full.expected/basic.json @@ -183,6 +183,50 @@ "@@@STEP_LOG_END@json.output@@@" ] }, + { + "cmd": [ + "python", + "-u", + "RECIPE_REPO[depot_tools]/gerrit_client.py", + "abandon", + "--host", + "https://chromium-review.googlesource.com", + "--change", + "123", + "--json_file", + "/path/to/tmp/json", + "--message", + "bad roll" + ], + "env": { + "PATH": ":RECIPE_REPO[depot_tools]" + }, + "infra_step": true, + "name": "gerrit abandon", + "~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\": \"master\", @@@", + "@@@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\": \"ABANDONED\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"subject\": \"Change title\"@@@", + "@@@STEP_LOG_LINE@json.output@ }@@@", + "@@@STEP_LOG_LINE@json.output@]@@@", + "@@@STEP_LOG_END@json.output@@@" + ] + }, { "cmd": [ "python", diff --git a/recipes/recipe_modules/gerrit/examples/full.py b/recipes/recipe_modules/gerrit/examples/full.py index 094c3cc8ec..9b8eb24b96 100644 --- a/recipes/recipe_modules/gerrit/examples/full.py +++ b/recipes/recipe_modules/gerrit/examples/full.py @@ -48,6 +48,8 @@ def RunSteps(api): api.gerrit.get_change_description( host, change=123, patchset=1) + api.gerrit.abandon_change(host, 123, 'bad roll') + with api.step.defer_results(): api.gerrit.get_change_description( host, change=122, patchset=3)