@cvr/linear 0.1.0 → 0.2.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 +13 -12
- package/bin/linear +0 -0
- package/package.json +29 -22
- package/src/commands/auth.ts +42 -40
- package/src/commands/issue.ts +167 -191
- package/src/commands/team.ts +17 -17
- package/src/lib/errors.ts +24 -26
- package/src/main.ts +22 -30
- package/src/services/Browser.ts +5 -5
- package/src/services/Config.ts +78 -80
- package/src/services/Linear.ts +124 -123
- package/src/services/Stdin.ts +9 -9
- package/tsconfig.json +0 -1
package/src/main.ts
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
import { Command } from "@effect/cli"
|
|
2
|
-
import { BunContext, BunRuntime } from "@effect/platform-bun"
|
|
3
|
-
import { Console, Effect, Layer } from "effect"
|
|
4
|
-
import { auth } from "./commands/auth.js"
|
|
5
|
-
import { team } from "./commands/team.js"
|
|
6
|
-
import { issue } from "./commands/issue.js"
|
|
7
|
-
import { ConfigService } from "./services/Config.js"
|
|
8
|
-
import { LinearService } from "./services/Linear.js"
|
|
9
|
-
import { BrowserService } from "./services/Browser.js"
|
|
10
|
-
import { StdinService } from "./services/Stdin.js"
|
|
11
|
-
import { TokenNotFoundError } from "./lib/errors.js"
|
|
1
|
+
import { Command } from "@effect/cli";
|
|
2
|
+
import { BunContext, BunRuntime } from "@effect/platform-bun";
|
|
3
|
+
import { Console, Effect, Layer } from "effect";
|
|
4
|
+
import { auth } from "./commands/auth.js";
|
|
5
|
+
import { team } from "./commands/team.js";
|
|
6
|
+
import { issue } from "./commands/issue.js";
|
|
7
|
+
import { ConfigService } from "./services/Config.js";
|
|
8
|
+
import { LinearService } from "./services/Linear.js";
|
|
9
|
+
import { BrowserService } from "./services/Browser.js";
|
|
10
|
+
import { StdinService } from "./services/Stdin.js";
|
|
12
11
|
|
|
13
12
|
// Root command
|
|
14
13
|
const linear = Command.make("linear", {}, () =>
|
|
15
|
-
Console.log("Linear CLI - Use --help to see available commands")
|
|
16
|
-
).pipe(Command.withSubcommands([auth, team, issue]))
|
|
14
|
+
Console.log("Linear CLI - Use --help to see available commands"),
|
|
15
|
+
).pipe(Command.withSubcommands([auth, team, issue]));
|
|
17
16
|
|
|
18
17
|
// Build the CLI runner
|
|
19
18
|
const cli = Command.run(linear, {
|
|
20
19
|
name: "linear",
|
|
21
20
|
version: "0.1.0",
|
|
22
|
-
})
|
|
21
|
+
});
|
|
23
22
|
|
|
24
23
|
// Layer composition:
|
|
25
24
|
// - BunContext provides FileSystem, Path, Terminal
|
|
@@ -32,23 +31,16 @@ const MainLayer = StdinService.layer.pipe(
|
|
|
32
31
|
Layer.provideMerge(BrowserService.layer),
|
|
33
32
|
Layer.provideMerge(LinearService.layer),
|
|
34
33
|
Layer.provideMerge(ConfigService.layer),
|
|
35
|
-
Layer.provideMerge(BunContext.layer)
|
|
36
|
-
)
|
|
34
|
+
Layer.provideMerge(BunContext.layer),
|
|
35
|
+
);
|
|
37
36
|
|
|
38
37
|
// Run the CLI
|
|
39
38
|
cli(process.argv).pipe(
|
|
40
|
-
Effect.catchTag("TokenNotFoundError", (e) =>
|
|
41
|
-
|
|
42
|
-
),
|
|
43
|
-
Effect.catchTag("
|
|
44
|
-
|
|
45
|
-
),
|
|
46
|
-
Effect.catchTag("ConfigError", (e) =>
|
|
47
|
-
Console.error(`Config Error: ${e.message}`)
|
|
48
|
-
),
|
|
49
|
-
Effect.catchTag("InvalidTokenError", (e) =>
|
|
50
|
-
Console.error(`Authentication Error: ${e.message}`)
|
|
51
|
-
),
|
|
39
|
+
Effect.catchTag("TokenNotFoundError", (e) => Console.error(`Error: ${e.message}`)),
|
|
40
|
+
Effect.catchTag("LinearApiError", (e) => Console.error(`Linear API Error: ${e.message}`)),
|
|
41
|
+
Effect.catchTag("ConfigError", (e) => Console.error(`Config Error: ${e.message}`)),
|
|
42
|
+
Effect.catchTag("InvalidTokenError", (e) => Console.error(`Authentication Error: ${e.message}`)),
|
|
43
|
+
Effect.catchTag("NoIssuesError", (e) => Console.error(e.message)),
|
|
52
44
|
Effect.provide(MainLayer),
|
|
53
|
-
BunRuntime.runMain
|
|
54
|
-
)
|
|
45
|
+
BunRuntime.runMain,
|
|
46
|
+
);
|
package/src/services/Browser.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Context, Effect, Layer } from "effect"
|
|
2
|
-
import { BrowserError } from "../lib/errors.js"
|
|
1
|
+
import { Context, Effect, Layer } from "effect";
|
|
2
|
+
import { BrowserError } from "../lib/errors.js";
|
|
3
3
|
|
|
4
4
|
export class BrowserService extends Context.Tag("@linear/BrowserService")<
|
|
5
5
|
BrowserService,
|
|
6
6
|
{
|
|
7
|
-
readonly open: (url: string) => Effect.Effect<void, BrowserError
|
|
7
|
+
readonly open: (url: string) => Effect.Effect<void, BrowserError>;
|
|
8
8
|
}
|
|
9
9
|
>() {
|
|
10
10
|
// macOS-only implementation using `open` command
|
|
@@ -14,10 +14,10 @@ export class BrowserService extends Context.Tag("@linear/BrowserService")<
|
|
|
14
14
|
try: () => Bun.$`open ${url}`.quiet(),
|
|
15
15
|
catch: (e) => BrowserError.make({ message: String(e) }),
|
|
16
16
|
}).pipe(Effect.asVoid),
|
|
17
|
-
})
|
|
17
|
+
});
|
|
18
18
|
|
|
19
19
|
// No-op layer for testing
|
|
20
20
|
static readonly testLayer = Layer.succeed(BrowserService, {
|
|
21
21
|
open: (_url) => Effect.void,
|
|
22
|
-
})
|
|
22
|
+
});
|
|
23
23
|
}
|
package/src/services/Config.ts
CHANGED
|
@@ -1,98 +1,95 @@
|
|
|
1
|
-
import { Context, Effect, Layer, Option } from "effect"
|
|
2
|
-
import { FileSystem, Path } from "@effect/platform"
|
|
3
|
-
import { ConfigError, TokenNotFoundError } from "../lib/errors.js"
|
|
1
|
+
import { Context, Effect, Layer, Option } from "effect";
|
|
2
|
+
import { FileSystem, Path } from "@effect/platform";
|
|
3
|
+
import { ConfigError, TokenNotFoundError } from "../lib/errors.js";
|
|
4
4
|
|
|
5
5
|
// Config structure for .linear.toml
|
|
6
6
|
export interface LinearConfig {
|
|
7
|
-
readonly teamId?: string
|
|
8
|
-
readonly workspace?: string
|
|
9
|
-
readonly issueSort?: "manual" | "priority"
|
|
7
|
+
readonly teamId?: string;
|
|
8
|
+
readonly workspace?: string;
|
|
9
|
+
readonly issueSort?: "manual" | "priority";
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export class ConfigService extends Context.Tag("@linear/ConfigService")<
|
|
13
13
|
ConfigService,
|
|
14
14
|
{
|
|
15
|
-
readonly getToken: Effect.Effect<string, TokenNotFoundError | ConfigError
|
|
16
|
-
readonly saveToken: (token: string) => Effect.Effect<void, ConfigError
|
|
17
|
-
readonly getConfig: Effect.Effect<LinearConfig, ConfigError
|
|
15
|
+
readonly getToken: Effect.Effect<string, TokenNotFoundError | ConfigError>;
|
|
16
|
+
readonly saveToken: (token: string) => Effect.Effect<void, ConfigError>;
|
|
17
|
+
readonly getConfig: Effect.Effect<LinearConfig, ConfigError>;
|
|
18
18
|
}
|
|
19
19
|
>() {
|
|
20
20
|
static readonly layer = Layer.effect(
|
|
21
21
|
ConfigService,
|
|
22
22
|
Effect.gen(function* () {
|
|
23
|
-
const fs = yield* FileSystem.FileSystem
|
|
24
|
-
const path = yield* Path.Path
|
|
23
|
+
const fs = yield* FileSystem.FileSystem;
|
|
24
|
+
const path = yield* Path.Path;
|
|
25
25
|
|
|
26
|
-
const homeDir = process.env.HOME ?? ""
|
|
27
|
-
const configDir = path.join(homeDir, ".config", "linear")
|
|
28
|
-
const tokenPath = path.join(configDir, "token")
|
|
29
|
-
const configPath = path.join(configDir, "config.toml")
|
|
26
|
+
const homeDir = process.env.HOME ?? "";
|
|
27
|
+
const configDir = path.join(homeDir, ".config", "linear");
|
|
28
|
+
const tokenPath = path.join(configDir, "token");
|
|
29
|
+
const configPath = path.join(configDir, "config.toml");
|
|
30
30
|
|
|
31
31
|
const ensureConfigDir = Effect.gen(function* () {
|
|
32
|
-
const exists = yield* fs.exists(configDir)
|
|
32
|
+
const exists = yield* fs.exists(configDir);
|
|
33
33
|
if (!exists) {
|
|
34
|
-
yield* fs.makeDirectory(configDir, { recursive: true })
|
|
34
|
+
yield* fs.makeDirectory(configDir, { recursive: true });
|
|
35
35
|
}
|
|
36
36
|
}).pipe(
|
|
37
37
|
Effect.catchAll((e) =>
|
|
38
|
-
ConfigError.make({ message: `Failed to create config directory: ${e}` })
|
|
39
|
-
)
|
|
40
|
-
)
|
|
38
|
+
ConfigError.make({ message: `Failed to create config directory: ${e}` }),
|
|
39
|
+
),
|
|
40
|
+
);
|
|
41
41
|
|
|
42
42
|
const getToken = Effect.gen(function* () {
|
|
43
43
|
// 1. Try config file first
|
|
44
44
|
const fileToken = yield* Effect.tryPromise({
|
|
45
45
|
try: () => Bun.file(tokenPath).text(),
|
|
46
46
|
catch: () => null,
|
|
47
|
-
}).pipe(Effect.option)
|
|
47
|
+
}).pipe(Effect.option);
|
|
48
48
|
|
|
49
49
|
if (Option.isSome(fileToken) && fileToken.value.trim()) {
|
|
50
|
-
return fileToken.value.trim()
|
|
50
|
+
return fileToken.value.trim();
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// 2. Try env var
|
|
54
|
-
const envToken = process.env.LINEAR_API_KEY
|
|
54
|
+
const envToken = process.env.LINEAR_API_KEY;
|
|
55
55
|
if (envToken) {
|
|
56
|
-
return envToken
|
|
56
|
+
return envToken;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// 3. Error
|
|
60
|
-
return yield* TokenNotFoundError.default
|
|
61
|
-
}).pipe(Effect.withSpan("ConfigService.getToken"))
|
|
60
|
+
return yield* TokenNotFoundError.default;
|
|
61
|
+
}).pipe(Effect.withSpan("ConfigService.getToken"));
|
|
62
62
|
|
|
63
63
|
const saveToken = (token: string) =>
|
|
64
64
|
Effect.gen(function* () {
|
|
65
|
-
yield* ensureConfigDir
|
|
65
|
+
yield* ensureConfigDir;
|
|
66
66
|
yield* Effect.tryPromise({
|
|
67
67
|
try: () => Bun.write(tokenPath, token.trim()),
|
|
68
68
|
catch: (e) => ConfigError.make({ message: `Failed to save token: ${e}` }),
|
|
69
|
-
})
|
|
70
|
-
}).pipe(Effect.withSpan("ConfigService.saveToken"))
|
|
69
|
+
});
|
|
70
|
+
}).pipe(Effect.withSpan("ConfigService.saveToken"));
|
|
71
71
|
|
|
72
72
|
const getConfig = Effect.gen(function* () {
|
|
73
73
|
// Try project config first (.linear.toml in cwd or git root)
|
|
74
|
-
const projectConfig = yield* loadProjectConfig(
|
|
74
|
+
const projectConfig = yield* loadProjectConfig(path);
|
|
75
75
|
if (Option.isSome(projectConfig)) {
|
|
76
|
-
return projectConfig.value
|
|
76
|
+
return projectConfig.value;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
// Fall back to global config
|
|
80
|
-
const globalConfig = yield* loadTomlConfig(configPath)
|
|
81
|
-
return globalConfig
|
|
82
|
-
}).pipe(Effect.withSpan("ConfigService.getConfig"))
|
|
80
|
+
const globalConfig = yield* loadTomlConfig(configPath);
|
|
81
|
+
return globalConfig;
|
|
82
|
+
}).pipe(Effect.withSpan("ConfigService.getConfig"));
|
|
83
83
|
|
|
84
84
|
return ConfigService.of({
|
|
85
85
|
getToken,
|
|
86
86
|
saveToken,
|
|
87
87
|
getConfig,
|
|
88
|
-
})
|
|
89
|
-
})
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
static readonly testLayer = (options?: {
|
|
93
|
-
token?: string
|
|
94
|
-
config?: LinearConfig
|
|
95
|
-
}) =>
|
|
88
|
+
});
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
static readonly testLayer = (options?: { token?: string; config?: LinearConfig }) =>
|
|
96
93
|
Layer.succeed(ConfigService, {
|
|
97
94
|
getToken:
|
|
98
95
|
options?.token != null
|
|
@@ -100,67 +97,68 @@ export class ConfigService extends Context.Tag("@linear/ConfigService")<
|
|
|
100
97
|
: Effect.fail(TokenNotFoundError.default),
|
|
101
98
|
saveToken: (_token) => Effect.void,
|
|
102
99
|
getConfig: Effect.succeed(options?.config ?? {}),
|
|
103
|
-
})
|
|
100
|
+
});
|
|
104
101
|
}
|
|
105
102
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
): Effect.Effect<LinearConfig, ConfigError> {
|
|
109
|
-
return Effect.tryPromise({
|
|
103
|
+
const loadTomlConfig = Effect.fn("ConfigService.loadTomlConfig")((filePath: string) =>
|
|
104
|
+
Effect.tryPromise({
|
|
110
105
|
try: async () => {
|
|
111
|
-
const file = Bun.file(filePath)
|
|
112
|
-
const exists = await file.exists()
|
|
113
|
-
if (!exists) return {}
|
|
106
|
+
const file = Bun.file(filePath);
|
|
107
|
+
const exists = await file.exists();
|
|
108
|
+
if (!exists) return {};
|
|
114
109
|
|
|
115
|
-
const content = await file.text()
|
|
110
|
+
const content = await file.text();
|
|
116
111
|
// Simple TOML parsing for our use case
|
|
117
|
-
|
|
112
|
+
let teamId: string | undefined;
|
|
113
|
+
let workspace: string | undefined;
|
|
114
|
+
let issueSort: "manual" | "priority" | undefined;
|
|
115
|
+
|
|
118
116
|
for (const line of content.split("\n")) {
|
|
119
|
-
const trimmed = line.trim()
|
|
120
|
-
if (trimmed.startsWith("#") || !trimmed.includes("=")) continue
|
|
117
|
+
const trimmed = line.trim();
|
|
118
|
+
if (trimmed.startsWith("#") || !trimmed.includes("=")) continue;
|
|
121
119
|
|
|
122
|
-
const [key, ...rest] = trimmed.split("=")
|
|
123
|
-
const value = rest
|
|
120
|
+
const [key, ...rest] = trimmed.split("=");
|
|
121
|
+
const value = rest
|
|
122
|
+
.join("=")
|
|
123
|
+
.trim()
|
|
124
|
+
.replace(/^["']|["']$/g, "");
|
|
124
125
|
|
|
125
126
|
switch (key.trim()) {
|
|
126
127
|
case "team_id":
|
|
127
|
-
|
|
128
|
-
break
|
|
128
|
+
teamId = value;
|
|
129
|
+
break;
|
|
129
130
|
case "workspace":
|
|
130
|
-
|
|
131
|
-
break
|
|
131
|
+
workspace = value;
|
|
132
|
+
break;
|
|
132
133
|
case "issue_sort":
|
|
133
134
|
if (value === "manual" || value === "priority") {
|
|
134
|
-
|
|
135
|
+
issueSort = value;
|
|
135
136
|
}
|
|
136
|
-
break
|
|
137
|
+
break;
|
|
137
138
|
}
|
|
138
139
|
}
|
|
139
|
-
return
|
|
140
|
+
return { teamId, workspace, issueSort } as LinearConfig;
|
|
140
141
|
},
|
|
141
142
|
catch: (e) => ConfigError.make({ message: `Failed to load config: ${e}` }),
|
|
142
|
-
})
|
|
143
|
-
|
|
143
|
+
}),
|
|
144
|
+
);
|
|
144
145
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
): Effect.Effect<Option.Option<LinearConfig>, ConfigError> {
|
|
149
|
-
return Effect.gen(function* () {
|
|
150
|
-
const cwd = process.cwd()
|
|
146
|
+
const loadProjectConfig = Effect.fn("ConfigService.loadProjectConfig")((pathService: Path.Path) =>
|
|
147
|
+
Effect.gen(function* () {
|
|
148
|
+
const cwd = process.cwd();
|
|
151
149
|
const candidates = [
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
]
|
|
150
|
+
pathService.join(cwd, ".linear.toml"),
|
|
151
|
+
pathService.join(cwd, "linear.toml"),
|
|
152
|
+
];
|
|
155
153
|
|
|
156
154
|
for (const candidate of candidates) {
|
|
157
|
-
const exists = yield*
|
|
155
|
+
const exists = yield* Effect.promise(() => Bun.file(candidate).exists());
|
|
158
156
|
if (exists) {
|
|
159
|
-
const config = yield* loadTomlConfig(candidate)
|
|
160
|
-
return Option.some(config)
|
|
157
|
+
const config = yield* loadTomlConfig(candidate);
|
|
158
|
+
return Option.some(config);
|
|
161
159
|
}
|
|
162
160
|
}
|
|
163
161
|
|
|
164
|
-
return Option.none()
|
|
165
|
-
})
|
|
166
|
-
|
|
162
|
+
return Option.none();
|
|
163
|
+
}),
|
|
164
|
+
);
|
package/src/services/Linear.ts
CHANGED
|
@@ -1,159 +1,160 @@
|
|
|
1
|
-
import { Context, Effect, Layer
|
|
2
|
-
import { LinearClient
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { Context, Effect, Layer } from "effect";
|
|
2
|
+
import { LinearClient } from "@linear/sdk";
|
|
3
|
+
import type { Issue, User, Team } from "@linear/sdk";
|
|
4
|
+
import { LinearApiError, InvalidTokenError, TokenNotFoundError } from "../lib/errors.js";
|
|
5
|
+
import { ConfigService } from "./Config.js";
|
|
5
6
|
|
|
6
7
|
export interface IssueFilter {
|
|
7
|
-
readonly teamId?: string
|
|
8
|
-
readonly state?: "triage" | "backlog" | "unstarted" | "started" | "completed" | "canceled"
|
|
9
|
-
readonly assigneeId?: string
|
|
10
|
-
readonly limit?: number
|
|
8
|
+
readonly teamId?: string;
|
|
9
|
+
readonly state?: "triage" | "backlog" | "unstarted" | "started" | "completed" | "canceled";
|
|
10
|
+
readonly assigneeId?: string;
|
|
11
|
+
readonly limit?: number;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export class LinearService extends Context.Tag("@linear/LinearService")<
|
|
14
15
|
LinearService,
|
|
15
16
|
{
|
|
16
|
-
readonly getViewer: Effect.Effect<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
readonly
|
|
21
|
-
readonly
|
|
17
|
+
readonly getViewer: Effect.Effect<
|
|
18
|
+
User,
|
|
19
|
+
LinearApiError | InvalidTokenError | TokenNotFoundError
|
|
20
|
+
>;
|
|
21
|
+
readonly getTeams: Effect.Effect<readonly Team[], LinearApiError | TokenNotFoundError>;
|
|
22
|
+
readonly getIssues: (
|
|
23
|
+
filter: IssueFilter,
|
|
24
|
+
) => Effect.Effect<readonly Issue[], LinearApiError | TokenNotFoundError>;
|
|
25
|
+
readonly getIssue: (id: string) => Effect.Effect<Issue, LinearApiError | TokenNotFoundError>;
|
|
26
|
+
readonly getMyIssues: (filter?: {
|
|
27
|
+
state?: string;
|
|
28
|
+
}) => Effect.Effect<readonly Issue[], LinearApiError | TokenNotFoundError>;
|
|
29
|
+
readonly updateIssueState: (
|
|
30
|
+
issueId: string,
|
|
31
|
+
stateId: string,
|
|
32
|
+
) => Effect.Effect<void, LinearApiError | TokenNotFoundError>;
|
|
22
33
|
readonly createIssue: (input: {
|
|
23
|
-
title: string
|
|
24
|
-
teamId: string
|
|
25
|
-
description?: string
|
|
26
|
-
}) => Effect.Effect<Issue, LinearApiError | TokenNotFoundError
|
|
34
|
+
title: string;
|
|
35
|
+
teamId: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
}) => Effect.Effect<Issue, LinearApiError | TokenNotFoundError>;
|
|
27
38
|
}
|
|
28
39
|
>() {
|
|
29
40
|
static readonly layer = Layer.effect(
|
|
30
41
|
LinearService,
|
|
31
42
|
Effect.gen(function* () {
|
|
32
|
-
const configService = yield* ConfigService
|
|
43
|
+
const configService = yield* ConfigService;
|
|
33
44
|
|
|
34
|
-
//
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const token = yield* configService.getToken
|
|
43
|
-
const client = new LinearClient({ apiKey: token })
|
|
44
|
-
yield* Ref.set(clientRef, client)
|
|
45
|
-
return client
|
|
46
|
-
})
|
|
45
|
+
// Lazy client creation - token is loaded when first API call is made
|
|
46
|
+
const getClient = configService.getToken.pipe(
|
|
47
|
+
Effect.catchTag("ConfigError", (e) => TokenNotFoundError.make({ message: e.message })),
|
|
48
|
+
Effect.map((token) => new LinearClient({ apiKey: token })),
|
|
49
|
+
Effect.cached,
|
|
50
|
+
Effect.runSync,
|
|
51
|
+
);
|
|
47
52
|
|
|
48
53
|
const getViewer = Effect.gen(function* () {
|
|
49
|
-
const client = yield* getClient
|
|
50
|
-
|
|
54
|
+
const client = yield* getClient;
|
|
55
|
+
return yield* Effect.tryPromise({
|
|
51
56
|
try: () => client.viewer,
|
|
52
57
|
catch: (e) => {
|
|
53
|
-
const msg = String(e)
|
|
58
|
+
const msg = String(e);
|
|
54
59
|
if (msg.includes("Authentication") || msg.includes("401")) {
|
|
55
|
-
return InvalidTokenError.make({ message: "Invalid API token" })
|
|
60
|
+
return InvalidTokenError.make({ message: "Invalid API token" });
|
|
56
61
|
}
|
|
57
|
-
return LinearApiError.make({ message: msg })
|
|
62
|
+
return LinearApiError.make({ message: msg });
|
|
58
63
|
},
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
})
|
|
64
|
+
});
|
|
65
|
+
}).pipe(Effect.withSpan("LinearService.getViewer"));
|
|
62
66
|
|
|
63
67
|
const getTeams = Effect.gen(function* () {
|
|
64
|
-
const client = yield* getClient
|
|
65
|
-
const
|
|
66
|
-
try:
|
|
67
|
-
const connection = await client.teams()
|
|
68
|
-
return connection.nodes
|
|
69
|
-
},
|
|
68
|
+
const client = yield* getClient;
|
|
69
|
+
const connection = yield* Effect.tryPromise({
|
|
70
|
+
try: () => client.teams(),
|
|
70
71
|
catch: (e) => LinearApiError.make({ message: String(e) }),
|
|
71
|
-
})
|
|
72
|
-
return
|
|
73
|
-
})
|
|
72
|
+
});
|
|
73
|
+
return connection.nodes;
|
|
74
|
+
}).pipe(Effect.withSpan("LinearService.getTeams"));
|
|
74
75
|
|
|
75
|
-
const getIssues = (filter: IssueFilter) =>
|
|
76
|
+
const getIssues = Effect.fn("LinearService.getIssues")((filter: IssueFilter) =>
|
|
76
77
|
Effect.gen(function* () {
|
|
77
|
-
const client = yield* getClient
|
|
78
|
-
const
|
|
79
|
-
try:
|
|
80
|
-
|
|
78
|
+
const client = yield* getClient;
|
|
79
|
+
const connection = yield* Effect.tryPromise({
|
|
80
|
+
try: () =>
|
|
81
|
+
client.issues({
|
|
81
82
|
first: filter.limit ?? 50,
|
|
82
83
|
filter: {
|
|
83
84
|
team: filter.teamId ? { id: { eq: filter.teamId } } : undefined,
|
|
84
85
|
state: filter.state ? { type: { eq: filter.state } } : undefined,
|
|
85
|
-
assignee: filter.assigneeId
|
|
86
|
-
? { id: { eq: filter.assigneeId } }
|
|
87
|
-
: undefined,
|
|
86
|
+
assignee: filter.assigneeId ? { id: { eq: filter.assigneeId } } : undefined,
|
|
88
87
|
},
|
|
89
|
-
})
|
|
90
|
-
return connection.nodes
|
|
91
|
-
},
|
|
88
|
+
}),
|
|
92
89
|
catch: (e) => LinearApiError.make({ message: String(e) }),
|
|
93
|
-
})
|
|
94
|
-
return
|
|
95
|
-
})
|
|
90
|
+
});
|
|
91
|
+
return connection.nodes;
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
96
94
|
|
|
97
|
-
const getMyIssues = (filter?: { state?: string }) =>
|
|
95
|
+
const getMyIssues = Effect.fn("LinearService.getMyIssues")((filter?: { state?: string }) =>
|
|
98
96
|
Effect.gen(function* () {
|
|
99
|
-
const client = yield* getClient
|
|
100
|
-
const
|
|
101
|
-
try:
|
|
102
|
-
|
|
103
|
-
|
|
97
|
+
const client = yield* getClient;
|
|
98
|
+
const viewer = yield* Effect.tryPromise({
|
|
99
|
+
try: () => client.viewer,
|
|
100
|
+
catch: (e) => LinearApiError.make({ message: String(e) }),
|
|
101
|
+
});
|
|
102
|
+
const connection = yield* Effect.tryPromise({
|
|
103
|
+
try: () =>
|
|
104
|
+
viewer.assignedIssues({
|
|
104
105
|
first: 50,
|
|
105
|
-
filter: filter?.state
|
|
106
|
-
|
|
107
|
-
: undefined,
|
|
108
|
-
})
|
|
109
|
-
return connection.nodes
|
|
110
|
-
},
|
|
106
|
+
filter: filter?.state ? { state: { type: { eq: filter.state } } } : undefined,
|
|
107
|
+
}),
|
|
111
108
|
catch: (e) => LinearApiError.make({ message: String(e) }),
|
|
112
|
-
})
|
|
113
|
-
return
|
|
114
|
-
})
|
|
109
|
+
});
|
|
110
|
+
return connection.nodes;
|
|
111
|
+
}),
|
|
112
|
+
);
|
|
115
113
|
|
|
116
|
-
const getIssue = (id: string) =>
|
|
114
|
+
const getIssue = Effect.fn("LinearService.getIssue")((id: string) =>
|
|
117
115
|
Effect.gen(function* () {
|
|
118
|
-
const client = yield* getClient
|
|
119
|
-
|
|
116
|
+
const client = yield* getClient;
|
|
117
|
+
return yield* Effect.tryPromise({
|
|
120
118
|
try: () => client.issue(id),
|
|
121
119
|
catch: (e) => LinearApiError.make({ message: String(e) }),
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
});
|
|
121
|
+
}),
|
|
122
|
+
);
|
|
125
123
|
|
|
126
|
-
const updateIssueState = (
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
124
|
+
const updateIssueState = Effect.fn("LinearService.updateIssueState")(
|
|
125
|
+
(issueId: string, stateId: string) =>
|
|
126
|
+
Effect.gen(function* () {
|
|
127
|
+
const client = yield* getClient;
|
|
128
|
+
yield* Effect.tryPromise({
|
|
129
|
+
try: () => client.updateIssue(issueId, { stateId }),
|
|
130
|
+
catch: (e) => LinearApiError.make({ message: String(e) }),
|
|
131
|
+
});
|
|
132
|
+
}),
|
|
133
|
+
);
|
|
134
134
|
|
|
135
|
-
const createIssue = (
|
|
136
|
-
title: string
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
135
|
+
const createIssue = Effect.fn("LinearService.createIssue")(
|
|
136
|
+
(input: { title: string; teamId: string; description?: string }) =>
|
|
137
|
+
Effect.gen(function* () {
|
|
138
|
+
const client = yield* getClient;
|
|
139
|
+
const payload = yield* Effect.tryPromise({
|
|
140
|
+
try: () =>
|
|
141
|
+
client.createIssue({
|
|
142
|
+
title: input.title,
|
|
143
|
+
teamId: input.teamId,
|
|
144
|
+
description: input.description,
|
|
145
|
+
}),
|
|
146
|
+
catch: (e) => LinearApiError.make({ message: String(e) }),
|
|
147
|
+
});
|
|
148
|
+
const issueFetch = payload.issue;
|
|
149
|
+
if (!issueFetch) {
|
|
150
|
+
return yield* LinearApiError.make({ message: "Failed to create issue" });
|
|
151
|
+
}
|
|
152
|
+
return yield* Effect.tryPromise({
|
|
153
|
+
try: () => issueFetch,
|
|
154
|
+
catch: (e) => LinearApiError.make({ message: String(e) }),
|
|
155
|
+
});
|
|
156
|
+
}),
|
|
157
|
+
);
|
|
157
158
|
|
|
158
159
|
return LinearService.of({
|
|
159
160
|
getViewer,
|
|
@@ -163,14 +164,14 @@ export class LinearService extends Context.Tag("@linear/LinearService")<
|
|
|
163
164
|
getIssue,
|
|
164
165
|
updateIssueState,
|
|
165
166
|
createIssue,
|
|
166
|
-
})
|
|
167
|
-
})
|
|
168
|
-
)
|
|
167
|
+
});
|
|
168
|
+
}),
|
|
169
|
+
);
|
|
169
170
|
|
|
170
171
|
static readonly testLayer = (options?: {
|
|
171
|
-
viewer?: User
|
|
172
|
-
teams?: readonly Team[]
|
|
173
|
-
issues?: readonly Issue[]
|
|
172
|
+
viewer?: User;
|
|
173
|
+
teams?: readonly Team[];
|
|
174
|
+
issues?: readonly Issue[];
|
|
174
175
|
}) =>
|
|
175
176
|
Layer.succeed(LinearService, {
|
|
176
177
|
getViewer: options?.viewer
|
|
@@ -180,13 +181,13 @@ export class LinearService extends Context.Tag("@linear/LinearService")<
|
|
|
180
181
|
getIssues: (_filter) => Effect.succeed(options?.issues ?? []),
|
|
181
182
|
getMyIssues: (_filter) => Effect.succeed(options?.issues ?? []),
|
|
182
183
|
getIssue: (id) => {
|
|
183
|
-
const issue = options?.issues?.find((i) => i.id === id ||
|
|
184
|
+
const issue = options?.issues?.find((i) => i.id === id || i.identifier === id);
|
|
184
185
|
return issue
|
|
185
186
|
? Effect.succeed(issue)
|
|
186
|
-
: Effect.fail(LinearApiError.make({ message: `Issue ${id} not found` }))
|
|
187
|
+
: Effect.fail(LinearApiError.make({ message: `Issue ${id} not found` }));
|
|
187
188
|
},
|
|
188
189
|
updateIssueState: (_issueId, _stateId) => Effect.void,
|
|
189
190
|
createIssue: (_input) =>
|
|
190
191
|
Effect.fail(LinearApiError.make({ message: "Not implemented in test" })),
|
|
191
|
-
})
|
|
192
|
+
});
|
|
192
193
|
}
|