Skip to content

Instantly share code, notes, and snippets.

@pissang
Last active January 11, 2021 14:38
Show Gist options
  • Save pissang/4b6a1e76a837bb99820e766d577df66c to your computer and use it in GitHub Desktop.
Save pissang/4b6a1e76a837bb99820e766d577df66c to your computer and use it in GitHub Desktop.
Generate changelog for ECharts
const { Octokit } = require('@octokit/rest');
const octokit = new Octokit({
// auth: ''
});
const OWNER = 'apache';
const REPO = 'incubator-echarts';
const MILESTONE = 21;
async function generates() {
const desc = [];
const issues = await octokit.issues.listForRepo({
owner: OWNER,
repo: REPO,
state: 'closed',
milestone: MILESTONE
});
const addedMap = {};
function addItem(issue) {
if (addedMap[issue.number]) {
return;
}
const repoName = issue.repository
? issue.repository.full_name
: `${OWNER}/${REPO}`;
console.log(`added ${repoName}#${issue.number}`);
addedMap[issue.number] = true;
desc.push(
`+ ${issue.title} [#${issue.number}](https://github.com/${repoName}/issues/${issue.number}) ([${issue.user.login}](${issue.user.html_url}))`
);
}
for (let issue of issues.data) {
let added = false;
// Is a pull request
if (issue.pull_request) {
addItem(issue);
added = true;
}
else {
const events = await octokit.issues.listEventsForTimeline({
owner: OWNER,
repo: REPO,
per_page: 100,
issue_number: issue.number
});
// Find referenced pull request.
for (let event of events.data) {
if (event.event === 'cross-referenced') {
if (event.source.issue.pull_request) {
addItem(event.source.issue);
added = true;
}
}
}
}
if (!added) {
console.log(`${issue.number} not added`);
}
}
return desc.join('\n');
}
generates().then(str => {
console.log(str);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment