mirror of
https://github.com/ButlerLogic/action-autotag.git
synced 2024-11-10 02:11:08 +07:00
Added simplistic commit message template
This commit is contained in:
parent
b30eee1686
commit
f0d209c27a
20
README.md
20
README.md
@ -121,6 +121,26 @@ This is the annotated commit message associated with the tag. By default, a chan
|
||||
tag_message: "Custom message goes here."
|
||||
```
|
||||
|
||||
#### commit_message_template
|
||||
|
||||
By default, a changelog is generated, containing the commit messages since the last release. The message is generated by applying a commit message template to each commit's data attributes.
|
||||
|
||||
```yaml
|
||||
- uses: butlerlogic/action-autotag@1.0.0
|
||||
with:
|
||||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
||||
commit_message_template: "({{sha}} by {{author}}) {{message}}"
|
||||
```
|
||||
|
||||
Optional data points:
|
||||
|
||||
1. `number` The commit number (relevant to the overall list)
|
||||
1. `message` The commit message.
|
||||
1. `author` The author of the commit.
|
||||
1. `sha` The SHA value representing the commit.
|
||||
|
||||
The default is `{{number}}) {{message}} ({{author}})\nSHA: {{sha}}\n`.
|
||||
|
||||
#### version
|
||||
|
||||
Explicitly set the version instead of using automatic detection.
|
||||
|
@ -25,6 +25,9 @@ inputs:
|
||||
tag_message:
|
||||
description: This is the annotated commit message associated with the tag. By default, a changelog will be generated from the commits between the latest tag and the new tag (HEAD). This will override that with a hard-coded message.
|
||||
required: false
|
||||
commit_message_template:
|
||||
description: "The commit message template (per commit). Default is `{{number}}) {{message}} ({{author}})\nSHA: {{sha}}\n`"
|
||||
required: false
|
||||
version:
|
||||
description: Explicitly set the version here instead of automatically detecting from `package.json`. Useful for non-JavaScript projects where version may be output by a previous action.
|
||||
required: false
|
||||
|
@ -55,18 +55,28 @@ export default class Tag {
|
||||
}
|
||||
|
||||
const changelog = await github.repos.compareCommits({ owner, repo, base: tags.shift().name, head: 'master' })
|
||||
const tpl = (core.getInput('commit_message_template', { required: false }) || '').trim()
|
||||
|
||||
return changelog.data.commits
|
||||
.map(
|
||||
(commit, i) =>
|
||||
`${i === 0 ? '\n' : ''}${i + 1}) ${commit.commit.message}${
|
||||
commit.hasOwnProperty('author')
|
||||
? commit.author.hasOwnProperty('login')
|
||||
? ' (' + commit.author.login + ')'
|
||||
(commit, i) => {
|
||||
if (tpl.length > 0) {
|
||||
return tpl
|
||||
.replace(/\{\{\s?(number)\s?\}\}/gi, i + 1)
|
||||
.replace(/\{\{\s?(message)\s?\}\}/gi, commit.commit.message)
|
||||
.replace(/\{\{\s?(author)\s?\}\}/gi, commit.hasOwnProperty('author') ? (commit.author.hasOwnProperty('login') ? commit.author.login : '') : '')
|
||||
.replace(/\{\{\s?(sha)\s?\}\}/gi, commit.sha)
|
||||
.trim() + '\n'
|
||||
} else {
|
||||
return `${i === 0 ? '\n' : ''}${i + 1}) ${commit.commit.message}${
|
||||
commit.hasOwnProperty('author')
|
||||
? commit.author.hasOwnProperty('login')
|
||||
? ' (' + commit.author.login + ')'
|
||||
: ''
|
||||
: ''
|
||||
: ''
|
||||
}\n(SHA: ${commit.sha})\n`
|
||||
)
|
||||
}\n(SHA: ${commit.sha})\n`
|
||||
}
|
||||
})
|
||||
.join('\n')
|
||||
} catch (e) {
|
||||
core.warning('Failed to generate changelog from commits: ' + e.message + os.EOL)
|
||||
|
Loading…
Reference in New Issue
Block a user