Create /api/get-branches to support frontend listing branches#682
Create /api/get-branches to support frontend listing branches#682keyonghan merged 3 commits intoflutter:masterfrom
Conversation
CaseyHillers
left a comment
There was a problem hiding this comment.
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.
We should consider caching this endpoint.
There was a problem hiding this comment.
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. | |||
| /// 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.
nit: in dartdocs I believe it would be formatted as $attempt since it's a variable
There was a problem hiding this comment.
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.
We should consider storing the flutter/flutter slug in the config so the specifics aren't littered throughout the code.
| 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.
Where is loadBranchRegExps defined?
There was a problem hiding this comment.
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.
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.
nit: "list of all available branches on the flutter/flutter repo"
nit: "and returns List of branches"
| 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.
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.
| 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.
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.
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. | |||
| }); | ||
| }); | ||
|
|
||
| test('returns branches matching regExps', () async { |
There was a problem hiding this comment.
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.
moved to utils.dart and added corresponding tests.
@CaseyHillers Thank you for the detailed comments! |
|
|
||
| /// 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.
nit: flutter/flutter isn't a variable. Should it be [config.flutterSlug]?
| /// 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.
nit: dartdocs [attempt]
| /// | ||
| /// 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. |
| 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.
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.
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