@kud/jira-cli 0.12.0 → 0.13.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 +13 -1
- package/dist/index.js +239 -61
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,15 +88,18 @@ jira issue open ABC-123
|
|
|
88
88
|
Writing:
|
|
89
89
|
|
|
90
90
|
```sh
|
|
91
|
-
jira issue create -p ABC -t Task -s 'Fix the thing' -b 'Longer **markdown** body'
|
|
91
|
+
jira issue create -p ABC -t Task -s 'Fix the thing' -b 'Longer **markdown** body' --status 'In Progress'
|
|
92
92
|
jira issue create -p ABC -t Task -s 'A sub-task' --parent ABC-100 --link Relates:ABC-99
|
|
93
93
|
jira issue edit ABC-123 --summary 'Better title' --assignee me --parent ABC-100
|
|
94
|
+
jira issue edit ABC-123 --prepend-description '**Update:** finished QA'
|
|
94
95
|
jira issue assign ABC-123 me # or a name, an email, an account id, or 'none'
|
|
95
96
|
jira issue comment add ABC-123 - # body from stdin
|
|
96
97
|
jira issue comment list ABC-123
|
|
98
|
+
jira issue comment list ABC-123 --last 5 # the 5 most recent, oldest first
|
|
97
99
|
jira issue comment edit ABC-123 12345 'Actually fixed in 2.1'
|
|
98
100
|
jira issue delete ABC-123 # asks first; --yes to confirm in scripts
|
|
99
101
|
jira issue rank ABC-1 ABC-2 --before ABC-3
|
|
102
|
+
jira issue rank ABC-1 ABC-2 --top --jql 'project = ABC AND sprint = 42'
|
|
100
103
|
jira issue link ABC-1 Blocks ABC-2
|
|
101
104
|
jira issue link list ABC-1
|
|
102
105
|
jira issue watch add ABC-123
|
|
@@ -115,8 +118,14 @@ People are resolved for you. `issue assign`, and `--assignee` on `create` and `e
|
|
|
115
118
|
|
|
116
119
|
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
120
|
|
|
121
|
+
`create --status 'In Progress'` moves the new issue to that status right after creation and any links. If the fresh issue already sits in that status nothing is sent, and if the move fails the key and the reason are reported with a non-zero exit, as with links.
|
|
122
|
+
|
|
123
|
+
`edit --prepend-description` and `--append-description` splice markdown onto the start or end of an existing description without touching it: the current ADF nodes are preserved and the converted markdown is added around them. Both may be combined; with `--body` neither is allowed. Like `-b`, a value of `-` reads stdin.
|
|
124
|
+
|
|
118
125
|
`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
126
|
|
|
127
|
+
`issue rank --top --jql <jql>` ranks the keys above the first issue of the JQL scope. The JQL must order by rank (`ORDER BY Rank ASC` is appended when missing, and a JQL ordered any other way is refused, since its first result would not be the top). When the keys already occupy the top in rank order nothing is sent.
|
|
128
|
+
|
|
120
129
|
Bodies accept Markdown — paragraphs, headings, lists, fenced code, links and code spans are converted to ADF.
|
|
121
130
|
|
|
122
131
|
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.
|
|
@@ -130,6 +139,9 @@ jira project components ABC
|
|
|
130
139
|
jira project statuses ABC
|
|
131
140
|
|
|
132
141
|
jira board list
|
|
142
|
+
jira board list --project ABC
|
|
143
|
+
jira board view 42 # columns, their statuses, and the board's filter
|
|
144
|
+
jira board view 42 --json
|
|
133
145
|
jira board issues 42
|
|
134
146
|
jira board backlog 42
|
|
135
147
|
jira board epics 42
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import { realpathSync } from "fs";
|
|
|
14
14
|
import { createRequire } from "module";
|
|
15
15
|
import { fileURLToPath } from "url";
|
|
16
16
|
import { Command } from "commander";
|
|
17
|
-
import { configPath as configPath2, isJiraApiError as
|
|
17
|
+
import { configPath as configPath2, isJiraApiError as isJiraApiError3 } from "@kud/jira";
|
|
18
18
|
|
|
19
19
|
// src/commands/automation.ts
|
|
20
20
|
import { readFileSync } from "fs";
|
|
@@ -344,6 +344,7 @@ var registerAttachmentCommands = (program2) => {
|
|
|
344
344
|
};
|
|
345
345
|
|
|
346
346
|
// src/commands/agile.ts
|
|
347
|
+
import { isJiraApiError as isJiraApiError2 } from "@kud/jira";
|
|
347
348
|
var issueRows = [
|
|
348
349
|
{ header: "KEY", value: (i) => i.key },
|
|
349
350
|
{ header: "STATUS", value: (i) => i.fields.status?.name ?? "\u2014" },
|
|
@@ -362,18 +363,73 @@ var writeIssues = (issues, json) => {
|
|
|
362
363
|
process.stdout.write(`${table(issues, issueRows)}
|
|
363
364
|
`);
|
|
364
365
|
};
|
|
366
|
+
var listProjectBoards = async (request, project) => {
|
|
367
|
+
const base = `/rest/agile/1.0/board?projectKeyOrId=${encodeURIComponent(project)}`;
|
|
368
|
+
const boards = [];
|
|
369
|
+
let path = base;
|
|
370
|
+
while (path) {
|
|
371
|
+
const page = await request(path);
|
|
372
|
+
const pageBoards = page.values ?? [];
|
|
373
|
+
boards.push(...pageBoards);
|
|
374
|
+
const startAt = (page.startAt ?? 0) + pageBoards.length;
|
|
375
|
+
path = page.isLast !== false || pageBoards.length === 0 ? "" : `${base}&startAt=${startAt}`;
|
|
376
|
+
}
|
|
377
|
+
return boards;
|
|
378
|
+
};
|
|
365
379
|
var registerBoardCommands = (program2) => {
|
|
366
380
|
const board = program2.command("board").description("boards, backlogs and epics");
|
|
367
|
-
board.command("list").alias("ls").description("list boards").option("--json", "emit JSON").action(async (options) => {
|
|
381
|
+
board.command("list").alias("ls").description("list boards").option("--json", "emit JSON").option("--project <key>", "filter boards by project key").action(async (options) => {
|
|
368
382
|
const ctx = context();
|
|
369
|
-
const
|
|
370
|
-
if (options.json) return printJson(
|
|
383
|
+
const boards = options.project ? await listProjectBoards(ctx.client.request, options.project) : (await ctx.client.getBoards()).values;
|
|
384
|
+
if (options.json) return printJson(boards);
|
|
371
385
|
process.stdout.write(
|
|
372
|
-
`${table(
|
|
386
|
+
`${table(boards, [
|
|
373
387
|
{ header: "ID", value: (b) => String(b.id) },
|
|
374
388
|
{ header: "NAME", value: (b) => b.name },
|
|
375
389
|
{ header: "TYPE", value: (b) => b.type ?? "\u2014" }
|
|
376
390
|
])}
|
|
391
|
+
`
|
|
392
|
+
);
|
|
393
|
+
});
|
|
394
|
+
board.command("view <id>").description("show a board's configuration and filter").option("--json", "emit JSON").action(async (id, options) => {
|
|
395
|
+
const ctx = context();
|
|
396
|
+
const config = await ctx.client.getBoardConfiguration(
|
|
397
|
+
Number(id)
|
|
398
|
+
);
|
|
399
|
+
let filter = null;
|
|
400
|
+
let unavailable = !config.filter?.id;
|
|
401
|
+
if (config.filter?.id) {
|
|
402
|
+
try {
|
|
403
|
+
filter = await ctx.client.request(
|
|
404
|
+
`/rest/api/3/filter/${config.filter.id}`
|
|
405
|
+
);
|
|
406
|
+
} catch (e) {
|
|
407
|
+
if (isJiraApiError2(e) && (e.status === 403 || e.status === 404))
|
|
408
|
+
unavailable = true;
|
|
409
|
+
else throw e;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
const statuses = await ctx.client.getStatuses();
|
|
413
|
+
const statusMap = new Map(statuses.map((s) => [s.id, s.name]));
|
|
414
|
+
if (options.json) {
|
|
415
|
+
return printJson({
|
|
416
|
+
...config,
|
|
417
|
+
filter: filter ? { ...config.filter, ...filter } : { ...config.filter, unavailable: true }
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
const { dim } = ctx.out;
|
|
421
|
+
const columns = config.columnConfig?.columns ?? [];
|
|
422
|
+
const columnLines = columns.map((col) => {
|
|
423
|
+
const statusNames = col.statuses.map((s) => statusMap.get(s.id) ?? s.id).join(", ");
|
|
424
|
+
return `${dim("column")} ${col.name} ${dim(statusNames)}`;
|
|
425
|
+
});
|
|
426
|
+
process.stdout.write(
|
|
427
|
+
`${[
|
|
428
|
+
config.name,
|
|
429
|
+
`${dim("type")} ${config.type ?? "\u2014"}`,
|
|
430
|
+
`${dim("filter")} ${filter ? `${filter.name} ${dim(filter.jql ?? "")}` : unavailable ? "unavailable" : "\u2014"}`,
|
|
431
|
+
...columnLines
|
|
432
|
+
].join("\n")}
|
|
377
433
|
`
|
|
378
434
|
);
|
|
379
435
|
});
|
|
@@ -476,7 +532,11 @@ import { adfToMarkdown as adfToMarkdown2, flattenIssueLinks as flattenIssueLinks
|
|
|
476
532
|
|
|
477
533
|
// src/commands/issue-write.ts
|
|
478
534
|
import { readFileSync as readFileSync2 } from "fs";
|
|
479
|
-
import {
|
|
535
|
+
import {
|
|
536
|
+
adfToMarkdown,
|
|
537
|
+
flattenIssueLinks,
|
|
538
|
+
markdownToAdf
|
|
539
|
+
} from "@kud/jira";
|
|
480
540
|
|
|
481
541
|
// src/commands/confirm.ts
|
|
482
542
|
import { createInterface } from "readline/promises";
|
|
@@ -498,7 +558,18 @@ var confirmDestructive = async (what, options) => {
|
|
|
498
558
|
|
|
499
559
|
// src/commands/issue-write.ts
|
|
500
560
|
var rankPosition = (options) => {
|
|
501
|
-
const { before, after } = options;
|
|
561
|
+
const { before, after, top, jql } = options;
|
|
562
|
+
if (top) {
|
|
563
|
+
if (!jql) throw exitError(1, "--top requires --jql");
|
|
564
|
+
if (before || after)
|
|
565
|
+
throw exitError(1, "--top is mutually exclusive with --before and --after");
|
|
566
|
+
return { top: true, jql };
|
|
567
|
+
}
|
|
568
|
+
if (jql)
|
|
569
|
+
throw exitError(
|
|
570
|
+
1,
|
|
571
|
+
"--jql needs --top; use --before or --after to rank against an issue"
|
|
572
|
+
);
|
|
502
573
|
if (before && after) throw exitError(1, "pass --before or --after, not both");
|
|
503
574
|
if (!before && !after)
|
|
504
575
|
throw exitError(1, "pass one of --before <key> or --after <key>");
|
|
@@ -507,6 +578,39 @@ var rankPosition = (options) => {
|
|
|
507
578
|
};
|
|
508
579
|
var readBody = (value) => value === "-" ? readFileSync2(0, "utf8") : value;
|
|
509
580
|
var projectOf = (issueKey) => issueKey.split("-")[0];
|
|
581
|
+
var TRANSITION_HINT = "the argument may be either the transition name or its target status";
|
|
582
|
+
var resolveTransition = (transitions, key, status) => {
|
|
583
|
+
const wanted = status.toLowerCase();
|
|
584
|
+
const byName = transitions.filter(
|
|
585
|
+
(t) => t.name.toLowerCase() === wanted || t.id === status
|
|
586
|
+
);
|
|
587
|
+
const byTarget = transitions.filter(
|
|
588
|
+
(t) => t.to?.name.toLowerCase() === wanted
|
|
589
|
+
);
|
|
590
|
+
const match = byName.length > 0 ? byName.length === 1 ? byName[0] : void 0 : byTarget.length === 1 ? byTarget[0] : void 0;
|
|
591
|
+
if (byName.length > 1) {
|
|
592
|
+
throw exitError(
|
|
593
|
+
1,
|
|
594
|
+
`'${status}' matches ${byName.length} transitions on ${key}: ${byName.map((t) => `${t.name} \u2192 ${t.to?.name ?? "\u2014"}`).join("; ")}`
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
if (byName.length === 0 && byTarget.length > 1) {
|
|
598
|
+
throw exitError(
|
|
599
|
+
1,
|
|
600
|
+
`${byTarget.length} transitions reach '${status}' on ${key}: ${byTarget.map((t) => `${t.name} \u2192 ${t.to?.name ?? "\u2014"}`).join("; ")}
|
|
601
|
+
Use a transition name instead`
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
if (!match) {
|
|
605
|
+
throw exitError(
|
|
606
|
+
1,
|
|
607
|
+
`no transition or status '${status}' on ${key}. Available:
|
|
608
|
+
${transitions.map((t) => ` ${t.name} \u2192 ${t.to?.name ?? "\u2014"}`).join("\n")}
|
|
609
|
+
${TRANSITION_HINT}`
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
return match;
|
|
613
|
+
};
|
|
510
614
|
var collectLink = (value, prior) => [
|
|
511
615
|
...prior,
|
|
512
616
|
value
|
|
@@ -560,7 +664,7 @@ var registerIssueWriteCommands = (issue) => {
|
|
|
560
664
|
"link the new issue to another, repeatable, e.g. Relates:ABC-2",
|
|
561
665
|
collectLink,
|
|
562
666
|
[]
|
|
563
|
-
).option("--json", "emit JSON").action(
|
|
667
|
+
).option("--status <name>", "transition the new issue to this status after creation").option("--json", "emit JSON").action(
|
|
564
668
|
async (options) => {
|
|
565
669
|
const ctx = context();
|
|
566
670
|
const fields = {
|
|
@@ -597,10 +701,51 @@ var registerIssueWriteCommands = (issue) => {
|
|
|
597
701
|
process.stderr.write(`linked ${created.key} ${link2.type} ${link2.key}
|
|
598
702
|
`);
|
|
599
703
|
}
|
|
704
|
+
if (options.status) {
|
|
705
|
+
try {
|
|
706
|
+
const found = await ctx.client.getIssue(created.key);
|
|
707
|
+
const currentStatus = found.fields.status?.name;
|
|
708
|
+
if (currentStatus && currentStatus.toLowerCase() === options.status.toLowerCase()) {
|
|
709
|
+
process.stderr.write(
|
|
710
|
+
`${created.key} is already in '${currentStatus}', not moving
|
|
711
|
+
`
|
|
712
|
+
);
|
|
713
|
+
} else {
|
|
714
|
+
const { transitions } = await ctx.client.getTransitions(
|
|
715
|
+
created.key
|
|
716
|
+
);
|
|
717
|
+
const match = resolveTransition(
|
|
718
|
+
transitions,
|
|
719
|
+
created.key,
|
|
720
|
+
options.status
|
|
721
|
+
);
|
|
722
|
+
await ctx.client.transitionIssue(created.key, match.id);
|
|
723
|
+
process.stderr.write(
|
|
724
|
+
`moved ${created.key} to ${match.to?.name ?? match.name}
|
|
725
|
+
`
|
|
726
|
+
);
|
|
727
|
+
}
|
|
728
|
+
} catch (e) {
|
|
729
|
+
throw exitError(
|
|
730
|
+
1,
|
|
731
|
+
`created ${created.key}, but moving it to ${options.status} failed: ${messageOf(e)}`
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
600
735
|
}
|
|
601
736
|
);
|
|
602
|
-
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(
|
|
737
|
+
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("--prepend-description <md>", "prepend markdown to the description; '-' reads stdin").option("--append-description <md>", "append markdown to the 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(
|
|
603
738
|
async (key, options) => {
|
|
739
|
+
if (options.body && (options.prependDescription || options.appendDescription))
|
|
740
|
+
throw exitError(
|
|
741
|
+
2,
|
|
742
|
+
"--prepend-description and --append-description are mutually exclusive with --body"
|
|
743
|
+
);
|
|
744
|
+
if (options.prependDescription === "-" && options.appendDescription === "-")
|
|
745
|
+
throw exitError(
|
|
746
|
+
2,
|
|
747
|
+
"--prepend-description and --append-description both read stdin; run two edits instead"
|
|
748
|
+
);
|
|
604
749
|
const fields = {};
|
|
605
750
|
if (options.summary) fields["summary"] = options.summary;
|
|
606
751
|
if (options.body)
|
|
@@ -616,6 +761,22 @@ var registerIssueWriteCommands = (issue) => {
|
|
|
616
761
|
);
|
|
617
762
|
fields["assignee"] = accountId ? { accountId } : null;
|
|
618
763
|
}
|
|
764
|
+
if (options.prependDescription || options.appendDescription) {
|
|
765
|
+
const ctx = context();
|
|
766
|
+
const issue2 = await ctx.client.getIssue(key);
|
|
767
|
+
const existingDescription = issue2.fields.description;
|
|
768
|
+
let existingContent = [];
|
|
769
|
+
if (existingDescription && typeof existingDescription === "object" && "content" in existingDescription) {
|
|
770
|
+
existingContent = existingDescription.content;
|
|
771
|
+
}
|
|
772
|
+
const prependContent = options.prependDescription ? markdownToAdf(readBody(options.prependDescription)).content : [];
|
|
773
|
+
const appendContent = options.appendDescription ? markdownToAdf(readBody(options.appendDescription)).content : [];
|
|
774
|
+
fields["description"] = {
|
|
775
|
+
type: "doc",
|
|
776
|
+
version: 1,
|
|
777
|
+
content: [...prependContent, ...existingContent, ...appendContent]
|
|
778
|
+
};
|
|
779
|
+
}
|
|
619
780
|
if (Object.keys(fields).length === 0)
|
|
620
781
|
throw exitError(2, "nothing to change \u2014 pass at least one option");
|
|
621
782
|
await context().client.updateIssue(key, fields);
|
|
@@ -636,22 +797,39 @@ var registerIssueWriteCommands = (issue) => {
|
|
|
636
797
|
`);
|
|
637
798
|
});
|
|
638
799
|
const comment = issue.command("comment").description("read and write comments");
|
|
639
|
-
comment.command("list <key>").alias("ls").description("comments on an issue").option("--json", "emit JSON").
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
(
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
800
|
+
comment.command("list <key>").alias("ls").description("comments on an issue").option("--json", "emit JSON").option("--last [n]", "show only the n most recent comments (default 1)").action(
|
|
801
|
+
async (key, options) => {
|
|
802
|
+
const ctx = context();
|
|
803
|
+
let lastN;
|
|
804
|
+
if (options.last !== void 0) {
|
|
805
|
+
const raw = options.last === true ? "1" : String(options.last);
|
|
806
|
+
if (!/^\d+$/.test(raw) || Number(raw) < 1)
|
|
807
|
+
throw exitError(2, "--last requires a positive integer");
|
|
808
|
+
lastN = Number(raw);
|
|
809
|
+
}
|
|
810
|
+
let comments;
|
|
811
|
+
if (lastN !== void 0) {
|
|
812
|
+
const response = await ctx.client.request(
|
|
813
|
+
`/rest/api/3/issue/${encodeURIComponent(key)}/comment?orderBy=-created&maxResults=${lastN}`
|
|
814
|
+
);
|
|
815
|
+
comments = response.comments.reverse();
|
|
816
|
+
} else {
|
|
817
|
+
comments = (await ctx.client.getComments(key)).comments;
|
|
818
|
+
}
|
|
819
|
+
if (options.json) return printJson(comments);
|
|
820
|
+
process.stdout.write(
|
|
821
|
+
`${comments.map(
|
|
822
|
+
(c) => [
|
|
823
|
+
`${ctx.out.bold(c.author?.displayName ?? "unknown")} ${ctx.out.dim(
|
|
824
|
+
`${c.created?.slice(0, 10) ?? ""} ${c.id}`
|
|
825
|
+
)}`,
|
|
826
|
+
adfToMarkdown(c.body)
|
|
827
|
+
].join("\n")
|
|
828
|
+
).join("\n\n")}
|
|
652
829
|
`
|
|
653
|
-
|
|
654
|
-
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
);
|
|
655
833
|
comment.command("add <key> <body>").description("comment on an issue; '-' reads stdin").action(async (key, body) => {
|
|
656
834
|
await context().client.addComment(key, markdownToAdf(readBody(body)));
|
|
657
835
|
process.stderr.write(`commented on ${key}
|
|
@@ -788,15 +966,44 @@ var registerIssueWriteCommands = (issue) => {
|
|
|
788
966
|
process.stderr.write(`removed remote link ${linkId} from ${key}
|
|
789
967
|
`);
|
|
790
968
|
});
|
|
791
|
-
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(
|
|
969
|
+
issue.command("rank <keys...>").description("order issues before or after another issue, or at the top of a JQL scope").option("--before <key>", "place the issues before this one").option("--after <key>", "place the issues after this one").option("--top", "rank at the top of the JQL scope (requires --jql)").option("--jql <jql>", "JQL scope for --top").action(
|
|
792
970
|
async (keys, options) => {
|
|
793
971
|
const position = rankPosition(options);
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
972
|
+
if (!("top" in position)) {
|
|
973
|
+
await context().client.rankIssues(keys, position);
|
|
974
|
+
const anchor2 = "before" in position ? position.before : position.after;
|
|
975
|
+
process.stderr.write(
|
|
976
|
+
`ranked ${keys.join(", ")} ${"before" in position ? "before" : "after"} ${anchor2}
|
|
798
977
|
`
|
|
799
|
-
|
|
978
|
+
);
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
981
|
+
const jql = position.jql.trim();
|
|
982
|
+
const orderByMatch = jql.match(/\bORDER\s+BY\s+(.+)$/i);
|
|
983
|
+
if (orderByMatch && !/^Rank(\s+ASC)?$/i.test(orderByMatch[1].trim()))
|
|
984
|
+
throw exitError(
|
|
985
|
+
1,
|
|
986
|
+
`foreign ORDER BY is not supported with --top: '${orderByMatch[1].trim()}'. Remove it, or use ORDER BY Rank ASC`
|
|
987
|
+
);
|
|
988
|
+
position.jql = orderByMatch ? jql : `${jql} ORDER BY Rank ASC`;
|
|
989
|
+
const ctx = context();
|
|
990
|
+
const issues = await ctx.client.searchIssues(position.jql, {
|
|
991
|
+
limit: keys.length + 1
|
|
992
|
+
});
|
|
993
|
+
if (issues.length === 0)
|
|
994
|
+
throw exitError(1, `no issues match: ${position.jql}`);
|
|
995
|
+
const wanted = keys.map((k) => k.toLowerCase());
|
|
996
|
+
const alreadyTop = issues.length >= keys.length && issues.slice(0, keys.length).every((issue2, index) => issue2.key.toLowerCase() === wanted[index]);
|
|
997
|
+
const anchor = alreadyTop ? void 0 : issues.find((i) => !wanted.includes(i.key.toLowerCase()));
|
|
998
|
+
if (!anchor) {
|
|
999
|
+
process.stderr.write(
|
|
1000
|
+
alreadyTop ? "issues already at the top in order\n" : "no issue outside the given keys in the scope to rank against\n"
|
|
1001
|
+
);
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
await ctx.client.rankIssues(keys, { before: anchor.key });
|
|
1005
|
+
process.stderr.write(`ranked ${keys.join(", ")} before ${anchor.key}
|
|
1006
|
+
`);
|
|
800
1007
|
}
|
|
801
1008
|
);
|
|
802
1009
|
const link = issue.command("link").description("link two issues, e.g. jira issue link ABC-1 Blocks ABC-2");
|
|
@@ -989,35 +1196,7 @@ var registerIssueCommands = (program2) => {
|
|
|
989
1196
|
process.stderr.write(TRANSITION_HINT + "\n");
|
|
990
1197
|
return;
|
|
991
1198
|
}
|
|
992
|
-
const
|
|
993
|
-
const byName = transitions.filter(
|
|
994
|
-
(t) => t.name.toLowerCase() === wanted || t.id === status
|
|
995
|
-
);
|
|
996
|
-
const byTarget = transitions.filter(
|
|
997
|
-
(t) => t.to?.name.toLowerCase() === wanted
|
|
998
|
-
);
|
|
999
|
-
const match = byName.length > 0 ? byName.length === 1 ? byName[0] : void 0 : byTarget.length === 1 ? byTarget[0] : void 0;
|
|
1000
|
-
if (byName.length > 1) {
|
|
1001
|
-
throw exitError(
|
|
1002
|
-
1,
|
|
1003
|
-
`'${status}' matches ${byName.length} transitions on ${key}: ${byName.map((t) => `${t.name} \u2192 ${t.to?.name ?? "\u2014"}`).join("; ")}`
|
|
1004
|
-
);
|
|
1005
|
-
}
|
|
1006
|
-
if (byName.length === 0 && byTarget.length > 1) {
|
|
1007
|
-
throw exitError(
|
|
1008
|
-
1,
|
|
1009
|
-
`${byTarget.length} transitions reach '${status}' on ${key}: ${byTarget.map((t) => `${t.name} \u2192 ${t.to?.name ?? "\u2014"}`).join("; ")}
|
|
1010
|
-
Use a transition name instead`
|
|
1011
|
-
);
|
|
1012
|
-
}
|
|
1013
|
-
if (!match) {
|
|
1014
|
-
throw exitError(
|
|
1015
|
-
1,
|
|
1016
|
-
`no transition or status '${status}' on ${key}. Available:
|
|
1017
|
-
${transitions.map((t) => ` ${t.name} \u2192 ${t.to?.name ?? "\u2014"}`).join("\n")}
|
|
1018
|
-
${TRANSITION_HINT}`
|
|
1019
|
-
);
|
|
1020
|
-
}
|
|
1199
|
+
const match = resolveTransition(transitions, key, status);
|
|
1021
1200
|
await ctx.client.transitionIssue(
|
|
1022
1201
|
key,
|
|
1023
1202
|
match.id,
|
|
@@ -1041,7 +1220,6 @@ ${TRANSITION_HINT}`
|
|
|
1041
1220
|
});
|
|
1042
1221
|
};
|
|
1043
1222
|
var issueUrl = (ctx, key) => `${ctx.config.baseUrl.replace(/\/$/, "")}/browse/${key}`;
|
|
1044
|
-
var TRANSITION_HINT = "the argument may be either the transition name or its target status";
|
|
1045
1223
|
var formatField = (value) => {
|
|
1046
1224
|
if (value == null) return "\u2014";
|
|
1047
1225
|
if (typeof value === "object") {
|
|
@@ -1386,7 +1564,7 @@ registerAutomationCommands(program);
|
|
|
1386
1564
|
registerApiCommand(program);
|
|
1387
1565
|
var exitCodeFor = (error) => {
|
|
1388
1566
|
if (isExitError(error)) return error.code;
|
|
1389
|
-
if (
|
|
1567
|
+
if (isJiraApiError3(error))
|
|
1390
1568
|
return error.status === 401 || error.status === 403 ? 4 : 1;
|
|
1391
1569
|
return 1;
|
|
1392
1570
|
};
|