-
Notifications
You must be signed in to change notification settings - Fork 100
Create /api/get-branches to support frontend listing branches #682
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
Conversation
CaseyHillers
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this Keyong!
app_dart/bin/server.dart
Outdated
| delegate: GetStatus(config), | ||
| ), | ||
| '/api/public/get-timeseries-history': GetTimeSeriesHistory(config), | ||
| '/api/public/get-branches': GetBranches(config), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should consider caching this endpoint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, good point. BTW: the dashboard sometimes shows red when all tasks seem to be successful. Is it due to the caching delay? If so, maybe good to consider reducing the refreshing period.
| @@ -0,0 +1,65 @@ | |||
| // Copyright 2019 The Chromium Authors. All rights reserved. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2020?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
| /// Signature for a function that calculates the backoff duration to wait in | ||
| /// between requests when GitHub responds with an error. | ||
| /// | ||
| /// The `attempt` argument is zero-based, so if the first attempt to request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: in dartdocs I believe it would be formatted as $attempt since it's a variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a quick search, seems we have been using [] instead of $. Changed.
| @override | ||
| Future<Body> get() async { | ||
| final GitHub github = await config.createGitHubClient(); | ||
| const RepositorySlug slug = RepositorySlug('flutter', 'flutter'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should consider storing the flutter/flutter slug in the config so the specifics aren't littered throughout the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
| final GitHub github = await config.createGitHubClient(); | ||
| const RepositorySlug slug = RepositorySlug('flutter', 'flutter'); | ||
| final Stream<Branch> branchList = github.repositories.listBranches(slug); | ||
| final List<String> regExps = await loadBranchRegExps( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is loadBranchRegExps defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was originally defined in refresh_github_commits.dart as a private function. To share/reduce the codes, make it public so the API here can call that function as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to utils.dart.
| return const Duration(seconds: 2) * (attempt + 1); | ||
| } | ||
|
|
||
| /// Queries GitHub for the list of all available branches, and returns those |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "list of all available branches on the flutter/flutter repo"
nit: "and returns List of branches"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
| const String path = | ||
| '/flutter/cocoon/master/app_dart/dev/branch_regexps.txt'; | ||
| final Uri url = Uri.https('raw.githubusercontent.com', path); | ||
| Future<List<String>> loadBranchRegExps( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems this is used between this file and get-branches handler. We should consider moving it to something similar to github/utils.dart to reuse the logic between the two files and test it once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
| HttpClientProvider branchHttpClientProvider, | ||
| Logging log, | ||
| GitHubBackoffCalculator gitHubBackoffCalculator) async { | ||
| const String path = '/flutter/cocoon/master/app_dart/dev/branch_regexps.txt'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note, doesn't have to be addressed this PR: Was there a reason the branch regexps weren't just stored in the cocoon config? Seems like it would save us this extra HTTP query.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTTP request is intentional: this enables instant access without app re-deployment when some changes are made.
| @@ -0,0 +1,79 @@ | |||
| // Copyright 2019 The Chromium Authors. All rights reserved. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2020?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
| }); | ||
| }); | ||
|
|
||
| test('returns branches matching regExps', () async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot of different try/catch if/else logic blocks that I believe should be tested here. I think moving the loadRegExp to a separate util file would make it easier to focus on this logic for a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to utils.dart and added corresponding tests.
@CaseyHillers Thank you for the detailed comments! |
CaseyHillers
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with nits
|
|
||
| /// Queries GitHub for the list of all available branches, and returns those | ||
| /// Queries GitHub for the list of all available branches on | ||
| /// [flutter/flutter] repo, and returns list of branches |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: flutter/flutter isn't a variable. Should it be [config.flutterSlug]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
| /// Signature for a function that calculates the backoff duration to wait in | ||
| /// between requests when GitHub responds with an error. | ||
| /// | ||
| /// The `attempt` argument is zero-based, so if the first attempt to request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: dartdocs [attempt]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
| /// | ||
| /// The `attempt` argument is zero-based, so if the first attempt to request | ||
| /// from GitHub fails, and we're backing off before making the second attempt, | ||
| /// the `attempt` argument will be zero. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| log.error( | ||
| 'Attempt to download branch_regexps.txt failed:\n$error\n$stackTrace'); | ||
| } | ||
| await Future<void>.delayed(gitHubBackoffCalculator(attempt)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should wait for #683 to land and take advantage of that logic instead of reimplementing it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite some other existing logics exist in cocoon can be applied with #683
It would be good to have an issue to track: flutter/flutter#52427. So merge here and make the bunch updates later.
This is to support dashboard to list branches by returning the available matched ones.
Part of flutter/flutter#51807