diff --git a/README.md b/README.md index 248e633f0..6ef2a1187 100644 --- a/README.md +++ b/README.md @@ -347,6 +347,8 @@ The Release Drafter GitHub Action accepts a number of optional inputs directly i | `publish` | A boolean indicating whether the release being created or updated should be immediately published. This may be useful if the output of a previous workflow step determines that a new version of your project has been (or will be) released, as with [`salsify/action-detect-and-tag-new-version`](https://github.com/salsify/action-detect-and-tag-new-version). | | `prerelease` | A boolean indicating whether the release being created or updated is a prerelease. | | `commitish` | A string specifying the target branch for the release being created. | +| `header` | A string that would be added before the template body. | +| `footer` | A string that would be added after the template body. | ## Action Outputs diff --git a/dist/index.js b/dist/index.js index 779f87df4..04592c17c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -141206,6 +141206,16 @@ module.exports = (app, { getRouter }) => { 'tag-prefix': tagPrefix, } = config + // override header and footer when passed as input + const header = core.getInput('header') + const footer = core.getInput('footer') + if (header) { + config['header'] = header + } + if (footer) { + config['footer'] = footer + } + const { draftRelease, lastRelease } = await findReleases({ context, targetCommitish, @@ -141291,6 +141301,7 @@ function getInput({ config } = {}) { // Merges the config file with the input // the input takes precedence, because it's more easy to change at runtime const preRelease = core.getInput('prerelease').toLowerCase() + return { isPreRelease: preRelease === 'true' || (!preRelease && config.prerelease), } @@ -141622,6 +141633,8 @@ const DEFAULT_CONFIG = Object.freeze({ 'filter-by-commitish': false, commitish: '', 'category-template': `## $TITLE`, + header: '', + footer: '', }) exports.DEFAULT_CONFIG = DEFAULT_CONFIG @@ -142033,8 +142046,7 @@ const generateReleaseInfo = ({ }) => { const { owner, repo } = context.repo() - let body = - (config['header'] || '') + config.template + (config['footer'] || '') + let body = config['header'] + config.template + config['footer'] body = template( body, @@ -142323,11 +142335,11 @@ const schema = (context) => { .allow('') .default(DEFAULT_CONFIG['category-template']), - header: Joi.string(), + header: Joi.string().allow('').default(DEFAULT_CONFIG.header), template: Joi.string().required(), - footer: Joi.string(), + footer: Joi.string().allow('').default(DEFAULT_CONFIG.footer), _extends: Joi.string(), }) diff --git a/index.js b/index.js index e732ec663..52c872c16 100644 --- a/index.js +++ b/index.js @@ -164,6 +164,16 @@ module.exports = (app, { getRouter }) => { 'tag-prefix': tagPrefix, } = config + // override header and footer when passed as input + const header = core.getInput('header') + const footer = core.getInput('footer') + if (header) { + config['header'] = header + } + if (footer) { + config['footer'] = footer + } + const { draftRelease, lastRelease } = await findReleases({ context, targetCommitish, @@ -249,6 +259,7 @@ function getInput({ config } = {}) { // Merges the config file with the input // the input takes precedence, because it's more easy to change at runtime const preRelease = core.getInput('prerelease').toLowerCase() + return { isPreRelease: preRelease === 'true' || (!preRelease && config.prerelease), } diff --git a/lib/default-config.js b/lib/default-config.js index a27d66a41..5affa9465 100644 --- a/lib/default-config.js +++ b/lib/default-config.js @@ -28,6 +28,8 @@ const DEFAULT_CONFIG = Object.freeze({ 'filter-by-commitish': false, commitish: '', 'category-template': `## $TITLE`, + header: '', + footer: '', }) exports.DEFAULT_CONFIG = DEFAULT_CONFIG diff --git a/lib/releases.js b/lib/releases.js index 6cae5870b..db3a38f7a 100644 --- a/lib/releases.js +++ b/lib/releases.js @@ -322,8 +322,7 @@ const generateReleaseInfo = ({ }) => { const { owner, repo } = context.repo() - let body = - (config['header'] || '') + config.template + (config['footer'] || '') + let body = config['header'] + config.template + config['footer'] body = template( body, diff --git a/lib/schema.js b/lib/schema.js index 41a1e917e..60dd8209a 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -156,11 +156,11 @@ const schema = (context) => { .allow('') .default(DEFAULT_CONFIG['category-template']), - header: Joi.string(), + header: Joi.string().allow('').default(DEFAULT_CONFIG.header), template: Joi.string().required(), - footer: Joi.string(), + footer: Joi.string().allow('').default(DEFAULT_CONFIG.footer), _extends: Joi.string(), }) diff --git a/schema.json b/schema.json index 39a98b095..22ef087af 100644 --- a/schema.json +++ b/schema.json @@ -311,13 +311,31 @@ ] }, "header": { - "type": "string" + "anyOf": [ + { + "type": "string", + "enum": [""] + }, + { + "default": "", + "type": "string" + } + ] }, "template": { "type": "string" }, "footer": { - "type": "string" + "anyOf": [ + { + "type": "string", + "enum": [""] + }, + { + "default": "", + "type": "string" + } + ] }, "_extends": { "type": "string" diff --git a/test/index.test.js b/test/index.test.js index 3057890d3..812f87856 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1654,6 +1654,54 @@ describe('release-drafter', () => { expect.assertions(1) }) + it('only header from input', async () => { + getConfigMock('config-with-header-template.yml') + + let restoreEnvironment = mockedEnv({ + INPUT_HEADER: + 'I AM AWESOME_mockenv_strips_newline_and_trailing_spaces_', + }) + + nock('https://api.github.com') + .get('/repos/toolmantim/release-drafter-test-project/releases') + .query(true) + .reply(200, [releasePayload]) + + 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": "I AM AWESOME_mockenv_strips_newline_and_trailing_spaces_This is the template in the middle + ", + "draft": true, + "name": "", + "prerelease": false, + "tag_name": "", + "target_commitish": "refs/heads/master", + } + `) + return true + } + ) + .reply(200, releasePayload) + + await probot.receive({ + name: 'push', + payload: pushPayload, + }) + + expect.assertions(1) + + restoreEnvironment() + }) }) describe('merging strategies', () => {