Skip to content

Commit

Permalink
add additional console logging (#59)
Browse files Browse the repository at this point in the history
* add additional console logging

* also print headers
  • Loading branch information
devoncarew authored Feb 7, 2023
1 parent e4c8c74 commit a8a5370
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 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.11

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

## 0.3.10

- Fixed an exception that occurred when no CHANGELOG.md file was present.
Expand Down
9 changes: 7 additions & 2 deletions pkgs/firehose/lib/firehose.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Firehose {
/// - provide feedback on the PR (via a PR comment) about packages which are
/// ready to publish
Future<void> validate() async {
var github = Github();
var github = Github(verbose: true);

// Do basic validation of our expected env var.
if (!_expectEnv(github.githubAuthToken, 'GITHUB_TOKEN')) return;
Expand Down Expand Up @@ -285,7 +285,12 @@ class Result {
Result(Severity.success, package, message, other);

@override
String toString() => severity == Severity.error ? 'error: $message' : message;
String toString() {
final details = other == null ? '' : ' ($other)';
return severity == Severity.error
? 'error: $message$details'
: '$message$details';
}
}

enum Severity {
Expand Down
19 changes: 16 additions & 3 deletions pkgs/firehose/lib/src/github.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import 'package:http/http.dart' as http;
class Github {
static Map<String, String> get _env => Platform.environment;

/// When true, details of any RPC error are printed to the console.
final bool verbose;

http.Client? _httpClient;

Github({this.verbose = false});

String? get githubAuthToken => _env['GITHUB_TOKEN'];

/// The owner and repository name. For example, `octocat/Hello-World`.
Expand Down Expand Up @@ -62,9 +67,17 @@ class Github {
},
body: body)
.then((response) {
return response.statusCode != 201
? throw RpcException(response.reasonPhrase!)
: response.body;
if (response.statusCode != 201) {
if (verbose) {
stderr.writeln('${response.statusCode} ${response.reasonPhrase}');
for (var entry in response.headers.entries) {
stderr.writeln('${entry.key}: ${entry.value}');
}
stderr.writeln(response.body);
}
throw RpcException(response.reasonPhrase!);
}
return response.body;
});
}

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.10
version: 0.3.11
repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose

environment:
Expand Down

0 comments on commit a8a5370

Please sign in to comment.