Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add BASE_REF_NAME and HEAD_REF_NAME template variables #816

Merged
merged 1 commit into from Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 9 additions & 7 deletions README.md
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions dist/index.js
Expand Up @@ -298,6 +298,8 @@ module.exports.findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ `
$withPullRequestURL: Boolean!
$since: GitTimestamp
$after: String
$withBaseRefName: Boolean!
$withHeadRefName: Boolean!
) {
repository(name: $name, owner: $owner) {
object(expression: $ref) {
Expand Down Expand Up @@ -337,6 +339,8 @@ module.exports.findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ `
name
}
}
baseRefName @include(if: $withBaseRefName)
headRefName @include(if: $withHeadRefName)
}
}
}
Expand All @@ -360,6 +364,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}`
Expand Down Expand Up @@ -764,6 +770,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')
Expand Down
6 changes: 6 additions & 0 deletions lib/commits.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -50,6 +52,8 @@ module.exports.findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ `
name
}
}
baseRefName @include(if: $withBaseRefName)
headRefName @include(if: $withHeadRefName)
}
}
}
Expand All @@ -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}`
Expand Down
2 changes: 2 additions & 0 deletions lib/releases.js
Expand Up @@ -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')
Expand Down
16 changes: 16 additions & 0 deletions test/releases.test.js
Expand Up @@ -8,13 +8,17 @@ const pullRequests = [
body: 'A1 body',
url: 'https://github.com',
labels: { nodes: [{ name: 'bug' }] },
baseRefName: 'master',
headRefName: 'fix-bug',
},
{
title: 'B2',
number: 2,
body: 'B2 body',
url: 'https://github.com',
labels: { nodes: [{ name: 'feature' }] },
baseRefName: 'master',
headRefName: 'implement-feature',
},
{
title: 'Adds missing <example>',
Expand All @@ -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`',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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`',
Expand All @@ -63,6 +77,8 @@ const pullRequests = [
url: 'https://github.com',
labels: { nodes: [{ name: 'feature' }] },
author: { login: 'Happypig375' },
baseRefName: 'master',
headRefName: 'implement-feature',
},
]
const baseConfig = {
Expand Down