mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
This reverts commit e61b75f007.
This commit is contained in:
@@ -1,186 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
// Generate (or inject) the `### 🙌 Contributors` table for a CHANGELOG version section.
|
||||
//
|
||||
// WHY: every version's CHANGELOG `## [vX.Y.Z]` section MUST end with a `### 🙌 Contributors`
|
||||
// table (the convention across every prior version). v3.8.43 shipped without it (a real miss the
|
||||
// owner caught) because it was assembled by hand. This makes it reproducible + accurate.
|
||||
//
|
||||
// A naive `@handle` scan mis-assigns rollup PRs — a maintenance bullet lists many PRs under one
|
||||
// `— thanks @X`, and a flat scan would credit every handle on the line with all of them. This
|
||||
// parses each `([#refs] — thanks @X / @Y)` PARENTHETICAL GROUP and assigns that group's refs only
|
||||
// to that group's handles (crediting is per-parenthetical, matching how bullets are written).
|
||||
//
|
||||
// Usage:
|
||||
// node scripts/release/gen-contributors.mjs <version> # print the table
|
||||
// node scripts/release/gen-contributors.mjs <version> --inject # insert/replace it in CHANGELOG.md
|
||||
//
|
||||
// Exit codes: 0 ok · 2 version section not found · 3 nothing to inject over.
|
||||
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
|
||||
|
||||
// Handles that are package names / code refs / scopes, never people. Extend as needed.
|
||||
export const NOISE_HANDLES = new Set([
|
||||
"toon-format",
|
||||
"dnd-kit",
|
||||
"om-usage",
|
||||
"anthropic-ai",
|
||||
"huggingface",
|
||||
"oven",
|
||||
"latest",
|
||||
"next",
|
||||
"types",
|
||||
]);
|
||||
|
||||
const MAINTAINER = "diegosouzapw";
|
||||
|
||||
/** Extract the `## [version]` … up to the next `## [` section body (exclusive of the next header). */
|
||||
export function extractVersionSection(changelog, version) {
|
||||
const esc = version.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
const startRe = new RegExp(`^## \\[${esc}\\][^\\n]*$`, "m");
|
||||
const sm = changelog.match(startRe);
|
||||
if (!sm) return null;
|
||||
const bodyStart = sm.index + sm[0].length;
|
||||
const rest = changelog.slice(bodyStart);
|
||||
const nextIdx = rest.search(/\n## \[/);
|
||||
return nextIdx === -1 ? rest : rest.slice(0, nextIdx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse contributor → set of ref numbers from a version section body.
|
||||
* Rules (in order, per bullet line starting with "- "):
|
||||
* 1. Parenthetical groups containing "thanks": refs in the group → handles in the group.
|
||||
* 2. A "thanks @X" NOT inside such a group (direct-commit trailing credit): the last ref before
|
||||
* it on the line (if any) → the handles.
|
||||
* 3. "Extracted from [#N] by [@X]": N → X.
|
||||
* Excludes NOISE_HANDLES and the maintainer (returned separately by caller).
|
||||
*/
|
||||
export function parseContributors(sectionText) {
|
||||
const agg = new Map(); // handle -> Set(refs)
|
||||
const add = (handle, refs) => {
|
||||
if (NOISE_HANDLES.has(handle) || handle === MAINTAINER) return;
|
||||
if (!agg.has(handle)) agg.set(handle, new Set());
|
||||
for (const r of refs) agg.get(handle).add(r);
|
||||
};
|
||||
const handlesIn = (s) => [...s.matchAll(/@([A-Za-z0-9_-]+)/g)].map((m) => m[1]);
|
||||
const refsIn = (s) => [...s.matchAll(/#(\d+)/g)].map((m) => Number(m[1]));
|
||||
|
||||
for (const raw of sectionText.split("\n")) {
|
||||
if (!raw.startsWith("- ")) continue;
|
||||
// Collapse markdown links so parenthetical groups aren't broken by the URL's own parens:
|
||||
// [#5720](https://…/pull/5720) → #5720 · [@pizzav-xyz](https://…) → @pizzav-xyz
|
||||
const line = raw
|
||||
.replace(/\[#(\d+)\]\([^)]*\)/g, "#$1")
|
||||
.replace(/\[@([A-Za-z0-9_-]+)\]\([^)]*\)/g, "@$1");
|
||||
const usedSpans = [];
|
||||
|
||||
// (1) parenthetical groups with "thanks"
|
||||
for (const g of line.matchAll(/\(([^()]*thanks[^()]*)\)/g)) {
|
||||
const inner = g[1];
|
||||
const refs = refsIn(inner);
|
||||
for (const th of inner.matchAll(/thanks\s+((?:@[A-Za-z0-9_-]+(?:\s*\/\s*)?)+)/g)) {
|
||||
for (const h of handlesIn(th[1])) add(h, refs);
|
||||
}
|
||||
usedSpans.push([g.index, g.index + g[0].length]);
|
||||
}
|
||||
|
||||
// (2) trailing "— thanks @X" outside any used parenthetical (direct commits)
|
||||
for (const th of line.matchAll(/thanks\s+((?:@[A-Za-z0-9_-]+(?:\s*\/\s*)?)+)/g)) {
|
||||
const inGroup = usedSpans.some(([s, e]) => th.index >= s && th.index < e);
|
||||
if (inGroup) continue;
|
||||
const before = line.slice(0, th.index);
|
||||
const refsBefore = refsIn(before);
|
||||
const refs = refsBefore.length ? [refsBefore[refsBefore.length - 1]] : [];
|
||||
for (const h of handlesIn(th[1])) add(h, refs);
|
||||
}
|
||||
|
||||
// (3) "Extracted from #N by @X" (links already collapsed by the preprocessing above)
|
||||
for (const em of line.matchAll(/[Ee]xtracted from #(\d+)\s+by\s+@([A-Za-z0-9_-]+)/g)) {
|
||||
add(em[2], [Number(em[1])]);
|
||||
}
|
||||
}
|
||||
return agg;
|
||||
}
|
||||
|
||||
export function renderContributors(version, agg, maintainerNote = "maintainer") {
|
||||
const fmt = (set) =>
|
||||
set.size
|
||||
? [...set]
|
||||
.sort((a, b) => a - b)
|
||||
.map((n) => `#${n}`)
|
||||
.join(", ")
|
||||
: "direct commit / report";
|
||||
const rows = [...agg.entries()].sort((a, b) =>
|
||||
a[0].toLowerCase().localeCompare(b[0].toLowerCase())
|
||||
);
|
||||
const lines = [
|
||||
"### 🙌 Contributors",
|
||||
"",
|
||||
`Thanks to everyone whose work landed in v${version}:`,
|
||||
"",
|
||||
"| Contributor | PRs / Issues |",
|
||||
"| --- | --- |",
|
||||
];
|
||||
for (const [h, refs] of rows) {
|
||||
lines.push(`| [@${h}](https://github.com/${h}) | ${fmt(refs)} |`);
|
||||
}
|
||||
lines.push(`| [@${MAINTAINER}](https://github.com/${MAINTAINER}) | ${maintainerNote} |`);
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
/** Insert or replace the Contributors section inside the version block, before its closing `---`. */
|
||||
export function injectContributors(changelog, version, table) {
|
||||
const esc = version.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
const startRe = new RegExp(`^## \\[${esc}\\][^\\n]*$`, "m");
|
||||
const sm = changelog.match(startRe);
|
||||
if (!sm) return null;
|
||||
const headerEnd = sm.index + sm[0].length;
|
||||
const rest = changelog.slice(headerEnd);
|
||||
const nextIdx = rest.search(/\n## \[/);
|
||||
const bodyEnd = nextIdx === -1 ? changelog.length : headerEnd + nextIdx;
|
||||
let body = changelog.slice(headerEnd, bodyEnd);
|
||||
// strip an existing Contributors section (idempotent re-run)
|
||||
body = body.replace(/\n### 🙌 Contributors[\s\S]*?(?=\n---\n|$)/, "\n");
|
||||
// insert before the trailing `---` (or append if none)
|
||||
const idx = body.lastIndexOf("\n---");
|
||||
const insertion = `\n${table}\n`;
|
||||
body = idx >= 0 ? body.slice(0, idx) + insertion + body.slice(idx) : `${body}${insertion}\n---\n`;
|
||||
return changelog.slice(0, headerEnd) + body + changelog.slice(bodyEnd);
|
||||
}
|
||||
|
||||
function main(argv) {
|
||||
const version = argv[0];
|
||||
const inject = argv.includes("--inject");
|
||||
if (!version || !/^\d+\.\d+\.\d+$/.test(version)) {
|
||||
process.stderr.write("usage: gen-contributors.mjs <version> [--inject]\n");
|
||||
process.exit(1);
|
||||
}
|
||||
const clPath = path.join(ROOT, "CHANGELOG.md");
|
||||
const changelog = fs.readFileSync(clPath, "utf8");
|
||||
const section = extractVersionSection(changelog, version);
|
||||
if (section == null) {
|
||||
process.stderr.write(`No [${version}] section in CHANGELOG.md\n`);
|
||||
process.exit(2);
|
||||
}
|
||||
const agg = parseContributors(section);
|
||||
const table = renderContributors(version, agg);
|
||||
if (!inject) {
|
||||
process.stdout.write(table + "\n");
|
||||
return;
|
||||
}
|
||||
const next = injectContributors(changelog, version, table);
|
||||
if (next == null) {
|
||||
process.stderr.write(`Could not locate [${version}] block for injection\n`);
|
||||
process.exit(3);
|
||||
}
|
||||
fs.writeFileSync(clPath, next);
|
||||
process.stderr.write(`✓ Injected ${agg.size} external contributor(s) into [${version}]\n`);
|
||||
}
|
||||
|
||||
// direct-run guard (importable for tests)
|
||||
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
||||
main(process.argv.slice(2));
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
// Reconciliation helper: list non-merge commits since the last tag whose PR/issue ref is NOT
|
||||
// represented in the current version's CHANGELOG section (or [Unreleased]).
|
||||
//
|
||||
// WHY: during the cycle, PRs merge into release/** and some land WITHOUT a CHANGELOG bullet, so
|
||||
// /generate-release reconciliation has to rediscover them by hand (v3.8.43: 123 of 176 commits had
|
||||
// no bullet). This surfaces exactly that gap in seconds — maintainer-side, non-blocking, run it at
|
||||
// reconciliation (Phase 0a) so the release CHANGELOG is complete before the PR opens.
|
||||
//
|
||||
// A commit is "covered" iff ANY `#N` in its subject appears anywhere in the CHANGELOG scan window
|
||||
// (the version section + [Unreleased]) — matching on issue OR PR number, since a bullet may cite
|
||||
// either. Internal commits (chore/ci/test/refactor) are listed under "rollup candidates" so the
|
||||
// maintainer can consolidate rather than write one bullet each.
|
||||
//
|
||||
// Usage: node scripts/release/list-uncovered-commits.mjs [--json]
|
||||
// Exit: 0 always (advisory). Prints a report to stdout.
|
||||
|
||||
import { execFileSync } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
|
||||
const git = (args) => execFileSync("git", args, { cwd: ROOT, encoding: "utf8" }).trim();
|
||||
|
||||
const ROLLUP_TYPES = new Set(["chore", "ci", "test", "refactor", "build", "docs", "style"]);
|
||||
|
||||
export function refsOf(subject) {
|
||||
return [...subject.matchAll(/#(\d+)/g)].map((m) => Number(m[1]));
|
||||
}
|
||||
|
||||
export function typeOf(subject) {
|
||||
const m = subject.match(/^([a-z]+)(\(|:|!)/);
|
||||
return m ? m[1] : "other";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{hash:string, subject:string}[]} commits
|
||||
* @param {Set<number>} changelogRefs every #N present in the CHANGELOG scan window
|
||||
* @returns {{covered:number, uncovered:{hash,subject,refs,type,rollup}[]}}
|
||||
*/
|
||||
export function computeUncovered(commits, changelogRefs) {
|
||||
const uncovered = [];
|
||||
let covered = 0;
|
||||
for (const c of commits) {
|
||||
const refs = refsOf(c.subject);
|
||||
const isCovered = refs.length > 0 && refs.some((r) => changelogRefs.has(r));
|
||||
if (isCovered) {
|
||||
covered++;
|
||||
} else {
|
||||
const type = typeOf(c.subject);
|
||||
uncovered.push({ ...c, refs, type, rollup: ROLLUP_TYPES.has(type) });
|
||||
}
|
||||
}
|
||||
return { covered, uncovered };
|
||||
}
|
||||
|
||||
/** Read every #N in the version's CHANGELOG section + the [Unreleased] section. */
|
||||
export function changelogRefWindow(changelog, version) {
|
||||
const esc = version.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
// From [Unreleased] up to (but excluding) the version-after-this one.
|
||||
const startRe = /^## \[Unreleased\]/m;
|
||||
const s = changelog.match(startRe);
|
||||
const from = s ? s.index : 0;
|
||||
// find the header AFTER the target version
|
||||
const verRe = new RegExp(`^## \\[${esc}\\]`, "m");
|
||||
const vm = changelog.slice(from).match(verRe);
|
||||
const afterVersionStart = vm ? from + vm.index + vm[0].length : from;
|
||||
const rest = changelog.slice(afterVersionStart);
|
||||
const nextIdx = rest.search(/\n## \[/);
|
||||
const to = nextIdx === -1 ? changelog.length : afterVersionStart + nextIdx;
|
||||
const window = changelog.slice(from, to);
|
||||
return new Set([...window.matchAll(/#(\d+)/g)].map((m) => Number(m[1])));
|
||||
}
|
||||
|
||||
function main(argv) {
|
||||
const jsonOut = argv.includes("--json");
|
||||
const lastTag = git(["describe", "--tags", "--abbrev=0"]);
|
||||
const version = JSON.parse(fs.readFileSync(path.join(ROOT, "package.json"), "utf8")).version;
|
||||
const log = git(["log", "--no-merges", `${lastTag}..HEAD`, "--pretty=format:%h%x09%s"]);
|
||||
const commits = log
|
||||
? log.split("\n").map((l) => {
|
||||
const [hash, subject] = l.split("\t");
|
||||
return { hash, subject };
|
||||
})
|
||||
: [];
|
||||
const changelog = fs.readFileSync(path.join(ROOT, "CHANGELOG.md"), "utf8");
|
||||
const refs = changelogRefWindow(changelog, version);
|
||||
const { covered, uncovered } = computeUncovered(commits, refs);
|
||||
|
||||
if (jsonOut) {
|
||||
process.stdout.write(
|
||||
JSON.stringify({ version, lastTag, total: commits.length, covered, uncovered }, null, 2) +
|
||||
"\n"
|
||||
);
|
||||
return;
|
||||
}
|
||||
const bulletsWorthy = uncovered.filter((c) => !c.rollup);
|
||||
const rollupCandidates = uncovered.filter((c) => c.rollup);
|
||||
process.stdout.write(`# Uncovered-commit reconciliation — v${version} (${lastTag}..HEAD)\n\n`);
|
||||
process.stdout.write(
|
||||
`Commits: ${commits.length} · covered: ${covered} · uncovered: ${uncovered.length}\n\n`
|
||||
);
|
||||
process.stdout.write(
|
||||
`## Needs a bullet (feat/fix/other — user-facing) — ${bulletsWorthy.length}\n`
|
||||
);
|
||||
for (const c of bulletsWorthy) process.stdout.write(`- ${c.hash} ${c.subject}\n`);
|
||||
process.stdout.write(
|
||||
`\n## Rollup candidates (chore/ci/test/refactor/docs) — ${rollupCandidates.length}\n`
|
||||
);
|
||||
for (const c of rollupCandidates) process.stdout.write(`- ${c.hash} ${c.subject}\n`);
|
||||
process.stdout.write(
|
||||
`\n> Advisory. Add a bullet for each user-facing item; consolidate rollup candidates into a few Maintenance bullets (list their PR numbers).\n`
|
||||
);
|
||||
}
|
||||
|
||||
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
||||
main(process.argv.slice(2));
|
||||
}
|
||||
Reference in New Issue
Block a user