pipe-kan 0.20.0 → 0.20.2

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/dist/pipe-kan.js CHANGED
@@ -261,6 +261,15 @@ function flagsToJql(flags) {
261
261
  function emptyList(text) {
262
262
  return /no result found/i.test(text);
263
263
  }
264
+ var LIST_PAGE = 100;
265
+ function issueKey(issue) {
266
+ if (!issue || typeof issue !== "object" || !("key" in issue))
267
+ return;
268
+ return typeof issue.key === "string" ? issue.key : undefined;
269
+ }
270
+ function hasPaginate(args) {
271
+ return args.some((arg) => arg === "--paginate" || arg.startsWith("--paginate="));
272
+ }
264
273
  function createStoreCli(store) {
265
274
  return {
266
275
  async list(flags) {
@@ -330,62 +339,72 @@ function createJiraCli(opts = {}) {
330
339
  child.on("close", (code) => resolveRun({ code: code ?? 1, stdout, stderr }));
331
340
  });
332
341
  }
342
+ async function listOnce(args) {
343
+ const result = await run(args);
344
+ if (result.code !== 0) {
345
+ const text = result.stderr || result.stdout || "jira issue list failed";
346
+ if (emptyList(text))
347
+ return [];
348
+ throw new Error(text);
349
+ }
350
+ const parsed = JSON.parse(result.stdout);
351
+ return Array.isArray(parsed) ? parsed : [];
352
+ }
353
+ async function listAll(args) {
354
+ if (hasPaginate(args)) {
355
+ return JSON.stringify(await listOnce([...args, "--raw"]));
356
+ }
357
+ const issues = [];
358
+ const seen = new Set;
359
+ for (let from = 0;; from += LIST_PAGE) {
360
+ const page = await listOnce([
361
+ ...args,
362
+ "--paginate",
363
+ `${from}:${LIST_PAGE}`,
364
+ "--raw"
365
+ ]);
366
+ if (!page.length)
367
+ break;
368
+ const first = issueKey(page[0]);
369
+ if (first && seen.has(first))
370
+ break;
371
+ for (const issue of page) {
372
+ const key = issueKey(issue);
373
+ if (key)
374
+ seen.add(key);
375
+ issues.push(issue);
376
+ }
377
+ if (page.length < LIST_PAGE)
378
+ break;
379
+ }
380
+ return JSON.stringify(issues);
381
+ }
333
382
  return {
334
383
  async list(flags) {
335
384
  const extra = (flags || DEFAULT_FLAGS).split(/\s+/).filter(Boolean);
336
- const result = await run(["issue", "list", ...extra, "--raw"]);
337
- if (result.code !== 0) {
338
- const text = result.stderr || result.stdout || "jira issue list failed";
339
- if (emptyList(text))
340
- return "[]";
341
- throw new Error(text);
342
- }
343
- return result.stdout;
385
+ return listAll(["issue", "list", ...extra]);
344
386
  },
345
387
  async listEpics() {
346
- const result = await run(["issue", "list", "-tEpic", "--raw"]);
347
- if (result.code !== 0) {
348
- const text = result.stderr || result.stdout || "jira issue list failed";
349
- if (emptyList(text))
350
- return "[]";
351
- throw new Error(text);
352
- }
353
- return result.stdout;
388
+ return listAll(["issue", "list", "-tEpic"]);
354
389
  },
355
390
  async listEpic(key) {
356
- const result = await run([
391
+ return listAll([
357
392
  "issue",
358
393
  "list",
359
394
  "-q",
360
- `(parent="${key}" OR "Epic Link"="${key}")`,
361
- "--raw"
395
+ `(parent="${key}" OR "Epic Link"="${key}")`
362
396
  ]);
363
- if (result.code !== 0) {
364
- const text = result.stderr || result.stdout || "jira issue list failed";
365
- if (emptyList(text))
366
- return "[]";
367
- throw new Error(text);
368
- }
369
- return result.stdout;
370
397
  },
371
398
  async listChildren(keys) {
372
399
  if (!keys.length)
373
400
  return "[]";
374
401
  const list = keys.map((key) => `"${key}"`).join(", ");
375
- const result = await run([
402
+ return listAll([
376
403
  "issue",
377
404
  "list",
378
405
  "-q",
379
- `(parent in (${list}) OR "Epic Link" in (${list}))`,
380
- "--raw"
406
+ `(parent in (${list}) OR "Epic Link" in (${list}))`
381
407
  ]);
382
- if (result.code !== 0) {
383
- const text = result.stderr || result.stdout || "jira issue list failed";
384
- if (emptyList(text))
385
- return "[]";
386
- throw new Error(text);
387
- }
388
- return result.stdout;
389
408
  },
390
409
  async move(key, status) {
391
410
  const result = await run(["issue", "move", key, status]);