Skip to content

Commit

Permalink
Don't copy commit description into changelog
Browse files Browse the repository at this point in the history
Because it creates a changelog that is not Common Changelog
compliant. The original reason for including the commit description
was to provide context while writing the changelog, but I often just
end up deleting the commit description.

Category: fix
  • Loading branch information
vweevers committed Oct 8, 2024
1 parent 90a69fa commit 869157d
Showing 1 changed file with 1 addition and 45 deletions.
46 changes: 1 addition & 45 deletions lib/changelog.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { is } from 'unist-util-is'
import { u } from 'unist-builder'

const LIST_ITEM_RE = /^[*-] /

export default function fromTree (parse, tree) {
class Section {
constructor (depth, parent, heading) {
Expand Down Expand Up @@ -172,46 +170,13 @@ export default function fromTree (parse, tree) {

createList (changes) {
const list = u('list', { ordered: false, spread: false }, changes.map(change => {
const hasDescription = !!change.description
const children = parse(hasDescription ? sentence(change.title) : change.title)

// Whether to put a blank line between children
let spread = false

if (hasDescription) {
const lines = change.description.split('\n')

if (isSquashedCommitList(lines)) {
children.push(createSublist(lines))
} else {
// Add full description for context (may require manual intervention)
children.push(...parse(change.description))
spread = true
}
}

return u('listItem', { spread }, children)
return u('listItem', { spread: false }, parse(change.title))
}))

return this.add(list)
}
}

function createSublist (lines) {
const sublist = u('list', { ordered: false, spread: false }, [])

for (const line of lines) {
if (!line) continue

const value = line.replace(LIST_ITEM_RE, '').trim()
const item = u('listItem', { spread: false }, parse(value))

sublist.children.push(item)
}

return sublist
}

const root = new Changelog()

for (let i = 0, section = root; i < tree.length; i++) {
Expand All @@ -221,17 +186,8 @@ export default function fromTree (parse, tree) {
return root
}

function sentence (str) {
return str.endsWith('.') ? str : str + '.'
}

function soleChild (node, test) {
if (!node || !node.children || node.children.length !== 1) return null
const child = node.children[0]
return is(child, test) ? child : null
}

function isSquashedCommitList (lines) {
lines = lines.filter(Boolean)
return lines.length > 0 && lines.every(line => LIST_ITEM_RE.test(line))
}

0 comments on commit 869157d

Please sign in to comment.