Skip to content

Commit

Permalink
fix(scripts): more complete commit message formatting (#4216)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Jan 6, 2022
1 parent c942f3a commit 3b93654
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions scripts/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ function printCommit (c) {
console.log(`* [\`${c.hash}\`](${c.url})`)
for (const pr of c.prs) {
console.log(` [#${pr.number}](${pr.url})`)
// remove the (#111) relating to this pull request from the commit message,
// since we manually add the link outside of the commit message
const msgRe = new RegExp(`\\s*\\(#${pr.number}\\)`, 'g')
c.message = c.message.replace(msgRe, '')
}
console.log(` ${c.message}`)
// no credit for deps commits
if (!c.message.startsWith('deps')) {
// no need to indent this output, it's already got 2 spaces
console.log(c.message)
// no credit for deps commits, leading spaces are important here
if (!c.message.startsWith(' deps')) {
for (const user of c.credit) {
console.log(` ([${user.name}](${user.url}))`)
}
Expand All @@ -36,7 +41,7 @@ const main = async () => {
const query = `
fragment commitCredit on GitObject {
... on Commit {
messageHeadline
message
url
authors (first:10) {
nodes {
Expand Down Expand Up @@ -74,7 +79,9 @@ const main = async () => {
const commit = {
hash: hash.slice(1), // remove leading _
url: data.url,
message: data.messageHeadline.replace(/\(#\d+\)$/, ''),
message: data.message.replace(/(\r?\n)+/gm, '\n') // swap multiple new lines with one
.replace(/^/gm, ' ') // add two spaces to the start of each line
.replace(/([^\s]+@\d+\.\d+\.\d+.*)/g, '`$1`'), // wrap package@version in backticks
prs: data.associatedPullRequests.nodes.filter((pull) => pull.merged),
credit: data.authors.nodes.map((author) => {
if (author.user && author.user.login) {
Expand Down

0 comments on commit 3b93654

Please sign in to comment.