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 7 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. |
| `exclude-pre-releases` | Optional | Only use full releases when drafting release notes. Default: `true`. |
| `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
13 changes: 11 additions & 2 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,
'exclude-pre-releases': excludePreReleases,
'tag-prefix': tagPrefix,
} = config

Expand All @@ -142381,6 +142382,7 @@ module.exports = (app, { getRouter }) => {
context,
targetCommitish,
filterByCommitish,
excludePreReleases,
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,
'exclude-pre-releases': true,
commitish: '',
'category-template': `## $TITLE`,
header: '',
Expand Down Expand Up @@ -142909,6 +142912,7 @@ const findReleases = async ({
context,
targetCommitish,
filterByCommitish,
excludePreReleases,
tagPrefix,
}) => {
let releaseCount = 0
Expand Down Expand Up @@ -142942,7 +142946,9 @@ const findReleases = async ({
? commitishFilteredReleases.filter((r) => r.tag_name.startsWith(tagPrefix))
: commitishFilteredReleases
const sortedPublishedReleases = sortReleases(
filteredReleases.filter((r) => !r.draft && !r.prerelease)
filteredReleases.filter(
(r) => !r.draft && (!excludePreReleases || !r.prerelease)
)
)
const draftRelease = filteredReleases.find((r) => r.draft)
const lastRelease =
Expand Down Expand Up @@ -143208,7 +143214,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 +143426,10 @@ const schema = (context) => {
DEFAULT_CONFIG['filter-by-commitish']
),

'exclude-pre-releases': Joi.boolean().default(
DEFAULT_CONFIG['exclude-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,
'exclude-pre-releases': excludePreReleases,
'tag-prefix': tagPrefix,
} = config

Expand All @@ -178,6 +179,7 @@ module.exports = (app, { getRouter }) => {
context,
targetCommitish,
filterByCommitish,
excludePreReleases,
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,
'exclude-pre-releases': true,
commitish: '',
'category-template': `## $TITLE`,
header: '',
Expand Down
6 changes: 4 additions & 2 deletions lib/releases.js
Expand Up @@ -24,6 +24,7 @@ const findReleases = async ({
context,
targetCommitish,
filterByCommitish,
excludePreReleases,
tagPrefix,
}) => {
let releaseCount = 0
Expand Down Expand Up @@ -57,7 +58,9 @@ const findReleases = async ({
? commitishFilteredReleases.filter((r) => r.tag_name.startsWith(tagPrefix))
: commitishFilteredReleases
const sortedPublishedReleases = sortReleases(
robbinjanssen marked this conversation as resolved.
Show resolved Hide resolved
filteredReleases.filter((r) => !r.draft && !r.prerelease)
filteredReleases.filter(
(r) => !r.draft && (!excludePreReleases || !r.prerelease)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic checks out, but it doesn't read right.

!r.draft && (!r.prerelease || includePreReleases)

would be preferable.

I'm quite concerned about the amount of boolean logic in this function already which is why I'm even giving this a comment. It probably needs to get reflowed entirely, but that's out of scope here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the configuration to include-pre-releases which makes more sense :) Thanks for your input!

)
)
const draftRelease = filteredReleases.find((r) => r.draft)
const lastRelease =
Expand Down Expand Up @@ -323,7 +326,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']
),

'exclude-pre-releases': Joi.boolean().default(
DEFAULT_CONFIG['exclude-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"
},
"exclude-pre-releases": {
"default": true,
"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
exclude-pre-releases: false
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"
}
51 changes: 51 additions & 0 deletions test/index.test.js
Expand Up @@ -10,6 +10,7 @@ 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 exclude-pre-releases false config', () => {
it('includes pre releases', async () => {
getConfigMock('config-with-exclude-pre-releases-false.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