Skip to content

Commit

Permalink
feat(tools): Add script to generate changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Clashsoft committed Dec 13, 2023
1 parent 2bb0605 commit 298330e
Show file tree
Hide file tree
Showing 4 changed files with 517 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
66 changes: 66 additions & 0 deletions tools/generate-release-notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {Octokit} from 'octokit';

const milestone = +process.argv[2];

const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
});

// get issues for milestone
async function getIssues(milestone) {
return octokit.paginate(
'GET /repos/{owner}/{repo}/issues',
{
owner: 'fujaba',
repo: 'fulib.org',
state: 'closed',
milestone,
},
);
}


function generateReleaseBody(issues) {
// Each issue is a pull request with a body like this:
// ```
// ## New Changes
// + ...
// ## Improvements
// * ...
// ## Bugfixes
// * ...
// ```

// Group by these sections and append the issue number at the end of each bullet point.
const sections = {
'General': [],
'New Features': [],
'Improvements': [],
'Bugfixes': [],
'Removals': [],
};
for (const issue of issues) {
const body = issue.body;
const lines = body.split('\r\n');
let section = null;
for (const line of lines) {
if (line.startsWith('##')) {
section = line.substr(3);
if (!sections[section]) {
sections[section] = [];
}
} else if (section && (line.startsWith('+') || line.startsWith('*') || line.startsWith('-'))) {
sections[section].push(line + ' #' + issue.number);
}
}
}

// Append the sections to the release body.
return Object.entries(sections)
.filter(section => section[1].length > 0)
.map(section => `## ${section[0]}\n\n${section[1].join('\n')}`)
.join('\n\n');
}

const issues = await getIssues(milestone);
console.log(generateReleaseBody(issues));
6 changes: 6 additions & 0 deletions tools/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "module",
"dependencies": {
"octokit": "^3.1.2"
}
}
Loading

0 comments on commit 298330e

Please sign in to comment.