Skip to content

Commit e11806d

Browse files
Add include-pre-releases configuration option (#1302)
1 parent cfc5540 commit e11806d

File tree

10 files changed

+129
-11
lines changed

10 files changed

+129
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ You can configure Release Drafter using the following key in your `.github/relea
133133
| `exclude-labels` | Optional | Exclude pull requests using labels. Refer to [Exclude Pull Requests](#exclude-pull-requests) to learn more about this option. |
134134
| `include-labels` | Optional | Include only the specified pull requests using labels. Refer to [Include Pull Requests](#include-pull-requests) to learn more about this option. |
135135
| `exclude-contributors` | Optional | Exclude specific usernames from the generated `$CONTRIBUTORS` variable. Refer to [Exclude Contributors](#exclude-contributors) to learn more about this option. |
136+
| `include-pre-releases` | Optional | Include pre releases as "full" releases when drafting release notes. Default: `false`. |
136137
| `no-contributors-template` | Optional | The template to use for `$CONTRIBUTORS` when there's no contributors to list. Default: `"No contributors"`. |
137138
| `replacers` | Optional | Search and replace content in the generated changelog body. Refer to [Replacers](#replacers) to learn more about this option. |
138139
| `sort-by` | Optional | Sort changelog by merged_at or title. Can be one of: `merged_at`, `title`. Default: `merged_at`. |

dist/index.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142364,6 +142364,7 @@ module.exports = (app, { getRouter }) => {
142364142364
const targetCommitish = commitish || config['commitish'] || ref
142365142365
const {
142366142366
'filter-by-commitish': filterByCommitish,
142367+
'include-pre-releases': includePreReleases,
142367142368
'tag-prefix': tagPrefix,
142368142369
} = config
142369142370

@@ -142381,6 +142382,7 @@ module.exports = (app, { getRouter }) => {
142381142382
context,
142382142383
targetCommitish,
142383142384
filterByCommitish,
142385+
includePreReleases,
142384142386
tagPrefix,
142385142387
})
142386142388

@@ -142792,6 +142794,7 @@ const DEFAULT_CONFIG = Object.freeze({
142792142794
'sort-direction': SORT_DIRECTIONS.descending,
142793142795
prerelease: false,
142794142796
'filter-by-commitish': false,
142797+
'include-pre-releases': false,
142795142798
commitish: '',
142796142799
'category-template': `## $TITLE`,
142797142800
header: '',
@@ -142909,6 +142912,7 @@ const findReleases = async ({
142909142912
context,
142910142913
targetCommitish,
142911142914
filterByCommitish,
142915+
includePreReleases,
142912142916
tagPrefix,
142913142917
}) => {
142914142918
let releaseCount = 0
@@ -142941,12 +142945,13 @@ const findReleases = async ({
142941142945
const filteredReleases = tagPrefix
142942142946
? commitishFilteredReleases.filter((r) => r.tag_name.startsWith(tagPrefix))
142943142947
: commitishFilteredReleases
142944-
const sortedPublishedReleases = sortReleases(
142945-
filteredReleases.filter((r) => !r.draft && !r.prerelease)
142948+
const sortedSelectedReleases = sortReleases(
142949+
filteredReleases.filter(
142950+
(r) => !r.draft && (!r.prerelease || includePreReleases)
142951+
)
142946142952
)
142947142953
const draftRelease = filteredReleases.find((r) => r.draft)
142948-
const lastRelease =
142949-
sortedPublishedReleases[sortedPublishedReleases.length - 1]
142954+
const lastRelease = sortedSelectedReleases[sortedSelectedReleases.length - 1]
142950142955

142951142956
if (draftRelease) {
142952142957
log({ context, message: `Draft release: ${draftRelease.tag_name}` })
@@ -143208,7 +143213,6 @@ const generateReleaseInfo = ({
143208143213
const { owner, repo } = context.repo()
143209143214

143210143215
let body = config['header'] + config.template + config['footer']
143211-
143212143216
body = template(
143213143217
body,
143214143218
{
@@ -143421,6 +143425,10 @@ const schema = (context) => {
143421143425
DEFAULT_CONFIG['filter-by-commitish']
143422143426
),
143423143427

143428+
'include-pre-releases': Joi.boolean().default(
143429+
DEFAULT_CONFIG['include-pre-releases']
143430+
),
143431+
143424143432
commitish: Joi.string().allow('').default(DEFAULT_CONFIG['commitish']),
143425143433

143426143434
replacers: Joi.array()

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ module.exports = (app, { getRouter }) => {
161161
const targetCommitish = commitish || config['commitish'] || ref
162162
const {
163163
'filter-by-commitish': filterByCommitish,
164+
'include-pre-releases': includePreReleases,
164165
'tag-prefix': tagPrefix,
165166
} = config
166167

@@ -178,6 +179,7 @@ module.exports = (app, { getRouter }) => {
178179
context,
179180
targetCommitish,
180181
filterByCommitish,
182+
includePreReleases,
181183
tagPrefix,
182184
})
183185

lib/default-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const DEFAULT_CONFIG = Object.freeze({
2626
'sort-direction': SORT_DIRECTIONS.descending,
2727
prerelease: false,
2828
'filter-by-commitish': false,
29+
'include-pre-releases': false,
2930
commitish: '',
3031
'category-template': `## $TITLE`,
3132
header: '',

lib/releases.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const findReleases = async ({
2424
context,
2525
targetCommitish,
2626
filterByCommitish,
27+
includePreReleases,
2728
tagPrefix,
2829
}) => {
2930
let releaseCount = 0
@@ -56,12 +57,13 @@ const findReleases = async ({
5657
const filteredReleases = tagPrefix
5758
? commitishFilteredReleases.filter((r) => r.tag_name.startsWith(tagPrefix))
5859
: commitishFilteredReleases
59-
const sortedPublishedReleases = sortReleases(
60-
filteredReleases.filter((r) => !r.draft && !r.prerelease)
60+
const sortedSelectedReleases = sortReleases(
61+
filteredReleases.filter(
62+
(r) => !r.draft && (!r.prerelease || includePreReleases)
63+
)
6164
)
6265
const draftRelease = filteredReleases.find((r) => r.draft)
63-
const lastRelease =
64-
sortedPublishedReleases[sortedPublishedReleases.length - 1]
66+
const lastRelease = sortedSelectedReleases[sortedSelectedReleases.length - 1]
6567

6668
if (draftRelease) {
6769
log({ context, message: `Draft release: ${draftRelease.tag_name}` })
@@ -323,7 +325,6 @@ const generateReleaseInfo = ({
323325
const { owner, repo } = context.repo()
324326

325327
let body = config['header'] + config.template + config['footer']
326-
327328
body = template(
328329
body,
329330
{

lib/schema.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ const schema = (context) => {
8181
DEFAULT_CONFIG['filter-by-commitish']
8282
),
8383

84+
'include-pre-releases': Joi.boolean().default(
85+
DEFAULT_CONFIG['include-pre-releases']
86+
),
87+
8488
commitish: Joi.string().allow('').default(DEFAULT_CONFIG['commitish']),
8589

8690
replacers: Joi.array()

schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@
121121
"default": false,
122122
"type": "boolean"
123123
},
124+
"include-pre-releases": {
125+
"default": false,
126+
"type": "boolean"
127+
},
124128
"commitish": {
125129
"anyOf": [
126130
{
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name-template: 'v$RESOLVED_VERSION'
2+
tag-template: 'v$RESOLVED_VERSION'
3+
template: |
4+
# What's Changed
5+
6+
$CHANGES
7+
include-pre-releases: true

test/fixtures/pre-release.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"url": "https://api.github.com/repos/toolmantim/release-drafter-test-project/releases/11691725",
3+
"assets_url": "https://api.github.com/repos/toolmantim/release-drafter-test-project/releases/11691725/assets",
4+
"upload_url": "https://uploads.github.com/repos/toolmantim/release-drafter-test-project/releases/11691725/assets{?name,label}",
5+
"html_url": "https://github.com/toolmantim/release-drafter-test-project/releases/tag/v1.5.0-alpha",
6+
"id": 11691725,
7+
"node_id": "MDc6UmVsZWFzZTExNjkxNzI2",
8+
"tag_name": "v1.5.0-alpha",
9+
"target_commitish": "master",
10+
"name": "v1.5.0-alpha",
11+
"draft": false,
12+
"author": {
13+
"login": "release-drafter[bot]",
14+
"id": 40600115,
15+
"node_id": "MDM6Qm90NDA2MDAxMTU=",
16+
"avatar_url": "https://avatars2.githubusercontent.com/in/14050?v=4",
17+
"gravatar_id": "",
18+
"url": "https://api.github.com/users/release-drafter%5Bbot%5D",
19+
"html_url": "https://github.com/apps/release-drafter",
20+
"followers_url": "https://api.github.com/users/release-drafter%5Bbot%5D/followers",
21+
"following_url": "https://api.github.com/users/release-drafter%5Bbot%5D/following{/other_user}",
22+
"gists_url": "https://api.github.com/users/release-drafter%5Bbot%5D/gists{/gist_id}",
23+
"starred_url": "https://api.github.com/users/release-drafter%5Bbot%5D/starred{/owner}{/repo}",
24+
"subscriptions_url": "https://api.github.com/users/release-drafter%5Bbot%5D/subscriptions",
25+
"organizations_url": "https://api.github.com/users/release-drafter%5Bbot%5D/orgs",
26+
"repos_url": "https://api.github.com/users/release-drafter%5Bbot%5D/repos",
27+
"events_url": "https://api.github.com/users/release-drafter%5Bbot%5D/events{/privacy}",
28+
"received_events_url": "https://api.github.com/users/release-drafter%5Bbot%5D/received_events",
29+
"type": "Bot",
30+
"site_admin": false
31+
},
32+
"prerelease": true,
33+
"created_at": "2018-06-28T05:45:15Z",
34+
"published_at": "2018-06-28T05:47:08Z",
35+
"assets": [],
36+
"tarball_url": "https://api.github.com/repos/toolmantim/release-drafter-test-project/tarball/v1.5.0-alpha",
37+
"zipball_url": "https://api.github.com/repos/toolmantim/release-drafter-test-project/zipball/v1.5.0-alpha",
38+
"body": "A pre release"
39+
}

test/index.test.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ const { getConfigMock } = require('./helpers/config-mock')
44
const releaseDrafter = require('../index')
55
const mockedEnv = require('mocked-env')
66
const pino = require('pino')
7-
const Stream = require('stream')
7+
const Stream = require('node:stream')
88
const pushPayload = require('./fixtures/push.json')
99
const pushTagPayload = require('./fixtures/push-tag.json')
1010
const releasePayload = require('./fixtures/release.json')
1111
const release2Payload = require('./fixtures/release-2.json')
1212
const release3Payload = require('./fixtures/release-3.json')
13+
const preReleasePayload = require('./fixtures/pre-release.json')
1314
const pushNonMasterPayload = require('./fixtures/push-non-master-branch.json')
1415
const graphqlCommitsNoPRsPayload = require('./fixtures/graphql-commits-no-prs.json')
1516
const graphqlCommitsMergeCommit = require('./fixtures/__generated__/graphql-commits-merge-commit.json')
@@ -1255,6 +1256,56 @@ describe('release-drafter', () => {
12551256
})
12561257
})
12571258

1259+
describe('with include-pre-releases true config', () => {
1260+
it('includes pre releases', async () => {
1261+
getConfigMock('config-with-include-pre-releases-true.yml')
1262+
1263+
nock('https://api.github.com')
1264+
.get('/repos/toolmantim/release-drafter-test-project/releases')
1265+
.query(true)
1266+
.reply(200, [release2Payload, preReleasePayload])
1267+
1268+
nock('https://api.github.com')
1269+
.post('/graphql', (body) =>
1270+
body.query.includes('query findCommitsWithAssociatedPullRequests')
1271+
)
1272+
.reply(200, graphqlCommitsMergeCommit)
1273+
1274+
nock('https://api.github.com')
1275+
.post(
1276+
'/repos/toolmantim/release-drafter-test-project/releases',
1277+
(body) => {
1278+
expect(body).toMatchInlineSnapshot(`
1279+
Object {
1280+
"body": "# What's Changed
1281+
1282+
* Add documentation (#5) @TimonVS
1283+
* Update dependencies (#4) @TimonVS
1284+
* Bug fixes (#3) @TimonVS
1285+
* Add big feature (#2) @TimonVS
1286+
* 👽 Add alien technology (#1) @TimonVS
1287+
",
1288+
"draft": true,
1289+
"name": "v1.5.0",
1290+
"prerelease": false,
1291+
"tag_name": "v1.5.0",
1292+
"target_commitish": "refs/heads/master",
1293+
}
1294+
`)
1295+
return true
1296+
}
1297+
)
1298+
.reply(200, preReleasePayload)
1299+
1300+
await probot.receive({
1301+
name: 'push',
1302+
payload: pushPayload,
1303+
})
1304+
1305+
expect.assertions(1)
1306+
})
1307+
})
1308+
12581309
describe('with exclude-labels config', () => {
12591310
it('excludes pull requests', async () => {
12601311
getConfigMock('config-with-exclude-labels.yml')

0 commit comments

Comments
 (0)