Skip to content

Commit

Permalink
add and template variables (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eun committed Sep 6, 2021
1 parent f92c808 commit 3b224b0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
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 @@ -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) {
Expand Down Expand Up @@ -322,6 +324,8 @@ module.exports.findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ `
name
}
}
baseRefName @include(if: $withBaseRefName)
headRefName @include(if: $withHeadRefName)
}
}
}
Expand All @@ -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}`
Expand Down Expand Up @@ -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')
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

0 comments on commit 3b224b0

Please sign in to comment.