Skip to content

Instantly share code, notes, and snippets.

@cmwylie19
Last active April 14, 2025 14:15
Show Gist options
  • Save cmwylie19/5dccd9d752d9264c3896b67ca67f8e58 to your computer and use it in GitHub Desktop.
Save cmwylie19/5dccd9d752d9264c3896b67ca67f8e58 to your computer and use it in GitHub Desktop.
organizes github release note
const fs = require('fs');
function reorganizeChangelog(filePath) {
const changelog = fs.readFileSync(filePath, 'utf8');
const lines = changelog.split('\n');
const whatsChangedIdx = lines.findIndex(line => line.trim() === '## What\'s Changed');
if (whatsChangedIdx === -1) {
console.error('No "## What\'s Changed" section found.');
return;
}
const fullChangelogIdx = lines.findIndex(line => line.toLowerCase().startsWith('**full changelog**'));
const fullChangelogLine = fullChangelogIdx !== -1 ? lines.splice(fullChangelogIdx, 1)[0] : '';
let dependabotLines = [];
let otherLines = [];
let i = whatsChangedIdx + 1;
while (i < lines.length && !lines[i].startsWith('## ')) {
const line = lines[i].trim();
if (line.startsWith('*') && line.includes('@dependabot')) {
dependabotLines.push(lines[i]);
} else if (line.startsWith('*')) {
otherLines.push(lines[i]);
} else {
// Append continuation lines to the last bullet
if (dependabotLines.length && line) {
dependabotLines[dependabotLines.length - 1] += `\n${lines[i]}`;
} else if (otherLines.length && line) {
otherLines[otherLines.length - 1] += `\n${lines[i]}`;
}
}
i++;
}
const restOfDoc = lines.slice(i);
const updatedContent = [
...lines.slice(0, whatsChangedIdx + 1),
...otherLines,
'',
'## Dependabot',
...dependabotLines,
'',
...restOfDoc,
'',
fullChangelogLine // Ensure there's a space before it
].join('\n');
fs.writeFileSync(filePath, updatedContent.trimEnd() + '\n', 'utf8');
console.log(`Updated changelog written to ${filePath}`);
}
reorganizeChangelog('./CHANGELOG.md');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment