mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 03:34:15 -06:00
Toolkit: Remove unused close-milestone command (#57062)
* Toolkit: Remove unused close-milestone command * Remove import line
This commit is contained in:
parent
27f072beb3
commit
0abf04a20f
@ -1,7 +1,6 @@
|
||||
import chalk from 'chalk';
|
||||
import { program } from 'commander';
|
||||
|
||||
import { closeMilestoneTask } from './tasks/closeMilestone';
|
||||
import { componentCreateTask } from './tasks/component.create';
|
||||
import { nodeVersionCheckerTask } from './tasks/nodeVersionChecker';
|
||||
import { buildPackageTask } from './tasks/package.build';
|
||||
@ -65,23 +64,6 @@ export const run = (includeInternalScripts = false) => {
|
||||
await execTask(searchTestDataSetupTask)({ count: cmd.count });
|
||||
});
|
||||
|
||||
program
|
||||
.command('close-milestone')
|
||||
.option('-m, --milestone <milestone>', 'Specify milestone')
|
||||
.option('--dryRun', 'Only simulate actions')
|
||||
.description('Helps ends a milestone by removing the cherry-pick label and closing it')
|
||||
.action(async (cmd) => {
|
||||
if (!cmd.milestone) {
|
||||
console.log('Please specify milestone, example: -m <milestone id from github milestone URL>');
|
||||
return;
|
||||
}
|
||||
|
||||
await execTask(closeMilestoneTask)({
|
||||
milestone: cmd.milestone,
|
||||
dryRun: !!cmd.dryRun,
|
||||
});
|
||||
});
|
||||
|
||||
// React generator
|
||||
program
|
||||
.command('component:create')
|
||||
|
@ -1,96 +0,0 @@
|
||||
import GithubClient from '../utils/githubClient';
|
||||
|
||||
import { Task, TaskRunner } from './task';
|
||||
|
||||
interface CloseMilestoneOptions {
|
||||
milestone: string;
|
||||
dryRun: boolean;
|
||||
}
|
||||
|
||||
const closeMilestoneTaskRunner: TaskRunner<CloseMilestoneOptions> = async ({ milestone, dryRun }) => {
|
||||
const githubClient = new GithubClient({ required: true });
|
||||
|
||||
const cherryPickLabel = 'cherry-pick needed';
|
||||
const client = githubClient.client;
|
||||
|
||||
if (!/^\d+$/.test(milestone)) {
|
||||
console.log('Use milestone number not title, find number in milestone url');
|
||||
return;
|
||||
}
|
||||
|
||||
if (dryRun) {
|
||||
console.log('dry run is enabled');
|
||||
}
|
||||
|
||||
const milestoneRes = await client.get(`/milestones/${milestone}`, {});
|
||||
|
||||
const milestoneState = milestoneRes.data.state;
|
||||
|
||||
if (milestoneState === 'closed') {
|
||||
console.log('milestone already closed. ✅');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('fetching issues/PRs of the milestone ⏬');
|
||||
|
||||
let totalIssues = 0;
|
||||
|
||||
while (true) {
|
||||
// Get first 100 issues/PRs with the label cherry-pick
|
||||
// Every pull request is actually an issue
|
||||
const issuesRes = await client.get('/issues', {
|
||||
params: {
|
||||
state: 'closed',
|
||||
labels: cherryPickLabel,
|
||||
per_page: 100,
|
||||
milestone: milestone,
|
||||
},
|
||||
});
|
||||
|
||||
if (issuesRes.data.length < 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
const comparativeStr = totalIssues === 0 ? ' ' : ' more ';
|
||||
console.log(`found ${issuesRes.data.length}${comparativeStr}issues to remove the cherry-pick label from 🔎`);
|
||||
totalIssues += issuesRes.data.length;
|
||||
|
||||
for (const issue of issuesRes.data) {
|
||||
// the reason for using stdout.write is for achieving 'action -> result' on
|
||||
// the same line
|
||||
process.stdout.write(`🔧removing label from issue #${issue.number} 🗑...`);
|
||||
if (!dryRun) {
|
||||
const resDelete = await client.delete(`/issues/${issue.number}/labels/${cherryPickLabel}`, {});
|
||||
if (resDelete.status === 200) {
|
||||
process.stdout.write('done ✅\n');
|
||||
} else {
|
||||
console.log('failed ❌');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (totalIssues === 0) {
|
||||
console.log('no issues to remove label from');
|
||||
} else {
|
||||
console.log(`cleaned up ${totalIssues} issues/prs ⚡️`);
|
||||
}
|
||||
|
||||
if (!dryRun) {
|
||||
const resClose = await client.patch(`/milestones/${milestone}`, {
|
||||
state: 'closed',
|
||||
});
|
||||
|
||||
if (resClose.status === 200) {
|
||||
console.log('milestone closed 🙌');
|
||||
} else {
|
||||
console.log('failed to close the milestone, response:');
|
||||
console.log(resClose);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const closeMilestoneTask = new Task<CloseMilestoneOptions>(
|
||||
'Close Milestone generator task',
|
||||
closeMilestoneTaskRunner
|
||||
);
|
Loading…
Reference in New Issue
Block a user