Skip to content

Commit 5aa76d2

Browse files
authored
Merge pull request SpinlockLabs#271 from SpinlockLabs/auto_release_notes
Add: Auto release notes & generateReleaseNotes API
2 parents aff1ace + 2eecc00 commit 5aa76d2

File tree

7 files changed

+111
-16
lines changed

7 files changed

+111
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 8.2.3
2+
- Added `generateReleaseNotes` boolean to CreateRelase class to have github auto-create release notes
3+
- Added `generateReleaseNotes` method to RepositoriesService to have github create release notes
4+
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
15
## 8.2.2
26
- Up minimum json_serializable to ^6.0.0, json_annotation to ^4.3.0
37
- Cleanup and regenerate generated files

lib/src/common/model/repos_releases.dart

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,21 @@ class CreateRelease {
173173
@JsonKey(name: 'prerelease')
174174
bool? isPrerelease;
175175

176+
String? discussionCategoryName;
177+
178+
bool generateReleaseNotes = false;
179+
176180
CreateRelease(this.tagName);
177181

178-
CreateRelease.from({
179-
required this.tagName,
180-
required this.name,
181-
required this.targetCommitish,
182-
required this.isDraft,
183-
required this.isPrerelease,
184-
this.body,
185-
});
182+
CreateRelease.from(
183+
{required this.tagName,
184+
required this.name,
185+
required this.targetCommitish,
186+
required this.isDraft,
187+
required this.isPrerelease,
188+
this.body,
189+
this.discussionCategoryName,
190+
this.generateReleaseNotes = false});
186191

187192
@override
188193
bool operator ==(Object other) =>
@@ -194,7 +199,9 @@ class CreateRelease {
194199
name == other.name &&
195200
body == other.body &&
196201
isDraft == other.isDraft &&
197-
isPrerelease == other.isPrerelease;
202+
isPrerelease == other.isPrerelease &&
203+
generateReleaseNotes == other.generateReleaseNotes &&
204+
discussionCategoryName == other.discussionCategoryName;
198205

199206
@override
200207
int get hashCode =>
@@ -203,7 +210,9 @@ class CreateRelease {
203210
name.hashCode ^
204211
body.hashCode ^
205212
isDraft.hashCode ^
206-
isPrerelease.hashCode;
213+
isPrerelease.hashCode ^
214+
discussionCategoryName.hashCode ^
215+
generateReleaseNotes.hashCode;
207216

208217
factory CreateRelease.fromJson(Map<String, dynamic> input) =>
209218
_$CreateReleaseFromJson(input);
@@ -236,3 +245,32 @@ class CreateReleaseAsset {
236245
/// GitHub expects the asset data in its raw binary form, rather than JSON.
237246
Uint8List assetData;
238247
}
248+
249+
/// Holds release notes information
250+
@JsonSerializable()
251+
class ReleaseNotes {
252+
ReleaseNotes(this.name, this.body);
253+
String name;
254+
String body;
255+
256+
factory ReleaseNotes.fromJson(Map<String, dynamic> input) =>
257+
_$ReleaseNotesFromJson(input);
258+
Map<String, dynamic> toJson() => _$ReleaseNotesToJson(this);
259+
}
260+
261+
@JsonSerializable()
262+
class CreateReleaseNotes {
263+
CreateReleaseNotes(this.owner, this.repo, this.tagName,
264+
{this.targetCommitish, this.previousTagName, this.configurationFilePath});
265+
266+
String owner;
267+
String repo;
268+
String tagName;
269+
String? targetCommitish;
270+
String? previousTagName;
271+
String? configurationFilePath;
272+
273+
factory CreateReleaseNotes.fromJson(Map<String, dynamic> input) =>
274+
_$CreateReleaseNotesFromJson(input);
275+
Map<String, dynamic> toJson() => _$CreateReleaseNotesToJson(this);
276+
}

lib/src/common/model/repos_releases.g.dart

Lines changed: 36 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/common/repos_service.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,4 +1276,20 @@ class RepositoriesService extends Service {
12761276
statusCode: StatusCodes.OK,
12771277
);
12781278
}
1279+
1280+
/// Generate a name and body describing a release. The body content will be
1281+
/// markdown formatted and contain information like the changes since last
1282+
/// release and users who contributed. The generated release notes are not
1283+
/// saved anywhere. They are intended to be generated and used when
1284+
/// creating a new release.
1285+
///
1286+
/// API docs: https://docs.github.com/en/rest/reference/repos#generate-release-notes-content-for-a-release
1287+
Future<ReleaseNotes> generateReleaseNotes(CreateReleaseNotes crn) async {
1288+
return github.postJSON<Map<String, dynamic>, ReleaseNotes>(
1289+
'/repos/${crn.owner}/${crn.repo}/releases/generate-notes',
1290+
body: GitHubJson.encode(crn),
1291+
statusCode: StatusCodes.OK,
1292+
convert: (i) => ReleaseNotes.fromJson(i),
1293+
);
1294+
}
12791295
}

lib/src/server/hooks.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ class CheckRunEvent extends HookEvent {
9898
this.repository,
9999
});
100100

101-
factory CheckRunEvent.fromJson(Map<String, dynamic> input) => _$CheckRunEventFromJson(input);
101+
factory CheckRunEvent.fromJson(Map<String, dynamic> input) =>
102+
_$CheckRunEventFromJson(input);
102103
CheckRun? checkRun;
103104
String? action;
104105
User? sender;

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: github
2-
version: 8.2.2
2+
version: 8.2.3
33
description: A high-level GitHub API Client Library that uses Github's v3 API
44
homepage: https://github.com/SpinlockLabs/github.dart
55

test/server/hooks_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import 'hooks_test_data.dart';
88
void main() {
99
group('CheckSuiteEvent', () {
1010
test('deserialize', () async {
11-
final checkSuiteEvent =
12-
CheckSuiteEvent.fromJson(json.decode(checkSuiteString) as Map<String, dynamic>);
11+
final checkSuiteEvent = CheckSuiteEvent.fromJson(
12+
json.decode(checkSuiteString) as Map<String, dynamic>);
1313
// Top level properties.
1414
expect(checkSuiteEvent.action, 'requested');
1515
expect(checkSuiteEvent.checkSuite, isA<CheckSuite>());
@@ -22,7 +22,8 @@ void main() {
2222
});
2323
group('CheckRunEvent', () {
2424
test('deserialize', () async {
25-
final checkRunEvent = CheckRunEvent.fromJson(json.decode(checkRunString) as Map<String, dynamic>);
25+
final checkRunEvent = CheckRunEvent.fromJson(
26+
json.decode(checkRunString) as Map<String, dynamic>);
2627
// Top level properties.
2728
expect(checkRunEvent.action, 'created');
2829
expect(checkRunEvent.checkRun, isA<CheckRun>());

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy