@cvr/linear 0.4.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 +8 -0
- package/bin/linear +2 -2
- package/package.json +5 -5
- package/skills/linear/SKILL.md +12 -0
- package/src/cli.ts +2 -1
- package/src/commands/api.ts +8 -7
- package/src/commands/auth.ts +9 -2
- package/src/commands/file.ts +61 -0
- package/src/commands/issue.ts +139 -42
- package/src/commands/team.ts +13 -4
- package/src/domain/Files.ts +81 -0
- package/src/domain/Input.ts +14 -1
- package/src/domain/Linear.ts +25 -1
- package/src/lib/downloads.ts +71 -0
- package/src/lib/effect.ts +9 -0
- package/src/lib/errors.ts +4 -0
- package/src/lib/flags.ts +10 -0
- package/src/main.ts +1 -0
- package/src/services/Config.ts +29 -17
- package/src/services/Linear.ts +228 -94
- package/tsconfig.json +22 -3
package/README.md
CHANGED
|
@@ -71,6 +71,13 @@ linear team list
|
|
|
71
71
|
| `linear issue start [id]` | Start work, with `--dry-run` and `--json` support |
|
|
72
72
|
| `linear issue create` | Create a new issue |
|
|
73
73
|
| `linear issue comment ID` | Add a comment, with `--dry-run` support |
|
|
74
|
+
| `linear issue files ID` | List uploads; `--download` saves them |
|
|
75
|
+
|
|
76
|
+
### Files
|
|
77
|
+
|
|
78
|
+
| Command | Description |
|
|
79
|
+
| --------------------------- | --------------------------------------------------- |
|
|
80
|
+
| `linear file download URL…` | Download `uploads.linear.app` files with your token |
|
|
74
81
|
|
|
75
82
|
### Teams
|
|
76
83
|
|
|
@@ -96,6 +103,7 @@ linear team list
|
|
|
96
103
|
- Keep `--query-file` paths inside the current workspace; traversal and escaping symlinks are rejected.
|
|
97
104
|
- Raw GraphQL mutations require the explicit `--allow-mutation` flag.
|
|
98
105
|
- Never read or interpolate the token directly; the CLI owns authentication.
|
|
106
|
+
- Download attachments with `linear issue files ID --download` or `linear file download URL`. The token is sent only to `uploads.linear.app`, never to a redirect target. Existing files are kept unless `--overwrite` is passed.
|
|
99
107
|
|
|
100
108
|
## Configuration
|
|
101
109
|
|
package/bin/linear
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/bin/linear
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 84186592 bytes
|
|
4
|
+
sha256: d2e8660ed2ec348271c4ec15f498e46fda5ea587ecc1ed7235a309446af2d2c8
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cvr/linear",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/cevr/linear-cli.git"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"lint:fix": "oxlint --fix",
|
|
28
28
|
"fmt": "oxfmt",
|
|
29
29
|
"fmt:check": "oxfmt --check",
|
|
30
|
-
"typecheck": "
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
31
|
"gate": "concurrently -n type,style,build,test -c blue,yellow,cyan,green \"bun run typecheck\" \"bun run lint && bun run fmt:check\" \"bun run build\" \"bun run test\"",
|
|
32
32
|
"prepare": "lefthook install && effect-tsgo patch",
|
|
33
33
|
"version": "changeset version",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"toml": "^5.0.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@changesets/changelog-github": "^0.
|
|
45
|
-
"@changesets/cli": "^
|
|
44
|
+
"@changesets/changelog-github": "^1.0.1",
|
|
45
|
+
"@changesets/cli": "^3.0.3",
|
|
46
46
|
"@effect/tsgo": "^0.23.0",
|
|
47
47
|
"@effect/vitest": "4.0.0-beta.98",
|
|
48
48
|
"@types/bun": "^1.3.14",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"lefthook": "^2.1.10",
|
|
52
52
|
"oxfmt": "^0.59.0",
|
|
53
53
|
"oxlint": "^1.74.0",
|
|
54
|
-
"oxlint-plugin-effect": "
|
|
54
|
+
"oxlint-plugin-effect": "^0.5.0",
|
|
55
55
|
"typescript": "^7.0.2",
|
|
56
56
|
"vitest": "^4.1.10"
|
|
57
57
|
},
|
package/skills/linear/SKILL.md
CHANGED
|
@@ -54,6 +54,18 @@ linear issue view BITE-123 --children --comments --relations --json
|
|
|
54
54
|
|
|
55
55
|
Use the returned `branchName`; do not invent a branch name from the title.
|
|
56
56
|
|
|
57
|
+
### Download attachments
|
|
58
|
+
|
|
59
|
+
Files attached to an issue are Markdown links to `https://uploads.linear.app/...`, which need the Linear credential. Never fetch them with `curl`; use the CLI:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
linear issue files BITE-123 --json
|
|
63
|
+
linear issue files BITE-123 --download --output-dir ./files --json
|
|
64
|
+
linear file download https://uploads.linear.app/... --output-dir ./files --json
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`issue files` scans the description and every comment and returns `name`, `url`, and `source` (`description` or the comment ID). With `--download`, each file is saved under its Markdown name, and the output lists `path`, `bytes`, and `contentType`. The CLI accepts only `uploads.linear.app` URLs, and it does not send the token to a redirect target. An existing file stops the run unless you pass `--overwrite`.
|
|
68
|
+
|
|
57
69
|
## Mutations
|
|
58
70
|
|
|
59
71
|
### Start work
|
package/src/cli.ts
CHANGED
|
@@ -2,13 +2,14 @@ import { Command } from "effect/unstable/cli";
|
|
|
2
2
|
import packageJson from "../package.json" with { type: "json" };
|
|
3
3
|
import { api } from "./commands/api.js";
|
|
4
4
|
import { auth } from "./commands/auth.js";
|
|
5
|
+
import { file } from "./commands/file.js";
|
|
5
6
|
import { issue } from "./commands/issue.js";
|
|
6
7
|
import { project } from "./commands/project.js";
|
|
7
8
|
import { team } from "./commands/team.js";
|
|
8
9
|
|
|
9
10
|
export const linear = Command.make("linear").pipe(
|
|
10
11
|
Command.withDescription("Manage Linear issues, teams, projects, and authentication"),
|
|
11
|
-
Command.withSubcommands([auth, team, project, issue, api]),
|
|
12
|
+
Command.withSubcommands([auth, team, project, issue, file, api]),
|
|
12
13
|
);
|
|
13
14
|
|
|
14
15
|
export const runCli = Command.runWith(linear, { version: packageJson.version });
|
package/src/commands/api.ts
CHANGED
|
@@ -87,13 +87,14 @@ export const graphqlCommand = Command.make(
|
|
|
87
87
|
InvalidInputError.make({ message: "--query or --query-file is required" }),
|
|
88
88
|
onSome: (path) =>
|
|
89
89
|
readWorkspaceQueryFile(path).pipe(
|
|
90
|
-
Effect.mapError((error) =>
|
|
91
|
-
error._tag === "InvalidInputError"
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
90
|
+
Effect.mapError((error) => {
|
|
91
|
+
if (error._tag === "InvalidInputError") {
|
|
92
|
+
return error;
|
|
93
|
+
}
|
|
94
|
+
return InvalidInputError.make({
|
|
95
|
+
message: `Could not read GraphQL query file ${path}: ${error}`,
|
|
96
|
+
});
|
|
97
|
+
}),
|
|
97
98
|
),
|
|
98
99
|
}),
|
|
99
100
|
});
|
package/src/commands/auth.ts
CHANGED
|
@@ -21,7 +21,7 @@ export const authCommand = Command.make("auth", {}, () =>
|
|
|
21
21
|
return (yield* process.exitCode) === 0;
|
|
22
22
|
}).pipe(
|
|
23
23
|
Effect.scoped,
|
|
24
|
-
Effect.
|
|
24
|
+
Effect.orElseSucceed(() => false),
|
|
25
25
|
);
|
|
26
26
|
if (!browserOpened) {
|
|
27
27
|
yield* Console.log(`Could not open browser. Please visit the URL manually.`);
|
|
@@ -66,7 +66,7 @@ export const whoamiCommand = Command.make("whoami", { json: jsonFlag }, ({ json
|
|
|
66
66
|
yield* Console.log(`\nLogged in as:`);
|
|
67
67
|
yield* Console.log(` Name: ${viewer.name}`);
|
|
68
68
|
yield* Console.log(` Email: ${viewer.email}`);
|
|
69
|
-
yield* Console.log(` Admin: ${viewer.admin
|
|
69
|
+
yield* Console.log(` Admin: ${formatYesNo(viewer.admin)}`);
|
|
70
70
|
if (viewer.status?.label !== undefined) {
|
|
71
71
|
yield* Console.log(` Status: ${viewer.status.emoji ?? ""} ${viewer.status.label}`);
|
|
72
72
|
}
|
|
@@ -81,3 +81,10 @@ export const whoamiCommand = Command.make("whoami", { json: jsonFlag }, ({ json
|
|
|
81
81
|
|
|
82
82
|
// Combined auth command with subcommands
|
|
83
83
|
export const auth = authCommand.pipe(Command.withSubcommands([whoamiCommand]));
|
|
84
|
+
|
|
85
|
+
function formatYesNo(value: boolean): string {
|
|
86
|
+
if (value) {
|
|
87
|
+
return "Yes";
|
|
88
|
+
}
|
|
89
|
+
return "No";
|
|
90
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Argument, Command } from "effect/unstable/cli";
|
|
2
|
+
import { Console, Effect } from "effect";
|
|
3
|
+
import type { SavedFile } from "../domain/Linear.js";
|
|
4
|
+
import { parseUploadUrl } from "../domain/Input.js";
|
|
5
|
+
import { saveDownloads } from "../lib/downloads.js";
|
|
6
|
+
import { InvalidInputError } from "../lib/errors.js";
|
|
7
|
+
import { jsonFlag, outputDirFlag, overwriteFlag } from "../lib/flags.js";
|
|
8
|
+
import { encodeJson } from "../lib/json.js";
|
|
9
|
+
|
|
10
|
+
const uploadUrlsArg = Argument.string("url").pipe(
|
|
11
|
+
Argument.withDescription("https://uploads.linear.app/... URL (repeat for several files)"),
|
|
12
|
+
Argument.variadic(),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const logSavedFiles = (savedFiles: ReadonlyArray<SavedFile>, json: boolean) =>
|
|
16
|
+
Effect.gen(function* () {
|
|
17
|
+
if (json) {
|
|
18
|
+
yield* Console.log(encodeJson(savedFiles));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
for (const savedFile of savedFiles) {
|
|
22
|
+
yield* Console.log(`Saved ${savedFile.path} (${savedFile.bytes} bytes)`);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// linear file download <url>... - Download files uploaded to Linear
|
|
27
|
+
export const fileDownloadCommand = Command.make(
|
|
28
|
+
"download",
|
|
29
|
+
{ urls: uploadUrlsArg, outputDir: outputDirFlag, overwrite: overwriteFlag, json: jsonFlag },
|
|
30
|
+
({ urls, outputDir, overwrite, json }) =>
|
|
31
|
+
Effect.gen(function* () {
|
|
32
|
+
if (urls.length === 0) {
|
|
33
|
+
return yield* InvalidInputError.make({
|
|
34
|
+
message:
|
|
35
|
+
"Upload URL required. Usage: linear file download https://uploads.linear.app/... --json",
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const uploadUrls = yield* Effect.forEach(urls, parseUploadUrl);
|
|
39
|
+
const savedFiles = yield* saveDownloads({
|
|
40
|
+
requests: uploadUrls.map((url) => ({ url })),
|
|
41
|
+
outputDir,
|
|
42
|
+
overwrite,
|
|
43
|
+
});
|
|
44
|
+
yield* logSavedFiles(savedFiles, json);
|
|
45
|
+
}),
|
|
46
|
+
).pipe(
|
|
47
|
+
Command.withDescription("Download files uploaded to Linear with the configured credential"),
|
|
48
|
+
Command.withExamples([
|
|
49
|
+
{
|
|
50
|
+
command: "linear file download https://uploads.linear.app/... --output-dir ./files --json",
|
|
51
|
+
description: "Save one upload and print its path as JSON",
|
|
52
|
+
},
|
|
53
|
+
]),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
export const file = Command.make("file", {}, () =>
|
|
57
|
+
Console.log("Use 'linear file download <url>' to download an upload. See --help for more."),
|
|
58
|
+
).pipe(
|
|
59
|
+
Command.withDescription("Download files uploaded to Linear"),
|
|
60
|
+
Command.withSubcommands([fileDownloadCommand]),
|
|
61
|
+
);
|
package/src/commands/issue.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { Argument, Command, Flag, Prompt } from "effect/unstable/cli";
|
|
2
2
|
import { Console, Effect, Option } from "effect";
|
|
3
3
|
import type { IssueDetails } from "../domain/Linear.js";
|
|
4
|
-
import {
|
|
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";
|
|
5
8
|
import { InvalidInputError, NoIssuesError } from "../lib/errors.js";
|
|
6
|
-
import { jsonFlag } from "../lib/flags.js";
|
|
9
|
+
import { jsonFlag, outputDirFlag, overwriteFlag } from "../lib/flags.js";
|
|
10
|
+
import { logSavedFiles } from "./file.js";
|
|
7
11
|
import { encodeJson } from "../lib/json.js";
|
|
8
12
|
import { LinearService } from "../services/Linear.js";
|
|
9
13
|
import { ConfigService } from "../services/Config.js";
|
|
@@ -94,7 +98,7 @@ export const issueListCommand = Command.make(
|
|
|
94
98
|
const issues = yield* linear.getMyIssues({ state: stateFilter, limit });
|
|
95
99
|
|
|
96
100
|
if (issues.length === 0) {
|
|
97
|
-
yield*
|
|
101
|
+
yield* logEmptyList(json, "No issues found.");
|
|
98
102
|
return;
|
|
99
103
|
}
|
|
100
104
|
|
|
@@ -151,10 +155,11 @@ export const issueViewCommand = Command.make(
|
|
|
151
155
|
"Issue identifier required in non-interactive mode. Usage: linear issue view ISSUE-123 --json",
|
|
152
156
|
});
|
|
153
157
|
}
|
|
154
|
-
|
|
155
|
-
|
|
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
164
|
const details = yield* Effect.forEach(
|
|
160
165
|
selectedIds,
|
|
@@ -198,13 +203,15 @@ export const issueStartCommand = Command.make(
|
|
|
198
203
|
({ id, dryRun, json, interactive }) =>
|
|
199
204
|
Effect.gen(function* () {
|
|
200
205
|
const selectedIssue = yield* Option.match(id, {
|
|
201
|
-
onNone: () =>
|
|
202
|
-
interactive
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
+
},
|
|
208
215
|
onSome: Effect.succeed,
|
|
209
216
|
});
|
|
210
217
|
const issueId = yield* parseIssueSelector(selectedIssue);
|
|
@@ -288,13 +295,15 @@ export const issueCreateCommand = Command.make(
|
|
|
288
295
|
onSome: Effect.succeed,
|
|
289
296
|
});
|
|
290
297
|
const issueDescription = yield* Option.match(description, {
|
|
291
|
-
onNone: () =>
|
|
292
|
-
isInteractive
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
+
},
|
|
298
307
|
onSome: Effect.succeed,
|
|
299
308
|
});
|
|
300
309
|
const validatedTitle = yield* validateText({
|
|
@@ -314,16 +323,16 @@ export const issueCreateCommand = Command.make(
|
|
|
314
323
|
}
|
|
315
324
|
|
|
316
325
|
const projectSelector = Option.getOrUndefined(project);
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
326
|
+
let projectId: string | undefined = undefined;
|
|
327
|
+
if (projectSelector !== undefined) {
|
|
328
|
+
projectId = yield* resolveProjectId(yield* linear.getProjects, projectSelector);
|
|
329
|
+
}
|
|
321
330
|
const input = {
|
|
322
331
|
title: validatedTitle,
|
|
323
332
|
teamId,
|
|
324
|
-
description: validatedDescription
|
|
333
|
+
description: emptyToUndefined(validatedDescription),
|
|
325
334
|
parent: yield* Option.match(parent, {
|
|
326
|
-
onNone: () =>
|
|
335
|
+
onNone: () => succeedUndefined,
|
|
327
336
|
onSome: parseIssueSelector,
|
|
328
337
|
}),
|
|
329
338
|
projectId,
|
|
@@ -411,6 +420,68 @@ export const issueCommentCommand = Command.make(
|
|
|
411
420
|
]),
|
|
412
421
|
);
|
|
413
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
|
+
]),
|
|
483
|
+
);
|
|
484
|
+
|
|
414
485
|
// Combined issue command with subcommands
|
|
415
486
|
export const issue = Command.make("issue", {}, () =>
|
|
416
487
|
Console.log("Use 'linear issue list' to list issues. See --help for more."),
|
|
@@ -422,6 +493,7 @@ export const issue = Command.make("issue", {}, () =>
|
|
|
422
493
|
issueStartCommand,
|
|
423
494
|
issueCreateCommand,
|
|
424
495
|
issueCommentCommand,
|
|
496
|
+
issueFilesCommand,
|
|
425
497
|
]),
|
|
426
498
|
);
|
|
427
499
|
|
|
@@ -429,8 +501,10 @@ export const issue = Command.make("issue", {}, () =>
|
|
|
429
501
|
|
|
430
502
|
const selectIssue = Effect.gen(function* () {
|
|
431
503
|
const linear = yield* LinearService;
|
|
432
|
-
|
|
433
|
-
|
|
504
|
+
let allIssues = yield* linear.getMyIssues({ state: "started" });
|
|
505
|
+
if (allIssues.length === 0) {
|
|
506
|
+
allIssues = yield* linear.getMyIssues({ state: "unstarted" });
|
|
507
|
+
}
|
|
434
508
|
|
|
435
509
|
if (allIssues.length === 0) {
|
|
436
510
|
return yield* NoIssuesError.default;
|
|
@@ -515,19 +589,24 @@ const resolveTeamId = Effect.fn("IssueCommand.resolveTeamId")(function* (
|
|
|
515
589
|
const selected = teams.find(
|
|
516
590
|
(team) => team.id === selector || team.key.toLowerCase() === normalized,
|
|
517
591
|
);
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
592
|
+
if (selected === undefined) {
|
|
593
|
+
return yield* InvalidInputError.make({ message: `Unknown team: ${selector}` });
|
|
594
|
+
}
|
|
595
|
+
return selected.id;
|
|
521
596
|
}
|
|
522
597
|
if (teams.length === 1) {
|
|
523
598
|
const [team] = teams;
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
599
|
+
if (team === undefined) {
|
|
600
|
+
return yield* InvalidInputError.make({ message: "No team available" });
|
|
601
|
+
}
|
|
602
|
+
return team.id;
|
|
603
|
+
}
|
|
604
|
+
if (interactive) {
|
|
605
|
+
return yield* selectTeam(teams);
|
|
527
606
|
}
|
|
528
|
-
return
|
|
529
|
-
|
|
530
|
-
|
|
607
|
+
return yield* InvalidInputError.make({
|
|
608
|
+
message: "--team is required when multiple teams exist",
|
|
609
|
+
});
|
|
531
610
|
});
|
|
532
611
|
|
|
533
612
|
const resolveProjectId = Effect.fn("IssueCommand.resolveProjectId")(function* (
|
|
@@ -541,9 +620,10 @@ const resolveProjectId = Effect.fn("IssueCommand.resolveProjectId")(function* (
|
|
|
541
620
|
project.name.toLowerCase() === normalized ||
|
|
542
621
|
project.slug.toLowerCase() === normalized,
|
|
543
622
|
);
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
623
|
+
if (selected === undefined) {
|
|
624
|
+
return yield* InvalidInputError.make({ message: `Unknown project: ${selector}` });
|
|
625
|
+
}
|
|
626
|
+
return selected.id;
|
|
547
627
|
});
|
|
548
628
|
|
|
549
629
|
const toCreatedIssue = (created: {
|
|
@@ -559,7 +639,24 @@ const toCreatedIssue = (created: {
|
|
|
559
639
|
});
|
|
560
640
|
|
|
561
641
|
function truncate(str: string, len: number): string {
|
|
562
|
-
|
|
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);
|
|
563
660
|
}
|
|
564
661
|
|
|
565
662
|
function getPriorityIcon(priority: number): string {
|
package/src/commands/team.ts
CHANGED
|
@@ -11,7 +11,11 @@ export const teamListCommand = Command.make("list", { json: jsonFlag }, ({ json
|
|
|
11
11
|
const teams = yield* linear.getTeams;
|
|
12
12
|
|
|
13
13
|
if (teams.length === 0) {
|
|
14
|
-
|
|
14
|
+
if (json) {
|
|
15
|
+
yield* Console.log("[]");
|
|
16
|
+
} else {
|
|
17
|
+
yield* Console.log("No teams found.");
|
|
18
|
+
}
|
|
15
19
|
return;
|
|
16
20
|
}
|
|
17
21
|
|
|
@@ -34,9 +38,7 @@ export const teamListCommand = Command.make("list", { json: jsonFlag }, ({ json
|
|
|
34
38
|
for (const team of teams) {
|
|
35
39
|
const key = team.key;
|
|
36
40
|
const name = team.name;
|
|
37
|
-
|
|
38
|
-
team.description !== undefined && team.description !== null ? ` - ${team.description}` : "";
|
|
39
|
-
yield* Console.log(` ${key.padEnd(8)} ${name}${description}`);
|
|
41
|
+
yield* Console.log(` ${key.padEnd(8)} ${name}${formatDescription(team.description)}`);
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
yield* Console.log("");
|
|
@@ -53,3 +55,10 @@ export const teamListCommand = Command.make("list", { json: jsonFlag }, ({ json
|
|
|
53
55
|
export const team = Command.make("team", {}, () =>
|
|
54
56
|
Console.log("Use 'linear team list' to list teams. See --help for more."),
|
|
55
57
|
).pipe(Command.withDescription("Manage Linear teams"), Command.withSubcommands([teamListCommand]));
|
|
58
|
+
|
|
59
|
+
function formatDescription(description: string | null | undefined): string {
|
|
60
|
+
if (description === undefined || description === null) {
|
|
61
|
+
return "";
|
|
62
|
+
}
|
|
63
|
+
return ` - ${description}`;
|
|
64
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Result } from "effect";
|
|
2
|
+
import { IssueFile } from "./Linear.js";
|
|
3
|
+
|
|
4
|
+
// Markdown links and images whose target is a Linear upload: `[name](url)` or ``.
|
|
5
|
+
const uploadLinkPattern = /!?\[([^\]]*)\]\(<?(https:\/\/uploads\.linear\.app\/[^)\s>]+)>?\)/g;
|
|
6
|
+
|
|
7
|
+
export const extractUploadLinks = (
|
|
8
|
+
markdown: string | undefined,
|
|
9
|
+
source: string,
|
|
10
|
+
): ReadonlyArray<IssueFile> => {
|
|
11
|
+
if (markdown === undefined) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
return Array.from(markdown.matchAll(uploadLinkPattern), (match) =>
|
|
15
|
+
IssueFile.make({ name: match[1] ?? "", url: match[2] ?? "", source }),
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Keeps the first link to each URL. */
|
|
20
|
+
export const uniqueByUrl = (files: ReadonlyArray<IssueFile>): ReadonlyArray<IssueFile> => {
|
|
21
|
+
const seenUrls = new Set<string>();
|
|
22
|
+
return files.filter((file) => {
|
|
23
|
+
if (seenUrls.has(file.url)) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
seenUrls.add(file.url);
|
|
27
|
+
return true;
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const unsafeFileNameCharacters = /[^A-Za-z0-9._ ()-]/g;
|
|
32
|
+
|
|
33
|
+
/** A plain file name that cannot leave the output directory. */
|
|
34
|
+
export const toSafeFileName = (candidate: string): string => {
|
|
35
|
+
const baseName = candidate.split(/[/\\]/).pop() ?? "";
|
|
36
|
+
const cleaned = baseName
|
|
37
|
+
.replace(unsafeFileNameCharacters, "_")
|
|
38
|
+
.replace(/^[.\s]+/, "")
|
|
39
|
+
.trim();
|
|
40
|
+
if (cleaned.length === 0) {
|
|
41
|
+
return "download";
|
|
42
|
+
}
|
|
43
|
+
return cleaned;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const splitExtension = (
|
|
47
|
+
fileName: string,
|
|
48
|
+
): { readonly stem: string; readonly extension: string } => {
|
|
49
|
+
const dotIndex = fileName.lastIndexOf(".");
|
|
50
|
+
if (dotIndex <= 0) {
|
|
51
|
+
return { stem: fileName, extension: "" };
|
|
52
|
+
}
|
|
53
|
+
return { stem: fileName.slice(0, dotIndex), extension: fileName.slice(dotIndex) };
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** `report.pdf`, then `report-2.pdf`, `report-3.pdf`, ... for names already taken in this run. */
|
|
57
|
+
export const withUniqueSuffix = (fileName: string, takenNames: ReadonlySet<string>): string => {
|
|
58
|
+
if (!takenNames.has(fileName)) {
|
|
59
|
+
return fileName;
|
|
60
|
+
}
|
|
61
|
+
const { stem, extension } = splitExtension(fileName);
|
|
62
|
+
let counter = 2;
|
|
63
|
+
while (takenNames.has(`${stem}-${counter}${extension}`)) {
|
|
64
|
+
counter += 1;
|
|
65
|
+
}
|
|
66
|
+
return `${stem}-${counter}${extension}`;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const contentDispositionFileName = /filename\*?=(?:UTF-8'')?"?([^";]+)"?/i;
|
|
70
|
+
|
|
71
|
+
export const fileNameFromContentDisposition = (header: string | null): string | undefined => {
|
|
72
|
+
const match = header?.match(contentDispositionFileName);
|
|
73
|
+
if (match?.[1] === undefined) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
const rawName = match[1];
|
|
77
|
+
return Result.getOrElse(
|
|
78
|
+
Result.try(() => decodeURIComponent(rawName)),
|
|
79
|
+
() => rawName,
|
|
80
|
+
);
|
|
81
|
+
};
|
package/src/domain/Input.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { IssueSelector } from "./Linear.js";
|
|
2
|
+
import { IssueSelector, UploadUrl } from "./Linear.js";
|
|
3
3
|
import { InvalidInputError } from "../lib/errors.js";
|
|
4
4
|
|
|
5
5
|
const issueIdentifierPattern = /^[A-Za-z][A-Za-z0-9]*-\d+$/;
|
|
@@ -53,3 +53,16 @@ export const validateText = Effect.fn("Input.validateText")(function* (options:
|
|
|
53
53
|
}
|
|
54
54
|
return options.value;
|
|
55
55
|
});
|
|
56
|
+
|
|
57
|
+
const uploadHost = "uploads.linear.app";
|
|
58
|
+
|
|
59
|
+
// The stored token is sent with the download, so only Linear's own upload host is accepted.
|
|
60
|
+
export const parseUploadUrl = Effect.fn("Input.parseUploadUrl")(function* (input: string) {
|
|
61
|
+
const url = URL.parse(input);
|
|
62
|
+
if (url === null || url.protocol !== "https:" || url.hostname !== uploadHost) {
|
|
63
|
+
return yield* InvalidInputError.make({
|
|
64
|
+
message: `Invalid upload URL: ${input}. Expected https://${uploadHost}/...`,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return UploadUrl.make(url.href);
|
|
68
|
+
});
|
package/src/domain/Linear.ts
CHANGED
|
@@ -3,6 +3,9 @@ import { Schema } from "effect";
|
|
|
3
3
|
export const IssueSelector = Schema.String.pipe(Schema.brand("IssueSelector"));
|
|
4
4
|
export type IssueSelector = Schema.Schema.Type<typeof IssueSelector>;
|
|
5
5
|
|
|
6
|
+
export const UploadUrl = Schema.String.pipe(Schema.brand("UploadUrl"));
|
|
7
|
+
export type UploadUrl = Schema.Schema.Type<typeof UploadUrl>;
|
|
8
|
+
|
|
6
9
|
export class ViewerStatus extends Schema.Class<ViewerStatus>("ViewerStatus")({
|
|
7
10
|
emoji: Schema.optional(Schema.String),
|
|
8
11
|
label: Schema.optional(Schema.String),
|
|
@@ -45,7 +48,7 @@ export class IssueState extends Schema.Class<IssueState>("IssueState")({
|
|
|
45
48
|
}) {}
|
|
46
49
|
|
|
47
50
|
export class IssuePriority extends Schema.Class<IssuePriority>("IssuePriority")({
|
|
48
|
-
value: Schema.
|
|
51
|
+
value: Schema.Finite,
|
|
49
52
|
label: Schema.String,
|
|
50
53
|
}) {}
|
|
51
54
|
|
|
@@ -132,3 +135,24 @@ export interface CreateIssueInput {
|
|
|
132
135
|
readonly projectId?: string;
|
|
133
136
|
readonly priority?: number;
|
|
134
137
|
}
|
|
138
|
+
|
|
139
|
+
export class IssueFile extends Schema.Class<IssueFile>("IssueFile")({
|
|
140
|
+
name: Schema.String,
|
|
141
|
+
url: Schema.String,
|
|
142
|
+
/** `description`, or the ID of the comment that links the file. */
|
|
143
|
+
source: Schema.String,
|
|
144
|
+
}) {}
|
|
145
|
+
|
|
146
|
+
export class SavedFile extends Schema.Class<SavedFile>("SavedFile")({
|
|
147
|
+
url: Schema.String,
|
|
148
|
+
path: Schema.String,
|
|
149
|
+
bytes: Schema.Finite,
|
|
150
|
+
contentType: Schema.optional(Schema.String),
|
|
151
|
+
}) {}
|
|
152
|
+
|
|
153
|
+
export interface DownloadedFile {
|
|
154
|
+
readonly bytes: Uint8Array;
|
|
155
|
+
readonly contentType?: string;
|
|
156
|
+
/** From the `Content-Disposition` header, when the server sends one. */
|
|
157
|
+
readonly fileName?: string;
|
|
158
|
+
}
|