-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tools): Add script to generate changelog
- Loading branch information
Showing
4 changed files
with
517 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"type": "module", | ||
"dependencies": { | ||
"octokit": "^3.1.2" | ||
} | ||
} |
Oops, something went wrong.