diff --git a/mcp/buildbucket.py b/mcp/buildbucket.py index f478e26604..21167298dd 100644 --- a/mcp/buildbucket.py +++ b/mcp/buildbucket.py @@ -47,25 +47,8 @@ async def get_build_from_id( https://ci.chromium.org/b/ 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": "", - "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/ + https://ci.chromium.org/ui/p//builders////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": "", - "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 diff --git a/mcp/git_cl.py b/mcp/git_cl.py index deb97e76ce..77f3b0866d 100644 --- a/mcp/git_cl.py +++ b/mcp/git_cl.py @@ -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/+/ + 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, diff --git a/mcp/git_cl_test.py b/mcp/git_cl_test.py index acdc1faa1c..84c09fc74d 100644 --- a/mcp/git_cl_test.py +++ b/mcp/git_cl_test.py @@ -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'