Skip to content

Conversation

@keyonghan
Copy link
Contributor

This is to support dashboard to list branches by returning the available matched ones.

Part of flutter/flutter#51807

Copy link
Contributor

@CaseyHillers CaseyHillers left a 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!

delegate: GetStatus(config),
),
'/api/public/get-timeseries-history': GetTimeSeriesHistory(config),
'/api/public/get-branches': GetBranches(config),
Copy link
Contributor

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.

Copy link
Contributor Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

2020?

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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');
Copy link
Contributor

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.

Copy link
Contributor Author

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(
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is loadBranchRegExps defined?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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
Copy link
Contributor

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"

Copy link
Contributor Author

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(
Copy link
Contributor

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.

Copy link
Contributor Author

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';
Copy link
Contributor

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.

Copy link
Contributor Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

2020?

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@keyonghan
Copy link
Contributor Author

keyonghan commented Mar 11, 2020

Thanks for working on this Keyong!

@CaseyHillers Thank you for the detailed comments!

Copy link
Contributor

@CaseyHillers CaseyHillers left a 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
Copy link
Contributor

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]?

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: dartdocs [attempt]

Copy link
Contributor Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

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));
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@keyonghan keyonghan merged commit 0bfe29a into flutter:master Mar 11, 2020
@keyonghan keyonghan deleted the get_branch_list branch March 13, 2024 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants