Added first iteration/poc of changelog task

This commit is contained in:
Torkel Ödegaard
2019-03-05 15:53:25 +01:00
parent 3fc24fa964
commit 10ff3db1ab
4 changed files with 50 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import chalk from 'chalk';
import { startTask } from './tasks/core.start';
import { buildTask } from './tasks/grafanaui.build';
import { releaseTask } from './tasks/grafanaui.release';
import { changelogTask } from './tasks/changelog';
program.option('-d, --depreciate <scripts>', 'Inform about npm script deprecation', v => v.split(','));
@@ -38,6 +39,13 @@ program
});
});
program
.command('core:changelog')
.description('Builds changelog markdown')
.action(async cmd => {
await execTask(changelogTask)({});
});
program.parse(process.argv);
if (program.depreciate && program.depreciate.length === 2) {

View File

@@ -0,0 +1,34 @@
import { Task, TaskRunner } from './task';
import axios from 'axios';
import issueRegex from 'issue-regex';
const githubGrafanaUrl = 'https://github.com/grafana/grafana';
interface ChangelogOptions {}
const changelogTaskRunner: TaskRunner<ChangelogOptions> = async () => {
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'));
let markdown = '';
for (const item of res.data) {
markdown += '* ' + item.title;
markdown += ` [#${item.number}](${githubGrafanaUrl}/issues/${item.number})`;
for (const issue of item.body.match(issueRegex())) {
markdown += ` [#${issue}](${githubGrafanaUrl}/issues/${issue})`;
}
markdown += '\n';
}
console.log(markdown);
};
export const changelogTask = new Task<ChangelogOptions>();
changelogTask.setName('Changelog generator task');
changelogTask.setRunner(changelogTaskRunner);