grafana/scripts/cli/tasks/changelog.ts
gotjosh bc94f85dee
Improvement: Grafana release process minor improvements (#17661)
* Don't display changelog category title when no items

The output of the changelog is meant to be copy/pasted with ease. When a
changelog category does not contain items is better to not display title
at all thus avoiding having the manually modify the output as we include
it in the steps of the process.

* Introduce a CLI task to close milestones whilst doing a Grafana release

As part of a Grafana release, we need to eventually close the GitHub
milestone to indicate is done and remove all the cherry-pick labels from
issues/prs within the milestone to avoid our cherry-pick CLI command to
pick them up on the next release.

* Abstract the GitHub client into a module

* Introduce `GitHubClient` to all CLI tasks
2019-06-24 16:00:01 +01:00

84 lines
2.0 KiB
TypeScript

import _ from 'lodash';
import { Task, TaskRunner } from './task';
import GithubClient from '../utils/githubClient';
interface ChangelogOptions {
milestone: string;
}
const changelogTaskRunner: TaskRunner<ChangelogOptions> = async ({ milestone }) => {
const githubClient = new GithubClient();
const client = githubClient.client;
if (!/^\d+$/.test(milestone)) {
console.log('Use milestone number not title, find number in milestone url');
return;
}
const res = await client.get('/issues', {
params: {
state: 'closed',
per_page: 100,
labels: 'add to changelog',
milestone: milestone,
},
});
const issues = res.data;
const bugs = _.sortBy(
issues.filter(item => {
if (item.title.match(/fix|fixes/i)) {
return true;
}
if (item.labels.find(label => label.name === 'type/bug')) {
return true;
}
return false;
}),
'title'
);
const notBugs = _.sortBy(issues.filter(item => !bugs.find(bug => bug === item)), 'title');
let markdown = '';
if (notBugs.length > 0) {
markdown = '### Features / Enhancements\n';
}
for (const item of notBugs) {
markdown += getMarkdownLineForIssue(item);
}
if (bugs.length > 0) {
markdown += '\n### Bug Fixes\n';
}
for (const item of bugs) {
markdown += getMarkdownLineForIssue(item);
}
console.log(markdown);
};
function getMarkdownLineForIssue(item: any) {
const githubGrafanaUrl = 'https://github.com/grafana/grafana';
let markdown = '';
const title = item.title.replace(/^([^:]*)/, (match, g1) => {
return `**${g1}**`;
});
markdown += '* ' + title + '.';
markdown += ` [#${item.number}](${githubGrafanaUrl}/pull/${item.number})`;
markdown += `, [@${item.user.login}](${item.user.html_url})`;
markdown += '\n';
return markdown;
}
export const changelogTask = new Task<ChangelogOptions>();
changelogTask.setName('Changelog generator task');
changelogTask.setRunner(changelogTaskRunner);