Skip to content

Commit

Permalink
add owner and repository context to template variables (#1017)
Browse files Browse the repository at this point in the history
  • Loading branch information
jetersen committed Jan 16, 2022
1 parent 5e4f930 commit 3bc1905
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/release-drafter.yml
Expand Up @@ -4,6 +4,9 @@ template: |
# What's Changed
$CHANGES
**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION
categories:
- title: 'Breaking'
label: 'type: breaking'
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -141,6 +141,8 @@ You can use any of the following variables in your `template`:
| `$CHANGES` | The markdown list of pull requests that have been merged. |
| `$CONTRIBUTORS` | A comma separated list of contributors to this release (pull request authors, commit authors, and commit committers). |
| `$PREVIOUS_TAG` | The previous releases’s tag. |
| `$REPOSITORY` | Current Repository |
| `$OWNER` | Current Repository Owner |

## Category Template Variables

Expand Down
6 changes: 6 additions & 0 deletions dist/index.js
Expand Up @@ -132982,6 +132982,7 @@ module.exports = (app, { getRouter }) => {
)

const releaseInfo = generateReleaseInfo({
context,
commits,
config,
lastRelease,
Expand Down Expand Up @@ -133655,6 +133656,7 @@ const resolveVersionKeyIncrement = (mergedPullRequests, config) => {
}

const generateReleaseInfo = ({
context,
commits,
config,
lastRelease,
Expand All @@ -133666,6 +133668,8 @@ const generateReleaseInfo = ({
shouldDraft,
commitish,
}) => {
const { owner, repo } = context.repo()

let body = config.template

body = template(
Expand All @@ -133678,6 +133682,8 @@ const generateReleaseInfo = ({
pullRequests: mergedPullRequests,
config,
}),
$OWNER: owner,
$REPOSITORY: repo,
},
config.replacers
)
Expand Down
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -178,6 +178,7 @@ module.exports = (app, { getRouter }) => {
)

const releaseInfo = generateReleaseInfo({
context,
commits,
config,
lastRelease,
Expand Down
5 changes: 5 additions & 0 deletions lib/releases.js
Expand Up @@ -259,6 +259,7 @@ const resolveVersionKeyIncrement = (mergedPullRequests, config) => {
}

const generateReleaseInfo = ({
context,
commits,
config,
lastRelease,
Expand All @@ -270,6 +271,8 @@ const generateReleaseInfo = ({
shouldDraft,
commitish,
}) => {
const { owner, repo } = context.repo()

let body = config.template

body = template(
Expand All @@ -282,6 +285,8 @@ const generateReleaseInfo = ({
pullRequests: mergedPullRequests,
config,
}),
$OWNER: owner,
$REPOSITORY: repo,
},
config.replacers
)
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/config/config-with-compare-link.yml
@@ -0,0 +1,12 @@
template: |
# What's Changed
$CHANGES
**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION
categories:
- label: feature
title: 🚀 Features
- label: fix
title: 🐛 Bug Fixes
58 changes: 58 additions & 0 deletions test/index.test.js
Expand Up @@ -861,6 +861,64 @@ describe('release-drafter', () => {
})
})

describe('with owner and repository templating', () => {
it('include full-changelog link in output', async () => {
getConfigMock('config-with-compare-link.yml')

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": "# What's Changed
* Add documentation (#5) @TimonVS
* Update dependencies (#4) @TimonVS
## 🚀 Features
* Add big feature (#2) @TimonVS
* 👽 Add alien technology (#1) @TimonVS
## 🐛 Bug Fixes
* Bug fixes (#3) @TimonVS
**Full Changelog**: https://github.com/toolmantim/release-drafter-test-project/compare/v2.0.0...v2.0.1
",
"draft": true,
"name": "",
"prerelease": false,
"tag_name": "",
"target_commitish": "",
}
`)
return true
}
)
.reply(200, releasePayload)

await probot.receive({
name: 'push',
payload: pushPayload,
})

expect.assertions(1)
})
})

describe('with categories config', () => {
it('categorizes pull requests with single label', async () => {
getConfigMock('config-with-categories.yml')
Expand Down

0 comments on commit 3bc1905

Please sign in to comment.