Commit 982b2a75 authored by Josip Sokcevic's avatar Josip Sokcevic Committed by LUCI CQ

Add move change to Gerrit recipes

Will be used by a LUCI cron to move Gerrit changes for repos that are in
transition state #1 and #2.

R=ehmaldonado@chromium.org

Change-Id: Id7383ef677aa1cc90102c9a2aadbcc17712e150d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2522559
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
parent d9992955
......@@ -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
&mdash; **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]
......
......@@ -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
......@@ -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": "<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",
......
......@@ -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()))
......@@ -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])
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