Skip to content
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
29 changes: 17 additions & 12 deletions app_dart/lib/src/request_handlers/github/webhook_subscription.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ const Set<String> kNeedsCheckLabelsAndTests = <String>{
final RegExp kEngineTestRegExp = RegExp(r'(tests?|benchmarks?)\.(dart|java|mm|m|cc|sh)$');
final List<String> kNeedsTestsLabels = <String>['needs tests'];

// Extentions for files that use // for single line comments.
// See [_allChangesAreCodeComments] for more.
@visibleForTesting
const Set<String> knownCommentCodeExtensions = <String>{
'cc',
'cpp',
'dart',
'gradle',
'groovy',
'java',
'kt',
'm',
'mm',
'swift',
};

/// Subscription for processing GitHub webhooks.
///
/// The PubSub subscription is set up here:
Expand Down Expand Up @@ -660,20 +676,9 @@ class GithubWebhookSubscription extends SubscriptionHandler {
return false;
}

// Ensure that the file is a language reconized by the check below.
const Set<String> codeExtensions = <String>{
'cc',
'cpp',
'dart',
'java',
'kt',
'm',
'mm',
'swift',
};
final String filename = file.filename!;
final String? extension = filename.contains('.') ? filename.split('.').last.toLowerCase() : null;
if (extension == null || !codeExtensions.contains(extension)) {
if (extension == null || !knownCommentCodeExtensions.contains(extension)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1436,12 +1436,13 @@ void main() {
);
});

test('Framework no comment if only comments changed', () async {
const int issueNumber = 123;
tester.message = generateGithubWebhookMessage(action: 'opened', number: issueNumber);
final RepositorySlug slug = RepositorySlug('flutter', 'flutter');
for (String extention in knownCommentCodeExtensions) {
test('Framework no comment if only comments changed .$extention', () async {
const int issueNumber = 123;
tester.message = generateGithubWebhookMessage(action: 'opened', number: issueNumber);
final RepositorySlug slug = RepositorySlug('flutter', 'flutter');

const String patch = '''
const String patch = '''
@@ -128,7 +128,7 @@

/// Insert interesting comment here.
Expand All @@ -1453,27 +1454,28 @@ void foo() {
String baz = '';
''';

when(pullRequestsService.listFiles(slug, issueNumber)).thenAnswer(
(_) => Stream<PullRequestFile>.fromIterable(<PullRequestFile>[
PullRequestFile()
..filename = 'packages/foo/lib/foo.dart'
..additionsCount = 1
..deletionsCount = 1
..changesCount = 2
..patch = patch,
]),
);
when(pullRequestsService.listFiles(slug, issueNumber)).thenAnswer(
(_) => Stream<PullRequestFile>.fromIterable(<PullRequestFile>[
PullRequestFile()
..filename = 'packages/foo/lib/foo.$extention'
..additionsCount = 1
..deletionsCount = 1
..changesCount = 2
..patch = patch,
]),
);

await tester.post(webhook);
await tester.post(webhook);

verifyNever(
issuesService.createComment(
slug,
issueNumber,
argThat(contains(config.missingTestsPullRequestMessageValue)),
),
);
});
verifyNever(
issuesService.createComment(
slug,
issueNumber,
argThat(contains(config.missingTestsPullRequestMessageValue)),
),
);
});
}

test('Framework labels PRs, no comment if tests (dev/bots/test.dart)', () async {
const int issueNumber = 123;
Expand Down