Skip to content

Commit

Permalink
[INTERNAL] Changelog: Consolidate dependency changes for GitHub relea…
Browse files Browse the repository at this point in the history
…ses (#382)

Co-authored-by: Matthias Osswald <mat.osswald@sap.com>
  • Loading branch information
RandomByte and matz3 authored Nov 3, 2020
1 parent ddef5e6 commit c97b4ea
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
59 changes: 59 additions & 0 deletions .chglog/consolidate-changelogs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const readline = require("readline");
const path = require("path");
const fs = require("fs");

function handleDependencyBump(line) {
line = line.replace("[@ui5](https://github.com/ui5)", "@ui5");
const moduleMatch = line.match(/Bump (@ui5\/[^\s]+).*to ([0-9.]+)/);
if (moduleMatch) {
const [, moduleName, moduleVersion] = moduleMatch;
const moduleDir = path.dirname(require.resolve(moduleName));
const changelogPath = path.join(moduleDir, "CHANGELOG.md");
const changelog = fs.readFileSync(changelogPath, {
encoding: "utf8"
});
const sectionRegExp = new RegExp(`^## \\[v${moduleVersion.replace(".", "\\.")}\\].+\\n((?:.|\\n)+?)(?=\\n<a )`, "m");
const changelogMatch = changelog.match(sectionRegExp);
if (!changelogMatch) {
throw new Error(`Failed to find relevant changelog for ${moduleName}@${moduleVersion}`)
}
let versionChangelog = changelogMatch[1];
versionChangelog = versionChangelog.replace(/^### /gm, "#### ");
versionChangelog = versionChangelog.replace(/^./gm, " $&");
const repoUrl = `https://github.com/SAP/${moduleName.replace("@ui5/", "ui5-")}/tree/v${moduleVersion}`;
line += `
- Changes contained in [v${moduleVersion}](${repoUrl})
${versionChangelog}`;
}
return line;
}

function readStdin() {
return new Promise((resolve, reject) => {
const rl = readline.createInterface({
input: process.stdin
});

let buffer = "";
rl.on("line", (line) => {
try {
if (line.startsWith("- Bump")) {
buffer += `${handleDependencyBump(line)}`
} else {
buffer += `${line}\n`;
}
} catch (err) {
reject(err)
}
});

rl.on("pause", () => {
resolve(buffer);
});
});
}

readStdin().then((result) => {
process.stdout.write(result); // Don't use console.log since one new line at the end is already enough
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"preversion": "npm test",
"version": "git-chglog --next-tag v$npm_package_version -o CHANGELOG.md && git add CHANGELOG.md",
"prepublishOnly": "git push --follow-tags",
"release-note": "git-chglog -c .chglog/release-config.yml v$npm_package_version",
"release-note": "git-chglog -c .chglog/release-config.yml v$npm_package_version | node .chglog/consolidate-changelogs.js",
"report-coveralls": "nyc report --reporter=text-lcov | COVERALLS_PARALLEL=true coveralls"
},
"files": [
Expand All @@ -67,6 +67,7 @@
"text-summary"
],
"exclude": [
".chglog/**",
"docs/**",
"jsdocs/**",
"coverage/**",
Expand Down

0 comments on commit c97b4ea

Please sign in to comment.