@blogic-cz/agent-tools 0.14.31 → 0.14.33
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/package.json +1 -1
- package/src/gh-tool/pr/commands.ts +22 -2
- package/src/gh-tool/pr/core.ts +68 -2
- package/src/gh-tool/types.ts +4 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Command, Flag } from "effect/unstable/cli";
|
|
2
2
|
import { Effect, Option } from "effect";
|
|
3
3
|
|
|
4
|
-
import type { PRStatusResult } from "#gh/types";
|
|
4
|
+
import type { CheckResult, PRStatusResult } from "#gh/types";
|
|
5
5
|
|
|
6
6
|
import { formatOption, logFormatted } from "#shared";
|
|
7
7
|
import { GitHubService } from "#gh/service";
|
|
@@ -56,6 +56,25 @@ const withRepo = <A, E, R>(repo: Option.Option<string>, effect: Effect.Effect<A,
|
|
|
56
56
|
return yield* gh.withRepoTarget(Option.getOrNull(repo), effect);
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
+
type ReviewTriageSummary = {
|
|
60
|
+
readonly visibleOpenReviewThreadsCount: number;
|
|
61
|
+
readonly unrepliedReviewThreadsCount: number;
|
|
62
|
+
readonly unresolvedReviewThreadsCount: number;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const classifyReviewTriage = (
|
|
66
|
+
summary: ReviewTriageSummary,
|
|
67
|
+
checks: readonly CheckResult[],
|
|
68
|
+
) => {
|
|
69
|
+
const reasons = [
|
|
70
|
+
...(checks.some((check) => check.bucket === "fail") ? ["failed_checks"] : []),
|
|
71
|
+
...(summary.visibleOpenReviewThreadsCount > 0 ? ["visible_open_review_threads"] : []),
|
|
72
|
+
...(summary.unrepliedReviewThreadsCount > 0 ? ["unreplied_review_threads"] : []),
|
|
73
|
+
...(summary.unresolvedReviewThreadsCount > 0 ? ["unresolved_review_threads"] : []),
|
|
74
|
+
];
|
|
75
|
+
return { status: reasons.length > 0 ? "needs_investigation" : "clear", reasons };
|
|
76
|
+
};
|
|
77
|
+
|
|
59
78
|
export const prViewCommand = Command.make(
|
|
60
79
|
"view",
|
|
61
80
|
{
|
|
@@ -670,8 +689,9 @@ export const prReviewTriageCommand = Command.make(
|
|
|
670
689
|
fetchDiscussionSummary(prNumber),
|
|
671
690
|
fetchChecks(prNumber, false, false, 0),
|
|
672
691
|
]);
|
|
692
|
+
const classification = classifyReviewTriage(summary, checks);
|
|
673
693
|
yield* logFormatted(
|
|
674
|
-
{ info, unresolvedThreads, visibleOpenThreads, summary, checks },
|
|
694
|
+
{ classification, info, unresolvedThreads, visibleOpenThreads, summary, checks },
|
|
675
695
|
format,
|
|
676
696
|
);
|
|
677
697
|
}),
|
package/src/gh-tool/pr/core.ts
CHANGED
|
@@ -523,16 +523,46 @@ export const mergePR = Effect.fn("pr.mergePR")(function* (opts: {
|
|
|
523
523
|
"number,url,title,headRefName,baseRefName,state,isDraft,mergeable",
|
|
524
524
|
]);
|
|
525
525
|
|
|
526
|
+
// Stacked-PR safety: find open PRs that depend on this PR's head branch.
|
|
527
|
+
// Deleting the head branch of an open PR that uses it as its base CLOSES that
|
|
528
|
+
// PR (GitHub CLI behavior, see cli/cli#1168) instead of retargeting it. We
|
|
529
|
+
// retarget such dependents onto this PR's base first, and only delete the
|
|
530
|
+
// branch if EVERY retarget succeeds (fail-closed).
|
|
531
|
+
const dependentOpenPrs =
|
|
532
|
+
opts.deleteBranch && info.headRefName
|
|
533
|
+
? yield* gh.runGhJson<Array<{ number: number; headRefName: string; baseRefName: string }>>([
|
|
534
|
+
"pr",
|
|
535
|
+
"list",
|
|
536
|
+
"--base",
|
|
537
|
+
info.headRefName,
|
|
538
|
+
"--state",
|
|
539
|
+
"open",
|
|
540
|
+
"--limit",
|
|
541
|
+
"100",
|
|
542
|
+
"--json",
|
|
543
|
+
"number,headRefName,baseRefName",
|
|
544
|
+
])
|
|
545
|
+
: [];
|
|
546
|
+
|
|
526
547
|
if (!opts.confirm) {
|
|
527
548
|
const mergeableNote =
|
|
528
549
|
info.mergeable === "MERGEABLE"
|
|
529
550
|
? "PR is mergeable."
|
|
530
551
|
: `PR mergeable status: ${info.mergeable}`;
|
|
531
552
|
|
|
553
|
+
const dependentNote =
|
|
554
|
+
dependentOpenPrs.length > 0
|
|
555
|
+
? `${dependentOpenPrs.length} dependent open PR(s) (${dependentOpenPrs
|
|
556
|
+
.map((d) => `#${d.number}`)
|
|
557
|
+
.join(", ")}) will be retargeted to \`${info.baseRefName}\` before deletion; ` +
|
|
558
|
+
"branch deletion is skipped if any retarget fails. "
|
|
559
|
+
: "";
|
|
560
|
+
|
|
532
561
|
yield* Console.log(
|
|
533
562
|
`DRY RUN: Would merge PR #${info.number} "${info.title}" via ${opts.strategy.toUpperCase()}. ` +
|
|
534
563
|
`Branch \`${info.headRefName}\` → \`${info.baseRefName}\`. ` +
|
|
535
564
|
(opts.deleteBranch ? `Branch \`${info.headRefName}\` will be deleted. ` : "") +
|
|
565
|
+
dependentNote +
|
|
536
566
|
mergeableNote,
|
|
537
567
|
);
|
|
538
568
|
|
|
@@ -545,9 +575,43 @@ export const mergePR = Effect.fn("pr.mergePR")(function* (opts: {
|
|
|
545
575
|
return result;
|
|
546
576
|
}
|
|
547
577
|
|
|
578
|
+
// Retarget dependents BEFORE merging so the head branch can be deleted safely.
|
|
579
|
+
// If any retarget fails, keep the branch (fail-closed) so no dependent PR is closed.
|
|
580
|
+
let willDeleteBranch = opts.deleteBranch;
|
|
581
|
+
let branchDeleteSkipped = false;
|
|
582
|
+
const retargetedChildren: number[] = [];
|
|
583
|
+
|
|
584
|
+
if (opts.deleteBranch && dependentOpenPrs.length > 0) {
|
|
585
|
+
const repo = yield* gh.getRepoInfo();
|
|
586
|
+
|
|
587
|
+
for (const child of dependentOpenPrs) {
|
|
588
|
+
const retargeted = yield* gh
|
|
589
|
+
.runGh([
|
|
590
|
+
"api",
|
|
591
|
+
"--method",
|
|
592
|
+
"PATCH",
|
|
593
|
+
`repos/${repo.owner}/${repo.name}/pulls/${child.number}`,
|
|
594
|
+
"-f",
|
|
595
|
+
`base=${info.baseRefName}`,
|
|
596
|
+
])
|
|
597
|
+
.pipe(
|
|
598
|
+
Effect.as(true),
|
|
599
|
+
Effect.orElseSucceed(() => false),
|
|
600
|
+
);
|
|
601
|
+
|
|
602
|
+
if (retargeted) {
|
|
603
|
+
retargetedChildren.push(child.number);
|
|
604
|
+
} else {
|
|
605
|
+
willDeleteBranch = false;
|
|
606
|
+
branchDeleteSkipped = true;
|
|
607
|
+
break;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
548
612
|
const mergeArgs = ["pr", "merge", String(opts.pr), `--${opts.strategy}`];
|
|
549
613
|
|
|
550
|
-
if (
|
|
614
|
+
if (willDeleteBranch) {
|
|
551
615
|
mergeArgs.push("--delete-branch");
|
|
552
616
|
}
|
|
553
617
|
|
|
@@ -604,8 +668,10 @@ export const mergePR = Effect.fn("pr.mergePR")(function* (opts: {
|
|
|
604
668
|
const result: MergeResult = {
|
|
605
669
|
merged: true,
|
|
606
670
|
strategy: opts.strategy,
|
|
607
|
-
branchDeleted:
|
|
671
|
+
branchDeleted: willDeleteBranch,
|
|
608
672
|
sha: shaMatch?.[1] ?? null,
|
|
673
|
+
retargetedChildren: retargetedChildren.length > 0 ? retargetedChildren : undefined,
|
|
674
|
+
branchDeleteSkipped: branchDeleteSkipped ? true : undefined,
|
|
609
675
|
};
|
|
610
676
|
return result;
|
|
611
677
|
});
|
package/src/gh-tool/types.ts
CHANGED
|
@@ -127,6 +127,10 @@ export type MergeResult = {
|
|
|
127
127
|
strategy: MergeStrategy;
|
|
128
128
|
branchDeleted: boolean;
|
|
129
129
|
sha: string | null;
|
|
130
|
+
/** PR numbers whose base was retargeted off the deleted branch before deletion. */
|
|
131
|
+
retargetedChildren?: number[];
|
|
132
|
+
/** True when branch deletion was requested but skipped to protect dependent PRs. */
|
|
133
|
+
branchDeleteSkipped?: boolean;
|
|
130
134
|
};
|
|
131
135
|
|
|
132
136
|
export type RepoInfo = {
|