Skip to content

Commit

Permalink
allow header and footer to be passed as input (#1142)
Browse files Browse the repository at this point in the history
  • Loading branch information
jetersen committed May 11, 2022
1 parent c06c2ff commit d481987
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -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

Expand Down
20 changes: 16 additions & 4 deletions dist/index.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -141622,6 +141633,8 @@ const DEFAULT_CONFIG = Object.freeze({
'filter-by-commitish': false,
commitish: '',
'category-template': `## $TITLE`,
header: '',
footer: '',
})

exports.DEFAULT_CONFIG = DEFAULT_CONFIG
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
})
Expand Down
11 changes: 11 additions & 0 deletions index.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
}
Expand Down
2 changes: 2 additions & 0 deletions lib/default-config.js
Expand Up @@ -28,6 +28,8 @@ const DEFAULT_CONFIG = Object.freeze({
'filter-by-commitish': false,
commitish: '',
'category-template': `## $TITLE`,
header: '',
footer: '',
})

exports.DEFAULT_CONFIG = DEFAULT_CONFIG
3 changes: 1 addition & 2 deletions lib/releases.js
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lib/schema.js
Expand Up @@ -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(),
})
Expand Down
22 changes: 20 additions & 2 deletions schema.json
Expand Up @@ -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"
Expand Down
48 changes: 48 additions & 0 deletions test/index.test.js
Expand Up @@ -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', () => {
Expand Down

0 comments on commit d481987

Please sign in to comment.