Skip to content

Commit

Permalink
🔧 Chore: improve auto changelog configuration
Browse files Browse the repository at this point in the history
Resolved #434
  • Loading branch information
Lruihao committed Apr 22, 2024
1 parent 429698a commit 7f19569
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 53 deletions.
10 changes: 0 additions & 10 deletions .auto-changelog

This file was deleted.

22 changes: 22 additions & 0 deletions .auto-changelog/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"output": "CHANGELOG.md",
"template": ".auto-changelog/template.hbs",
"handlebarsSetup": ".auto-changelog/setup.js",
"sortCommits": "relevance",
"package": true,
"unreleased": true,
"commitLimit": false,
"unreleasedOnly": true,
"replaceText": {
"#(\\d+)": "[#$1](https://github.com/hugo-fixit/FixIt/issues/$1)",
"^(Feat|feat):": ":sparkles: Feat:",
"^(Fix|fix):": ":bug: Fix:",
"^(Build|build):": ":hammer: Build:",
"^(Refactor|refactor):": ":recycle: Refactor:",
"^(Style|style):": ":lipstick: Style:",
"^(Perf|perf):": ":zap: Perf:",
"^(Test|test):": ":white_check_mark: Test:",
"^(Docs|docs):": ":memo: Docs:",
"^(Chore|chore):": ":wrench: Chore:"
}
}
31 changes: 31 additions & 0 deletions .auto-changelog/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Custom Handlebars helpers
module.exports = function (Handlebars) {
/**
* Handlebars helper to replace a string with another string
* @param {String} context the string to replace
* @param {Object} options
* @param {String} options.hash.from the string to replace
* @param {String} options.hash.to the string to replace with
* @example {{replace "foo bar" from="foo" to="baz"}} => "baz bar"
*/
Handlebars.registerHelper('replace', function (context, options) {
return context.replace(options.hash.from, options.hash.to)
})
/**
* Handlebars helper to convert a name to a GitHub username
* @param {String} context name to convert
* @param {Object} options
* @param {Boolean} [options.hash.linked=true] whether to return a linked username
* @example {{githubUser "Cell"}} => "Lruihao"
*/
Handlebars.registerHelper('githubUser', function (context, { hash: { linked = true }}) {
const map = {
'Cell': "Lruihao",
}
const username = map[context] || context
if (linked) {
return `[@${username}](https://github.com/${username})`
}
return `@${username}`
})
}
68 changes: 68 additions & 0 deletions .auto-changelog/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Changelog

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

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

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

{{!-- List commits with `Breaking change: ` somewhere in the message --}}
{{#commit-list commits heading='### :boom: Breaking Changes' message='^(Breaking change|BREAKING CHANGE):'}}
- {{subject}} [`{{shorthash}}`]({{href}}) by {{githubUser author}}
{{/commit-list}}

{{!-- List commits that add new features, but exclude those that have `:sparkles:` in the message --}}
{{#commit-list commits heading='### :tada: New Features' message='(:tada:|Feat:|feat:)' exclude='^:sparkles:'}}
- {{subject}} [`{{shorthash}}`]({{href}}) by {{githubUser author}}
{{/commit-list}}

{{!-- List commits that enhance existing features, but exclude those that have `:tada:` in the message --}}
{{#commit-list commits heading='### :sparkles: Enhancements' message='(:sparkles:|Feat:|feat:|Perf:|perf:)' exclude='^:tada:'}}
- {{subject}} [`{{shorthash}}`]({{href}}) by {{githubUser author}}
{{/commit-list}}

{{!-- List commits that bug fixes --}}
{{#commit-list commits heading='### :bug: Bug Fixes' message='(:bug:|Fix:|fix:)'}}
- {{subject}} [`{{shorthash}}`]({{href}}) by {{githubUser author}}
{{/commit-list}}

{{!-- List commits that improve the documentation --}}
{{#commit-list commits heading='### :memo: Documentation' message='(:memo:|Docs:|docs:)'}}
- {{subject}} [`{{shorthash}}`]({{href}}) by {{githubUser author}}
{{/commit-list}}

{{!-- List other changes commits --}}
{{#commit-list commits heading='### :wrench: Other Changes' message='(Refactor:|refactor:|Style:|style:|Test:|test:|Chore:|chore:|Build:|build:)'}}
- {{subject}} [`{{shorthash}}`]({{href}}) by {{githubUser author}}
{{/commit-list}}

- **Full Changelog**: {{href}}

---

### Uncategorized

{{#if merges}}
#### Merged pull requests

{{#each merges}}
- {{#if commit.breaking}}**Breaking change:** {{/if}}{{message}} {{#if href}}[`#{{id}}`]({{href}}){{/if}}
{{/each}}
{{/if}}

{{#if fixes}}
#### Closed issues

{{#each fixes}}
- {{#if commit.breaking}}**Breaking change:** {{/if}}{{commit.subject}}{{#each fixes}} {{#if href}}[`#{{id}}`]({{href}}){{/if}}{{/each}}
{{/each}}
{{/if}}

{{/each}}
42 changes: 0 additions & 42 deletions changelog-template.hbs

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"server:docs": "hugo server --source=../fixit-docs -D --disableFastRender --navigateToChanged --ignoreCache --bind 0.0.0.0",
"version": "sed -i '' \"s/v$npm_package_version-RC/v$npm_package_version/g\" layouts/partials/init/index.html && git add .",
"postversion": "git push && git push --tags",
"release": "auto-changelog --template changelog-template.hbs"
"release": "auto-changelog --config .auto-changelog/config.json"
},
"devDependencies": {
"auto-changelog": "^2.4.0"
Expand Down

0 comments on commit 7f19569

Please sign in to comment.