From c3aef952826115b8e07fd3929df1d7813952c0c1 Mon Sep 17 00:00:00 2001 From: Rob Becker Date: Wed, 20 Oct 2021 21:47:52 -0600 Subject: [PATCH 1/2] Add auto-release notes --- lib/src/common/model/repos_releases.dart | 58 ++++++++++++++++++---- lib/src/common/model/repos_releases.g.dart | 37 +++++++++++++- lib/src/common/repos_service.dart | 16 ++++++ lib/src/server/hooks.dart | 3 +- test/server/hooks_test.dart | 7 +-- 5 files changed, 106 insertions(+), 15 deletions(-) diff --git a/lib/src/common/model/repos_releases.dart b/lib/src/common/model/repos_releases.dart index 3259ff1e..4656dd1c 100644 --- a/lib/src/common/model/repos_releases.dart +++ b/lib/src/common/model/repos_releases.dart @@ -173,16 +173,21 @@ class CreateRelease { @JsonKey(name: 'prerelease') bool? isPrerelease; + String? discussionCategoryName; + + bool generateReleaseNotes = false; + CreateRelease(this.tagName); - CreateRelease.from({ - required this.tagName, - required this.name, - required this.targetCommitish, - required this.isDraft, - required this.isPrerelease, - this.body, - }); + CreateRelease.from( + {required this.tagName, + required this.name, + required this.targetCommitish, + required this.isDraft, + required this.isPrerelease, + this.body, + this.discussionCategoryName, + this.generateReleaseNotes = false}); @override bool operator ==(Object other) => @@ -194,7 +199,9 @@ class CreateRelease { name == other.name && body == other.body && isDraft == other.isDraft && - isPrerelease == other.isPrerelease; + isPrerelease == other.isPrerelease && + generateReleaseNotes == other.generateReleaseNotes && + discussionCategoryName == other.discussionCategoryName; @override int get hashCode => @@ -203,7 +210,9 @@ class CreateRelease { name.hashCode ^ body.hashCode ^ isDraft.hashCode ^ - isPrerelease.hashCode; + isPrerelease.hashCode ^ + discussionCategoryName.hashCode ^ + generateReleaseNotes.hashCode; factory CreateRelease.fromJson(Map input) => _$CreateReleaseFromJson(input); @@ -236,3 +245,32 @@ class CreateReleaseAsset { /// GitHub expects the asset data in its raw binary form, rather than JSON. Uint8List assetData; } + +/// Holds release notes information +@JsonSerializable() +class ReleaseNotes { + ReleaseNotes(this.name, this.body); + String name; + String body; + + factory ReleaseNotes.fromJson(Map input) => + _$ReleaseNotesFromJson(input); + Map toJson() => _$ReleaseNotesToJson(this); +} + +@JsonSerializable() +class CreateReleaseNotes { + CreateReleaseNotes(this.owner, this.repo, this.tagName, + {this.targetCommitish, this.previousTagName, this.configurationFilePath}); + + String owner; + String repo; + String tagName; + String? targetCommitish; + String? previousTagName; + String? configurationFilePath; + + factory CreateReleaseNotes.fromJson(Map input) => + _$CreateReleaseNotesFromJson(input); + Map toJson() => _$CreateReleaseNotesToJson(this); +} diff --git a/lib/src/common/model/repos_releases.g.dart b/lib/src/common/model/repos_releases.g.dart index faf4db03..bcaec1ee 100644 --- a/lib/src/common/model/repos_releases.g.dart +++ b/lib/src/common/model/repos_releases.g.dart @@ -99,7 +99,9 @@ CreateRelease _$CreateReleaseFromJson(Map json) => ..name = json['name'] as String? ..body = json['body'] as String? ..isDraft = json['draft'] as bool? - ..isPrerelease = json['prerelease'] as bool?; + ..isPrerelease = json['prerelease'] as bool? + ..discussionCategoryName = json['discussion_category_name'] as String? + ..generateReleaseNotes = json['generate_release_notes'] as bool; Map _$CreateReleaseToJson(CreateRelease instance) => { @@ -109,4 +111,37 @@ Map _$CreateReleaseToJson(CreateRelease instance) => 'body': instance.body, 'draft': instance.isDraft, 'prerelease': instance.isPrerelease, + 'discussion_category_name': instance.discussionCategoryName, + 'generate_release_notes': instance.generateReleaseNotes, + }; + +ReleaseNotes _$ReleaseNotesFromJson(Map json) => ReleaseNotes( + json['name'] as String, + json['body'] as String, + ); + +Map _$ReleaseNotesToJson(ReleaseNotes instance) => + { + 'name': instance.name, + 'body': instance.body, + }; + +CreateReleaseNotes _$CreateReleaseNotesFromJson(Map json) => + CreateReleaseNotes( + json['owner'] as String, + json['repo'] as String, + json['tag_name'] as String, + targetCommitish: json['target_commitish'] as String?, + previousTagName: json['previous_tag_name'] as String?, + configurationFilePath: json['configuration_file_path'] as String?, + ); + +Map _$CreateReleaseNotesToJson(CreateReleaseNotes instance) => + { + 'owner': instance.owner, + 'repo': instance.repo, + 'tag_name': instance.tagName, + 'target_commitish': instance.targetCommitish, + 'previous_tag_name': instance.previousTagName, + 'configuration_file_path': instance.configurationFilePath, }; diff --git a/lib/src/common/repos_service.dart b/lib/src/common/repos_service.dart index 9e9c0717..16e573f8 100644 --- a/lib/src/common/repos_service.dart +++ b/lib/src/common/repos_service.dart @@ -1276,4 +1276,20 @@ class RepositoriesService extends Service { statusCode: StatusCodes.OK, ); } + + /// Generate a name and body describing a release. The body content will be + /// markdown formatted and contain information like the changes since last + /// release and users who contributed. The generated release notes are not + /// saved anywhere. They are intended to be generated and used when + /// creating a new release. + /// + /// API docs: https://docs.github.com/en/rest/reference/repos#generate-release-notes-content-for-a-release + Future generateReleaseNotes(CreateReleaseNotes crn) async { + return github.postJSON, ReleaseNotes>( + '/repos/${crn.owner}/${crn.repo}/releases/generate-notes', + body: GitHubJson.encode(crn), + statusCode: StatusCodes.OK, + convert: (i) => ReleaseNotes.fromJson(i), + ); + } } diff --git a/lib/src/server/hooks.dart b/lib/src/server/hooks.dart index 4d69d8f5..8c8ac396 100644 --- a/lib/src/server/hooks.dart +++ b/lib/src/server/hooks.dart @@ -98,7 +98,8 @@ class CheckRunEvent extends HookEvent { this.repository, }); - factory CheckRunEvent.fromJson(Map input) => _$CheckRunEventFromJson(input); + factory CheckRunEvent.fromJson(Map input) => + _$CheckRunEventFromJson(input); CheckRun? checkRun; String? action; User? sender; diff --git a/test/server/hooks_test.dart b/test/server/hooks_test.dart index d1b9f5ee..b9d87e65 100644 --- a/test/server/hooks_test.dart +++ b/test/server/hooks_test.dart @@ -8,8 +8,8 @@ import 'hooks_test_data.dart'; void main() { group('CheckSuiteEvent', () { test('deserialize', () async { - final checkSuiteEvent = - CheckSuiteEvent.fromJson(json.decode(checkSuiteString) as Map); + final checkSuiteEvent = CheckSuiteEvent.fromJson( + json.decode(checkSuiteString) as Map); // Top level properties. expect(checkSuiteEvent.action, 'requested'); expect(checkSuiteEvent.checkSuite, isA()); @@ -22,7 +22,8 @@ void main() { }); group('CheckRunEvent', () { test('deserialize', () async { - final checkRunEvent = CheckRunEvent.fromJson(json.decode(checkRunString) as Map); + final checkRunEvent = CheckRunEvent.fromJson( + json.decode(checkRunString) as Map); // Top level properties. expect(checkRunEvent.action, 'created'); expect(checkRunEvent.checkRun, isA()); From 2eecc00d1c07cc9fcdd68eea8c55430bd8b94e1b Mon Sep 17 00:00:00 2001 From: Rob Becker Date: Wed, 20 Oct 2021 21:53:09 -0600 Subject: [PATCH 2/2] prep 8.2.3 --- CHANGELOG.md | 4 ++++ pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index afa44789..8ce2f14f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 8.2.3 +- Added `generateReleaseNotes` boolean to CreateRelase class to have github auto-create release notes +- Added `generateReleaseNotes` method to RepositoriesService to have github create release notes + between to tags (without creating a release) and return the name and body. This is helpful when you want to add the release notes to a CHANGELOG.md before making the actual release ## 8.2.2 - Up minimum json_serializable to ^6.0.0, json_annotation to ^4.3.0 - Cleanup and regenerate generated files diff --git a/pubspec.yaml b/pubspec.yaml index ab59f896..cad01e51 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: github -version: 8.2.2 +version: 8.2.3 description: A high-level GitHub API Client Library that uses Github's v3 API homepage: https://github.com/SpinlockLabs/github.dart