Skip to content

Instantly share code, notes, and snippets.

@thomasmichaelwallace
Created April 15, 2020 12:53
Show Gist options
  • Save thomasmichaelwallace/1f40cbf6f686c67b34eafa052a69d17f to your computer and use it in GitHub Desktop.
Save thomasmichaelwallace/1f40cbf6f686c67b34eafa052a69d17f to your computer and use it in GitHub Desktop.
Use lerna to backfill GitHub release notes from a change log.
/* eslint-disable no-console */
const createRelease = require('@lerna/version/lib/create-release.js'); // eslint-disable-line import/no-extraneous-dependencies
const fs = require('fs');
function parseEntry(entry) {
const lines = entry.split('\n');
const header = lines.shift();
const [version] = header.split(']');
const tag = `v${version}`;
const title = `# [${header}`;
lines.unshift(title);
const body = lines.join('\n').trim();
return { tag, body };
}
function getReleases() {
const log = fs.readFileSync('./CHANGELOG.md').toString();
const entries = log.split(/#+ \[/);
entries.shift(); // dump header
entries.shift(); // dump already released version
const releases = entries.map((e) => parseEntry(e));
return releases;
}
async function push(release) {
const { tag, body } = release;
const type = 'github';
const git = {
gitRemote: 'origin',
// execOpts: ?,
};
const details = {
tags: [tag],
releaseNotes: [{ name: 'fixed', notes: body }],
};
try {
// console.log(body);
await createRelease(type, details, git);
} catch (e) {
console.error(e);
}
}
async function pushAll(releases, offset = 0) {
const release = releases[offset];
if (!release) {
console.log('complete');
return releases.length;
}
console.log(`[${offset + 1}/${releases.length}] releasing ${release.tag}...`);
await push(release);
return pushAll(releases, offset + 1);
}
console.log('backfilling release notes');
const releases = getReleases();
pushAll(releases, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment