Skip to content

Commit

Permalink
Merge pull request #271 from SpinlockLabs/auto_release_notes
Browse files Browse the repository at this point in the history
Add: Auto release notes & generateReleaseNotes API
  • Loading branch information
robrbecker authored Oct 21, 2021
2 parents aff1ace + 2eecc00 commit 5aa76d2
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
58 changes: 48 additions & 10 deletions lib/src/common/model/repos_releases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -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 =>
Expand All @@ -203,7 +210,9 @@ class CreateRelease {
name.hashCode ^
body.hashCode ^
isDraft.hashCode ^
isPrerelease.hashCode;
isPrerelease.hashCode ^
discussionCategoryName.hashCode ^
generateReleaseNotes.hashCode;

factory CreateRelease.fromJson(Map<String, dynamic> input) =>
_$CreateReleaseFromJson(input);
Expand Down Expand Up @@ -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<String, dynamic> input) =>
_$ReleaseNotesFromJson(input);
Map<String, dynamic> 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<String, dynamic> input) =>
_$CreateReleaseNotesFromJson(input);
Map<String, dynamic> toJson() => _$CreateReleaseNotesToJson(this);
}
37 changes: 36 additions & 1 deletion lib/src/common/model/repos_releases.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions lib/src/common/repos_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReleaseNotes> generateReleaseNotes(CreateReleaseNotes crn) async {
return github.postJSON<Map<String, dynamic>, ReleaseNotes>(
'/repos/${crn.owner}/${crn.repo}/releases/generate-notes',
body: GitHubJson.encode(crn),
statusCode: StatusCodes.OK,
convert: (i) => ReleaseNotes.fromJson(i),
);
}
}
3 changes: 2 additions & 1 deletion lib/src/server/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ class CheckRunEvent extends HookEvent {
this.repository,
});

factory CheckRunEvent.fromJson(Map<String, dynamic> input) => _$CheckRunEventFromJson(input);
factory CheckRunEvent.fromJson(Map<String, dynamic> input) =>
_$CheckRunEventFromJson(input);
CheckRun? checkRun;
String? action;
User? sender;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
7 changes: 4 additions & 3 deletions test/server/hooks_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, dynamic>);
final checkSuiteEvent = CheckSuiteEvent.fromJson(
json.decode(checkSuiteString) as Map<String, dynamic>);
// Top level properties.
expect(checkSuiteEvent.action, 'requested');
expect(checkSuiteEvent.checkSuite, isA<CheckSuite>());
Expand All @@ -22,7 +22,8 @@ void main() {
});
group('CheckRunEvent', () {
test('deserialize', () async {
final checkRunEvent = CheckRunEvent.fromJson(json.decode(checkRunString) as Map<String, dynamic>);
final checkRunEvent = CheckRunEvent.fromJson(
json.decode(checkRunString) as Map<String, dynamic>);
// Top level properties.
expect(checkRunEvent.action, 'created');
expect(checkRunEvent.checkRun, isA<CheckRun>());
Expand Down

0 comments on commit 5aa76d2

Please sign in to comment.