Skip to content

Instantly share code, notes, and snippets.

@ayame113
Created July 14, 2022 01:58
Show Gist options
  • Select an option

  • Save ayame113/a6953caacd704ed5cdb012e1f8558ca8 to your computer and use it in GitHub Desktop.

Select an option

Save ayame113/a6953caacd704ed5cdb012e1f8558ca8 to your computer and use it in GitHub Desktop.
リリースノートの中の `feat` や `fix` の数をカウントしてcsvにするやつ
const RELEASE_URL =
"https://raw.githubusercontent.com/denoland/deno/main/Releases.md";
const response = await fetch(RELEASE_URL);
const markdown = await response.text();
const lines = markdown.split("\n");
const prefixEscape: Record<string, string> = {
"add": "add",
"added": "add",
"adds": "add",
"fix": "fix",
"fixes": "fix",
"improve": "improve",
"improvements": "improve",
"rename": "rename",
"renames": "rename",
"update": "update",
"upgrade": "update",
};
// "- feat: xxxx" => "feat"
const result = new Map<string, Record<string, number>>();
const prefixes = new Set<string>();
let currentVersion: string;
for (const line of lines) {
if (line.startsWith("### ")) {
const [version, date] = line.slice("### ".length).split(" / ");
console.log({ version, date });
currentVersion = version;
result.set(currentVersion, {});
} else if (line.startsWith("- ")) {
const prefix = line
.slice("- ".length)
.split(/[/\.\s\(:]/)[0]
.toLowerCase()
.replaceAll('"', "");
const escaped = prefixEscape[prefix] ?? prefix;
prefixes.add(escaped);
result.get(currentVersion!)![escaped] ??= 0;
result.get(currentVersion!)![escaped]++;
}
}
console.log(result);
const prefixes_ = [...prefixes];
// output csv
console.log(`release,${prefixes_.join(",")}`);
for (const [release, data] of result.entries()) {
const line = release + prefixes_.map((prefix) => data[prefix] ?? 0).join(",");
console.log(line);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment