-
Notifications
You must be signed in to change notification settings - Fork 13
/
start.ts
73 lines (60 loc) · 2.12 KB
/
start.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
import * as clipboardy from 'clipboardy';
import chalk from 'chalk';
import inquirer from 'inquirer';
import Command, { flags } from '../../base';
import { issueArgs, getIssueId, IssueArgs } from '../../utils/issueId';
import { GetFlagsType } from '../../base';
import { render } from '../../components';
export default class IssueStart extends Command {
static description = 'Change status of issue to "In progress" and assign to yourself.';
static aliases = ['start', 's'];
static args = issueArgs;
static flags = {
'copy-branch': flags.boolean({
char: 'c',
description: 'copy git branch to clip-board',
}),
};
async run() {
const { args, flags } = this.parse<GetFlagsType<typeof IssueStart>, IssueArgs>(
IssueStart
);
const issueId = getIssueId(args);
const currentIssue = await this.linear.query.issue(issueId);
if (currentIssue.assignee && currentIssue.assignee.id !== this.user.id) {
const { confirmAssign } = await inquirer.prompt<{ confirmAssign: boolean }>([
{
name: 'confirmAssign',
message: `Issue ${render.IssueId(currentIssue.identifier)} is assigned to ${
currentIssue.assignee.displayName
}, do you want to assign to yourself?`,
type: 'confirm',
},
]);
if (!confirmAssign) {
return;
}
}
const nextState = currentIssue.team.states.nodes
.filter((state) => state.type === 'started')
.sort((s1, s2) => (s1.position > s2.position ? 1 : -1))[0];
await this.linear.issueUpdate(currentIssue.identifier, {
stateId: nextState.id,
assigneeId: this.user.id,
});
this.log('');
this.success(
`The state of issue ${render.IssueId(
currentIssue.identifier
)} is now in the ${render.Status(nextState)} state and is assigned to you.`
);
if (flags['copy-branch']) {
const gitBranch = `${currentIssue.identifier}/${currentIssue.title.replace(
/\s/g,
'-'
)}`.toLowerCase();
clipboardy.writeSync(gitBranch);
this.log(`${chalk.blue(gitBranch)} branch copied to clipboard`);
}
}
}