jira-pilot 2.0.1 → 2.0.3
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/LICENSE +5 -5
- package/README.md +465 -373
- package/bin/jira.js +62 -55
- package/package.json +90 -90
- package/src/commands/ai-actions/plan.js +119 -0
- package/src/commands/ai-actions/review.js +102 -0
- package/src/commands/ai-actions/standup.js +42 -0
- package/src/commands/ai.js +212 -209
- package/src/commands/board.js +75 -66
- package/src/commands/bulk.js +108 -0
- package/src/commands/config.js +224 -154
- package/src/commands/dashboard.js +89 -0
- package/src/commands/git.js +59 -63
- package/src/commands/issue.js +925 -707
- package/src/commands/mcp.js +27 -20
- package/src/commands/project.js +59 -50
- package/src/commands/sprint.js +153 -78
- package/src/server/mcp-server.js +332 -332
- package/src/services/ai-service.js +165 -107
- package/src/services/api-service.js +115 -115
- package/src/utils/adf-parser.js +49 -49
- package/src/utils/config.js +97 -60
- package/src/utils/error-handler.js +41 -41
- package/src/utils/text-to-adf.js +34 -34
- package/src/utils/validators.js +88 -88
package/src/commands/issue.js
CHANGED
|
@@ -1,707 +1,925 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { table } from 'table';
|
|
4
|
-
import { api } from '../services/api-service.js';
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
$ jira issue
|
|
19
|
-
$ jira issue
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
.
|
|
26
|
-
.
|
|
27
|
-
.option('-
|
|
28
|
-
.option('
|
|
29
|
-
.option('-
|
|
30
|
-
.option('-
|
|
31
|
-
.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
console.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
.
|
|
555
|
-
.
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
const
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
spinner.
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
.
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
const
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
}
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { table } from 'table';
|
|
4
|
+
import { api } from '../services/api-service.js';
|
|
5
|
+
import { aiService } from '../services/ai-service.js';
|
|
6
|
+
import ora from 'ora';
|
|
7
|
+
import enquirer from 'enquirer';
|
|
8
|
+
import { parseADF } from '../utils/adf-parser.js';
|
|
9
|
+
import { textToADF } from '../utils/text-to-adf.js';
|
|
10
|
+
import { validateIssueKey } from '../utils/validators.js';
|
|
11
|
+
import { handleCommandError } from '../utils/error-handler.js';
|
|
12
|
+
|
|
13
|
+
export function registerIssueCommand(program) {
|
|
14
|
+
const issueCmd = new Command('issue')
|
|
15
|
+
.description('Manage Jira issues')
|
|
16
|
+
.addHelpText('after', `
|
|
17
|
+
Common Actions:
|
|
18
|
+
$ jira issue list # List assigned issues
|
|
19
|
+
$ jira issue view <KEY> # View issue details
|
|
20
|
+
$ jira issue create # Create new issue (interactive)
|
|
21
|
+
$ jira issue transition <KEY> # Move issue status
|
|
22
|
+
`);
|
|
23
|
+
|
|
24
|
+
issueCmd
|
|
25
|
+
.command('list')
|
|
26
|
+
.description('List issues')
|
|
27
|
+
.option('-j, --jql <query>', 'JQL query to filter issues')
|
|
28
|
+
.option('--ask <query>', 'Filter issues using natural language query (AI)')
|
|
29
|
+
.option('-l, --limit <number>', 'Limit results', '20')
|
|
30
|
+
.option('-p, --project <key>', 'Filter by project')
|
|
31
|
+
.option('-a, --assignee <id>', 'Filter by assignee (use "currentUser" for self)')
|
|
32
|
+
.option('-s, --status <status>', 'Filter by status')
|
|
33
|
+
.option('-e, --export <format>', 'Export output (json, md)')
|
|
34
|
+
.option('-o, --output <format>', 'Output format (json)')
|
|
35
|
+
.addHelpText('after', `
|
|
36
|
+
Examples:
|
|
37
|
+
$ jira issue list --project PROJ --status "In Progress"
|
|
38
|
+
$ jira issue list --assignee currentUser --limit 10
|
|
39
|
+
$ jira issue list --jql "created >= -7d"
|
|
40
|
+
$ jira issue list --export json
|
|
41
|
+
`)
|
|
42
|
+
.action(async (options) => {
|
|
43
|
+
const spinner = ora('Fetching issues...').start();
|
|
44
|
+
try {
|
|
45
|
+
// Natural Language JQL
|
|
46
|
+
if (options.ask) {
|
|
47
|
+
const aiSpinner = ora(`Translating query: "${options.ask}"...`).start();
|
|
48
|
+
try {
|
|
49
|
+
const generatedJql = await aiService.generateJql(options.ask);
|
|
50
|
+
aiSpinner.succeed(`JQL: ${chalk.cyan(generatedJql)}`);
|
|
51
|
+
options.jql = generatedJql; // Override/Set JQL
|
|
52
|
+
} catch (e) {
|
|
53
|
+
aiSpinner.fail('Failed to translate query.');
|
|
54
|
+
console.error(chalk.red(e.message));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const jqlParts = [];
|
|
60
|
+
if (options.project) jqlParts.push(`project = "${options.project}"`);
|
|
61
|
+
if (options.assignee) jqlParts.push(`assignee = ${options.assignee === 'currentUser' ? 'currentUser()' : `"${options.assignee}"`}`);
|
|
62
|
+
if (options.status) jqlParts.push(`status = "${options.status}"`);
|
|
63
|
+
if (options.jql) jqlParts.push(options.jql);
|
|
64
|
+
|
|
65
|
+
// Order by updated desc by default if no JQL
|
|
66
|
+
if (!options.jql && jqlParts.length === 0) {
|
|
67
|
+
jqlParts.push('order by updated DESC');
|
|
68
|
+
} else if (jqlParts.length > 0 && !options.jql) {
|
|
69
|
+
// Add order if not custom jql
|
|
70
|
+
// jqlParts.push('order by updated DESC');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const jql = jqlParts.join(' AND ');
|
|
74
|
+
|
|
75
|
+
const searchApi = '/search/jql';
|
|
76
|
+
const body = {
|
|
77
|
+
jql: jql || 'created is not empty',
|
|
78
|
+
maxResults: parseInt(options.limit),
|
|
79
|
+
fields: ['summary', 'status', 'assignee', 'created', 'updated', 'description']
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const data = await api.post(searchApi, body);
|
|
83
|
+
spinner.stop();
|
|
84
|
+
|
|
85
|
+
if (!data.issues || data.issues.length === 0) {
|
|
86
|
+
console.log(chalk.yellow('No issues found.'));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Handling Export
|
|
91
|
+
if (options.export) {
|
|
92
|
+
const fs = await import('fs');
|
|
93
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
94
|
+
|
|
95
|
+
if (options.export === 'json') {
|
|
96
|
+
const filename = `issues-${timestamp}.json`;
|
|
97
|
+
fs.writeFileSync(filename, JSON.stringify(data.issues, null, 2));
|
|
98
|
+
console.log(chalk.green(`\nExported ${data.issues.length} issues to ${chalk.bold(filename)}`));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (options.export === 'md') {
|
|
103
|
+
const filename = `issues-${timestamp}.md`;
|
|
104
|
+
let mdContent = `# Jira Issues Export\nGenerated: ${new Date().toLocaleString()}\n\n`;
|
|
105
|
+
mdContent += `| Key | Summary | Status | Assignee |\n`;
|
|
106
|
+
mdContent += `|---|---|---|---|\n`;
|
|
107
|
+
|
|
108
|
+
data.issues.forEach(i => {
|
|
109
|
+
const key = i.key;
|
|
110
|
+
const summary = i.fields.summary || '';
|
|
111
|
+
const status = i.fields.status?.name || '';
|
|
112
|
+
const assignee = i.fields.assignee?.displayName || 'Unassigned';
|
|
113
|
+
mdContent += `| ${key} | ${summary} | ${status} | ${assignee} |\n`;
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
fs.writeFileSync(filename, mdContent);
|
|
117
|
+
console.log(chalk.green(`\nExported ${data.issues.length} issues to ${chalk.bold(filename)}`));
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (options.output === 'json') {
|
|
123
|
+
console.log(JSON.stringify(data.issues.map(i => ({
|
|
124
|
+
key: i.key, summary: i.fields.summary,
|
|
125
|
+
status: i.fields.status?.name, assignee: i.fields.assignee?.displayName || null,
|
|
126
|
+
created: i.fields.created, updated: i.fields.updated
|
|
127
|
+
})), null, 2));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const tableData = [
|
|
132
|
+
[chalk.bold('Key'), chalk.bold('Summary'), chalk.bold('Status'), chalk.bold('Assignee'), chalk.bold('Created'), chalk.bold('Updated')]
|
|
133
|
+
];
|
|
134
|
+
|
|
135
|
+
data.issues.forEach(i => {
|
|
136
|
+
tableData.push([
|
|
137
|
+
chalk.cyan(i.key),
|
|
138
|
+
i.fields.summary ? (i.fields.summary.length > 50 ? i.fields.summary.substring(0, 47) + '...' : i.fields.summary) : '',
|
|
139
|
+
i.fields.status ? i.fields.status.name : '',
|
|
140
|
+
i.fields.assignee ? i.fields.assignee.displayName : 'Unassigned',
|
|
141
|
+
i.fields.created ? i.fields.created.split('T')[0] : '',
|
|
142
|
+
i.fields.updated ? i.fields.updated.split('T')[0] : ''
|
|
143
|
+
]);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
console.log(table(tableData));
|
|
147
|
+
|
|
148
|
+
} catch (e) {
|
|
149
|
+
handleCommandError(spinner, e, 'Failed to list issues');
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
issueCmd
|
|
154
|
+
.command('view')
|
|
155
|
+
.description('View issue details')
|
|
156
|
+
.argument('<issueKey>', 'Issue Key')
|
|
157
|
+
.option('-o, --output <format>', 'Output format (json)')
|
|
158
|
+
.addHelpText('after', `
|
|
159
|
+
Examples:
|
|
160
|
+
$ jira issue view PROJ-123
|
|
161
|
+
$ jira issue view PROJ-123 --output json
|
|
162
|
+
`)
|
|
163
|
+
.action(async (issueKey, options) => {
|
|
164
|
+
const check = validateIssueKey(issueKey);
|
|
165
|
+
if (!check.valid) { console.error(chalk.red(check.message)); return; }
|
|
166
|
+
const spinner = ora(`Fetching issue ${issueKey}...`).start();
|
|
167
|
+
try {
|
|
168
|
+
const issue = await api.get(`/issue/${issueKey}`);
|
|
169
|
+
spinner.stop();
|
|
170
|
+
|
|
171
|
+
if (options.output === 'json') {
|
|
172
|
+
console.log(JSON.stringify({
|
|
173
|
+
key: issue.key, summary: issue.fields.summary,
|
|
174
|
+
status: issue.fields.status?.name, priority: issue.fields.priority?.name,
|
|
175
|
+
assignee: issue.fields.assignee?.displayName || null,
|
|
176
|
+
type: issue.fields.issuetype?.name,
|
|
177
|
+
description: parseADF(issue.fields.description) || null,
|
|
178
|
+
created: issue.fields.created, updated: issue.fields.updated
|
|
179
|
+
}, null, 2));
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
console.log(chalk.bold(`\n${issue.key}: ${issue.fields.summary}`));
|
|
184
|
+
console.log(chalk.grey(`${issue.fields.issuetype.name} - ${issue.fields.status.name} - ${issue.fields.priority ? issue.fields.priority.name : 'No Priority'}`));
|
|
185
|
+
console.log(chalk.bold('\nDescription:'));
|
|
186
|
+
console.log(parseADF(issue.fields.description) || 'No description provided.');
|
|
187
|
+
|
|
188
|
+
if (issue.fields.assignee) {
|
|
189
|
+
console.log(chalk.bold('\nAssignee: ') + issue.fields.assignee.displayName);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (issue.fields.comment && issue.fields.comment.comments.length > 0) {
|
|
193
|
+
console.log(chalk.bold('\nComments:'));
|
|
194
|
+
issue.fields.comment.comments.forEach(c => {
|
|
195
|
+
console.log(chalk.cyan(c.author.displayName) + ': ' + c.body);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
console.log('');
|
|
199
|
+
} catch (e) {
|
|
200
|
+
handleCommandError(spinner, e, 'Failed to fetch issue');
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// ── CREATE ────────────────────────────────────────────────────────
|
|
205
|
+
issueCmd
|
|
206
|
+
.command('create')
|
|
207
|
+
.description('Create a new Jira issue')
|
|
208
|
+
.option('-p, --project <key>', 'Project key')
|
|
209
|
+
.option('-t, --type <type>', 'Issue type (e.g., Bug, Story, Task)')
|
|
210
|
+
.option('-s, --summary <text>', 'Issue summary')
|
|
211
|
+
.option('-d, --description <text>', 'Issue description')
|
|
212
|
+
.option('--priority <name>', 'Priority name (e.g., High, Medium, Low)')
|
|
213
|
+
.option('-a, --assignee <id>', 'Assignee account ID (use "me" for self)')
|
|
214
|
+
.addHelpText('after', `
|
|
215
|
+
Examples:
|
|
216
|
+
$ jira issue create # Interactive wizard
|
|
217
|
+
$ jira issue create -p PROJ -s "Fix login bug" # Quick create
|
|
218
|
+
$ jira issue create -p PROJ -t Bug -s "Crash on save" --priority High
|
|
219
|
+
$ jira issue create -p PROJ -s "New feature" -a me
|
|
220
|
+
`)
|
|
221
|
+
.action(async (options) => {
|
|
222
|
+
try {
|
|
223
|
+
// ── Step 1: Select Project ──────────────────────────
|
|
224
|
+
let projectKey = options.project;
|
|
225
|
+
if (!projectKey) {
|
|
226
|
+
const spinner = ora('Fetching projects...').start();
|
|
227
|
+
const projectData = await api.get('/project/search');
|
|
228
|
+
spinner.stop();
|
|
229
|
+
|
|
230
|
+
if (!projectData.values || projectData.values.length === 0) {
|
|
231
|
+
console.error(chalk.red('No projects found. Check your permissions.'));
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const projectChoices = projectData.values.map(p => ({
|
|
236
|
+
name: p.key,
|
|
237
|
+
message: `${p.key} — ${p.name}`
|
|
238
|
+
}));
|
|
239
|
+
|
|
240
|
+
const { selectedProject } = await enquirer.prompt({
|
|
241
|
+
type: 'select',
|
|
242
|
+
name: 'selectedProject',
|
|
243
|
+
message: 'Select Project:',
|
|
244
|
+
choices: projectChoices
|
|
245
|
+
});
|
|
246
|
+
projectKey = selectedProject;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// ── Step 2: Select Issue Type ───────────────────────
|
|
250
|
+
let issueTypeName = options.type;
|
|
251
|
+
if (!issueTypeName) {
|
|
252
|
+
const spinner = ora('Fetching issue types...').start();
|
|
253
|
+
let issueTypes = [];
|
|
254
|
+
try {
|
|
255
|
+
// Jira Cloud v3 - createmeta endpoint
|
|
256
|
+
const metaData = await api.get(`/issue/createmeta/${projectKey}/issuetypes`);
|
|
257
|
+
issueTypes = metaData.issueTypes || metaData.values || [];
|
|
258
|
+
} catch (metaErr) {
|
|
259
|
+
// Fallback: use project-level issue types
|
|
260
|
+
try {
|
|
261
|
+
const projectInfo = await api.get(`/project/${projectKey}`);
|
|
262
|
+
issueTypes = projectInfo.issueTypes || [];
|
|
263
|
+
} catch {
|
|
264
|
+
issueTypes = [
|
|
265
|
+
{ name: 'Task' }, { name: 'Bug' },
|
|
266
|
+
{ name: 'Story' }, { name: 'Epic' }
|
|
267
|
+
];
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
spinner.stop();
|
|
271
|
+
|
|
272
|
+
if (issueTypes.length === 0) {
|
|
273
|
+
issueTypes = [
|
|
274
|
+
{ name: 'Task' }, { name: 'Bug' },
|
|
275
|
+
{ name: 'Story' }, { name: 'Epic' }
|
|
276
|
+
];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Filter out sub-tasks if present
|
|
280
|
+
const filteredTypes = issueTypes.filter(t => !t.subtask);
|
|
281
|
+
const typeChoices = (filteredTypes.length > 0 ? filteredTypes : issueTypes)
|
|
282
|
+
.map(t => ({ name: t.name, message: t.name }));
|
|
283
|
+
|
|
284
|
+
const { selectedType } = await enquirer.prompt({
|
|
285
|
+
type: 'select',
|
|
286
|
+
name: 'selectedType',
|
|
287
|
+
message: 'Select Issue Type:',
|
|
288
|
+
choices: typeChoices
|
|
289
|
+
});
|
|
290
|
+
issueTypeName = selectedType;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// ── Step 3: Summary (required) ──────────────────────
|
|
294
|
+
let summary = options.summary;
|
|
295
|
+
if (!summary) {
|
|
296
|
+
const { inputSummary } = await enquirer.prompt({
|
|
297
|
+
type: 'input',
|
|
298
|
+
name: 'inputSummary',
|
|
299
|
+
message: 'Summary (required):',
|
|
300
|
+
validate: (val) => val.trim().length > 0 || 'Summary cannot be empty'
|
|
301
|
+
});
|
|
302
|
+
summary = inputSummary;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// ── Step 4: Description (optional) ──────────────────
|
|
306
|
+
let description = options.description;
|
|
307
|
+
if (description === undefined) {
|
|
308
|
+
const { inputDescription } = await enquirer.prompt({
|
|
309
|
+
type: 'input',
|
|
310
|
+
name: 'inputDescription',
|
|
311
|
+
message: 'Description (optional, press Enter to skip):'
|
|
312
|
+
});
|
|
313
|
+
description = inputDescription || null;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// ── Step 5: Priority ────────────────────────────────
|
|
317
|
+
let priorityName = options.priority;
|
|
318
|
+
if (!priorityName) {
|
|
319
|
+
const spinner = ora('Fetching priorities...').start();
|
|
320
|
+
try {
|
|
321
|
+
const priorities = await api.get('/priority');
|
|
322
|
+
spinner.stop();
|
|
323
|
+
|
|
324
|
+
if (Array.isArray(priorities) && priorities.length > 0) {
|
|
325
|
+
const priorityChoices = priorities.map(p => ({
|
|
326
|
+
name: p.name,
|
|
327
|
+
message: p.name
|
|
328
|
+
}));
|
|
329
|
+
|
|
330
|
+
const { selectedPriority } = await enquirer.prompt({
|
|
331
|
+
type: 'select',
|
|
332
|
+
name: 'selectedPriority',
|
|
333
|
+
message: 'Select Priority:',
|
|
334
|
+
choices: priorityChoices
|
|
335
|
+
});
|
|
336
|
+
priorityName = selectedPriority;
|
|
337
|
+
}
|
|
338
|
+
} catch {
|
|
339
|
+
spinner.stop();
|
|
340
|
+
// Priority endpoint may not be available; skip
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// ── Step 6: Assignee ────────────────────────────────
|
|
345
|
+
let assigneeId = options.assignee;
|
|
346
|
+
if (!assigneeId) {
|
|
347
|
+
const { assigneeChoice } = await enquirer.prompt({
|
|
348
|
+
type: 'select',
|
|
349
|
+
name: 'assigneeChoice',
|
|
350
|
+
message: 'Assign to:',
|
|
351
|
+
choices: [
|
|
352
|
+
{ name: 'me', message: 'Myself' },
|
|
353
|
+
{ name: 'unassigned', message: 'Leave Unassigned' },
|
|
354
|
+
{ name: 'search', message: 'Search for a user...' }
|
|
355
|
+
]
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
if (assigneeChoice === 'me') {
|
|
359
|
+
const spinner = ora('Fetching your account...').start();
|
|
360
|
+
try {
|
|
361
|
+
const myself = await api.get('/myself');
|
|
362
|
+
assigneeId = myself.accountId;
|
|
363
|
+
spinner.stop();
|
|
364
|
+
} catch {
|
|
365
|
+
spinner.fail('Could not fetch your account. Leaving unassigned.');
|
|
366
|
+
assigneeId = null;
|
|
367
|
+
}
|
|
368
|
+
} else if (assigneeChoice === 'search') {
|
|
369
|
+
const { searchQuery } = await enquirer.prompt({
|
|
370
|
+
type: 'input',
|
|
371
|
+
name: 'searchQuery',
|
|
372
|
+
message: 'Search user by name or email:'
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
if (searchQuery.trim()) {
|
|
376
|
+
const spinner = ora('Searching users...').start();
|
|
377
|
+
try {
|
|
378
|
+
const users = await api.get(`/user/search?query=${encodeURIComponent(searchQuery)}`);
|
|
379
|
+
spinner.stop();
|
|
380
|
+
|
|
381
|
+
if (Array.isArray(users) && users.length > 0) {
|
|
382
|
+
const userChoices = users.map(u => ({
|
|
383
|
+
name: u.accountId,
|
|
384
|
+
message: `${u.displayName} (${u.emailAddress || u.accountId})`
|
|
385
|
+
}));
|
|
386
|
+
|
|
387
|
+
const { selectedUser } = await enquirer.prompt({
|
|
388
|
+
type: 'select',
|
|
389
|
+
name: 'selectedUser',
|
|
390
|
+
message: 'Select User:',
|
|
391
|
+
choices: userChoices
|
|
392
|
+
});
|
|
393
|
+
assigneeId = selectedUser;
|
|
394
|
+
} else {
|
|
395
|
+
console.log(chalk.yellow('No users found. Leaving unassigned.'));
|
|
396
|
+
assigneeId = null;
|
|
397
|
+
}
|
|
398
|
+
} catch {
|
|
399
|
+
spinner.fail('User search failed. Leaving unassigned.');
|
|
400
|
+
assigneeId = null;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
} else {
|
|
404
|
+
assigneeId = null;
|
|
405
|
+
}
|
|
406
|
+
} else if (assigneeId === 'me') {
|
|
407
|
+
// --assignee me flag: resolve to account ID
|
|
408
|
+
const spinner = ora('Fetching your account...').start();
|
|
409
|
+
try {
|
|
410
|
+
const myself = await api.get('/myself');
|
|
411
|
+
assigneeId = myself.accountId;
|
|
412
|
+
spinner.stop();
|
|
413
|
+
} catch {
|
|
414
|
+
spinner.fail('Could not fetch your account. Leaving unassigned.');
|
|
415
|
+
assigneeId = null;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// ── Confirmation ────────────────────────────────────
|
|
420
|
+
console.log(chalk.blue('\n── Issue Summary ──────────────────'));
|
|
421
|
+
console.log(` Project: ${chalk.cyan(projectKey)}`);
|
|
422
|
+
console.log(` Type: ${issueTypeName}`);
|
|
423
|
+
console.log(` Summary: ${summary}`);
|
|
424
|
+
console.log(` Description: ${description || chalk.grey('(none)')}`);
|
|
425
|
+
console.log(` Priority: ${priorityName || chalk.grey('(default)')}`);
|
|
426
|
+
console.log(` Assignee: ${assigneeId || chalk.grey('Unassigned')}`);
|
|
427
|
+
console.log(chalk.blue('──────────────────────────────────\n'));
|
|
428
|
+
|
|
429
|
+
const { confirmed } = await enquirer.prompt({
|
|
430
|
+
type: 'confirm',
|
|
431
|
+
name: 'confirmed',
|
|
432
|
+
message: 'Create this issue?',
|
|
433
|
+
initial: true
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
if (!confirmed) {
|
|
437
|
+
console.log(chalk.yellow('Issue creation cancelled.'));
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// ── Build Request Body ──────────────────────────────
|
|
442
|
+
const issueBody = {
|
|
443
|
+
fields: {
|
|
444
|
+
project: { key: projectKey },
|
|
445
|
+
issuetype: { name: issueTypeName },
|
|
446
|
+
summary: summary
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
if (description) {
|
|
451
|
+
issueBody.fields.description = textToADF(description);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if (priorityName) {
|
|
455
|
+
issueBody.fields.priority = { name: priorityName };
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
if (assigneeId) {
|
|
459
|
+
issueBody.fields.assignee = { accountId: assigneeId };
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// ── Create Issue ────────────────────────────────────
|
|
463
|
+
const spinner = ora('Creating issue...').start();
|
|
464
|
+
const result = await api.post('/issue', issueBody);
|
|
465
|
+
spinner.succeed(chalk.green(`Issue created: ${chalk.bold(result.key)}`));
|
|
466
|
+
|
|
467
|
+
console.log(chalk.grey(`View it: jira issue view ${result.key}`));
|
|
468
|
+
|
|
469
|
+
} catch (e) {
|
|
470
|
+
handleCommandError(spinner, e, 'Failed to create issue');
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
// ── TRANSITION ────────────────────────────────────────────────────
|
|
475
|
+
issueCmd
|
|
476
|
+
.command('transition')
|
|
477
|
+
.description('Transition an issue to a new status')
|
|
478
|
+
.argument('<issueKey>', 'Issue Key (e.g., PROJ-123)')
|
|
479
|
+
.option('-s, --status <name>', 'Target status name (skips interactive selection)')
|
|
480
|
+
.addHelpText('after', `
|
|
481
|
+
Examples:
|
|
482
|
+
$ jira issue transition PROJ-123 # Interactive
|
|
483
|
+
$ jira issue transition PROJ-123 --status "In Progress"
|
|
484
|
+
$ jira issue transition PROJ-123 -s Done
|
|
485
|
+
`)
|
|
486
|
+
.action(async (issueKey, options) => {
|
|
487
|
+
const check = validateIssueKey(issueKey);
|
|
488
|
+
if (!check.valid) { console.error(chalk.red(check.message)); return; }
|
|
489
|
+
const spinner = ora(`Fetching transitions for ${issueKey}...`).start();
|
|
490
|
+
try {
|
|
491
|
+
// Fetch current issue to show context
|
|
492
|
+
const issue = await api.get(`/issue/${issueKey}?fields=summary,status`);
|
|
493
|
+
const currentStatus = issue.fields.status.name;
|
|
494
|
+
|
|
495
|
+
// Fetch available transitions
|
|
496
|
+
const transData = await api.get(`/issue/${issueKey}/transitions`);
|
|
497
|
+
spinner.stop();
|
|
498
|
+
|
|
499
|
+
if (!transData.transitions || transData.transitions.length === 0) {
|
|
500
|
+
console.log(chalk.yellow(`No transitions available for ${issueKey} (current status: ${currentStatus}).`));
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
console.log(chalk.bold(`\n${issue.key}: ${issue.fields.summary}`));
|
|
505
|
+
console.log(chalk.grey(`Current Status: ${currentStatus}\n`));
|
|
506
|
+
|
|
507
|
+
let targetTransition;
|
|
508
|
+
|
|
509
|
+
if (options.status) {
|
|
510
|
+
// Non-interactive: find matching transition
|
|
511
|
+
targetTransition = transData.transitions.find(
|
|
512
|
+
t => t.name.toLowerCase() === options.status.toLowerCase() ||
|
|
513
|
+
t.to.name.toLowerCase() === options.status.toLowerCase()
|
|
514
|
+
);
|
|
515
|
+
|
|
516
|
+
if (!targetTransition) {
|
|
517
|
+
console.error(chalk.red(`Status "${options.status}" is not a valid transition from "${currentStatus}".`));
|
|
518
|
+
console.log(chalk.grey('Available transitions:'));
|
|
519
|
+
transData.transitions.forEach(t => {
|
|
520
|
+
console.log(chalk.grey(` • ${t.name} → ${t.to.name}`));
|
|
521
|
+
});
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
} else {
|
|
525
|
+
// Interactive: show selection
|
|
526
|
+
const transitionChoices = transData.transitions.map(t => ({
|
|
527
|
+
name: t.id,
|
|
528
|
+
message: `${t.name} → ${chalk.cyan(t.to.name)}`
|
|
529
|
+
}));
|
|
530
|
+
|
|
531
|
+
const { selectedTransition } = await enquirer.prompt({
|
|
532
|
+
type: 'select',
|
|
533
|
+
name: 'selectedTransition',
|
|
534
|
+
message: 'Select transition:',
|
|
535
|
+
choices: transitionChoices
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
targetTransition = transData.transitions.find(t => t.id === selectedTransition);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// Execute transition
|
|
542
|
+
const execSpinner = ora(`Transitioning to "${targetTransition.to.name}"...`).start();
|
|
543
|
+
await api.post(`/issue/${issueKey}/transitions`, {
|
|
544
|
+
transition: { id: targetTransition.id }
|
|
545
|
+
});
|
|
546
|
+
execSpinner.succeed(chalk.green(`${issueKey} transitioned: ${currentStatus} → ${chalk.bold(targetTransition.to.name)}`));
|
|
547
|
+
|
|
548
|
+
} catch (e) {
|
|
549
|
+
handleCommandError(spinner, e, 'Failed to transition issue');
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
// ── ASSIGN ────────────────────────────────────────────────────────
|
|
553
|
+
issueCmd
|
|
554
|
+
.command('assign')
|
|
555
|
+
.description('Assign or reassign an issue')
|
|
556
|
+
.argument('<issueKey>', 'Issue Key (e.g., PROJ-123)')
|
|
557
|
+
.option('-a, --assignee <id>', 'Assignee account ID (use "me" for self, "none" to unassign)')
|
|
558
|
+
.addHelpText('after', `
|
|
559
|
+
Examples:
|
|
560
|
+
$ jira issue assign PROJ-123 # Interactive
|
|
561
|
+
$ jira issue assign PROJ-123 -a me # Assign to yourself
|
|
562
|
+
$ jira issue assign PROJ-123 -a none # Unassign
|
|
563
|
+
`)
|
|
564
|
+
.action(async (issueKey, options) => {
|
|
565
|
+
const check = validateIssueKey(issueKey);
|
|
566
|
+
if (!check.valid) { console.error(chalk.red(check.message)); return; }
|
|
567
|
+
try {
|
|
568
|
+
let assigneeId = options.assignee;
|
|
569
|
+
|
|
570
|
+
if (!assigneeId) {
|
|
571
|
+
// Interactive selection
|
|
572
|
+
const spinner = ora(`Fetching issue ${issueKey}...`).start();
|
|
573
|
+
const issue = await api.get(`/issue/${issueKey}?fields=summary,assignee`);
|
|
574
|
+
spinner.stop();
|
|
575
|
+
|
|
576
|
+
const currentAssignee = issue.fields.assignee?.displayName || 'Unassigned';
|
|
577
|
+
console.log(chalk.bold(`\n${issue.key}: ${issue.fields.summary}`));
|
|
578
|
+
console.log(chalk.grey(`Current Assignee: ${currentAssignee}\n`));
|
|
579
|
+
|
|
580
|
+
const { assignChoice } = await enquirer.prompt({
|
|
581
|
+
type: 'select',
|
|
582
|
+
name: 'assignChoice',
|
|
583
|
+
message: 'Assign to:',
|
|
584
|
+
choices: [
|
|
585
|
+
{ name: 'me', message: 'Myself' },
|
|
586
|
+
{ name: 'none', message: 'Unassign' },
|
|
587
|
+
{ name: 'search', message: 'Search for a user...' }
|
|
588
|
+
]
|
|
589
|
+
});
|
|
590
|
+
assigneeId = assignChoice;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
if (assigneeId === 'me') {
|
|
594
|
+
const spinner = ora('Fetching your account...').start();
|
|
595
|
+
const myself = await api.get('/myself');
|
|
596
|
+
assigneeId = myself.accountId;
|
|
597
|
+
spinner.stop();
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
if (assigneeId === 'search') {
|
|
601
|
+
const { searchQuery } = await enquirer.prompt({
|
|
602
|
+
type: 'input',
|
|
603
|
+
name: 'searchQuery',
|
|
604
|
+
message: 'Search user by name or email:'
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
const spinner = ora('Searching users...').start();
|
|
608
|
+
const users = await api.get(`/user/search?query=${encodeURIComponent(searchQuery)}`);
|
|
609
|
+
spinner.stop();
|
|
610
|
+
|
|
611
|
+
if (!Array.isArray(users) || users.length === 0) {
|
|
612
|
+
console.log(chalk.yellow('No users found.'));
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
const { selectedUser } = await enquirer.prompt({
|
|
617
|
+
type: 'select',
|
|
618
|
+
name: 'selectedUser',
|
|
619
|
+
message: 'Select User:',
|
|
620
|
+
choices: users.map(u => ({
|
|
621
|
+
name: u.accountId,
|
|
622
|
+
message: `${u.displayName} (${u.emailAddress || u.accountId})`
|
|
623
|
+
}))
|
|
624
|
+
});
|
|
625
|
+
assigneeId = selectedUser;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
const spinner = ora('Updating assignee...').start();
|
|
629
|
+
const body = assigneeId === 'none'
|
|
630
|
+
? { accountId: null }
|
|
631
|
+
: { accountId: assigneeId };
|
|
632
|
+
|
|
633
|
+
await api.put(`/issue/${issueKey}/assignee`, body);
|
|
634
|
+
spinner.succeed(chalk.green(`${issueKey} ${assigneeId === 'none' ? 'unassigned' : 'assigned'} successfully.`));
|
|
635
|
+
|
|
636
|
+
} catch (e) {
|
|
637
|
+
handleCommandError(spinner, e, 'Failed to assign issue');
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
// ── COMMENT ───────────────────────────────────────────────────────
|
|
642
|
+
issueCmd
|
|
643
|
+
.command('comment')
|
|
644
|
+
.description('Add a comment to an issue')
|
|
645
|
+
.argument('<issueKey>', 'Issue Key (e.g., PROJ-123)')
|
|
646
|
+
.option('-m, --message <text>', 'Comment text (skips interactive prompt)')
|
|
647
|
+
.addHelpText('after', `
|
|
648
|
+
Examples:
|
|
649
|
+
$ jira issue comment PROJ-123 # Interactive
|
|
650
|
+
$ jira issue comment PROJ-123 -m "Fixed in latest build"
|
|
651
|
+
`)
|
|
652
|
+
.action(async (issueKey, options) => {
|
|
653
|
+
const check = validateIssueKey(issueKey);
|
|
654
|
+
if (!check.valid) { console.error(chalk.red(check.message)); return; }
|
|
655
|
+
try {
|
|
656
|
+
let commentText = options.message;
|
|
657
|
+
|
|
658
|
+
if (!commentText) {
|
|
659
|
+
// Show issue context first
|
|
660
|
+
const spinner = ora(`Fetching issue ${issueKey}...`).start();
|
|
661
|
+
const issue = await api.get(`/issue/${issueKey}?fields=summary,status`);
|
|
662
|
+
spinner.stop();
|
|
663
|
+
|
|
664
|
+
console.log(chalk.bold(`\n${issue.key}: ${issue.fields.summary}`));
|
|
665
|
+
console.log(chalk.grey(`Status: ${issue.fields.status.name}\n`));
|
|
666
|
+
|
|
667
|
+
const { inputComment } = await enquirer.prompt({
|
|
668
|
+
type: 'input',
|
|
669
|
+
name: 'inputComment',
|
|
670
|
+
message: 'Enter your comment:',
|
|
671
|
+
validate: (val) => val.trim().length > 0 || 'Comment cannot be empty'
|
|
672
|
+
});
|
|
673
|
+
commentText = inputComment;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
const spinner = ora('Adding comment...').start();
|
|
677
|
+
await api.post(`/issue/${issueKey}/comment`, {
|
|
678
|
+
body: textToADF(commentText)
|
|
679
|
+
});
|
|
680
|
+
spinner.succeed(chalk.green(`Comment added to ${issueKey}.`));
|
|
681
|
+
|
|
682
|
+
} catch (e) {
|
|
683
|
+
handleCommandError(spinner, e, 'Failed to add comment');
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
// ── EDIT ──────────────────────────────────────────────────────────
|
|
688
|
+
issueCmd
|
|
689
|
+
.command('edit')
|
|
690
|
+
.description('Edit issue fields')
|
|
691
|
+
.argument('<issueKey>', 'Issue Key (e.g., PROJ-123)')
|
|
692
|
+
.option('-s, --summary <text>', 'New summary')
|
|
693
|
+
.option('-d, --description <text>', 'New description')
|
|
694
|
+
.option('--priority <name>', 'New priority')
|
|
695
|
+
.addHelpText('after', `
|
|
696
|
+
Examples:
|
|
697
|
+
$ jira issue edit PROJ-123 # Interactive field picker
|
|
698
|
+
$ jira issue edit PROJ-123 -s "Updated title"
|
|
699
|
+
$ jira issue edit PROJ-123 --priority High
|
|
700
|
+
$ jira issue edit PROJ-123 -d "New description"
|
|
701
|
+
`)
|
|
702
|
+
.action(async (issueKey, options) => {
|
|
703
|
+
const check = validateIssueKey(issueKey);
|
|
704
|
+
if (!check.valid) { console.error(chalk.red(check.message)); return; }
|
|
705
|
+
const spinner = ora(`Fetching issue ${issueKey}...`).start();
|
|
706
|
+
try {
|
|
707
|
+
const issue = await api.get(`/issue/${issueKey}?fields=summary,description,priority`);
|
|
708
|
+
spinner.stop();
|
|
709
|
+
|
|
710
|
+
const updateBody = { fields: {} };
|
|
711
|
+
const hasFlags = options.summary || options.description || options.priority;
|
|
712
|
+
|
|
713
|
+
if (hasFlags) {
|
|
714
|
+
if (options.summary) updateBody.fields.summary = options.summary;
|
|
715
|
+
if (options.description) updateBody.fields.description = textToADF(options.description);
|
|
716
|
+
if (options.priority) updateBody.fields.priority = { name: options.priority };
|
|
717
|
+
} else {
|
|
718
|
+
// Interactive: pick which fields to edit
|
|
719
|
+
console.log(chalk.bold(`\nEditing ${chalk.cyan(issueKey)}: ${issue.fields.summary}\n`));
|
|
720
|
+
|
|
721
|
+
const { Select, Input } = enquirer;
|
|
722
|
+
|
|
723
|
+
const fieldSelect = new Select({
|
|
724
|
+
name: 'fields',
|
|
725
|
+
message: 'Select fields to edit',
|
|
726
|
+
choices: [
|
|
727
|
+
{ name: 'summary', message: `Summary: ${issue.fields.summary}` },
|
|
728
|
+
{ name: 'description', message: 'Description' },
|
|
729
|
+
{ name: 'priority', message: `Priority: ${issue.fields.priority?.name || 'None'}` }
|
|
730
|
+
],
|
|
731
|
+
multiple: true
|
|
732
|
+
});
|
|
733
|
+
const selectedFields = await fieldSelect.run();
|
|
734
|
+
|
|
735
|
+
if (!selectedFields || selectedFields.length === 0) {
|
|
736
|
+
console.log(chalk.yellow('No fields selected.'));
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
for (const field of selectedFields) {
|
|
741
|
+
if (field === 'summary') {
|
|
742
|
+
const prompt = new Input({ message: 'New summary', initial: issue.fields.summary });
|
|
743
|
+
updateBody.fields.summary = await prompt.run();
|
|
744
|
+
}
|
|
745
|
+
if (field === 'description') {
|
|
746
|
+
const prompt = new Input({ message: 'New description' });
|
|
747
|
+
const desc = await prompt.run();
|
|
748
|
+
if (desc) updateBody.fields.description = textToADF(desc);
|
|
749
|
+
}
|
|
750
|
+
if (field === 'priority') {
|
|
751
|
+
const priorities = await api.get('/priority');
|
|
752
|
+
const prioSelect = new Select({
|
|
753
|
+
name: 'priority',
|
|
754
|
+
message: 'Select priority',
|
|
755
|
+
choices: priorities.map(p => ({ name: p.name, message: p.name }))
|
|
756
|
+
});
|
|
757
|
+
updateBody.fields.priority = { name: await prioSelect.run() };
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
if (Object.keys(updateBody.fields).length === 0) {
|
|
763
|
+
console.log(chalk.yellow('No changes specified.'));
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
const updateSpinner = ora('Updating issue...').start();
|
|
768
|
+
await api.put(`/issue/${issueKey}`, updateBody);
|
|
769
|
+
updateSpinner.succeed(`${chalk.cyan(issueKey)} updated successfully`);
|
|
770
|
+
|
|
771
|
+
} catch (e) {
|
|
772
|
+
handleCommandError(spinner, e, `Failed to edit ${issueKey}`);
|
|
773
|
+
}
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
// ── SEARCH ────────────────────────────────────────────────────────
|
|
777
|
+
issueCmd
|
|
778
|
+
.command('search')
|
|
779
|
+
.description('Quick text search across issues')
|
|
780
|
+
.argument('<query>', 'Search text')
|
|
781
|
+
.option('-p, --project <key>', 'Filter by project')
|
|
782
|
+
.option('-l, --limit <n>', 'Max results', '15')
|
|
783
|
+
.option('-o, --output <format>', 'Output format (json)')
|
|
784
|
+
.addHelpText('after', `
|
|
785
|
+
Examples:
|
|
786
|
+
$ jira issue search "login bug"
|
|
787
|
+
$ jira issue search "payment" -p PROJ
|
|
788
|
+
$ jira issue search "crash" --output json
|
|
789
|
+
`)
|
|
790
|
+
.action(async (query, options) => {
|
|
791
|
+
const spinner = ora(`Searching for "${query}"...`).start();
|
|
792
|
+
try {
|
|
793
|
+
const jqlParts = [`text ~ "${query.replace(/"/g, '\\"')}"`];
|
|
794
|
+
if (options.project) jqlParts.push(`project = "${options.project}"`);
|
|
795
|
+
const jql = jqlParts.join(' AND ') + ' ORDER BY updated DESC';
|
|
796
|
+
|
|
797
|
+
const data = await api.post('/search/jql', {
|
|
798
|
+
jql,
|
|
799
|
+
maxResults: parseInt(options.limit),
|
|
800
|
+
fields: ['summary', 'status', 'assignee', 'updated']
|
|
801
|
+
});
|
|
802
|
+
spinner.stop();
|
|
803
|
+
|
|
804
|
+
if (!data.issues || data.issues.length === 0) {
|
|
805
|
+
console.log(chalk.yellow('No issues found.'));
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
if (options.output === 'json') {
|
|
810
|
+
console.log(JSON.stringify(data.issues.map(i => ({
|
|
811
|
+
key: i.key, summary: i.fields.summary,
|
|
812
|
+
status: i.fields.status?.name, assignee: i.fields.assignee?.displayName || null,
|
|
813
|
+
updated: i.fields.updated
|
|
814
|
+
})), null, 2));
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
const tableData = [
|
|
819
|
+
[chalk.bold('Key'), chalk.bold('Summary'), chalk.bold('Status'), chalk.bold('Assignee')]
|
|
820
|
+
];
|
|
821
|
+
data.issues.forEach(i => {
|
|
822
|
+
tableData.push([
|
|
823
|
+
chalk.cyan(i.key),
|
|
824
|
+
i.fields.summary ? (i.fields.summary.length > 55 ? i.fields.summary.substring(0, 52) + '...' : i.fields.summary) : '',
|
|
825
|
+
i.fields.status?.name || '',
|
|
826
|
+
i.fields.assignee?.displayName || 'Unassigned'
|
|
827
|
+
]);
|
|
828
|
+
});
|
|
829
|
+
console.log(table(tableData));
|
|
830
|
+
console.log(chalk.grey(`Found ${data.issues.length} result(s)`));
|
|
831
|
+
|
|
832
|
+
} catch (e) {
|
|
833
|
+
handleCommandError(spinner, e, 'Search failed');
|
|
834
|
+
}
|
|
835
|
+
});
|
|
836
|
+
|
|
837
|
+
// ── LINK ──────────────────────────────────────────────────────────
|
|
838
|
+
issueCmd
|
|
839
|
+
.command('link')
|
|
840
|
+
.description('Link two issues together')
|
|
841
|
+
.argument('<sourceKey>', 'Source issue key')
|
|
842
|
+
.argument('<targetKey>', 'Target issue key')
|
|
843
|
+
.option('-t, --type <name>', 'Link type (e.g., "Blocks", "Relates")')
|
|
844
|
+
.addHelpText('after', `
|
|
845
|
+
Examples:
|
|
846
|
+
$ jira issue link PROJ-1 PROJ-2 # Interactive type selection
|
|
847
|
+
$ jira issue link PROJ-1 PROJ-2 -t "Blocks"
|
|
848
|
+
$ jira issue link PROJ-1 PROJ-2 -t "Relates"
|
|
849
|
+
`)
|
|
850
|
+
.action(async (sourceKey, targetKey, options) => {
|
|
851
|
+
const srcCheck = validateIssueKey(sourceKey);
|
|
852
|
+
if (!srcCheck.valid) { console.error(chalk.red(srcCheck.message)); return; }
|
|
853
|
+
const tgtCheck = validateIssueKey(targetKey);
|
|
854
|
+
if (!tgtCheck.valid) { console.error(chalk.red(tgtCheck.message)); return; }
|
|
855
|
+
|
|
856
|
+
try {
|
|
857
|
+
let linkType = options.type;
|
|
858
|
+
|
|
859
|
+
if (!linkType) {
|
|
860
|
+
const spinner = ora('Fetching link types...').start();
|
|
861
|
+
const linkTypes = await api.get('/issueLinkType');
|
|
862
|
+
spinner.stop();
|
|
863
|
+
|
|
864
|
+
const { Select } = enquirer;
|
|
865
|
+
const typeSelect = new Select({
|
|
866
|
+
name: 'linkType',
|
|
867
|
+
message: `Link type: ${chalk.cyan(sourceKey)} → ${chalk.cyan(targetKey)}`,
|
|
868
|
+
choices: linkTypes.issueLinkTypes.map(lt => ({
|
|
869
|
+
name: lt.name,
|
|
870
|
+
message: `${lt.name} (${lt.inward} / ${lt.outward})`
|
|
871
|
+
}))
|
|
872
|
+
});
|
|
873
|
+
linkType = await typeSelect.run();
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
const spinner = ora(`Linking ${sourceKey} → ${targetKey}...`).start();
|
|
877
|
+
await api.post('/issueLink', {
|
|
878
|
+
type: { name: linkType },
|
|
879
|
+
inwardIssue: { key: sourceKey },
|
|
880
|
+
outwardIssue: { key: targetKey }
|
|
881
|
+
});
|
|
882
|
+
spinner.succeed(`Linked ${chalk.cyan(sourceKey)} ${chalk.grey(`—[${linkType}]→`)} ${chalk.cyan(targetKey)}`);
|
|
883
|
+
|
|
884
|
+
} catch (e) {
|
|
885
|
+
handleCommandError(null, e, `Failed to link issues`);
|
|
886
|
+
}
|
|
887
|
+
});
|
|
888
|
+
|
|
889
|
+
// ── WATCH ─────────────────────────────────────────────────────────
|
|
890
|
+
issueCmd
|
|
891
|
+
.command('watch')
|
|
892
|
+
.description('Start watching an issue')
|
|
893
|
+
.argument('<issueKey>', 'Issue Key')
|
|
894
|
+
.action(async (issueKey) => {
|
|
895
|
+
const check = validateIssueKey(issueKey);
|
|
896
|
+
if (!check.valid) { console.error(chalk.red(check.message)); return; }
|
|
897
|
+
const spinner = ora(`Watching ${issueKey}...`).start();
|
|
898
|
+
try {
|
|
899
|
+
await api.post(`/issue/${issueKey}/watchers`, null);
|
|
900
|
+
spinner.succeed(`Now watching ${chalk.cyan(issueKey)}`);
|
|
901
|
+
} catch (e) {
|
|
902
|
+
handleCommandError(spinner, e, `Failed to watch ${issueKey}`);
|
|
903
|
+
}
|
|
904
|
+
});
|
|
905
|
+
|
|
906
|
+
// ── UNWATCH ───────────────────────────────────────────────────────
|
|
907
|
+
issueCmd
|
|
908
|
+
.command('unwatch')
|
|
909
|
+
.description('Stop watching an issue')
|
|
910
|
+
.argument('<issueKey>', 'Issue Key')
|
|
911
|
+
.action(async (issueKey) => {
|
|
912
|
+
const check = validateIssueKey(issueKey);
|
|
913
|
+
if (!check.valid) { console.error(chalk.red(check.message)); return; }
|
|
914
|
+
const spinner = ora(`Unwatching ${issueKey}...`).start();
|
|
915
|
+
try {
|
|
916
|
+
const me = await api.get('/myself');
|
|
917
|
+
await api.delete(`/issue/${issueKey}/watchers?accountId=${me.accountId}`);
|
|
918
|
+
spinner.succeed(`Stopped watching ${chalk.cyan(issueKey)}`);
|
|
919
|
+
} catch (e) {
|
|
920
|
+
handleCommandError(spinner, e, `Failed to unwatch ${issueKey}`);
|
|
921
|
+
}
|
|
922
|
+
});
|
|
923
|
+
|
|
924
|
+
program.addCommand(issueCmd);
|
|
925
|
+
}
|