@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/commands/issue.ts
CHANGED
|
@@ -1,330 +1,523 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Console, Effect, Option } from "effect"
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { Argument, Command, Flag, Prompt } from "effect/unstable/cli";
|
|
2
|
+
import { Console, Effect, Option } from "effect";
|
|
3
|
+
import { InvalidInputError, NoIssuesError } from "../lib/errors.js";
|
|
4
|
+
import { encodeJson } from "../lib/json.js";
|
|
5
|
+
import { LinearService, type IssueDetails } from "../services/Linear.js";
|
|
6
|
+
import { ConfigService } from "../services/Config.js";
|
|
7
|
+
|
|
8
|
+
/** Resolve LinearFetch<T> | undefined (LinearFetch is Promise-like lazy loader) */
|
|
9
|
+
const resolveFetch = <T>(fetch: PromiseLike<T> | undefined): Effect.Effect<T | null> =>
|
|
10
|
+
fetch !== undefined
|
|
11
|
+
? Effect.tryPromise(() => Promise.resolve(fetch)).pipe(Effect.orElseSucceed(() => null))
|
|
12
|
+
: Effect.succeed(null);
|
|
5
13
|
|
|
6
14
|
// Options
|
|
7
|
-
const stateOption =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
)
|
|
15
|
+
const stateOption = Flag.string("state").pipe(
|
|
16
|
+
Flag.withAlias("s"),
|
|
17
|
+
Flag.withDescription("Filter by state type (started, unstarted, backlog, etc.)"),
|
|
18
|
+
Flag.optional,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const limitOption = Flag.integer("limit").pipe(
|
|
22
|
+
Flag.withAlias("n"),
|
|
23
|
+
Flag.withDefault(20),
|
|
24
|
+
Flag.withDescription("Number of issues to show"),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const jsonOption = Flag.boolean("json").pipe(
|
|
28
|
+
Flag.withDescription("Emit stable JSON for scripts and agents"),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const commentsOption = Flag.boolean("comments").pipe(
|
|
32
|
+
Flag.withDescription("Include issue comments"),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const childrenOption = Flag.boolean("children").pipe(Flag.withDescription("Include sub-issues"));
|
|
36
|
+
|
|
37
|
+
const relationsOption = Flag.boolean("relations").pipe(
|
|
38
|
+
Flag.withDescription("Include inbound and outbound issue relations"),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const titleOption = Flag.string("title").pipe(
|
|
42
|
+
Flag.withDescription("Issue title; enables non-interactive creation"),
|
|
43
|
+
Flag.optional,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const descriptionOption = Flag.string("description").pipe(
|
|
47
|
+
Flag.withDescription("Issue description in Markdown"),
|
|
48
|
+
Flag.optional,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const teamOption = Flag.string("team").pipe(
|
|
52
|
+
Flag.withDescription("Team key or UUID"),
|
|
53
|
+
Flag.optional,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const parentOption = Flag.string("parent").pipe(
|
|
57
|
+
Flag.withDescription("Parent issue identifier or UUID"),
|
|
58
|
+
Flag.optional,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const projectOption = Flag.string("project").pipe(
|
|
62
|
+
Flag.withDescription("Project name, slug, or UUID"),
|
|
63
|
+
Flag.optional,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const priorityOption = Flag.integer("priority").pipe(
|
|
67
|
+
Flag.withDescription("Priority from 0 (none) to 4 (low)"),
|
|
68
|
+
Flag.optional,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const dryRunOption = Flag.boolean("dry-run").pipe(
|
|
72
|
+
Flag.withDescription("Validate and print the mutation without writing"),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const bodyOption = Flag.string("body").pipe(Flag.withDescription("Comment body in Markdown"));
|
|
24
76
|
|
|
25
77
|
// Args
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
)
|
|
78
|
+
const issueIdsArg = Argument.string("id").pipe(
|
|
79
|
+
Argument.withDescription("Issue ID, URL, or identifier (repeat for bulk reads)"),
|
|
80
|
+
Argument.variadic(),
|
|
81
|
+
);
|
|
30
82
|
|
|
31
83
|
// linear issue list - List issues
|
|
32
84
|
export const issueListCommand = Command.make(
|
|
33
85
|
"list",
|
|
34
|
-
{ state: stateOption,
|
|
35
|
-
({ state,
|
|
86
|
+
{ state: stateOption, limit: limitOption, json: jsonOption },
|
|
87
|
+
({ state, limit, json }) =>
|
|
36
88
|
Effect.gen(function* () {
|
|
37
|
-
const linear = yield* LinearService
|
|
89
|
+
const linear = yield* LinearService;
|
|
38
90
|
|
|
39
|
-
const stateFilter = Option.getOrUndefined(state)
|
|
40
|
-
const issues = yield* linear.getMyIssues({ state: stateFilter })
|
|
91
|
+
const stateFilter = Option.getOrUndefined(state);
|
|
92
|
+
const issues = yield* linear.getMyIssues({ state: stateFilter });
|
|
41
93
|
|
|
42
94
|
if (issues.length === 0) {
|
|
43
|
-
yield* Console.log("No issues found.")
|
|
44
|
-
return
|
|
95
|
+
yield* Console.log(json ? "[]" : "No issues found.");
|
|
96
|
+
return;
|
|
45
97
|
}
|
|
46
98
|
|
|
47
|
-
yield* Console.log("\nYour Issues:\n")
|
|
99
|
+
yield* Console.log("\nYour Issues:\n");
|
|
100
|
+
|
|
101
|
+
const displayed = issues.slice(0, limit);
|
|
102
|
+
|
|
103
|
+
if (json) {
|
|
104
|
+
const values = yield* Effect.forEach(
|
|
105
|
+
displayed,
|
|
106
|
+
(issue) =>
|
|
107
|
+
resolveFetch(issue.state).pipe(
|
|
108
|
+
Effect.map((issueState) => ({
|
|
109
|
+
id: issue.id,
|
|
110
|
+
identifier: issue.identifier,
|
|
111
|
+
title: issue.title,
|
|
112
|
+
url: issue.url,
|
|
113
|
+
branchName: issue.branchName,
|
|
114
|
+
priority: { value: issue.priority, label: getPriorityLabel(issue.priority) },
|
|
115
|
+
state:
|
|
116
|
+
issueState === null
|
|
117
|
+
? undefined
|
|
118
|
+
: { id: issueState.id, name: issueState.name, type: issueState.type },
|
|
119
|
+
})),
|
|
120
|
+
),
|
|
121
|
+
{ concurrency: 4 },
|
|
122
|
+
);
|
|
123
|
+
yield* Console.log(encodeJson(values));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
48
126
|
|
|
49
|
-
const displayed = issues.slice(0, limit)
|
|
50
127
|
for (const issue of displayed) {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const stateName = state?.name ?? "Unknown"
|
|
56
|
-
const priority = issue.priority ?? 0
|
|
57
|
-
const priorityIcon = getPriorityIcon(priority)
|
|
128
|
+
const issueState = yield* resolveFetch(issue.state);
|
|
129
|
+
const stateName = issueState?.name ?? "Unknown";
|
|
130
|
+
const priority = issue.priority ?? 0;
|
|
131
|
+
const priorityIcon = getPriorityIcon(priority);
|
|
58
132
|
|
|
59
133
|
yield* Console.log(
|
|
60
|
-
` ${priorityIcon} ${issue.identifier.padEnd(10)} ${stateName.padEnd(12)} ${truncate(issue.title, 50)}
|
|
61
|
-
)
|
|
134
|
+
` ${priorityIcon} ${issue.identifier.padEnd(10)} ${stateName.padEnd(12)} ${truncate(issue.title, 50)}`,
|
|
135
|
+
);
|
|
62
136
|
}
|
|
63
137
|
|
|
64
138
|
if (issues.length > limit) {
|
|
65
|
-
yield* Console.log(`\n ... and ${issues.length - limit} more`)
|
|
139
|
+
yield* Console.log(`\n ... and ${issues.length - limit} more`);
|
|
66
140
|
}
|
|
67
141
|
|
|
68
|
-
yield* Console.log("")
|
|
69
|
-
})
|
|
70
|
-
)
|
|
142
|
+
yield* Console.log("");
|
|
143
|
+
}),
|
|
144
|
+
);
|
|
71
145
|
|
|
72
146
|
// linear issue view [id] - View issue details
|
|
73
147
|
export const issueViewCommand = Command.make(
|
|
74
148
|
"view",
|
|
75
|
-
{
|
|
76
|
-
|
|
149
|
+
{
|
|
150
|
+
ids: issueIdsArg,
|
|
151
|
+
json: jsonOption,
|
|
152
|
+
comments: commentsOption,
|
|
153
|
+
children: childrenOption,
|
|
154
|
+
relations: relationsOption,
|
|
155
|
+
},
|
|
156
|
+
({ ids, json, comments, children, relations }) =>
|
|
77
157
|
Effect.gen(function* () {
|
|
78
|
-
const linear = yield* LinearService
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
catch: () => null,
|
|
90
|
-
})
|
|
91
|
-
const assignee = yield* Effect.tryPromise({
|
|
92
|
-
try: () => issue.assignee,
|
|
93
|
-
catch: () => null,
|
|
94
|
-
})
|
|
95
|
-
const team = yield* Effect.tryPromise({
|
|
96
|
-
try: () => issue.team,
|
|
97
|
-
catch: () => null,
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
yield* Console.log("")
|
|
101
|
-
yield* Console.log(`${issue.identifier}: ${issue.title}`)
|
|
102
|
-
yield* Console.log(`${"─".repeat(60)}`)
|
|
103
|
-
yield* Console.log(`State: ${state?.name ?? "Unknown"}`)
|
|
104
|
-
yield* Console.log(`Team: ${team?.name ?? "Unknown"}`)
|
|
105
|
-
yield* Console.log(`Priority: ${getPriorityLabel(issue.priority ?? 0)}`)
|
|
106
|
-
yield* Console.log(`Assignee: ${assignee?.name ?? "Unassigned"}`)
|
|
107
|
-
yield* Console.log(`URL: ${issue.url}`)
|
|
108
|
-
|
|
109
|
-
if (issue.description) {
|
|
110
|
-
yield* Console.log(`\nDescription:\n${issue.description}`)
|
|
158
|
+
const linear = yield* LinearService;
|
|
159
|
+
const selectedIds = ids.length === 0 ? [yield* selectIssue] : ids;
|
|
160
|
+
const details = yield* Effect.forEach(
|
|
161
|
+
selectedIds,
|
|
162
|
+
(id) => linear.getIssueDetails(id, { comments, children, relations }),
|
|
163
|
+
{ concurrency: 4 },
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
if (json) {
|
|
167
|
+
yield* Console.log(encodeJson(details));
|
|
168
|
+
return;
|
|
111
169
|
}
|
|
112
170
|
|
|
113
|
-
yield*
|
|
114
|
-
})
|
|
115
|
-
)
|
|
171
|
+
yield* Effect.forEach(details, renderIssueDetails, { discard: true });
|
|
172
|
+
}),
|
|
173
|
+
);
|
|
116
174
|
|
|
117
175
|
// linear issue start [id] - Start working on an issue
|
|
118
|
-
|
|
119
|
-
"
|
|
120
|
-
|
|
121
|
-
|
|
176
|
+
const optionalIssueIdArg = Argument.string("id").pipe(
|
|
177
|
+
Argument.withDescription("Issue ID, URL, or identifier"),
|
|
178
|
+
Argument.optional,
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
export const issueStartCommand = Command.make("start", { id: optionalIssueIdArg }, ({ id }) =>
|
|
182
|
+
Effect.gen(function* () {
|
|
183
|
+
const linear = yield* LinearService;
|
|
184
|
+
|
|
185
|
+
// If no ID provided, prompt for selection
|
|
186
|
+
const issueId = yield* Option.match(id, {
|
|
187
|
+
onNone: () => selectIssue,
|
|
188
|
+
onSome: (selectedId) => Effect.succeed(selectedId),
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const issue = yield* linear.getIssue(issueId);
|
|
192
|
+
const issueTeam = yield* resolveFetch(issue.team);
|
|
193
|
+
|
|
194
|
+
// Get the "Started" state for this team
|
|
195
|
+
const states = yield* Effect.tryPromise({
|
|
196
|
+
try: async () => {
|
|
197
|
+
if (issueTeam === null) return [];
|
|
198
|
+
const connection = await issueTeam.states();
|
|
199
|
+
return connection.nodes;
|
|
200
|
+
},
|
|
201
|
+
catch: () => [],
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
const startedState = states.find(
|
|
205
|
+
(s) => s.type === "started" || s.name.toLowerCase() === "in progress",
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
if (startedState !== undefined) {
|
|
209
|
+
yield* linear.updateIssueState(issue.id, startedState.id);
|
|
210
|
+
yield* Console.log(`\nStarted: ${issue.identifier} - ${issue.title}`);
|
|
211
|
+
yield* Console.log(`State changed to: ${startedState.name}`);
|
|
212
|
+
} else {
|
|
213
|
+
yield* Console.log(`\nCould not find a "started" state for this issue's team.`);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Show branch name for git
|
|
217
|
+
if (issue.branchName !== undefined && issue.branchName !== null) {
|
|
218
|
+
yield* Console.log(`\nBranch name: ${issue.branchName}`);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
yield* Console.log("");
|
|
222
|
+
}),
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
// linear issue create - Create a new issue
|
|
226
|
+
export const issueCreateCommand = Command.make(
|
|
227
|
+
"create",
|
|
228
|
+
{
|
|
229
|
+
title: titleOption,
|
|
230
|
+
description: descriptionOption,
|
|
231
|
+
team: teamOption,
|
|
232
|
+
parent: parentOption,
|
|
233
|
+
project: projectOption,
|
|
234
|
+
priority: priorityOption,
|
|
235
|
+
dryRun: dryRunOption,
|
|
236
|
+
json: jsonOption,
|
|
237
|
+
},
|
|
238
|
+
({ title, description, team, parent, project, priority, dryRun, json }) =>
|
|
122
239
|
Effect.gen(function* () {
|
|
123
|
-
const linear = yield* LinearService
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
const issue = yield* linear.getIssue(issueId)
|
|
132
|
-
const team = yield* Effect.tryPromise({
|
|
133
|
-
try: () => issue.team,
|
|
134
|
-
catch: () => null,
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
// Get the "Started" state for this team
|
|
138
|
-
const states = yield* Effect.tryPromise({
|
|
139
|
-
try: async () => {
|
|
140
|
-
if (!team) return []
|
|
141
|
-
const connection = await team.states()
|
|
142
|
-
return connection.nodes
|
|
143
|
-
},
|
|
144
|
-
catch: () => [],
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
const startedState = states.find(
|
|
148
|
-
(s) => s.type === "started" || s.name.toLowerCase() === "in progress"
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
if (startedState) {
|
|
152
|
-
yield* linear.updateIssueState(issue.id, startedState.id)
|
|
153
|
-
yield* Console.log(`\nStarted: ${issue.identifier} - ${issue.title}`)
|
|
154
|
-
yield* Console.log(`State changed to: ${startedState.name}`)
|
|
155
|
-
} else {
|
|
156
|
-
yield* Console.log(`\nCould not find a "started" state for this issue's team.`)
|
|
157
|
-
}
|
|
240
|
+
const linear = yield* LinearService;
|
|
241
|
+
const config = yield* ConfigService;
|
|
242
|
+
const linearConfig = yield* config.getConfig;
|
|
243
|
+
|
|
244
|
+
// Get teams for selection
|
|
245
|
+
const teams = yield* linear.getTeams;
|
|
158
246
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
247
|
+
if (teams.length === 0) {
|
|
248
|
+
yield* Console.error("No teams found. Cannot create issue.");
|
|
249
|
+
return;
|
|
162
250
|
}
|
|
163
251
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
)
|
|
252
|
+
const isInteractive = Option.isNone(title);
|
|
253
|
+
const requestedTeam = Option.getOrUndefined(team) ?? linearConfig.teamId;
|
|
254
|
+
const teamId = yield* resolveTeamId(teams, requestedTeam, isInteractive);
|
|
255
|
+
const issueTitle = yield* Option.match(title, {
|
|
256
|
+
onNone: () => Prompt.text({ message: "Issue title" }),
|
|
257
|
+
onSome: Effect.succeed,
|
|
258
|
+
});
|
|
259
|
+
const issueDescription = yield* Option.match(description, {
|
|
260
|
+
onNone: () =>
|
|
261
|
+
isInteractive
|
|
262
|
+
? Prompt.text({
|
|
263
|
+
message: "Description (optional, press Enter to skip)",
|
|
264
|
+
default: "",
|
|
265
|
+
})
|
|
266
|
+
: Effect.succeed(""),
|
|
267
|
+
onSome: Effect.succeed,
|
|
268
|
+
});
|
|
269
|
+
const priorityValue = Option.getOrUndefined(priority);
|
|
270
|
+
if (priorityValue !== undefined && (priorityValue < 0 || priorityValue > 4)) {
|
|
271
|
+
return yield* InvalidInputError.make({ message: "--priority must be between 0 and 4" });
|
|
272
|
+
}
|
|
167
273
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
274
|
+
const projectSelector = Option.getOrUndefined(project);
|
|
275
|
+
const projectId =
|
|
276
|
+
projectSelector === undefined
|
|
277
|
+
? undefined
|
|
278
|
+
: yield* resolveProjectId(yield* linear.getProjects, projectSelector);
|
|
279
|
+
const input = {
|
|
280
|
+
title: issueTitle,
|
|
281
|
+
teamId,
|
|
282
|
+
description: issueDescription.length === 0 ? undefined : issueDescription,
|
|
283
|
+
parentId: Option.getOrUndefined(parent),
|
|
284
|
+
projectId,
|
|
285
|
+
priority: priorityValue,
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
if (dryRun) {
|
|
289
|
+
yield* Console.log(encodeJson({ dryRun: true, operation: "issue.create", input }));
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
174
292
|
|
|
175
|
-
|
|
176
|
-
|
|
293
|
+
// Create the issue
|
|
294
|
+
const created = yield* linear.createIssue(input);
|
|
177
295
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
296
|
+
if (json) {
|
|
297
|
+
yield* Console.log(encodeJson(toCreatedIssue(created)));
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
182
300
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
301
|
+
yield* Console.log(`\nCreated: ${created.identifier} - ${created.title}`);
|
|
302
|
+
yield* Console.log(`URL: ${created.url}`);
|
|
303
|
+
yield* Console.log("");
|
|
304
|
+
}),
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
export const issueCommentCommand = Command.make(
|
|
308
|
+
"comment",
|
|
309
|
+
{
|
|
310
|
+
id: Argument.string("id").pipe(Argument.withDescription("Issue ID, URL, or identifier")),
|
|
311
|
+
body: bodyOption,
|
|
312
|
+
dryRun: dryRunOption,
|
|
313
|
+
json: jsonOption,
|
|
314
|
+
},
|
|
315
|
+
({ id, body, dryRun, json }) =>
|
|
316
|
+
Effect.gen(function* () {
|
|
317
|
+
if (dryRun) {
|
|
318
|
+
yield* Console.log(
|
|
319
|
+
encodeJson({ dryRun: true, operation: "issue.comment", input: { id, body } }),
|
|
320
|
+
);
|
|
321
|
+
return;
|
|
195
322
|
}
|
|
196
|
-
} else if (teams.length === 1) {
|
|
197
|
-
teamId = teams[0].id
|
|
198
|
-
yield* Console.log(`Using team: ${teams[0].name}`)
|
|
199
|
-
} else {
|
|
200
|
-
teamId = yield* selectTeam(teams)
|
|
201
|
-
}
|
|
202
323
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
// Create the issue
|
|
215
|
-
const issue = yield* linear.createIssue({
|
|
216
|
-
title,
|
|
217
|
-
teamId,
|
|
218
|
-
description: description || undefined,
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
yield* Console.log(`\nCreated: ${issue.identifier} - ${issue.title}`)
|
|
222
|
-
yield* Console.log(`URL: ${issue.url}`)
|
|
223
|
-
yield* Console.log("")
|
|
224
|
-
})
|
|
225
|
-
)
|
|
324
|
+
const linear = yield* LinearService;
|
|
325
|
+
const comment = yield* linear.createComment(id, body);
|
|
326
|
+
if (json) {
|
|
327
|
+
yield* Console.log(encodeJson(comment));
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
yield* Console.log(`Comment created: ${comment.url}`);
|
|
331
|
+
}),
|
|
332
|
+
);
|
|
226
333
|
|
|
227
334
|
// Combined issue command with subcommands
|
|
228
335
|
export const issue = Command.make("issue", {}, () =>
|
|
229
|
-
Console.log("Use 'linear issue list' to list issues. See --help for more.")
|
|
336
|
+
Console.log("Use 'linear issue list' to list issues. See --help for more."),
|
|
230
337
|
).pipe(
|
|
231
338
|
Command.withSubcommands([
|
|
232
339
|
issueListCommand,
|
|
233
340
|
issueViewCommand,
|
|
234
341
|
issueStartCommand,
|
|
235
342
|
issueCreateCommand,
|
|
236
|
-
|
|
237
|
-
)
|
|
343
|
+
issueCommentCommand,
|
|
344
|
+
]),
|
|
345
|
+
);
|
|
238
346
|
|
|
239
347
|
// Helper functions
|
|
240
348
|
|
|
241
|
-
|
|
242
|
-
linear
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
349
|
+
const selectIssue = Effect.gen(function* () {
|
|
350
|
+
const linear = yield* LinearService;
|
|
351
|
+
const issues = yield* linear.getMyIssues({ state: "started" });
|
|
352
|
+
const allIssues = issues.length > 0 ? issues : yield* linear.getMyIssues({ state: "unstarted" });
|
|
353
|
+
|
|
354
|
+
if (allIssues.length === 0) {
|
|
355
|
+
return yield* NoIssuesError.default;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Build choices with state info
|
|
359
|
+
const choices = yield* Effect.all(
|
|
360
|
+
allIssues.slice(0, 20).map((candidate) =>
|
|
361
|
+
Effect.gen(function* () {
|
|
362
|
+
const issueState = yield* resolveFetch(candidate.state);
|
|
363
|
+
return {
|
|
364
|
+
title: `${candidate.identifier}: ${truncate(candidate.title, 40)}`,
|
|
365
|
+
value: candidate.identifier,
|
|
366
|
+
description: issueState?.name ?? "Unknown state",
|
|
367
|
+
};
|
|
368
|
+
}),
|
|
369
|
+
),
|
|
370
|
+
);
|
|
371
|
+
|
|
372
|
+
const selected = yield* Prompt.select({
|
|
373
|
+
message: "Select an issue",
|
|
374
|
+
choices,
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
return selected;
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
const renderIssueDetails = Effect.fn("IssueCommand.renderDetails")(function* (
|
|
381
|
+
details: IssueDetails,
|
|
382
|
+
) {
|
|
383
|
+
yield* Console.log("");
|
|
384
|
+
yield* Console.log(`${details.identifier}: ${details.title}`);
|
|
385
|
+
yield* Console.log(`${"─".repeat(60)}`);
|
|
386
|
+
yield* Console.log(`State: ${details.state?.name ?? "Unknown"}`);
|
|
387
|
+
yield* Console.log(`Team: ${details.team?.name ?? "Unknown"}`);
|
|
388
|
+
yield* Console.log(`Priority: ${details.priority.label}`);
|
|
389
|
+
yield* Console.log(`Assignee: ${details.assignee?.name ?? "Unassigned"}`);
|
|
390
|
+
yield* Console.log(`Project: ${details.project?.name ?? "None"}`);
|
|
391
|
+
yield* Console.log(`Parent: ${details.parent?.identifier ?? "None"}`);
|
|
392
|
+
yield* Console.log(`Branch: ${details.branchName}`);
|
|
393
|
+
yield* Console.log(`URL: ${details.url}`);
|
|
394
|
+
|
|
395
|
+
if (details.description !== undefined) {
|
|
396
|
+
yield* Console.log(`\nDescription:\n${details.description}`);
|
|
397
|
+
}
|
|
398
|
+
if (details.children !== undefined) {
|
|
399
|
+
yield* Console.log(`\nSub-issues (${details.children.length}):`);
|
|
400
|
+
for (const child of details.children) {
|
|
401
|
+
yield* Console.log(` ${child.identifier} ${child.title}`);
|
|
254
402
|
}
|
|
403
|
+
}
|
|
404
|
+
if (details.comments !== undefined) {
|
|
405
|
+
yield* Console.log(`\nComments (${details.comments.length}):`);
|
|
406
|
+
for (const comment of details.comments) {
|
|
407
|
+
yield* Console.log(
|
|
408
|
+
` ${comment.author?.name ?? "Unknown"} · ${comment.createdAt}\n ${comment.body}`,
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
if (details.relations !== undefined) {
|
|
413
|
+
yield* Console.log(`\nRelations (${details.relations.length}):`);
|
|
414
|
+
for (const relation of details.relations) {
|
|
415
|
+
yield* Console.log(
|
|
416
|
+
` ${relation.direction} ${relation.type} ${relation.issue.identifier} ${relation.issue.title}`,
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
255
420
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
allIssues.slice(0, 20).map((issue) =>
|
|
259
|
-
Effect.gen(function* () {
|
|
260
|
-
const state = yield* Effect.tryPromise({
|
|
261
|
-
try: () => issue.state,
|
|
262
|
-
catch: () => null,
|
|
263
|
-
})
|
|
264
|
-
return {
|
|
265
|
-
title: `${issue.identifier}: ${truncate(issue.title, 40)}`,
|
|
266
|
-
value: issue.identifier,
|
|
267
|
-
description: state?.name ?? "Unknown state",
|
|
268
|
-
}
|
|
269
|
-
})
|
|
270
|
-
)
|
|
271
|
-
)
|
|
272
|
-
|
|
273
|
-
const selected = yield* Prompt.select({
|
|
274
|
-
message: "Select an issue",
|
|
275
|
-
choices,
|
|
276
|
-
})
|
|
277
|
-
|
|
278
|
-
return selected
|
|
279
|
-
})
|
|
280
|
-
}
|
|
421
|
+
yield* Console.log("");
|
|
422
|
+
});
|
|
281
423
|
|
|
282
|
-
function selectTeam(
|
|
283
|
-
teams: readonly { id: string; key: string; name: string }[]
|
|
284
|
-
): Effect.Effect<string, any, any> {
|
|
424
|
+
function selectTeam(teams: readonly { id: string; key: string; name: string }[]) {
|
|
285
425
|
return Prompt.select({
|
|
286
426
|
message: "Select a team",
|
|
287
427
|
choices: teams.map((team) => ({
|
|
288
428
|
title: `${team.key}: ${team.name}`,
|
|
289
429
|
value: team.id,
|
|
290
430
|
})),
|
|
291
|
-
})
|
|
431
|
+
});
|
|
292
432
|
}
|
|
293
433
|
|
|
434
|
+
const resolveTeamId = Effect.fn("IssueCommand.resolveTeamId")(function* (
|
|
435
|
+
teams: readonly { id: string; key: string; name: string }[],
|
|
436
|
+
selector: string | undefined,
|
|
437
|
+
interactive: boolean,
|
|
438
|
+
) {
|
|
439
|
+
if (selector !== undefined) {
|
|
440
|
+
const normalized = selector.toLowerCase();
|
|
441
|
+
const selected = teams.find(
|
|
442
|
+
(team) => team.id === selector || team.key.toLowerCase() === normalized,
|
|
443
|
+
);
|
|
444
|
+
return selected === undefined
|
|
445
|
+
? yield* InvalidInputError.make({ message: `Unknown team: ${selector}` })
|
|
446
|
+
: selected.id;
|
|
447
|
+
}
|
|
448
|
+
if (teams.length === 1) {
|
|
449
|
+
const [team] = teams;
|
|
450
|
+
return team === undefined
|
|
451
|
+
? yield* InvalidInputError.make({ message: "No team available" })
|
|
452
|
+
: team.id;
|
|
453
|
+
}
|
|
454
|
+
return interactive
|
|
455
|
+
? yield* selectTeam(teams)
|
|
456
|
+
: yield* InvalidInputError.make({ message: "--team is required when multiple teams exist" });
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
const resolveProjectId = Effect.fn("IssueCommand.resolveProjectId")(function* (
|
|
460
|
+
projects: readonly { id: string; name: string; slugId: string }[],
|
|
461
|
+
selector: string,
|
|
462
|
+
) {
|
|
463
|
+
const normalized = selector.toLowerCase();
|
|
464
|
+
const selected = projects.find(
|
|
465
|
+
(project) =>
|
|
466
|
+
project.id === selector ||
|
|
467
|
+
project.name.toLowerCase() === normalized ||
|
|
468
|
+
project.slugId.toLowerCase() === normalized,
|
|
469
|
+
);
|
|
470
|
+
return selected === undefined
|
|
471
|
+
? yield* InvalidInputError.make({ message: `Unknown project: ${selector}` })
|
|
472
|
+
: selected.id;
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
const toCreatedIssue = (created: {
|
|
476
|
+
id: string;
|
|
477
|
+
identifier: string;
|
|
478
|
+
title: string;
|
|
479
|
+
url: string;
|
|
480
|
+
}) => ({
|
|
481
|
+
id: created.id,
|
|
482
|
+
identifier: created.identifier,
|
|
483
|
+
title: created.title,
|
|
484
|
+
url: created.url,
|
|
485
|
+
});
|
|
486
|
+
|
|
294
487
|
function truncate(str: string, len: number): string {
|
|
295
|
-
return str.length > len ? str.slice(0, len - 1) + "…" : str
|
|
488
|
+
return str.length > len ? str.slice(0, len - 1) + "…" : str;
|
|
296
489
|
}
|
|
297
490
|
|
|
298
491
|
function getPriorityIcon(priority: number): string {
|
|
299
492
|
switch (priority) {
|
|
300
493
|
case 0:
|
|
301
|
-
return "○" // No priority
|
|
494
|
+
return "○"; // No priority
|
|
302
495
|
case 1:
|
|
303
|
-
return "⬆" // Urgent
|
|
496
|
+
return "⬆"; // Urgent
|
|
304
497
|
case 2:
|
|
305
|
-
return "↑" // High
|
|
498
|
+
return "↑"; // High
|
|
306
499
|
case 3:
|
|
307
|
-
return "─" // Medium
|
|
500
|
+
return "─"; // Medium
|
|
308
501
|
case 4:
|
|
309
|
-
return "↓" // Low
|
|
502
|
+
return "↓"; // Low
|
|
310
503
|
default:
|
|
311
|
-
return "○"
|
|
504
|
+
return "○";
|
|
312
505
|
}
|
|
313
506
|
}
|
|
314
507
|
|
|
315
508
|
function getPriorityLabel(priority: number): string {
|
|
316
509
|
switch (priority) {
|
|
317
510
|
case 0:
|
|
318
|
-
return "No priority"
|
|
511
|
+
return "No priority";
|
|
319
512
|
case 1:
|
|
320
|
-
return "Urgent"
|
|
513
|
+
return "Urgent";
|
|
321
514
|
case 2:
|
|
322
|
-
return "High"
|
|
515
|
+
return "High";
|
|
323
516
|
case 3:
|
|
324
|
-
return "Medium"
|
|
517
|
+
return "Medium";
|
|
325
518
|
case 4:
|
|
326
|
-
return "Low"
|
|
519
|
+
return "Low";
|
|
327
520
|
default:
|
|
328
|
-
return "Unknown"
|
|
521
|
+
return "Unknown";
|
|
329
522
|
}
|
|
330
523
|
}
|