Add target variables in changelog script parser

Add variables specifying the repository and branch that the changelog
script parser operates on in order to make it easier to use this script
on other projects.
This commit is contained in:
Hornwitser authored and Hornwitser committed 2026-04-09 23:46:35 +00:00
1 parent 2e48b728dd
commit a7620d3cdc
1 file changed
+9 -6
+9 -6
View File
@@ -7,6 +7,9 @@ import {
type Changelog = Record<string, string[]>; type Changelog = Record<string, string[]>;
const repository = "clusterio/clusterio";
const branch = "master";
const changelogSections = [ const changelogSections = [
"Major Features", "Major Features",
"Features", "Features",
@@ -115,7 +118,7 @@ function parseChangelog(parser: ParserState, pr: Issue, issues: Issue[]): [Chang
const entry = line const entry = line
.slice(2) .slice(2)
.trim() .trim()
.replace(/\[#(\d+)\]\(https:\/\/github.com\/clusterio\/clusterio\/(issues|pull)\/\d+\)/g, "#$1"); .replace(new RegExp(`\\[#(\\d+)\\]\\(https://github.com/${repository}/(issues|pull)/\\d+\\)`, "g"), "#$1");
let hasRef = false let hasRef = false
for (const ref of entry.matchAll(/#(\d+)/g)) { for (const ref of entry.matchAll(/#(\d+)/g)) {
hasRef = true; hasRef = true;
@@ -169,17 +172,17 @@ function changelogFromPullRequests(pullRequests: Issue[], issues: Issue[]) {
async function fetchLastRelease() { async function fetchLastRelease() {
// Assumes releases are ordered by their creation or tag time in descending order. // Assumes releases are ordered by their creation or tag time in descending order.
const releases = await githubFetchJson<Release[]>("/repos/clusterio/clusterio/releases"); const releases = await githubFetchJson<Release[]>(`/repos/${repository}/releases`);
const latest = releases.find(r => r.target_commitish === "master"); const latest = releases.find(r => r.target_commitish === branch);
if (!latest) { if (!latest) {
throw new Error("Unable to find latest release on master"); throw new Error(`Unable to find latest release on ${branch}`);
} }
return latest; return latest;
} }
async function fetchIssuesUpdatedSince(since: string) { async function fetchIssuesUpdatedSince(since: string) {
return await githubFetchJsonPaginated<Issue>( return await githubFetchJsonPaginated<Issue>(
"/repos/clusterio/clusterio/issues", `/repos/${repository}/issues`,
{ state: "all", since, sort: "updated", direction: "asc" }, { state: "all", since, sort: "updated", direction: "asc" },
); );
} }
@@ -222,7 +225,7 @@ async function main() {
console.log(); console.log();
console.log("=== Github markdown ==="); console.log("=== Github markdown ===");
printMarkdown(changelog, issues, issue => `clusterio/clusterio#${issue.number}`); printMarkdown(changelog, issues, issue => `${repository}#${issue.number}`);
console.log(); console.log();
console.log("=== Discord markdown ==="); console.log("=== Discord markdown ===");
printMarkdown(changelog, issues, issue => `[#${issue.number}](<${issue.html_url}>`); printMarkdown(changelog, issues, issue => `[#${issue.number}](<${issue.html_url}>`);