Toolkit: Remove changelog command (already replaced by a github workflow) (#56073)

Co-authored-by: gitstart <gitstart@gitstart.com>
Co-authored-by: Rubens Rafael <70234898+RubensRafael@users.noreply.github.com>
Co-authored-by: Matheus Muniz <matheusmuniz100@hotmail.com>
Co-authored-by: Nitesh Singh <nitesh.singh@gitstart.dev>
Co-authored-by: Matheus Benini Ferreira <88898100+MatheusBeniniF@users.noreply.github.com>
Co-authored-by: Thiago Nascimbeni <tnascimbeni@gmail.com>
Co-authored-by: Rafael Toledo <87545086+Toledodev@users.noreply.github.com>
Co-authored-by: Murilo Amaral <87545137+MuriloAmarals@users.noreply.github.com>
pull/56398/head
GitStart 3 years ago committed by GitHub
parent 87cba8836f
commit 48ebaa48cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      .betterer.results
  2. 17
      packages/grafana-toolkit/src/cli/index.ts
  3. 148
      packages/grafana-toolkit/src/cli/tasks/changelog.ts

@ -1101,21 +1101,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Do not use any type assertions.", "1"]
],
"packages/grafana-toolkit/src/cli/tasks/changelog.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
[0, 0, 0, "Unexpected any. Specify a different type.", "6"],
[0, 0, 0, "Unexpected any. Specify a different type.", "7"],
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
[0, 0, 0, "Unexpected any. Specify a different type.", "9"],
[0, 0, 0, "Unexpected any. Specify a different type.", "10"],
[0, 0, 0, "Unexpected any. Specify a different type.", "11"],
[0, 0, 0, "Unexpected any. Specify a different type.", "12"]
],
"packages/grafana-toolkit/src/cli/tasks/component.create.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]

@ -1,7 +1,6 @@
import chalk from 'chalk';
import { program } from 'commander';
import { changelogTask } from './tasks/changelog';
import { closeMilestoneTask } from './tasks/closeMilestone';
import { componentCreateTask } from './tasks/component.create';
import { nodeVersionCheckerTask } from './tasks/nodeVersionChecker';
@ -37,22 +36,6 @@ export const run = (includeInternalScripts = false) => {
});
});
program
.command('changelog')
.option('-m, --milestone <milestone>', 'Specify milestone')
.description('Builds changelog markdown')
.action(async (cmd) => {
if (!cmd.milestone) {
console.log('Please specify milestone, example: -m <milestone id from github milestone URL>');
return;
}
await execTask(changelogTask)({
milestone: cmd.milestone,
silent: true,
});
});
program
.command('node-version-check')
.description('Verify node version')

@ -1,148 +0,0 @@
import chalk from 'chalk';
import { difference, sortBy } from 'lodash';
import GithubClient from '../utils/githubClient';
import { useSpinner } from '../utils/useSpinner';
import { Task } from './task';
interface ChangelogOptions {
milestone: string;
}
const filterBugs = (item: any) => {
if (item.title.match(/fix|fixes/i)) {
return true;
}
if (item.labels.find((label: any) => label.name === 'type/bug')) {
return true;
}
return false;
};
const getPackageChangelog = (packageName: string, issues: any[]) => {
if (issues.length === 0) {
return '';
}
let markdown = chalk.bold.yellow(`\n\n/*** ${packageName} changelog ***/\n\n`);
const bugs = sortBy(issues.filter(filterBugs), 'title');
const notBugs = sortBy(difference(issues, bugs), 'title');
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);
}
}
return markdown;
};
const changelogTaskRunner = ({ milestone }: ChangelogOptions) =>
useSpinner('Generating changelog', async () => {
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;
}
let res = await client.get('/issues', {
params: {
state: 'closed',
per_page: 100,
labels: 'add to changelog',
milestone: milestone,
},
});
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 = [];
for (const item of data) {
if (!item.pull_request) {
// it's an issue, not pull request
mergedIssues.push(item);
continue;
}
const isMerged = await client.get(item.pull_request.url + '/merge');
if (isMerged.status === 204) {
mergedIssues.push(item);
}
}
const issues = sortBy(mergedIssues, 'title');
const toolkitIssues = issues.filter((item: any) =>
item.labels.find((label: any) => label.name === 'area/grafana/toolkit')
);
const grafanaUiIssues = issues.filter((item: any) =>
item.labels.find((label: any) => label.name === 'area/grafana/ui')
);
let markdown = '';
markdown += getPackageChangelog('Grafana', issues);
markdown += getPackageChangelog('grafana-toolkit', toolkitIssues);
markdown += getPackageChangelog('grafana-ui', grafanaUiIssues);
console.log(markdown);
});
function getMarkdownLineForIssue(item: any) {
const githubGrafanaUrl = 'https://github.com/grafana/grafana';
let markdown = '';
let title: string = item.title.replace(/^([^:]*)/, (_match: any, g1: any) => {
return `**${g1}**`;
});
title = title.trim();
if (title[title.length - 1] === '.') {
title = title.slice(0, -1);
}
if (!item.pull_request) {
markdown += '* ' + title + '.';
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';
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);
Loading…
Cancel
Save