Skip to content

Commit fc3dd9a

Browse files
authored
fix(firehose): update existing publishing PR comments when no packages are ready to publish (#449)
## Rationale When a PR initially has a publishable version (e.g. `4.0.1-dev`) and firehose posts the `Package publishing` comment, but subsequently updates the package to a `-wip` version (e.g. `4.0.1-wip`), `VerificationResults.hasSuccess` becomes `false`. Previously: - In `lib/firehose.dart`, saving `existingCommentId` to `./output/commentId` and generating `./output/comment.md` was guarded strictly by `if (results.hasSuccess)`. When `hasSuccess` was `false`, neither file was written. - As a result, the existing `Package publishing` comment with outdated `ready to publish` status and release links was never updated and remained on the PR indefinitely. ## Changes - **`lib/firehose.dart`**: Save `existingCommentId` to `./output/commentId` unconditionally whenever an existing publishing comment is found. When `results.hasSuccess || existingCommentId != null`, write `./output/comment.md` with the updated `$markdownTable` (omitting the `"If you have publishing permissions..."` description when no packages are ready to publish). - **`lib/src/github.dart`** & **`lib/src/local_github_api.dart`**: Add `deleteComment` helper to `GithubApi`. - **`bin/comment.dart`**: Add `delete` subcommand (`firehose:comment delete --comment-id <id>`). - **`test/firehose_test.dart`**: Add CLI argument validation and exit code tests for `comment delete`. - **`CHANGELOG.md`**: Note that existing publishing PR comments are updated with accurate status when packages are no longer ready to publish.
1 parent e0a78b4 commit fc3dd9a

6 files changed

Lines changed: 74 additions & 14 deletions

File tree

‎pkgs/firehose/CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
- Update `dependency_validator` pinned commit hash to 5.0.6 (`7582a808960d2170800bfbd7a83526619ce300ce`),
44
enabling support for newer Dart syntax (up to analyzer 13).
5+
- Update existing publishing PR comments with accurate status when packages are
6+
no longer ready to publish (e.g. when updated to `-wip`).
7+
- Add `delete` command to `firehose:comment` executable.
58
- Condense PR package publishing table to show only packages affected by the PR,
69
packages ready to publish, and errors, summarizing unaffected WIP and published
710
packages.

‎pkgs/firehose/bin/comment.dart‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Future<void> main(List<String> arguments) async {
3636
await _findComment(command);
3737
} else if (command.name == 'create-or-update') {
3838
await _createOrUpdateComment(command);
39+
} else if (command.name == 'delete') {
40+
await _deleteComment(command);
3941
}
4042
}
4143

@@ -54,6 +56,10 @@ ArgParser _createArgParser() {
5456
..addOption('body', help: 'Comment body text')
5557
..addOption('body-path', help: 'Path to file containing comment body');
5658

59+
parser
60+
.addCommand('delete')
61+
.addOption('comment-id', help: 'Existing comment ID to delete');
62+
5763
return parser;
5864
}
5965

@@ -143,3 +149,25 @@ Future<void> _createOrUpdateComment(ArgResults results) async {
143149
github.close();
144150
}
145151
}
152+
153+
Future<void> _deleteComment(ArgResults results) async {
154+
final commentId = results.option('comment-id');
155+
if (commentId == null || commentId == '0' || commentId.isEmpty) {
156+
stderr.writeln('Invalid comment ID: $commentId');
157+
exitCode = 64;
158+
return;
159+
}
160+
final id = int.tryParse(commentId);
161+
if (id == null) {
162+
stderr.writeln('Invalid comment ID: $commentId');
163+
exitCode = 64;
164+
return;
165+
}
166+
final github = GithubApi();
167+
try {
168+
await github.deleteComment(id);
169+
print('Deleted comment $id');
170+
} finally {
171+
github.close();
172+
}
173+
}

‎pkgs/firehose/lib/firehose.dart‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,27 +80,29 @@ Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automati
8080
logError: print,
8181
);
8282

83-
if (results.hasSuccess) {
83+
if (existingCommentId != null) {
84+
final idFile = File('./output/commentId');
85+
print('''
86+
Saving existing comment id $existingCommentId to file ${idFile.path}''');
87+
await idFile.create(recursive: true);
88+
await idFile.writeAsString(existingCommentId.toString());
89+
}
90+
91+
if (results.hasSuccess || existingCommentId != null) {
92+
final description =
93+
results.hasSuccess ? '$_publishBotDescription\n\n' : '';
8494
final commentText = '$_publishBotTag\n\n'
85-
'$_publishBotDescription\n\n'
95+
'$description'
8696
'$markdownTable';
8797

88-
if (existingCommentId != null) {
89-
final idFile = File('./output/commentId');
90-
print('''
91-
Saving existing comment id $existingCommentId to file ${idFile.path}''');
92-
await idFile.create(recursive: true);
93-
await idFile.writeAsString(existingCommentId.toString());
94-
}
95-
9698
final commentFile = File('./output/comment.md');
9799
print('Saving comment markdown to file ${commentFile.path}');
98100
await commentFile.create(recursive: true);
99101
await commentFile.writeAsString(commentText);
100-
} else {
101-
if (results.hasError && exitCode == 0) {
102-
exitCode = 1;
103-
}
102+
}
103+
104+
if (results.hasError && exitCode == 0) {
105+
exitCode = 1;
104106
}
105107

106108
github.close();

‎pkgs/firehose/lib/src/github.dart‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ class GithubApi {
132132
await _github.issues.updateComment(_slug, commentId, body);
133133
}
134134

135+
Future<bool> deleteComment(int commentId) =>
136+
_github.issues.deleteComment(_slug, commentId);
137+
135138
Future<List<GitFile>> listFilesForPR(
136139
Directory directory, [
137140
List<Glob> ignoredFiles = const [],

‎pkgs/firehose/lib/src/local_github_api.dart‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class LocalGithubApi implements GithubApi {
4444
throw UnimplementedError();
4545
}
4646

47+
@override
48+
Future<bool> deleteComment(int commentId) => throw UnimplementedError();
49+
4750
@override
4851
String? get githubAuthToken => throw UnimplementedError();
4952

‎pkgs/firehose/test/firehose_test.dart‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,25 @@ void main() {
140140
);
141141
});
142142
});
143+
144+
group('bin/comment.dart CLI', () {
145+
test('delete command exits with code 64 on missing or empty comment ID',
146+
() async {
147+
final result = await Process.run(
148+
Platform.resolvedExecutable,
149+
['bin/comment.dart', 'delete', '--comment-id', '0'],
150+
);
151+
expect(result.exitCode, 64);
152+
expect(result.stderr, contains('Invalid comment ID'));
153+
});
154+
155+
test('delete command fails when required option is omitted', () async {
156+
final result = await Process.run(
157+
Platform.resolvedExecutable,
158+
['bin/comment.dart', 'delete'],
159+
);
160+
expect(result.exitCode, 64);
161+
expect(result.stderr, contains('Invalid comment ID'));
162+
});
163+
});
143164
}

0 commit comments

Comments
 (0)