Fix docstrings and add support for arbitrary CL try-results

This fixes the copy-paste error with the _from_id and _from_build_number
versions of get_build. It also adds support for getting try results
from a URL, not just the current checked out version.

Bug: None
Change-Id: I1e076c5c461c346f5864eda068a6552237f5691f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6890424
Reviewed-by: Brian Sheedy <bsheedy@chromium.org>
Commit-Queue: Struan Shrimpton <sshrimp@google.com>
Auto-Submit: Struan Shrimpton <sshrimp@google.com>
changes/24/6890424/7
Struan Shrimpton 2 months ago committed by LUCI CQ
parent e0cc7e0bef
commit 28ecc1b36a

@ -47,25 +47,8 @@ async def get_build_from_id(
https://ci.chromium.org/b/<build_id>
Args:
build_id: The request body for the RPC. All fields should be represented
by strings. Integer fields will be parsed later.
https://chromium.googlesource.com/infra/luci/luci-go/+/main/buildbucket/proto/builds_service.proto
for more details.
The request's mask can be set to get more information. By default only
high level statuses will be returned. Some useful fields to include in
this mask are:
status, input, output, id, builder, builder_info, tags, steps, infra
Multiple fields in the mask can be included as a comma separated string
e.g.
The build_number is mutually exclusive with the build_id. To get the
build from a build_id, only the build_id is needed. e.g.
{
"id": "<build id>",
"mask": {
"fields": "steps,tags"
}
}
build_id: The BuildBucket build id. This is a unique identifier for the
build.
fields: A list of fields to return. Options are:
status, input, output, id, builder, builder_info, tags, steps, infra
@ -93,27 +76,14 @@ async def get_build_from_build_number(
The url of a build can be deconstructed and used to get more details about
the build. e.g.
https://ci.chromium.org/b/<build_id>
https://ci.chromium.org/ui/p/<builder_project>/builders/<builder_bucket>/<builder_name>/<build_number>/overview
Args:
build_id: The request body for the RPC. All fields should be represented
by strings. Integer fields will be parsed later.
https://chromium.googlesource.com/infra/luci/luci-go/+/main/buildbucket/proto/builds_service.proto
for more details.
The request's mask can be set to get more information. By default only
high level statuses will be returned. Some useful fields to include in
this mask are:
status, input, output, id, builder, builder_info, tags, steps, infra
Multiple fields in the mask can be included as a comma separated string
The build_number is mutually exclusive with the build_id. To get the
build from a build_id only the build_id is needed. e.g.
{
"id": "<build_id>",
"mask": {
"fields": "steps,tags"
}
}
build_number: The build number of the builder. This is a consecutive
value that uniquely identifies the build per builder.
builder_name: The name of the builder the build belongs to.
builder_bucket: The bucket the builder belongs to. e.g. 'try' or 'ci'
builder_project: The project the bucket belongs to. e.g. 'chromium'
fields: A list of fields to return. Options are:
status, input, output, id, builder, builder_info, tags, steps, infra

@ -13,14 +13,21 @@ tracer = telemetry.get_tracer(__name__)
async def try_builder_results(
ctx: fastmcp.Context,
checkout: str,
change_list_issue: int | None = None,
):
"""Gets the try builder results for the current checked out branch
"""Gets the try builder results for the provided change list issue
The url of a gerrit change can be parsed from a gerrit cl e.g.
https://chromium-review.googlesource.com/c/chromium/src/+/<change_list_issue>
Args:
checkout: Location of the current checkout.
change_list_issue: The change list (CL) issue id. If none is provided,
the current branch and its associated CL is used.
Returns:
A json list of builds that either ran or are still running on the current
CL
A json list of builds that either ran or are still running on the provided
CL or current branch.
"""
with tracer.start_as_current_span('chromium.mcp.try_builder_results'):
command = [
@ -29,6 +36,8 @@ async def try_builder_results(
"try-results",
"--json=-",
]
if change_list_issue:
command.extend(['-i', str(change_list_issue)])
result = subprocess.run(
command,
capture_output=True,

@ -32,7 +32,7 @@ class GitClTest(unittest.IsolatedAsyncioTestCase):
args=[], returncode=0, stdout=expected_output, stderr='')
output = await git_cl.try_builder_results(self.mock_context,
self.checkout)
self.checkout, None)
self.assertEqual(output, expected_output)
expected_command = ["git", "cl", "try-results", "--json=-"]
@ -42,6 +42,26 @@ class GitClTest(unittest.IsolatedAsyncioTestCase):
text=True,
cwd=self.checkout)
@mock.patch('subprocess.run')
async def test_try_builder_results_with_issue_success(
self, mock_subprocess_run):
expected_output = '{"builds": []}'
mock_subprocess_run.return_value = subprocess.CompletedProcess(
args=[], returncode=0, stdout=expected_output, stderr='')
output = await git_cl.try_builder_results(self.mock_context,
self.checkout, 1234)
self.assertEqual(output, expected_output)
expected_command = [
"git", "cl", "try-results", "--json=-", "-i", "1234"
]
mock_subprocess_run.assert_called_once_with(expected_command,
capture_output=True,
check=True,
text=True,
cwd=self.checkout)
@mock.patch('subprocess.run')
async def test_get_current_changes_success(self, mock_subprocess_run):
expected_output = 'diff --git a/file.txt b/file.txt'

Loading…
Cancel
Save