@cvr/linear 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -10
- package/bin/linear +0 -0
- package/package.json +25 -21
- package/skills/linear/SKILL.md +146 -0
- package/src/cli.ts +14 -0
- package/src/commands/api.ts +148 -0
- package/src/commands/auth.ts +46 -34
- package/src/commands/issue.ts +475 -201
- package/src/commands/project.ts +51 -0
- package/src/commands/team.ts +28 -5
- package/src/domain/Input.ts +55 -0
- package/src/domain/Linear.ts +134 -0
- package/src/lib/errors.ts +11 -18
- package/src/lib/flags.ts +5 -0
- package/src/lib/json.ts +5 -0
- package/src/main.ts +18 -30
- package/src/services/Config.ts +118 -129
- package/src/services/Linear.ts +421 -159
- package/tsconfig.json +67 -7
- package/src/services/Browser.ts +0 -23
- package/src/services/Stdin.ts +0 -34
package/src/commands/issue.ts
CHANGED
|
@@ -1,60 +1,114 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Terminal } from "@effect/platform";
|
|
3
|
-
import type { Context, Types } from "effect";
|
|
1
|
+
import { Argument, Command, Flag, Prompt } from "effect/unstable/cli";
|
|
4
2
|
import { Console, Effect, Option } from "effect";
|
|
5
|
-
import
|
|
3
|
+
import type { IssueDetails } from "../domain/Linear.js";
|
|
4
|
+
import { parseIssueSelector, validateText } from "../domain/Input.js";
|
|
5
|
+
import { InvalidInputError, NoIssuesError } from "../lib/errors.js";
|
|
6
|
+
import { jsonFlag } from "../lib/flags.js";
|
|
7
|
+
import { encodeJson } from "../lib/json.js";
|
|
6
8
|
import { LinearService } from "../services/Linear.js";
|
|
7
9
|
import { ConfigService } from "../services/Config.js";
|
|
8
10
|
|
|
9
|
-
/** Resolve LinearFetch<T> | undefined (LinearFetch is Promise-like lazy loader) */
|
|
10
|
-
const resolveFetch = <T>(fetch: PromiseLike<T> | undefined): Effect.Effect<T | null> =>
|
|
11
|
-
fetch
|
|
12
|
-
? Effect.tryPromise(() => Promise.resolve(fetch)).pipe(Effect.orElseSucceed(() => null))
|
|
13
|
-
: Effect.succeed(null);
|
|
14
|
-
|
|
15
11
|
// Options
|
|
16
|
-
const stateOption =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
const stateOption = Flag.string("state").pipe(
|
|
13
|
+
Flag.withAlias("s"),
|
|
14
|
+
Flag.withDescription("Filter by state type (started, unstarted, backlog, etc.)"),
|
|
15
|
+
Flag.optional,
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const limitOption = Flag.integer("limit").pipe(
|
|
19
|
+
Flag.withAlias("n"),
|
|
20
|
+
Flag.withDefault(20),
|
|
21
|
+
Flag.withDescription("Number of issues to show"),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const commentsOption = Flag.boolean("comments").pipe(
|
|
25
|
+
Flag.withDescription("Include issue comments"),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const childrenOption = Flag.boolean("children").pipe(Flag.withDescription("Include sub-issues"));
|
|
29
|
+
|
|
30
|
+
const relationsOption = Flag.boolean("relations").pipe(
|
|
31
|
+
Flag.withDescription("Include inbound and outbound issue relations"),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const titleOption = Flag.string("title").pipe(
|
|
35
|
+
Flag.withDescription("Issue title; enables non-interactive creation"),
|
|
36
|
+
Flag.optional,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const descriptionOption = Flag.string("description").pipe(
|
|
40
|
+
Flag.withDescription("Issue description in Markdown"),
|
|
41
|
+
Flag.optional,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const teamOption = Flag.string("team").pipe(
|
|
45
|
+
Flag.withDescription("Team key or UUID"),
|
|
46
|
+
Flag.optional,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const parentOption = Flag.string("parent").pipe(
|
|
50
|
+
Flag.withDescription("Parent issue identifier or UUID"),
|
|
51
|
+
Flag.optional,
|
|
20
52
|
);
|
|
21
53
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Options.withDescription("Number of issues to show"),
|
|
54
|
+
const projectOption = Flag.string("project").pipe(
|
|
55
|
+
Flag.withDescription("Project name, slug, or UUID"),
|
|
56
|
+
Flag.optional,
|
|
26
57
|
);
|
|
27
58
|
|
|
59
|
+
const priorityOption = Flag.integer("priority").pipe(
|
|
60
|
+
Flag.withDescription("Priority from 0 (none) to 4 (low)"),
|
|
61
|
+
Flag.optional,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const dryRunOption = Flag.boolean("dry-run").pipe(
|
|
65
|
+
Flag.withDescription("Validate and print the mutation without writing"),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const interactiveOption = Flag.boolean("interactive").pipe(
|
|
69
|
+
Flag.withDescription("Allow prompts when required input is missing"),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const bodyOption = Flag.string("body").pipe(Flag.withDescription("Comment body in Markdown"));
|
|
73
|
+
|
|
28
74
|
// Args
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
75
|
+
const issueIdsArg = Argument.string("id").pipe(
|
|
76
|
+
Argument.withDescription("Issue ID, URL, or identifier (repeat for bulk reads)"),
|
|
77
|
+
Argument.variadic(),
|
|
32
78
|
);
|
|
33
79
|
|
|
34
80
|
// linear issue list - List issues
|
|
35
81
|
export const issueListCommand = Command.make(
|
|
36
82
|
"list",
|
|
37
|
-
{ state: stateOption, limit: limitOption },
|
|
38
|
-
({ state, limit }) =>
|
|
83
|
+
{ state: stateOption, limit: limitOption, json: jsonFlag },
|
|
84
|
+
({ state, limit, json }) =>
|
|
39
85
|
Effect.gen(function* () {
|
|
40
|
-
|
|
86
|
+
if (limit < 1 || limit > 250) {
|
|
87
|
+
return yield* InvalidInputError.make({
|
|
88
|
+
message: "--limit must be between 1 and 250. Example: linear issue list --limit 20",
|
|
89
|
+
});
|
|
90
|
+
}
|
|
41
91
|
|
|
92
|
+
const linear = yield* LinearService;
|
|
42
93
|
const stateFilter = Option.getOrUndefined(state);
|
|
43
|
-
const issues = yield* linear.getMyIssues({ state: stateFilter });
|
|
94
|
+
const issues = yield* linear.getMyIssues({ state: stateFilter, limit });
|
|
44
95
|
|
|
45
96
|
if (issues.length === 0) {
|
|
46
|
-
yield* Console.log("No issues found.");
|
|
97
|
+
yield* Console.log(json ? "[]" : "No issues found.");
|
|
47
98
|
return;
|
|
48
99
|
}
|
|
49
100
|
|
|
50
|
-
yield* Console.log("\nYour Issues:\n");
|
|
51
|
-
|
|
52
101
|
const displayed = issues.slice(0, limit);
|
|
102
|
+
|
|
103
|
+
if (json) {
|
|
104
|
+
yield* Console.log(encodeJson(displayed));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
yield* Console.log("\nYour Issues:\n");
|
|
53
109
|
for (const issue of displayed) {
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
const priority = issue.priority ?? 0;
|
|
57
|
-
const priorityIcon = getPriorityIcon(priority);
|
|
110
|
+
const stateName = issue.state?.name ?? "Unknown";
|
|
111
|
+
const priorityIcon = getPriorityIcon(issue.priority.value);
|
|
58
112
|
|
|
59
113
|
yield* Console.log(
|
|
60
114
|
` ${priorityIcon} ${issue.identifier.padEnd(10)} ${stateName.padEnd(12)} ${truncate(issue.title, 50)}`,
|
|
@@ -67,195 +121,379 @@ export const issueListCommand = Command.make(
|
|
|
67
121
|
|
|
68
122
|
yield* Console.log("");
|
|
69
123
|
}),
|
|
124
|
+
).pipe(
|
|
125
|
+
Command.withDescription("List issues assigned to the authenticated user"),
|
|
126
|
+
Command.withExamples([
|
|
127
|
+
{ command: "linear issue list --json", description: "List assigned issues as JSON" },
|
|
128
|
+
{
|
|
129
|
+
command: "linear issue list --state started --limit 10 --json",
|
|
130
|
+
description: "List up to ten started issues",
|
|
131
|
+
},
|
|
132
|
+
]),
|
|
70
133
|
);
|
|
71
134
|
|
|
72
135
|
// linear issue view [id] - View issue details
|
|
73
|
-
export const issueViewCommand = Command.make(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
136
|
+
export const issueViewCommand = Command.make(
|
|
137
|
+
"view",
|
|
138
|
+
{
|
|
139
|
+
ids: issueIdsArg,
|
|
140
|
+
json: jsonFlag,
|
|
141
|
+
interactive: interactiveOption,
|
|
142
|
+
comments: commentsOption,
|
|
143
|
+
children: childrenOption,
|
|
144
|
+
relations: relationsOption,
|
|
145
|
+
},
|
|
146
|
+
({ ids, json, interactive, comments, children, relations }) =>
|
|
147
|
+
Effect.gen(function* () {
|
|
148
|
+
if (ids.length === 0 && !interactive) {
|
|
149
|
+
return yield* InvalidInputError.make({
|
|
150
|
+
message:
|
|
151
|
+
"Issue identifier required in non-interactive mode. Usage: linear issue view ISSUE-123 --json",
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
const selectedIds = yield* Effect.forEach(
|
|
155
|
+
ids.length === 0 ? [yield* selectIssue] : ids,
|
|
156
|
+
parseIssueSelector,
|
|
157
|
+
);
|
|
158
|
+
const linear = yield* LinearService;
|
|
159
|
+
const details = yield* Effect.forEach(
|
|
160
|
+
selectedIds,
|
|
161
|
+
(id) => linear.getIssueDetails(id, { comments, children, relations }),
|
|
162
|
+
{ concurrency: 4 },
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
if (json) {
|
|
166
|
+
yield* Console.log(encodeJson(details));
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
100
169
|
|
|
101
|
-
|
|
102
|
-
|
|
170
|
+
yield* Effect.forEach(details, renderIssueDetails, { discard: true });
|
|
171
|
+
}),
|
|
172
|
+
).pipe(
|
|
173
|
+
Command.withDescription("Read one or more issues"),
|
|
174
|
+
Command.withExamples([
|
|
175
|
+
{ command: "linear issue view ENG-123 --json", description: "Read one issue as JSON" },
|
|
176
|
+
{
|
|
177
|
+
command: "linear issue view ENG-123 ENG-124 --comments --json",
|
|
178
|
+
description: "Read several issues with comments",
|
|
179
|
+
},
|
|
180
|
+
{ command: "linear issue view --interactive", description: "Choose an issue interactively" },
|
|
181
|
+
]),
|
|
103
182
|
);
|
|
104
183
|
|
|
105
184
|
// linear issue start [id] - Start working on an issue
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// If no ID provided, prompt for selection
|
|
111
|
-
const issueId = yield* Option.match(id, {
|
|
112
|
-
onNone: () => selectIssue(linear),
|
|
113
|
-
onSome: (id) => Effect.succeed(id),
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
const issue = yield* linear.getIssue(issueId);
|
|
117
|
-
const issueTeam = yield* resolveFetch(issue.team);
|
|
118
|
-
|
|
119
|
-
// Get the "Started" state for this team
|
|
120
|
-
const states = yield* Effect.tryPromise({
|
|
121
|
-
try: async () => {
|
|
122
|
-
if (!issueTeam) return [];
|
|
123
|
-
const connection = await issueTeam.states();
|
|
124
|
-
return connection.nodes;
|
|
125
|
-
},
|
|
126
|
-
catch: () => [],
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
const startedState = states.find(
|
|
130
|
-
(s) => s.type === "started" || s.name.toLowerCase() === "in progress",
|
|
131
|
-
);
|
|
185
|
+
const optionalIssueIdArg = Argument.string("id").pipe(
|
|
186
|
+
Argument.withDescription("Issue ID, URL, or identifier"),
|
|
187
|
+
Argument.optional,
|
|
188
|
+
);
|
|
132
189
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
190
|
+
export const issueStartCommand = Command.make(
|
|
191
|
+
"start",
|
|
192
|
+
{
|
|
193
|
+
id: optionalIssueIdArg,
|
|
194
|
+
dryRun: dryRunOption,
|
|
195
|
+
json: jsonFlag,
|
|
196
|
+
interactive: interactiveOption,
|
|
197
|
+
},
|
|
198
|
+
({ id, dryRun, json, interactive }) =>
|
|
199
|
+
Effect.gen(function* () {
|
|
200
|
+
const selectedIssue = yield* Option.match(id, {
|
|
201
|
+
onNone: () =>
|
|
202
|
+
interactive
|
|
203
|
+
? selectIssue
|
|
204
|
+
: InvalidInputError.make({
|
|
205
|
+
message:
|
|
206
|
+
"Issue identifier required in non-interactive mode. Usage: linear issue start ISSUE-123 --dry-run",
|
|
207
|
+
}),
|
|
208
|
+
onSome: Effect.succeed,
|
|
209
|
+
});
|
|
210
|
+
const issueId = yield* parseIssueSelector(selectedIssue);
|
|
140
211
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
212
|
+
const linear = yield* LinearService;
|
|
213
|
+
const started = yield* linear.startIssue(issueId, { dryRun });
|
|
214
|
+
if (dryRun) {
|
|
215
|
+
yield* Console.log(
|
|
216
|
+
encodeJson({
|
|
217
|
+
dryRun: true,
|
|
218
|
+
operation: "issue.start",
|
|
219
|
+
input: { id: issueId },
|
|
220
|
+
result: started,
|
|
221
|
+
}),
|
|
222
|
+
);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (json) {
|
|
226
|
+
yield* Console.log(encodeJson(started));
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
145
229
|
|
|
146
|
-
|
|
147
|
-
|
|
230
|
+
yield* Console.log(`\nStarted: ${started.issue.identifier} - ${started.issue.title}`);
|
|
231
|
+
yield* Console.log(`State changed to: ${started.state.name}`);
|
|
232
|
+
yield* Console.log(`\nBranch name: ${started.branchName}`);
|
|
233
|
+
yield* Console.log("");
|
|
234
|
+
}),
|
|
235
|
+
).pipe(
|
|
236
|
+
Command.withDescription("Move an issue to its team's started state"),
|
|
237
|
+
Command.withExamples([
|
|
238
|
+
{
|
|
239
|
+
command: "linear issue start ENG-123 --dry-run",
|
|
240
|
+
description: "Validate and preview the state change",
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
command: "linear issue start ENG-123 --json",
|
|
244
|
+
description: "Start an issue and return the result as JSON",
|
|
245
|
+
},
|
|
246
|
+
]),
|
|
148
247
|
);
|
|
149
248
|
|
|
150
249
|
// linear issue create - Create a new issue
|
|
151
|
-
export const issueCreateCommand = Command.make(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
250
|
+
export const issueCreateCommand = Command.make(
|
|
251
|
+
"create",
|
|
252
|
+
{
|
|
253
|
+
title: titleOption,
|
|
254
|
+
description: descriptionOption,
|
|
255
|
+
team: teamOption,
|
|
256
|
+
parent: parentOption,
|
|
257
|
+
project: projectOption,
|
|
258
|
+
priority: priorityOption,
|
|
259
|
+
dryRun: dryRunOption,
|
|
260
|
+
json: jsonFlag,
|
|
261
|
+
interactive: interactiveOption,
|
|
262
|
+
},
|
|
263
|
+
({ title, description, team, parent, project, priority, dryRun, json, interactive }) =>
|
|
264
|
+
Effect.gen(function* () {
|
|
265
|
+
if (Option.isNone(title) && !interactive) {
|
|
266
|
+
return yield* InvalidInputError.make({
|
|
267
|
+
message:
|
|
268
|
+
'--title is required in non-interactive mode. Usage: linear issue create --team ENG --title "Title" --dry-run',
|
|
269
|
+
});
|
|
270
|
+
}
|
|
164
271
|
|
|
165
|
-
|
|
166
|
-
|
|
272
|
+
const linear = yield* LinearService;
|
|
273
|
+
const config = yield* ConfigService;
|
|
274
|
+
const linearConfig = yield* config.getConfig;
|
|
275
|
+
const teams = yield* linear.getTeams;
|
|
276
|
+
|
|
277
|
+
if (teams.length === 0) {
|
|
278
|
+
return yield* InvalidInputError.make({
|
|
279
|
+
message: "No teams found; an issue cannot be created",
|
|
280
|
+
});
|
|
281
|
+
}
|
|
167
282
|
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
283
|
+
const isInteractive = Option.isNone(title);
|
|
284
|
+
const requestedTeam = Option.getOrUndefined(team) ?? linearConfig.teamId;
|
|
285
|
+
const teamId = yield* resolveTeamId(teams, requestedTeam, isInteractive);
|
|
286
|
+
const issueTitle = yield* Option.match(title, {
|
|
287
|
+
onNone: () => Prompt.text({ message: "Issue title" }),
|
|
288
|
+
onSome: Effect.succeed,
|
|
289
|
+
});
|
|
290
|
+
const issueDescription = yield* Option.match(description, {
|
|
291
|
+
onNone: () =>
|
|
292
|
+
isInteractive
|
|
293
|
+
? Prompt.text({
|
|
294
|
+
message: "Description (optional, press Enter to skip)",
|
|
295
|
+
default: "",
|
|
296
|
+
})
|
|
297
|
+
: Effect.succeed(""),
|
|
298
|
+
onSome: Effect.succeed,
|
|
299
|
+
});
|
|
300
|
+
const validatedTitle = yield* validateText({
|
|
301
|
+
name: "Issue title",
|
|
302
|
+
value: issueTitle,
|
|
303
|
+
maximumLength: 255,
|
|
304
|
+
});
|
|
305
|
+
const validatedDescription = yield* validateText({
|
|
306
|
+
name: "Issue description",
|
|
307
|
+
value: issueDescription,
|
|
308
|
+
maximumLength: 100_000,
|
|
309
|
+
allowEmpty: true,
|
|
310
|
+
});
|
|
311
|
+
const priorityValue = Option.getOrUndefined(priority);
|
|
312
|
+
if (priorityValue !== undefined && (priorityValue < 0 || priorityValue > 4)) {
|
|
313
|
+
return yield* InvalidInputError.make({ message: "--priority must be between 0 and 4" });
|
|
175
314
|
}
|
|
176
|
-
} else if (teams.length === 1) {
|
|
177
|
-
teamId = teams[0].id;
|
|
178
|
-
yield* Console.log(`Using team: ${teams[0].name}`);
|
|
179
|
-
} else {
|
|
180
|
-
teamId = yield* selectTeam(teams);
|
|
181
|
-
}
|
|
182
315
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
316
|
+
const projectSelector = Option.getOrUndefined(project);
|
|
317
|
+
const projectId =
|
|
318
|
+
projectSelector === undefined
|
|
319
|
+
? undefined
|
|
320
|
+
: yield* resolveProjectId(yield* linear.getProjects, projectSelector);
|
|
321
|
+
const input = {
|
|
322
|
+
title: validatedTitle,
|
|
323
|
+
teamId,
|
|
324
|
+
description: validatedDescription.length === 0 ? undefined : validatedDescription,
|
|
325
|
+
parent: yield* Option.match(parent, {
|
|
326
|
+
onNone: () => Effect.succeed(undefined),
|
|
327
|
+
onSome: parseIssueSelector,
|
|
328
|
+
}),
|
|
329
|
+
projectId,
|
|
330
|
+
priority: priorityValue,
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
if (dryRun) {
|
|
334
|
+
yield* Console.log(encodeJson({ dryRun: true, operation: "issue.create", input }));
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Create the issue
|
|
339
|
+
const created = yield* linear.createIssue(input);
|
|
340
|
+
|
|
341
|
+
if (json) {
|
|
342
|
+
yield* Console.log(encodeJson(toCreatedIssue(created)));
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
yield* Console.log(`\nCreated: ${created.identifier} - ${created.title}`);
|
|
347
|
+
yield* Console.log(`URL: ${created.url}`);
|
|
348
|
+
yield* Console.log("");
|
|
349
|
+
}),
|
|
350
|
+
).pipe(
|
|
351
|
+
Command.withDescription("Create an issue interactively or from flags"),
|
|
352
|
+
Command.withExamples([
|
|
353
|
+
{
|
|
354
|
+
command: 'linear issue create --team ENG --title "Title" --dry-run',
|
|
355
|
+
description: "Validate and preview a non-interactive creation",
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
command: 'linear issue create --team ENG --title "Title" --json',
|
|
359
|
+
description: "Create an issue and return it as JSON",
|
|
360
|
+
},
|
|
361
|
+
{ command: "linear issue create --interactive", description: "Create with prompts" },
|
|
362
|
+
]),
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
export const issueCommentCommand = Command.make(
|
|
366
|
+
"comment",
|
|
367
|
+
{
|
|
368
|
+
id: Argument.string("id").pipe(Argument.withDescription("Issue ID, URL, or identifier")),
|
|
369
|
+
body: bodyOption,
|
|
370
|
+
dryRun: dryRunOption,
|
|
371
|
+
json: jsonFlag,
|
|
372
|
+
},
|
|
373
|
+
({ id, body, dryRun, json }) =>
|
|
374
|
+
Effect.gen(function* () {
|
|
375
|
+
const issueId = yield* parseIssueSelector(id);
|
|
376
|
+
const commentBody = yield* validateText({
|
|
377
|
+
name: "Comment body",
|
|
378
|
+
value: body,
|
|
379
|
+
maximumLength: 100_000,
|
|
380
|
+
});
|
|
381
|
+
if (dryRun) {
|
|
382
|
+
yield* Console.log(
|
|
383
|
+
encodeJson({
|
|
384
|
+
dryRun: true,
|
|
385
|
+
operation: "issue.comment",
|
|
386
|
+
input: { id: issueId, body: commentBody },
|
|
387
|
+
}),
|
|
388
|
+
);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const linear = yield* LinearService;
|
|
393
|
+
const comment = yield* linear.createComment(issueId, commentBody);
|
|
394
|
+
if (json) {
|
|
395
|
+
yield* Console.log(encodeJson(comment));
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
yield* Console.log(`Comment created: ${comment.url}`);
|
|
399
|
+
}),
|
|
400
|
+
).pipe(
|
|
401
|
+
Command.withDescription("Add a Markdown comment to an issue"),
|
|
402
|
+
Command.withExamples([
|
|
403
|
+
{
|
|
404
|
+
command: 'linear issue comment ENG-123 --body "Ready" --dry-run',
|
|
405
|
+
description: "Preview a comment without sending it",
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
command: 'linear issue comment ENG-123 --body "Ready" --json',
|
|
409
|
+
description: "Create a comment and return its URL",
|
|
410
|
+
},
|
|
411
|
+
]),
|
|
205
412
|
);
|
|
206
413
|
|
|
207
414
|
// Combined issue command with subcommands
|
|
208
415
|
export const issue = Command.make("issue", {}, () =>
|
|
209
416
|
Console.log("Use 'linear issue list' to list issues. See --help for more."),
|
|
210
417
|
).pipe(
|
|
418
|
+
Command.withDescription("Read and mutate Linear issues"),
|
|
211
419
|
Command.withSubcommands([
|
|
212
420
|
issueListCommand,
|
|
213
421
|
issueViewCommand,
|
|
214
422
|
issueStartCommand,
|
|
215
423
|
issueCreateCommand,
|
|
424
|
+
issueCommentCommand,
|
|
216
425
|
]),
|
|
217
426
|
);
|
|
218
427
|
|
|
219
428
|
// Helper functions
|
|
220
429
|
|
|
221
|
-
|
|
222
|
-
linear
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
LinearApiError | TokenNotFoundError | NoIssuesError | Types.NoInfer<Terminal.QuitException>,
|
|
226
|
-
Terminal.Terminal
|
|
227
|
-
> {
|
|
228
|
-
return Effect.gen(function* () {
|
|
229
|
-
const issues = yield* linear.getMyIssues({ state: "started" });
|
|
230
|
-
const allIssues =
|
|
231
|
-
issues.length > 0 ? issues : yield* linear.getMyIssues({ state: "unstarted" });
|
|
232
|
-
|
|
233
|
-
if (allIssues.length === 0) {
|
|
234
|
-
return yield* NoIssuesError.default;
|
|
235
|
-
}
|
|
430
|
+
const selectIssue = Effect.gen(function* () {
|
|
431
|
+
const linear = yield* LinearService;
|
|
432
|
+
const issues = yield* linear.getMyIssues({ state: "started" });
|
|
433
|
+
const allIssues = issues.length > 0 ? issues : yield* linear.getMyIssues({ state: "unstarted" });
|
|
236
434
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
Effect.gen(function* () {
|
|
241
|
-
const issueState = yield* resolveFetch(issue.state);
|
|
242
|
-
return {
|
|
243
|
-
title: `${issue.identifier}: ${truncate(issue.title, 40)}`,
|
|
244
|
-
value: issue.identifier,
|
|
245
|
-
description: issueState?.name ?? "Unknown state",
|
|
246
|
-
};
|
|
247
|
-
}),
|
|
248
|
-
),
|
|
249
|
-
);
|
|
435
|
+
if (allIssues.length === 0) {
|
|
436
|
+
return yield* NoIssuesError.default;
|
|
437
|
+
}
|
|
250
438
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
439
|
+
// Build choices with state info
|
|
440
|
+
const choices = allIssues.slice(0, 20).map((candidate) => ({
|
|
441
|
+
title: `${candidate.identifier}: ${truncate(candidate.title, 40)}`,
|
|
442
|
+
value: candidate.identifier,
|
|
443
|
+
description: candidate.state?.name ?? "Unknown state",
|
|
444
|
+
}));
|
|
255
445
|
|
|
256
|
-
|
|
446
|
+
const selected = yield* Prompt.select({
|
|
447
|
+
message: "Select an issue",
|
|
448
|
+
choices,
|
|
257
449
|
});
|
|
258
|
-
|
|
450
|
+
|
|
451
|
+
return selected;
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
const renderIssueDetails = Effect.fn("IssueCommand.renderDetails")(function* (
|
|
455
|
+
details: IssueDetails,
|
|
456
|
+
) {
|
|
457
|
+
yield* Console.log("");
|
|
458
|
+
yield* Console.log(`${details.identifier}: ${details.title}`);
|
|
459
|
+
yield* Console.log(`${"─".repeat(60)}`);
|
|
460
|
+
yield* Console.log(`State: ${details.state?.name ?? "Unknown"}`);
|
|
461
|
+
yield* Console.log(`Team: ${details.team?.name ?? "Unknown"}`);
|
|
462
|
+
yield* Console.log(`Priority: ${details.priority.label}`);
|
|
463
|
+
yield* Console.log(`Assignee: ${details.assignee?.name ?? "Unassigned"}`);
|
|
464
|
+
yield* Console.log(`Project: ${details.project?.name ?? "None"}`);
|
|
465
|
+
yield* Console.log(`Parent: ${details.parent?.identifier ?? "None"}`);
|
|
466
|
+
yield* Console.log(`Branch: ${details.branchName}`);
|
|
467
|
+
yield* Console.log(`URL: ${details.url}`);
|
|
468
|
+
|
|
469
|
+
if (details.description !== undefined) {
|
|
470
|
+
yield* Console.log(`\nDescription:\n${details.description}`);
|
|
471
|
+
}
|
|
472
|
+
if (details.children !== undefined) {
|
|
473
|
+
yield* Console.log(`\nSub-issues (${details.children.length}):`);
|
|
474
|
+
for (const child of details.children) {
|
|
475
|
+
yield* Console.log(` ${child.identifier} ${child.title}`);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
if (details.comments !== undefined) {
|
|
479
|
+
yield* Console.log(`\nComments (${details.comments.length}):`);
|
|
480
|
+
for (const comment of details.comments) {
|
|
481
|
+
yield* Console.log(
|
|
482
|
+
` ${comment.author?.name ?? "Unknown"} · ${comment.createdAt}\n ${comment.body}`,
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
if (details.relations !== undefined) {
|
|
487
|
+
yield* Console.log(`\nRelations (${details.relations.length}):`);
|
|
488
|
+
for (const relation of details.relations) {
|
|
489
|
+
yield* Console.log(
|
|
490
|
+
` ${relation.direction} ${relation.type} ${relation.issue.identifier} ${relation.issue.title}`,
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
yield* Console.log("");
|
|
496
|
+
});
|
|
259
497
|
|
|
260
498
|
function selectTeam(teams: readonly { id: string; key: string; name: string }[]) {
|
|
261
499
|
return Prompt.select({
|
|
@@ -267,6 +505,59 @@ function selectTeam(teams: readonly { id: string; key: string; name: string }[])
|
|
|
267
505
|
});
|
|
268
506
|
}
|
|
269
507
|
|
|
508
|
+
const resolveTeamId = Effect.fn("IssueCommand.resolveTeamId")(function* (
|
|
509
|
+
teams: readonly { id: string; key: string; name: string }[],
|
|
510
|
+
selector: string | undefined,
|
|
511
|
+
interactive: boolean,
|
|
512
|
+
) {
|
|
513
|
+
if (selector !== undefined) {
|
|
514
|
+
const normalized = selector.toLowerCase();
|
|
515
|
+
const selected = teams.find(
|
|
516
|
+
(team) => team.id === selector || team.key.toLowerCase() === normalized,
|
|
517
|
+
);
|
|
518
|
+
return selected === undefined
|
|
519
|
+
? yield* InvalidInputError.make({ message: `Unknown team: ${selector}` })
|
|
520
|
+
: selected.id;
|
|
521
|
+
}
|
|
522
|
+
if (teams.length === 1) {
|
|
523
|
+
const [team] = teams;
|
|
524
|
+
return team === undefined
|
|
525
|
+
? yield* InvalidInputError.make({ message: "No team available" })
|
|
526
|
+
: team.id;
|
|
527
|
+
}
|
|
528
|
+
return interactive
|
|
529
|
+
? yield* selectTeam(teams)
|
|
530
|
+
: yield* InvalidInputError.make({ message: "--team is required when multiple teams exist" });
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
const resolveProjectId = Effect.fn("IssueCommand.resolveProjectId")(function* (
|
|
534
|
+
projects: readonly { id: string; name: string; slug: string }[],
|
|
535
|
+
selector: string,
|
|
536
|
+
) {
|
|
537
|
+
const normalized = selector.toLowerCase();
|
|
538
|
+
const selected = projects.find(
|
|
539
|
+
(project) =>
|
|
540
|
+
project.id === selector ||
|
|
541
|
+
project.name.toLowerCase() === normalized ||
|
|
542
|
+
project.slug.toLowerCase() === normalized,
|
|
543
|
+
);
|
|
544
|
+
return selected === undefined
|
|
545
|
+
? yield* InvalidInputError.make({ message: `Unknown project: ${selector}` })
|
|
546
|
+
: selected.id;
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
const toCreatedIssue = (created: {
|
|
550
|
+
id: string;
|
|
551
|
+
identifier: string;
|
|
552
|
+
title: string;
|
|
553
|
+
url: string;
|
|
554
|
+
}) => ({
|
|
555
|
+
id: created.id,
|
|
556
|
+
identifier: created.identifier,
|
|
557
|
+
title: created.title,
|
|
558
|
+
url: created.url,
|
|
559
|
+
});
|
|
560
|
+
|
|
270
561
|
function truncate(str: string, len: number): string {
|
|
271
562
|
return str.length > len ? str.slice(0, len - 1) + "…" : str;
|
|
272
563
|
}
|
|
@@ -287,20 +578,3 @@ function getPriorityIcon(priority: number): string {
|
|
|
287
578
|
return "○";
|
|
288
579
|
}
|
|
289
580
|
}
|
|
290
|
-
|
|
291
|
-
function getPriorityLabel(priority: number): string {
|
|
292
|
-
switch (priority) {
|
|
293
|
-
case 0:
|
|
294
|
-
return "No priority";
|
|
295
|
-
case 1:
|
|
296
|
-
return "Urgent";
|
|
297
|
-
case 2:
|
|
298
|
-
return "High";
|
|
299
|
-
case 3:
|
|
300
|
-
return "Medium";
|
|
301
|
-
case 4:
|
|
302
|
-
return "Low";
|
|
303
|
-
default:
|
|
304
|
-
return "Unknown";
|
|
305
|
-
}
|
|
306
|
-
}
|