Commit fe34723a authored by Sergiy Belozorov's avatar Sergiy Belozorov Committed by Commit Bot

Add gerrit.abandon_change command

R=tandrii@chromium.org

Bug: 935715
Change-Id: Ia7b8e2b187b59680270d694b24edf82493d1ed5c
Reviewed-on: https://chromium-review.googlesource.com/c/1487212Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
Commit-Queue: Sergiy Belozorov <sergiyb@chromium.org>
parent be28670f
......@@ -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):
......
......@@ -325,6 +325,8 @@ Module for interact with gerrit endpoints
Wrapper for easy calling of gerrit_utils steps.
&mdash; **def [abandon\_change](/recipes/recipe_modules/gerrit/api.py#159)(self, host, change, message=None, name=None, step_test_data=None):**
&mdash; **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
......
......@@ -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
......@@ -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": "<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",
......
......@@ -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)
......
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