Fix pagination of issues/PR's in changelog generator (#23997)
Fix pagination of issues/PR's in changelog generator
This commit is contained in:
@@ -57,7 +57,7 @@ const changelogTaskRunner: TaskRunner<ChangelogOptions> = useSpinner<ChangelogOp
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await client.get('/issues', {
|
let res = await client.get('/issues', {
|
||||||
params: {
|
params: {
|
||||||
state: 'closed',
|
state: 'closed',
|
||||||
per_page: 100,
|
per_page: 100,
|
||||||
@@ -66,8 +66,20 @@ const changelogTaskRunner: TaskRunner<ChangelogOptions> = useSpinner<ChangelogOp
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const data: any[] = res.data;
|
||||||
|
|
||||||
|
while (res.headers.link) {
|
||||||
|
const links = parseLink(res.headers.link);
|
||||||
|
if (links.next) {
|
||||||
|
res = await client.get(links.next);
|
||||||
|
data.push(...res.data);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const mergedIssues = [];
|
const mergedIssues = [];
|
||||||
for (const item of res.data) {
|
for (const item of data) {
|
||||||
if (!item.pull_request) {
|
if (!item.pull_request) {
|
||||||
// it's an issue, not pull request
|
// it's an issue, not pull request
|
||||||
mergedIssues.push(item);
|
mergedIssues.push(item);
|
||||||
@@ -100,17 +112,39 @@ const changelogTaskRunner: TaskRunner<ChangelogOptions> = useSpinner<ChangelogOp
|
|||||||
function getMarkdownLineForIssue(item: any) {
|
function getMarkdownLineForIssue(item: any) {
|
||||||
const githubGrafanaUrl = 'https://github.com/grafana/grafana';
|
const githubGrafanaUrl = 'https://github.com/grafana/grafana';
|
||||||
let markdown = '';
|
let markdown = '';
|
||||||
const title = item.title.replace(/^([^:]*)/, (_match: any, g1: any) => {
|
let title: string = item.title.replace(/^([^:]*)/, (_match: any, g1: any) => {
|
||||||
return `**${g1}**`;
|
return `**${g1}**`;
|
||||||
});
|
});
|
||||||
|
title = title.trim();
|
||||||
|
if (title[title.length - 1] === '.') {
|
||||||
|
title = title.slice(0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
markdown += '* ' + title + '.';
|
if (!item.pull_request) {
|
||||||
markdown += ` [#${item.number}](${githubGrafanaUrl}/pull/${item.number})`;
|
markdown += '* ' + title + '.';
|
||||||
markdown += `, [@${item.user.login}](${item.user.html_url})`;
|
markdown += ` [#${item.number}](${githubGrafanaUrl}/issues/${item.number})`;
|
||||||
|
} else {
|
||||||
|
markdown += '* ' + title + '.';
|
||||||
|
markdown += ` [#${item.number}](${githubGrafanaUrl}/pull/${item.number})`;
|
||||||
|
markdown += `, [@${item.user.login}](${item.user.html_url})`;
|
||||||
|
}
|
||||||
|
|
||||||
markdown += '\n';
|
markdown += '\n';
|
||||||
|
|
||||||
return markdown;
|
return markdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseLink(s: any) {
|
||||||
|
const output: any = {};
|
||||||
|
const regex = /<([^>]+)>; rel="([^"]+)"/g;
|
||||||
|
|
||||||
|
let m;
|
||||||
|
while ((m = regex.exec(s))) {
|
||||||
|
const [, v, k] = m;
|
||||||
|
output[k] = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
export const changelogTask = new Task<ChangelogOptions>('Changelog generator task', changelogTaskRunner);
|
export const changelogTask = new Task<ChangelogOptions>('Changelog generator task', changelogTaskRunner);
|
||||||
|
|||||||
Reference in New Issue
Block a user