Logo GiwiSoft
Générer un changelog Github

Générer un changelog Github

Xavier MARIN Xavier MARIN Non classé

Bon, c’est cadeau, voici un script NodeJS pour vous générer un changelog tout beau tout propre avec les commits (hors merge) entre 2 tags Github :

#!/usr/bin/env node
const { execSync } = require('child_process');
let repo = '';
let md =
`TITRE DE VOTRE CHANGELOG
---

`;
// changez 'head -n 10' pour avoir autre chose que les 10 derniers tags
let tagList = execSync('git tag --sort=-committerdate | head -n 10').toString().split('\n');
let lastTag = tagList[0];
tagList = tagList.slice(1, -1);
tagList.forEach(tag => {
md += `## ${lastTag}

`;
execSync(`git log --no-merges --date=iso --format="> + ts%ct | %s %N (*[%cN](%ce) | [view commit](${repo}/commit/%H)*)" ${tag}..${lastTag}`)
.toString().split('\n').forEach(l => {
let timestamp = /ts([0-9]+)/.exec(l);
if (timestamp) {
l = l.replace('ts' + timestamp[1], new Date(timestamp[1] * 1000).toISOString().split('T')[0].replace(/\-/gi, '/'));
}
let issue = /#([0-9]+)/.exec(l);
if (issue) {
l = l.replace('#' + issue[1], `[#${issue[1]}](${repo}/issues/${issue[1]})`);
}
md += l + '\n';
});
lastTag = tag;

});
console.log(md);

Usage :

node changelog.js > CHANGELOG.md