@workit-dev/pi 1.9.3 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/workit.js +197 -25
- package/package.json +1 -1
package/dist/workit.js
CHANGED
|
@@ -23922,7 +23922,7 @@ var ytrackDetail = (out) => out.stderr.trim().split(`
|
|
|
23922
23922
|
var YTRACK_MISSING = "ytrack is not on PATH: Workit reaches YouTrack only through ytrack";
|
|
23923
23923
|
|
|
23924
23924
|
// packages/workit-core/src/core/youtrack.ts
|
|
23925
|
-
var ISSUE_RE = /^[A-Z]
|
|
23925
|
+
var ISSUE_RE = /^[A-Z][A-Z0-9_]*-\d+$/;
|
|
23926
23926
|
var youTrackReadOnlyConfigPath = () => process.env.WORKIT_YOUTRACK_CONFIG ?? path33.join(resolveConfigDir(), "youtrack.json");
|
|
23927
23927
|
var readYouTrackContextConfig = () => {
|
|
23928
23928
|
const cfgPath = youTrackReadOnlyConfigPath();
|
|
@@ -23978,11 +23978,11 @@ function parseIssueRef(input) {
|
|
|
23978
23978
|
if (ISSUE_RE.test(trimmed)) {
|
|
23979
23979
|
return { issueId: trimmed, source: "id" };
|
|
23980
23980
|
}
|
|
23981
|
-
const fromPath = trimmed.match(/\/(?:issue|issues)\/([A-Z]
|
|
23981
|
+
const fromPath = trimmed.match(/\/(?:issue|issues)\/([A-Z][A-Z0-9_]*-\d+)/i);
|
|
23982
23982
|
if (fromPath && ISSUE_RE.test(fromPath[1])) {
|
|
23983
23983
|
return { issueId: fromPath[1], source: "url" };
|
|
23984
23984
|
}
|
|
23985
|
-
const anywhere = trimmed.match(/([A-Z]
|
|
23985
|
+
const anywhere = trimmed.match(/([A-Z][A-Z0-9_]*-\d+)/);
|
|
23986
23986
|
if (anywhere && ISSUE_RE.test(anywhere[1])) {
|
|
23987
23987
|
return { issueId: anywhere[1], source: "url" };
|
|
23988
23988
|
}
|
|
@@ -29381,7 +29381,7 @@ var minutesOf = (text = "") => {
|
|
|
29381
29381
|
});
|
|
29382
29382
|
return rest.trim() || !Number.isInteger(total) || total <= 0 ? null : total;
|
|
29383
29383
|
};
|
|
29384
|
-
var VALUE = new Set(("--host --body -b --body-file --text --date --duration --type --project -p --summary -s " + "--description --description-file --field --tag --add-tag --remove-tag --assignee --comment " + "--json --jq -X --method -f -F --raw-field --input --fields -q --query --author --since --limit").split(" "));
|
|
29384
|
+
var VALUE = new Set(("--host --body -b --body-file --text --date --duration --type --project -p --summary -s " + "--description --description-file --field --tag --add-tag --remove-tag --assignee --comment " + "--json --jq -X --method -f -F --raw-field --input --fields -q --query --author --since --limit " + "--attach -H --header").split(" "));
|
|
29385
29385
|
var BARE = new Set("--debug --no-color --paginate --include --dry-run --silent --yes --meeting --help -h".split(" "));
|
|
29386
29386
|
var standsAlone = (args, at) => {
|
|
29387
29387
|
const before = args[at - 1] ?? "";
|
|
@@ -29400,7 +29400,7 @@ var ASKS = /^(?:post|put|patch|delete)$/i;
|
|
|
29400
29400
|
var BODY = /^(?:-[fF]|--(?:field|raw-field|input))(?:=|$)|^-[fF]./;
|
|
29401
29401
|
var QUIET = /^--(?:debug|no-color|json|jq)$/;
|
|
29402
29402
|
var CARRIES = {
|
|
29403
|
-
note: { "--body": "body", "-b": "body", "--body-file": "file" },
|
|
29403
|
+
note: { "--body": "body", "-b": "body", "--body-file": "file", "--attach": "attach" },
|
|
29404
29404
|
time: { "--duration": "duration", "--text": "text", "--date": "date" },
|
|
29405
29405
|
create: {
|
|
29406
29406
|
"--project": "project",
|
|
@@ -29412,9 +29412,60 @@ var CARRIES = {
|
|
|
29412
29412
|
}
|
|
29413
29413
|
};
|
|
29414
29414
|
var gap = (part) => ({ workit: null, gap: part });
|
|
29415
|
+
var ISSUE = /^[A-Z][A-Z0-9_]*-\d+$/;
|
|
29416
|
+
var EXPANDS = /[$`*?[\]]|^~/;
|
|
29417
|
+
var commandFlag = (command) => {
|
|
29418
|
+
const state = /^State\s+(\S.*)$/u.exec(command)?.[1];
|
|
29419
|
+
return state ? pair("--state", state) : pair("--command", command);
|
|
29420
|
+
};
|
|
29421
|
+
var callFor = (effect) => {
|
|
29422
|
+
const comment = effect.markdown !== undefined || effect.file !== undefined;
|
|
29423
|
+
const time = effect.minutes !== undefined;
|
|
29424
|
+
const timeFlags = [
|
|
29425
|
+
effect.text === undefined ? "" : pair("--text", effect.text),
|
|
29426
|
+
effect.date === undefined ? "" : pair("--date", effect.date)
|
|
29427
|
+
];
|
|
29428
|
+
const commentFlag = effect.markdown !== undefined ? pair("--markdown", effect.markdown) : effect.file !== undefined ? pair("--file", effect.file) : "";
|
|
29429
|
+
const only = !effect.attach?.length && effect.command === undefined;
|
|
29430
|
+
if (only && comment && !time)
|
|
29431
|
+
return `workit youtrack note ${effect.issue} ${commentFlag}`;
|
|
29432
|
+
if (only && time && !comment)
|
|
29433
|
+
return [`workit youtrack time ${effect.issue} --minutes ${effect.minutes}`, ...timeFlags].filter(Boolean).join(" ");
|
|
29434
|
+
return [
|
|
29435
|
+
`workit youtrack update ${effect.issue}`,
|
|
29436
|
+
commentFlag,
|
|
29437
|
+
...(effect.attach ?? []).map((file) => pair("--attach", file)),
|
|
29438
|
+
time ? `--minutes ${effect.minutes}` : "",
|
|
29439
|
+
...time ? timeFlags : [],
|
|
29440
|
+
effect.command === undefined ? "" : commandFlag(effect.command)
|
|
29441
|
+
].filter(Boolean).join(" ");
|
|
29442
|
+
};
|
|
29443
|
+
var mapped = (effect) => ({ workit: callFor(effect), effect });
|
|
29444
|
+
var combine = (effects) => {
|
|
29445
|
+
const out = { issue: effects[0].issue };
|
|
29446
|
+
for (const effect of effects) {
|
|
29447
|
+
if (effect.issue !== out.issue)
|
|
29448
|
+
return null;
|
|
29449
|
+
const comment = effect.markdown !== undefined || effect.file !== undefined;
|
|
29450
|
+
if (comment && (out.markdown !== undefined || out.file !== undefined))
|
|
29451
|
+
return null;
|
|
29452
|
+
if (effect.minutes !== undefined && out.minutes !== undefined)
|
|
29453
|
+
return null;
|
|
29454
|
+
if (effect.command !== undefined && out.command !== undefined)
|
|
29455
|
+
return null;
|
|
29456
|
+
Object.assign(out, {
|
|
29457
|
+
...effect,
|
|
29458
|
+
attach: [...out.attach ?? [], ...effect.attach ?? []]
|
|
29459
|
+
});
|
|
29460
|
+
}
|
|
29461
|
+
if (!out.attach?.length)
|
|
29462
|
+
delete out.attach;
|
|
29463
|
+
return out;
|
|
29464
|
+
};
|
|
29415
29465
|
var pair = (flag, value) => value.startsWith("-") ? `${flag}=${quote2(value)}` : `${flag} ${quote2(value)}`;
|
|
29416
29466
|
var mapWrite = (verb, args) => {
|
|
29417
29467
|
const values = {};
|
|
29468
|
+
const attach = [];
|
|
29418
29469
|
const operands = [];
|
|
29419
29470
|
for (let at = 0;at < args.length; at++) {
|
|
29420
29471
|
const arg = args[at];
|
|
@@ -29430,9 +29481,12 @@ var mapWrite = (verb, args) => {
|
|
|
29430
29481
|
const key = CARRIES[verb][flag];
|
|
29431
29482
|
if (!key || value === undefined || key in values)
|
|
29432
29483
|
return gap(`\`${flag}\``);
|
|
29433
|
-
if (/[$`]|^~/.test(value))
|
|
29484
|
+
if (/[$`]|^~/.test(value) || key === "attach" && EXPANDS.test(value))
|
|
29434
29485
|
return gap(`the value of \`${flag}\`, which the shell expands when it runs`);
|
|
29435
|
-
|
|
29486
|
+
if (key === "attach")
|
|
29487
|
+
attach.push(value);
|
|
29488
|
+
else
|
|
29489
|
+
values[key] = value;
|
|
29436
29490
|
}
|
|
29437
29491
|
const [issue, ...more] = operands.slice(2);
|
|
29438
29492
|
const v = values;
|
|
@@ -29455,7 +29509,7 @@ var mapWrite = (verb, args) => {
|
|
|
29455
29509
|
].filter(Boolean).join(" ")
|
|
29456
29510
|
};
|
|
29457
29511
|
}
|
|
29458
|
-
if (issue === undefined || more.length ||
|
|
29512
|
+
if (issue === undefined || more.length || !ISSUE.test(issue))
|
|
29459
29513
|
return gap("the issue, which must be one id like ABC-123");
|
|
29460
29514
|
if (verb === "note") {
|
|
29461
29515
|
if (v.body === undefined === (v.file === undefined))
|
|
@@ -29464,22 +29518,108 @@ var mapWrite = (verb, args) => {
|
|
|
29464
29518
|
return gap("text read from standard input");
|
|
29465
29519
|
if (v.body !== undefined && !v.body.trim())
|
|
29466
29520
|
return gap("an empty --body");
|
|
29467
|
-
return {
|
|
29468
|
-
|
|
29469
|
-
|
|
29521
|
+
return mapped({
|
|
29522
|
+
issue,
|
|
29523
|
+
...v.body === undefined ? { file: v.file } : { markdown: v.body },
|
|
29524
|
+
...attach.length ? { attach } : {}
|
|
29525
|
+
});
|
|
29470
29526
|
}
|
|
29471
29527
|
const minutes = minutesOf(v.duration);
|
|
29472
29528
|
if (minutes === null)
|
|
29473
29529
|
return gap(`\`--duration ${v.duration ?? ""}\`, which is no whole number of minutes`);
|
|
29474
29530
|
if (v.date !== undefined && !/^(?:auto|\d{4}-\d{2}-\d{2})$/.test(v.date))
|
|
29475
29531
|
return gap(`\`--date ${v.date}\``);
|
|
29476
|
-
return {
|
|
29477
|
-
|
|
29478
|
-
|
|
29479
|
-
|
|
29480
|
-
|
|
29481
|
-
|
|
29482
|
-
|
|
29532
|
+
return mapped({
|
|
29533
|
+
issue,
|
|
29534
|
+
minutes,
|
|
29535
|
+
...v.text === undefined ? {} : { text: v.text },
|
|
29536
|
+
...v.date === undefined ? {} : { date: v.date }
|
|
29537
|
+
});
|
|
29538
|
+
};
|
|
29539
|
+
var mapIssueWrite = (verb, args) => {
|
|
29540
|
+
const operands = [];
|
|
29541
|
+
for (let at = 0;at < args.length; at++) {
|
|
29542
|
+
const arg = args[at];
|
|
29543
|
+
if (!arg.startsWith("-") || arg === "-") {
|
|
29544
|
+
operands.push(arg);
|
|
29545
|
+
continue;
|
|
29546
|
+
}
|
|
29547
|
+
const eq = arg.startsWith("--") ? arg.indexOf("=") : -1;
|
|
29548
|
+
const flag = eq > 0 ? arg.slice(0, eq) : arg;
|
|
29549
|
+
if (!QUIET.test(flag))
|
|
29550
|
+
return gap(`\`${flag}\``);
|
|
29551
|
+
if (eq < 0 && VALUE.has(flag))
|
|
29552
|
+
at++;
|
|
29553
|
+
}
|
|
29554
|
+
const [issue, ...rest] = operands.slice(2);
|
|
29555
|
+
if (issue === undefined || !ISSUE.test(issue))
|
|
29556
|
+
return gap("the issue, which must be one id like ABC-123");
|
|
29557
|
+
if (verb === "attach") {
|
|
29558
|
+
if (!rest.length)
|
|
29559
|
+
return gap("an attach with no file");
|
|
29560
|
+
const odd = rest.find((file) => file === "-" || EXPANDS.test(file));
|
|
29561
|
+
if (odd !== undefined)
|
|
29562
|
+
return gap(`the file \`${odd}\`, which the shell expands or reads from standard input`);
|
|
29563
|
+
return mapped({ issue, attach: rest });
|
|
29564
|
+
}
|
|
29565
|
+
if (rest.length !== 1 || !rest[0].trim())
|
|
29566
|
+
return gap("a command that is not one quoted word (`ytrack issue command X-1 'State Done'`)");
|
|
29567
|
+
if (/[$`]/.test(rest[0]))
|
|
29568
|
+
return gap("a command the shell expands when it runs");
|
|
29569
|
+
return mapped({ issue, command: rest[0].trim() });
|
|
29570
|
+
};
|
|
29571
|
+
var mapApi = (args, target) => {
|
|
29572
|
+
const where = /^\/?(?:api\/)?issues\/([A-Z][A-Z0-9_]*-\d+)\/(comments|attachments)\/?(?:\?.*)?$/u.exec(target);
|
|
29573
|
+
if (!where)
|
|
29574
|
+
return null;
|
|
29575
|
+
const [, issue, kind] = where;
|
|
29576
|
+
const fields = [];
|
|
29577
|
+
for (let at = 0;at < args.length; at++) {
|
|
29578
|
+
const arg = args[at];
|
|
29579
|
+
if (!arg.startsWith("-"))
|
|
29580
|
+
continue;
|
|
29581
|
+
const eq = arg.startsWith("--") ? arg.indexOf("=") : -1;
|
|
29582
|
+
const glued = /^-[fFX]./.test(arg) && !arg.startsWith("--");
|
|
29583
|
+
const flag = glued ? arg.slice(0, 2) : eq > 0 ? arg.slice(0, eq) : arg;
|
|
29584
|
+
const value = glued ? arg.slice(2) : eq > 0 ? arg.slice(eq + 1) : VALUE.has(flag) ? args[++at] : undefined;
|
|
29585
|
+
if (QUIET.test(flag))
|
|
29586
|
+
continue;
|
|
29587
|
+
if (/^(?:-X|--method)$/.test(flag)) {
|
|
29588
|
+
if (!/^=?post$/i.test(value ?? ""))
|
|
29589
|
+
return gap(`\`${flag} ${value ?? ""}\``);
|
|
29590
|
+
continue;
|
|
29591
|
+
}
|
|
29592
|
+
if (/^(?:-H|--header)$/.test(flag) && /^(?:content-type|accept)\s*:/i.test(value ?? ""))
|
|
29593
|
+
continue;
|
|
29594
|
+
if (!/^(?:-f|-F|--field|--raw-field)$/.test(flag) || value === undefined)
|
|
29595
|
+
return gap(`\`${flag}\``);
|
|
29596
|
+
const split = value.indexOf("=");
|
|
29597
|
+
if (split <= 0)
|
|
29598
|
+
return gap(`the field \`${value}\``);
|
|
29599
|
+
fields.push({
|
|
29600
|
+
typed: flag === "-F" || flag === "--field",
|
|
29601
|
+
key: value.slice(0, split),
|
|
29602
|
+
value: value.slice(split + 1)
|
|
29603
|
+
});
|
|
29604
|
+
}
|
|
29605
|
+
if (fields.some((field) => /[$`]/.test(field.value)))
|
|
29606
|
+
return gap("a field value the shell expands when it runs");
|
|
29607
|
+
if (kind === "comments") {
|
|
29608
|
+
const [field, ...more] = fields;
|
|
29609
|
+
if (!field || more.length || field.key !== "text")
|
|
29610
|
+
return gap("a comment body other than one `text` field");
|
|
29611
|
+
if (field.typed && field.value.startsWith("@")) {
|
|
29612
|
+
const file = field.value.slice(1);
|
|
29613
|
+
if (!file || file === "-" || EXPANDS.test(file))
|
|
29614
|
+
return gap(`the file \`${file}\``);
|
|
29615
|
+
return mapped({ issue, file });
|
|
29616
|
+
}
|
|
29617
|
+
return field.value.trim() ? mapped({ issue, markdown: field.value }) : gap("an empty `text`");
|
|
29618
|
+
}
|
|
29619
|
+
const files = fields.map((field) => field.typed && field.value.startsWith("@") ? field.value.slice(1) : null);
|
|
29620
|
+
if (!files.length || files.some((file) => !file || file === "-" || EXPANDS.test(file)))
|
|
29621
|
+
return gap("an upload other than `-F <name>=@<file>` fields");
|
|
29622
|
+
return mapped({ issue, attach: files });
|
|
29483
29623
|
};
|
|
29484
29624
|
var UNCOVERED = { workit: null, gap: "" };
|
|
29485
29625
|
var classify2 = (args) => {
|
|
@@ -29494,11 +29634,12 @@ var judge = (args, words) => {
|
|
|
29494
29634
|
const verb = words[1] ?? "";
|
|
29495
29635
|
if (group === "api") {
|
|
29496
29636
|
const methods = args.flatMap((arg, at) => /^(?:-X|--method)$/.test(arg) ? [{ value: args[at + 1] ?? "", alone: standsAlone(args, at) }] : /^(?:-X.|--method=)/.test(arg) ? [{ value: arg.replace(/^(?:-X=?|--method=)/, ""), alone: standsAlone(args, at) }] : []);
|
|
29637
|
+
const posts = methods.length > 0 && methods.every((method) => /^post$/i.test(method.value));
|
|
29497
29638
|
if (methods.some((method) => ASKS.test(method.value)))
|
|
29498
|
-
return UNCOVERED;
|
|
29639
|
+
return (posts ? mapApi(args, words[1] ?? "") : null) ?? UNCOVERED;
|
|
29499
29640
|
if (methods.some((method) => method.alone))
|
|
29500
29641
|
return null;
|
|
29501
|
-
return args.some((a) => BODY.test(a)) ? UNCOVERED : null;
|
|
29642
|
+
return args.some((a) => BODY.test(a)) ? mapApi(args, words[1] ?? "") ?? UNCOVERED : null;
|
|
29502
29643
|
}
|
|
29503
29644
|
if (group === "work-item" && /^(?:add|create)$/.test(verb))
|
|
29504
29645
|
return mapWrite("time", args);
|
|
@@ -29511,7 +29652,9 @@ var judge = (args, words) => {
|
|
|
29511
29652
|
if (verb === "create")
|
|
29512
29653
|
return mapWrite("create", args);
|
|
29513
29654
|
if (verb === "command")
|
|
29514
|
-
return flagged(args, /^--dry-run$/) ? null :
|
|
29655
|
+
return flagged(args, /^--dry-run$/) ? null : mapIssueWrite("command", args);
|
|
29656
|
+
if (verb === "attach")
|
|
29657
|
+
return mapIssueWrite("attach", args);
|
|
29515
29658
|
return /^(?:edit|update|delete|rm)$/.test(verb) ? UNCOVERED : null;
|
|
29516
29659
|
};
|
|
29517
29660
|
var SHELLS3 = /^(?:sh|bash|zsh|dash|ksh|ash|mksh|yash|fish)$/;
|
|
@@ -29589,7 +29732,10 @@ var passed = (words) => {
|
|
|
29589
29732
|
};
|
|
29590
29733
|
var plainLines = (command, dialect) => {
|
|
29591
29734
|
let first = null;
|
|
29735
|
+
const chain = [];
|
|
29592
29736
|
const later = [];
|
|
29737
|
+
let chaining = !command.includes("||");
|
|
29738
|
+
let piped = false;
|
|
29593
29739
|
for (const segment of segmentsOf(command, dialect)) {
|
|
29594
29740
|
if (segment.group || segment.unanalyzable || segment.subs?.length)
|
|
29595
29741
|
return null;
|
|
@@ -29602,10 +29748,32 @@ var plainLines = (command, dialect) => {
|
|
|
29602
29748
|
if (!names || segment.expands?.length)
|
|
29603
29749
|
return null;
|
|
29604
29750
|
first = passed(segment.words);
|
|
29605
|
-
|
|
29606
|
-
|
|
29751
|
+
chaining &&= name2(first[0]) === "ytrack";
|
|
29752
|
+
} else {
|
|
29753
|
+
const words = passed(segment.words);
|
|
29754
|
+
chaining &&= !piped && !segment.expands?.length && !segment.stdin?.length && !segment.inputs?.length && name2(words[0]) === "ytrack";
|
|
29755
|
+
if (chaining)
|
|
29756
|
+
chain.push(words);
|
|
29757
|
+
else if (names)
|
|
29758
|
+
later.push(segment.words);
|
|
29759
|
+
}
|
|
29760
|
+
piped = segment.pipe === true;
|
|
29607
29761
|
}
|
|
29608
|
-
return first ? { first, later } : null;
|
|
29762
|
+
return first ? { first, chain, later } : null;
|
|
29763
|
+
};
|
|
29764
|
+
var chained = (first, chain, depth) => {
|
|
29765
|
+
if (first.length !== 1 || !first[0].effect || !chain.length)
|
|
29766
|
+
return null;
|
|
29767
|
+
const found = [...first];
|
|
29768
|
+
for (const line of chain)
|
|
29769
|
+
ytrackArgs(line, found, depth, new Map, true);
|
|
29770
|
+
const effects = found.flatMap((write) => write.effect ? [write.effect] : []);
|
|
29771
|
+
if (effects.length !== found.length)
|
|
29772
|
+
return null;
|
|
29773
|
+
const effect = combine(effects);
|
|
29774
|
+
if (!effect)
|
|
29775
|
+
return null;
|
|
29776
|
+
return [{ command: found.map((write) => write.command).join(" && "), ...mapped(effect) }];
|
|
29609
29777
|
};
|
|
29610
29778
|
var ytrackWrites = (command, dialect = "posix", depth = 0, plain = true) => {
|
|
29611
29779
|
if (!namesYtrack(command))
|
|
@@ -29619,7 +29787,11 @@ var ytrackWrites = (command, dialect = "posix", depth = 0, plain = true) => {
|
|
|
29619
29787
|
let found = [];
|
|
29620
29788
|
const lines = plain ? plainLines(command, dialect) : null;
|
|
29621
29789
|
const none = new Map;
|
|
29622
|
-
|
|
29790
|
+
const plainFirst = lines ? ytrackArgs(lines.first, found, depth, none, true) : false;
|
|
29791
|
+
const joined = lines && plainFirst ? chained(found, lines.chain, depth) : null;
|
|
29792
|
+
if (joined)
|
|
29793
|
+
found = joined;
|
|
29794
|
+
if (!lines || !plainFirst || !(joined ? [] : lines.chain).every((line) => ytrackArgs(line, found, depth, none, false)) || !lines.later.every((line) => ytrackArgs(line, found, depth, none, false))) {
|
|
29623
29795
|
found = [];
|
|
29624
29796
|
for (const line of commandLines(command, dialect))
|
|
29625
29797
|
ytrackArgs(line, found, depth, aliases(command), false);
|