Skip to content

Commit

Permalink
[tool] Add details to missing gradle coverage error (#6029)
Browse files Browse the repository at this point in the history
When failing a package due to missing gradle coverage, explain what needs to be done to fix it.

Fixes flutter/flutter#132453
  • Loading branch information
stuartmorgan authored Feb 1, 2024
1 parent 9a7ca13 commit cbaa340
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
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

0 comments on commit cbaa340

Please sign in to comment.