Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add include-pre-releases configuration option #1302

Merged
merged 11 commits into from Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
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
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
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
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
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
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
Expand Up @@ -121,6 +121,10 @@
"default": false,
"type": "boolean"
},
"include-pre-releases": {
"default": false,
"type": "boolean"
},
"commitish": {
"anyOf": [
{
Expand Down
@@ -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
@@ -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
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