Skip to content

Commit

Permalink
chore: updated auto-changelog template
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhom committed Dec 15, 2020
1 parent 113da47 commit d78f220
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 15 deletions.
8 changes: 4 additions & 4 deletions .release-it.json
Expand Up @@ -3,11 +3,11 @@
"push": true,
"tagName": "v${version}",
"commitMessage": "chore: release v${version}",
"changelog": "auto-changelog --stdout --commit-limit false --ignore-commit-pattern \"^chore: release v\" --unreleased --template ./release-template.hbs --tag-pattern \"^v\\d+\\.\\d+\\.\\d+$\""
"changelog": "auto-changelog --stdout --commit-limit false --ignore-commit-pattern \"^chore: release v\" --unreleased --template ./release-template.hbs --tag-pattern \"^v\\d+\\.\\d+\\.\\d+$\" --handlebars-setup ./scripts/auto-changelog.js"
},
"github": {
"release": true,
"releaseNotes": "auto-changelog --stdout --commit-limit false --ignore-commit-pattern \"^chore: release v\" --unreleased --template ./release-template.hbs --tag-pattern \"^v\\d+\\.\\d+\\.\\d+$\""
"releaseNotes": "auto-changelog --stdout --commit-limit false --ignore-commit-pattern \"^chore: release v\" --unreleased --template ./release-template.hbs --tag-pattern \"^v\\d+\\.\\d+\\.\\d+$\" --handlebars-setup ./scripts/auto-changelog.js"
},
"npm": {
"publish": false
Expand All @@ -18,6 +18,6 @@
}
},
"hooks": {
"after:bump": "auto-changelog -p --ignore-commit-pattern \"^chore: release v\" --template \"keepachangelog\" --tag-pattern \"^v\\d+\\.\\d+\\.\\d+$\""
"after:bump": "auto-changelog -p --ignore-commit-pattern \"^chore: release v\" --template ./release-template.hbs --tag-pattern \"^v\\d+\\.\\d+\\.\\d+$\" --handlebars-setup ./scripts/auto-changelog.js"
}
}
}
48 changes: 37 additions & 11 deletions release-template.hbs
@@ -1,13 +1,39 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

{{#unless options.hideCredit}}
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
{{/unless}}

{{#each releases}}
{{#if @first}}
{{#each merges}}
- {{{message}}}{{#if href}} [`#{{id}}`]({{href}}){{/if}}
{{/each}}
{{#each fixes}}
- {{{commit.subject}}}{{#each fixes}}{{#if href}} [`#{{id}}`]({{href}}){{/if}}{{/each}}
{{/each}}
{{#each commits}}
- {{#if breaking}}**Breaking change:** {{/if}}{{{subject}}}{{#if href}} [`{{shorthash}}`]({{href}}){{/if}}
{{/each}}
{{/if}}
{{#if href}}
## [{{title}}]({{href}}){{#if tag}} - {{isoDate}}{{/if}}
{{else}}
## {{title}}{{#if tag}} - {{isoDate}}{{/if}}
{{/if}}

{{#if summary}}
{{summary}}
{{/if}}

{{#custom merges commits heading="#### Features" subject="feat: "}}
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
{{/custom}}

{{#custom merges commits heading="#### Improvements" subject="(chore|refactor|style): "}}
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
{{/custom}}

{{#custom merges commits heading="#### Fixes" subject="fix: "}}
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
{{/custom}}

{{#custom merges commits heading="#### Documentations" subject="docs: "}}
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
{{/custom}}

{{/each}}
37 changes: 37 additions & 0 deletions scripts/auto-changelog.js
@@ -0,0 +1,37 @@
module.exports = function (Handlebars) {
Handlebars.registerHelper('custom', function (context, extra, options) {
if ((!context || context.length === 0) && (!extra || extra.length === 0)) {
return '';
}

const list = [...context, ...extra]
.filter(item => {
const commit = item.commit || item;
if (options.hash.exclude) {
const pattern = new RegExp(options.hash.exclude, 'm');
if (pattern.test(commit.message)) {
return false;
}
}
if (options.hash.message) {
const pattern = new RegExp(options.hash.message, 'm');
return pattern.test(commit.message);
}
if (options.hash.subject) {
const pattern = new RegExp(options.hash.subject);
return pattern.test(commit.subject);
}
return true;
})
.map(item => options.fn(item))
.join('');

if (!list) {
return '';
}

return options.hash.heading
? `${options.hash.heading}\n\n${list}`
: `${list}`;
});
};

0 comments on commit d78f220

Please sign in to comment.