Skip to content

Delete the V2 experiment, add a TreeStatusPage. #4761

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 1 commit into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dashboard/lib/logic/links.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

import '../build_dashboard_page.dart';
import '../views/build_dashboard_page.dart';

/// List of links that are shown in the [DashboardNavigationDrawer].
List<CocoonLink> createCocoonLinks(BuildContext context) {
Expand Down
39 changes: 13 additions & 26 deletions dashboard/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'build_dashboard_page.dart';
import 'firebase_options.dart';
import 'service/cocoon.dart';
import 'service/firebase_auth.dart';
import 'src/v2/router.dart';
import 'state/build.dart';
import 'views/build_dashboard_page.dart';
import 'views/tree_status_page.dart';
import 'widgets/now.dart';
import 'widgets/state_provider.dart';
import 'widgets/task_box.dart';
Expand Down Expand Up @@ -117,40 +117,27 @@ class MyApp extends StatelessWidget {

switch (uriData.pathSegments.first) {
case BuildDashboardPage.routeSegment:
return MaterialPageRoute<void>(
return MaterialPageRoute(
settings: settings,
builder: (BuildContext context) {
builder: (_) {
return BuildDashboardPage(
queryParameters: uriData.queryParameters,
);
},
);
case 'v2':
if (_findV2Route(context, uriData, settings) case (
final WidgetBuilder builder,
final RouteSettings settings,
)) {
return MaterialPageRoute<void>(
builder: builder,
settings: settings,
);
}
case TreeStatusPage.routeSegment:
return MaterialPageRoute(
settings: settings,
builder: (_) {
return TreeStatusPage(
queryParameters: uriData.queryParameters,
);
},
);
}
return null;
},
),
);
}

(WidgetBuilder, RouteSettings)? _findV2Route(
BuildContext context,
Uri route,
RouteSettings settings,
) {
if (route.pathSegments.isEmpty || route.pathSegments.first != 'v2') {
throw ArgumentError.value(route, 'route', 'not a v2 route');
}

return v2PreviewRoute(context, route, settings);
}
}
57 changes: 57 additions & 0 deletions dashboard/lib/service/appengine_cocoon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,63 @@ class AppEngineCocoonService implements CocoonService {
}
}

@override
Future<CocoonResponse<List<TreeStatusChange>>> fetchTreeStatusChanges({
required String repo,
}) async {
final getTreeStatusChangesUrl = apiEndpoint(
'/api/public/get-tree-status-changes',
queryParameters: {'repo': repo},
);

final response = await _client.get(getTreeStatusChangesUrl);

if (response.statusCode != HttpStatus.ok) {
return CocoonResponse.error(
'/api/public/get-tree-status-changes returned ${response.statusCode}',
statusCode: response.statusCode,
);
}

try {
final jsonResponse = jsonDecode(response.body) as List<Object?>;
final changes = <TreeStatusChange>[];
for (final jsonChange in jsonResponse.cast<Map<String, Object?>>()) {
changes.add(TreeStatusChange.fromJson(jsonChange));
}
return CocoonResponse.data(changes);
} catch (error) {
return CocoonResponse.error(
error.toString(),
statusCode: response.statusCode,
);
}
}

@override
Future<CocoonResponse<void>> updateTreeStatus({
required String repo,
required TreeStatus status,
String? reason,
}) async {
final updateTreeStatusUrl = apiEndpoint('/api/public/update-tree-status');
final response = await _client.post(
updateTreeStatusUrl,
body: jsonEncode({
'repo': repo,
'status': status.name,
if (reason != null) 'reason': reason,
}),
Comment on lines +233 to +237
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want a shared JsonSerializable for this? TreeStatusChange has repo/status/reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mental TODO, yeah this should just be using TreeStatusChange.toJson().

);
if (response.statusCode == HttpStatus.ok) {
return const CocoonResponse.data(null);
}
return CocoonResponse.error(
'HTTP Code: ${response.statusCode}, ${response.body}',
statusCode: response.statusCode,
);
}

@override
Future<CocoonResponse<bool>> vacuumGitHubCommits(
String idToken, {
Expand Down
14 changes: 13 additions & 1 deletion dashboard/lib/service/cocoon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,21 @@ abstract class CocoonService {
/// Get the current list of version branches in flutter/flutter.
Future<CocoonResponse<List<Branch>>> fetchFlutterBranches();

/// Get the current list of version branches in flutter/flutter.
/// Get the current list of repositories supported by Cocoon.
Future<CocoonResponse<List<String>>> fetchRepos();

/// Get the current list of manual tree status changes in a particular repo.
Future<CocoonResponse<List<TreeStatusChange>>> fetchTreeStatusChanges({
required String repo,
});

/// Adds a tree status change with an optional [reason].
Future<CocoonResponse<void>> updateTreeStatus({
required String repo,
required TreeStatus status,
String? reason,
});

/// Schedule the provided [task] to be re-run.
Future<CocoonResponse<bool>> rerunTask({
required String? idToken,
Expand Down
51 changes: 51 additions & 0 deletions dashboard/lib/service/dev_cocoon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,57 @@ class DevelopmentCocoonService implements CocoonService {
return _pausedStatus!.future;
}

final _treeStatusChanges = <String, List<TreeStatusChange>>{};
static final _defaultChanges = [
TreeStatusChange(
createdAt: DateTime.now().subtract(const Duration(hours: 1)),
status: TreeStatus.success,
authoredBy: 'Joe Admin',
reason: 'Test',
),
TreeStatusChange(
createdAt: DateTime.now().subtract(const Duration(hours: 2)),
status: TreeStatus.failure,
authoredBy: 'Joe Admin',
reason: 'Test',
),
];

@override
Future<CocoonResponse<List<TreeStatusChange>>> fetchTreeStatusChanges({
required String repo,
}) async {
return CocoonResponse<List<TreeStatusChange>>.data(
_treeStatusChanges.putIfAbsent(repo, () => [..._defaultChanges]),
);
}

@override
Future<CocoonResponse<void>> updateTreeStatus({
required String repo,
required TreeStatus status,
String? reason,
}) async {
// At most 10 per.
final list = _treeStatusChanges.putIfAbsent(
repo,
() => [..._defaultChanges],
);
list.insert(
0,
TreeStatusChange(
createdAt: DateTime.now(),
status: status,
authoredBy: 'Joe Widget',
reason: reason,
),
);
if (list.length > 10) {
list.removeLast();
}
return const CocoonResponse<void>.data(null);
}

static const List<String> _repos = <String>['flutter', 'cocoon'];

@override
Expand Down
9 changes: 0 additions & 9 deletions dashboard/lib/src/v2/README.md

This file was deleted.

60 changes: 0 additions & 60 deletions dashboard/lib/src/v2/helpers/invoke_if_non_null.dart

This file was deleted.

33 changes: 0 additions & 33 deletions dashboard/lib/src/v2/models/git_branch.dart

This file was deleted.

45 changes: 0 additions & 45 deletions dashboard/lib/src/v2/models/git_commit.dart

This file was deleted.

Loading