in app_dart/lib/src/request_handlers/github_webhook.dart [379:429]
Future<void> _applyPackageTestChecks(GitHub gitHubClient, String? eventAction, PullRequest pr) async {
final RepositorySlug slug = pr.base!.repo!.slug();
final Stream<PullRequestFile> files = gitHubClient.pullRequests.listFiles(slug, pr.number!);
bool hasTests = false;
bool needsTests = false;
await for (PullRequestFile file in files) {
final String filename = file.filename!;
// When null, do not assume 0 lines have been added.
final int linesAdded = file.additionsCount ?? 1;
final int linesDeleted = file.deletionsCount ?? 0;
final int linesTotal = file.changesCount ?? linesDeleted + linesAdded;
final bool addedCode = linesAdded > 0 || linesDeleted != linesTotal;
if (addedCode &&
!filename.endsWith('AUTHORS') &&
!filename.endsWith('CODEOWNERS') &&
!filename.endsWith('pubspec.yaml') &&
!filename.endsWith('.ci.yaml') &&
!filename.endsWith('.cirrus.yml') &&
!filename.contains('.ci/') &&
!filename.contains('.github/') &&
!filename.endsWith('.md')) {
needsTests = !_allChangesAreCodeComments(file);
}
// See https://github.com/flutter/flutter/wiki/Plugin-Tests for discussion
// of various plugin test types and locations.
if (filename.endsWith('_test.dart') ||
// Native iOS/macOS tests.
filename.contains('RunnerTests/') ||
filename.contains('RunnerUITests/') ||
// Native Android tests.
filename.contains('android/src/test/') ||
filename.contains('androidTest/') ||
// Native Linux tests.
filename.endsWith('_test.cc') ||
// Native Windows tests.
filename.endsWith('_test.cpp')) {
hasTests = true;
}
}
if (!hasTests && needsTests && !pr.draft!) {
final String body = config.missingTestsPullRequestMessage;
if (!await _alreadyCommented(gitHubClient, pr, body)) {
await gitHubClient.issues.createComment(slug, pr.number!, body);
await gitHubClient.issues.addLabelsToIssue(slug, pr.number!, kNeedsTestsLabels);
}
}
}