-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathstop.ts
80 lines (63 loc) · 2.42 KB
/
stop.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import * as inquirer from 'inquirer';
import ora from 'ora';
import { flags } from '@oclif/command';
import { IssueUpdateInput } from '../../generated/_documents';
import chalk from 'chalk';
import Command, { GetFlagsType } from '../../base';
import { render } from '../../components';
import { issueArgs, getIssueId, IssueArgs } from '../../utils/issueId';
export default class IssueStop extends Command {
static description = 'Return issue to preview state';
static aliases = ['stop'];
static flags = {
unassign: flags.boolean({ char: 'u', description: 'Unassign issue from yourself' }),
};
static args = issueArgs;
async run() {
const { args, flags } = this.parse<GetFlagsType<typeof IssueStop>, IssueArgs>(
IssueStop
);
const issueId = getIssueId(args);
const issue = await this.linear.query.issue(issueId, { historyCount: 20 });
if (issue.assignee?.id !== this.user.id) {
const currentAssigneeMessage = issue.assignee?.id
? `Current assignee is ${chalk.blue(issue.assignee.displayName)}`
: 'Currently nobody is assigned';
return this.warn(
`Issue ${render.IssueId(
issue.identifier
)} cannot be stopped because it is not assigned to you.\n${currentAssigneeMessage}.`
);
}
if (issue.state.type !== 'started') {
return this.warn(
`Issue ${render.IssueId(
issue.identifier
)} is not in a started status.\nCurrent status: ${render.Status(issue.state)}`
);
}
const { nextStateId } = await inquirer.prompt<{ nextStateId: string }>([
{
name: 'nextStateId',
message: 'Select which status',
type: 'list',
choices: issue.team.states.nodes
.filter((state) => state.type === 'unstarted')
.map((state) => ({ name: render.Status(state), value: state.id })),
},
]);
const unassign: IssueUpdateInput = flags.unassign ? { assigneeId: null } : {};
const spinner = ora('Updating issue').start();
await this.linear.issueUpdate(issue.id, { stateId: nextStateId, ...unassign });
const nextState = issue.team.states.nodes.find((state) => state.id === nextStateId);
spinner.stop();
this.log('');
this.success(
`The state of issue ${render.IssueId(
issue.identifier
)} now has status ${render.Status(nextState!)}${
flags.unassign ? ' and is no longer assigned to you' : ''
}.`
);
}
}