diff --git a/README.md b/README.md index 58c0bb573..175932a57 100644 --- a/README.md +++ b/README.md @@ -192,13 +192,15 @@ If a pull requests is found with the label `major`/`minor`/`patch`, the correspo You can use any of the following variables in `change-template`: -| Variable | Description | -| --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `$NUMBER` | The number of the pull request, e.g. `42`. | -| `$TITLE` | The title of the pull request, e.g. `Add alien technology`. Any characters excluding @ and # matching `change-title-escapes` will be prepended with a backslash so that they will appear verbatim instead of being interpreted as markdown format characters. @s and #s if present in `change-title-escapes` will be appended with an HTML comment so that they don't become mentions. | -| `$AUTHOR` | The pull request author’s username, e.g. `gracehopper`. | -| `$BODY` | The body of the pull request e.g. `Fixed spelling mistake`. | -| `$URL` | The URL of the pull request e.g. `https://github.com/octocat/repo/pull/42`. | +| Variable | Description | +| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `$NUMBER` | The number of the pull request, e.g. `42`. | +| `$TITLE` | The title of the pull request, e.g. `Add alien technology`. Any characters excluding @ and # matching `change-title-escapes` will be prepended with a backslash so that they will appear verbatim instead of being interpreted as markdown format characters. @s and #s if present in `change-title-escapes` will be appended with an HTML comment so that they don't become mentions. | +| `$AUTHOR` | The pull request author’s username, e.g. `gracehopper`. | +| `$BODY` | The body of the pull request e.g. `Fixed spelling mistake`. | +| `$URL` | The URL of the pull request e.g. `https://github.com/octocat/repo/pull/42`. | +| `$BASE_REF_NAME` | The base name of of the base Ref associated with the pull request e.g. `master`. | +| `$HEAD_REF_NAME` | The head name of the head Ref associated with the pull request e.g. `my-bug-fix`. | ## References diff --git a/dist/index.js b/dist/index.js index 2b98e7b2a..69cb54a37 100644 --- a/dist/index.js +++ b/dist/index.js @@ -283,6 +283,8 @@ module.exports.findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ ` $withPullRequestURL: Boolean! $since: GitTimestamp $after: String + $withBaseRefName: Boolean! + $withHeadRefName: Boolean! ) { repository(name: $name, owner: $owner) { object(expression: $ref) { @@ -322,6 +324,8 @@ module.exports.findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ ` name } } + baseRefName @include(if: $withBaseRefName) + headRefName @include(if: $withHeadRefName) } } } @@ -345,6 +349,8 @@ module.exports.findCommitsWithAssociatedPullRequests = async ({ ref, withPullRequestBody: config['change-template'].includes('$BODY'), withPullRequestURL: config['change-template'].includes('$URL'), + withBaseRefName: config['change-template'].includes('$BASE_REF_NAME'), + withHeadRefName: config['change-template'].includes('$HEAD_REF_NAME'), } const dataPath = ['repository', 'object', 'history'] const repoNameWithOwner = `${owner}/${repo}` @@ -749,6 +755,8 @@ const generateChangeLog = (mergedPullRequests, config) => { $AUTHOR: pullRequest.author ? pullRequest.author.login : 'ghost', $BODY: pullRequest.body, $URL: pullRequest.url, + $BASE_REF_NAME: pullRequest.baseRefName, + $HEAD_REF_NAME: pullRequest.headRefName, }) ) .join('\n') diff --git a/lib/commits.js b/lib/commits.js index 3569cb2c9..2e345e33f 100644 --- a/lib/commits.js +++ b/lib/commits.js @@ -11,6 +11,8 @@ module.exports.findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ ` $withPullRequestURL: Boolean! $since: GitTimestamp $after: String + $withBaseRefName: Boolean! + $withHeadRefName: Boolean! ) { repository(name: $name, owner: $owner) { object(expression: $ref) { @@ -50,6 +52,8 @@ module.exports.findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ ` name } } + baseRefName @include(if: $withBaseRefName) + headRefName @include(if: $withHeadRefName) } } } @@ -73,6 +77,8 @@ module.exports.findCommitsWithAssociatedPullRequests = async ({ ref, withPullRequestBody: config['change-template'].includes('$BODY'), withPullRequestURL: config['change-template'].includes('$URL'), + withBaseRefName: config['change-template'].includes('$BASE_REF_NAME'), + withHeadRefName: config['change-template'].includes('$HEAD_REF_NAME'), } const dataPath = ['repository', 'object', 'history'] const repoNameWithOwner = `${owner}/${repo}` diff --git a/lib/releases.js b/lib/releases.js index fe4c73c0b..717c14dfe 100644 --- a/lib/releases.js +++ b/lib/releases.js @@ -186,6 +186,8 @@ const generateChangeLog = (mergedPullRequests, config) => { $AUTHOR: pullRequest.author ? pullRequest.author.login : 'ghost', $BODY: pullRequest.body, $URL: pullRequest.url, + $BASE_REF_NAME: pullRequest.baseRefName, + $HEAD_REF_NAME: pullRequest.headRefName, }) ) .join('\n') diff --git a/test/releases.test.js b/test/releases.test.js index 27576df54..4353607ea 100644 --- a/test/releases.test.js +++ b/test/releases.test.js @@ -8,6 +8,8 @@ const pullRequests = [ body: 'A1 body', url: 'https://github.com', labels: { nodes: [{ name: 'bug' }] }, + baseRefName: 'master', + headRefName: 'fix-bug', }, { title: 'B2', @@ -15,6 +17,8 @@ const pullRequests = [ body: 'B2 body', url: 'https://github.com', labels: { nodes: [{ name: 'feature' }] }, + baseRefName: 'master', + headRefName: 'implement-feature', }, { title: 'Adds missing ', @@ -23,6 +27,8 @@ const pullRequests = [ url: 'https://github.com', labels: { nodes: [{ name: 'bug' }] }, author: { login: 'jetersen' }, + baseRefName: 'master', + headRefName: 'fix-bug', }, { title: '`#code_block`', @@ -31,6 +37,8 @@ const pullRequests = [ url: 'https://github.com', labels: { nodes: [{ name: 'bug' }] }, author: { login: 'jetersen' }, + baseRefName: 'master', + headRefName: 'fix-bug', }, { title: 'Fixes #4', @@ -39,6 +47,8 @@ const pullRequests = [ url: 'https://github.com', labels: { nodes: [{ name: 'bug' }] }, author: { login: 'Happypig375' }, + baseRefName: 'master', + headRefName: 'fix-bug', }, { title: '2*2 should equal to 4*1', @@ -47,6 +57,8 @@ const pullRequests = [ url: 'https://github.com', labels: { nodes: [{ name: 'bug' }] }, author: { login: 'jetersen' }, + baseRefName: 'master', + headRefName: 'fix-bug', }, { title: 'Rename __confgs\\confg.yml to __configs\\config.yml', @@ -55,6 +67,8 @@ const pullRequests = [ url: 'https://github.com', labels: { nodes: [{ name: 'bugfix' }] }, author: { login: 'ghost' }, + baseRefName: 'master', + headRefName: 'fix-bug', }, { title: 'Adds @nullable annotations to the 1*1+2*4 test in `tests.java`', @@ -63,6 +77,8 @@ const pullRequests = [ url: 'https://github.com', labels: { nodes: [{ name: 'feature' }] }, author: { login: 'Happypig375' }, + baseRefName: 'master', + headRefName: 'implement-feature', }, ] const baseConfig = {