Skip to content

Commit

Permalink
Add include-pre-releases configuration option (#1302)
Browse files Browse the repository at this point in the history
  • Loading branch information
robbinjanssen authored Feb 21, 2023
1 parent cfc5540 commit e11806d
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ You can configure Release Drafter using the following key in your `.github/relea
| `exclude-labels` | Optional | Exclude pull requests using labels. Refer to [Exclude Pull Requests](#exclude-pull-requests) to learn more about this option. |
| `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. |
| `exclude-contributors` | Optional | Exclude specific usernames from the generated `$CONTRIBUTORS` variable. Refer to [Exclude Contributors](#exclude-contributors) to learn more about this option. |
| `include-pre-releases` | Optional | Include pre releases as "full" releases when drafting release notes. Default: `false`. |
| `no-contributors-template` | Optional | The template to use for `$CONTRIBUTORS` when there's no contributors to list. Default: `"No contributors"`. |
| `replacers` | Optional | Search and replace content in the generated changelog body. Refer to [Replacers](#replacers) to learn more about this option. |
| `sort-by` | Optional | Sort changelog by merged_at or title. Can be one of: `merged_at`, `title`. Default: `merged_at`. |
Expand Down
18 changes: 13 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142364,6 +142364,7 @@ module.exports = (app, { getRouter }) => {
const targetCommitish = commitish || config['commitish'] || ref
const {
'filter-by-commitish': filterByCommitish,
'include-pre-releases': includePreReleases,
'tag-prefix': tagPrefix,
} = config

Expand All @@ -142381,6 +142382,7 @@ module.exports = (app, { getRouter }) => {
context,
targetCommitish,
filterByCommitish,
includePreReleases,
tagPrefix,
})

Expand Down Expand Up @@ -142792,6 +142794,7 @@ const DEFAULT_CONFIG = Object.freeze({
'sort-direction': SORT_DIRECTIONS.descending,
prerelease: false,
'filter-by-commitish': false,
'include-pre-releases': false,
commitish: '',
'category-template': `## $TITLE`,
header: '',
Expand Down Expand Up @@ -142909,6 +142912,7 @@ const findReleases = async ({
context,
targetCommitish,
filterByCommitish,
includePreReleases,
tagPrefix,
}) => {
let releaseCount = 0
Expand Down Expand Up @@ -142941,12 +142945,13 @@ const findReleases = async ({
const filteredReleases = tagPrefix
? commitishFilteredReleases.filter((r) => r.tag_name.startsWith(tagPrefix))
: commitishFilteredReleases
const sortedPublishedReleases = sortReleases(
filteredReleases.filter((r) => !r.draft && !r.prerelease)
const sortedSelectedReleases = sortReleases(
filteredReleases.filter(
(r) => !r.draft && (!r.prerelease || includePreReleases)
)
)
const draftRelease = filteredReleases.find((r) => r.draft)
const lastRelease =
sortedPublishedReleases[sortedPublishedReleases.length - 1]
const lastRelease = sortedSelectedReleases[sortedSelectedReleases.length - 1]

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

let body = config['header'] + config.template + config['footer']

body = template(
body,
{
Expand Down Expand Up @@ -143421,6 +143425,10 @@ const schema = (context) => {
DEFAULT_CONFIG['filter-by-commitish']
),

'include-pre-releases': Joi.boolean().default(
DEFAULT_CONFIG['include-pre-releases']
),

commitish: Joi.string().allow('').default(DEFAULT_CONFIG['commitish']),

replacers: Joi.array()
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ module.exports = (app, { getRouter }) => {
const targetCommitish = commitish || config['commitish'] || ref
const {
'filter-by-commitish': filterByCommitish,
'include-pre-releases': includePreReleases,
'tag-prefix': tagPrefix,
} = config

Expand All @@ -178,6 +179,7 @@ module.exports = (app, { getRouter }) => {
context,
targetCommitish,
filterByCommitish,
includePreReleases,
tagPrefix,
})

Expand Down
1 change: 1 addition & 0 deletions lib/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const DEFAULT_CONFIG = Object.freeze({
'sort-direction': SORT_DIRECTIONS.descending,
prerelease: false,
'filter-by-commitish': false,
'include-pre-releases': false,
commitish: '',
'category-template': `## $TITLE`,
header: '',
Expand Down
11 changes: 6 additions & 5 deletions lib/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const findReleases = async ({
context,
targetCommitish,
filterByCommitish,
includePreReleases,
tagPrefix,
}) => {
let releaseCount = 0
Expand Down Expand Up @@ -56,12 +57,13 @@ const findReleases = async ({
const filteredReleases = tagPrefix
? commitishFilteredReleases.filter((r) => r.tag_name.startsWith(tagPrefix))
: commitishFilteredReleases
const sortedPublishedReleases = sortReleases(
filteredReleases.filter((r) => !r.draft && !r.prerelease)
const sortedSelectedReleases = sortReleases(
filteredReleases.filter(
(r) => !r.draft && (!r.prerelease || includePreReleases)
)
)
const draftRelease = filteredReleases.find((r) => r.draft)
const lastRelease =
sortedPublishedReleases[sortedPublishedReleases.length - 1]
const lastRelease = sortedSelectedReleases[sortedSelectedReleases.length - 1]

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

let body = config['header'] + config.template + config['footer']

body = template(
body,
{
Expand Down
4 changes: 4 additions & 0 deletions lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ const schema = (context) => {
DEFAULT_CONFIG['filter-by-commitish']
),

'include-pre-releases': Joi.boolean().default(
DEFAULT_CONFIG['include-pre-releases']
),

commitish: Joi.string().allow('').default(DEFAULT_CONFIG['commitish']),

replacers: Joi.array()
Expand Down
4 changes: 4 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@
"default": false,
"type": "boolean"
},
"include-pre-releases": {
"default": false,
"type": "boolean"
},
"commitish": {
"anyOf": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'
template: |
# What's Changed
$CHANGES
include-pre-releases: true
39 changes: 39 additions & 0 deletions test/fixtures/pre-release.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"url": "https://api.github.com/repos/toolmantim/release-drafter-test-project/releases/11691725",
"assets_url": "https://api.github.com/repos/toolmantim/release-drafter-test-project/releases/11691725/assets",
"upload_url": "https://uploads.github.com/repos/toolmantim/release-drafter-test-project/releases/11691725/assets{?name,label}",
"html_url": "https://github.com/toolmantim/release-drafter-test-project/releases/tag/v1.5.0-alpha",
"id": 11691725,
"node_id": "MDc6UmVsZWFzZTExNjkxNzI2",
"tag_name": "v1.5.0-alpha",
"target_commitish": "master",
"name": "v1.5.0-alpha",
"draft": false,
"author": {
"login": "release-drafter[bot]",
"id": 40600115,
"node_id": "MDM6Qm90NDA2MDAxMTU=",
"avatar_url": "https://avatars2.githubusercontent.com/in/14050?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/release-drafter%5Bbot%5D",
"html_url": "https://github.com/apps/release-drafter",
"followers_url": "https://api.github.com/users/release-drafter%5Bbot%5D/followers",
"following_url": "https://api.github.com/users/release-drafter%5Bbot%5D/following{/other_user}",
"gists_url": "https://api.github.com/users/release-drafter%5Bbot%5D/gists{/gist_id}",
"starred_url": "https://api.github.com/users/release-drafter%5Bbot%5D/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/release-drafter%5Bbot%5D/subscriptions",
"organizations_url": "https://api.github.com/users/release-drafter%5Bbot%5D/orgs",
"repos_url": "https://api.github.com/users/release-drafter%5Bbot%5D/repos",
"events_url": "https://api.github.com/users/release-drafter%5Bbot%5D/events{/privacy}",
"received_events_url": "https://api.github.com/users/release-drafter%5Bbot%5D/received_events",
"type": "Bot",
"site_admin": false
},
"prerelease": true,
"created_at": "2018-06-28T05:45:15Z",
"published_at": "2018-06-28T05:47:08Z",
"assets": [],
"tarball_url": "https://api.github.com/repos/toolmantim/release-drafter-test-project/tarball/v1.5.0-alpha",
"zipball_url": "https://api.github.com/repos/toolmantim/release-drafter-test-project/zipball/v1.5.0-alpha",
"body": "A pre release"
}
53 changes: 52 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ const { getConfigMock } = require('./helpers/config-mock')
const releaseDrafter = require('../index')
const mockedEnv = require('mocked-env')
const pino = require('pino')
const Stream = require('stream')
const Stream = require('node:stream')
const pushPayload = require('./fixtures/push.json')
const pushTagPayload = require('./fixtures/push-tag.json')
const releasePayload = require('./fixtures/release.json')
const release2Payload = require('./fixtures/release-2.json')
const release3Payload = require('./fixtures/release-3.json')
const preReleasePayload = require('./fixtures/pre-release.json')
const pushNonMasterPayload = require('./fixtures/push-non-master-branch.json')
const graphqlCommitsNoPRsPayload = require('./fixtures/graphql-commits-no-prs.json')
const graphqlCommitsMergeCommit = require('./fixtures/__generated__/graphql-commits-merge-commit.json')
Expand Down Expand Up @@ -1255,6 +1256,56 @@ describe('release-drafter', () => {
})
})

describe('with include-pre-releases true config', () => {
it('includes pre releases', async () => {
getConfigMock('config-with-include-pre-releases-true.yml')

nock('https://api.github.com')
.get('/repos/toolmantim/release-drafter-test-project/releases')
.query(true)
.reply(200, [release2Payload, preReleasePayload])

nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsMergeCommit)

nock('https://api.github.com')
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "# What's Changed
* Add documentation (#5) @TimonVS
* Update dependencies (#4) @TimonVS
* Bug fixes (#3) @TimonVS
* Add big feature (#2) @TimonVS
* 👽 Add alien technology (#1) @TimonVS
",
"draft": true,
"name": "v1.5.0",
"prerelease": false,
"tag_name": "v1.5.0",
"target_commitish": "refs/heads/master",
}
`)
return true
}
)
.reply(200, preReleasePayload)

await probot.receive({
name: 'push',
payload: pushPayload,
})

expect.assertions(1)
})
})

describe('with exclude-labels config', () => {
it('excludes pull requests', async () => {
getConfigMock('config-with-exclude-labels.yml')
Expand Down

0 comments on commit e11806d

Please sign in to comment.