From 5ad62ea2fe763e84bc6a293ee86c9904060d2554 Mon Sep 17 00:00:00 2001 From: Robbin Janssen Date: Fri, 20 Jan 2023 14:21:46 +0100 Subject: [PATCH 01/11] Add exclude pre release configuration option --- README.md | 1 + index.js | 2 ++ lib/default-config.js | 1 + lib/releases.js | 9 +++++---- lib/schema.js | 4 ++++ schema.json | 4 ++++ 6 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 24ae54038..a39c34ece 100644 --- a/README.md +++ b/README.md @@ -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`. | diff --git a/index.js b/index.js index 52c872c16..70c5b37ec 100644 --- a/index.js +++ b/index.js @@ -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 @@ -178,6 +179,7 @@ module.exports = (app, { getRouter }) => { context, targetCommitish, filterByCommitish, + excludePreReleases, tagPrefix, }) diff --git a/lib/default-config.js b/lib/default-config.js index 5affa9465..9a68dc649 100644 --- a/lib/default-config.js +++ b/lib/default-config.js @@ -26,6 +26,7 @@ const DEFAULT_CONFIG = Object.freeze({ 'sort-direction': SORT_DIRECTIONS.descending, prerelease: false, 'filter-by-commitish': false, + 'exclude-pre-release': true, commitish: '', 'category-template': `## $TITLE`, header: '', diff --git a/lib/releases.js b/lib/releases.js index 2d30ff1a2..b3d12bd43 100644 --- a/lib/releases.js +++ b/lib/releases.js @@ -24,6 +24,7 @@ const findReleases = async ({ context, targetCommitish, filterByCommitish, + excludePreReleases, tagPrefix, }) => { let releaseCount = 0 @@ -49,15 +50,15 @@ const findReleases = async ({ const targetCommitishName = targetCommitish.replace(headRefRegex, '') const commitishFilteredReleases = filterByCommitish ? releases.filter( - (r) => - targetCommitishName === r.target_commitish.replace(headRefRegex, '') - ) + (r) => + targetCommitishName === r.target_commitish.replace(headRefRegex, '') + ) : releases const filteredReleases = tagPrefix ? 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 = diff --git a/lib/schema.js b/lib/schema.js index 60dd8209a..7f9e93b87 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -81,6 +81,10 @@ const schema = (context) => { DEFAULT_CONFIG['filter-by-commitish'] ), + 'exclude-pre-release': Joi.boolean().default( + DEFAULT_CONFIG['exclude-pre-release'] + ), + commitish: Joi.string().allow('').default(DEFAULT_CONFIG['commitish']), replacers: Joi.array() diff --git a/schema.json b/schema.json index cf5b7c8eb..f3a5cbeb0 100644 --- a/schema.json +++ b/schema.json @@ -99,6 +99,10 @@ "type": "string" } }, + "exclude-pre-release": { + "default": true, + "type": "boolean" + }, "no-contributors-template": { "default": "No contributors", "type": "string" From ee98e817226f2902a014d2c0c043ddaa40dc87bf Mon Sep 17 00:00:00 2001 From: Robbin Janssen Date: Fri, 20 Jan 2023 14:26:28 +0100 Subject: [PATCH 02/11] Revert change --- lib/releases.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/releases.js b/lib/releases.js index b3d12bd43..abef7b9de 100644 --- a/lib/releases.js +++ b/lib/releases.js @@ -50,9 +50,9 @@ const findReleases = async ({ const targetCommitishName = targetCommitish.replace(headRefRegex, '') const commitishFilteredReleases = filterByCommitish ? releases.filter( - (r) => - targetCommitishName === r.target_commitish.replace(headRefRegex, '') - ) + (r) => + targetCommitishName === r.target_commitish.replace(headRefRegex, '') + ) : releases const filteredReleases = tagPrefix ? commitishFilteredReleases.filter((r) => r.tag_name.startsWith(tagPrefix)) From 7ba4bf0694d21d913bcf46c17db94a3f2b4cc11d Mon Sep 17 00:00:00 2001 From: Robbin Janssen Date: Fri, 20 Jan 2023 14:27:02 +0100 Subject: [PATCH 03/11] Fix name --- lib/default-config.js | 2 +- lib/schema.js | 4 +-- schema.json | 71 ++++++++++++++++++++++++++++++++----------- 3 files changed, 57 insertions(+), 20 deletions(-) diff --git a/lib/default-config.js b/lib/default-config.js index 9a68dc649..9d139913f 100644 --- a/lib/default-config.js +++ b/lib/default-config.js @@ -26,7 +26,7 @@ const DEFAULT_CONFIG = Object.freeze({ 'sort-direction': SORT_DIRECTIONS.descending, prerelease: false, 'filter-by-commitish': false, - 'exclude-pre-release': true, + 's': true, commitish: '', 'category-template': `## $TITLE`, header: '', diff --git a/lib/schema.js b/lib/schema.js index 7f9e93b87..71300c772 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -81,8 +81,8 @@ const schema = (context) => { DEFAULT_CONFIG['filter-by-commitish'] ), - 'exclude-pre-release': Joi.boolean().default( - DEFAULT_CONFIG['exclude-pre-release'] + 'exclude-pre-releases': Joi.boolean().default( + DEFAULT_CONFIG['exclude-pre-releases'] ), commitish: Joi.string().allow('').default(DEFAULT_CONFIG['commitish']), diff --git a/schema.json b/schema.json index f3a5cbeb0..17d6be94b 100644 --- a/schema.json +++ b/schema.json @@ -5,7 +5,9 @@ "type": "object", "properties": { "references": { - "default": ["master"], + "default": [ + "master" + ], "type": "array", "items": { "type": "string" @@ -19,7 +21,9 @@ "anyOf": [ { "type": "string", - "enum": [""] + "enum": [ + "" + ] }, { "default": "", @@ -39,7 +43,9 @@ "anyOf": [ { "type": "string", - "enum": [""] + "enum": [ + "" + ] }, { "default": "", @@ -51,7 +57,9 @@ "anyOf": [ { "type": "string", - "enum": [""] + "enum": [ + "" + ] }, { "default": "", @@ -63,7 +71,9 @@ "anyOf": [ { "type": "string", - "enum": [""] + "enum": [ + "" + ] }, { "default": "", @@ -99,7 +109,7 @@ "type": "string" } }, - "exclude-pre-release": { + "exclude-pre-releases": { "default": true, "type": "boolean" }, @@ -109,12 +119,18 @@ }, "sort-by": { "default": "merged_at", - "enum": ["merged_at", "title"], + "enum": [ + "merged_at", + "title" + ], "type": "string" }, "sort-direction": { "default": "descending", - "enum": ["ascending", "descending"], + "enum": [ + "ascending", + "descending" + ], "type": "string" }, "prerelease": { @@ -129,7 +145,9 @@ "anyOf": [ { "type": "string", - "enum": [""] + "enum": [ + "" + ] }, { "default": "", @@ -150,7 +168,9 @@ "anyOf": [ { "type": "string", - "enum": [""] + "enum": [ + "" + ] }, { "type": "string" @@ -160,7 +180,10 @@ }, "additionalProperties": false, "patterns": [], - "required": ["search", "replace"] + "required": [ + "search", + "replace" + ] } }, "autolabeler": { @@ -203,7 +226,9 @@ }, "additionalProperties": false, "patterns": [], - "required": ["label"] + "required": [ + "label" + ] } }, "categories": { @@ -233,7 +258,9 @@ }, "additionalProperties": false, "patterns": [], - "required": ["title"] + "required": [ + "title" + ] } }, "version-resolver": { @@ -295,7 +322,11 @@ }, "default": { "default": "patch", - "enum": ["major", "minor", "patch"], + "enum": [ + "major", + "minor", + "patch" + ], "type": "string" } }, @@ -306,7 +337,9 @@ "anyOf": [ { "type": "string", - "enum": [""] + "enum": [ + "" + ] }, { "default": "## $TITLE", @@ -318,7 +351,9 @@ "anyOf": [ { "type": "string", - "enum": [""] + "enum": [ + "" + ] }, { "default": "", @@ -333,7 +368,9 @@ "anyOf": [ { "type": "string", - "enum": [""] + "enum": [ + "" + ] }, { "default": "", From d2ef5dbd6e657042e8771300bb38cbf7b5b0122a Mon Sep 17 00:00:00 2001 From: Robbin Janssen Date: Sat, 28 Jan 2023 14:02:05 +0100 Subject: [PATCH 04/11] Fix test --- dist/index.js | 14 +++- lib/default-config.js | 2 +- lib/releases.js | 8 +- schema.json | 77 +++++-------------- ...config-with-exclude-pre-releases-false.yml | 7 ++ test/fixtures/pre-release.json | 39 ++++++++++ test/index.test.js | 56 +++++++++++++- 7 files changed, 138 insertions(+), 65 deletions(-) create mode 100644 test/fixtures/config/config-with-exclude-pre-releases-false.yml create mode 100644 test/fixtures/pre-release.json diff --git a/dist/index.js b/dist/index.js index b851d5f52..6a00b66c7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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 @@ -142381,6 +142382,7 @@ module.exports = (app, { getRouter }) => { context, targetCommitish, filterByCommitish, + excludePreReleases, tagPrefix, }) @@ -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: '', @@ -142909,6 +142912,7 @@ const findReleases = async ({ context, targetCommitish, filterByCommitish, + excludePreReleases, tagPrefix, }) => { let releaseCount = 0 @@ -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 = @@ -143208,7 +143214,7 @@ const generateReleaseInfo = ({ const { owner, repo } = context.repo() let body = config['header'] + config.template + config['footer'] - + console.log(lastRelease.tag_name) body = template( body, { @@ -143421,6 +143427,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() diff --git a/lib/default-config.js b/lib/default-config.js index 9d139913f..77e375beb 100644 --- a/lib/default-config.js +++ b/lib/default-config.js @@ -26,7 +26,7 @@ const DEFAULT_CONFIG = Object.freeze({ 'sort-direction': SORT_DIRECTIONS.descending, prerelease: false, 'filter-by-commitish': false, - 's': true, + 'exclude-pre-releases': true, commitish: '', 'category-template': `## $TITLE`, header: '', diff --git a/lib/releases.js b/lib/releases.js index abef7b9de..dda324176 100644 --- a/lib/releases.js +++ b/lib/releases.js @@ -52,13 +52,15 @@ const findReleases = async ({ ? releases.filter( (r) => targetCommitishName === r.target_commitish.replace(headRefRegex, '') - ) + ) : releases const filteredReleases = tagPrefix ? commitishFilteredReleases.filter((r) => r.tag_name.startsWith(tagPrefix)) : commitishFilteredReleases const sortedPublishedReleases = sortReleases( - filteredReleases.filter((r) => !r.draft && (!excludePreReleases || !r.prerelease)) + filteredReleases.filter( + (r) => !r.draft && (!excludePreReleases || !r.prerelease) + ) ) const draftRelease = filteredReleases.find((r) => r.draft) const lastRelease = @@ -324,7 +326,7 @@ const generateReleaseInfo = ({ const { owner, repo } = context.repo() let body = config['header'] + config.template + config['footer'] - + console.log(lastRelease.tag_name) body = template( body, { diff --git a/schema.json b/schema.json index 17d6be94b..caa0992a5 100644 --- a/schema.json +++ b/schema.json @@ -5,9 +5,7 @@ "type": "object", "properties": { "references": { - "default": [ - "master" - ], + "default": ["master"], "type": "array", "items": { "type": "string" @@ -21,9 +19,7 @@ "anyOf": [ { "type": "string", - "enum": [ - "" - ] + "enum": [""] }, { "default": "", @@ -43,9 +39,7 @@ "anyOf": [ { "type": "string", - "enum": [ - "" - ] + "enum": [""] }, { "default": "", @@ -57,9 +51,7 @@ "anyOf": [ { "type": "string", - "enum": [ - "" - ] + "enum": [""] }, { "default": "", @@ -71,9 +63,7 @@ "anyOf": [ { "type": "string", - "enum": [ - "" - ] + "enum": [""] }, { "default": "", @@ -109,28 +99,18 @@ "type": "string" } }, - "exclude-pre-releases": { - "default": true, - "type": "boolean" - }, "no-contributors-template": { "default": "No contributors", "type": "string" }, "sort-by": { "default": "merged_at", - "enum": [ - "merged_at", - "title" - ], + "enum": ["merged_at", "title"], "type": "string" }, "sort-direction": { "default": "descending", - "enum": [ - "ascending", - "descending" - ], + "enum": ["ascending", "descending"], "type": "string" }, "prerelease": { @@ -141,13 +121,15 @@ "default": false, "type": "boolean" }, + "exclude-pre-releases": { + "default": true, + "type": "boolean" + }, "commitish": { "anyOf": [ { "type": "string", - "enum": [ - "" - ] + "enum": [""] }, { "default": "", @@ -168,9 +150,7 @@ "anyOf": [ { "type": "string", - "enum": [ - "" - ] + "enum": [""] }, { "type": "string" @@ -180,10 +160,7 @@ }, "additionalProperties": false, "patterns": [], - "required": [ - "search", - "replace" - ] + "required": ["search", "replace"] } }, "autolabeler": { @@ -226,9 +203,7 @@ }, "additionalProperties": false, "patterns": [], - "required": [ - "label" - ] + "required": ["label"] } }, "categories": { @@ -258,9 +233,7 @@ }, "additionalProperties": false, "patterns": [], - "required": [ - "title" - ] + "required": ["title"] } }, "version-resolver": { @@ -322,11 +295,7 @@ }, "default": { "default": "patch", - "enum": [ - "major", - "minor", - "patch" - ], + "enum": ["major", "minor", "patch"], "type": "string" } }, @@ -337,9 +306,7 @@ "anyOf": [ { "type": "string", - "enum": [ - "" - ] + "enum": [""] }, { "default": "## $TITLE", @@ -351,9 +318,7 @@ "anyOf": [ { "type": "string", - "enum": [ - "" - ] + "enum": [""] }, { "default": "", @@ -368,9 +333,7 @@ "anyOf": [ { "type": "string", - "enum": [ - "" - ] + "enum": [""] }, { "default": "", diff --git a/test/fixtures/config/config-with-exclude-pre-releases-false.yml b/test/fixtures/config/config-with-exclude-pre-releases-false.yml new file mode 100644 index 000000000..914a4ca61 --- /dev/null +++ b/test/fixtures/config/config-with-exclude-pre-releases-false.yml @@ -0,0 +1,7 @@ +name-template: 'v$RESOLVED_VERSION' +tag-template: 'v$RESOLVED_VERSION' +template: | + # What's Changed + + $CHANGES +exclude-pre-releases: false diff --git a/test/fixtures/pre-release.json b/test/fixtures/pre-release.json new file mode 100644 index 000000000..9f4e329e4 --- /dev/null +++ b/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" +} diff --git a/test/index.test.js b/test/index.test.js index 812f87856..983c8a3ad 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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') @@ -1255,6 +1256,57 @@ describe('release-drafter', () => { }) }) + describe('with exclude-pre-release 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) => { + console.dir(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, releasePayload) + + 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') @@ -1348,7 +1400,7 @@ describe('release-drafter', () => { return true } ) - .reply(200, releasePayload) + .reply(200, preReleasePayload) await probot.receive({ name: 'push', From 9ce7f6c4738ab3aea591c19c9b4e7ed2b718e069 Mon Sep 17 00:00:00 2001 From: Robbin Janssen Date: Sat, 28 Jan 2023 14:07:05 +0100 Subject: [PATCH 05/11] Remove logging --- dist/index.js | 1 - lib/releases.js | 1 - test/index.test.js | 5 ++--- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/dist/index.js b/dist/index.js index 6a00b66c7..61e9175cd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -143214,7 +143214,6 @@ const generateReleaseInfo = ({ const { owner, repo } = context.repo() let body = config['header'] + config.template + config['footer'] - console.log(lastRelease.tag_name) body = template( body, { diff --git a/lib/releases.js b/lib/releases.js index dda324176..d5ed7d40e 100644 --- a/lib/releases.js +++ b/lib/releases.js @@ -326,7 +326,6 @@ const generateReleaseInfo = ({ const { owner, repo } = context.repo() let body = config['header'] + config.template + config['footer'] - console.log(lastRelease.tag_name) body = template( body, { diff --git a/test/index.test.js b/test/index.test.js index 983c8a3ad..0739484fb 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1275,7 +1275,6 @@ describe('release-drafter', () => { .post( '/repos/toolmantim/release-drafter-test-project/releases', (body) => { - console.dir(body) expect(body).toMatchInlineSnapshot(` Object { "body": "# What's Changed @@ -1296,7 +1295,7 @@ describe('release-drafter', () => { return true } ) - .reply(200, releasePayload) + .reply(200, preReleasePayload) await probot.receive({ name: 'push', @@ -1400,7 +1399,7 @@ describe('release-drafter', () => { return true } ) - .reply(200, preReleasePayload) + .reply(200, releasePayload) await probot.receive({ name: 'push', From aa4f042737c81930968909494c003a33c175c6f2 Mon Sep 17 00:00:00 2001 From: Robbin Janssen Date: Sat, 28 Jan 2023 14:08:10 +0100 Subject: [PATCH 06/11] Remove node: --- test/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.test.js b/test/index.test.js index 0739484fb..05be4f510 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -4,7 +4,7 @@ const { getConfigMock } = require('./helpers/config-mock') const releaseDrafter = require('../index') const mockedEnv = require('mocked-env') const pino = require('pino') -const Stream = require('node:stream') +const Stream = require('stream') const pushPayload = require('./fixtures/push.json') const pushTagPayload = require('./fixtures/push-tag.json') const releasePayload = require('./fixtures/release.json') From dbb907d1038dfacfd000c0236a265e7945e90cac Mon Sep 17 00:00:00 2001 From: Robbin Janssen Date: Sat, 28 Jan 2023 14:13:51 +0100 Subject: [PATCH 07/11] Fix typo --- test/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.test.js b/test/index.test.js index 05be4f510..64e231cad 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1256,7 +1256,7 @@ describe('release-drafter', () => { }) }) - describe('with exclude-pre-release false config', () => { + describe('with exclude-pre-releases false config', () => { it('includes pre releases', async () => { getConfigMock('config-with-exclude-pre-releases-false.yml') From f85f5ae597a49cbb65be20c6b890d12fcf2a312d Mon Sep 17 00:00:00 2001 From: Robbin Janssen Date: Sat, 4 Feb 2023 13:21:40 +0100 Subject: [PATCH 08/11] Apply pr changes --- README.md | 2 +- index.js | 4 ++-- lib/default-config.js | 2 +- lib/releases.js | 9 ++++----- lib/schema.js | 4 ++-- schema.json | 2 +- ...lse.yml => config-with-include-pre-releases-true.yml} | 2 +- test/index.test.js | 6 +++--- 8 files changed, 15 insertions(+), 16 deletions(-) rename test/fixtures/config/{config-with-exclude-pre-releases-false.yml => config-with-include-pre-releases-true.yml} (80%) diff --git a/README.md b/README.md index a39c34ece..53bf3ad3e 100644 --- a/README.md +++ b/README.md @@ -133,7 +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`. | +| `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`. | diff --git a/index.js b/index.js index 70c5b37ec..d0f8c81c9 100644 --- a/index.js +++ b/index.js @@ -161,7 +161,7 @@ module.exports = (app, { getRouter }) => { const targetCommitish = commitish || config['commitish'] || ref const { 'filter-by-commitish': filterByCommitish, - 'exclude-pre-releases': excludePreReleases, + 'include-pre-releases': includePreReleases, 'tag-prefix': tagPrefix, } = config @@ -179,7 +179,7 @@ module.exports = (app, { getRouter }) => { context, targetCommitish, filterByCommitish, - excludePreReleases, + includePreReleases, tagPrefix, }) diff --git a/lib/default-config.js b/lib/default-config.js index 77e375beb..af88e85e9 100644 --- a/lib/default-config.js +++ b/lib/default-config.js @@ -26,7 +26,7 @@ const DEFAULT_CONFIG = Object.freeze({ 'sort-direction': SORT_DIRECTIONS.descending, prerelease: false, 'filter-by-commitish': false, - 'exclude-pre-releases': true, + 'include-pre-releases': true, commitish: '', 'category-template': `## $TITLE`, header: '', diff --git a/lib/releases.js b/lib/releases.js index d5ed7d40e..1f99289b4 100644 --- a/lib/releases.js +++ b/lib/releases.js @@ -24,7 +24,7 @@ const findReleases = async ({ context, targetCommitish, filterByCommitish, - excludePreReleases, + includePreReleases, tagPrefix, }) => { let releaseCount = 0 @@ -57,14 +57,13 @@ const findReleases = async ({ const filteredReleases = tagPrefix ? commitishFilteredReleases.filter((r) => r.tag_name.startsWith(tagPrefix)) : commitishFilteredReleases - const sortedPublishedReleases = sortReleases( + const sortedSelectedReleases = sortReleases( filteredReleases.filter( - (r) => !r.draft && (!excludePreReleases || !r.prerelease) + (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}` }) diff --git a/lib/schema.js b/lib/schema.js index 71300c772..b17e40620 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -81,8 +81,8 @@ const schema = (context) => { DEFAULT_CONFIG['filter-by-commitish'] ), - 'exclude-pre-releases': Joi.boolean().default( - DEFAULT_CONFIG['exclude-pre-releases'] + 'include-pre-releases': Joi.boolean().default( + DEFAULT_CONFIG['include-pre-releases'] ), commitish: Joi.string().allow('').default(DEFAULT_CONFIG['commitish']), diff --git a/schema.json b/schema.json index caa0992a5..5802942f2 100644 --- a/schema.json +++ b/schema.json @@ -121,7 +121,7 @@ "default": false, "type": "boolean" }, - "exclude-pre-releases": { + "include-pre-releases": { "default": true, "type": "boolean" }, diff --git a/test/fixtures/config/config-with-exclude-pre-releases-false.yml b/test/fixtures/config/config-with-include-pre-releases-true.yml similarity index 80% rename from test/fixtures/config/config-with-exclude-pre-releases-false.yml rename to test/fixtures/config/config-with-include-pre-releases-true.yml index 914a4ca61..01e9b1221 100644 --- a/test/fixtures/config/config-with-exclude-pre-releases-false.yml +++ b/test/fixtures/config/config-with-include-pre-releases-true.yml @@ -4,4 +4,4 @@ template: | # What's Changed $CHANGES -exclude-pre-releases: false +include-pre-releases: true diff --git a/test/index.test.js b/test/index.test.js index 64e231cad..bba6dbed8 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -4,7 +4,7 @@ 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') @@ -1256,9 +1256,9 @@ describe('release-drafter', () => { }) }) - describe('with exclude-pre-releases false config', () => { + describe('with include-pre-releases true config', () => { it('includes pre releases', async () => { - getConfigMock('config-with-exclude-pre-releases-false.yml') + getConfigMock('config-with-include-pre-releases-true.yml') nock('https://api.github.com') .get('/repos/toolmantim/release-drafter-test-project/releases') From c2d1a2eca3d0f1269075f4c3c1a49fd77c5c4b10 Mon Sep 17 00:00:00 2001 From: Robbin Janssen Date: Sat, 4 Feb 2023 13:21:51 +0100 Subject: [PATCH 09/11] Update dist file --- dist/index.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/dist/index.js b/dist/index.js index 61e9175cd..64e5e1869 100644 --- a/dist/index.js +++ b/dist/index.js @@ -142364,7 +142364,7 @@ module.exports = (app, { getRouter }) => { const targetCommitish = commitish || config['commitish'] || ref const { 'filter-by-commitish': filterByCommitish, - 'exclude-pre-releases': excludePreReleases, + 'include-pre-releases': includePreReleases, 'tag-prefix': tagPrefix, } = config @@ -142382,7 +142382,7 @@ module.exports = (app, { getRouter }) => { context, targetCommitish, filterByCommitish, - excludePreReleases, + includePreReleases, tagPrefix, }) @@ -142794,7 +142794,7 @@ const DEFAULT_CONFIG = Object.freeze({ 'sort-direction': SORT_DIRECTIONS.descending, prerelease: false, 'filter-by-commitish': false, - 'exclude-pre-releases': true, + 'include-pre-releases': true, commitish: '', 'category-template': `## $TITLE`, header: '', @@ -142912,7 +142912,7 @@ const findReleases = async ({ context, targetCommitish, filterByCommitish, - excludePreReleases, + includePreReleases, tagPrefix, }) => { let releaseCount = 0 @@ -142945,14 +142945,13 @@ const findReleases = async ({ const filteredReleases = tagPrefix ? commitishFilteredReleases.filter((r) => r.tag_name.startsWith(tagPrefix)) : commitishFilteredReleases - const sortedPublishedReleases = sortReleases( + const sortedSelectedReleases = sortReleases( filteredReleases.filter( - (r) => !r.draft && (!excludePreReleases || !r.prerelease) + (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}` }) @@ -143426,8 +143425,8 @@ const schema = (context) => { DEFAULT_CONFIG['filter-by-commitish'] ), - 'exclude-pre-releases': Joi.boolean().default( - DEFAULT_CONFIG['exclude-pre-releases'] + 'include-pre-releases': Joi.boolean().default( + DEFAULT_CONFIG['include-pre-releases'] ), commitish: Joi.string().allow('').default(DEFAULT_CONFIG['commitish']), From 7f43e55d723c5a353f4c6ab94bdd621991cd7a6f Mon Sep 17 00:00:00 2001 From: Robbin Janssen Date: Sat, 4 Feb 2023 13:23:30 +0100 Subject: [PATCH 10/11] Default should be false --- dist/index.js | 2 +- lib/default-config.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 64e5e1869..f0b23c061 100644 --- a/dist/index.js +++ b/dist/index.js @@ -142794,7 +142794,7 @@ const DEFAULT_CONFIG = Object.freeze({ 'sort-direction': SORT_DIRECTIONS.descending, prerelease: false, 'filter-by-commitish': false, - 'include-pre-releases': true, + 'include-pre-releases': false, commitish: '', 'category-template': `## $TITLE`, header: '', diff --git a/lib/default-config.js b/lib/default-config.js index af88e85e9..bc65a4508 100644 --- a/lib/default-config.js +++ b/lib/default-config.js @@ -26,7 +26,7 @@ const DEFAULT_CONFIG = Object.freeze({ 'sort-direction': SORT_DIRECTIONS.descending, prerelease: false, 'filter-by-commitish': false, - 'include-pre-releases': true, + 'include-pre-releases': false, commitish: '', 'category-template': `## $TITLE`, header: '', From e62f15ec811540db5f891cbe45d8104f536bd796 Mon Sep 17 00:00:00 2001 From: Robbin Janssen Date: Sat, 4 Feb 2023 13:24:40 +0100 Subject: [PATCH 11/11] Small fixes --- schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schema.json b/schema.json index 5802942f2..66ab1148e 100644 --- a/schema.json +++ b/schema.json @@ -122,7 +122,7 @@ "type": "boolean" }, "include-pre-releases": { - "default": true, + "default": false, "type": "boolean" }, "commitish": {