@kud/jira-cli 0.12.0 โ 0.13.1
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 +50 -209
- package/dist/index.js +288 -78
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,236 +1,77 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
๐ซ
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
# Jira CLI
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Setup
|
|
14
|
-
|
|
15
|
-
Only the token is a secret, so only the token comes from the environment:
|
|
16
|
-
|
|
17
|
-
```sh
|
|
18
|
-
export ATLASSIAN_API_TOKEN=... # id.atlassian.com/manage-profile/security/api-tokens
|
|
19
|
-
jira init --base-url myorg.atlassian.net --email you@example.com
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
That writes `~/.config/jira/config.json`. `ATLASSIAN_BASE_URL` and `ATLASSIAN_USER_EMAIL` override it when you need a second instance.
|
|
23
|
-
|
|
24
|
-
## Attachments
|
|
25
|
-
|
|
26
|
-
The thing most Jira CLIs skip. Attachments are listed with the comment they came from, and text ones print straight to stdout:
|
|
27
|
-
|
|
28
|
-
```sh
|
|
29
|
-
jira attachment list ABC-123
|
|
30
|
-
# ID FILENAME SIZE TYPE FROM
|
|
31
|
-
# 292542 error.log 22.0KB text/plain comment by Ada Lovelace
|
|
32
|
-
# 292731 screen.png 118KB image/png description
|
|
33
|
-
|
|
34
|
-
jira attachment read ABC-123 error.log | grep -i timeout
|
|
35
|
-
jira attachment get ABC-123 screen.png --output ~/Desktop/
|
|
36
|
-
jira attachment upload ABC-123 ./build.log ./screenshot.png
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
Descriptions and comments render as Markdown, with embedded files named rather than left as opaque ids:
|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
40
11
|
|
|
41
|
-
|
|
42
|
-
jira issue view ABC-123 --comments
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## The interactive view
|
|
46
|
-
|
|
47
|
-
Run `jira` with no arguments:
|
|
48
|
-
|
|
49
|
-
```sh
|
|
50
|
-
jira
|
|
51
|
-
```
|
|
52
|
-
|
|
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.
|
|
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.
|
|
12
|
+
**Jira on the command line โ read issues, comments and attachments as plain text**
|
|
56
13
|
|
|
57
|
-
|
|
14
|
+
<a href="https://kud.io/projects/jira-cli">Website</a> ยท <a href="https://kud.io/projects/jira-cli/docs">Documentation</a>
|
|
58
15
|
|
|
59
|
-
|
|
16
|
+
</div>
|
|
60
17
|
|
|
61
|
-
|
|
18
|
+
## Features
|
|
62
19
|
|
|
63
|
-
|
|
20
|
+
- **Attachments as text** โ list what is attached, with the comment it came from, and print text files straight to stdout or download the rest
|
|
21
|
+
- **Plain and pipeable** โ black and white output, `--json` on every read, stable exit codes
|
|
22
|
+
- **Full issue workflow** โ create, edit, transition (with a resolution), comment, link, watch, rank and log work
|
|
23
|
+
- **Projects, boards and sprints** โ browse projects, boards, sprints, epics and the backlog
|
|
24
|
+
- **Automation rules** โ list, export, import and switch Jira Automation rules, with secrets redacted on request
|
|
25
|
+
- **Interactive board** โ bare `jira` opens your issues as tabs, with search and in-place writes; Ink loads only for this view
|
|
64
26
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
```sh
|
|
68
|
-
jira attachment list ABC-123 # what is there, and where it came from
|
|
69
|
-
jira attachment read ABC-123 error.log # text, straight to stdout
|
|
70
|
-
jira attachment get ABC-123 shot.png -o /tmp/shot.png # then open or read it
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
Useful for agents in particular: `get` writes a real file, so an image can then be read and reasoned about rather than skipped.
|
|
74
|
-
|
|
75
|
-
## Issues
|
|
76
|
-
|
|
77
|
-
```sh
|
|
78
|
-
jira issue list # yours, most recently updated first
|
|
79
|
-
jira issue list --status 'In Progress'
|
|
80
|
-
jira issue list --project ABC --sprint current
|
|
81
|
-
jira issue view ABC-123
|
|
82
|
-
jira issue view ABC-123 --fields status,assignee,issuelinks
|
|
83
|
-
jira issue transition ABC-123 # list what's available
|
|
84
|
-
jira issue transition ABC-123 'In Review' # by transition name or target status
|
|
85
|
-
jira issue open ABC-123
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
Writing:
|
|
89
|
-
|
|
90
|
-
```sh
|
|
91
|
-
jira issue create -p ABC -t Task -s 'Fix the thing' -b 'Longer **markdown** body'
|
|
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'
|
|
95
|
-
jira issue comment add ABC-123 - # body from stdin
|
|
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
|
|
100
|
-
jira issue link ABC-1 Blocks ABC-2
|
|
101
|
-
jira issue link list ABC-1
|
|
102
|
-
jira issue watch add ABC-123
|
|
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
|
|
109
|
-
jira issue history ABC-123
|
|
110
|
-
```
|
|
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
|
-
|
|
120
|
-
Bodies accept Markdown โ paragraphs, headings, lists, fenced code, links and code spans are converted to ADF.
|
|
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
|
-
|
|
124
|
-
## Projects, boards and sprints
|
|
125
|
-
|
|
126
|
-
```sh
|
|
127
|
-
jira project list
|
|
128
|
-
jira project versions ABC
|
|
129
|
-
jira project components ABC
|
|
130
|
-
jira project statuses ABC
|
|
131
|
-
|
|
132
|
-
jira board list
|
|
133
|
-
jira board issues 42
|
|
134
|
-
jira board backlog 42
|
|
135
|
-
jira board epics 42
|
|
136
|
-
jira epic ABC-100
|
|
137
|
-
|
|
138
|
-
jira sprint list 42 --state active
|
|
139
|
-
jira sprint issues 1234
|
|
140
|
-
jira sprint add 1234 ABC-1 ABC-2
|
|
141
|
-
jira backlog add ABC-1 ABC-2
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
## Knowing what this instance supports
|
|
145
|
-
|
|
146
|
-
```sh
|
|
147
|
-
jira whoami
|
|
148
|
-
jira meta issuetypes # also: priorities, statuses, resolutions, linktypes
|
|
149
|
-
jira meta labels
|
|
150
|
-
jira meta filters
|
|
151
|
-
jira meta permissions ABC
|
|
152
|
-
jira meta server
|
|
153
|
-
jira count 'project = ABC AND status = Done'
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
## Scripting
|
|
157
|
-
|
|
158
|
-
Every read command takes `--json`:
|
|
27
|
+
## Install
|
|
159
28
|
|
|
160
29
|
```sh
|
|
161
|
-
|
|
162
|
-
jira search 'project = ABC AND created >= -7d' --json
|
|
30
|
+
npm install -g @kud/jira-cli
|
|
163
31
|
```
|
|
164
32
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
| Code | Means |
|
|
168
|
-
| ---- | --------------------------------------- |
|
|
169
|
-
| `0` | success |
|
|
170
|
-
| `1` | Jira rejected the request, or bad usage |
|
|
171
|
-
| `2` | the environment is not set up |
|
|
172
|
-
| `3` | `--json` result may be truncated |
|
|
173
|
-
| `4` | not authenticated |
|
|
174
|
-
|
|
175
|
-
`issue list` and `search` stop at `--limit` (50 by default), and Jira no longer
|
|
176
|
-
reports a total, so a full page is the only evidence that rows were left behind.
|
|
177
|
-
When one comes back, both commands warn on stderr, and with `--json` they also
|
|
178
|
-
exit `3`. Stdout is untouched, so `--json` parses exactly as before and a caller
|
|
179
|
-
that ignores the exit code sees no change. The table output keeps exiting `0`,
|
|
180
|
-
so `jira issue list && โฆ` still works at a terminal.
|
|
181
|
-
Raise `--limit` to be sure you have it all.
|
|
182
|
-
|
|
183
|
-
Colour is disabled automatically when stdout is not a TTY, and when `NO_COLOR` is set.
|
|
33
|
+
## Usage
|
|
184
34
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
Jira instances differ. Find yours, then name the ones you care about:
|
|
35
|
+
Only the API token is a secret, so only the token comes from the environment:
|
|
188
36
|
|
|
189
37
|
```sh
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
# customfield_10784 Offshore Story Points string
|
|
193
|
-
# customfield_10002 Story Points number
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
```json
|
|
197
|
-
{
|
|
198
|
-
"baseUrl": "myorg.atlassian.net",
|
|
199
|
-
"email": "you@example.com",
|
|
200
|
-
"customFields": [{ "id": "customfield_10002", "label": "points" }],
|
|
201
|
-
"sprintField": "customfield_10020",
|
|
202
|
-
"defaultProject": "ABC"
|
|
203
|
-
}
|
|
38
|
+
export ATLASSIAN_API_TOKEN=...
|
|
39
|
+
jira init --base-url jira.example.com --email you@example.com
|
|
204
40
|
```
|
|
205
41
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
jira
|
|
213
|
-
jira
|
|
214
|
-
jira
|
|
215
|
-
jira
|
|
216
|
-
jira
|
|
42
|
+
```console
|
|
43
|
+
$ jira attachment list ACME-1234
|
|
44
|
+
ID FILENAME SIZE TYPE FROM
|
|
45
|
+
292542 error.log 22.0KB text/plain comment by Ada Lovelace
|
|
46
|
+
292731 screen.png 118KB image/png description
|
|
47
|
+
|
|
48
|
+
$ jira attachment read ACME-1234 error.log | grep -i timeout
|
|
49
|
+
$ jira issue view ACME-1234 --fields status,assignee,issuelinks
|
|
50
|
+
$ jira issue transition ACME-1234 Done --resolution Fixed
|
|
51
|
+
$ jira issue open ACME-1234 --print
|
|
52
|
+
$ jira issue watch list ACME-1234
|
|
53
|
+
$ jira issue worklog edit ACME-1234 456 --time 3h --started 2026-10-27T09:00:00.000+0000
|
|
54
|
+
$ jira issue comment delete ACME-1234 12345
|
|
55
|
+
$ jira user search ada --project ACME
|
|
56
|
+
$ jira project view ACME
|
|
57
|
+
$ jira sprint view 1234
|
|
58
|
+
$ jira search 'project = ACME AND created >= -7d' --json | jq -r '.[].key'
|
|
59
|
+
$ jira automation get 0192e5ac-0e25-71de-ba7b-d972e6a2049a --redact
|
|
217
60
|
```
|
|
218
61
|
|
|
219
|
-
|
|
62
|
+
Run `jira` with no arguments in a terminal for the interactive board. Inside an issue, description, comments and attachments sit in one scrolling view. Two flags help when exploring it: `--screen detail:ACME-1234` opens an issue directly (`--screen list` prints the available screens), and `--mock` runs against built-in sample data with no Jira needed.
|
|
220
63
|
|
|
221
|
-
|
|
64
|
+
Exit codes: `0` success, `1` Jira rejected the request or bad usage, `2` environment not set up, `3` `--json` result may be truncated, `4` not authenticated.
|
|
222
65
|
|
|
223
|
-
|
|
66
|
+
Anything not covered has an escape hatch: `jira api /rest/api/3/myself`.
|
|
224
67
|
|
|
225
|
-
|
|
68
|
+
## Development
|
|
226
69
|
|
|
227
70
|
```sh
|
|
228
|
-
|
|
229
|
-
jira
|
|
71
|
+
git clone https://github.com/kud/jira-cli.git
|
|
72
|
+
cd jira-cli
|
|
73
|
+
npm install
|
|
74
|
+
npm run dev
|
|
230
75
|
```
|
|
231
76
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
## Licence
|
|
235
|
-
|
|
236
|
-
MIT
|
|
77
|
+
๐ **Full documentation โ [jira-cli/docs](https://kud.io/projects/jira-cli/docs)**
|
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 isJiraApiError4 } 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,13 @@ 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
|
+
errorMessagesOf,
|
|
538
|
+
flattenIssueLinks,
|
|
539
|
+
isJiraApiError as isJiraApiError3,
|
|
540
|
+
markdownToAdf
|
|
541
|
+
} from "@kud/jira";
|
|
480
542
|
|
|
481
543
|
// src/commands/confirm.ts
|
|
482
544
|
import { createInterface } from "readline/promises";
|
|
@@ -498,7 +560,21 @@ var confirmDestructive = async (what, options) => {
|
|
|
498
560
|
|
|
499
561
|
// src/commands/issue-write.ts
|
|
500
562
|
var rankPosition = (options) => {
|
|
501
|
-
const { before, after } = options;
|
|
563
|
+
const { before, after, top, jql } = options;
|
|
564
|
+
if (top) {
|
|
565
|
+
if (!jql) throw exitError(1, "--top requires --jql");
|
|
566
|
+
if (before || after)
|
|
567
|
+
throw exitError(
|
|
568
|
+
1,
|
|
569
|
+
"--top is mutually exclusive with --before and --after"
|
|
570
|
+
);
|
|
571
|
+
return { top: true, jql };
|
|
572
|
+
}
|
|
573
|
+
if (jql)
|
|
574
|
+
throw exitError(
|
|
575
|
+
1,
|
|
576
|
+
"--jql needs --top; use --before or --after to rank against an issue"
|
|
577
|
+
);
|
|
502
578
|
if (before && after) throw exitError(1, "pass --before or --after, not both");
|
|
503
579
|
if (!before && !after)
|
|
504
580
|
throw exitError(1, "pass one of --before <key> or --after <key>");
|
|
@@ -507,6 +583,39 @@ var rankPosition = (options) => {
|
|
|
507
583
|
};
|
|
508
584
|
var readBody = (value) => value === "-" ? readFileSync2(0, "utf8") : value;
|
|
509
585
|
var projectOf = (issueKey) => issueKey.split("-")[0];
|
|
586
|
+
var TRANSITION_HINT = "the argument may be either the transition name or its target status";
|
|
587
|
+
var resolveTransition = (transitions, key, status) => {
|
|
588
|
+
const wanted = status.toLowerCase();
|
|
589
|
+
const byName = transitions.filter(
|
|
590
|
+
(t) => t.name.toLowerCase() === wanted || t.id === status
|
|
591
|
+
);
|
|
592
|
+
const byTarget = transitions.filter(
|
|
593
|
+
(t) => t.to?.name.toLowerCase() === wanted
|
|
594
|
+
);
|
|
595
|
+
const match = byName.length > 0 ? byName.length === 1 ? byName[0] : void 0 : byTarget.length === 1 ? byTarget[0] : void 0;
|
|
596
|
+
if (byName.length > 1) {
|
|
597
|
+
throw exitError(
|
|
598
|
+
1,
|
|
599
|
+
`'${status}' matches ${byName.length} transitions on ${key}: ${byName.map((t) => `${t.name} \u2192 ${t.to?.name ?? "\u2014"}`).join("; ")}`
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
if (byName.length === 0 && byTarget.length > 1) {
|
|
603
|
+
throw exitError(
|
|
604
|
+
1,
|
|
605
|
+
`${byTarget.length} transitions reach '${status}' on ${key}: ${byTarget.map((t) => `${t.name} \u2192 ${t.to?.name ?? "\u2014"}`).join("; ")}
|
|
606
|
+
Use a transition name instead`
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
if (!match) {
|
|
610
|
+
throw exitError(
|
|
611
|
+
1,
|
|
612
|
+
`no transition or status '${status}' on ${key}. Available:
|
|
613
|
+
${transitions.map((t) => ` ${t.name} \u2192 ${t.to?.name ?? "\u2014"}`).join("\n")}
|
|
614
|
+
${TRANSITION_HINT}`
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
return match;
|
|
618
|
+
};
|
|
510
619
|
var collectLink = (value, prior) => [
|
|
511
620
|
...prior,
|
|
512
621
|
value
|
|
@@ -529,10 +638,7 @@ var parseLinkSpecs = (link, types) => {
|
|
|
529
638
|
(t) => t.name.toLowerCase() === type.toLowerCase()
|
|
530
639
|
);
|
|
531
640
|
if (!resolved)
|
|
532
|
-
throw exitError(
|
|
533
|
-
1,
|
|
534
|
-
`no link type '${type}'. Valid: ${titles.join(", ")}`
|
|
535
|
-
);
|
|
641
|
+
throw exitError(1, `no link type '${type}'. Valid: ${titles.join(", ")}`);
|
|
536
642
|
return { type: resolved.name, key };
|
|
537
643
|
});
|
|
538
644
|
};
|
|
@@ -544,22 +650,29 @@ var resolveAccountId = async (who, projectKey) => {
|
|
|
544
650
|
const assignable = projectKey ? await ctx.client.searchAssignableUsers(who, projectKey) : [];
|
|
545
651
|
const candidates = assignable.length > 0 ? assignable : await ctx.client.searchUsers(who);
|
|
546
652
|
if (candidates.length === 0) throw exitError(1, `no user matching '${who}'`);
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
653
|
+
const wanted = who.trim().toLowerCase();
|
|
654
|
+
const exact = candidates.filter(
|
|
655
|
+
(u) => u.displayName?.toLowerCase() === wanted || u.emailAddress?.toLowerCase() === wanted
|
|
656
|
+
);
|
|
657
|
+
const active = exact.filter((u) => u.active !== false);
|
|
658
|
+
if (active.length === 1) return active[0].accountId;
|
|
659
|
+
for (const u of candidates) process.stderr.write(`${candidateLine(u)}
|
|
660
|
+
`);
|
|
661
|
+
throw exitError(
|
|
662
|
+
1,
|
|
663
|
+
active.length > 1 ? `'${who}' matches ${active.length} active users exactly \u2014 retry with an account id or email` : exact.length > 0 ? `'${who}' matches only inactive or unassignable users \u2014 retry with an assignable account` : `'${who}' has no exact match among ${candidates.length} result${candidates.length === 1 ? "" : "s"} \u2014 retry with the exact name, email, or account id`
|
|
664
|
+
);
|
|
556
665
|
};
|
|
666
|
+
var candidateLine = (u) => `${u.displayName}${u.emailAddress ? ` ${u.emailAddress}` : ""} ${u.accountId}${u.active === false ? " (inactive)" : ""}`;
|
|
557
667
|
var registerIssueWriteCommands = (issue) => {
|
|
558
668
|
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(
|
|
559
669
|
"--link <type:key>",
|
|
560
670
|
"link the new issue to another, repeatable, e.g. Relates:ABC-2",
|
|
561
671
|
collectLink,
|
|
562
672
|
[]
|
|
673
|
+
).option(
|
|
674
|
+
"--status <name>",
|
|
675
|
+
"transition the new issue to this status after creation"
|
|
563
676
|
).option("--json", "emit JSON").action(
|
|
564
677
|
async (options) => {
|
|
565
678
|
const ctx = context();
|
|
@@ -594,13 +707,62 @@ var registerIssueWriteCommands = (issue) => {
|
|
|
594
707
|
`created ${created.key}, but the ${link2.type} link to ${link2.key} failed: ${messageOf(e)}`
|
|
595
708
|
);
|
|
596
709
|
}
|
|
597
|
-
process.stderr.write(
|
|
598
|
-
`
|
|
710
|
+
process.stderr.write(
|
|
711
|
+
`linked ${created.key} ${link2.type} ${link2.key}
|
|
712
|
+
`
|
|
713
|
+
);
|
|
714
|
+
}
|
|
715
|
+
if (options.status) {
|
|
716
|
+
try {
|
|
717
|
+
const found = await ctx.client.getIssue(created.key);
|
|
718
|
+
const currentStatus = found.fields.status?.name;
|
|
719
|
+
if (currentStatus && currentStatus.toLowerCase() === options.status.toLowerCase()) {
|
|
720
|
+
process.stderr.write(
|
|
721
|
+
`${created.key} is already in '${currentStatus}', not moving
|
|
722
|
+
`
|
|
723
|
+
);
|
|
724
|
+
} else {
|
|
725
|
+
const { transitions } = await ctx.client.getTransitions(
|
|
726
|
+
created.key
|
|
727
|
+
);
|
|
728
|
+
const match = resolveTransition(
|
|
729
|
+
transitions,
|
|
730
|
+
created.key,
|
|
731
|
+
options.status
|
|
732
|
+
);
|
|
733
|
+
await ctx.client.transitionIssue(created.key, match.id);
|
|
734
|
+
process.stderr.write(
|
|
735
|
+
`moved ${created.key} to ${match.to?.name ?? match.name}
|
|
736
|
+
`
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
} catch (e) {
|
|
740
|
+
throw exitError(
|
|
741
|
+
1,
|
|
742
|
+
`created ${created.key}, but moving it to ${options.status} failed: ${messageOf(e)}`
|
|
743
|
+
);
|
|
744
|
+
}
|
|
599
745
|
}
|
|
600
746
|
}
|
|
601
747
|
);
|
|
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(
|
|
748
|
+
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(
|
|
749
|
+
"--prepend-description <md>",
|
|
750
|
+
"prepend markdown to the description; '-' reads stdin"
|
|
751
|
+
).option(
|
|
752
|
+
"--append-description <md>",
|
|
753
|
+
"append markdown to the description; '-' reads stdin"
|
|
754
|
+
).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
755
|
async (key, options) => {
|
|
756
|
+
if (options.body && (options.prependDescription || options.appendDescription))
|
|
757
|
+
throw exitError(
|
|
758
|
+
2,
|
|
759
|
+
"--prepend-description and --append-description are mutually exclusive with --body"
|
|
760
|
+
);
|
|
761
|
+
if (options.prependDescription === "-" && options.appendDescription === "-")
|
|
762
|
+
throw exitError(
|
|
763
|
+
2,
|
|
764
|
+
"--prepend-description and --append-description both read stdin; run two edits instead"
|
|
765
|
+
);
|
|
604
766
|
const fields = {};
|
|
605
767
|
if (options.summary) fields["summary"] = options.summary;
|
|
606
768
|
if (options.body)
|
|
@@ -616,6 +778,22 @@ var registerIssueWriteCommands = (issue) => {
|
|
|
616
778
|
);
|
|
617
779
|
fields["assignee"] = accountId ? { accountId } : null;
|
|
618
780
|
}
|
|
781
|
+
if (options.prependDescription || options.appendDescription) {
|
|
782
|
+
const ctx = context();
|
|
783
|
+
const issue2 = await ctx.client.getIssue(key);
|
|
784
|
+
const existingDescription = issue2.fields.description;
|
|
785
|
+
let existingContent = [];
|
|
786
|
+
if (existingDescription && typeof existingDescription === "object" && "content" in existingDescription) {
|
|
787
|
+
existingContent = existingDescription.content;
|
|
788
|
+
}
|
|
789
|
+
const prependContent = options.prependDescription ? markdownToAdf(readBody(options.prependDescription)).content : [];
|
|
790
|
+
const appendContent = options.appendDescription ? markdownToAdf(readBody(options.appendDescription)).content : [];
|
|
791
|
+
fields["description"] = {
|
|
792
|
+
type: "doc",
|
|
793
|
+
version: 1,
|
|
794
|
+
content: [...prependContent, ...existingContent, ...appendContent]
|
|
795
|
+
};
|
|
796
|
+
}
|
|
619
797
|
if (Object.keys(fields).length === 0)
|
|
620
798
|
throw exitError(2, "nothing to change \u2014 pass at least one option");
|
|
621
799
|
await context().client.updateIssue(key, fields);
|
|
@@ -630,28 +808,58 @@ var registerIssueWriteCommands = (issue) => {
|
|
|
630
808
|
`);
|
|
631
809
|
});
|
|
632
810
|
issue.command("assign <key> <who>").description("assign an issue; 'me', a name, or 'none' all work").action(async (key, who) => {
|
|
633
|
-
const accountId = await resolveAccountId(who, projectOf(key));
|
|
634
|
-
await context().client.assignIssue(key, accountId);
|
|
635
|
-
process.stderr.write(`${key} assigned to ${accountId ? who : "nobody"}
|
|
636
|
-
`);
|
|
637
|
-
});
|
|
638
|
-
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").action(async (key, options) => {
|
|
640
811
|
const ctx = context();
|
|
641
|
-
const
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
)}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
812
|
+
const accountId = await resolveAccountId(who, projectOf(key));
|
|
813
|
+
try {
|
|
814
|
+
await ctx.client.assignIssue(key, accountId);
|
|
815
|
+
} catch (e) {
|
|
816
|
+
if (isJiraApiError3(e))
|
|
817
|
+
throw exitError(
|
|
818
|
+
1,
|
|
819
|
+
`could not assign ${key}: ${errorMessagesOf(e).join("; ")}`
|
|
820
|
+
);
|
|
821
|
+
throw e;
|
|
822
|
+
}
|
|
823
|
+
const after = await ctx.client.getIssue(key);
|
|
824
|
+
process.stderr.write(
|
|
825
|
+
`${key} assigned to ${after.fields.assignee?.displayName ?? "nobody"}
|
|
652
826
|
`
|
|
653
827
|
);
|
|
654
828
|
});
|
|
829
|
+
const comment = issue.command("comment").description("read and write comments");
|
|
830
|
+
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(
|
|
831
|
+
async (key, options) => {
|
|
832
|
+
const ctx = context();
|
|
833
|
+
let lastN;
|
|
834
|
+
if (options.last !== void 0) {
|
|
835
|
+
const raw = options.last === true ? "1" : String(options.last);
|
|
836
|
+
if (!/^\d+$/.test(raw) || Number(raw) < 1)
|
|
837
|
+
throw exitError(2, "--last requires a positive integer");
|
|
838
|
+
lastN = Number(raw);
|
|
839
|
+
}
|
|
840
|
+
let comments;
|
|
841
|
+
if (lastN !== void 0) {
|
|
842
|
+
const response = await ctx.client.request(
|
|
843
|
+
`/rest/api/3/issue/${encodeURIComponent(key)}/comment?orderBy=-created&maxResults=${lastN}`
|
|
844
|
+
);
|
|
845
|
+
comments = response.comments.reverse();
|
|
846
|
+
} else {
|
|
847
|
+
comments = (await ctx.client.getComments(key)).comments;
|
|
848
|
+
}
|
|
849
|
+
if (options.json) return printJson(comments);
|
|
850
|
+
process.stdout.write(
|
|
851
|
+
`${comments.map(
|
|
852
|
+
(c) => [
|
|
853
|
+
`${ctx.out.bold(c.author?.displayName ?? "unknown")} ${ctx.out.dim(
|
|
854
|
+
`${c.created?.slice(0, 10) ?? ""} ${c.id}`
|
|
855
|
+
)}`,
|
|
856
|
+
adfToMarkdown(c.body)
|
|
857
|
+
].join("\n")
|
|
858
|
+
).join("\n\n")}
|
|
859
|
+
`
|
|
860
|
+
);
|
|
861
|
+
}
|
|
862
|
+
);
|
|
655
863
|
comment.command("add <key> <body>").description("comment on an issue; '-' reads stdin").action(async (key, body) => {
|
|
656
864
|
await context().client.addComment(key, markdownToAdf(readBody(body)));
|
|
657
865
|
process.stderr.write(`commented on ${key}
|
|
@@ -788,15 +996,46 @@ var registerIssueWriteCommands = (issue) => {
|
|
|
788
996
|
process.stderr.write(`removed remote link ${linkId} from ${key}
|
|
789
997
|
`);
|
|
790
998
|
});
|
|
791
|
-
issue.command("rank <keys...>").description(
|
|
999
|
+
issue.command("rank <keys...>").description(
|
|
1000
|
+
"order issues before or after another issue, or at the top of a JQL scope"
|
|
1001
|
+
).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
1002
|
async (keys, options) => {
|
|
793
1003
|
const position = rankPosition(options);
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
1004
|
+
if (!("top" in position)) {
|
|
1005
|
+
await context().client.rankIssues(keys, position);
|
|
1006
|
+
const anchor2 = "before" in position ? position.before : position.after;
|
|
1007
|
+
process.stderr.write(
|
|
1008
|
+
`ranked ${keys.join(", ")} ${"before" in position ? "before" : "after"} ${anchor2}
|
|
798
1009
|
`
|
|
799
|
-
|
|
1010
|
+
);
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
const jql = position.jql.trim();
|
|
1014
|
+
const orderByMatch = jql.match(/\bORDER\s+BY\s+(.+)$/i);
|
|
1015
|
+
if (orderByMatch && !/^Rank(\s+ASC)?$/i.test(orderByMatch[1].trim()))
|
|
1016
|
+
throw exitError(
|
|
1017
|
+
1,
|
|
1018
|
+
`foreign ORDER BY is not supported with --top: '${orderByMatch[1].trim()}'. Remove it, or use ORDER BY Rank ASC`
|
|
1019
|
+
);
|
|
1020
|
+
position.jql = orderByMatch ? jql : `${jql} ORDER BY Rank ASC`;
|
|
1021
|
+
const ctx = context();
|
|
1022
|
+
const issues = await ctx.client.searchIssues(position.jql, {
|
|
1023
|
+
limit: keys.length + 1
|
|
1024
|
+
});
|
|
1025
|
+
if (issues.length === 0)
|
|
1026
|
+
throw exitError(1, `no issues match: ${position.jql}`);
|
|
1027
|
+
const wanted = keys.map((k) => k.toLowerCase());
|
|
1028
|
+
const alreadyTop = issues.length >= keys.length && issues.slice(0, keys.length).every((issue2, index) => issue2.key.toLowerCase() === wanted[index]);
|
|
1029
|
+
const anchor = alreadyTop ? void 0 : issues.find((i) => !wanted.includes(i.key.toLowerCase()));
|
|
1030
|
+
if (!anchor) {
|
|
1031
|
+
process.stderr.write(
|
|
1032
|
+
alreadyTop ? "issues already at the top in order\n" : "no issue outside the given keys in the scope to rank against\n"
|
|
1033
|
+
);
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
await ctx.client.rankIssues(keys, { before: anchor.key });
|
|
1037
|
+
process.stderr.write(`ranked ${keys.join(", ")} before ${anchor.key}
|
|
1038
|
+
`);
|
|
800
1039
|
}
|
|
801
1040
|
);
|
|
802
1041
|
const link = issue.command("link").description("link two issues, e.g. jira issue link ABC-1 Blocks ABC-2");
|
|
@@ -989,35 +1228,7 @@ var registerIssueCommands = (program2) => {
|
|
|
989
1228
|
process.stderr.write(TRANSITION_HINT + "\n");
|
|
990
1229
|
return;
|
|
991
1230
|
}
|
|
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
|
-
}
|
|
1231
|
+
const match = resolveTransition(transitions, key, status);
|
|
1021
1232
|
await ctx.client.transitionIssue(
|
|
1022
1233
|
key,
|
|
1023
1234
|
match.id,
|
|
@@ -1041,7 +1252,6 @@ ${TRANSITION_HINT}`
|
|
|
1041
1252
|
});
|
|
1042
1253
|
};
|
|
1043
1254
|
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
1255
|
var formatField = (value) => {
|
|
1046
1256
|
if (value == null) return "\u2014";
|
|
1047
1257
|
if (typeof value === "object") {
|
|
@@ -1386,7 +1596,7 @@ registerAutomationCommands(program);
|
|
|
1386
1596
|
registerApiCommand(program);
|
|
1387
1597
|
var exitCodeFor = (error) => {
|
|
1388
1598
|
if (isExitError(error)) return error.code;
|
|
1389
|
-
if (
|
|
1599
|
+
if (isJiraApiError4(error))
|
|
1390
1600
|
return error.status === 401 || error.status === 403 ? 4 : 1;
|
|
1391
1601
|
return 1;
|
|
1392
1602
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kud/jira-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Jira on the command line โ read issues, comments and attachments as plain text",
|
|
6
6
|
"keywords": [
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"type": "git",
|
|
17
17
|
"url": "git+https://github.com/kud/jira-cli.git"
|
|
18
18
|
},
|
|
19
|
-
"homepage": "https://
|
|
19
|
+
"homepage": "https://kud.io/projects/jira-cli",
|
|
20
20
|
"bugs": "https://github.com/kud/jira-cli/issues",
|
|
21
21
|
"bin": {
|
|
22
22
|
"jira": "dist/index.js"
|