Skip to content

Commit

Permalink
make publish tags link to the release page with populated fields (#98)
Browse files Browse the repository at this point in the history
V1 of #97

Updates the markdown table so that "publish tag" tags are links to a release page with all the information pre-populated.
  • Loading branch information
jakemac53 authored May 9, 2023
1 parent 57b9202 commit 3163b3b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
7 changes: 6 additions & 1 deletion pkgs/firehose/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.3.15

- Make publish tags link to the new release page for that tag, with
pre-populated fields.

## 0.3.14

- Require Dart `2.19.0`.
Expand All @@ -20,7 +25,7 @@

## 0.3.11

- Add additional console logging when we encounter GitHub API errors.
- Add additional console logging when we encounter GitHub API errors.

## 0.3.10

Expand Down
19 changes: 13 additions & 6 deletions pkgs/firehose/lib/firehose.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Firehose {
var results = await _validate(github);

var markdownTable = '''
| Package | Version | Status | Publish tag |
| Package | Version | Status | Publish tag (post-merge) |
| :--- | ---: | :--- | ---: |
${results.describeAsMarkdown}
Expand Down Expand Up @@ -166,8 +166,8 @@ Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automati
github.notice(message: message);
results.addResult(Result.fail(package, message));
} else {
var result = Result.success(package,
'**ready to publish** (merge and tag to publish)', repoTag);
var result = Result.success(package, '**ready to publish**', repoTag,
repo.calculateReleaseUri(package, github));
print(result);
results.addResult(result);
}
Expand Down Expand Up @@ -299,6 +299,10 @@ class VerificationResults {
return results.map((r) {
var sev = r.severity == Severity.error ? '(error) ' : '';
var tag = r.gitTag == null ? '' : '`${r.gitTag}`';
var publishReleaseUri = r.publishReleaseUri;
if (publishReleaseUri != null) {
tag = '[$tag]($publishReleaseUri)';
}

return '| package:${r.package.name} | ${r.package.version} | '
'$sev${r.message} | $tag |';
Expand All @@ -311,17 +315,20 @@ class Result {
final Package package;
final String message;
final String? gitTag;
final Uri? publishReleaseUri;

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

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, [String? gitTag]) =>
Result(Severity.success, package, message, gitTag);
factory Result.success(Package package, String message,
[String? gitTag, Uri? publishReleaseUri]) =>
Result(Severity.success, package, message, gitTag, publishReleaseUri);

@override
String toString() {
Expand Down
9 changes: 9 additions & 0 deletions pkgs/firehose/lib/src/repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:firehose/src/changelog.dart';
import 'package:path/path.dart' as path;
import 'package:yaml/yaml.dart' as yaml;

import 'github.dart';
import 'pubspec.dart';

class Repository {
Expand Down Expand Up @@ -65,6 +66,14 @@ class Repository {
return '${package.name}-v${package.pubspec.version}';
}
}

Uri calculateReleaseUri(Package package, Github github) {
final tag = calculateRepoTag(package);
final title = 'package:${package.name} v${package.pubspec.version}';
final body = package.changelog.describeLatestChanges;
return Uri.https('github.com', '/${github.repoSlug}/releases/new',
{'tag': tag, 'title': title, 'body': body});
}
}

class Package {
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.14
version: 0.3.15
repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose

environment:
Expand Down
13 changes: 13 additions & 0 deletions pkgs/firehose/test/repo_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:firehose/src/github.dart';
import 'package:firehose/src/repo.dart';
import 'package:test/test.dart';

Expand All @@ -22,5 +23,17 @@ void main() {
var result = packages.locatePackages();
expect(result, isNotEmpty);
});

test('github release link', () {
final github = Github();
final package = packages.locatePackages().single;
final releaseUri = packages.calculateReleaseUri(package, github);
expect(releaseUri.path, '/${github.repoSlug}/releases/new');
final queryParams = releaseUri.queryParameters;
expect(queryParams['tag'], packages.calculateRepoTag(package));
expect(queryParams['title'],
allOf(contains(package.name), contains(package.version)));
expect(queryParams['body'], package.changelog.describeLatestChanges);
});
});
}

0 comments on commit 3163b3b

Please sign in to comment.