Skip to content

Commit 5aa3cc7

Browse files
nerradgithub-actions
and
github-actions
authored
Include changelog entry from pr body if it's present. (#33)
* add support for grabbing changelog entry from pr body if special format is present * update tests to include changelog entry generated from pr body * generating changeset for pull request * generating changeset for pull request Co-authored-by: github-actions <[email protected]>
1 parent 759a77e commit 5aa3cc7

File tree

4 files changed

+151
-4
lines changed

4 files changed

+151
-4
lines changed

lib/automations/release/test/__snapshots__/branch-create-handler.js.snap

+3-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Array [
124124
]
125125
`;
126126
127-
exports[`branch-create-handler for release pull request generation creates a pull request 1`] = `
127+
exports[`branch-create-handler for release pull request generation creates a pull request with changelog 1`] = `
128128
Array [
129129
Object {
130130
"base": "trunk",
@@ -146,6 +146,7 @@ This release introduces:
146146
#### Various
147147
148148
- Found a bug. ([1347](https://github.com/octocat/Hello-World/issues/1347))
149+
- Fixed an item and this should be the changelog entry. ([1348](https://github.com/octocat/Hello-World/issues/1348))
149150
150151
151152
@@ -227,7 +228,7 @@ _Link to any special instructions or helpful notes for HE related to this releas
227228
]
228229
`;
229230
230-
exports[`branch-create-handler for release pull request generation creates a pull request 2`] = `
231+
exports[`branch-create-handler for release pull request generation creates a pull request with changelog 2`] = `
231232
Array [
232233
Object {
233234
"body": "The release pull request has been created! This checklist is a guide to follow for the remainder of the release process. You can check off each item in this list once completed.

lib/automations/release/test/branch-create-handler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe( 'branch-create-handler for release pull request generation', () => {
1313
config = gimmeConfig( 'release' );
1414
app = gimmeApp( 'release' );
1515
} );
16-
it( 'creates a pull request', async () => {
16+
it( 'creates a pull request with changelog', async () => {
1717
await app( context, octokit, config );
1818
expect( octokit.search.issuesAndPullRequests ).toHaveBeenCalled();
1919
expect( octokit.repos.getContents ).toHaveBeenCalled();

lib/utils/changelog/common/changelog.js

+10
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,16 @@ const TITLE_NORMALIZATIONS = ( config ) => [
318318
function getNormalizedTitle( title, issue, config ) {
319319
/** @type {string|undefined} */
320320
let normalizedTitle = title;
321+
if ( /### Changelog\r\n\r\n> /.test( issue.body ) ) {
322+
const bodyParts = issue.body.split( '### Changelog\r\n\r\n> ' );
323+
const note = bodyParts[ bodyParts.length - 1 ];
324+
normalizedTitle = note
325+
// Remove comment prompt
326+
.replace( /<!---(.*)--->/gm, '' )
327+
// Remove new lines and whitespace
328+
.trim();
329+
normalizedTitle = ! normalizedTitle.length ? title : normalizedTitle;
330+
}
321331
for ( const normalize of TITLE_NORMALIZATIONS( config ) ) {
322332
normalizedTitle = normalize( normalizedTitle, issue );
323333
if ( normalizedTitle === undefined ) {

tests/fixtures/payloads/issues-list.json

+137-1
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,141 @@
134134
"closed_at": null,
135135
"created_at": "2011-04-22T13:33:48Z",
136136
"updated_at": "2011-04-22T13:33:48Z"
137-
}
137+
},
138+
{
139+
"id": 2,
140+
"node_id": "MDU6SXNzdWUx",
141+
"url": "https://api.github.com/repos/octocat/Hello-World/issues/1348",
142+
"repository_url": "https://api.github.com/repos/octocat/Hello-World",
143+
"labels_url": "https://api.github.com/repos/octocat/Hello-World/issues/1348/labels{/name}",
144+
"comments_url": "https://api.github.com/repos/octocat/Hello-World/issues/1348/comments",
145+
"events_url": "https://api.github.com/repos/octocat/Hello-World/issues/1348/events",
146+
"html_url": "https://github.com/octocat/Hello-World/issues/1348",
147+
"number": 1348,
148+
"state": "closed",
149+
"title": "This title shouldn't be in the changelog",
150+
"body": "Some thing.\n\n### Changelog\r\n\r\n> Fixed an item and this should be the changelog entry.",
151+
"user": {
152+
"login": "octocat",
153+
"id": 1,
154+
"node_id": "MDQ6VXNlcjE=",
155+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
156+
"gravatar_id": "",
157+
"url": "https://api.github.com/users/octocat",
158+
"html_url": "https://github.com/octocat",
159+
"followers_url": "https://api.github.com/users/octocat/followers",
160+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
161+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
162+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
163+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
164+
"organizations_url": "https://api.github.com/users/octocat/orgs",
165+
"repos_url": "https://api.github.com/users/octocat/repos",
166+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
167+
"received_events_url": "https://api.github.com/users/octocat/received_events",
168+
"type": "User",
169+
"site_admin": false
170+
},
171+
"labels": [
172+
{
173+
"id": 208045946,
174+
"node_id": "MDU6TGFiZWwyMDgwNDU5NDY=",
175+
"url": "https://api.github.com/repos/octocat/Hello-World/labels/bug",
176+
"name": "bug",
177+
"description": "Something isn't working",
178+
"color": "f29513",
179+
"default": true
180+
}
181+
],
182+
"assignee": {
183+
"login": "octocat",
184+
"id": 1,
185+
"node_id": "MDQ6VXNlcjE=",
186+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
187+
"gravatar_id": "",
188+
"url": "https://api.github.com/users/octocat",
189+
"html_url": "https://github.com/octocat",
190+
"followers_url": "https://api.github.com/users/octocat/followers",
191+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
192+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
193+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
194+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
195+
"organizations_url": "https://api.github.com/users/octocat/orgs",
196+
"repos_url": "https://api.github.com/users/octocat/repos",
197+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
198+
"received_events_url": "https://api.github.com/users/octocat/received_events",
199+
"type": "User",
200+
"site_admin": false
201+
},
202+
"assignees": [
203+
{
204+
"login": "octocat",
205+
"id": 1,
206+
"node_id": "MDQ6VXNlcjE=",
207+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
208+
"gravatar_id": "",
209+
"url": "https://api.github.com/users/octocat",
210+
"html_url": "https://github.com/octocat",
211+
"followers_url": "https://api.github.com/users/octocat/followers",
212+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
213+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
214+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
215+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
216+
"organizations_url": "https://api.github.com/users/octocat/orgs",
217+
"repos_url": "https://api.github.com/users/octocat/repos",
218+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
219+
"received_events_url": "https://api.github.com/users/octocat/received_events",
220+
"type": "User",
221+
"site_admin": false
222+
}
223+
],
224+
"milestone": {
225+
"url": "https://api.github.com/repos/octocat/Hello-World/milestones/1",
226+
"html_url": "https://github.com/octocat/Hello-World/milestones/v1.0",
227+
"labels_url": "https://api.github.com/repos/octocat/Hello-World/milestones/1/labels",
228+
"id": 1002604,
229+
"node_id": "MDk6TWlsZXN0b25lMTAwMjYwNA==",
230+
"number": 1,
231+
"state": "open",
232+
"title": "v1.0",
233+
"description": "Tracking milestone for version 1.0",
234+
"creator": {
235+
"login": "octocat",
236+
"id": 1,
237+
"node_id": "MDQ6VXNlcjE=",
238+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
239+
"gravatar_id": "",
240+
"url": "https://api.github.com/users/octocat",
241+
"html_url": "https://github.com/octocat",
242+
"followers_url": "https://api.github.com/users/octocat/followers",
243+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
244+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
245+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
246+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
247+
"organizations_url": "https://api.github.com/users/octocat/orgs",
248+
"repos_url": "https://api.github.com/users/octocat/repos",
249+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
250+
"received_events_url": "https://api.github.com/users/octocat/received_events",
251+
"type": "User",
252+
"site_admin": false
253+
},
254+
"open_issues": 4,
255+
"closed_issues": 8,
256+
"created_at": "2011-04-10T20:09:31Z",
257+
"updated_at": "2014-03-03T18:58:10Z",
258+
"closed_at": "2013-02-12T13:22:01Z",
259+
"due_on": "2012-10-09T23:39:01Z"
260+
},
261+
"locked": true,
262+
"active_lock_reason": "too heated",
263+
"comments": 0,
264+
"pull_request": {
265+
"url": "https://api.github.com/repos/octocat/Hello-World/pulls/1347",
266+
"html_url": "https://github.com/octocat/Hello-World/pull/1347",
267+
"diff_url": "https://github.com/octocat/Hello-World/pull/1347.diff",
268+
"patch_url": "https://github.com/octocat/Hello-World/pull/1347.patch"
269+
},
270+
"closed_at": null,
271+
"created_at": "2011-04-22T13:33:48Z",
272+
"updated_at": "2011-04-22T13:33:48Z"
273+
}
138274
]

0 commit comments

Comments
 (0)