diff --git a/scripts/cli/index.ts b/scripts/cli/index.ts index 108f7877569..d2b3c75a61b 100644 --- a/scripts/cli/index.ts +++ b/scripts/cli/index.ts @@ -41,9 +41,17 @@ program program .command('core:changelog') + .option('-m, --milestone ', 'Specify milestone') .description('Builds changelog markdown') .action(async cmd => { - await execTask(changelogTask)({}); + if (!cmd.milestone) { + console.log('Please specify milestone, example: --m 6.0.1'); + return; + } + + await execTask(changelogTask)({ + milestone: cmd.milestone, + }); }); program.parse(process.argv); diff --git a/scripts/cli/tasks/changelog.ts b/scripts/cli/tasks/changelog.ts index 1e8ebf9c09c..fc56c60531c 100644 --- a/scripts/cli/tasks/changelog.ts +++ b/scripts/cli/tasks/changelog.ts @@ -3,18 +3,37 @@ import axios from 'axios'; const githubGrafanaUrl = 'https://github.com/grafana/grafana'; -interface ChangelogOptions {} +interface ChangelogOptions { + milestone: string; +} -const changelogTaskRunner: TaskRunner = async () => { +const changelogTaskRunner: TaskRunner = async ({ milestone }) => { let client = axios.create({ baseURL: 'https://api.github.com/repos/grafana/grafana', timeout: 10000, }); - const res = await client.get('/issues?state=closed&labels=' + encodeURIComponent('add to changelog')); + const res = await client.get('/issues', { + params: { + state: 'closed', + labels: 'add to changelog', + }, + }); + let markdown = ''; for (const item of res.data) { + if (!item.milestone) { + console.log('Item missing milestone', item.number); + continue; + } + + // For some reason I could not get the github api to filter on milestone and label + // So doing this filter here + if (item.milestone.title !== milestone) { + continue; + } + markdown += '* ' + item.title + '.'; markdown += ` [#${item.number}](${githubGrafanaUrl}/pull/${item.number})`; markdown += `, [@${item.user.login}](${item.user.html_url})`;