@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
package/src/services/Linear.ts
CHANGED
|
@@ -1,192 +1,493 @@
|
|
|
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, Project, Team, User } 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
|
-
export
|
|
14
|
+
export interface IssueDetailsOptions {
|
|
15
|
+
readonly comments: boolean;
|
|
16
|
+
readonly children: boolean;
|
|
17
|
+
readonly relations: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface IssueReference {
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly identifier: string;
|
|
23
|
+
readonly title: string;
|
|
24
|
+
readonly url: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface IssueDetails extends IssueReference {
|
|
28
|
+
readonly description?: string;
|
|
29
|
+
readonly branchName: string;
|
|
30
|
+
readonly priority: {
|
|
31
|
+
readonly value: number;
|
|
32
|
+
readonly label: string;
|
|
33
|
+
};
|
|
34
|
+
readonly state?: {
|
|
35
|
+
readonly id: string;
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly type: string;
|
|
38
|
+
};
|
|
39
|
+
readonly team?: {
|
|
40
|
+
readonly id: string;
|
|
41
|
+
readonly key: string;
|
|
42
|
+
readonly name: string;
|
|
43
|
+
};
|
|
44
|
+
readonly assignee?: {
|
|
45
|
+
readonly id: string;
|
|
46
|
+
readonly name: string;
|
|
47
|
+
readonly email: string;
|
|
48
|
+
};
|
|
49
|
+
readonly project?: {
|
|
50
|
+
readonly id: string;
|
|
51
|
+
readonly name: string;
|
|
52
|
+
readonly url: string;
|
|
53
|
+
};
|
|
54
|
+
readonly parent?: IssueReference;
|
|
55
|
+
readonly labels: ReadonlyArray<{ readonly id: string; readonly name: string }>;
|
|
56
|
+
readonly children?: ReadonlyArray<IssueReference>;
|
|
57
|
+
readonly comments?: ReadonlyArray<{
|
|
58
|
+
readonly id: string;
|
|
59
|
+
readonly body: string;
|
|
60
|
+
readonly createdAt: string;
|
|
61
|
+
readonly url: string;
|
|
62
|
+
readonly author?: { readonly id: string; readonly name: string };
|
|
63
|
+
}>;
|
|
64
|
+
readonly relations?: ReadonlyArray<{
|
|
65
|
+
readonly id: string;
|
|
66
|
+
readonly type: string;
|
|
67
|
+
readonly direction: "outbound" | "inbound";
|
|
68
|
+
readonly issue: IssueReference;
|
|
69
|
+
}>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export class LinearService extends Context.Service<
|
|
14
73
|
LinearService,
|
|
15
74
|
{
|
|
16
|
-
readonly getViewer: Effect.Effect<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
readonly
|
|
21
|
-
readonly
|
|
75
|
+
readonly getViewer: Effect.Effect<
|
|
76
|
+
User,
|
|
77
|
+
LinearApiError | InvalidTokenError | TokenNotFoundError
|
|
78
|
+
>;
|
|
79
|
+
readonly getTeams: Effect.Effect<readonly Team[], LinearApiError | TokenNotFoundError>;
|
|
80
|
+
readonly getProjects: Effect.Effect<readonly Project[], LinearApiError | TokenNotFoundError>;
|
|
81
|
+
readonly getIssues: (
|
|
82
|
+
filter: IssueFilter,
|
|
83
|
+
) => Effect.Effect<readonly Issue[], LinearApiError | TokenNotFoundError>;
|
|
84
|
+
readonly getIssue: (id: string) => Effect.Effect<Issue, LinearApiError | TokenNotFoundError>;
|
|
85
|
+
readonly getIssueDetails: (
|
|
86
|
+
id: string,
|
|
87
|
+
options: IssueDetailsOptions,
|
|
88
|
+
) => Effect.Effect<IssueDetails, LinearApiError | TokenNotFoundError>;
|
|
89
|
+
readonly getMyIssues: (filter?: {
|
|
90
|
+
state?: string;
|
|
91
|
+
}) => Effect.Effect<readonly Issue[], LinearApiError | TokenNotFoundError>;
|
|
92
|
+
readonly updateIssueState: (
|
|
93
|
+
issueId: string,
|
|
94
|
+
stateId: string,
|
|
95
|
+
) => Effect.Effect<void, LinearApiError | TokenNotFoundError>;
|
|
22
96
|
readonly createIssue: (input: {
|
|
23
|
-
title: string
|
|
24
|
-
teamId: string
|
|
25
|
-
description?: string
|
|
26
|
-
|
|
97
|
+
title: string;
|
|
98
|
+
teamId: string;
|
|
99
|
+
description?: string;
|
|
100
|
+
parentId?: string;
|
|
101
|
+
projectId?: string;
|
|
102
|
+
priority?: number;
|
|
103
|
+
}) => Effect.Effect<Issue, LinearApiError | TokenNotFoundError>;
|
|
104
|
+
readonly createComment: (
|
|
105
|
+
issueId: string,
|
|
106
|
+
body: string,
|
|
107
|
+
) => Effect.Effect<
|
|
108
|
+
{ readonly id: string; readonly url: string },
|
|
109
|
+
LinearApiError | TokenNotFoundError
|
|
110
|
+
>;
|
|
111
|
+
readonly rawQuery: (
|
|
112
|
+
query: string,
|
|
113
|
+
variables: Readonly<Record<string, unknown>>,
|
|
114
|
+
) => Effect.Effect<unknown, LinearApiError | TokenNotFoundError>;
|
|
27
115
|
}
|
|
28
|
-
>() {
|
|
116
|
+
>()("@cvr/linear/services/Linear/LinearService") {
|
|
29
117
|
static readonly layer = Layer.effect(
|
|
30
118
|
LinearService,
|
|
31
119
|
Effect.gen(function* () {
|
|
32
|
-
const configService = yield* ConfigService
|
|
33
|
-
|
|
34
|
-
// Cache the client once token is loaded
|
|
35
|
-
const clientRef = yield* Ref.make<LinearClient | null>(null)
|
|
120
|
+
const configService = yield* ConfigService;
|
|
36
121
|
|
|
37
|
-
//
|
|
38
|
-
const getClient =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
yield* Ref.set(clientRef, client)
|
|
45
|
-
return client
|
|
46
|
-
})
|
|
122
|
+
// Lazy client creation - token is loaded when first API call is made
|
|
123
|
+
const getClient = configService.getToken.pipe(
|
|
124
|
+
Effect.catchTag("ConfigError", (e) => TokenNotFoundError.make({ message: e.message })),
|
|
125
|
+
Effect.map((token) => new LinearClient({ apiKey: token })),
|
|
126
|
+
Effect.cached,
|
|
127
|
+
Effect.runSync,
|
|
128
|
+
);
|
|
47
129
|
|
|
48
130
|
const getViewer = Effect.gen(function* () {
|
|
49
|
-
const client = yield* getClient
|
|
50
|
-
|
|
131
|
+
const client = yield* getClient;
|
|
132
|
+
return yield* Effect.tryPromise({
|
|
51
133
|
try: () => client.viewer,
|
|
52
134
|
catch: (e) => {
|
|
53
|
-
const msg = String(e)
|
|
135
|
+
const msg = String(e);
|
|
54
136
|
if (msg.includes("Authentication") || msg.includes("401")) {
|
|
55
|
-
return InvalidTokenError.make({ message: "Invalid API token" })
|
|
137
|
+
return InvalidTokenError.make({ message: "Invalid API token" });
|
|
56
138
|
}
|
|
57
|
-
return LinearApiError.make({ message: msg })
|
|
139
|
+
return LinearApiError.make({ message: msg });
|
|
58
140
|
},
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
})
|
|
141
|
+
});
|
|
142
|
+
}).pipe(Effect.withSpan("LinearService.getViewer"));
|
|
62
143
|
|
|
63
144
|
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
|
-
},
|
|
145
|
+
const client = yield* getClient;
|
|
146
|
+
const connection = yield* Effect.tryPromise({
|
|
147
|
+
try: () => client.teams(),
|
|
70
148
|
catch: (e) => LinearApiError.make({ message: String(e) }),
|
|
71
|
-
})
|
|
72
|
-
return
|
|
73
|
-
})
|
|
149
|
+
});
|
|
150
|
+
return connection.nodes;
|
|
151
|
+
}).pipe(Effect.withSpan("LinearService.getTeams"));
|
|
74
152
|
|
|
75
|
-
const
|
|
153
|
+
const getProjects = Effect.gen(function* () {
|
|
154
|
+
const client = yield* getClient;
|
|
155
|
+
const connection = yield* Effect.tryPromise({
|
|
156
|
+
try: () => client.projects(),
|
|
157
|
+
catch: (error) => LinearApiError.make({ message: String(error) }),
|
|
158
|
+
});
|
|
159
|
+
return connection.nodes;
|
|
160
|
+
}).pipe(Effect.withSpan("LinearService.getProjects"));
|
|
161
|
+
|
|
162
|
+
const getIssues = Effect.fn("LinearService.getIssues")((filter: IssueFilter) =>
|
|
76
163
|
Effect.gen(function* () {
|
|
77
|
-
const client = yield* getClient
|
|
78
|
-
const
|
|
79
|
-
try:
|
|
80
|
-
|
|
164
|
+
const client = yield* getClient;
|
|
165
|
+
const connection = yield* Effect.tryPromise({
|
|
166
|
+
try: () =>
|
|
167
|
+
client.issues({
|
|
81
168
|
first: filter.limit ?? 50,
|
|
82
169
|
filter: {
|
|
83
|
-
team: filter.teamId ? { id: { eq: filter.teamId } } : undefined,
|
|
84
|
-
state: filter.state ? { type: { eq: filter.state } } : undefined,
|
|
85
|
-
assignee:
|
|
86
|
-
? { id: { eq: filter.assigneeId } }
|
|
87
|
-
: undefined,
|
|
170
|
+
team: filter.teamId !== undefined ? { id: { eq: filter.teamId } } : undefined,
|
|
171
|
+
state: filter.state !== undefined ? { type: { eq: filter.state } } : undefined,
|
|
172
|
+
assignee:
|
|
173
|
+
filter.assigneeId !== undefined ? { id: { eq: filter.assigneeId } } : undefined,
|
|
88
174
|
},
|
|
89
|
-
})
|
|
90
|
-
return connection.nodes
|
|
91
|
-
},
|
|
175
|
+
}),
|
|
92
176
|
catch: (e) => LinearApiError.make({ message: String(e) }),
|
|
93
|
-
})
|
|
94
|
-
return
|
|
95
|
-
})
|
|
177
|
+
});
|
|
178
|
+
return connection.nodes;
|
|
179
|
+
}),
|
|
180
|
+
);
|
|
96
181
|
|
|
97
|
-
const getMyIssues = (filter?: { state?: string }) =>
|
|
182
|
+
const getMyIssues = Effect.fn("LinearService.getMyIssues")((filter?: { state?: string }) =>
|
|
98
183
|
Effect.gen(function* () {
|
|
99
|
-
const client = yield* getClient
|
|
100
|
-
const
|
|
101
|
-
try:
|
|
102
|
-
|
|
103
|
-
|
|
184
|
+
const client = yield* getClient;
|
|
185
|
+
const viewer = yield* Effect.tryPromise({
|
|
186
|
+
try: () => client.viewer,
|
|
187
|
+
catch: (e) => LinearApiError.make({ message: String(e) }),
|
|
188
|
+
});
|
|
189
|
+
const connection = yield* Effect.tryPromise({
|
|
190
|
+
try: () =>
|
|
191
|
+
viewer.assignedIssues({
|
|
104
192
|
first: 50,
|
|
105
|
-
filter:
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
},
|
|
193
|
+
filter:
|
|
194
|
+
filter?.state !== undefined
|
|
195
|
+
? { state: { type: { eq: filter.state } } }
|
|
196
|
+
: undefined,
|
|
197
|
+
}),
|
|
111
198
|
catch: (e) => LinearApiError.make({ message: String(e) }),
|
|
112
|
-
})
|
|
113
|
-
return
|
|
114
|
-
})
|
|
199
|
+
});
|
|
200
|
+
return connection.nodes;
|
|
201
|
+
}),
|
|
202
|
+
);
|
|
115
203
|
|
|
116
|
-
const getIssue = (id: string) =>
|
|
204
|
+
const getIssue = Effect.fn("LinearService.getIssue")((id: string) =>
|
|
117
205
|
Effect.gen(function* () {
|
|
118
|
-
const client = yield* getClient
|
|
119
|
-
|
|
206
|
+
const client = yield* getClient;
|
|
207
|
+
return yield* Effect.tryPromise({
|
|
120
208
|
try: () => client.issue(id),
|
|
121
209
|
catch: (e) => LinearApiError.make({ message: String(e) }),
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
|
|
210
|
+
});
|
|
211
|
+
}),
|
|
212
|
+
);
|
|
125
213
|
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
214
|
+
const getIssueDetails = Effect.fn("LinearService.getIssueDetails")(
|
|
215
|
+
(id: string, options: IssueDetailsOptions) =>
|
|
216
|
+
Effect.gen(function* () {
|
|
217
|
+
const issue = yield* getIssue(normalizeIssueId(id));
|
|
218
|
+
const [state, team, assignee, project, parent, labels] = yield* Effect.all([
|
|
219
|
+
resolveLinearFetch(issue.state),
|
|
220
|
+
resolveLinearFetch(issue.team),
|
|
221
|
+
resolveLinearFetch(issue.assignee),
|
|
222
|
+
resolveLinearFetch(issue.project),
|
|
223
|
+
resolveLinearFetch(issue.parent),
|
|
224
|
+
loadConnection(() => issue.labels()),
|
|
225
|
+
]);
|
|
226
|
+
|
|
227
|
+
const children = options.children
|
|
228
|
+
? yield* loadConnection(() => issue.children())
|
|
229
|
+
: undefined;
|
|
230
|
+
const comments = options.comments
|
|
231
|
+
? yield* loadConnection(() => issue.comments())
|
|
232
|
+
: undefined;
|
|
233
|
+
const outboundRelations = options.relations
|
|
234
|
+
? yield* loadConnection(() => issue.relations())
|
|
235
|
+
: undefined;
|
|
236
|
+
const inboundRelations = options.relations
|
|
237
|
+
? yield* loadConnection(() => issue.inverseRelations())
|
|
238
|
+
: undefined;
|
|
239
|
+
|
|
240
|
+
const detailedComments =
|
|
241
|
+
comments === undefined
|
|
242
|
+
? undefined
|
|
243
|
+
: yield* Effect.forEach(
|
|
244
|
+
comments,
|
|
245
|
+
(comment) =>
|
|
246
|
+
resolveLinearFetch(comment.user).pipe(
|
|
247
|
+
Effect.map((author) => ({
|
|
248
|
+
id: comment.id,
|
|
249
|
+
body: comment.body,
|
|
250
|
+
createdAt: comment.createdAt.toISOString(),
|
|
251
|
+
url: comment.url,
|
|
252
|
+
author:
|
|
253
|
+
author === undefined ? undefined : { id: author.id, name: author.name },
|
|
254
|
+
})),
|
|
255
|
+
),
|
|
256
|
+
{ concurrency: 4 },
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
const relations =
|
|
260
|
+
outboundRelations === undefined || inboundRelations === undefined
|
|
261
|
+
? undefined
|
|
262
|
+
: yield* Effect.forEach(
|
|
263
|
+
outboundRelations
|
|
264
|
+
.map(
|
|
265
|
+
(
|
|
266
|
+
relation,
|
|
267
|
+
): {
|
|
268
|
+
readonly relation: typeof relation;
|
|
269
|
+
readonly direction: "outbound" | "inbound";
|
|
270
|
+
} => ({ relation, direction: "outbound" }),
|
|
271
|
+
)
|
|
272
|
+
.concat(
|
|
273
|
+
inboundRelations.map((relation) => ({
|
|
274
|
+
relation,
|
|
275
|
+
direction: "inbound" as const,
|
|
276
|
+
})),
|
|
277
|
+
),
|
|
278
|
+
({ direction, relation }) =>
|
|
279
|
+
resolveLinearFetch(
|
|
280
|
+
direction === "outbound" ? relation.relatedIssue : relation.issue,
|
|
281
|
+
).pipe(
|
|
282
|
+
Effect.flatMap((relatedIssue) =>
|
|
283
|
+
relatedIssue === undefined
|
|
284
|
+
? Effect.succeed(undefined)
|
|
285
|
+
: Effect.succeed({
|
|
286
|
+
id: relation.id,
|
|
287
|
+
type: relation.type,
|
|
288
|
+
direction,
|
|
289
|
+
issue: toIssueReference(relatedIssue),
|
|
290
|
+
}),
|
|
291
|
+
),
|
|
292
|
+
),
|
|
293
|
+
{ concurrency: 4 },
|
|
294
|
+
).pipe(
|
|
295
|
+
Effect.map((items) =>
|
|
296
|
+
items.filter((item): item is NonNullable<typeof item> => item !== undefined),
|
|
297
|
+
),
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
return {
|
|
301
|
+
id: issue.id,
|
|
302
|
+
identifier: issue.identifier,
|
|
303
|
+
title: issue.title,
|
|
304
|
+
url: issue.url,
|
|
305
|
+
description: issue.description ?? undefined,
|
|
306
|
+
branchName: issue.branchName,
|
|
307
|
+
priority: { value: issue.priority, label: issue.priorityLabel },
|
|
308
|
+
state:
|
|
309
|
+
state === undefined
|
|
310
|
+
? undefined
|
|
311
|
+
: { id: state.id, name: state.name, type: state.type },
|
|
312
|
+
team:
|
|
313
|
+
team === undefined ? undefined : { id: team.id, key: team.key, name: team.name },
|
|
314
|
+
assignee:
|
|
315
|
+
assignee === undefined
|
|
316
|
+
? undefined
|
|
317
|
+
: { id: assignee.id, name: assignee.name, email: assignee.email },
|
|
318
|
+
project:
|
|
319
|
+
project === undefined
|
|
320
|
+
? undefined
|
|
321
|
+
: { id: project.id, name: project.name, url: project.url },
|
|
322
|
+
parent: parent === undefined ? undefined : toIssueReference(parent),
|
|
323
|
+
labels: labels.map((label) => ({ id: label.id, name: label.name })),
|
|
324
|
+
children: children?.map(toIssueReference),
|
|
325
|
+
comments: detailedComments,
|
|
326
|
+
relations,
|
|
327
|
+
} satisfies IssueDetails;
|
|
328
|
+
}),
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
const updateIssueState = Effect.fn("LinearService.updateIssueState")(
|
|
332
|
+
(issueId: string, stateId: string) =>
|
|
333
|
+
Effect.gen(function* () {
|
|
334
|
+
const client = yield* getClient;
|
|
335
|
+
yield* Effect.tryPromise({
|
|
336
|
+
try: () => client.updateIssue(issueId, { stateId }),
|
|
337
|
+
catch: (e) => LinearApiError.make({ message: String(e) }),
|
|
338
|
+
});
|
|
339
|
+
}),
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
const createIssue = Effect.fn("LinearService.createIssue")(
|
|
343
|
+
(input: {
|
|
344
|
+
title: string;
|
|
345
|
+
teamId: string;
|
|
346
|
+
description?: string;
|
|
347
|
+
parentId?: string;
|
|
348
|
+
projectId?: string;
|
|
349
|
+
priority?: number;
|
|
350
|
+
}) =>
|
|
351
|
+
Effect.gen(function* () {
|
|
352
|
+
const client = yield* getClient;
|
|
353
|
+
const payload = yield* Effect.tryPromise({
|
|
354
|
+
try: () =>
|
|
355
|
+
client.createIssue({
|
|
356
|
+
title: input.title,
|
|
357
|
+
teamId: input.teamId,
|
|
358
|
+
description: input.description,
|
|
359
|
+
parentId: input.parentId,
|
|
360
|
+
projectId: input.projectId,
|
|
361
|
+
priority: input.priority,
|
|
362
|
+
}),
|
|
363
|
+
catch: (e) => LinearApiError.make({ message: String(e) }),
|
|
364
|
+
});
|
|
365
|
+
const issueFetch = payload.issue;
|
|
366
|
+
if (issueFetch === undefined) {
|
|
367
|
+
return yield* LinearApiError.make({ message: "Failed to create issue" });
|
|
368
|
+
}
|
|
369
|
+
return yield* Effect.tryPromise({
|
|
370
|
+
try: () => issueFetch,
|
|
371
|
+
catch: (e) => LinearApiError.make({ message: String(e) }),
|
|
372
|
+
});
|
|
373
|
+
}),
|
|
374
|
+
);
|
|
375
|
+
|
|
376
|
+
const createComment = Effect.fn("LinearService.createComment")(
|
|
377
|
+
(issueId: string, body: string) =>
|
|
378
|
+
Effect.gen(function* () {
|
|
379
|
+
const client = yield* getClient;
|
|
380
|
+
const payload = yield* Effect.tryPromise({
|
|
381
|
+
try: () => client.createComment({ issueId: normalizeIssueId(issueId), body }),
|
|
382
|
+
catch: (error) => LinearApiError.make({ message: String(error) }),
|
|
383
|
+
});
|
|
384
|
+
const comment = yield* resolveLinearFetch(payload.comment);
|
|
385
|
+
return comment === undefined
|
|
386
|
+
? yield* LinearApiError.make({ message: "Linear did not return the created comment" })
|
|
387
|
+
: { id: comment.id, url: comment.url };
|
|
388
|
+
}),
|
|
389
|
+
);
|
|
390
|
+
|
|
391
|
+
const rawQuery = Effect.fn("LinearService.rawQuery")(
|
|
392
|
+
(query: string, variables: Readonly<Record<string, unknown>>) =>
|
|
393
|
+
Effect.gen(function* () {
|
|
394
|
+
const client = yield* getClient;
|
|
395
|
+
const response = yield* Effect.tryPromise({
|
|
396
|
+
try: () =>
|
|
397
|
+
client.client.rawRequest<unknown, Record<string, unknown>>(query, variables),
|
|
398
|
+
catch: (error) => LinearApiError.make({ message: String(error) }),
|
|
399
|
+
});
|
|
400
|
+
return response.data;
|
|
401
|
+
}),
|
|
402
|
+
);
|
|
157
403
|
|
|
158
404
|
return LinearService.of({
|
|
159
405
|
getViewer,
|
|
160
406
|
getTeams,
|
|
407
|
+
getProjects,
|
|
161
408
|
getIssues,
|
|
162
409
|
getMyIssues,
|
|
163
410
|
getIssue,
|
|
411
|
+
getIssueDetails,
|
|
164
412
|
updateIssueState,
|
|
165
413
|
createIssue,
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
414
|
+
createComment,
|
|
415
|
+
rawQuery,
|
|
416
|
+
});
|
|
417
|
+
}),
|
|
418
|
+
);
|
|
419
|
+
|
|
420
|
+
static readonly layerTest = (options?: {
|
|
421
|
+
viewer?: User;
|
|
422
|
+
teams?: readonly Team[];
|
|
423
|
+
issues?: readonly Issue[];
|
|
174
424
|
}) =>
|
|
175
425
|
Layer.succeed(LinearService, {
|
|
176
|
-
getViewer:
|
|
177
|
-
|
|
178
|
-
|
|
426
|
+
getViewer:
|
|
427
|
+
options?.viewer !== undefined
|
|
428
|
+
? Effect.succeed(options.viewer)
|
|
429
|
+
: Effect.fail(LinearApiError.make({ message: "No viewer in test" })),
|
|
179
430
|
getTeams: Effect.succeed(options?.teams ?? []),
|
|
431
|
+
getProjects: Effect.succeed([]),
|
|
180
432
|
getIssues: (_filter) => Effect.succeed(options?.issues ?? []),
|
|
181
433
|
getMyIssues: (_filter) => Effect.succeed(options?.issues ?? []),
|
|
182
434
|
getIssue: (id) => {
|
|
183
|
-
const issue = options?.issues?.find((i) => i.id === id ||
|
|
184
|
-
return issue
|
|
435
|
+
const issue = options?.issues?.find((i) => i.id === id || i.identifier === id);
|
|
436
|
+
return issue !== undefined
|
|
185
437
|
? Effect.succeed(issue)
|
|
186
|
-
: Effect.fail(LinearApiError.make({ message: `Issue ${id} not found` }))
|
|
438
|
+
: Effect.fail(LinearApiError.make({ message: `Issue ${id} not found` }));
|
|
439
|
+
},
|
|
440
|
+
getIssueDetails: (id, _options) => {
|
|
441
|
+
const issue = options?.issues?.find(
|
|
442
|
+
(candidate) => candidate.id === id || candidate.identifier === id,
|
|
443
|
+
);
|
|
444
|
+
return issue === undefined
|
|
445
|
+
? Effect.fail(LinearApiError.make({ message: `Issue ${id} not found` }))
|
|
446
|
+
: Effect.succeed({
|
|
447
|
+
id: issue.id,
|
|
448
|
+
identifier: issue.identifier,
|
|
449
|
+
title: issue.title,
|
|
450
|
+
url: issue.url,
|
|
451
|
+
description: issue.description ?? undefined,
|
|
452
|
+
branchName: issue.branchName,
|
|
453
|
+
priority: { value: issue.priority, label: issue.priorityLabel },
|
|
454
|
+
labels: [],
|
|
455
|
+
});
|
|
187
456
|
},
|
|
188
457
|
updateIssueState: (_issueId, _stateId) => Effect.void,
|
|
189
458
|
createIssue: (_input) =>
|
|
190
459
|
Effect.fail(LinearApiError.make({ message: "Not implemented in test" })),
|
|
191
|
-
|
|
460
|
+
createComment: (_issueId, _body) =>
|
|
461
|
+
Effect.fail(LinearApiError.make({ message: "Not implemented in test" })),
|
|
462
|
+
rawQuery: (_query, _variables) =>
|
|
463
|
+
Effect.fail(LinearApiError.make({ message: "Not implemented in test" })),
|
|
464
|
+
});
|
|
192
465
|
}
|
|
466
|
+
|
|
467
|
+
const normalizeIssueId = (input: string): string => {
|
|
468
|
+
const match = input.match(/\/issue\/([A-Za-z]+-\d+)(?:\/|$)/);
|
|
469
|
+
return match?.[1] ?? input;
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
const toIssueReference = (issue: Issue): IssueReference => ({
|
|
473
|
+
id: issue.id,
|
|
474
|
+
identifier: issue.identifier,
|
|
475
|
+
title: issue.title,
|
|
476
|
+
url: issue.url,
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
const resolveLinearFetch = <T>(
|
|
480
|
+
fetch: PromiseLike<T> | undefined,
|
|
481
|
+
): Effect.Effect<T | undefined, LinearApiError> =>
|
|
482
|
+
fetch === undefined
|
|
483
|
+
? Effect.succeed<T | undefined>(undefined)
|
|
484
|
+
: Effect.tryPromise({
|
|
485
|
+
try: () => Promise.resolve(fetch),
|
|
486
|
+
catch: (error) => LinearApiError.make({ message: String(error) }),
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
const loadConnection = <T>(load: () => PromiseLike<{ readonly nodes: ReadonlyArray<T> }>) =>
|
|
490
|
+
Effect.tryPromise({
|
|
491
|
+
try: () => Promise.resolve(load()),
|
|
492
|
+
catch: (error) => LinearApiError.make({ message: String(error) }),
|
|
493
|
+
}).pipe(Effect.map((connection) => connection.nodes));
|
package/src/services/Stdin.ts
CHANGED
|
@@ -1,34 +1,27 @@
|
|
|
1
|
-
import { Context, Effect, Layer } from "effect"
|
|
1
|
+
import { Console, Context, Effect, Layer, Terminal } from "effect";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Simple stdin reading service that works with Bun compiled binaries.
|
|
5
5
|
* Uses Node's readline API which Bun supports.
|
|
6
6
|
*/
|
|
7
|
-
export class StdinService extends Context.
|
|
7
|
+
export class StdinService extends Context.Service<
|
|
8
8
|
StdinService,
|
|
9
9
|
{
|
|
10
|
-
readonly readLine: (prompt: string) => Effect.Effect<string
|
|
10
|
+
readonly readLine: (prompt: string) => Effect.Effect<string, Terminal.QuitError>;
|
|
11
11
|
}
|
|
12
|
-
>() {
|
|
13
|
-
static readonly layer = Layer.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
>()("@cvr/linear/services/Stdin/StdinService") {
|
|
13
|
+
static readonly layer = Layer.effect(
|
|
14
|
+
StdinService,
|
|
15
|
+
Effect.gen(function* () {
|
|
16
|
+
const terminal = yield* Terminal.Terminal;
|
|
17
|
+
return StdinService.of({
|
|
18
|
+
readLine: (prompt) => Console.log(prompt).pipe(Effect.andThen(terminal.readLine)),
|
|
19
|
+
});
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
rl.close()
|
|
25
|
-
resume(Effect.succeed(answer))
|
|
26
|
-
})
|
|
27
|
-
}),
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
static readonly testLayer = (input: string) =>
|
|
23
|
+
static readonly layerTest = (input: string) =>
|
|
31
24
|
Layer.succeed(StdinService, {
|
|
32
25
|
readLine: (_prompt) => Effect.succeed(input),
|
|
33
|
-
})
|
|
26
|
+
});
|
|
34
27
|
}
|