parent
b9f226e4aa
commit
f70b565c4d
@ -1,41 +1,40 @@
|
|||||||
|
const { execSync, spawnSync } = require("child_process");
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
const { execSync, spawnSync } = require('child_process');
|
const tag = execSync("git describe --tags --abbrev=0").toString().trim();
|
||||||
const fs = require('fs');
|
console.log("Checking commits since", tag);
|
||||||
|
|
||||||
const tag = execSync('git describe --tags --abbrev=0').toString().trim();
|
const args = ["-n", "1", `${tag}..HEAD`, "--abbrev=7", "--pretty=%h", "--", "CHANGELOG.md"];
|
||||||
console.log('Checking commits since', tag);
|
|
||||||
|
|
||||||
const args = ['-n', '1', `${tag}..HEAD`, '--abbrev=7', '--pretty=%h', '--', 'CHANGELOG.md'];
|
|
||||||
function findCommit(line) {
|
function findCommit(line) {
|
||||||
const result = spawnSync('git', ['log', '-S', line, ...args], { shell: false });
|
const result = spawnSync("git", ["log", "-S", line, ...args], { shell: false });
|
||||||
if (result.status === 0) return result.stdout.toString().trim();
|
if (result.status === 0) return result.stdout.toString().trim();
|
||||||
throw new Error(result.stderr.toString());
|
throw new Error(result.stderr.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
const lines = fs.readFileSync('CHANGELOG.md').toString().split(/\r?\n/g);
|
const lines = fs.readFileSync("CHANGELOG.md").toString().split(/\r?\n/g);
|
||||||
|
|
||||||
let enhanced = 0;
|
let enhanced = 0;
|
||||||
let shouldEnhance = false;
|
let shouldEnhance = false;
|
||||||
for (let i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
const line = lines[i];
|
const line = lines[i];
|
||||||
if (line.startsWith('## Unreleased')) shouldEnhance = true;
|
if (line.startsWith("## Unreleased")) shouldEnhance = true;
|
||||||
else if (line.startsWith('## ')) break;
|
else if (line.startsWith("## ")) break;
|
||||||
if (!line.startsWith('- ')) continue;
|
if (!line.startsWith("- ")) continue;
|
||||||
const commit = findCommit(line);
|
const commit = findCommit(line);
|
||||||
if (!commit) return;
|
if (!commit) continue;
|
||||||
console.log(line, '=>', commit);
|
console.log(line, "=>", commit);
|
||||||
const brackets = line.match(/ \((.*?)\)$/);
|
const brackets = line.match(/ \((.*?)\)$/);
|
||||||
if (brackets) {
|
if (brackets) {
|
||||||
if (brackets[1].match(/[\da-fA-F]{7}/)) continue;
|
if (brackets[1].match(/[\da-fA-F]{7}/)) continue;
|
||||||
if (!brackets[1].includes(' ')) {
|
if (!brackets[1].includes(" ")) {
|
||||||
lines[i] = line.replace(/\(.*?\)$/, `(${commit}, ${brackets[1]})`);
|
lines[i] = line.replace(/\(.*?\)$/, `(${commit}, ${brackets[1]})`);
|
||||||
enhanced++;
|
enhanced++;
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
lines[i] = `${line} (${commit})`;
|
}
|
||||||
enhanced++;
|
lines[i] = `${line} (${commit})`;
|
||||||
|
enhanced++;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Enhanced ${enhanced} lines`);
|
console.log(`Enhanced ${enhanced} lines`);
|
||||||
fs.writeFileSync('CHANGELOG.md', lines.join('\n'));
|
fs.writeFileSync("CHANGELOG.md", lines.join("\n"));
|
||||||
|
Loading…
Reference in new issue