-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INTERNAL] Changelog: Consolidate dependency changes for GitHub relea…
…ses (#382) Co-authored-by: Matthias Osswald <mat.osswald@sap.com>
- Loading branch information
1 parent
ddef5e6
commit c97b4ea
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters