@kud/jira-cli 0.9.0 → 0.11.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.
Files changed (3) hide show
  1. package/README.md +30 -4
  2. package/dist/index.js +352 -41
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -33,6 +33,7 @@ jira attachment list ABC-123
33
33
 
34
34
  jira attachment read ABC-123 error.log | grep -i timeout
35
35
  jira attachment get ABC-123 screen.png --output ~/Desktop/
36
+ jira attachment upload ABC-123 ./build.log ./screenshot.png
36
37
  ```
37
38
 
38
39
  Descriptions and comments render as Markdown, with embedded files named rather than left as opaque ids:
@@ -49,7 +50,7 @@ Run `jira` with no arguments:
49
50
  jira
50
51
  ```
51
52
 
52
- Your issues as a board. By default the tabs are Jira's three status *categories* — **To do**, **In progress**, **Done** — so it works on any instance without knowing what your board calls its columns. Pass `--board <id>` (or set `defaultBoard` in the config file) and the tabs become that board's own columns, matched by status id; statuses no column claims land on an **Off board** tab. Hand-written `tabs` in the config file win over both. Rows hang under their epic, carry a type pill, a priority glyph (`▲` high, `▼` low) and how long since they last moved. Closed work from the last fortnight is on the Done tab; `a` loads everything.
53
+ Your issues as a board. By default the tabs are Jira's three status _categories_ — **To do**, **In progress**, **Done** — so it works on any instance without knowing what your board calls its columns. Pass `--board <id>` (or set `defaultBoard` in the config file) and the tabs become that board's own columns, matched by status id; statuses no column claims land on an **Off board** tab. Hand-written `tabs` in the config file win over both. Rows hang under their epic, carry a type pill, a priority glyph (`▲` high, `▼` low) and how long since they last moved. Closed work from the last fortnight is on the Done tab; `a` loads everything.
53
54
 
54
55
  `↑↓` to move, `←→` (or `⇥`) to switch tab, `enter` to open, `?` for the legend, `r` to refresh. `q` quits from anywhere; `esc` or `⌫` goes back one level — a prompt, then the issue, then nothing.
55
56
 
@@ -78,8 +79,9 @@ jira issue list # yours, most recently updated first
78
79
  jira issue list --status 'In Progress'
79
80
  jira issue list --project ABC --sprint current
80
81
  jira issue view ABC-123
82
+ jira issue view ABC-123 --fields status,assignee,issuelinks
81
83
  jira issue transition ABC-123 # list what's available
82
- jira issue transition ABC-123 'In Review'
84
+ jira issue transition ABC-123 'In Review' # by transition name or target status
83
85
  jira issue open ABC-123
84
86
  ```
85
87
 
@@ -87,18 +89,38 @@ Writing:
87
89
 
88
90
  ```sh
89
91
  jira issue create -p ABC -t Task -s 'Fix the thing' -b 'Longer **markdown** body'
90
- jira issue edit ABC-123 --summary 'Better title'
91
- jira issue assign ABC-123 me # or a name, or 'none'
92
+ jira issue create -p ABC -t Task -s 'A sub-task' --parent ABC-100 --link Relates:ABC-99
93
+ jira issue edit ABC-123 --summary 'Better title' --assignee me --parent ABC-100
94
+ jira issue assign ABC-123 me # or a name, an email, an account id, or 'none'
92
95
  jira issue comment add ABC-123 - # body from stdin
93
96
  jira issue comment list ABC-123
97
+ jira issue comment edit ABC-123 12345 'Actually fixed in 2.1'
98
+ jira issue delete ABC-123 # asks first; --yes to confirm in scripts
99
+ jira issue rank ABC-1 ABC-2 --before ABC-3
94
100
  jira issue link ABC-1 Blocks ABC-2
101
+ jira issue link list ABC-1
95
102
  jira issue watch add ABC-123
96
103
  jira issue worklog add ABC-123 '2h 30m'
104
+ jira issue worklog edit ABC-123 456 --time '3h'
105
+ jira issue worklog delete ABC-123 456
106
+ jira issue remotelink list ABC-123
107
+ jira issue remotelink add ABC-123 https://example.atlassian.net/wiki/spaces/ABC/pages/1234
108
+ jira issue remotelink remove ABC-123 789
97
109
  jira issue history ABC-123
98
110
  ```
99
111
 
112
+ `jira issue view` lists the issue's links and subtasks, in plain text and in `--json`. Pass `--fields status,assignee,parent,issuelinks` (comma-separated) to see only those fields — both in plain text and `--json`; the key and summary stay either way, and without `--fields` the view is exactly what it has always been.
113
+
114
+ People are resolved for you. `issue assign`, and `--assignee` on `create` and `edit`, accept a name or an email: assignable users of the project are searched first, then every user. `me` means you, `none` unassigns, and a raw account id passes straight through. If a name matches several people nothing is assigned — every match is printed on stderr and the command exits non-zero, because a guess is worse than an error.
115
+
116
+ Parents and links belong to the same commands. `--parent ABC-100` sets a parent on `create` or `edit`, and `edit --parent none` clears it. `--link Relates:ABC-99` (repeatable, `<type>:<KEY>`) links the new issue right after creating it, exactly as `jira issue link <new> <type> <KEY>` would. The link type is checked against your instance's link type names before anything is created, so a typo costs nothing; if creation succeeds but a link fails, the new key and the failure are reported and the exit is non-zero.
117
+
118
+ `issue transition` takes either a transition name or the status it leads to (`Start Progress` or `In Progress`), matched case-insensitively and by transition id. With no argument it lists the transitions as `name → target status`.
119
+
100
120
  Bodies accept Markdown — paragraphs, headings, lists, fenced code, links and code spans are converted to ADF.
101
121
 
122
+ Deletes (`issue delete`, `comment delete`, `worklog delete`, `remotelink remove`) ask before they act; piped or scripted runs refuse unless `--yes` is passed, since there is no undo on Jira's side. `remotelink add` is idempotent: re-adding the same url updates the same link rather than creating duplicates.
123
+
102
124
  ## Projects, boards and sprints
103
125
 
104
126
  ```sh
@@ -115,6 +137,8 @@ jira epic ABC-100
115
137
 
116
138
  jira sprint list 42 --state active
117
139
  jira sprint issues 1234
140
+ jira sprint add 1234 ABC-1 ABC-2
141
+ jira backlog add ABC-1 ABC-2
118
142
  ```
119
143
 
120
144
  ## Knowing what this instance supports
@@ -190,6 +214,8 @@ jira api /rest/api/3/myself
190
214
  jira api /rest/api/3/issue/ABC-123/watchers -X POST -d '{"accountId":"..."}'
191
215
  ```
192
216
 
217
+ A call returning 2xx with an empty body — a 204, or a 201 with no content — prints nothing and exits 0, rather than printing the string `null`; that way `null` only ever means Jira really answered null. A non-2xx is still an error, showing the body.
218
+
193
219
  ## Licence
194
220
 
195
221
  MIT
package/dist/index.js CHANGED
@@ -75,6 +75,31 @@ var registerAttachmentCommands = (program2) => {
75
75
  `
76
76
  );
77
77
  });
78
+ attachment.command("upload <key> <file...>").description("attach files to an issue").option("--json", "emit JSON").action(
79
+ async (key, files, options) => {
80
+ const ctx = context();
81
+ const uploaded = [];
82
+ for (const file of files) {
83
+ try {
84
+ uploaded.push(...await ctx.client.uploadAttachment(key, file));
85
+ } catch (err) {
86
+ const done = uploaded.map((a) => a.filename).join(", ");
87
+ throw new Error(
88
+ `${file}: ${err.message}${done ? ` (already attached: ${done})` : ""}`
89
+ );
90
+ }
91
+ }
92
+ if (options.json) return printJson(uploaded);
93
+ process.stdout.write(
94
+ `${table(uploaded, [
95
+ { header: "ID", value: (a) => a.id },
96
+ { header: "FILENAME", value: (a) => a.filename },
97
+ { header: "SIZE", value: (a) => humanSize(a.size), align: "right" }
98
+ ])}
99
+ `
100
+ );
101
+ }
102
+ );
78
103
  attachment.command("read <key> <selector>").alias("cat").description("print a text attachment to stdout").action(async (key, selector) => {
79
104
  const ctx = context();
80
105
  const attachments = locateAttachments(await ctx.client.getIssue(key));
@@ -203,6 +228,11 @@ var registerSprintCommands = (program2) => {
203
228
  const { issues } = await ctx.client.getSprintIssues(Number(id));
204
229
  writeIssues(issues, options.json);
205
230
  });
231
+ sprint.command("add <sprintId> <keys...>").description("move issues into a sprint").action(async (sprintId, keys) => {
232
+ await context().client.moveIssuesToSprint(Number(sprintId), keys);
233
+ process.stderr.write(`moved ${keys.join(", ")} to sprint ${sprintId}
234
+ `);
235
+ });
206
236
  sprint.command("view <id>").description("show one sprint").option("--json", "emit JSON").action(async (id, options) => {
207
237
  const ctx = context();
208
238
  const found = await ctx.client.getSprint(Number(id));
@@ -226,34 +256,106 @@ var registerEpicCommands = (program2) => {
226
256
  writeIssues(issues, options.json);
227
257
  });
228
258
  };
259
+ var registerBacklogCommand = (program2) => {
260
+ const backlog = program2.command("backlog").description("backlog management");
261
+ backlog.command("add <keys...>").description("move issues to the backlog").action(async (keys) => {
262
+ await context().client.moveIssuesToBacklog(keys);
263
+ process.stderr.write(`moved ${keys.join(", ")} to the backlog
264
+ `);
265
+ });
266
+ };
229
267
 
230
268
  // src/commands/issue.ts
231
269
  import { execFile } from "child_process";
232
- import {
233
- adfToMarkdown as adfToMarkdown2,
234
- locateAttachments as locateAttachments2
235
- } from "@kud/jira";
270
+ import { adfToMarkdown as adfToMarkdown2, flattenIssueLinks as flattenIssueLinks2, locateAttachments as locateAttachments2 } from "@kud/jira";
236
271
 
237
272
  // src/commands/issue-write.ts
238
273
  import { readFileSync } from "fs";
239
- import { adfToMarkdown, markdownToAdf } from "@kud/jira";
274
+ import { adfToMarkdown, flattenIssueLinks, markdownToAdf } from "@kud/jira";
275
+
276
+ // src/commands/confirm.ts
277
+ import { createInterface } from "readline/promises";
278
+ var confirmDestructive = async (what, options) => {
279
+ if (options.yes) return;
280
+ if (!process.stdin.isTTY)
281
+ throw exitError(
282
+ 1,
283
+ `${what} is destructive \u2014 re-run with --yes to confirm it non-interactively`
284
+ );
285
+ const rl = createInterface({ input: process.stdin, output: process.stderr });
286
+ try {
287
+ const answer = await rl.question(`${what} \u2014 proceed? [y/N] `);
288
+ if (answer.trim().toLowerCase() !== "y") throw exitError(1, "aborted");
289
+ } finally {
290
+ rl.close();
291
+ }
292
+ };
293
+
294
+ // src/commands/issue-write.ts
295
+ var rankPosition = (options) => {
296
+ const { before, after } = options;
297
+ if (before && after) throw exitError(1, "pass --before or --after, not both");
298
+ if (!before && !after)
299
+ throw exitError(1, "pass one of --before <key> or --after <key>");
300
+ if (before) return { before };
301
+ return { after };
302
+ };
240
303
  var readBody = (value) => value === "-" ? readFileSync(0, "utf8") : value;
304
+ var projectOf = (issueKey) => issueKey.split("-")[0];
305
+ var collectLink = (value, prior) => [
306
+ ...prior,
307
+ value
308
+ ];
309
+ var messageOf = (e) => e instanceof Error ? e.message : String(e);
310
+ var linkTypes = (ctx) => ctx.client.getIssueLinkTypes().then(({ issueLinkTypes }) => issueLinkTypes);
311
+ var parseLinkSpecs = (link, types) => {
312
+ if (!link?.length) return [];
313
+ const titles = types.map((t) => t.name);
314
+ return link.map((spec) => {
315
+ const colon = spec.indexOf(":");
316
+ const type = colon === -1 ? void 0 : spec.slice(0, colon);
317
+ const key = colon === -1 ? void 0 : spec.slice(colon + 1);
318
+ if (!type || !key)
319
+ throw exitError(
320
+ 1,
321
+ `malformed --link '${spec}' \u2014 expected <type>:<KEY>, e.g. Relates:ABC-2`
322
+ );
323
+ const resolved = types.find(
324
+ (t) => t.name.toLowerCase() === type.toLowerCase()
325
+ );
326
+ if (!resolved)
327
+ throw exitError(
328
+ 1,
329
+ `no link type '${type}'. Valid: ${titles.join(", ")}`
330
+ );
331
+ return { type: resolved.name, key };
332
+ });
333
+ };
241
334
  var resolveAccountId = async (who, projectKey) => {
242
335
  if (who === "none" || who === "unassigned") return null;
243
336
  if (who === "me") return (await context().client.getMe()).accountId;
244
337
  if (/^[0-9a-f]{24}$|:/.test(who)) return who;
245
338
  const ctx = context();
246
- const candidates = projectKey ? await ctx.client.searchAssignableUsers(who, projectKey) : await ctx.client.searchUsers(who);
339
+ const assignable = projectKey ? await ctx.client.searchAssignableUsers(who, projectKey) : [];
340
+ const candidates = assignable.length > 0 ? assignable : await ctx.client.searchUsers(who);
247
341
  if (candidates.length === 0) throw exitError(1, `no user matching '${who}'`);
248
- if (candidates.length > 1)
249
- throw exitError(
250
- 1,
251
- `'${who}' matches ${candidates.length} people: ${candidates.map((u) => `${u.displayName} (${u.accountId})`).join(", ")}`
252
- );
342
+ if (candidates.length > 1) {
343
+ for (const u of candidates)
344
+ process.stderr.write(
345
+ `${u.displayName}${u.emailAddress ? ` ${u.emailAddress}` : ""} ${u.accountId}
346
+ `
347
+ );
348
+ throw exitError(1, `'${who}' matches ${candidates.length} people`);
349
+ }
253
350
  return candidates[0].accountId;
254
351
  };
255
352
  var registerIssueWriteCommands = (issue) => {
256
- issue.command("create").description("create an issue").requiredOption("-p, --project <key>", "project key").requiredOption("-t, --type <type>", "issue type, e.g. Task").requiredOption("-s, --summary <text>", "summary").option("-b, --body <text>", "description; '-' reads stdin").option("-a, --assignee <who>", "assignee, or 'me'").option("-l, --label <label...>", "labels").option("--priority <name>", "priority name").option("--json", "emit JSON").action(
353
+ issue.command("create").description("create an issue").requiredOption("-p, --project <key>", "project key").requiredOption("-t, --type <type>", "issue type, e.g. Task").requiredOption("-s, --summary <text>", "summary").option("-b, --body <text>", "description; '-' reads stdin").option("-a, --assignee <who>", "assignee, or 'me'").option("-l, --label <label...>", "labels").option("--priority <name>", "priority name").option("--parent <key>", "parent issue key").option(
354
+ "--link <type:key>",
355
+ "link the new issue to another, repeatable, e.g. Relates:ABC-2",
356
+ collectLink,
357
+ []
358
+ ).option("--json", "emit JSON").action(
257
359
  async (options) => {
258
360
  const ctx = context();
259
361
  const fields = {
@@ -265,6 +367,7 @@ var registerIssueWriteCommands = (issue) => {
265
367
  fields["description"] = markdownToAdf(readBody(options.body));
266
368
  if (options.label) fields["labels"] = options.label;
267
369
  if (options.priority) fields["priority"] = { name: options.priority };
370
+ if (options.parent) fields["parent"] = { key: options.parent };
268
371
  if (options.assignee)
269
372
  fields["assignee"] = {
270
373
  accountId: await resolveAccountId(
@@ -272,13 +375,26 @@ var registerIssueWriteCommands = (issue) => {
272
375
  options.project
273
376
  )
274
377
  };
378
+ const links = options.link?.length ? parseLinkSpecs(options.link, await linkTypes(ctx)) : [];
275
379
  const created = await ctx.client.createIssue(fields);
276
- if (options.json) return printJson(created);
277
- process.stdout.write(`${created.key}
380
+ if (options.json) printJson(created);
381
+ else process.stdout.write(`${created.key}
278
382
  `);
383
+ for (const link2 of links) {
384
+ try {
385
+ await ctx.client.linkIssues(link2.type, created.key, link2.key);
386
+ } catch (e) {
387
+ throw exitError(
388
+ 1,
389
+ `created ${created.key}, but the ${link2.type} link to ${link2.key} failed: ${messageOf(e)}`
390
+ );
391
+ }
392
+ process.stderr.write(`linked ${created.key} ${link2.type} ${link2.key}
393
+ `);
394
+ }
279
395
  }
280
396
  );
281
- issue.command("edit <key>").description("change an issue's fields").option("-s, --summary <text>", "new summary").option("-b, --body <text>", "new description; '-' reads stdin").option("-l, --label <label...>", "replace labels").option("--priority <name>", "priority name").action(
397
+ issue.command("edit <key>").description("change an issue's fields").option("-s, --summary <text>", "new summary").option("-b, --body <text>", "new description; '-' reads stdin").option("-l, --label <label...>", "replace labels").option("--priority <name>", "priority name").option("--parent <key>", "parent issue key; 'none' clears it").option("-a, --assignee <who>", "assignee; 'me' or 'none' both work").action(
282
398
  async (key, options) => {
283
399
  const fields = {};
284
400
  if (options.summary) fields["summary"] = options.summary;
@@ -286,6 +402,15 @@ var registerIssueWriteCommands = (issue) => {
286
402
  fields["description"] = markdownToAdf(readBody(options.body));
287
403
  if (options.label) fields["labels"] = options.label;
288
404
  if (options.priority) fields["priority"] = { name: options.priority };
405
+ if (options.parent !== void 0)
406
+ fields["parent"] = options.parent === "none" ? null : { key: options.parent };
407
+ if (options.assignee) {
408
+ const accountId = await resolveAccountId(
409
+ options.assignee,
410
+ projectOf(key)
411
+ );
412
+ fields["assignee"] = accountId ? { accountId } : null;
413
+ }
289
414
  if (Object.keys(fields).length === 0)
290
415
  throw exitError(2, "nothing to change \u2014 pass at least one option");
291
416
  await context().client.updateIssue(key, fields);
@@ -293,8 +418,14 @@ var registerIssueWriteCommands = (issue) => {
293
418
  `);
294
419
  }
295
420
  );
296
- issue.command("assign <key> <who>").description("assign an issue; 'me' or 'none' both work").action(async (key, who) => {
297
- const accountId = await resolveAccountId(who);
421
+ issue.command("delete <key>").description("delete an issue, permanently").option("--yes", "skip the confirmation").action(async (key, options) => {
422
+ await confirmDestructive(`permanently delete ${key}`, options);
423
+ await context().client.deleteIssue(key);
424
+ process.stderr.write(`deleted ${key}
425
+ `);
426
+ });
427
+ issue.command("assign <key> <who>").description("assign an issue; 'me', a name, or 'none' all work").action(async (key, who) => {
428
+ const accountId = await resolveAccountId(who, projectOf(key));
298
429
  await context().client.assignIssue(key, accountId);
299
430
  process.stderr.write(`${key} assigned to ${accountId ? who : "nobody"}
300
431
  `);
@@ -321,6 +452,26 @@ var registerIssueWriteCommands = (issue) => {
321
452
  process.stderr.write(`commented on ${key}
322
453
  `);
323
454
  });
455
+ comment.command("edit <key> <commentId> <text>").description("edit a comment; '-' reads stdin").action(async (key, commentId, text) => {
456
+ await context().client.updateComment(
457
+ key,
458
+ commentId,
459
+ markdownToAdf(readBody(text))
460
+ );
461
+ process.stderr.write(`comment ${commentId} on ${key} updated
462
+ `);
463
+ });
464
+ comment.command("delete <key> <commentId>").description("delete a comment").option("--yes", "skip the confirmation").action(
465
+ async (key, commentId, options) => {
466
+ await confirmDestructive(
467
+ `delete comment ${commentId} on ${key}`,
468
+ options
469
+ );
470
+ await context().client.deleteComment(key, commentId);
471
+ process.stderr.write(`deleted comment ${commentId} on ${key}
472
+ `);
473
+ }
474
+ );
324
475
  const watch = issue.command("watch").description("watchers");
325
476
  watch.command("list <key>").alias("ls").description("who is watching an issue").action(async (key) => {
326
477
  const { watchers } = await context().client.getWatchers(key);
@@ -369,9 +520,105 @@ var registerIssueWriteCommands = (issue) => {
369
520
  `);
370
521
  }
371
522
  );
372
- issue.command("link <inward> <type> <outward>").description("link two issues, e.g. ABC-1 Blocks ABC-2").action(async (inward, type, outward) => {
523
+ worklog.command("edit <key> <worklogId>").description("change logged work").option("--time <timeSpent>", "new time spent, e.g. '1h 30m'").option("-b, --body <text>", "what you did; '-' reads stdin").option(
524
+ "--started <datetime>",
525
+ "start time, e.g. 2026-10-27T09:00:00.000+0000"
526
+ ).action(
527
+ async (key, worklogId, options) => {
528
+ if (!options.time && !options.body && !options.started)
529
+ throw exitError(2, "nothing to change \u2014 pass at least one option");
530
+ await context().client.updateWorklog(key, worklogId, {
531
+ ...options.time ? { timeSpent: options.time } : {},
532
+ ...options.body ? { comment: markdownToAdf(readBody(options.body)) } : {},
533
+ ...options.started ? { started: options.started } : {}
534
+ });
535
+ process.stderr.write(`worklog ${worklogId} on ${key} updated
536
+ `);
537
+ }
538
+ );
539
+ worklog.command("delete <key> <worklogId>").description("delete logged work").option("--yes", "skip the confirmation").action(
540
+ async (key, worklogId, options) => {
541
+ await confirmDestructive(
542
+ `delete worklog ${worklogId} on ${key}`,
543
+ options
544
+ );
545
+ await context().client.deleteWorklog(key, worklogId);
546
+ process.stderr.write(`deleted worklog ${worklogId} on ${key}
547
+ `);
548
+ }
549
+ );
550
+ const remotelink = issue.command("remotelink").description("links to pages outside Jira");
551
+ remotelink.command("list <key>").alias("ls").description("remote links on an issue").option("--json", "emit JSON").action(async (key, options) => {
552
+ const links = await context().client.getRemoteLinks(key);
553
+ if (options.json) return printJson(links);
554
+ if (links.length === 0) {
555
+ process.stderr.write(`${key} has no remote links
556
+ `);
557
+ return;
558
+ }
559
+ process.stdout.write(
560
+ `${table(links, [
561
+ { header: "ID", value: (l) => String(l.id) },
562
+ { header: "TITLE", value: (l) => l.object.title },
563
+ { header: "URL", value: (l) => l.object.url }
564
+ ])}
565
+ `
566
+ );
567
+ });
568
+ remotelink.command("add <key> <url>").description("link a url to an issue; re-adding the same url is a no-op").option("--title <text>", "link title, defaulting to the url").action(async (key, url, options) => {
569
+ await context().client.createRemoteLink(key, {
570
+ url,
571
+ title: options.title ?? url,
572
+ globalId: url
573
+ });
574
+ process.stderr.write(`linked ${url} to ${key}
575
+ `);
576
+ });
577
+ remotelink.command("remove <key> <linkId>").description("remove a remote link").option("--yes", "skip the confirmation").action(async (key, linkId, options) => {
578
+ await confirmDestructive(
579
+ `remove remote link ${linkId} from ${key}`,
580
+ options
581
+ );
582
+ await context().client.deleteRemoteLink(key, linkId);
583
+ process.stderr.write(`removed remote link ${linkId} from ${key}
584
+ `);
585
+ });
586
+ issue.command("rank <keys...>").description("order issues before or after another issue").option("--before <key>", "place the issues before this one").option("--after <key>", "place the issues after this one").action(
587
+ async (keys, options) => {
588
+ const position = rankPosition(options);
589
+ await context().client.rankIssues(keys, position);
590
+ const anchor = "before" in position ? position.before : position.after;
591
+ process.stderr.write(
592
+ `ranked ${keys.join(", ")} ${"before" in position ? "before" : "after"} ${anchor}
593
+ `
594
+ );
595
+ }
596
+ );
597
+ const link = issue.command("link").description("link two issues, e.g. jira issue link ABC-1 Blocks ABC-2");
598
+ link.command("list <key>").alias("ls").description("links on an issue").option("--json", "emit JSON").action(async (key, options) => {
599
+ const ctx = context();
600
+ const found = await ctx.client.getIssue(key);
601
+ const links = flattenIssueLinks(found);
602
+ if (options.json) return printJson(links);
603
+ if (links.length === 0) {
604
+ process.stderr.write(`${key} has no links
605
+ `);
606
+ return;
607
+ }
608
+ process.stdout.write(
609
+ `${table(links, [
610
+ { header: "DIR", value: (l) => l.direction },
611
+ { header: "TYPE", value: (l) => l.type },
612
+ { header: "KEY", value: (l) => l.key },
613
+ { header: "STATUS", value: (l) => l.status },
614
+ { header: "SUMMARY", value: (l) => truncate(l.summary, 40) }
615
+ ])}
616
+ `
617
+ );
618
+ });
619
+ link.argument("<inward>").argument("<type>").argument("<outward>").action(async (inward, type, outward) => {
373
620
  await context().client.linkIssues(type, inward, outward);
374
- process.stderr.write(`${inward} ${type} ${outward}
621
+ process.stderr.write(`linked ${inward} ${type} ${outward}
375
622
  `);
376
623
  });
377
624
  issue.command("history <key>").description("what changed on an issue and when").option("--json", "emit JSON").action(async (key, options) => {
@@ -390,9 +637,7 @@ var registerIssueWriteCommands = (issue) => {
390
637
  };
391
638
 
392
639
  // src/commands/issue.ts
393
- import {
394
- buildJql
395
- } from "@kud/jira";
640
+ import { buildJql } from "@kud/jira";
396
641
  var issueColumns = (ctx) => [
397
642
  { header: "KEY", value: (i) => i.key },
398
643
  { header: "STATUS", value: (i) => i.fields.status?.name ?? "\u2014" },
@@ -430,30 +675,71 @@ var registerIssueCommands = (program2) => {
430
675
  `);
431
676
  warnIfTruncated(issues.length, limit, { exitCode: false });
432
677
  });
433
- issue.command("view <key>").description("show one issue").option("--json", "emit JSON").option("--comments", "include comments").action(
678
+ issue.command("view <key>").description("show one issue").option("--json", "emit JSON").option("--comments", "include comments").option(
679
+ "--fields <list>",
680
+ "restrict the output to these fields, comma-separated"
681
+ ).action(
434
682
  async (key, options) => {
435
683
  const ctx = context();
436
684
  const found = await ctx.client.getIssue(key);
437
- if (options.json) return printJson(found);
685
+ const fields = options.fields?.split(",").map((f2) => f2.trim().toLowerCase()).filter(Boolean);
686
+ const show = (field) => !fields || fields.includes(field.toLowerCase());
687
+ if (options.json) {
688
+ const chosen = fields ? Object.fromEntries(
689
+ Object.entries(found.fields).filter(
690
+ ([k]) => fields.includes(k.toLowerCase())
691
+ )
692
+ ) : { ...found.fields };
693
+ if (show("issuelinks")) chosen["issuelinks"] = flattenIssueLinks2(found);
694
+ if (show("subtasks"))
695
+ chosen["subtasks"] = found.fields.subtasks?.map((s) => ({
696
+ key: s.key,
697
+ summary: s.fields.summary,
698
+ status: s.fields.status.name
699
+ }));
700
+ return printJson({ ...found, fields: chosen });
701
+ }
438
702
  const { bold, dim } = ctx.out;
439
703
  const f = found.fields;
440
704
  const lines = [
441
705
  `${bold(found.key)} ${f.summary ?? ""}`,
442
706
  "",
443
- ...f.parent ? [
707
+ ...show("parent") && f.parent ? [
444
708
  `${dim("parent")} ${f.parent.key} ${truncate(f.parent.fields?.summary ?? "", 60)}`
445
709
  ] : [],
446
- `${dim("status")} ${f.status?.name ?? "\u2014"}`,
447
- `${dim("type")} ${f.issuetype?.name ?? "\u2014"}`,
448
- `${dim("assignee")} ${f.assignee?.displayName ?? "unassigned"}`,
449
- `${dim("reporter")} ${f.reporter?.displayName ?? "\u2014"}`,
450
- ...f.labels?.length ? [`${dim("labels")} ${f.labels.join(", ")}`] : [],
451
- ...ctx.client.customFields.filter((cf) => f[cf.id] != null).map((cf) => `${dim(cf.label.padEnd(9))} ${formatField(f[cf.id])}`),
452
- `${dim("url")} ${issueUrl(ctx, found.key)}`
710
+ ...show("status") ? [`${dim("status")} ${f.status?.name ?? "\u2014"}`] : [],
711
+ ...show("issuetype") ? [`${dim("type")} ${f.issuetype?.name ?? "\u2014"}`] : [],
712
+ ...show("assignee") ? [`${dim("assignee")} ${f.assignee?.displayName ?? "unassigned"}`] : [],
713
+ ...show("reporter") ? [`${dim("reporter")} ${f.reporter?.displayName ?? "\u2014"}`] : [],
714
+ ...show("labels") && f.labels?.length ? [`${dim("labels")} ${f.labels.join(", ")}`] : [],
715
+ ...ctx.client.customFields.filter((cf) => f[cf.id] != null && show(cf.id)).map((cf) => `${dim(cf.label.padEnd(9))} ${formatField(f[cf.id])}`),
716
+ ...fields ? [] : [`${dim("url")} ${issueUrl(ctx, found.key)}`]
453
717
  ];
718
+ const links = flattenIssueLinks2(found);
719
+ if (show("issuelinks") && links.length > 0) {
720
+ lines.push(
721
+ "",
722
+ dim("\u2500\u2500\u2500 links \u2500\u2500\u2500"),
723
+ "",
724
+ ...links.map(
725
+ (l) => `${l.direction.padEnd(7)} ${l.type.padEnd(12)} ${l.key} ${dim(l.status.padEnd(12))} ${truncate(l.summary, 60)}`
726
+ )
727
+ );
728
+ }
729
+ const subtasks = f.subtasks;
730
+ if (show("subtasks") && subtasks?.length) {
731
+ lines.push(
732
+ "",
733
+ dim("\u2500\u2500\u2500 subtasks \u2500\u2500\u2500"),
734
+ "",
735
+ ...subtasks.map(
736
+ (s) => `${s.key} ${dim(s.fields.status.name.padEnd(12))} ${truncate(s.fields.summary, 60)}`
737
+ )
738
+ );
739
+ }
454
740
  const attachments = locateAttachments2(found);
455
741
  const filenameOf = (id) => attachments.find((a) => a.id === id)?.filename;
456
- if (attachments.length > 0) {
742
+ if (!fields && attachments.length > 0) {
457
743
  lines.push(
458
744
  "",
459
745
  dim("\u2500\u2500\u2500 attachments \u2500\u2500\u2500"),
@@ -466,9 +752,9 @@ var registerIssueCommands = (program2) => {
466
752
  );
467
753
  }
468
754
  const description = adfToMarkdown2(f.description, filenameOf);
469
- if (description)
755
+ if (show("description") && description)
470
756
  lines.push("", dim("\u2500\u2500\u2500 description \u2500\u2500\u2500"), "", description);
471
- if (options.comments && f.comment?.comments?.length) {
757
+ if (options.comments && show("comment") && f.comment?.comments?.length) {
472
758
  lines.push("", dim("\u2500\u2500\u2500 comments \u2500\u2500\u2500"));
473
759
  for (const c of f.comment.comments) {
474
760
  lines.push(
@@ -491,21 +777,40 @@ var registerIssueCommands = (program2) => {
491
777
  process.stdout.write(
492
778
  `${table(transitions, [
493
779
  { header: "ID", value: (t) => t.id },
494
- { header: "NAME", value: (t) => t.name },
495
- { header: "TO", value: (t) => t.to?.name ?? "\u2014" }
780
+ { header: "NAME \u2192 TO", value: (t) => `${t.name} \u2192 ${t.to?.name ?? "\u2014"}` }
496
781
  ])}
497
782
  `
498
783
  );
784
+ process.stderr.write(TRANSITION_HINT + "\n");
499
785
  return;
500
786
  }
501
787
  const wanted = status.toLowerCase();
502
- const match = transitions.find(
788
+ const byName = transitions.filter(
503
789
  (t) => t.name.toLowerCase() === wanted || t.id === status
504
790
  );
791
+ const byTarget = transitions.filter(
792
+ (t) => t.to?.name.toLowerCase() === wanted
793
+ );
794
+ const match = byName.length > 0 ? byName.length === 1 ? byName[0] : void 0 : byTarget.length === 1 ? byTarget[0] : void 0;
795
+ if (byName.length > 1) {
796
+ throw exitError(
797
+ 1,
798
+ `'${status}' matches ${byName.length} transitions on ${key}: ${byName.map((t) => `${t.name} \u2192 ${t.to?.name ?? "\u2014"}`).join("; ")}`
799
+ );
800
+ }
801
+ if (byName.length === 0 && byTarget.length > 1) {
802
+ throw exitError(
803
+ 1,
804
+ `${byTarget.length} transitions reach '${status}' on ${key}: ${byTarget.map((t) => `${t.name} \u2192 ${t.to?.name ?? "\u2014"}`).join("; ")}
805
+ Use a transition name instead`
806
+ );
807
+ }
505
808
  if (!match) {
506
809
  throw exitError(
507
810
  1,
508
- `no transition '${status}' on ${key}. Available: ${transitions.map((t) => t.name).join(", ")}`
811
+ `no transition or status '${status}' on ${key}. Available:
812
+ ${transitions.map((t) => ` ${t.name} \u2192 ${t.to?.name ?? "\u2014"}`).join("\n")}
813
+ ${TRANSITION_HINT}`
509
814
  );
510
815
  }
511
816
  await ctx.client.transitionIssue(
@@ -531,6 +836,7 @@ var registerIssueCommands = (program2) => {
531
836
  });
532
837
  };
533
838
  var issueUrl = (ctx, key) => `${ctx.config.baseUrl.replace(/\/$/, "")}/browse/${key}`;
839
+ var TRANSITION_HINT = "the argument may be either the transition name or its target status";
534
840
  var formatField = (value) => {
535
841
  if (value == null) return "\u2014";
536
842
  if (typeof value === "object") {
@@ -797,7 +1103,8 @@ var registerApiCommand = (program2) => {
797
1103
  method,
798
1104
  ...options.data ? { body: options.data } : {}
799
1105
  });
800
- printJson(result ?? null);
1106
+ if (result == null) return;
1107
+ printJson(result);
801
1108
  }
802
1109
  );
803
1110
  };
@@ -807,7 +1114,10 @@ var registerInitCommand = (program2) => {
807
1114
  const path = configPath();
808
1115
  const existing = readFileConfig(path);
809
1116
  if (Object.keys(existing).length > 0 && !options.force)
810
- throw exitError(1, `${path} already exists \u2014 pass --force to replace it`);
1117
+ throw exitError(
1118
+ 1,
1119
+ `${path} already exists \u2014 pass --force to replace it`
1120
+ );
811
1121
  const config = {
812
1122
  baseUrl: options.baseUrl ?? process.env["ATLASSIAN_BASE_URL"] ?? "",
813
1123
  email: options.email ?? process.env["ATLASSIAN_USER_EMAIL"] ?? "",
@@ -861,6 +1171,7 @@ registerInitCommand(program);
861
1171
  registerProjectCommands(program);
862
1172
  registerBoardCommands(program);
863
1173
  registerSprintCommands(program);
1174
+ registerBacklogCommand(program);
864
1175
  registerEpicCommands(program);
865
1176
  registerUserCommands(program);
866
1177
  registerMetaCommands(program);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kud/jira-cli",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "description": "Jira on the command line — read issues, comments and attachments as plain text",
6
6
  "keywords": [
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@kud/ink-ui": "0.32.0",
41
- "@kud/jira": "0.4.0",
41
+ "@kud/jira": "0.6.0",
42
42
  "@kud/jira-ink": "0.11.0",
43
43
  "commander": "14.0.1",
44
44
  "ink": "7.1.1",