@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.
@@ -1,330 +1,306 @@
1
- import { Args, Command, Options, Prompt } from "@effect/cli"
2
- import { Console, Effect, Option } from "effect"
3
- import { LinearService } from "../services/Linear.js"
4
- import { ConfigService } from "../services/Config.js"
1
+ import { Args, Command, Options, Prompt } from "@effect/cli";
2
+ import type { Terminal } from "@effect/platform";
3
+ import type { Context, Types } from "effect";
4
+ import { Console, Effect, Option } from "effect";
5
+ import { NoIssuesError, type LinearApiError, type TokenNotFoundError } from "../lib/errors.js";
6
+ import { LinearService } from "../services/Linear.js";
7
+ import { ConfigService } from "../services/Config.js";
8
+
9
+ /** Resolve LinearFetch<T> | undefined (LinearFetch is Promise-like lazy loader) */
10
+ const resolveFetch = <T>(fetch: PromiseLike<T> | undefined): Effect.Effect<T | null> =>
11
+ fetch
12
+ ? Effect.tryPromise(() => Promise.resolve(fetch)).pipe(Effect.orElseSucceed(() => null))
13
+ : Effect.succeed(null);
5
14
 
6
15
  // Options
7
16
  const stateOption = Options.text("state").pipe(
8
17
  Options.withAlias("s"),
9
18
  Options.withDescription("Filter by state type (started, unstarted, backlog, etc.)"),
10
- Options.optional
11
- )
12
-
13
- const teamOption = Options.text("team").pipe(
14
- Options.withAlias("t"),
15
- Options.withDescription("Filter by team key or ID"),
16
- Options.optional
17
- )
19
+ Options.optional,
20
+ );
18
21
 
19
22
  const limitOption = Options.integer("limit").pipe(
20
23
  Options.withAlias("n"),
21
24
  Options.withDefault(20),
22
- Options.withDescription("Number of issues to show")
23
- )
25
+ Options.withDescription("Number of issues to show"),
26
+ );
24
27
 
25
28
  // Args
26
29
  const issueIdArg = Args.text({ name: "id" }).pipe(
27
30
  Args.withDescription("Issue ID or identifier (e.g., ABC-123)"),
28
- Args.optional
29
- )
31
+ Args.optional,
32
+ );
30
33
 
31
34
  // linear issue list - List issues
32
35
  export const issueListCommand = Command.make(
33
36
  "list",
34
- { state: stateOption, team: teamOption, limit: limitOption },
35
- ({ state, team, limit }) =>
37
+ { state: stateOption, limit: limitOption },
38
+ ({ state, limit }) =>
36
39
  Effect.gen(function* () {
37
- const linear = yield* LinearService
40
+ const linear = yield* LinearService;
38
41
 
39
- const stateFilter = Option.getOrUndefined(state) as any
40
- const issues = yield* linear.getMyIssues({ state: stateFilter })
42
+ const stateFilter = Option.getOrUndefined(state);
43
+ const issues = yield* linear.getMyIssues({ state: stateFilter });
41
44
 
42
45
  if (issues.length === 0) {
43
- yield* Console.log("No issues found.")
44
- return
46
+ yield* Console.log("No issues found.");
47
+ return;
45
48
  }
46
49
 
47
- yield* Console.log("\nYour Issues:\n")
50
+ yield* Console.log("\nYour Issues:\n");
48
51
 
49
- const displayed = issues.slice(0, limit)
52
+ const displayed = issues.slice(0, limit);
50
53
  for (const issue of displayed) {
51
- const state = yield* Effect.tryPromise({
52
- try: () => issue.state,
53
- catch: () => null,
54
- })
55
- const stateName = state?.name ?? "Unknown"
56
- const priority = issue.priority ?? 0
57
- const priorityIcon = getPriorityIcon(priority)
54
+ const issueState = yield* resolveFetch(issue.state);
55
+ const stateName = issueState?.name ?? "Unknown";
56
+ const priority = issue.priority ?? 0;
57
+ const priorityIcon = getPriorityIcon(priority);
58
58
 
59
59
  yield* Console.log(
60
- ` ${priorityIcon} ${issue.identifier.padEnd(10)} ${stateName.padEnd(12)} ${truncate(issue.title, 50)}`
61
- )
60
+ ` ${priorityIcon} ${issue.identifier.padEnd(10)} ${stateName.padEnd(12)} ${truncate(issue.title, 50)}`,
61
+ );
62
62
  }
63
63
 
64
64
  if (issues.length > limit) {
65
- yield* Console.log(`\n ... and ${issues.length - limit} more`)
65
+ yield* Console.log(`\n ... and ${issues.length - limit} more`);
66
66
  }
67
67
 
68
- yield* Console.log("")
69
- })
70
- )
68
+ yield* Console.log("");
69
+ }),
70
+ );
71
71
 
72
72
  // linear issue view [id] - View issue details
73
- export const issueViewCommand = Command.make(
74
- "view",
75
- { id: issueIdArg },
76
- ({ id }) =>
77
- Effect.gen(function* () {
78
- const linear = yield* LinearService
79
-
80
- // If no ID provided, prompt for selection
81
- const issueId = yield* Option.match(id, {
82
- onNone: () => selectIssue(linear),
83
- onSome: (id) => Effect.succeed(id),
84
- })
85
-
86
- const issue = yield* linear.getIssue(issueId)
87
- const state = yield* Effect.tryPromise({
88
- try: () => issue.state,
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}`)
111
- }
73
+ export const issueViewCommand = Command.make("view", { id: issueIdArg }, ({ id }) =>
74
+ Effect.gen(function* () {
75
+ const linear = yield* LinearService;
76
+
77
+ // If no ID provided, prompt for selection
78
+ const issueId = yield* Option.match(id, {
79
+ onNone: () => selectIssue(linear),
80
+ onSome: (id) => Effect.succeed(id),
81
+ });
82
+
83
+ const issue = yield* linear.getIssue(issueId);
84
+ const issueState = yield* resolveFetch(issue.state);
85
+ const assignee = yield* resolveFetch(issue.assignee);
86
+ const issueTeam = yield* resolveFetch(issue.team);
87
+
88
+ yield* Console.log("");
89
+ yield* Console.log(`${issue.identifier}: ${issue.title}`);
90
+ yield* Console.log(`${"─".repeat(60)}`);
91
+ yield* Console.log(`State: ${issueState?.name ?? "Unknown"}`);
92
+ yield* Console.log(`Team: ${issueTeam?.name ?? "Unknown"}`);
93
+ yield* Console.log(`Priority: ${getPriorityLabel(issue.priority ?? 0)}`);
94
+ yield* Console.log(`Assignee: ${assignee?.name ?? "Unassigned"}`);
95
+ yield* Console.log(`URL: ${issue.url}`);
96
+
97
+ if (issue.description) {
98
+ yield* Console.log(`\nDescription:\n${issue.description}`);
99
+ }
112
100
 
113
- yield* Console.log("")
114
- })
115
- )
101
+ yield* Console.log("");
102
+ }),
103
+ );
116
104
 
117
105
  // linear issue start [id] - Start working on an issue
118
- export const issueStartCommand = Command.make(
119
- "start",
120
- { id: issueIdArg },
121
- ({ id }) =>
122
- Effect.gen(function* () {
123
- const linear = yield* LinearService
124
-
125
- // If no ID provided, prompt for selection
126
- const issueId = yield* Option.match(id, {
127
- onNone: () => selectIssue(linear),
128
- onSome: (id) => Effect.succeed(id),
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
- }
106
+ export const issueStartCommand = Command.make("start", { id: issueIdArg }, ({ id }) =>
107
+ Effect.gen(function* () {
108
+ const linear = yield* LinearService;
109
+
110
+ // If no ID provided, prompt for selection
111
+ const issueId = yield* Option.match(id, {
112
+ onNone: () => selectIssue(linear),
113
+ onSome: (id) => Effect.succeed(id),
114
+ });
115
+
116
+ const issue = yield* linear.getIssue(issueId);
117
+ const issueTeam = yield* resolveFetch(issue.team);
118
+
119
+ // Get the "Started" state for this team
120
+ const states = yield* Effect.tryPromise({
121
+ try: async () => {
122
+ if (!issueTeam) return [];
123
+ const connection = await issueTeam.states();
124
+ return connection.nodes;
125
+ },
126
+ catch: () => [],
127
+ });
128
+
129
+ const startedState = states.find(
130
+ (s) => s.type === "started" || s.name.toLowerCase() === "in progress",
131
+ );
132
+
133
+ if (startedState) {
134
+ yield* linear.updateIssueState(issue.id, startedState.id);
135
+ yield* Console.log(`\nStarted: ${issue.identifier} - ${issue.title}`);
136
+ yield* Console.log(`State changed to: ${startedState.name}`);
137
+ } else {
138
+ yield* Console.log(`\nCould not find a "started" state for this issue's team.`);
139
+ }
158
140
 
159
- // Show branch name for git
160
- if (issue.branchName) {
161
- yield* Console.log(`\nBranch name: ${issue.branchName}`)
162
- }
141
+ // Show branch name for git
142
+ if (issue.branchName) {
143
+ yield* Console.log(`\nBranch name: ${issue.branchName}`);
144
+ }
163
145
 
164
- yield* Console.log("")
165
- })
166
- )
146
+ yield* Console.log("");
147
+ }),
148
+ );
167
149
 
168
150
  // linear issue create - Create a new issue
169
151
  export const issueCreateCommand = Command.make("create", {}, () =>
170
152
  Effect.gen(function* () {
171
- const linear = yield* LinearService
172
- const config = yield* ConfigService
173
- const linearConfig = yield* config.getConfig
153
+ const linear = yield* LinearService;
154
+ const config = yield* ConfigService;
155
+ const linearConfig = yield* config.getConfig;
174
156
 
175
157
  // Get teams for selection
176
- const teams = yield* linear.getTeams
158
+ const teams = yield* linear.getTeams;
177
159
 
178
160
  if (teams.length === 0) {
179
- yield* Console.error("No teams found. Cannot create issue.")
180
- return
161
+ yield* Console.error("No teams found. Cannot create issue.");
162
+ return;
181
163
  }
182
164
 
183
165
  // Select team (or use default from config)
184
- let teamId: string
166
+ let teamId: string;
185
167
 
186
168
  if (linearConfig.teamId) {
187
- const team = teams.find(
188
- (t) => t.id === linearConfig.teamId || t.key === linearConfig.teamId
189
- )
169
+ const team = teams.find((t) => t.id === linearConfig.teamId || t.key === linearConfig.teamId);
190
170
  if (team) {
191
- teamId = team.id
192
- yield* Console.log(`Using team from config: ${team.name}`)
171
+ teamId = team.id;
172
+ yield* Console.log(`Using team from config: ${team.name}`);
193
173
  } else {
194
- teamId = yield* selectTeam(teams)
174
+ teamId = yield* selectTeam(teams);
195
175
  }
196
176
  } else if (teams.length === 1) {
197
- teamId = teams[0].id
198
- yield* Console.log(`Using team: ${teams[0].name}`)
177
+ teamId = teams[0].id;
178
+ yield* Console.log(`Using team: ${teams[0].name}`);
199
179
  } else {
200
- teamId = yield* selectTeam(teams)
180
+ teamId = yield* selectTeam(teams);
201
181
  }
202
182
 
203
183
  // Prompt for title
204
184
  const title = yield* Prompt.text({
205
185
  message: "Issue title",
206
- })
186
+ });
207
187
 
208
188
  // Prompt for description (optional)
209
189
  const description = yield* Prompt.text({
210
190
  message: "Description (optional, press Enter to skip)",
211
191
  default: "",
212
- })
192
+ });
213
193
 
214
194
  // Create the issue
215
195
  const issue = yield* linear.createIssue({
216
196
  title,
217
197
  teamId,
218
198
  description: description || undefined,
219
- })
199
+ });
220
200
 
221
- yield* Console.log(`\nCreated: ${issue.identifier} - ${issue.title}`)
222
- yield* Console.log(`URL: ${issue.url}`)
223
- yield* Console.log("")
224
- })
225
- )
201
+ yield* Console.log(`\nCreated: ${issue.identifier} - ${issue.title}`);
202
+ yield* Console.log(`URL: ${issue.url}`);
203
+ yield* Console.log("");
204
+ }),
205
+ );
226
206
 
227
207
  // Combined issue command with subcommands
228
208
  export const issue = Command.make("issue", {}, () =>
229
- Console.log("Use 'linear issue list' to list issues. See --help for more.")
209
+ Console.log("Use 'linear issue list' to list issues. See --help for more."),
230
210
  ).pipe(
231
211
  Command.withSubcommands([
232
212
  issueListCommand,
233
213
  issueViewCommand,
234
214
  issueStartCommand,
235
215
  issueCreateCommand,
236
- ])
237
- )
216
+ ]),
217
+ );
238
218
 
239
219
  // Helper functions
240
220
 
241
221
  function selectIssue(
242
- linear: Context.Tag.Service<typeof LinearService>
243
- ): Effect.Effect<string, any, any> {
222
+ linear: Context.Tag.Service<typeof LinearService>,
223
+ ): Effect.Effect<
224
+ string,
225
+ LinearApiError | TokenNotFoundError | NoIssuesError | Types.NoInfer<Terminal.QuitException>,
226
+ Terminal.Terminal
227
+ > {
244
228
  return Effect.gen(function* () {
245
- const issues = yield* linear.getMyIssues({ state: "started" })
229
+ const issues = yield* linear.getMyIssues({ state: "started" });
246
230
  const allIssues =
247
- issues.length > 0
248
- ? issues
249
- : yield* linear.getMyIssues({ state: "unstarted" })
231
+ issues.length > 0 ? issues : yield* linear.getMyIssues({ state: "unstarted" });
250
232
 
251
233
  if (allIssues.length === 0) {
252
- yield* Console.error("No issues found to select from.")
253
- return yield* Effect.die("No issues")
234
+ return yield* NoIssuesError.default;
254
235
  }
255
236
 
256
237
  // Build choices with state info
257
238
  const choices = yield* Effect.all(
258
239
  allIssues.slice(0, 20).map((issue) =>
259
240
  Effect.gen(function* () {
260
- const state = yield* Effect.tryPromise({
261
- try: () => issue.state,
262
- catch: () => null,
263
- })
241
+ const issueState = yield* resolveFetch(issue.state);
264
242
  return {
265
243
  title: `${issue.identifier}: ${truncate(issue.title, 40)}`,
266
244
  value: issue.identifier,
267
- description: state?.name ?? "Unknown state",
268
- }
269
- })
270
- )
271
- )
245
+ description: issueState?.name ?? "Unknown state",
246
+ };
247
+ }),
248
+ ),
249
+ );
272
250
 
273
251
  const selected = yield* Prompt.select({
274
252
  message: "Select an issue",
275
253
  choices,
276
- })
254
+ });
277
255
 
278
- return selected
279
- })
256
+ return selected;
257
+ });
280
258
  }
281
259
 
282
- function selectTeam(
283
- teams: readonly { id: string; key: string; name: string }[]
284
- ): Effect.Effect<string, any, any> {
260
+ function selectTeam(teams: readonly { id: string; key: string; name: string }[]) {
285
261
  return Prompt.select({
286
262
  message: "Select a team",
287
263
  choices: teams.map((team) => ({
288
264
  title: `${team.key}: ${team.name}`,
289
265
  value: team.id,
290
266
  })),
291
- })
267
+ });
292
268
  }
293
269
 
294
270
  function truncate(str: string, len: number): string {
295
- return str.length > len ? str.slice(0, len - 1) + "…" : str
271
+ return str.length > len ? str.slice(0, len - 1) + "…" : str;
296
272
  }
297
273
 
298
274
  function getPriorityIcon(priority: number): string {
299
275
  switch (priority) {
300
276
  case 0:
301
- return "○" // No priority
277
+ return "○"; // No priority
302
278
  case 1:
303
- return "⬆" // Urgent
279
+ return "⬆"; // Urgent
304
280
  case 2:
305
- return "↑" // High
281
+ return "↑"; // High
306
282
  case 3:
307
- return "─" // Medium
283
+ return "─"; // Medium
308
284
  case 4:
309
- return "↓" // Low
285
+ return "↓"; // Low
310
286
  default:
311
- return "○"
287
+ return "○";
312
288
  }
313
289
  }
314
290
 
315
291
  function getPriorityLabel(priority: number): string {
316
292
  switch (priority) {
317
293
  case 0:
318
- return "No priority"
294
+ return "No priority";
319
295
  case 1:
320
- return "Urgent"
296
+ return "Urgent";
321
297
  case 2:
322
- return "High"
298
+ return "High";
323
299
  case 3:
324
- return "Medium"
300
+ return "Medium";
325
301
  case 4:
326
- return "Low"
302
+ return "Low";
327
303
  default:
328
- return "Unknown"
304
+ return "Unknown";
329
305
  }
330
306
  }
@@ -1,32 +1,32 @@
1
- import { Command } from "@effect/cli"
2
- import { Console, Effect } from "effect"
3
- import { LinearService } from "../services/Linear.js"
1
+ import { Command } from "@effect/cli";
2
+ import { Console, Effect } from "effect";
3
+ import { LinearService } from "../services/Linear.js";
4
4
 
5
5
  // linear team list - List all teams
6
6
  export const teamListCommand = Command.make("list", {}, () =>
7
7
  Effect.gen(function* () {
8
- const linear = yield* LinearService
9
- const teams = yield* linear.getTeams
8
+ const linear = yield* LinearService;
9
+ const teams = yield* linear.getTeams;
10
10
 
11
11
  if (teams.length === 0) {
12
- yield* Console.log("No teams found.")
13
- return
12
+ yield* Console.log("No teams found.");
13
+ return;
14
14
  }
15
15
 
16
- yield* Console.log("\nTeams:\n")
16
+ yield* Console.log("\nTeams:\n");
17
17
 
18
18
  for (const team of teams) {
19
- const key = team.key
20
- const name = team.name
21
- const description = team.description ? ` - ${team.description}` : ""
22
- yield* Console.log(` ${key.padEnd(8)} ${name}${description}`)
19
+ const key = team.key;
20
+ const name = team.name;
21
+ const description = team.description ? ` - ${team.description}` : "";
22
+ yield* Console.log(` ${key.padEnd(8)} ${name}${description}`);
23
23
  }
24
24
 
25
- yield* Console.log("")
26
- })
27
- )
25
+ yield* Console.log("");
26
+ }),
27
+ );
28
28
 
29
29
  // Combined team command with subcommands
30
30
  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]))
31
+ Console.log("Use 'linear team list' to list teams. See --help for more."),
32
+ ).pipe(Command.withSubcommands([teamListCommand]));
package/src/lib/errors.ts CHANGED
@@ -1,50 +1,48 @@
1
- import { Schema } from "effect"
1
+ import { Schema } from "effect";
2
2
 
3
- export class ConfigError extends Schema.TaggedError<ConfigError>()(
4
- "ConfigError",
5
- {
6
- message: Schema.String,
7
- }
8
- ) {}
3
+ export class ConfigError extends Schema.TaggedError<ConfigError>()("ConfigError", {
4
+ message: Schema.String,
5
+ }) {}
9
6
 
10
- export class LinearApiError extends Schema.TaggedError<LinearApiError>()(
11
- "LinearApiError",
12
- {
13
- message: Schema.String,
14
- code: Schema.optional(Schema.String),
15
- }
16
- ) {}
7
+ export class LinearApiError extends Schema.TaggedError<LinearApiError>()("LinearApiError", {
8
+ message: Schema.String,
9
+ code: Schema.optional(Schema.String),
10
+ }) {}
17
11
 
18
- export class BrowserError extends Schema.TaggedError<BrowserError>()(
19
- "BrowserError",
20
- {
21
- message: Schema.String,
22
- }
23
- ) {}
12
+ export class BrowserError extends Schema.TaggedError<BrowserError>()("BrowserError", {
13
+ message: Schema.String,
14
+ }) {}
24
15
 
25
16
  export class TokenNotFoundError extends Schema.TaggedError<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
27
  export class InvalidTokenError extends Schema.TaggedError<InvalidTokenError>()(
37
28
  "InvalidTokenError",
38
29
  {
39
30
  message: Schema.String,
40
- }
31
+ },
41
32
  ) {}
42
33
 
34
+ export class NoIssuesError extends Schema.TaggedError<NoIssuesError>()("NoIssuesError", {
35
+ message: Schema.String,
36
+ }) {
37
+ static readonly default = NoIssuesError.make({ message: "No issues found to select from." });
38
+ }
39
+
43
40
  export const AppError = Schema.Union(
44
41
  ConfigError,
45
42
  LinearApiError,
46
43
  BrowserError,
47
44
  TokenNotFoundError,
48
- InvalidTokenError
49
- )
50
- export type AppError = typeof AppError.Type
45
+ InvalidTokenError,
46
+ NoIssuesError,
47
+ );
48
+ export type AppError = typeof AppError.Type;