Skip to content

Commit

Permalink
Add auto-release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
robbecker-wf committed Oct 21, 2021
1 parent aff1ace commit c3aef95
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 15 deletions.
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
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 c3aef95

Please sign in to comment.