Skip to content

[tool] Add details to missing gradle coverage error #6029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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: 20 additions & 9 deletions script/tool/lib/src/dependabot_check_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ class DependabotCheckCommand extends PackageLoopingCommand {
bool skipped = true;
final List<String> errors = <String>[];

final RunState gradleState = _validateDependabotGradleCoverage(package);
skipped = skipped && gradleState == RunState.skipped;
if (gradleState == RunState.failed) {
final _GradleCoverageResult gradleResult =
_validateDependabotGradleCoverage(package);
skipped = skipped && gradleResult.runState == RunState.skipped;
if (gradleResult.runState == RunState.failed) {
printError('${indentation}Missing Gradle coverage.');
print('${indentation}Add a "gradle" entry to '
'${getStringArg(_configPathFlag)} for ${gradleResult.missingPath}');
errors.add('Missing Gradle coverage');
}

Expand All @@ -90,7 +93,8 @@ class DependabotCheckCommand extends PackageLoopingCommand {
/// - succeeded if it includes gradle and is covered.
/// - failed if it includes gradle and is not covered.
/// - skipped if it doesn't include gradle.
RunState _validateDependabotGradleCoverage(RepositoryPackage package) {
_GradleCoverageResult _validateDependabotGradleCoverage(
RepositoryPackage package) {
final Directory androidDir =
package.platformDirectory(FlutterPlatform.android);
final Directory appDir = androidDir.childDirectory('app');
Expand All @@ -99,16 +103,23 @@ class DependabotCheckCommand extends PackageLoopingCommand {
final String dependabotPath =
'/${getRelativePosixPath(appDir, from: _repoRoot)}';
return _gradleDirs.contains(dependabotPath)
? RunState.succeeded
: RunState.failed;
? _GradleCoverageResult(RunState.succeeded)
: _GradleCoverageResult(RunState.failed, missingPath: dependabotPath);
} else if (androidDir.existsSync()) {
// It's a library, so only check for the android directory to be covered.
final String dependabotPath =
'/${getRelativePosixPath(androidDir, from: _repoRoot)}';
return _gradleDirs.contains(dependabotPath)
? RunState.succeeded
: RunState.failed;
? _GradleCoverageResult(RunState.succeeded)
: _GradleCoverageResult(RunState.failed, missingPath: dependabotPath);
}
return RunState.skipped;
return _GradleCoverageResult(RunState.skipped);
}
}

class _GradleCoverageResult {
_GradleCoverageResult(this.runState, {this.missingPath});

final RunState runState;
final String? missingPath;
}
4 changes: 4 additions & 0 deletions script/tool/test/dependabot_check_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ ${gradleEntries.join('\n')}
output,
containsAllInOrder(<Matcher>[
contains('Missing Gradle coverage.'),
contains(
'Add a "gradle" entry to .github/dependabot.yml for /packages/a_package/example/android/app'),
contains('a_package/example:\n'
' Missing Gradle coverage')
]));
Expand All @@ -112,6 +114,8 @@ ${gradleEntries.join('\n')}
output,
containsAllInOrder(<Matcher>[
contains('Missing Gradle coverage.'),
contains(
'Add a "gradle" entry to .github/dependabot.yml for /packages/a_plugin/android'),
contains('a_plugin:\n'
' Missing Gradle coverage')
]));
Expand Down