From 3bc19058001dbbdd774f09eb627a189c88e7336e Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Sun, 16 Jan 2022 19:53:39 +0100 Subject: [PATCH] add owner and repository context to template variables (#1017) --- .github/release-drafter.yml | 3 + README.md | 2 + dist/index.js | 6 ++ index.js | 1 + lib/releases.js | 5 ++ .../config/config-with-compare-link.yml | 12 ++++ test/index.test.js | 58 +++++++++++++++++++ 7 files changed, 87 insertions(+) create mode 100644 test/fixtures/config/config-with-compare-link.yml diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 43f6fc88c..8e176bd27 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -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' diff --git a/README.md b/README.md index 2d6c0c576..76b11519b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/dist/index.js b/dist/index.js index 864605c15..b77a3920a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -132982,6 +132982,7 @@ module.exports = (app, { getRouter }) => { ) const releaseInfo = generateReleaseInfo({ + context, commits, config, lastRelease, @@ -133655,6 +133656,7 @@ const resolveVersionKeyIncrement = (mergedPullRequests, config) => { } const generateReleaseInfo = ({ + context, commits, config, lastRelease, @@ -133666,6 +133668,8 @@ const generateReleaseInfo = ({ shouldDraft, commitish, }) => { + const { owner, repo } = context.repo() + let body = config.template body = template( @@ -133678,6 +133682,8 @@ const generateReleaseInfo = ({ pullRequests: mergedPullRequests, config, }), + $OWNER: owner, + $REPOSITORY: repo, }, config.replacers ) diff --git a/index.js b/index.js index 5dfe1d0f7..5740e8960 100644 --- a/index.js +++ b/index.js @@ -178,6 +178,7 @@ module.exports = (app, { getRouter }) => { ) const releaseInfo = generateReleaseInfo({ + context, commits, config, lastRelease, diff --git a/lib/releases.js b/lib/releases.js index a129708fb..d251ac193 100644 --- a/lib/releases.js +++ b/lib/releases.js @@ -259,6 +259,7 @@ const resolveVersionKeyIncrement = (mergedPullRequests, config) => { } const generateReleaseInfo = ({ + context, commits, config, lastRelease, @@ -270,6 +271,8 @@ const generateReleaseInfo = ({ shouldDraft, commitish, }) => { + const { owner, repo } = context.repo() + let body = config.template body = template( @@ -282,6 +285,8 @@ const generateReleaseInfo = ({ pullRequests: mergedPullRequests, config, }), + $OWNER: owner, + $REPOSITORY: repo, }, config.replacers ) diff --git a/test/fixtures/config/config-with-compare-link.yml b/test/fixtures/config/config-with-compare-link.yml new file mode 100644 index 000000000..f726960e7 --- /dev/null +++ b/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 diff --git a/test/index.test.js b/test/index.test.js index 1f046dd6b..106793605 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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')