Skip to content

Commit

Permalink
chore: updated changelog script and templates
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhom committed Sep 19, 2022
1 parent 657ca33 commit ee6230c
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 52 deletions.
24 changes: 22 additions & 2 deletions .auto-changelog
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
{
"handlebarsSetup": "./scripts/auto-changelog.js",
"ignoreCommitPattern": "^chore: release v",
"ignoreCommitPattern": "release v",
"startingVersion": "v4.0.0-alpha.0",
"unreleased": false,
"commitLimit": false
"commitLimit": false,
"replaceText": {
"([bB]reaking: )": "",
"([bB]reaking change: )": "",
"(^[fF]eat: )": "",
"(^[fF]eat\\()": "(",
"(^[fF]ix: )": "",
"(^[fF]ix\\()": "(",
"(^[cC]hore: )": "",
"(^[cC]hore\\()": "(",
"(^[dD]ocs: )": "",
"(^[dD]ocs\\()": "(",
"(^[rR]efactor: )": "",
"(^[rR]efactor\\()": "(",
"(^[tT]est: )": "",
"(^[tT]est\\()": "(",
"(^[sS]tyle: )": "",
"(^[sS]tyle\\()": "(",
"(^[pP]erf: )": "",
"(^[pP]erf\\()": "("
}
}
69 changes: 38 additions & 31 deletions scripts/auto-changelog.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
module.exports = function (Handlebars) {
Handlebars.registerHelper('custom', function (context, extra, options) {
if ((!context || context.length === 0) && (!extra || extra.length === 0)) {
return '';
}
Handlebars.registerHelper(
'custom',
function (context, merges, fixes, options) {
if (
(!context || context.length === 0) &&
(!merges || merges.length === 0) &&
(!fixes || fixes.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;
const list = [...context, ...(merges || []), ...(fixes || [])]
.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);
}
}
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('');
return true;
})
.map(item => options.fn(item.commit || item))
.join('');

if (!list) {
return '';
}
if (!list) {
return '';
}

return options.hash.heading
? `${options.hash.heading}\n\n${list}`
: `${list}`;
});
return options.hash.heading
? `${options.hash.heading}\n\n${list}`
: `${list}`;
}
);
};
114 changes: 103 additions & 11 deletions templates/changelog-template.hbs
Original file line number Diff line number Diff line change
@@ -1,30 +1,122 @@
# Changelog
## Changelog

{{!--
Introduction
• This template tries to follow conventional commits format https://www.conventionalcommits.org/en/v1.0.0/
• The template uses regex to filter commit types into their own headings (this is more than just fixes and features headings)
• It also uses the replaceText function in package.json to remove the commit type text from the message, because the headers are shown instead.
• The text 'Breaking:' or 'Breaking changes:' can be located anywhere in the commit.
• The types feat:, fix:, chore:, docs:, refactor:, test:, style:, perf: must be at the beginning of the commit subject with an : on end.
• They can optionally have a scope set to outline the module or component that is affected eg feat(bldAssess):
• There is a short hash on the end of every commit that is currently commented out so that change log did not grow too long (due to some system's file size limitations). You can uncomment if you wish [`{{shorthash}}`]({{href}})
Example Definitions
• feat: A new feature
• fix: A bug fix
• perf: A code change that improves performance
• refactor: A code change that neither fixes a bug nor adds a feature
• style: Changes that do not affect the meaning of the code (white-space, formatting, spelling mistakes, missing semi-colons, etc)
• test: Adding missing tests or correcting existing tests
• docs: Adding/updating documentation
• chore: Something like updating a library version, or moving files to be in a better location and updating all file refs
--}}


{{!-- In package.json need to add this to remove label text from the change log output (because the markdown headers are now used to group them).
NOTES • Individual brackets have been escaped twice to be Json compliant.
• For items that define a scope eg feat(bldAssess): We remove the 1st bracket and then re-add it so we can select the right piece of text
{
"name": "my-awesome-package",
"auto-changelog": {
"replaceText": {
"([bB]reaking:)": "",
"([bB]reaking change:)": "",
"(^[fF]eat:)": "",
"(^[fF]eat\\()": "\\(",
"(^[fF]ix:)": "",
"(^[fF]ix\\()": "\\(",
"(^[cC]hore:)": "",
"(^[cC]hore\\()": "\\(",
"(^[dD]ocs:)": "",
"(^[dD]ocs\\()": "\\(",
"(^[rR]efactor:)": "",
"(^[rR]efactor\\()": "\\(",
"(^[tT]est:)": "",
"(^[tT]est\\()": "\\(",
"(^[sS]tyle:)": "",
"(^[sS]tyle\\()": "\\(",
"(^[pP]erf:)": "",
"(^[pP]erf\\()": "\\("
}
}
}
--}}

{{!--
Regex reminders
^ = starts with
\( = ( character (otherwise it is interpreted as a regex lookup group)
* = zero or more of the previous character
\s = whitespace
. = any character except newline
| = or
[aA] = character a or character A
--}}


{{#each releases}}
{{#if href}}
## [{{title}}]({{href}}){{#if tag}} - {{isoDate}}{{/if}}
##{{#unless major}}#{{/unless}} [{{title}}]({{href}}) - {{#if tag}} {{niceDate}} {{/if}}

{{else}}
## {{title}}{{#if tag}} - {{isoDate}}{{/if}}
### {{title}}
{{/if}}

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

{{#custom merges commits heading="#### Features" subject="feat: "}}
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
{{#custom merges fixes commits heading='#### Breaking Changes :warning:' message='[bB]reaking [cC]hange:|[bB]reaking:' }}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{#custom merges fixes commits heading='#### New Features' message='^[fF]eat:|[fF]eat\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{#custom merges fixes commits heading='#### Fixes' message='^[fF]ix:|^[fF]ix\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{#custom merges fixes commits heading='#### Documentation Changes' message='^[dD]ocs:|^[dD]ocs\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{#custom merges fixes commits heading='#### Refactoring and Updates' message='^[rR]efactor:|^[rR]efactor\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{#custom merges fixes commits heading='#### Changes to Test Assets' message='^[tT]est:|^[tT]est\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{#custom merges fixes commits heading='#### Tidying of Code eg Whitespace' message='^[sS]tyle:|^[sS]tyle\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{#custom merges commits heading="#### Improvements" subject="(chore|refactor|style): "}}
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
{{#custom merges fixes commits heading='#### Performance Improvements' message='^[pP]erf:|^[pP]erf\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{#custom merges commits heading="#### Fixes" subject="fix: "}}
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
{{#custom merges fixes commits heading='#### Chores And Housekeeping' message='^[cC]hore:|^[cC]hore\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{#custom merges commits heading="#### Documentations" subject="docs: "}}
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
{{#custom merges fixes commits heading='#### General Changes' exclude='[bB]reaking [cC]hange:|[bB]reaking:|^[fF]eat:|^[fF]eat\(|^[fF]ix:|^[fF]ix\(|^[cC]hore:|^[cC]hore\(|^[dD]ocs:|^[dD]ocs\(|^[rR]efactor:|^[rR]efactor\(|^[tT]est:|^[tT]est\(|^[sS]tyle:|^[sS]tyle\(|^[pP]erf:|^[pP]erf\('}}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{/each}}
40 changes: 32 additions & 8 deletions templates/release-template.hbs
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
{{#each releases}}
{{#if @first}}
{{#custom merges commits heading="#### Features" subject="feat: "}}
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
{{#custom merges fixes commits heading='#### Breaking Changes :warning:' message='[bB]reaking [cC]hange:|[bB]reaking:' }}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{#custom merges commits heading="#### Improvements" subject="(chore|refactor|style): "}}
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
{{#custom merges fixes commits heading='#### New Features' message='^[fF]eat:|[fF]eat\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{#custom merges commits heading="#### Fixes" subject="fix: "}}
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
{{#custom merges fixes commits heading='#### Fixes' message='^[fF]ix:|^[fF]ix\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{#custom merges commits heading="#### Documentations" subject="docs: "}}
- {{message}} ({{#if id}}[`#{{id}}`]{{else}}[{{shorthash}}]{{/if}}({{href}})).
{{#custom merges fixes commits heading='#### Documentation Changes' message='^[dD]ocs:|^[dD]ocs\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{#custom merges fixes commits heading='#### Refactoring and Updates' message='^[rR]efactor:|^[rR]efactor\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{#custom merges fixes commits heading='#### Changes to Test Assets' message='^[tT]est:|^[tT]est\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{#custom merges fixes commits heading='#### Tidying of Code eg Whitespace' message='^[sS]tyle:|^[sS]tyle\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{#custom merges fixes commits heading='#### Performance Improvements' message='^[pP]erf:|^[pP]erf\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{#custom merges fixes commits heading='#### Chores And Housekeeping' message='^[cC]hore:|^[cC]hore\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}

{{#custom merges fixes commits heading='#### General Changes' exclude='[bB]reaking [cC]hange:|[bB]reaking:|^[fF]eat:|^[fF]eat\(|^[fF]ix:|^[fF]ix\(|^[cC]hore:|^[cC]hore\(|^[dD]ocs:|^[dD]ocs\(|^[rR]efactor:|^[rR]efactor\(|^[tT]est:|^[tT]est\(|^[sS]tyle:|^[sS]tyle\(|^[pP]erf:|^[pP]erf\('}}
- {{subject}} ([`{{shorthash}}`]({{href}}))
{{/custom}}
{{/if}}
{{/each}}

0 comments on commit ee6230c

Please sign in to comment.