-
Notifications
You must be signed in to change notification settings - Fork 100
176990 Implement get presubmit guard summaries api #4946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
6bfa647
feat(cocoon_common): Implement GuardStatus.calculate
ievdokdm 0b6e3b8
refactor(app_dart): Use GuardStatus.calculate in GetPresubmitGuard
ievdokdm 9cb5948
conductor(checkpoint): Phase Complete: Refactor GuardStatus Logic
ievdokdm 8834ea2
conductor(plan): Mark phase 'Refactor GuardStatus Logic' as complete
ievdokdm 471fd95
feat(app_dart): Implement GetPresubmitGuards request handler
ievdokdm 40fd9df
feat(rpc): Add PresubmitGuardsResponse model and use in handler
ievdokdm 3bf30c4
fix(cocoon_common): Fix TaskStatus serialization and regenerate RPC m…
ievdokdm ab5947b
conductor(checkpoint): Phase Complete: Implement GetPresubmitGuards H…
ievdokdm f8449aa
conductor(plan): Mark phase 'Implement GetPresubmitGuards Handler' as…
ievdokdm 9bfc82f
chore(conductor): Mark track 'Implement getPresubmitGuardsForPullRequ…
ievdokdm c1e36b1
feat(app_dart): Group presubmit guards by commitSha
ievdokdm 0ab5be6
refactor(rpc): Rename model to PresubmitGuardSummary and return top-l…
ievdokdm 722a108
chore(rpc): Remove obsolete PresubmitGuardsResponse files
ievdokdm d687e52
dart format --set-exit-if-changed .
ievdokdm 0223684
refactor(app_dart): Rename GetPresubmitGuards to GetPresubmitGuardSum…
ievdokdm 3f64598
chore(app_dart): Update API URL to /api/get-presubmit-guard-summaries
ievdokdm 962b010
docs(conductor): Synchronize docs for track 'Implement getPresubmitGu…
ievdokdm 09f9bf6
chore(conductor): Archive track 'Implement getPresubmitGuardsForPullR…
ievdokdm f73d759
docs: Archive completed presubmit guard and presubmit check developme…
ievdokdm 0bb281a
fix: Calculate PresubmitGuard summary creation time from the earliest…
ievdokdm da45ebd
feat: integration testing in dashboard/ with actual server (#4945)
jtmcdole 722bf16
Merge branch 'main' into 176990-guards-for-pr
ievdokdm 2601629
refactor: migrate `get_presubmit_guard_summaries_test` to use `cocoon…
ievdokdm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
app_dart/lib/src/request_handlers/get_presubmit_guard_summaries.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| // Copyright 2026 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'dart:async'; | ||
| import 'dart:io'; | ||
| import 'dart:math'; | ||
|
|
||
| import 'package:cocoon_common/guard_status.dart'; | ||
| import 'package:cocoon_common/rpc_model.dart' as rpc_model; | ||
| import 'package:github/github.dart'; | ||
| import 'package:meta/meta.dart'; | ||
|
|
||
| import '../../cocoon_service.dart'; | ||
| import '../model/firestore/presubmit_guard.dart'; | ||
| import '../request_handling/api_request_handler.dart'; | ||
| import '../service/firestore/unified_check_run.dart'; | ||
|
|
||
| /// Request handler for retrieving all presubmit guards for a specific pull request. | ||
| /// | ||
| /// GET: /api/get-presubmit-guard-summaries | ||
| /// | ||
| /// Parameters: | ||
| /// repo: (string in query) required. The repository name (e.g., 'flutter'). | ||
| /// pr: (int in query) required. The pull request number. | ||
| /// owner: (string in query) optional. The repository owner (e.g., 'flutter'). | ||
| @immutable | ||
| final class GetPresubmitGuardSummaries extends ApiRequestHandler { | ||
| /// Defines the [GetPresubmitGuardSummaries] handler. | ||
| const GetPresubmitGuardSummaries({ | ||
| required super.config, | ||
| required super.authenticationProvider, | ||
| required FirestoreService firestore, | ||
| }) : _firestore = firestore; | ||
|
|
||
| final FirestoreService _firestore; | ||
|
|
||
| /// The name of the query parameter for the repository name (e.g. 'flutter'). | ||
| static const String kRepoParam = 'repo'; | ||
|
|
||
| /// The name of the query parameter for the pull request number. | ||
| static const String kPRParam = 'pr'; | ||
|
|
||
| /// The name of the query parameter for the repository owner (e.g. 'flutter'). | ||
| static const String kOwnerParam = 'owner'; | ||
|
|
||
| @override | ||
| Future<Response> get(Request request) async { | ||
| checkRequiredQueryParameters(request, [kRepoParam, kPRParam]); | ||
|
|
||
| final repo = request.uri.queryParameters[kRepoParam]!; | ||
| final prNumber = int.parse(request.uri.queryParameters[kPRParam]!); | ||
| final owner = request.uri.queryParameters[kOwnerParam] ?? 'flutter'; | ||
|
|
||
| final slug = RepositorySlug(owner, repo); | ||
| final guards = await UnifiedCheckRun.getPresubmitGuardsForPullRequest( | ||
| firestoreService: _firestore, | ||
| slug: slug, | ||
| pullRequestId: prNumber, | ||
| ); | ||
|
|
||
| if (guards.isEmpty) { | ||
| return Response.json({ | ||
| 'error': 'No guards found for PR $prNumber in $slug', | ||
| }, statusCode: HttpStatus.notFound); | ||
| } | ||
|
|
||
| // Group guards by commitSha | ||
| final groupedGuards = <String, List<PresubmitGuard>>{}; | ||
| for (final guard in guards) { | ||
| groupedGuards.putIfAbsent(guard.commitSha, () => []).add(guard); | ||
| } | ||
ievdokdm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| final responseGuards = <rpc_model.PresubmitGuardSummary>[]; | ||
| for (final entry in groupedGuards.entries) { | ||
| final sha = entry.key; | ||
| final shaGuards = entry.value; | ||
|
|
||
| final totalFailed = shaGuards.fold<int>( | ||
| 0, | ||
| (int sum, PresubmitGuard g) => sum + g.failedBuilds, | ||
| ); | ||
| final totalRemaining = shaGuards.fold<int>( | ||
| 0, | ||
| (int sum, PresubmitGuard g) => sum + g.remainingBuilds, | ||
| ); | ||
| final totalBuilds = shaGuards.fold<int>( | ||
| 0, | ||
| (int sum, PresubmitGuard g) => sum + g.builds.length, | ||
| ); | ||
| final earliestCreationTime = shaGuards.fold<int>( | ||
| // assuming creation time is always in the past :) | ||
| DateTime.now().millisecondsSinceEpoch, | ||
| (int curr, PresubmitGuard g) => min(g.creationTime, curr), | ||
| ); | ||
|
|
||
| responseGuards.add( | ||
| rpc_model.PresubmitGuardSummary( | ||
| commitSha: sha, | ||
| creationTime: earliestCreationTime, | ||
| guardStatus: GuardStatus.calculate( | ||
| failedBuilds: totalFailed, | ||
| remainingBuilds: totalRemaining, | ||
| totalBuilds: totalBuilds, | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| return Response.json(responseGuards); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
app_dart/test/request_handlers/get_presubmit_guard_summaries_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // Copyright 2026 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'dart:convert'; | ||
| import 'dart:io'; | ||
|
|
||
| import 'package:cocoon_common/guard_status.dart'; | ||
| import 'package:cocoon_common/rpc_model.dart' as rpc_model; | ||
| import 'package:cocoon_common/task_status.dart'; | ||
| import 'package:cocoon_integration_test/testing.dart'; | ||
| import 'package:cocoon_server_test/test_logging.dart'; | ||
| import 'package:cocoon_service/src/request_handlers/get_presubmit_guard_summaries.dart'; | ||
| import 'package:cocoon_service/src/request_handling/exceptions.dart'; | ||
| import 'package:github/github.dart'; | ||
| import 'package:test/test.dart'; | ||
|
|
||
| import '../src/request_handling/request_handler_tester.dart'; | ||
|
|
||
| void main() { | ||
| useTestLoggerPerTest(); | ||
|
|
||
| late RequestHandlerTester tester; | ||
| late GetPresubmitGuardSummaries handler; | ||
| late FakeFirestoreService firestore; | ||
|
|
||
| Future<List<rpc_model.PresubmitGuardSummary>?> getResponse() async { | ||
| final response = await tester.get(handler); | ||
| if (response.statusCode != HttpStatus.ok) { | ||
| return null; | ||
| } | ||
| final responseBody = await utf8.decoder | ||
| .bind(response.body as Stream<List<int>>) | ||
| .transform(json.decoder) | ||
| .single; | ||
| return (responseBody as List<dynamic>) | ||
| .map( | ||
| (e) => rpc_model.PresubmitGuardSummary.fromJson( | ||
| e as Map<String, Object?>, | ||
| ), | ||
| ) | ||
| .toList(); | ||
| } | ||
|
|
||
| setUp(() { | ||
| firestore = FakeFirestoreService(); | ||
| tester = RequestHandlerTester(); | ||
| handler = GetPresubmitGuardSummaries( | ||
| config: FakeConfig(), | ||
| authenticationProvider: FakeDashboardAuthentication(), | ||
| firestore: firestore, | ||
| ); | ||
| }); | ||
|
|
||
| test('missing parameters', () async { | ||
| tester.request = FakeHttpRequest(); | ||
| expect(tester.get(handler), throwsA(isA<BadRequestException>())); | ||
| }); | ||
|
|
||
| test('no guards found', () async { | ||
| tester.request = FakeHttpRequest( | ||
| queryParametersValue: { | ||
| GetPresubmitGuardSummaries.kRepoParam: 'flutter', | ||
| GetPresubmitGuardSummaries.kPRParam: '123', | ||
| }, | ||
| ); | ||
|
|
||
| final response = await tester.get(handler); | ||
| expect(response.statusCode, HttpStatus.notFound); | ||
| }); | ||
|
|
||
| test('returns multiple guards grouped by commitSha', () async { | ||
| final slug = RepositorySlug('flutter', 'flutter'); | ||
| const prNumber = 123; | ||
|
|
||
| // SHA1: Two stages, both succeeded. | ||
| final guard1a = generatePresubmitGuard( | ||
| slug: slug, | ||
| pullRequestId: prNumber, | ||
| commitSha: 'sha1', | ||
| checkRun: generateCheckRun(1), | ||
| creationTime: 100, | ||
| builds: {'test1': TaskStatus.succeeded}, | ||
| remainingBuilds: 0, | ||
| ); | ||
|
|
||
| final guard1b = generatePresubmitGuard( | ||
| slug: slug, | ||
| pullRequestId: prNumber, | ||
| commitSha: 'sha1', | ||
| checkRun: generateCheckRun(2), | ||
| creationTime: 110, | ||
| builds: {'test2': TaskStatus.succeeded}, | ||
| remainingBuilds: 0, | ||
| ); | ||
|
|
||
| // SHA2: One stage, failed. | ||
| final guard2 = generatePresubmitGuard( | ||
| slug: slug, | ||
| pullRequestId: prNumber, | ||
| commitSha: 'sha2', | ||
| checkRun: generateCheckRun(3), | ||
| creationTime: 200, | ||
| builds: {'test3': TaskStatus.failed}, | ||
| failedBuilds: 1, | ||
| remainingBuilds: 0, | ||
| ); | ||
|
|
||
| firestore.putDocuments([guard1a, guard1b, guard2]); | ||
|
|
||
| tester.request = FakeHttpRequest( | ||
| queryParametersValue: { | ||
| GetPresubmitGuardSummaries.kRepoParam: 'flutter', | ||
| GetPresubmitGuardSummaries.kPRParam: prNumber.toString(), | ||
| }, | ||
| ); | ||
|
|
||
| final result = (await getResponse())!; | ||
| expect(result.length, 2); | ||
|
|
||
| final item1 = result.firstWhere((g) => g.commitSha == 'sha1'); | ||
| expect(item1.creationTime, 100); // earliest | ||
| expect(item1.guardStatus, GuardStatus.succeeded); | ||
|
|
||
| final item2 = result.firstWhere((g) => g.commitSha == 'sha2'); | ||
| expect(item2.creationTime, 200); | ||
| expect(item2.guardStatus, GuardStatus.failed); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
conductor/archive/get_presubmit_guard_summaries_20260211/index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Track get_presubmit_guards_20260211 Context | ||
|
|
||
| - [Specification](./spec.md) | ||
| - [Implementation Plan](./plan.md) | ||
| - [Metadata](./metadata.json) |
8 changes: 8 additions & 0 deletions
8
conductor/archive/get_presubmit_guard_summaries_20260211/metadata.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "track_id": "get_presubmit_guards_20260211", | ||
| "type": "feature", | ||
| "status": "new", | ||
| "created_at": "2026-02-11T12:00:00Z", | ||
| "updated_at": "2026-02-11T12:00:00Z", | ||
| "description": "Implement getPresubmitGuardsForPullRequest request handler" | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.