Skip to content

Commit

Permalink
Add utility script to add commits to changelog's unreleased section
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoofsKelvin committed Oct 2, 2021
1 parent 06c8e21 commit dce279d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- The problem matcher for the `Extension Webview - Watch` task has been simplified and fixed due to the above change
- Updated Yarn to 3.0.2 (with manual git issue fix applied)
- Updated TypeScript to ^4.4.3
- Added `enhance-changelog.js` which add commits to "top-level" items in the changelog's "Unreleased" section

## 1.22.0 (2021-09-21)

Expand Down
41 changes: 41 additions & 0 deletions enhance-changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

const { execSync, spawnSync } = require('child_process');
const fs = require('fs');

const tag = execSync('git describe --tags --abbrev=0').toString().trim();
console.log('Checking commits since', tag);

const args = ['-n', '1', `${tag}..HEAD`, '--abbrev=7', '--pretty=%h', '--', 'CHANGELOG.md'];
function findCommit(line) {
const result = spawnSync('git', ['log', '-S', line, ...args], { shell: false });
if (result.status === 0) return result.stdout.toString().trim();
throw new Error(result.stderr.toString());
}

const lines = fs.readFileSync('CHANGELOG.md').toString().split(/\r?\n/g);

let enhanced = 0;
let shouldEnhance = false;
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
if (line.startsWith('## Unreleased')) shouldEnhance = true;
else if (line.startsWith('## ')) break;
if (!line.startsWith('- ')) continue;
const commit = findCommit(line);
if (!commit) return;
console.log(line, '=>', commit);
const brackets = line.match(/ \((.*?)\)$/);
if (brackets) {
if (brackets[1].match(/[\da-fA-F]{7}/)) continue;
if (!brackets[1].includes(' ')) {
lines[i] = line.replace(/\(.*?\)$/, `(${commit}, ${brackets[1]})`);
enhanced++;
continue;
}
}
lines[i] = `${line} (${commit})`;
enhanced++;
}

console.log(`Enhanced ${enhanced} lines`);
fs.writeFileSync('CHANGELOG.md', lines.join('\n'));

0 comments on commit dce279d

Please sign in to comment.