@cvr/linear 0.1.0 → 0.3.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 -13
- package/bin/linear +0 -0
- package/package.json +35 -26
- package/skills/linear/SKILL.md +141 -0
- package/src/commands/api.ts +67 -0
- package/src/commands/auth.ts +63 -42
- package/src/commands/issue.ts +434 -241
- package/src/commands/project.ts +45 -0
- package/src/commands/team.ts +38 -18
- package/src/lib/errors.ts +35 -29
- package/src/lib/json.ts +5 -0
- package/src/main.ts +30 -34
- package/src/services/Browser.ts +8 -8
- package/src/services/Config.ts +85 -87
- package/src/services/Linear.ts +435 -134
- package/src/services/Stdin.ts +15 -22
- package/tsconfig.json +67 -8
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Console, Effect } from "effect";
|
|
2
|
+
import { Command, Flag } from "effect/unstable/cli";
|
|
3
|
+
import { encodeJson } from "../lib/json.js";
|
|
4
|
+
import { LinearService } from "../services/Linear.js";
|
|
5
|
+
|
|
6
|
+
const jsonOption = Flag.boolean("json").pipe(
|
|
7
|
+
Flag.withDescription("Emit stable JSON for scripts and agents"),
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export const projectListCommand = Command.make("list", { json: jsonOption }, ({ json }) =>
|
|
11
|
+
Effect.gen(function* () {
|
|
12
|
+
const linear = yield* LinearService;
|
|
13
|
+
const projects = yield* linear.getProjects;
|
|
14
|
+
|
|
15
|
+
if (json) {
|
|
16
|
+
yield* Console.log(
|
|
17
|
+
encodeJson(
|
|
18
|
+
projects.map((project) => ({
|
|
19
|
+
id: project.id,
|
|
20
|
+
name: project.name,
|
|
21
|
+
slug: project.slugId,
|
|
22
|
+
state: project.state,
|
|
23
|
+
url: project.url,
|
|
24
|
+
})),
|
|
25
|
+
),
|
|
26
|
+
);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (projects.length === 0) {
|
|
31
|
+
yield* Console.log("No projects found.");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
yield* Console.log("\nProjects:\n");
|
|
36
|
+
for (const project of projects) {
|
|
37
|
+
yield* Console.log(` ${project.name} ${project.state} ${project.id}`);
|
|
38
|
+
}
|
|
39
|
+
yield* Console.log("");
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
export const project = Command.make("project", {}, () =>
|
|
44
|
+
Console.log("Use 'linear project list' to list projects. See --help for more."),
|
|
45
|
+
).pipe(Command.withSubcommands([projectListCommand]));
|
package/src/commands/team.ts
CHANGED
|
@@ -1,32 +1,52 @@
|
|
|
1
|
-
import { Command } from "
|
|
2
|
-
import { Console, Effect } from "effect"
|
|
3
|
-
import {
|
|
1
|
+
import { Command, Flag } from "effect/unstable/cli";
|
|
2
|
+
import { Console, Effect } from "effect";
|
|
3
|
+
import { encodeJson } from "../lib/json.js";
|
|
4
|
+
import { LinearService } from "../services/Linear.js";
|
|
5
|
+
|
|
6
|
+
const jsonOption = Flag.boolean("json").pipe(
|
|
7
|
+
Flag.withDescription("Emit stable JSON for scripts and agents"),
|
|
8
|
+
);
|
|
4
9
|
|
|
5
10
|
// linear team list - List all teams
|
|
6
|
-
export const teamListCommand = Command.make("list", {}, () =>
|
|
11
|
+
export const teamListCommand = Command.make("list", { json: jsonOption }, ({ json }) =>
|
|
7
12
|
Effect.gen(function* () {
|
|
8
|
-
const linear = yield* LinearService
|
|
9
|
-
const teams = yield* linear.getTeams
|
|
13
|
+
const linear = yield* LinearService;
|
|
14
|
+
const teams = yield* linear.getTeams;
|
|
10
15
|
|
|
11
16
|
if (teams.length === 0) {
|
|
12
|
-
yield* Console.log("No teams found.")
|
|
13
|
-
return
|
|
17
|
+
yield* Console.log(json ? "[]" : "No teams found.");
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (json) {
|
|
22
|
+
yield* Console.log(
|
|
23
|
+
encodeJson(
|
|
24
|
+
teams.map((team) => ({
|
|
25
|
+
id: team.id,
|
|
26
|
+
key: team.key,
|
|
27
|
+
name: team.name,
|
|
28
|
+
description: team.description ?? undefined,
|
|
29
|
+
})),
|
|
30
|
+
),
|
|
31
|
+
);
|
|
32
|
+
return;
|
|
14
33
|
}
|
|
15
34
|
|
|
16
|
-
yield* Console.log("\nTeams:\n")
|
|
35
|
+
yield* Console.log("\nTeams:\n");
|
|
17
36
|
|
|
18
37
|
for (const team of teams) {
|
|
19
|
-
const key = team.key
|
|
20
|
-
const name = team.name
|
|
21
|
-
const description =
|
|
22
|
-
|
|
38
|
+
const key = team.key;
|
|
39
|
+
const name = team.name;
|
|
40
|
+
const description =
|
|
41
|
+
team.description !== undefined && team.description !== null ? ` - ${team.description}` : "";
|
|
42
|
+
yield* Console.log(` ${key.padEnd(8)} ${name}${description}`);
|
|
23
43
|
}
|
|
24
44
|
|
|
25
|
-
yield* Console.log("")
|
|
26
|
-
})
|
|
27
|
-
)
|
|
45
|
+
yield* Console.log("");
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
28
48
|
|
|
29
49
|
// Combined team command with subcommands
|
|
30
50
|
export const team = Command.make("team", {}, () =>
|
|
31
|
-
Console.log("Use 'linear team list' to list teams. See --help for more.")
|
|
32
|
-
).pipe(Command.withSubcommands([teamListCommand]))
|
|
51
|
+
Console.log("Use 'linear team list' to list teams. See --help for more."),
|
|
52
|
+
).pipe(Command.withSubcommands([teamListCommand]));
|
package/src/lib/errors.ts
CHANGED
|
@@ -1,50 +1,56 @@
|
|
|
1
|
-
import { Schema } from "effect"
|
|
1
|
+
import { Schema } from "effect";
|
|
2
2
|
|
|
3
|
-
export class ConfigError extends Schema.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
message: Schema.String,
|
|
7
|
-
}
|
|
8
|
-
) {}
|
|
3
|
+
export class ConfigError extends Schema.TaggedErrorClass<ConfigError>()("ConfigError", {
|
|
4
|
+
message: Schema.String,
|
|
5
|
+
}) {}
|
|
9
6
|
|
|
10
|
-
export class LinearApiError extends Schema.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
code: Schema.optional(Schema.String),
|
|
15
|
-
}
|
|
16
|
-
) {}
|
|
7
|
+
export class LinearApiError extends Schema.TaggedErrorClass<LinearApiError>()("LinearApiError", {
|
|
8
|
+
message: Schema.String,
|
|
9
|
+
code: Schema.optional(Schema.String),
|
|
10
|
+
}) {}
|
|
17
11
|
|
|
18
|
-
export class BrowserError extends Schema.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
message: Schema.String,
|
|
22
|
-
}
|
|
23
|
-
) {}
|
|
12
|
+
export class BrowserError extends Schema.TaggedErrorClass<BrowserError>()("BrowserError", {
|
|
13
|
+
message: Schema.String,
|
|
14
|
+
}) {}
|
|
24
15
|
|
|
25
|
-
export class TokenNotFoundError extends Schema.
|
|
16
|
+
export class TokenNotFoundError extends Schema.TaggedErrorClass<TokenNotFoundError>()(
|
|
26
17
|
"TokenNotFoundError",
|
|
27
18
|
{
|
|
28
19
|
message: Schema.String,
|
|
29
|
-
}
|
|
20
|
+
},
|
|
30
21
|
) {
|
|
31
22
|
static readonly default = TokenNotFoundError.make({
|
|
32
23
|
message: "No token found. Run 'linear auth' to authenticate.",
|
|
33
|
-
})
|
|
24
|
+
});
|
|
34
25
|
}
|
|
35
26
|
|
|
36
|
-
export class InvalidTokenError extends Schema.
|
|
27
|
+
export class InvalidTokenError extends Schema.TaggedErrorClass<InvalidTokenError>()(
|
|
37
28
|
"InvalidTokenError",
|
|
38
29
|
{
|
|
39
30
|
message: Schema.String,
|
|
40
|
-
}
|
|
31
|
+
},
|
|
32
|
+
) {}
|
|
33
|
+
|
|
34
|
+
export class NoIssuesError extends Schema.TaggedErrorClass<NoIssuesError>()("NoIssuesError", {
|
|
35
|
+
message: Schema.String,
|
|
36
|
+
}) {
|
|
37
|
+
static readonly default = NoIssuesError.make({ message: "No issues found to select from." });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class InvalidInputError extends Schema.TaggedErrorClass<InvalidInputError>()(
|
|
41
|
+
"InvalidInputError",
|
|
42
|
+
{
|
|
43
|
+
message: Schema.String,
|
|
44
|
+
},
|
|
41
45
|
) {}
|
|
42
46
|
|
|
43
|
-
export const AppError = Schema.Union(
|
|
47
|
+
export const AppError = Schema.Union([
|
|
44
48
|
ConfigError,
|
|
45
49
|
LinearApiError,
|
|
46
50
|
BrowserError,
|
|
47
51
|
TokenNotFoundError,
|
|
48
|
-
InvalidTokenError
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
InvalidTokenError,
|
|
53
|
+
NoIssuesError,
|
|
54
|
+
InvalidInputError,
|
|
55
|
+
]);
|
|
56
|
+
export type AppError = typeof AppError.Type;
|
package/src/lib/json.ts
ADDED
package/src/main.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
1
|
+
// @effect-diagnostics strictEffectProvide:off
|
|
2
|
+
import { Command } from "effect/unstable/cli";
|
|
3
|
+
import { BunRuntime, BunServices } from "@effect/platform-bun";
|
|
4
|
+
import { Console, Effect, Layer } from "effect";
|
|
5
|
+
import packageJson from "../package.json" with { type: "json" };
|
|
6
|
+
import { auth } from "./commands/auth.js";
|
|
7
|
+
import { api } from "./commands/api.js";
|
|
8
|
+
import { team } from "./commands/team.js";
|
|
9
|
+
import { issue } from "./commands/issue.js";
|
|
10
|
+
import { project } from "./commands/project.js";
|
|
11
|
+
import { ConfigService } from "./services/Config.js";
|
|
12
|
+
import { LinearService } from "./services/Linear.js";
|
|
13
|
+
import { BrowserService } from "./services/Browser.js";
|
|
14
|
+
import { StdinService } from "./services/Stdin.js";
|
|
12
15
|
|
|
13
16
|
// Root command
|
|
14
17
|
const linear = Command.make("linear", {}, () =>
|
|
15
|
-
Console.log("Linear CLI - Use --help to see available commands")
|
|
16
|
-
).pipe(Command.withSubcommands([auth, team, issue]))
|
|
18
|
+
Console.log("Linear CLI - Use --help to see available commands"),
|
|
19
|
+
).pipe(Command.withSubcommands([auth, team, project, issue, api]));
|
|
17
20
|
|
|
18
21
|
// Build the CLI runner
|
|
19
|
-
const cli = Command.run(linear, {
|
|
20
|
-
name: "linear",
|
|
21
|
-
version: "0.1.0",
|
|
22
|
-
})
|
|
22
|
+
const cli = Command.run(linear, { version: packageJson.version });
|
|
23
23
|
|
|
24
24
|
// Layer composition:
|
|
25
|
-
// -
|
|
25
|
+
// - BunServices provides FileSystem, Path, Terminal, Stdio, and child processes
|
|
26
26
|
// - ConfigService depends on FileSystem, Path
|
|
27
27
|
// - LinearService depends on ConfigService
|
|
28
28
|
// - BrowserService is standalone
|
|
@@ -32,23 +32,19 @@ const MainLayer = StdinService.layer.pipe(
|
|
|
32
32
|
Layer.provideMerge(BrowserService.layer),
|
|
33
33
|
Layer.provideMerge(LinearService.layer),
|
|
34
34
|
Layer.provideMerge(ConfigService.layer),
|
|
35
|
-
Layer.provideMerge(
|
|
36
|
-
)
|
|
35
|
+
Layer.provideMerge(BunServices.layer),
|
|
36
|
+
);
|
|
37
37
|
|
|
38
38
|
// Run the CLI
|
|
39
|
-
cli
|
|
40
|
-
Effect.
|
|
41
|
-
|
|
42
|
-
),
|
|
43
|
-
Effect.
|
|
44
|
-
Console.error(`
|
|
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}`)
|
|
39
|
+
cli.pipe(
|
|
40
|
+
Effect.tapErrorTag("TokenNotFoundError", (e) => Console.error(`Error: ${e.message}`)),
|
|
41
|
+
Effect.tapErrorTag("LinearApiError", (e) => Console.error(`Linear API Error: ${e.message}`)),
|
|
42
|
+
Effect.tapErrorTag("ConfigError", (e) => Console.error(`Config Error: ${e.message}`)),
|
|
43
|
+
Effect.tapErrorTag("InvalidTokenError", (e) =>
|
|
44
|
+
Console.error(`Authentication Error: ${e.message}`),
|
|
51
45
|
),
|
|
46
|
+
Effect.tapErrorTag("NoIssuesError", (e) => Console.error(e.message)),
|
|
47
|
+
Effect.tapErrorTag("InvalidInputError", (e) => Console.error(`Invalid input: ${e.message}`)),
|
|
52
48
|
Effect.provide(MainLayer),
|
|
53
|
-
BunRuntime.runMain
|
|
54
|
-
)
|
|
49
|
+
BunRuntime.runMain({ disableErrorReporting: true }),
|
|
50
|
+
);
|
package/src/services/Browser.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
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
|
-
export class BrowserService extends Context.
|
|
4
|
+
export class BrowserService extends Context.Service<
|
|
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
|
+
>()("@cvr/linear/services/Browser/BrowserService") {
|
|
10
10
|
// macOS-only implementation using `open` command
|
|
11
11
|
static readonly layer = Layer.succeed(BrowserService, {
|
|
12
12
|
open: (url) =>
|
|
@@ -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
|
-
static readonly
|
|
20
|
+
static readonly layerTest = 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 {
|
|
3
|
-
import { ConfigError, TokenNotFoundError } from "../lib/errors.js"
|
|
1
|
+
import { Config, Context, Effect, FileSystem, Layer, Option, Path } from "effect";
|
|
2
|
+
import { ConfigError, TokenNotFoundError } from "../lib/errors.js";
|
|
4
3
|
|
|
5
4
|
// Config structure for .linear.toml
|
|
6
5
|
export interface LinearConfig {
|
|
7
|
-
readonly teamId?: string
|
|
8
|
-
readonly workspace?: string
|
|
9
|
-
readonly issueSort?: "manual" | "priority"
|
|
6
|
+
readonly teamId?: string;
|
|
7
|
+
readonly workspace?: string;
|
|
8
|
+
readonly issueSort?: "manual" | "priority";
|
|
10
9
|
}
|
|
11
10
|
|
|
12
|
-
export class ConfigService extends Context.
|
|
11
|
+
export class ConfigService extends Context.Service<
|
|
13
12
|
ConfigService,
|
|
14
13
|
{
|
|
15
|
-
readonly getToken: Effect.Effect<string, TokenNotFoundError | ConfigError
|
|
16
|
-
readonly saveToken: (token: string) => Effect.Effect<void, ConfigError
|
|
17
|
-
readonly getConfig: Effect.Effect<LinearConfig, ConfigError
|
|
14
|
+
readonly getToken: Effect.Effect<string, TokenNotFoundError | ConfigError>;
|
|
15
|
+
readonly saveToken: (token: string) => Effect.Effect<void, ConfigError>;
|
|
16
|
+
readonly getConfig: Effect.Effect<LinearConfig, ConfigError>;
|
|
18
17
|
}
|
|
19
|
-
>() {
|
|
18
|
+
>()("@cvr/linear/services/Config/ConfigService") {
|
|
20
19
|
static readonly layer = Layer.effect(
|
|
21
20
|
ConfigService,
|
|
22
21
|
Effect.gen(function* () {
|
|
23
|
-
const fs = yield* FileSystem.FileSystem
|
|
24
|
-
const path = yield* Path.Path
|
|
22
|
+
const fs = yield* FileSystem.FileSystem;
|
|
23
|
+
const path = yield* Path.Path;
|
|
25
24
|
|
|
26
|
-
const homeDir =
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
25
|
+
const homeDir = yield* Config.string("HOME").pipe(Config.withDefault(""));
|
|
26
|
+
const envToken = yield* Config.string("LINEAR_API_KEY").pipe(Config.option);
|
|
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
|
-
Effect.
|
|
38
|
-
ConfigError.make({ message: `Failed to create config directory: ${e}` })
|
|
39
|
-
)
|
|
40
|
-
)
|
|
37
|
+
Effect.catch((e) =>
|
|
38
|
+
Effect.fail(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
|
-
if (Option.isSome(fileToken) && fileToken.value.trim()) {
|
|
50
|
-
return fileToken.value.trim()
|
|
49
|
+
if (Option.isSome(fileToken) && fileToken.value.trim().length > 0) {
|
|
50
|
+
return fileToken.value.trim();
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// 2. Try env var
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return envToken
|
|
54
|
+
if (Option.isSome(envToken)) {
|
|
55
|
+
return envToken.value;
|
|
57
56
|
}
|
|
58
57
|
|
|
59
58
|
// 3. Error
|
|
60
|
-
return yield* TokenNotFoundError.default
|
|
61
|
-
}).pipe(Effect.withSpan("ConfigService.getToken"))
|
|
59
|
+
return yield* TokenNotFoundError.default;
|
|
60
|
+
}).pipe(Effect.withSpan("ConfigService.getToken"));
|
|
62
61
|
|
|
63
|
-
const saveToken = (token: string) =>
|
|
62
|
+
const saveToken = Effect.fn("ConfigService.saveToken")((token: string) =>
|
|
64
63
|
Effect.gen(function* () {
|
|
65
|
-
yield* ensureConfigDir
|
|
64
|
+
yield* ensureConfigDir;
|
|
66
65
|
yield* Effect.tryPromise({
|
|
67
66
|
try: () => Bun.write(tokenPath, token.trim()),
|
|
68
67
|
catch: (e) => ConfigError.make({ message: `Failed to save token: ${e}` }),
|
|
69
|
-
})
|
|
70
|
-
})
|
|
68
|
+
});
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
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
|
|
93
|
-
token?: string
|
|
94
|
-
config?: LinearConfig
|
|
95
|
-
}) =>
|
|
88
|
+
});
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
static readonly layerTest = (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
|
-
switch (key
|
|
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
|
+
);
|