Skip to content

Commit

Permalink
update the 'publishable' PR comment to use a markdown table (#43)
Browse files Browse the repository at this point in the history
* use a markdown table

* tweak wording

* update message

* add a docs link

* Update firehose.dart
  • Loading branch information
devoncarew authored Jan 26, 2023
1 parent af7bc4b commit 524bd80
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 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.3.9

- Update the 'publishable' PR comment to use a markdown table.

## 0.3.8

- Updated the pubspec `repository` field to reflect the new source location.
Expand Down
44 changes: 27 additions & 17 deletions pkgs/firehose/lib/firehose.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const String _dependabotUser = 'dependabot[bot]';

const String _githubActionsUser = 'github-actions[bot]';

const String _publishBotTag = '**publish action**';
const String _publishBotTag = '## Package publishing';

class Firehose {
final Directory directory;
Expand Down Expand Up @@ -49,14 +49,25 @@ class Firehose {
user: _githubActionsUser, searchTerm: _publishBotTag);

if (results.hasSuccess) {
var text = '$_publishBotTag:\n\n${results.describe}';
var text = '''$_publishBotTag
| Package | Version | Status | Publish tag |
| :--- | ---: | :--- | ---: |
${results.describeAsMarkdown}
See also the docs at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.
''';

if (existingCommentId == null) {
await github.createComment(github.repoSlug!, github.issueNumber!, text);
} else {
await github.updateComment(github.repoSlug!, existingCommentId, text);
}
} else {
if (results.hasError && exitCode == 0) {
exitCode = 1;
}

if (existingCommentId != null) {
await github.deleteComment(github.repoSlug!, existingCommentId);
}
Expand Down Expand Up @@ -99,16 +110,13 @@ class Firehose {
}

if (await pub.hasPublishedVersion(package.name, pubspecVersion!)) {
var result = Result.info(
package,
'$pubspecVersion already published at pub.dev',
);
var result = Result.info(package, 'already published at pub.dev');
print(result);
results.addResult(result);
} else if (package.pubspec.isPreRelease) {
var result = Result.info(
package,
'version ($pubspecVersion) is pre-release; no publish is necessary',
'version $pubspecVersion is pre-release; no publish is necessary',
);
print(result);
results.addResult(result);
Expand All @@ -121,10 +129,8 @@ class Firehose {
} else {
print('No issues found.');

var result = Result.success(
package,
'${package.pubspec.version} is ready to publish; after merging, '
'tag with `$repoTag` to trigger publishing');
var result = Result.success(package,
'ready to publish; merge and tag to trigger publishing', repoTag);
print(result);
results.addResult(result);
}
Expand Down Expand Up @@ -248,12 +254,15 @@ class VerificationResults {

bool get hasSuccess => results.any((r) => r.severity == Severity.success);

String get describe {
bool get hasError => results.any((r) => r.severity == Severity.error);

String get describeAsMarkdown {
results.sort((a, b) => Enum.compareByIndex(a.severity, b.severity));

return results.map((r) {
var sev = r.severity == Severity.error ? '(error) ' : '';
return '- package:${r.package.name}: $sev${r.message}';
return '| package:${r.package.name} | ${r.package.version} | '
'$sev${r.message} | ${r.other ?? ''} |';
}).join('\n');
}
}
Expand All @@ -262,20 +271,21 @@ class Result {
final Severity severity;
final Package package;
final String message;
final String? other;

Result(this.severity, this.package, this.message);
Result(this.severity, this.package, this.message, [this.other]);

factory Result.fail(Package package, String message) =>
Result(Severity.error, package, message);

factory Result.info(Package package, String message) =>
Result(Severity.info, package, message);

factory Result.success(Package package, String message) =>
Result(Severity.success, package, message);
factory Result.success(Package package, String message, [String? other]) =>
Result(Severity.success, package, message, other);

@override
String toString() => message;
String toString() => severity == Severity.error ? 'error: $message' : message;
}

enum Severity {
Expand Down
2 changes: 2 additions & 0 deletions pkgs/firehose/lib/src/repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class Package {

String get name => pubspec.name;

String? get version => pubspec.version;

@override
String toString() {
return 'package:${pubspec.name} ${pubspec.version} (dir=${directory.path})';
Expand Down
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.3.8
version: 0.3.9
repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose

environment:
Expand Down

0 comments on commit 524bd80

Please sign in to comment.