Skip to content
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

Get needed version from API tool in health check #213

Merged
merged 3 commits into from
Jan 2, 2024
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
4 changes: 4 additions & 0 deletions pkgs/firehose/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.2

- Get needed version from `dart_apitool` in PR health checks.

## 0.4.1

- Ensure that packages are listed in lexical order.
Expand Down
53 changes: 28 additions & 25 deletions pkgs/firehose/lib/src/health/health.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,14 @@ Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automati
var formattedChanges = const JsonEncoder.withIndent(' ').convert(report);
print('Breaking change report:\n$formattedChanges');

BreakingLevel breakingLevel;
if ((report['noChangesDetected'] as bool?) ?? false) {
breakingLevel = BreakingLevel.none;
} else {
if ((report['breakingChanges'] as Map? ?? {}).isNotEmpty) {
breakingLevel = BreakingLevel.breaking;
} else if ((report['nonBreakingChanges'] as Map? ?? {}).isNotEmpty) {
breakingLevel = BreakingLevel.nonBreaking;
} else {
breakingLevel = BreakingLevel.none;
}
}

var oldPackage = Package(
Directory(path.join(baseDirectory.path, currentPath)),
package.repository,
);
final versionMap = decoded['version'] as Map<String, dynamic>;
changeForPackage[package] = BreakingChange(
level: breakingLevel,
oldVersion: oldPackage.version!,
newVersion: package.version!,
level: _breakingLevel(report),
oldVersion: Version.parse(versionMap['old'].toString()),
newVersion: Version.parse(versionMap['new'].toString()),
neededVersion: Version.parse(versionMap['needed'].toString()),
versionIsFine: versionMap['success'] as bool,
explanation: versionMap['explanation'].toString(),
);
}
return HealthCheckResult(
Expand All @@ -178,6 +165,20 @@ ${changeForPackage.entries.map((e) => '|${e.key.name}|${e.value.toMarkdownRow()}
);
}

BreakingLevel _breakingLevel(Map<String, dynamic> report) {
BreakingLevel breakingLevel;
if ((report['noChangesDetected'] as bool?) ?? false) {
breakingLevel = BreakingLevel.none;
} else if ((report['breakingChanges'] as Map? ?? {}).isNotEmpty) {
breakingLevel = BreakingLevel.breaking;
} else if ((report['nonBreakingChanges'] as Map? ?? {}).isNotEmpty) {
breakingLevel = BreakingLevel.nonBreaking;
} else {
breakingLevel = BreakingLevel.none;
}
return breakingLevel;
}

Future<HealthCheckResult> licenseCheck(GithubApi github) async {
var files = await github.listFilesForPR();
var allFilePaths = await getFilesWithoutLicenses(Directory.current);
Expand Down Expand Up @@ -379,22 +380,24 @@ class BreakingChange {
final BreakingLevel level;
final Version oldVersion;
final Version newVersion;
final Version neededVersion;
final bool versionIsFine;
final String explanation;

BreakingChange({
required this.level,
required this.oldVersion,
required this.newVersion,
required this.neededVersion,
required this.versionIsFine,
required this.explanation,
});

Version get suggestedNewVersion => getNewVersion(level, oldVersion);

bool get versionIsFine => newVersion == suggestedNewVersion;

String toMarkdownRow() => [
level.name,
oldVersion,
newVersion,
versionIsFine ? suggestedNewVersion : '**$suggestedNewVersion**',
versionIsFine ? neededVersion : '**$neededVersion** <br> $explanation',
versionIsFine ? ':heavy_check_mark:' : ':warning:'
].map((e) => e.toString()).join('|');
}
2 changes: 1 addition & 1 deletion pkgs/firehose/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: firehose
description: A tool to automate publishing of Pub packages from GitHub actions.
version: 0.4.1
version: 0.4.2
repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose

environment:
Expand Down
Loading