Skip to content

Commit 37154d8

Browse files
committed
Add support for custom changelog format (#1)
* feat: add changelog_structure * feat: bump minor version
1 parent 3071dd0 commit 37154d8

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ inputs:
1818
tag_message:
1919
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.
2020
required: false
21+
changelog_structure:
22+
description: "A string denoting changelog format. Supports `{{message}}`, `{{author}}` and `{{sha}}`. Defaults to `**1) {{message}}** {{author}}\n(SHA: {{sha}})\n` Only used when tag_message is empty."
23+
required: false
2124
version:
2225
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.
2326
required: false

lib/main.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ async function run() {
6565

6666
const tagPrefix = core.getInput('tag_prefix', { required: false })
6767
const tagSuffix = core.getInput('tag_suffix', { required: false })
68-
68+
const changelogStructure = core.getInput('changelog_structure', { required: false })
69+
6970
const getTagName = version => {
7071
return `${tagPrefix}${version}${tagSuffix}`
7172
}
@@ -93,17 +94,17 @@ async function run() {
9394
base: latestTag.name,
9495
head: 'master',
9596
})
97+
const structure = changelogStructure || `**1) {{message}}** {{author}}\n(SHA: {{sha}})\n`
9698

9799
tagMsg = changelog.data.commits
98100
.map(
99101
commit =>
100-
`**1) ${commit.commit.message}**${
101-
commit.hasOwnProperty('author')
102-
? commit.author.hasOwnProperty('login')
103-
? ' (' + commit.author.login + ')'
104-
: ''
105-
: ''
106-
}\n(SHA: ${commit.sha})\n`
102+
structure
103+
.replace(/({{message}})|({{author}})|({{sha}})/g, (match, message, author, sha) => {
104+
if (message) return commit.commit.message
105+
if (author) return !commit.hasOwnProperty('author') || !commit.author.hasOwnProperty('login') ? '' : commit.author.login
106+
if (sha) return commit.sha
107+
})
107108
)
108109
.join('\n')
109110
} catch (e) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "autotag-action",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"private": true,
55
"description": "Automatically create a tag whenever the version changes in package.json",
66
"main": "lib/main.js",

0 commit comments

Comments
 (0)