Skip to content

Commit

Permalink
docs: customize changelog template to include commit message body
Browse files Browse the repository at this point in the history
  • Loading branch information
kleinfreund committed Nov 24, 2023
1 parent a611e12 commit d01f3b4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
48 changes: 48 additions & 0 deletions changelog-template-commit.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{!--
Copy of https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-conventionalcommits/templates/commit.hbs
The following have been replaced:
- `commitUrlFormat` with `{{@root.host}}/{{@root.owner}}/{{@root.repository}}/commit/{{hash}})`
- `issueUrlFormat` with `{{@root.host}}/{{@root.owner}}/{{@root.repository}}/issues/{{this.id}}`
As they won't be replaced when overriding the commitPartial
--}}
*{{#if scope}} **{{scope}}:**
{{~/if}} {{#if subject}}
{{~subject}}
{{~else}}
{{~header}}
{{~/if}}

{{~!-- commit link --}}{{~#if hash}} {{#if @root.linkReferences~}}
([{{shortHash}}]({{@root.host}}/{{@root.owner}}/{{@root.repository}}/commit/{{hash}}))
{{~else}}
{{~shortHash}}
{{~/if}}{{~/if}}

{{~!-- commit references --}}
{{~#if references~}}
, closes
{{~#each references}} {{#if @root.linkReferences~}}
[
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}{{this.prefix}}{{this.issue}}]({{@root.host}}/{{@root.owner}}/{{@root.repository}}/issues/{{this.id}})
{{~else}}
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}{{this.prefix}}{{this.issue}}
{{~/if}}{{/each}}
{{~/if}}
{{!-- End of copy --}}

{{!-- Start of custom additions --}}
{{#each bodyLines}}

{{this}}
{{/each}}{{#each notes}}
**BREAKING CHANGE**: {{text}}
{{/each}}
21 changes: 21 additions & 0 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
import { readFileSync } from 'node:fs'

const commitPartial = readFileSync('./changelog-template-commit.hbs', { encoding: 'utf-8' })

/**
* Adds the commit body line by line so I can add it with the correct indentation in `changelog-template-commit.hbs`.
*/
function finalizeContext(context) {
for (const commitGroup of context.commitGroups) {
for (const commit of commitGroup.commits) {
commit.bodyLines = commit.body?.split('\n').filter((line) => line !== '') ?? []
}
}

return context
}

/** @type {import('semantic-release').Options} */ const options = {
branches: [
'main',
Expand All @@ -11,6 +28,10 @@
// https://github.com/semantic-release/release-notes-generator
['@semantic-release/release-notes-generator', {
preset: 'conventionalcommits',
writerOpts: {
commitPartial,
finalizeContext,
},
}],

// This creates/updates the CHANGELOG.md file.
Expand Down

0 comments on commit d01f3b4

Please sign in to comment.