blob: 44e12d75fb4d11bc3cbd1085933f387d3aba45d9 [file] [log] [blame]
# Copyright 2022 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Recipe for auto-submitting eligible changes on release branches. See
go/change-control-in-gerrit."""
from google.protobuf import json_format
from PB.go.chromium.org.luci.buildbucket.proto import common as common_pb2
from PB.recipe_engine.result import RawResult
from PB.recipes.fuchsia.release.auto_submit import InputProperties
from PB.recipes.fuchsia.release.cherry_pick import (
InputProperties as CherryPickProperties,
)
from RECIPE_MODULES.fuchsia.utils import pluralize
DEPS = [
"fuchsia/buildbucket_util",
"fuchsia/gerrit_auto_submit",
"fuchsia/utils",
"recipe_engine/buildbucket",
"recipe_engine/properties",
"recipe_engine/step",
]
PROPERTIES = InputProperties
def RunSteps(api, props):
changes = []
for gerrit_host in props.gerrit_hosts:
with api.step.nest("get eligible"):
changes_for_host = api.gerrit_auto_submit.get_eligible_changes(
gerrit_host,
"Release-Approval",
max_attempts=1,
)
changes.extend([(gerrit_host, c) for c in changes_for_host])
cherry_pick_builds = []
# For now, handle submission sequentially to avoid races. This could be
# parallelized across branches in the future.
for gerrit_host, change in changes:
with api.step.nest(f"submit change {change['_number']}"):
cherry_pick_properties = CherryPickProperties(
changes=[
CherryPickProperties.ChangeInfo(
revision=change["current_revision"],
change_id=str(change["_number"]),
change_url=f"https://{gerrit_host}/c/{change['project']}/+/{change['_number']}",
),
],
target_project=change["project"],
target_remote=f"https://{gerrit_host.replace('-review', '')}/{change['project']}",
target_branch=change["branch"],
# TODO(fxbug.dev/105915): Rename cherry_pick.proto dryrun
# property to dry_run for consistency.
dryrun=props.dry_run,
)
request = api.buildbucket.schedule_request(
props.submission_builder,
properties=json_format.MessageToDict(
cherry_pick_properties, preserving_proto_field_name=True
),
)
cherry_pick_builds.extend(api.buildbucket.run([request]))
api.buildbucket_util.display_builds(
"cherry-pick builds", cherry_pick_builds, raise_on_failure=True
)
return RawResult(
summary_markdown=f"cherry-picked {pluralize('change', changes)}",
status=common_pb2.SUCCESS,
)
def GenTests(api):
yield (
api.test("basic")
+ api.gerrit_auto_submit.changes_query_test_data()
+ api.gerrit_auto_submit.changes_submitted_together_test_data()
+ api.properties(
gerrit_hosts=["fuchsia-review.googlesource.com"],
submission_builder="auto-submit-cherry-pick",
)
)