Skip to content

Commit 4e3f074

Browse files
committed
Allow vacuuming a specific repository and branch.
1 parent 9a13a35 commit 4e3f074

File tree

7 files changed

+78
-17
lines changed

7 files changed

+78
-17
lines changed

app_dart/lib/src/request_handlers/vacuum_github_commits.dart

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,31 @@ final class VacuumGithubCommits extends ApiRequestHandler {
2626
}) : _scheduler = scheduler;
2727

2828
final Scheduler _scheduler;
29-
static const String branchParam = 'branch';
29+
30+
static const _paramRepo = 'repo';
31+
static const _paramBranch = 'branch';
3032

3133
@override
3234
Future<Response> get(Request request) async {
33-
for (var slug in config.supportedRepos) {
34-
final branch =
35-
request.uri.queryParameters[branchParam] ??
36-
Config.defaultBranch(slug);
37-
await _vacuumRepository(slug, branch: branch);
35+
final Iterable<gh.RepositorySlug> repos;
36+
if (request.uri.queryParameters[_paramRepo] case final specific?) {
37+
repos = [gh.RepositorySlug.full(specific)];
38+
} else {
39+
repos = config.supportedRepos;
40+
}
41+
42+
final String? branch;
43+
if (request.uri.queryParameters[_paramBranch] case final specific?) {
44+
branch = specific;
45+
} else {
46+
branch = null;
47+
}
48+
49+
for (final slug in repos) {
50+
await _vacuumRepository(
51+
slug,
52+
branch: branch ?? Config.defaultBranch(slug),
53+
);
3854
}
3955

4056
return Response.emptyOk;

app_dart/test/request_handlers/vacuum_github_commits_test.dart

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,31 +97,51 @@ void main() {
9797
});
9898

9999
test('succeeds when GitHub returns no commits', () async {
100-
fakeGithubCommitShas = <String>[];
101-
config.supportedBranchesValue = <String>['master'];
100+
fakeGithubCommitShas = [];
101+
config.supportedBranchesValue = ['master'];
102102
final body = await tester.get(handler);
103103

104104
expect(firestore, existsInStorage(fs.Commit.metadata, isEmpty));
105105
expect(await body.body.toList(), isEmpty);
106106
});
107107

108+
test('succeeds on specific repo and branch set', () async {
109+
fakeGithubCommitShas = ['123'];
110+
config.supportedReposValue = {RepositorySlug('flutter', 'cocoon')};
111+
112+
tester.request.uri = tester.request.uri.replace(
113+
queryParameters: {'repo': 'flutter/cocoon', 'branch': 'a-new-branch'},
114+
);
115+
116+
await tester.get(handler);
117+
expect(
118+
firestore,
119+
existsInStorage(fs.Commit.metadata, [
120+
isCommit
121+
.hasSha('123')
122+
.hasRepositoryPath('flutter/cocoon')
123+
.hasBranch('a-new-branch'),
124+
]),
125+
);
126+
});
127+
108128
test('does not fail on empty commit list', () async {
109-
fakeGithubCommitShas = <String>[];
129+
fakeGithubCommitShas = [];
110130
expect(firestore, existsInStorage(fs.Commit.metadata, isEmpty));
111131
await tester.get(handler);
112132
expect(firestore, existsInStorage(fs.Commit.metadata, isEmpty));
113133
});
114134

115135
test('does not add recent commits', () async {
116-
fakeGithubCommitShas = <String>['${DateTime.now().millisecondsSinceEpoch}'];
136+
fakeGithubCommitShas = ['${DateTime.now().millisecondsSinceEpoch}'];
117137

118138
expect(firestore, existsInStorage(fs.Commit.metadata, isEmpty));
119139
await tester.get(handler);
120140
expect(firestore, existsInStorage(fs.Commit.metadata, isEmpty));
121141
});
122142

123143
test('inserts all relevant fields of the commit', () async {
124-
fakeGithubCommitShas = <String>['1'];
144+
fakeGithubCommitShas = ['1'];
125145
expect(firestore, existsInStorage(fs.Commit.metadata, isEmpty));
126146
await tester.get(handler);
127147
expect(

dashboard/lib/service/appengine_cocoon.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,15 @@ class AppEngineCocoonService implements CocoonService {
189189
}
190190

191191
@override
192-
Future<CocoonResponse<bool>> vacuumGitHubCommits(String idToken) async {
193-
final refreshGitHubCommitsUrl = apiEndpoint('/api/vacuum-github-commits');
192+
Future<CocoonResponse<bool>> vacuumGitHubCommits(
193+
String idToken, {
194+
required String repo,
195+
required String branch,
196+
}) async {
197+
final refreshGitHubCommitsUrl = apiEndpoint(
198+
'/api/vacuum-github-commits',
199+
queryParameters: {'repo': repo, 'branch': branch},
200+
);
194201
final response = await _client.get(
195202
refreshGitHubCommitsUrl,
196203
headers: <String, String>{'X-Flutter-IdToken': idToken},

dashboard/lib/service/cocoon.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ abstract class CocoonService {
7070
});
7171

7272
/// Force update Cocoon to get the latest commits.
73-
Future<CocoonResponse<bool>> vacuumGitHubCommits(String idToken);
73+
Future<CocoonResponse<bool>> vacuumGitHubCommits(
74+
String idToken, {
75+
required String repo,
76+
required String branch,
77+
});
7478
}
7579

7680
/// Wrapper class for data this state serves.

dashboard/lib/service/dev_cocoon.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ class DevelopmentCocoonService implements CocoonService {
126126
}
127127

128128
@override
129-
Future<CocoonResponse<bool>> vacuumGitHubCommits(String idToken) async {
129+
Future<CocoonResponse<bool>> vacuumGitHubCommits(
130+
String idToken, {
131+
required String repo,
132+
required String branch,
133+
}) async {
130134
return const CocoonResponse<bool>.error(
131135
'Unable to vacuum against fake data. Try building the app to use prod data.',
132136
statusCode: 501 /* Not implemented */,

dashboard/lib/state/build.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ class BuildState extends ChangeNotifier {
360360
}
361361
final response = await cocoonService.vacuumGitHubCommits(
362362
await authService.idToken,
363+
repo: currentRepo,
364+
branch: currentBranch,
363365
);
364366
if (response.error != null) {
365367
_errors.send('$errorMessageRefreshGitHubCommits: ${response.error}');

dashboard/test/service/appengine_cocoon_test.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,11 @@ void main() {
254254

255255
test('should return true if request succeeds', () async {
256256
await expectLater(
257-
service.vacuumGitHubCommits('fakeIdToken'),
257+
service.vacuumGitHubCommits(
258+
'fakeIdToken',
259+
repo: 'flutter',
260+
branch: 'master',
261+
),
258262
completion(
259263
isA<CocoonResponse<bool>>().having((r) => r.data, 'data', isTrue),
260264
),
@@ -268,7 +272,11 @@ void main() {
268272
}),
269273
);
270274
await expectLater(
271-
service.vacuumGitHubCommits('fakeIdToken'),
275+
service.vacuumGitHubCommits(
276+
'fakeIdToken',
277+
repo: 'flutter',
278+
branch: 'master',
279+
),
272280
completion(
273281
isA<CocoonResponse<bool>>().having((r) => r.error, 'data', isNotNull),
274282
),

0 commit comments

Comments
 (0)