Skip to content

Commit

Permalink
Get needed version from API tool in health check (#213)
Browse files Browse the repository at this point in the history
* Get needed version from API tool in health check

* Fix bug

* Rev version
  • Loading branch information
mosuem authored Jan 2, 2024
1 parent 55251b1 commit dc44e82
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
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

0 comments on commit dc44e82

Please sign in to comment.