Skip to content

Commit

Permalink
doc: updates to changelog generation script
Browse files Browse the repository at this point in the history
Less manual effort paper cuts.
  • Loading branch information
isaacs committed Nov 3, 2020
1 parent e0302a0 commit fea7da3
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions scripts/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ function shortname (url) {

function printCommit (c) {
console.log(`* [\`${c.shortid}\`](https://github.com/npm/cli/commit/${c.fullid})`)
if (c.fixes) {
let label = shortname(c.fixes)
if (label) {
console.log(` [${label}](${c.fixes})`)
} else {
console.log(` [npm.community#${c.fixes}](https://npm.community/t/${c.fixes})`)
if (c.fixes.length) {
for (const fix of c.fixes) {
let label = shortname(fix)
if (label) {
console.log(` [${label}](${fix})`)
}
}
} else if (c.prurl) {
let label = shortname(c.prurl)
Expand All @@ -51,20 +51,23 @@ function printCommit (c) {
.replace(/^\s+/mg, '')
.replace(/^[-a-z]+: /, '')
.replace(/^/mg, ' ')
.replace(/^ Reviewed-by: @.*/mg, '')
.replace(/\n$/, '')
// backtickify package@version
.replace(/^(\s*@?[^@\s]+@\d+[.]\d+[.]\d+)(\s*\S)/g, '$1:$2')
.replace(/^(\s*@?[^@\s]+@\d+[.]\d+[.]\d+)\b(\s*\S)/g, '$1:$2')
.replace(/((?:\b|@)[^@\s]+@\d+[.]\d+[.]\d+)\b/g, '`$1`')
// linkify commitids
.replace(/\b([a-f0-9]{7,8})\b/g, '[`$1`](https://github.com/npm/cli/commit/$1)')
.replace(/\b#(\d+)\b/g, '[#$1](https://npm.community/t/$1)')
console.log(msg)
if (c.credit) {
c.credit.forEach(function (credit) {
console.log(` ([@${credit}](https://github.com/${credit}))`)
})
} else {
console.log(` ([@${c.author}](https://github.com/${c.author}))`)
// don't assign credit for dep updates
if (!/^ `[^`]+@\d+\.\d+\.\d+[^`]*`:?$/m.test(msg)) {
if (c.credit) {
c.credit.forEach(function (credit) {
console.log(` ([@${credit}](https://github.com/${credit}))`)
})
} else {
console.log(` ([@${c.author}](https://github.com/${c.author}))`)
}
}
}

Expand All @@ -84,16 +87,20 @@ function main () {
message: m[4],
author: m[5],
prurl: null,
fixes: null,
fixes: [],
credit: null
}
} else if (m = line.match(/^PR-URL: (.*)/)) {
commit.prurl = m[1]
} else if (m = line.match(/^Credit: @(.*)/)) {
if (!commit.credit) commit.credit = []
commit.credit.push(m[1])
} else if (m = line.match(/^Fixes: #?(.*)/)) {
commit.fixes = m[1]
} else if (m = line.match(/^(?:Fix(?:es)|Closes?): #?([0-9]+)/)) {
commit.fixes.push(`https://github.com/npm/cli/issues/${m[1]}`)
} else if (m = line.match(/^(?:Fix(?:es)|Closes?): ([^#]+)#([0-9]*)/)) {
commit.fixes.push(`https://github.com/${m[1]}/issues/${m[2]}`)
} else if (m = line.match(/^(?:Fix(?:es)|Closes?): (https?:\/\/.*)/)) {
commit.fixes.push(m[1])
} else if (m = line.match(/^Reviewed-By: @(.*)/)) {
commit.reviewed = m[1]
} else if (/\S/.test(line)) {
Expand Down

0 comments on commit fea7da3

Please sign in to comment.