automata-cli 0.2.0-develop.31 → 0.2.0-develop.40
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/index.js +126 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -404,6 +404,73 @@ function deleteLocalBranch(branch) {
|
|
|
404
404
|
throw new Error(`Failed to delete branch ${branch}: ${result.stderr.trim()}`);
|
|
405
405
|
}
|
|
406
406
|
}
|
|
407
|
+
var REVIEW_THREADS_QUERY = `
|
|
408
|
+
query($owner:String!,$repo:String!,$prNumber:Int!){
|
|
409
|
+
repository(owner:$owner,name:$repo){
|
|
410
|
+
pullRequest(number:$prNumber){
|
|
411
|
+
reviewThreads(first:100){
|
|
412
|
+
nodes{
|
|
413
|
+
isResolved
|
|
414
|
+
isOutdated
|
|
415
|
+
comments(first:1){
|
|
416
|
+
nodes{ author{login} body path line createdAt }
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}`.trim();
|
|
423
|
+
function getPrCommentsGh(branch) {
|
|
424
|
+
const prView = run2("gh", ["pr", "view", branch, "--json", "number"]);
|
|
425
|
+
if (prView.status !== 0) {
|
|
426
|
+
if (prView.stderr.includes("no pull requests found") || prView.stderr.includes("Could not resolve")) {
|
|
427
|
+
return null;
|
|
428
|
+
}
|
|
429
|
+
throw new Error(prView.stderr.trim() || "Failed to query GitHub. Is `gh` installed and authenticated?");
|
|
430
|
+
}
|
|
431
|
+
const { number: prNumber } = JSON.parse(prView.stdout);
|
|
432
|
+
const ownerRepo = parseOwnerRepo();
|
|
433
|
+
if (!ownerRepo) {
|
|
434
|
+
throw new Error("Could not determine GitHub owner/repo from git remote. Is 'origin' set to a GitHub URL?");
|
|
435
|
+
}
|
|
436
|
+
const slashIdx = ownerRepo.indexOf("/");
|
|
437
|
+
const owner = ownerRepo.slice(0, slashIdx);
|
|
438
|
+
const repo = ownerRepo.slice(slashIdx + 1);
|
|
439
|
+
const gql = run2("gh", [
|
|
440
|
+
"api",
|
|
441
|
+
"graphql",
|
|
442
|
+
"-f",
|
|
443
|
+
`query=${REVIEW_THREADS_QUERY}`,
|
|
444
|
+
"-f",
|
|
445
|
+
`owner=${owner}`,
|
|
446
|
+
"-f",
|
|
447
|
+
`repo=${repo}`,
|
|
448
|
+
"-F",
|
|
449
|
+
`prNumber=${String(prNumber)}`
|
|
450
|
+
]);
|
|
451
|
+
if (gql.status !== 0) {
|
|
452
|
+
throw new Error(gql.stderr.trim() || "Failed to query GitHub GraphQL API.");
|
|
453
|
+
}
|
|
454
|
+
const response = JSON.parse(gql.stdout);
|
|
455
|
+
const threads = response.data.repository.pullRequest.reviewThreads.nodes;
|
|
456
|
+
return threads.filter((t) => !t.isResolved && t.comments.nodes.length > 0).map((t) => {
|
|
457
|
+
const c = t.comments.nodes[0];
|
|
458
|
+
return {
|
|
459
|
+
author: c.author.login,
|
|
460
|
+
body: c.body,
|
|
461
|
+
path: c.path,
|
|
462
|
+
line: c.line ?? null,
|
|
463
|
+
createdAt: c.createdAt
|
|
464
|
+
};
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
function getPrComments(branch) {
|
|
468
|
+
const config = readConfig();
|
|
469
|
+
if (config.remoteType === "azdo") {
|
|
470
|
+
return "unsupported";
|
|
471
|
+
}
|
|
472
|
+
return getPrCommentsGh(branch);
|
|
473
|
+
}
|
|
407
474
|
|
|
408
475
|
// src/commands/git.ts
|
|
409
476
|
var FAIL_CONCLUSIONS = /* @__PURE__ */ new Set(["FAILURE", "TIMED_OUT", "ACTION_REQUIRED", "CANCELLED"]);
|
|
@@ -543,6 +610,64 @@ URL: ${pr.url}
|
|
|
543
610
|
process.stdout.write(formatChecks(pr.checks));
|
|
544
611
|
}
|
|
545
612
|
});
|
|
613
|
+
var ANSI_ESCAPE_RE = new RegExp("\x1B(?:[@-Z\\\\-_]|\\[[0-?]*[ -/]*[@-~])", "g");
|
|
614
|
+
var CONTROL_CHARS_RE = new RegExp("[\0-\b\v\f-\x7F]", "g");
|
|
615
|
+
function sanitizeText(text) {
|
|
616
|
+
return text.replace(ANSI_ESCAPE_RE, "").replace(CONTROL_CHARS_RE, "");
|
|
617
|
+
}
|
|
618
|
+
var getPrCommentsCmd = new Command2("get-pr-comments").description("List open (unresolved) review comments on the pull request for the current branch (GitHub only)").option("--json", "Output as JSON array").addHelpText(
|
|
619
|
+
"after",
|
|
620
|
+
`
|
|
621
|
+
Only GitHub (remoteType: gh) is supported. Azure DevOps is not supported.
|
|
622
|
+
See docs/azdo-gap.md for details.`
|
|
623
|
+
).action((options) => {
|
|
624
|
+
let branch;
|
|
625
|
+
try {
|
|
626
|
+
branch = getCurrentBranch();
|
|
627
|
+
} catch (err) {
|
|
628
|
+
process.stderr.write(`Error: ${err.message}
|
|
629
|
+
`);
|
|
630
|
+
process.exit(1);
|
|
631
|
+
}
|
|
632
|
+
let comments;
|
|
633
|
+
try {
|
|
634
|
+
comments = getPrComments(branch);
|
|
635
|
+
} catch (err) {
|
|
636
|
+
process.stderr.write(`Error: ${err.message}
|
|
637
|
+
`);
|
|
638
|
+
process.exit(1);
|
|
639
|
+
}
|
|
640
|
+
if (comments === "unsupported") {
|
|
641
|
+
process.stderr.write(
|
|
642
|
+
`Error: get-pr-comments is not supported for Azure DevOps. See docs/azdo-gap.md for details.
|
|
643
|
+
`
|
|
644
|
+
);
|
|
645
|
+
process.exit(1);
|
|
646
|
+
}
|
|
647
|
+
if (comments === null) {
|
|
648
|
+
process.stderr.write(`Error: No pull request found for branch: ${branch}
|
|
649
|
+
`);
|
|
650
|
+
process.exit(1);
|
|
651
|
+
}
|
|
652
|
+
if (options.json) {
|
|
653
|
+
process.stdout.write(JSON.stringify(comments, null, 2) + "\n");
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
if (comments.length === 0) {
|
|
657
|
+
process.stdout.write(`No open comments.
|
|
658
|
+
`);
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
const lines = [];
|
|
662
|
+
for (const c of comments) {
|
|
663
|
+
const loc = c.line !== null ? `${c.path}:${String(c.line)}` : `${c.path}:(file)`;
|
|
664
|
+
const safeBody = sanitizeText(c.body);
|
|
665
|
+
const safeAuthor = sanitizeText(c.author);
|
|
666
|
+
lines.push(`[${safeAuthor}] on ${loc}
|
|
667
|
+
${safeBody}`);
|
|
668
|
+
}
|
|
669
|
+
process.stdout.write(lines.join("\n\n") + "\n");
|
|
670
|
+
});
|
|
546
671
|
var finishFeatureCmd = new Command2("finish-feature").description("Clean up a merged feature branch: checkout develop, pull, and delete local branch").action(() => {
|
|
547
672
|
let branch;
|
|
548
673
|
try {
|
|
@@ -612,7 +737,7 @@ var finishFeatureCmd = new Command2("finish-feature").description("Clean up a me
|
|
|
612
737
|
process.exit(1);
|
|
613
738
|
}
|
|
614
739
|
});
|
|
615
|
-
var gitCommand = new Command2("git").description("Git workflow commands (requires gh CLI)").addCommand(getPrInfoCmd).addCommand(finishFeatureCmd);
|
|
740
|
+
var gitCommand = new Command2("git").description("Git workflow commands (requires gh CLI)").addCommand(getPrInfoCmd).addCommand(getPrCommentsCmd).addCommand(finishFeatureCmd);
|
|
616
741
|
|
|
617
742
|
// src/commands/getReady.ts
|
|
618
743
|
import { Command as Command3 } from "commander";
|