offline-github-changelog
Advanced tools
Comparing version 1.4.0 to 1.5.0
104
index.js
const { spawnSync } = require("child_process"); | ||
const markdownEscape = require("markdown-escape"); | ||
const MAX_REGULAR_COMMITS_PER_RELEASE = 5; | ||
@@ -29,2 +30,4 @@ const generateChangelog = (originName) => { | ||
const commitRange = lastHash ? `${lastHash}..${hash}` : hash; | ||
const getMerges = spawnSync("git", [ | ||
@@ -34,7 +37,5 @@ "log", | ||
"--pretty=%s|||||%b|||||%H|||||[%an](mailto:%ae)|||||%P=====", | ||
lastHash ? `${lastHash}..${hash}` : hash | ||
commitRange | ||
]); | ||
lastHash = hash; | ||
const merges = getMerges.stdout | ||
@@ -52,3 +53,2 @@ .toString() | ||
const authors = new Set(); | ||
const getAuthors = spawnSync("git", [ | ||
@@ -60,7 +60,7 @@ "log", | ||
getAuthors.stdout | ||
const authors = new Set(getAuthors.stdout | ||
.toString() | ||
.split("\n") | ||
.filter(line => line) | ||
.forEach(author => authors.add(author)); | ||
); | ||
@@ -75,25 +75,91 @@ return { | ||
const getRegularCommits = spawnSync("git", [ | ||
"log", | ||
"--no-merges", | ||
"--first-parent", | ||
"--pretty=%s|||||%b|||||%H|||||[%an](mailto:%ae)|||||%P=====", | ||
commitRange | ||
]); | ||
const regularCommits = getRegularCommits.stdout | ||
.toString() | ||
.split("=====\n") | ||
// Crudely skip version commits (with "x.y.z" message): | ||
.filter(line => line && !/^[\d+.-]+\|\|\|\|\|/.test(line)) | ||
.map(line => line.replace(/\n/g, "")) | ||
.map(line => line.split("|||||")) | ||
.map(([message, body, commitHash, author]) => { | ||
return { | ||
author, | ||
message, | ||
commitHash | ||
}; | ||
}); | ||
lastHash = hash; | ||
return { | ||
tag, | ||
date, | ||
merges | ||
merges, | ||
regularCommits | ||
}; | ||
}); | ||
}).reverse(); | ||
tags.reverse().forEach(({ tag, date, merges }) => { | ||
if (merges.length > 0) { | ||
for (const [i, { tag, date, merges, regularCommits }] of tags.entries()) { | ||
if (merges.length > 0 || regularCommits.length > 0) { | ||
console.log(`### ${tag} (${date})\n`); | ||
merges.forEach(({ authors, mergeAuthor, message, pullRequestNumber }) => { | ||
console.log( | ||
`- [#${pullRequestNumber}](${repositoryUrl}/pull/${pullRequestNumber}) ${markdownEscape(message)} (${authors.join( | ||
", " | ||
)})` | ||
); | ||
}); | ||
if (merges.length > 0) { | ||
if (regularCommits.length > 0) { | ||
console.log(`#### Pull requests\n`); | ||
} | ||
console.log(); | ||
for (const { | ||
authors, | ||
mergeAuthor, | ||
message, | ||
pullRequestNumber | ||
} of merges) { | ||
console.log( | ||
`- [#${pullRequestNumber}](${repositoryUrl}/pull/${pullRequestNumber}) ${markdownEscape( | ||
message | ||
)} (${authors.join(", ")})` | ||
); | ||
} | ||
console.log(); | ||
} | ||
if (regularCommits.length > 0) { | ||
if (merges.length > 0) { | ||
console.log(`#### Commits to master\n`); | ||
} | ||
for (const { author, message, commitHash } of regularCommits.slice(0, MAX_REGULAR_COMMITS_PER_RELEASE)) { | ||
console.log( | ||
`- [${markdownEscape( | ||
message | ||
)}](${repositoryUrl}/commit/${commitHash}) (${author})` | ||
); | ||
} | ||
if (regularCommits.length > MAX_REGULAR_COMMITS_PER_RELEASE) { | ||
let compareFrom; | ||
if (i === tags.length - 1) { | ||
compareFrom = `${regularCommits[0].commitHash}^`; | ||
} else { | ||
compareFrom = tags[i + 1].tag; | ||
} | ||
const targetUrl = `${repositoryUrl}/compare/${encodeURIComponent( | ||
compareFrom | ||
)}...${encodeURIComponent(tag)}`; | ||
console.log( | ||
`- [+${regularCommits.length - | ||
MAX_REGULAR_COMMITS_PER_RELEASE} more](${targetUrl})` | ||
); | ||
} | ||
console.log(); | ||
} | ||
} | ||
}); | ||
} | ||
}; | ||
module.exports = { generateChangelog }; |
{ | ||
"name": "offline-github-changelog", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "A changelog generator for Github projects that only uses the Git history", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
8594
141