chore: parse commit body from git for changelog

This commit is contained in:
alina 🌸 2023-12-02 19:23:57 +03:00
parent 895163c126
commit 6fb2b652d3
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
2 changed files with 35 additions and 8 deletions

View file

@ -18,7 +18,17 @@ function generateChangelog(onlyPackages) {
const changed = findChangedFilesSince(`${commit.hash}~1`, commit.hash)
const line = `- ${commit.hash}: ${breaking ? '**❗ BREAKING** ' : ''}${commit.msg}`
let line = `- ${commit.hash}: ${breaking ? '**❗ BREAKING** ' : ''}${commit.msg}`
if (breaking && commit.description) {
line +=
'\n' +
commit.description
.trim()
.split('\n')
.map((line) => ` ${line}`)
.join('\n')
}
for (const file of changed) {
if (!file.startsWith('packages/')) continue

View file

@ -20,16 +20,33 @@ function findChangedFilesSince(tag, until = 'HEAD') {
}
function getCommitsSince(tag, until = 'HEAD') {
return cp
.execSync(`git log --pretty="format:%H %s" ${tag}..${until}`, { encoding: 'utf8', stdio: 'pipe' })
const delim = `---${Math.random().toString(36).slice(2)}---`
const lines = cp
.execSync(`git log --pretty="format:%H %s%n%b%n${delim}" ${tag}..${until}`, { encoding: 'utf8', stdio: 'pipe' })
.trim()
.split('\n')
.reverse()
.map((it) => {
const [hash, ...msg] = it.split(' ')
return { hash, msg: msg.join(' ') }
})
const items = []
let current = null
for (const line of lines) {
if (line === delim) {
if (current) items.push(current)
current = null
} else if (current) {
if (current.description) current.description += '\n'
current.description += line
} else {
const [hash, ...msg] = line.split(' ')
current = { hash, msg: msg.join(' '), description: '' }
}
}
if (current) items.push(current)
return items.reverse()
}
function parseConventionalCommit(msg) {