@cvr/linear 0.3.0 → 0.5.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 +22 -10
- package/bin/linear +2 -2
- package/package.json +8 -6
- package/skills/linear/SKILL.md +23 -6
- package/src/cli.ts +15 -0
- package/src/commands/api.ts +94 -12
- package/src/commands/auth.ts +41 -41
- package/src/commands/file.ts +61 -0
- package/src/commands/issue.ts +307 -153
- package/src/commands/project.ts +14 -8
- package/src/commands/team.ts +23 -11
- package/src/domain/Files.ts +81 -0
- package/src/domain/Input.ts +68 -0
- package/src/domain/Linear.ts +158 -0
- package/src/lib/downloads.ts +71 -0
- package/src/lib/effect.ts +9 -0
- package/src/lib/errors.ts +3 -14
- package/src/lib/flags.ts +15 -0
- package/src/main.ts +3 -18
- package/src/services/Config.ts +126 -125
- package/src/services/Linear.ts +534 -438
- package/tsconfig.json +22 -3
- package/src/services/Browser.ts +0 -23
- package/src/services/Stdin.ts +0 -27
package/src/commands/issue.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { Argument, Command, Flag, Prompt } from "effect/unstable/cli";
|
|
2
2
|
import { Console, Effect, Option } from "effect";
|
|
3
|
+
import type { IssueDetails } from "../domain/Linear.js";
|
|
4
|
+
import { extractUploadLinks, uniqueByUrl } from "../domain/Files.js";
|
|
5
|
+
import { parseIssueSelector, parseUploadUrl, validateText } from "../domain/Input.js";
|
|
6
|
+
import { saveDownloads } from "../lib/downloads.js";
|
|
7
|
+
import { succeedUndefined } from "../lib/effect.js";
|
|
3
8
|
import { InvalidInputError, NoIssuesError } from "../lib/errors.js";
|
|
9
|
+
import { jsonFlag, outputDirFlag, overwriteFlag } from "../lib/flags.js";
|
|
10
|
+
import { logSavedFiles } from "./file.js";
|
|
4
11
|
import { encodeJson } from "../lib/json.js";
|
|
5
|
-
import { LinearService
|
|
12
|
+
import { LinearService } from "../services/Linear.js";
|
|
6
13
|
import { ConfigService } from "../services/Config.js";
|
|
7
14
|
|
|
8
|
-
/** Resolve LinearFetch<T> | undefined (LinearFetch is Promise-like lazy loader) */
|
|
9
|
-
const resolveFetch = <T>(fetch: PromiseLike<T> | undefined): Effect.Effect<T | null> =>
|
|
10
|
-
fetch !== undefined
|
|
11
|
-
? Effect.tryPromise(() => Promise.resolve(fetch)).pipe(Effect.orElseSucceed(() => null))
|
|
12
|
-
: Effect.succeed(null);
|
|
13
|
-
|
|
14
15
|
// Options
|
|
15
16
|
const stateOption = Flag.string("state").pipe(
|
|
16
17
|
Flag.withAlias("s"),
|
|
@@ -24,10 +25,6 @@ const limitOption = Flag.integer("limit").pipe(
|
|
|
24
25
|
Flag.withDescription("Number of issues to show"),
|
|
25
26
|
);
|
|
26
27
|
|
|
27
|
-
const jsonOption = Flag.boolean("json").pipe(
|
|
28
|
-
Flag.withDescription("Emit stable JSON for scripts and agents"),
|
|
29
|
-
);
|
|
30
|
-
|
|
31
28
|
const commentsOption = Flag.boolean("comments").pipe(
|
|
32
29
|
Flag.withDescription("Include issue comments"),
|
|
33
30
|
);
|
|
@@ -72,6 +69,10 @@ const dryRunOption = Flag.boolean("dry-run").pipe(
|
|
|
72
69
|
Flag.withDescription("Validate and print the mutation without writing"),
|
|
73
70
|
);
|
|
74
71
|
|
|
72
|
+
const interactiveOption = Flag.boolean("interactive").pipe(
|
|
73
|
+
Flag.withDescription("Allow prompts when required input is missing"),
|
|
74
|
+
);
|
|
75
|
+
|
|
75
76
|
const bodyOption = Flag.string("body").pipe(Flag.withDescription("Comment body in Markdown"));
|
|
76
77
|
|
|
77
78
|
// Args
|
|
@@ -83,52 +84,35 @@ const issueIdsArg = Argument.string("id").pipe(
|
|
|
83
84
|
// linear issue list - List issues
|
|
84
85
|
export const issueListCommand = Command.make(
|
|
85
86
|
"list",
|
|
86
|
-
{ state: stateOption, limit: limitOption, json:
|
|
87
|
+
{ state: stateOption, limit: limitOption, json: jsonFlag },
|
|
87
88
|
({ state, limit, json }) =>
|
|
88
89
|
Effect.gen(function* () {
|
|
89
|
-
|
|
90
|
+
if (limit < 1 || limit > 250) {
|
|
91
|
+
return yield* InvalidInputError.make({
|
|
92
|
+
message: "--limit must be between 1 and 250. Example: linear issue list --limit 20",
|
|
93
|
+
});
|
|
94
|
+
}
|
|
90
95
|
|
|
96
|
+
const linear = yield* LinearService;
|
|
91
97
|
const stateFilter = Option.getOrUndefined(state);
|
|
92
|
-
const issues = yield* linear.getMyIssues({ state: stateFilter });
|
|
98
|
+
const issues = yield* linear.getMyIssues({ state: stateFilter, limit });
|
|
93
99
|
|
|
94
100
|
if (issues.length === 0) {
|
|
95
|
-
yield*
|
|
101
|
+
yield* logEmptyList(json, "No issues found.");
|
|
96
102
|
return;
|
|
97
103
|
}
|
|
98
104
|
|
|
99
|
-
yield* Console.log("\nYour Issues:\n");
|
|
100
|
-
|
|
101
105
|
const displayed = issues.slice(0, limit);
|
|
102
106
|
|
|
103
107
|
if (json) {
|
|
104
|
-
|
|
105
|
-
displayed,
|
|
106
|
-
(issue) =>
|
|
107
|
-
resolveFetch(issue.state).pipe(
|
|
108
|
-
Effect.map((issueState) => ({
|
|
109
|
-
id: issue.id,
|
|
110
|
-
identifier: issue.identifier,
|
|
111
|
-
title: issue.title,
|
|
112
|
-
url: issue.url,
|
|
113
|
-
branchName: issue.branchName,
|
|
114
|
-
priority: { value: issue.priority, label: getPriorityLabel(issue.priority) },
|
|
115
|
-
state:
|
|
116
|
-
issueState === null
|
|
117
|
-
? undefined
|
|
118
|
-
: { id: issueState.id, name: issueState.name, type: issueState.type },
|
|
119
|
-
})),
|
|
120
|
-
),
|
|
121
|
-
{ concurrency: 4 },
|
|
122
|
-
);
|
|
123
|
-
yield* Console.log(encodeJson(values));
|
|
108
|
+
yield* Console.log(encodeJson(displayed));
|
|
124
109
|
return;
|
|
125
110
|
}
|
|
126
111
|
|
|
112
|
+
yield* Console.log("\nYour Issues:\n");
|
|
127
113
|
for (const issue of displayed) {
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
const priority = issue.priority ?? 0;
|
|
131
|
-
const priorityIcon = getPriorityIcon(priority);
|
|
114
|
+
const stateName = issue.state?.name ?? "Unknown";
|
|
115
|
+
const priorityIcon = getPriorityIcon(issue.priority.value);
|
|
132
116
|
|
|
133
117
|
yield* Console.log(
|
|
134
118
|
` ${priorityIcon} ${issue.identifier.padEnd(10)} ${stateName.padEnd(12)} ${truncate(issue.title, 50)}`,
|
|
@@ -141,6 +125,15 @@ export const issueListCommand = Command.make(
|
|
|
141
125
|
|
|
142
126
|
yield* Console.log("");
|
|
143
127
|
}),
|
|
128
|
+
).pipe(
|
|
129
|
+
Command.withDescription("List issues assigned to the authenticated user"),
|
|
130
|
+
Command.withExamples([
|
|
131
|
+
{ command: "linear issue list --json", description: "List assigned issues as JSON" },
|
|
132
|
+
{
|
|
133
|
+
command: "linear issue list --state started --limit 10 --json",
|
|
134
|
+
description: "List up to ten started issues",
|
|
135
|
+
},
|
|
136
|
+
]),
|
|
144
137
|
);
|
|
145
138
|
|
|
146
139
|
// linear issue view [id] - View issue details
|
|
@@ -148,15 +141,26 @@ export const issueViewCommand = Command.make(
|
|
|
148
141
|
"view",
|
|
149
142
|
{
|
|
150
143
|
ids: issueIdsArg,
|
|
151
|
-
json:
|
|
144
|
+
json: jsonFlag,
|
|
145
|
+
interactive: interactiveOption,
|
|
152
146
|
comments: commentsOption,
|
|
153
147
|
children: childrenOption,
|
|
154
148
|
relations: relationsOption,
|
|
155
149
|
},
|
|
156
|
-
({ ids, json, comments, children, relations }) =>
|
|
150
|
+
({ ids, json, interactive, comments, children, relations }) =>
|
|
157
151
|
Effect.gen(function* () {
|
|
152
|
+
if (ids.length === 0 && !interactive) {
|
|
153
|
+
return yield* InvalidInputError.make({
|
|
154
|
+
message:
|
|
155
|
+
"Issue identifier required in non-interactive mode. Usage: linear issue view ISSUE-123 --json",
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
let requestedIds: ReadonlyArray<string> = ids;
|
|
159
|
+
if (requestedIds.length === 0) {
|
|
160
|
+
requestedIds = [yield* selectIssue];
|
|
161
|
+
}
|
|
162
|
+
const selectedIds = yield* Effect.forEach(requestedIds, parseIssueSelector);
|
|
158
163
|
const linear = yield* LinearService;
|
|
159
|
-
const selectedIds = ids.length === 0 ? [yield* selectIssue] : ids;
|
|
160
164
|
const details = yield* Effect.forEach(
|
|
161
165
|
selectedIds,
|
|
162
166
|
(id) => linear.getIssueDetails(id, { comments, children, relations }),
|
|
@@ -170,6 +174,16 @@ export const issueViewCommand = Command.make(
|
|
|
170
174
|
|
|
171
175
|
yield* Effect.forEach(details, renderIssueDetails, { discard: true });
|
|
172
176
|
}),
|
|
177
|
+
).pipe(
|
|
178
|
+
Command.withDescription("Read one or more issues"),
|
|
179
|
+
Command.withExamples([
|
|
180
|
+
{ command: "linear issue view ENG-123 --json", description: "Read one issue as JSON" },
|
|
181
|
+
{
|
|
182
|
+
command: "linear issue view ENG-123 ENG-124 --comments --json",
|
|
183
|
+
description: "Read several issues with comments",
|
|
184
|
+
},
|
|
185
|
+
{ command: "linear issue view --interactive", description: "Choose an issue interactively" },
|
|
186
|
+
]),
|
|
173
187
|
);
|
|
174
188
|
|
|
175
189
|
// linear issue start [id] - Start working on an issue
|
|
@@ -178,48 +192,65 @@ const optionalIssueIdArg = Argument.string("id").pipe(
|
|
|
178
192
|
Argument.optional,
|
|
179
193
|
);
|
|
180
194
|
|
|
181
|
-
export const issueStartCommand = Command.make(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const startedState = states.find(
|
|
205
|
-
(s) => s.type === "started" || s.name.toLowerCase() === "in progress",
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
if (startedState !== undefined) {
|
|
209
|
-
yield* linear.updateIssueState(issue.id, startedState.id);
|
|
210
|
-
yield* Console.log(`\nStarted: ${issue.identifier} - ${issue.title}`);
|
|
211
|
-
yield* Console.log(`State changed to: ${startedState.name}`);
|
|
212
|
-
} else {
|
|
213
|
-
yield* Console.log(`\nCould not find a "started" state for this issue's team.`);
|
|
214
|
-
}
|
|
195
|
+
export const issueStartCommand = Command.make(
|
|
196
|
+
"start",
|
|
197
|
+
{
|
|
198
|
+
id: optionalIssueIdArg,
|
|
199
|
+
dryRun: dryRunOption,
|
|
200
|
+
json: jsonFlag,
|
|
201
|
+
interactive: interactiveOption,
|
|
202
|
+
},
|
|
203
|
+
({ id, dryRun, json, interactive }) =>
|
|
204
|
+
Effect.gen(function* () {
|
|
205
|
+
const selectedIssue = yield* Option.match(id, {
|
|
206
|
+
onNone: () => {
|
|
207
|
+
if (interactive) {
|
|
208
|
+
return selectIssue;
|
|
209
|
+
}
|
|
210
|
+
return InvalidInputError.make({
|
|
211
|
+
message:
|
|
212
|
+
"Issue identifier required in non-interactive mode. Usage: linear issue start ISSUE-123 --dry-run",
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
onSome: Effect.succeed,
|
|
216
|
+
});
|
|
217
|
+
const issueId = yield* parseIssueSelector(selectedIssue);
|
|
215
218
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
219
|
+
const linear = yield* LinearService;
|
|
220
|
+
const started = yield* linear.startIssue(issueId, { dryRun });
|
|
221
|
+
if (dryRun) {
|
|
222
|
+
yield* Console.log(
|
|
223
|
+
encodeJson({
|
|
224
|
+
dryRun: true,
|
|
225
|
+
operation: "issue.start",
|
|
226
|
+
input: { id: issueId },
|
|
227
|
+
result: started,
|
|
228
|
+
}),
|
|
229
|
+
);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (json) {
|
|
233
|
+
yield* Console.log(encodeJson(started));
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
220
236
|
|
|
221
|
-
|
|
222
|
-
|
|
237
|
+
yield* Console.log(`\nStarted: ${started.issue.identifier} - ${started.issue.title}`);
|
|
238
|
+
yield* Console.log(`State changed to: ${started.state.name}`);
|
|
239
|
+
yield* Console.log(`\nBranch name: ${started.branchName}`);
|
|
240
|
+
yield* Console.log("");
|
|
241
|
+
}),
|
|
242
|
+
).pipe(
|
|
243
|
+
Command.withDescription("Move an issue to its team's started state"),
|
|
244
|
+
Command.withExamples([
|
|
245
|
+
{
|
|
246
|
+
command: "linear issue start ENG-123 --dry-run",
|
|
247
|
+
description: "Validate and preview the state change",
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
command: "linear issue start ENG-123 --json",
|
|
251
|
+
description: "Start an issue and return the result as JSON",
|
|
252
|
+
},
|
|
253
|
+
]),
|
|
223
254
|
);
|
|
224
255
|
|
|
225
256
|
// linear issue create - Create a new issue
|
|
@@ -233,20 +264,27 @@ export const issueCreateCommand = Command.make(
|
|
|
233
264
|
project: projectOption,
|
|
234
265
|
priority: priorityOption,
|
|
235
266
|
dryRun: dryRunOption,
|
|
236
|
-
json:
|
|
267
|
+
json: jsonFlag,
|
|
268
|
+
interactive: interactiveOption,
|
|
237
269
|
},
|
|
238
|
-
({ title, description, team, parent, project, priority, dryRun, json }) =>
|
|
270
|
+
({ title, description, team, parent, project, priority, dryRun, json, interactive }) =>
|
|
239
271
|
Effect.gen(function* () {
|
|
272
|
+
if (Option.isNone(title) && !interactive) {
|
|
273
|
+
return yield* InvalidInputError.make({
|
|
274
|
+
message:
|
|
275
|
+
'--title is required in non-interactive mode. Usage: linear issue create --team ENG --title "Title" --dry-run',
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
240
279
|
const linear = yield* LinearService;
|
|
241
280
|
const config = yield* ConfigService;
|
|
242
281
|
const linearConfig = yield* config.getConfig;
|
|
243
|
-
|
|
244
|
-
// Get teams for selection
|
|
245
282
|
const teams = yield* linear.getTeams;
|
|
246
283
|
|
|
247
284
|
if (teams.length === 0) {
|
|
248
|
-
yield*
|
|
249
|
-
|
|
285
|
+
return yield* InvalidInputError.make({
|
|
286
|
+
message: "No teams found; an issue cannot be created",
|
|
287
|
+
});
|
|
250
288
|
}
|
|
251
289
|
|
|
252
290
|
const isInteractive = Option.isNone(title);
|
|
@@ -257,30 +295,46 @@ export const issueCreateCommand = Command.make(
|
|
|
257
295
|
onSome: Effect.succeed,
|
|
258
296
|
});
|
|
259
297
|
const issueDescription = yield* Option.match(description, {
|
|
260
|
-
onNone: () =>
|
|
261
|
-
isInteractive
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
298
|
+
onNone: () => {
|
|
299
|
+
if (isInteractive) {
|
|
300
|
+
return Prompt.text({
|
|
301
|
+
message: "Description (optional, press Enter to skip)",
|
|
302
|
+
default: "",
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
return Effect.succeed("");
|
|
306
|
+
},
|
|
267
307
|
onSome: Effect.succeed,
|
|
268
308
|
});
|
|
309
|
+
const validatedTitle = yield* validateText({
|
|
310
|
+
name: "Issue title",
|
|
311
|
+
value: issueTitle,
|
|
312
|
+
maximumLength: 255,
|
|
313
|
+
});
|
|
314
|
+
const validatedDescription = yield* validateText({
|
|
315
|
+
name: "Issue description",
|
|
316
|
+
value: issueDescription,
|
|
317
|
+
maximumLength: 100_000,
|
|
318
|
+
allowEmpty: true,
|
|
319
|
+
});
|
|
269
320
|
const priorityValue = Option.getOrUndefined(priority);
|
|
270
321
|
if (priorityValue !== undefined && (priorityValue < 0 || priorityValue > 4)) {
|
|
271
322
|
return yield* InvalidInputError.make({ message: "--priority must be between 0 and 4" });
|
|
272
323
|
}
|
|
273
324
|
|
|
274
325
|
const projectSelector = Option.getOrUndefined(project);
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
326
|
+
let projectId: string | undefined = undefined;
|
|
327
|
+
if (projectSelector !== undefined) {
|
|
328
|
+
projectId = yield* resolveProjectId(yield* linear.getProjects, projectSelector);
|
|
329
|
+
}
|
|
279
330
|
const input = {
|
|
280
|
-
title:
|
|
331
|
+
title: validatedTitle,
|
|
281
332
|
teamId,
|
|
282
|
-
description:
|
|
283
|
-
|
|
333
|
+
description: emptyToUndefined(validatedDescription),
|
|
334
|
+
parent: yield* Option.match(parent, {
|
|
335
|
+
onNone: () => succeedUndefined,
|
|
336
|
+
onSome: parseIssueSelector,
|
|
337
|
+
}),
|
|
284
338
|
projectId,
|
|
285
339
|
priority: priorityValue,
|
|
286
340
|
};
|
|
@@ -302,6 +356,19 @@ export const issueCreateCommand = Command.make(
|
|
|
302
356
|
yield* Console.log(`URL: ${created.url}`);
|
|
303
357
|
yield* Console.log("");
|
|
304
358
|
}),
|
|
359
|
+
).pipe(
|
|
360
|
+
Command.withDescription("Create an issue interactively or from flags"),
|
|
361
|
+
Command.withExamples([
|
|
362
|
+
{
|
|
363
|
+
command: 'linear issue create --team ENG --title "Title" --dry-run',
|
|
364
|
+
description: "Validate and preview a non-interactive creation",
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
command: 'linear issue create --team ENG --title "Title" --json',
|
|
368
|
+
description: "Create an issue and return it as JSON",
|
|
369
|
+
},
|
|
370
|
+
{ command: "linear issue create --interactive", description: "Create with prompts" },
|
|
371
|
+
]),
|
|
305
372
|
);
|
|
306
373
|
|
|
307
374
|
export const issueCommentCommand = Command.make(
|
|
@@ -310,37 +377,123 @@ export const issueCommentCommand = Command.make(
|
|
|
310
377
|
id: Argument.string("id").pipe(Argument.withDescription("Issue ID, URL, or identifier")),
|
|
311
378
|
body: bodyOption,
|
|
312
379
|
dryRun: dryRunOption,
|
|
313
|
-
json:
|
|
380
|
+
json: jsonFlag,
|
|
314
381
|
},
|
|
315
382
|
({ id, body, dryRun, json }) =>
|
|
316
383
|
Effect.gen(function* () {
|
|
384
|
+
const issueId = yield* parseIssueSelector(id);
|
|
385
|
+
const commentBody = yield* validateText({
|
|
386
|
+
name: "Comment body",
|
|
387
|
+
value: body,
|
|
388
|
+
maximumLength: 100_000,
|
|
389
|
+
});
|
|
317
390
|
if (dryRun) {
|
|
318
391
|
yield* Console.log(
|
|
319
|
-
encodeJson({
|
|
392
|
+
encodeJson({
|
|
393
|
+
dryRun: true,
|
|
394
|
+
operation: "issue.comment",
|
|
395
|
+
input: { id: issueId, body: commentBody },
|
|
396
|
+
}),
|
|
320
397
|
);
|
|
321
398
|
return;
|
|
322
399
|
}
|
|
323
400
|
|
|
324
401
|
const linear = yield* LinearService;
|
|
325
|
-
const comment = yield* linear.createComment(
|
|
402
|
+
const comment = yield* linear.createComment(issueId, commentBody);
|
|
326
403
|
if (json) {
|
|
327
404
|
yield* Console.log(encodeJson(comment));
|
|
328
405
|
return;
|
|
329
406
|
}
|
|
330
407
|
yield* Console.log(`Comment created: ${comment.url}`);
|
|
331
408
|
}),
|
|
409
|
+
).pipe(
|
|
410
|
+
Command.withDescription("Add a Markdown comment to an issue"),
|
|
411
|
+
Command.withExamples([
|
|
412
|
+
{
|
|
413
|
+
command: 'linear issue comment ENG-123 --body "Ready" --dry-run',
|
|
414
|
+
description: "Preview a comment without sending it",
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
command: 'linear issue comment ENG-123 --body "Ready" --json',
|
|
418
|
+
description: "Create a comment and return its URL",
|
|
419
|
+
},
|
|
420
|
+
]),
|
|
421
|
+
);
|
|
422
|
+
|
|
423
|
+
const downloadOption = Flag.boolean("download").pipe(
|
|
424
|
+
Flag.withDescription("Save every listed file into --output-dir"),
|
|
425
|
+
);
|
|
426
|
+
|
|
427
|
+
// linear issue files <id> - List (and optionally download) files uploaded to an issue
|
|
428
|
+
export const issueFilesCommand = Command.make(
|
|
429
|
+
"files",
|
|
430
|
+
{
|
|
431
|
+
id: Argument.string("id").pipe(Argument.withDescription("Issue ID, URL, or identifier")),
|
|
432
|
+
download: downloadOption,
|
|
433
|
+
outputDir: outputDirFlag,
|
|
434
|
+
overwrite: overwriteFlag,
|
|
435
|
+
json: jsonFlag,
|
|
436
|
+
},
|
|
437
|
+
({ id, download, outputDir, overwrite, json }) =>
|
|
438
|
+
Effect.gen(function* () {
|
|
439
|
+
const issueId = yield* parseIssueSelector(id);
|
|
440
|
+
const linear = yield* LinearService;
|
|
441
|
+
const details = yield* linear.getIssueDetails(issueId, {
|
|
442
|
+
comments: true,
|
|
443
|
+
children: false,
|
|
444
|
+
relations: false,
|
|
445
|
+
});
|
|
446
|
+
const files = uniqueByUrl([
|
|
447
|
+
...extractUploadLinks(details.description, "description"),
|
|
448
|
+
...(details.comments ?? []).flatMap((comment) =>
|
|
449
|
+
extractUploadLinks(comment.body, comment.id),
|
|
450
|
+
),
|
|
451
|
+
]);
|
|
452
|
+
|
|
453
|
+
if (!download) {
|
|
454
|
+
if (json) {
|
|
455
|
+
yield* Console.log(encodeJson(files));
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (files.length === 0) {
|
|
459
|
+
yield* Console.log(`No files found on ${details.identifier}.`);
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
for (const issueFile of files) {
|
|
463
|
+
yield* Console.log(`${issueFile.name}\t${issueFile.source}\t${issueFile.url}`);
|
|
464
|
+
}
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const requests = yield* Effect.forEach(files, (issueFile) =>
|
|
469
|
+
parseUploadUrl(issueFile.url).pipe(Effect.map((url) => ({ url, name: issueFile.name }))),
|
|
470
|
+
);
|
|
471
|
+
const savedFiles = yield* saveDownloads({ requests, outputDir, overwrite });
|
|
472
|
+
yield* logSavedFiles(savedFiles, json);
|
|
473
|
+
}),
|
|
474
|
+
).pipe(
|
|
475
|
+
Command.withDescription("List files uploaded to an issue's description and comments"),
|
|
476
|
+
Command.withExamples([
|
|
477
|
+
{ command: "linear issue files ENG-123 --json", description: "List uploads as JSON" },
|
|
478
|
+
{
|
|
479
|
+
command: "linear issue files ENG-123 --download --output-dir ./files --json",
|
|
480
|
+
description: "Save every upload under its Markdown name",
|
|
481
|
+
},
|
|
482
|
+
]),
|
|
332
483
|
);
|
|
333
484
|
|
|
334
485
|
// Combined issue command with subcommands
|
|
335
486
|
export const issue = Command.make("issue", {}, () =>
|
|
336
487
|
Console.log("Use 'linear issue list' to list issues. See --help for more."),
|
|
337
488
|
).pipe(
|
|
489
|
+
Command.withDescription("Read and mutate Linear issues"),
|
|
338
490
|
Command.withSubcommands([
|
|
339
491
|
issueListCommand,
|
|
340
492
|
issueViewCommand,
|
|
341
493
|
issueStartCommand,
|
|
342
494
|
issueCreateCommand,
|
|
343
495
|
issueCommentCommand,
|
|
496
|
+
issueFilesCommand,
|
|
344
497
|
]),
|
|
345
498
|
);
|
|
346
499
|
|
|
@@ -348,26 +501,21 @@ export const issue = Command.make("issue", {}, () =>
|
|
|
348
501
|
|
|
349
502
|
const selectIssue = Effect.gen(function* () {
|
|
350
503
|
const linear = yield* LinearService;
|
|
351
|
-
|
|
352
|
-
|
|
504
|
+
let allIssues = yield* linear.getMyIssues({ state: "started" });
|
|
505
|
+
if (allIssues.length === 0) {
|
|
506
|
+
allIssues = yield* linear.getMyIssues({ state: "unstarted" });
|
|
507
|
+
}
|
|
353
508
|
|
|
354
509
|
if (allIssues.length === 0) {
|
|
355
510
|
return yield* NoIssuesError.default;
|
|
356
511
|
}
|
|
357
512
|
|
|
358
513
|
// Build choices with state info
|
|
359
|
-
const choices =
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
title: `${candidate.identifier}: ${truncate(candidate.title, 40)}`,
|
|
365
|
-
value: candidate.identifier,
|
|
366
|
-
description: issueState?.name ?? "Unknown state",
|
|
367
|
-
};
|
|
368
|
-
}),
|
|
369
|
-
),
|
|
370
|
-
);
|
|
514
|
+
const choices = allIssues.slice(0, 20).map((candidate) => ({
|
|
515
|
+
title: `${candidate.identifier}: ${truncate(candidate.title, 40)}`,
|
|
516
|
+
value: candidate.identifier,
|
|
517
|
+
description: candidate.state?.name ?? "Unknown state",
|
|
518
|
+
}));
|
|
371
519
|
|
|
372
520
|
const selected = yield* Prompt.select({
|
|
373
521
|
message: "Select an issue",
|
|
@@ -441,23 +589,28 @@ const resolveTeamId = Effect.fn("IssueCommand.resolveTeamId")(function* (
|
|
|
441
589
|
const selected = teams.find(
|
|
442
590
|
(team) => team.id === selector || team.key.toLowerCase() === normalized,
|
|
443
591
|
);
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
592
|
+
if (selected === undefined) {
|
|
593
|
+
return yield* InvalidInputError.make({ message: `Unknown team: ${selector}` });
|
|
594
|
+
}
|
|
595
|
+
return selected.id;
|
|
447
596
|
}
|
|
448
597
|
if (teams.length === 1) {
|
|
449
598
|
const [team] = teams;
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
599
|
+
if (team === undefined) {
|
|
600
|
+
return yield* InvalidInputError.make({ message: "No team available" });
|
|
601
|
+
}
|
|
602
|
+
return team.id;
|
|
453
603
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
604
|
+
if (interactive) {
|
|
605
|
+
return yield* selectTeam(teams);
|
|
606
|
+
}
|
|
607
|
+
return yield* InvalidInputError.make({
|
|
608
|
+
message: "--team is required when multiple teams exist",
|
|
609
|
+
});
|
|
457
610
|
});
|
|
458
611
|
|
|
459
612
|
const resolveProjectId = Effect.fn("IssueCommand.resolveProjectId")(function* (
|
|
460
|
-
projects: readonly { id: string; name: string;
|
|
613
|
+
projects: readonly { id: string; name: string; slug: string }[],
|
|
461
614
|
selector: string,
|
|
462
615
|
) {
|
|
463
616
|
const normalized = selector.toLowerCase();
|
|
@@ -465,11 +618,12 @@ const resolveProjectId = Effect.fn("IssueCommand.resolveProjectId")(function* (
|
|
|
465
618
|
(project) =>
|
|
466
619
|
project.id === selector ||
|
|
467
620
|
project.name.toLowerCase() === normalized ||
|
|
468
|
-
project.
|
|
621
|
+
project.slug.toLowerCase() === normalized,
|
|
469
622
|
);
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
623
|
+
if (selected === undefined) {
|
|
624
|
+
return yield* InvalidInputError.make({ message: `Unknown project: ${selector}` });
|
|
625
|
+
}
|
|
626
|
+
return selected.id;
|
|
473
627
|
});
|
|
474
628
|
|
|
475
629
|
const toCreatedIssue = (created: {
|
|
@@ -485,7 +639,24 @@ const toCreatedIssue = (created: {
|
|
|
485
639
|
});
|
|
486
640
|
|
|
487
641
|
function truncate(str: string, len: number): string {
|
|
488
|
-
|
|
642
|
+
if (str.length > len) {
|
|
643
|
+
return str.slice(0, len - 1) + "…";
|
|
644
|
+
}
|
|
645
|
+
return str;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function emptyToUndefined(value: string): string | undefined {
|
|
649
|
+
if (value.length === 0) {
|
|
650
|
+
return undefined;
|
|
651
|
+
}
|
|
652
|
+
return value;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
function logEmptyList(json: boolean, message: string): Effect.Effect<void> {
|
|
656
|
+
if (json) {
|
|
657
|
+
return Console.log("[]");
|
|
658
|
+
}
|
|
659
|
+
return Console.log(message);
|
|
489
660
|
}
|
|
490
661
|
|
|
491
662
|
function getPriorityIcon(priority: number): string {
|
|
@@ -504,20 +675,3 @@ function getPriorityIcon(priority: number): string {
|
|
|
504
675
|
return "○";
|
|
505
676
|
}
|
|
506
677
|
}
|
|
507
|
-
|
|
508
|
-
function getPriorityLabel(priority: number): string {
|
|
509
|
-
switch (priority) {
|
|
510
|
-
case 0:
|
|
511
|
-
return "No priority";
|
|
512
|
-
case 1:
|
|
513
|
-
return "Urgent";
|
|
514
|
-
case 2:
|
|
515
|
-
return "High";
|
|
516
|
-
case 3:
|
|
517
|
-
return "Medium";
|
|
518
|
-
case 4:
|
|
519
|
-
return "Low";
|
|
520
|
-
default:
|
|
521
|
-
return "Unknown";
|
|
522
|
-
}
|
|
523
|
-
}
|