pr-shepherd 2.2.6 → 2.2.7
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/.claude-plugin/plugin.json +1 -1
- package/bin/cli/iterate-instructions.mjs +3 -0
- package/bin/cli/list-formatters.d.mts +3 -1
- package/bin/cli/list-formatters.mjs +7 -4
- package/bin/cli/stack-layer-view.d.mts +5 -0
- package/bin/cli/stack-layer-view.mjs +11 -1
- package/bin/cli/stack-overview.d.mts +1 -1
- package/bin/cli/stack-overview.mjs +5 -3
- package/bin/commands/apply-merge-resume.d.mts +22 -0
- package/bin/commands/apply-merge-resume.mjs +56 -0
- package/bin/commands/apply-merge.mjs +11 -19
- package/bin/commands/check.mjs +5 -4
- package/bin/commands/iterate/check-follow-up.mjs +1 -1
- package/bin/commands/iterate/index.mjs +4 -4
- package/bin/commands/iterate/merge-plan.d.mts +4 -0
- package/bin/commands/iterate/merge-plan.mjs +18 -0
- package/bin/commands/iterate/merge-state.mjs +2 -0
- package/bin/commands/iterate/report-gaps.d.mts +6 -0
- package/bin/commands/iterate/report-gaps.mjs +5 -0
- package/bin/commands/poll-summary.mjs +3 -1
- package/bin/commands/review-commit.d.mts +2 -2
- package/bin/commands/review-commit.mjs +11 -4
- package/bin/commands/stack-merge-plan.mjs +5 -3
- package/bin/commands/stack-merge-trunk-check.d.mts +12 -0
- package/bin/commands/stack-merge-trunk-check.mjs +26 -0
- package/bin/commands/stack-trunk-behind.d.mts +9 -0
- package/bin/commands/stack-trunk-behind.mjs +51 -0
- package/bin/config/merge-method.d.mts +2 -0
- package/bin/config/merge-method.mjs +17 -0
- package/bin/github/batch-parsers.mjs +9 -0
- package/bin/github/batch-raw-types.d.mts +8 -0
- package/bin/github/gql/batch-pr.gql +8 -0
- package/bin/github/poll-summary-readiness.mjs +2 -1
- package/bin/github/poll-summary-route.mjs +2 -1
- package/bin/github/rest-merge.d.mts +10 -0
- package/bin/github/rest-merge.mjs +26 -0
- package/bin/github/transport-evidence.d.mts +9 -2
- package/bin/github/transport-evidence.mjs +15 -3
- package/bin/state/merge-request.d.mts +6 -0
- package/bin/state/merge-request.mjs +9 -1
- package/bin/types/github.d.mts +2 -0
- package/bin/types/merge-action.d.mts +6 -0
- package/bin/types/poll-summary.d.mts +4 -0
- package/package.json +1 -1
- package/plugins/pr-shepherd/.claude-plugin/plugin.json +1 -1
- package/plugins/pr-shepherd/.codex-plugin/plugin.json +1 -1
- package/plugins/pr-shepherd/skills/pr-shepherd/SKILL.md +1 -1
- package/plugins/pr-shepherd/skills/pr-shepherd/references/check-follow-up.md +1 -1
- package/plugins/pr-shepherd/skills/pr-shepherd/references/ci-start-stall.md +1 -1
- package/plugins/pr-shepherd/skills/pr-shepherd/references/required-checks-unreported.md +1 -1
|
@@ -59,6 +59,9 @@ export function buildSimpleIterateInstructions(result) {
|
|
|
59
59
|
else if (result.merge.fallbackCommand) {
|
|
60
60
|
instructions.push(`Only if GitHub reports that auto-merge is unavailable, run the plain merge fallback: ${inlineCode(renderShellCommand(result.merge.fallbackCommand.argv))}.`);
|
|
61
61
|
}
|
|
62
|
+
if (result.merge.restFallbackCommand) {
|
|
63
|
+
instructions.push(`If GraphQL is rate limited, use REST: ${inlineCode(renderShellCommand(result.merge.restFallbackCommand.argv))}.`);
|
|
64
|
+
}
|
|
62
65
|
instructions.push(result.quotaWarning
|
|
63
66
|
? buildQuotaAwareContinuation(result.quotaWarning, "After running the merge command.")
|
|
64
67
|
: "Then iterate immediately with the same options until the PR merges or needs work.");
|
|
@@ -49,10 +49,11 @@ export declare function renderCommentBullet(c: {
|
|
|
49
49
|
}, opts?: {
|
|
50
50
|
statusTag?: string;
|
|
51
51
|
}): string;
|
|
52
|
-
/** ` [
|
|
52
|
+
/** ` [reviewed <sha>, head <sha>, N commits since]` when the review is on a commit other than the PR head. */
|
|
53
53
|
export declare function renderReviewCommitTag(r: {
|
|
54
54
|
commitOid?: string;
|
|
55
55
|
headOid?: string;
|
|
56
|
+
commitsSince?: number;
|
|
56
57
|
}): string;
|
|
57
58
|
export declare function renderReviewBullet(r: {
|
|
58
59
|
id: string;
|
|
@@ -64,6 +65,7 @@ export declare function renderReviewBullet(r: {
|
|
|
64
65
|
staleReview?: boolean;
|
|
65
66
|
commitOid?: string;
|
|
66
67
|
headOid?: string;
|
|
68
|
+
commitsSince?: number;
|
|
67
69
|
}, opts?: {
|
|
68
70
|
includeBody?: boolean;
|
|
69
71
|
}): string;
|
|
@@ -103,11 +103,14 @@ export function renderCommentBullet(c, opts = {}) {
|
|
|
103
103
|
const statusSuffix = opts.statusTag ? ` ${opts.statusTag}` : "";
|
|
104
104
|
return `- \`commentId=${c.id}\`${link} (${renderAuthor(c.author, c.authorType, c.authorAssociation)})${statusSuffix}: ${renderBodyPreview(c.body)}`;
|
|
105
105
|
}
|
|
106
|
-
/** ` [
|
|
106
|
+
/** ` [reviewed <sha>, head <sha>, N commits since]` when the review is on a commit other than the PR head. */
|
|
107
107
|
export function renderReviewCommitTag(r) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
if (!r.commitOid || !r.headOid)
|
|
109
|
+
return "";
|
|
110
|
+
const since = r.commitsSince === undefined
|
|
111
|
+
? ""
|
|
112
|
+
: `, ${r.commitsSince} commit${r.commitsSince === 1 ? "" : "s"} since`;
|
|
113
|
+
return ` [reviewed \`${r.commitOid}\`, head \`${r.headOid}\`${since}]`;
|
|
111
114
|
}
|
|
112
115
|
export function renderReviewBullet(r, opts = {}) {
|
|
113
116
|
const base = `- \`reviewId=${r.id}\` (${renderAuthor(r.author, r.authorType, r.authorAssociation)})${renderReviewCommitTag(r)}`;
|
|
@@ -27,8 +27,13 @@ export interface StackLayerView {
|
|
|
27
27
|
checksIncomplete?: true;
|
|
28
28
|
reviewIncomplete?: true;
|
|
29
29
|
ruleAutoResolve?: PollSummaryRuleAutoResolve;
|
|
30
|
+
trunkBehindBy?: number;
|
|
31
|
+
trunkBehindUnknown?: true;
|
|
30
32
|
queueRemoval?: {
|
|
31
33
|
reason: string | null;
|
|
32
34
|
actor?: string;
|
|
33
35
|
};
|
|
34
36
|
}
|
|
37
|
+
/** The `trunk behind` detail of a merge-top row, or undefined when trunk is not ahead. */
|
|
38
|
+
export declare function trunkDetail(layer: StackLayerView): string | undefined;
|
|
39
|
+
export declare function removalDetail(removal: StackLayerView["queueRemoval"]): string | undefined;
|
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/** The `trunk behind` detail of a merge-top row, or undefined when trunk is not ahead. */
|
|
2
|
+
export function trunkDetail(layer) {
|
|
3
|
+
if (layer.trunkBehindBy)
|
|
4
|
+
return `trunk behind ${layer.trunkBehindBy}`;
|
|
5
|
+
return layer.trunkBehindUnknown ? "trunk behind unknown" : undefined;
|
|
6
|
+
}
|
|
7
|
+
export function removalDetail(removal) {
|
|
8
|
+
if (!removal)
|
|
9
|
+
return undefined;
|
|
10
|
+
return `removed from merge queue (${removal.reason ?? "unknown reason"}${removal.actor ? ` by @${removal.actor}` : ""})`;
|
|
11
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PollSummaryResult, PollSummaryStackAncestry, StackNextAction } from "../types.mts";
|
|
2
2
|
import type { ApiUsage, GraphqlQuotaWarning } from "../types/api-usage.mts";
|
|
3
|
-
import type
|
|
3
|
+
import { type StackLayerView } from "./stack-layer-view.mts";
|
|
4
4
|
import type { NextCheck } from "../types/next-check.mts";
|
|
5
5
|
export interface StackOverview {
|
|
6
6
|
transport?: "rest";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { stackLayerBlockReason } from "../commands/stack-layer-readiness.mjs";
|
|
2
2
|
import { formatApiUsage, formatQuotaWarning } from "./api-usage-formatter.mjs";
|
|
3
3
|
import { formatTransportEvidence } from "./transport-formatter.mjs";
|
|
4
|
+
import { removalDetail, trunkDetail } from "./stack-layer-view.mjs";
|
|
4
5
|
import { formatNextCheckLines } from "./next-check-format.mjs";
|
|
5
6
|
import { formatPrUrl } from "../pr-reference.mjs";
|
|
6
7
|
import { formatRuleAutoResolveLines } from "./rule-auto-resolve-lines.mjs";
|
|
@@ -62,6 +63,8 @@ function projectLayer(item, stale) {
|
|
|
62
63
|
...(item.checks?.incomplete && { checksIncomplete: true }),
|
|
63
64
|
...(item.review?.incomplete && { reviewIncomplete: true }),
|
|
64
65
|
...(item.ruleAutoResolve && { ruleAutoResolve: item.ruleAutoResolve }),
|
|
66
|
+
...(item.trunkBehindBy && { trunkBehindBy: item.trunkBehindBy }),
|
|
67
|
+
...(item.trunkBehindUnknown && { trunkBehindUnknown: true }),
|
|
65
68
|
...(removal && {
|
|
66
69
|
queueRemoval: {
|
|
67
70
|
reason: removal.reason,
|
|
@@ -155,9 +158,8 @@ function formatLayerLines(layer, index, overview) {
|
|
|
155
158
|
layer.actionable ? `${layer.actionable} actionable` : undefined,
|
|
156
159
|
layer.checksIncomplete ? "checks incomplete" : undefined,
|
|
157
160
|
layer.reviewIncomplete ? "review incomplete" : undefined,
|
|
158
|
-
layer
|
|
159
|
-
|
|
160
|
-
: undefined,
|
|
161
|
+
trunkDetail(layer),
|
|
162
|
+
removalDetail(layer.queueRemoval),
|
|
161
163
|
].filter((detail) => detail !== undefined);
|
|
162
164
|
return [
|
|
163
165
|
`- ${layer.url === formatPrUrl(overview.repo, layer.pr) ? `PR #${layer.pr}: ${layer.title}` : `[PR #${layer.pr}: ${layer.title}](${layer.url})`}${facts.length > 0 ? ` — ${facts.join(" · ")}` : ""}`,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { RepoInfo } from "../github/client.mts";
|
|
2
|
+
import { type RestMergeOptions } from "../github/rest-merge.mts";
|
|
3
|
+
import { type MergeRequestRecord } from "../state/merge-request.mts";
|
|
4
|
+
import type { mergeResultFactory } from "./apply-merge-output.mts";
|
|
5
|
+
import type { ApplyMergeResult } from "./apply-merge.mts";
|
|
6
|
+
interface ResumeContext {
|
|
7
|
+
repo: RepoInfo;
|
|
8
|
+
pr: number;
|
|
9
|
+
key: {
|
|
10
|
+
owner: string;
|
|
11
|
+
repo: string;
|
|
12
|
+
pr: number;
|
|
13
|
+
};
|
|
14
|
+
existing: MergeRequestRecord & {
|
|
15
|
+
uuid: string;
|
|
16
|
+
};
|
|
17
|
+
options: RestMergeOptions;
|
|
18
|
+
factory: ReturnType<typeof mergeResultFactory>;
|
|
19
|
+
}
|
|
20
|
+
/** Resume a recorded asynchronous request, falling back to the synchronous merge when unreadable. */
|
|
21
|
+
export declare function resumeMergeRequest(ctx: ResumeContext): Promise<ApplyMergeResult>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { GitHubRequestError } from "../github/errors.mjs";
|
|
2
|
+
import { getRestMerge, matchesRestMergeRequest, requestRestSyncMerge, } from "../github/rest-merge.mjs";
|
|
3
|
+
import { clearMergeRequest, writeMergeRequestStatus, } from "../state/merge-request.mjs";
|
|
4
|
+
import { mergedResponse, readPull } from "./apply-merge-pull.mjs";
|
|
5
|
+
/** Resume a recorded asynchronous request, falling back to the synchronous merge when unreadable. */
|
|
6
|
+
export async function resumeMergeRequest(ctx) {
|
|
7
|
+
const { repo, pr, key, existing, options, factory } = ctx;
|
|
8
|
+
const { failed, project } = factory;
|
|
9
|
+
try {
|
|
10
|
+
const response = await getRestMerge(repo, pr, existing.uuid);
|
|
11
|
+
if (response.status === "pending" &&
|
|
12
|
+
(!matchesRestMergeRequest(response, options) || response.details.uuid !== existing.uuid))
|
|
13
|
+
return failed("Asynchronous merge status does not match the persisted guarded request.", true);
|
|
14
|
+
await writeMergeRequestStatus(key, { ...existing, response });
|
|
15
|
+
return project(response);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
// 404: the UUID expired. 403: the token cannot read merge-async status at all (for example a
|
|
19
|
+
// GitHub App installation without that permission). Either way the status is unknown, so the
|
|
20
|
+
// pull itself decides, and an unmerged direct merge converges through the synchronous route.
|
|
21
|
+
if (!(error instanceof GitHubRequestError) || (error.status !== 404 && error.status !== 403))
|
|
22
|
+
throw error;
|
|
23
|
+
const latest = await readPull(repo, pr);
|
|
24
|
+
if (latest.merged === true)
|
|
25
|
+
return project(mergedResponse(latest, "Pull request is merged; its asynchronous status was unreadable."));
|
|
26
|
+
// The synchronous route guards the head SHA itself; queue, default, method-less, and native
|
|
27
|
+
// stack requests have no synchronous equivalent, so their unknown outcome stays blocked.
|
|
28
|
+
if (options.mergeAction !== "direct_merge" || !options.mergeMethod || options.expectedStack)
|
|
29
|
+
return failed(`The asynchronous merge status is unavailable (${error.status}). The PR is not merged; its request outcome is unknown and no duplicate was submitted.`, true);
|
|
30
|
+
return syncFallback(ctx, options.mergeMethod);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function syncFallback(ctx, mergeMethod) {
|
|
34
|
+
const { repo, pr, key, options, factory } = ctx;
|
|
35
|
+
try {
|
|
36
|
+
const response = await requestRestSyncMerge(repo, pr, {
|
|
37
|
+
requireSha: options.requireSha,
|
|
38
|
+
mergeMethod,
|
|
39
|
+
});
|
|
40
|
+
await clearMergeRequest(key);
|
|
41
|
+
return factory.project({
|
|
42
|
+
...response,
|
|
43
|
+
details: {
|
|
44
|
+
...response.details,
|
|
45
|
+
message: `${response.details.message ?? ""} (merged synchronously: the asynchronous status was unreadable)`.trim(),
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
// A definite refusal (not mergeable, head changed) retires the stale request so the next
|
|
51
|
+
// command starts a fresh guarded attempt; an unknown outcome keeps the record and retries.
|
|
52
|
+
if (error instanceof GitHubRequestError && error.status >= 400 && error.status < 500)
|
|
53
|
+
await clearMergeRequest(key);
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -6,10 +6,11 @@ import { EXIT, ShepherdError } from "../exit-codes.mjs";
|
|
|
6
6
|
import { getCurrentPrNumber, getRepoInfo } from "../github/client.mjs";
|
|
7
7
|
import { GitHubRequestError } from "../github/errors.mjs";
|
|
8
8
|
import { mergedResponse, readPull } from "./apply-merge-pull.mjs";
|
|
9
|
+
import { resumeMergeRequest } from "./apply-merge-resume.mjs";
|
|
9
10
|
import { withRestConditionalScope } from "../github/rest-conditional-scope.mjs";
|
|
10
11
|
import { getGithubTransport } from "../github/transport.mjs";
|
|
11
|
-
import {
|
|
12
|
-
import { claimMergeRequest, replaceFailedMergeRequest, readMergeRequest, writeMergeRequest,
|
|
12
|
+
import { matchesRestMergeRequest, requestRestMerge, } from "../github/rest-merge.mjs";
|
|
13
|
+
import { claimMergeRequest, replaceFailedMergeRequest, readMergeRequest, writeMergeRequest, } from "../state/merge-request.mjs";
|
|
13
14
|
/** Submit one guarded asynchronous request, or resume its existing UUID without resubmitting. */
|
|
14
15
|
export async function runApplyMerge(input) {
|
|
15
16
|
validateApplyMergeOptions(input);
|
|
@@ -61,23 +62,14 @@ async function submitApplyMerge(input, repo, pr, key) {
|
|
|
61
62
|
};
|
|
62
63
|
if (!existing.uuid)
|
|
63
64
|
return failed("The previous merge submission has an unknown outcome and no UUID. The PR is not merged; no duplicate request was submitted.", true);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
if (error instanceof GitHubRequestError && error.status === 404) {
|
|
74
|
-
const latest = await readPull(repo, pr);
|
|
75
|
-
if (latest.merged === true)
|
|
76
|
-
return project(mergedResponse(latest, "Pull request is merged; its asynchronous request has expired."));
|
|
77
|
-
return failed("The asynchronous merge UUID expired or is unavailable. The PR is not merged; its request outcome is unknown and no duplicate was submitted.", true);
|
|
78
|
-
}
|
|
79
|
-
throw error;
|
|
80
|
-
}
|
|
65
|
+
return resumeMergeRequest({
|
|
66
|
+
repo,
|
|
67
|
+
pr,
|
|
68
|
+
key,
|
|
69
|
+
existing: { ...existing, uuid: existing.uuid },
|
|
70
|
+
options,
|
|
71
|
+
factory: { failed, project },
|
|
72
|
+
});
|
|
81
73
|
}
|
|
82
74
|
let record = {
|
|
83
75
|
version: 1,
|
package/bin/commands/check.mjs
CHANGED
|
@@ -25,7 +25,7 @@ import { buildTerminalReport } from "./check-terminal-report.mjs";
|
|
|
25
25
|
import { isBlockedByFilteredCheck, refreshReadyMergeability, refreshUnknownMergeability, } from "./ready-mergeability.mjs";
|
|
26
26
|
import { loadSeenMap, markSeen, classifyItem, mutationWasDenied } from "../state/seen-comments.mjs";
|
|
27
27
|
import { aliasThreadSeenMarkers } from "../github/rest-identities.mjs";
|
|
28
|
-
import { transportReadinessGaps } from "../github/transport-evidence.mjs";
|
|
28
|
+
import { conversationResolutionProven, transportReadinessGaps, } from "../github/transport-evidence.mjs";
|
|
29
29
|
import { canGenerateGithubMutation } from "../github/mutation-policy.mjs";
|
|
30
30
|
import { threadTranscriptBody } from "../threads/transcript.mjs";
|
|
31
31
|
import { classifyThreadVisibility } from "../comments/thread-visibility.mjs";
|
|
@@ -43,11 +43,12 @@ import { getEffectiveCwd } from "../execution-context.mjs";
|
|
|
43
43
|
function enforceTransportReadiness(status, data) {
|
|
44
44
|
if (status !== "READY" || data.transport !== "rest")
|
|
45
45
|
return status;
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const conversationsGated = data.branchRules?.requiresConversationResolution;
|
|
47
|
+
const statusProven = conversationResolutionProven(data.mergeStateStatus, conversationsGated);
|
|
48
|
+
if (data.reviewThreads.some((thread) => (!statusProven && (thread.isResolved === undefined || thread.isOutdated === undefined)) ||
|
|
48
49
|
thread.comments === undefined))
|
|
49
50
|
return "UNKNOWN";
|
|
50
|
-
if (transportReadinessGaps(data, data.mergeStateStatus).length > 0)
|
|
51
|
+
if (transportReadinessGaps(data, data.mergeStateStatus, conversationsGated).length > 0)
|
|
51
52
|
return "UNKNOWN";
|
|
52
53
|
return status;
|
|
53
54
|
}
|
|
@@ -29,7 +29,7 @@ export function buildCheckFollowUpInstructions(checks, repo, actionsRunIds) {
|
|
|
29
29
|
: "";
|
|
30
30
|
return [
|
|
31
31
|
`Shepherd has no rerun to offer and no log excerpt to show for the checks under \`## Failing checks\`, so it cannot tell from GitHub's data why they failed or what would fix them. Find out before acting.${start} ${playbookPointer("Check follow-up")}`,
|
|
32
|
-
"If the cause is within this PR, fix it and push. Otherwise make no change and keep what you found; do not rerun or retrigger these checks. If these checks are unchanged on the next poll, Shepherd escalates with `check-follow-up-unavailable`; report that diagnosis then.",
|
|
32
|
+
"If the cause is within this PR, fix it and push. Otherwise make no change and keep what you found; do not rerun or retrigger these checks, including with an empty or no-op commit. If these checks are unchanged on the next poll, Shepherd escalates with `check-follow-up-unavailable`; report that diagnosis then.",
|
|
33
33
|
];
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
@@ -30,7 +30,7 @@ import { findStaleNativeStackAncestry } from "./stale-ancestry.mjs";
|
|
|
30
30
|
import { annotateBlockedWait, resolveCheckBlockerGate } from "./check-blocker-gate.mjs";
|
|
31
31
|
import { buildUnreportedFixResult, planUnreportedRequired } from "./unreported-required.mjs";
|
|
32
32
|
import { createCheckExecutionContext } from "../check-execution-context.mjs";
|
|
33
|
-
import {
|
|
33
|
+
import { reportReadinessGaps } from "./report-gaps.mjs";
|
|
34
34
|
import { buildEscalateHumanMessage } from "./escalate.mjs";
|
|
35
35
|
import { markEditedCommentsSeen } from "./edited-comment-markers.mjs";
|
|
36
36
|
export function runIterate(opts) {
|
|
@@ -282,7 +282,7 @@ async function runIterateCore(opts, tick) {
|
|
|
282
282
|
const canMarkReady = report.status === "READY" &&
|
|
283
283
|
report.mergeStatus.isDraft &&
|
|
284
284
|
!report.mergeStatus.blockingBotReviewInProgress;
|
|
285
|
-
const gaps =
|
|
285
|
+
const gaps = reportReadinessGaps(report);
|
|
286
286
|
if (gaps.length > 0 &&
|
|
287
287
|
report.checks.inProgress.length === 0 &&
|
|
288
288
|
report.mergeStatus.mergeStateStatus !== "UNKNOWN") {
|
|
@@ -384,7 +384,7 @@ async function recordReadyReceipt(key, report, context) {
|
|
|
384
384
|
report.mergeStatus.isDraft ||
|
|
385
385
|
!report.headSha ||
|
|
386
386
|
!report.baseRefOid ||
|
|
387
|
-
|
|
387
|
+
reportReadinessGaps(report).length > 0)
|
|
388
388
|
return "failed";
|
|
389
389
|
try {
|
|
390
390
|
const raw = await receiptSummaryForReport(key, report, context);
|
|
@@ -457,7 +457,7 @@ async function revalidateReadyReceipt(key, report, hasReadinessWork, context) {
|
|
|
457
457
|
report.mergeStatus.isDraft ||
|
|
458
458
|
!report.headSha ||
|
|
459
459
|
!report.baseRefOid ||
|
|
460
|
-
|
|
460
|
+
reportReadinessGaps(report).length > 0 ||
|
|
461
461
|
(!retainQueuedReceipt && (report.status !== "READY" || hasReadinessWork))) {
|
|
462
462
|
await clearReadyReceipt(key);
|
|
463
463
|
return false;
|
|
@@ -13,6 +13,10 @@ export interface MergePlanInput {
|
|
|
13
13
|
queueKnown?: boolean;
|
|
14
14
|
/** Omitted when the batch did not select repository merge settings. */
|
|
15
15
|
allowedMergeMethods?: readonly MergeMethod[];
|
|
16
|
+
/** Branch policy requires linear history, so merge commits are excluded. */
|
|
17
|
+
linearHistory?: boolean;
|
|
18
|
+
/** Attach a REST equivalent of the GraphQL merge commands, for when GraphQL quota runs out. */
|
|
19
|
+
restFallback?: boolean;
|
|
16
20
|
expectedStack?: RestMergeStackGuard;
|
|
17
21
|
}
|
|
18
22
|
export interface MergeMethodUnavailable {
|
|
@@ -24,6 +24,7 @@ export function buildMergeCommandPlan(input) {
|
|
|
24
24
|
allowed: input.allowedMergeMethods,
|
|
25
25
|
configured,
|
|
26
26
|
fallback: "merge",
|
|
27
|
+
linearHistory: input.linearHistory,
|
|
27
28
|
});
|
|
28
29
|
if ("unavailable" in decision)
|
|
29
30
|
return decision;
|
|
@@ -81,6 +82,7 @@ export function buildMergeCommandPlan(input) {
|
|
|
81
82
|
allowed: input.allowedMergeMethods,
|
|
82
83
|
configured: configuredMergeMethod(mergeConfig),
|
|
83
84
|
fallback: "merge",
|
|
85
|
+
linearHistory: input.linearHistory,
|
|
84
86
|
});
|
|
85
87
|
if ("unavailable" in decision)
|
|
86
88
|
return decision;
|
|
@@ -90,5 +92,21 @@ export function buildMergeCommandPlan(input) {
|
|
|
90
92
|
mode: "auto",
|
|
91
93
|
command: { argv: [...base, "--auto", ...commandArgs] },
|
|
92
94
|
fallbackCommand: { argv: [...base, ...commandArgs] },
|
|
95
|
+
// `gh pr merge` is GraphQL; this REST call has its own quota and merges immediately.
|
|
96
|
+
...(input.restFallback && {
|
|
97
|
+
restFallbackCommand: {
|
|
98
|
+
argv: [
|
|
99
|
+
"gh",
|
|
100
|
+
"api",
|
|
101
|
+
"-X",
|
|
102
|
+
"PUT",
|
|
103
|
+
`repos/${input.repo}/pulls/${input.pr}/merge`,
|
|
104
|
+
"-f",
|
|
105
|
+
`sha=${input.headSha}`,
|
|
106
|
+
"-f",
|
|
107
|
+
`merge_method=${decision.method}`,
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
}),
|
|
93
111
|
};
|
|
94
112
|
}
|
|
@@ -56,6 +56,8 @@ export function buildReadyMergeOutcome(enabled, readyElapsed, base, report) {
|
|
|
56
56
|
queueKnown: (report.transport !== "rest" || report.branchProtection === null) &&
|
|
57
57
|
!(report.transportUnavailable ?? []).some(({ field }) => ["branchProtection", "branchRules"].includes(field)),
|
|
58
58
|
...(report.allowedMergeMethods && { allowedMergeMethods: report.allowedMergeMethods }),
|
|
59
|
+
restFallback: true,
|
|
60
|
+
linearHistory: report.mergeStatus.mergeRequirements?.linearHistory?.required === true,
|
|
59
61
|
});
|
|
60
62
|
if ("unavailable" in plan) {
|
|
61
63
|
// A REST policy read that may succeed on a later poll waits under the stall timer.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { transportReadinessGaps } from "../../github/transport-evidence.mjs";
|
|
2
|
+
/** Transport readiness gaps for a report, using its branch policy to clear provable gaps. */
|
|
3
|
+
export function reportReadinessGaps(report) {
|
|
4
|
+
return transportReadinessGaps(report, report.mergeStatus.mergeStateStatus, report.mergeStatus.mergeRequirements?.conversationsResolved.required);
|
|
5
|
+
}
|
|
@@ -15,6 +15,7 @@ import { summaryStatusSignature } from "./poll-summary-signature.mjs";
|
|
|
15
15
|
import { applyStackStallGuard, isStackRepairTick } from "./stack-stall.mjs";
|
|
16
16
|
import { applyStackOwnership, listedLayerLeftStack, missingListedLayers, } from "./stack-ownership.mjs";
|
|
17
17
|
import { stackRerunTarget } from "./stack-work.mjs";
|
|
18
|
+
import { withTrunkBehind } from "./stack-trunk-behind.mjs";
|
|
18
19
|
import { requestedMergeScope, stackAddedLayers } from "./stack-merge-scope.mjs";
|
|
19
20
|
import { aggregateDeadline } from "./stall-deadline.mjs";
|
|
20
21
|
import { aggregateTargets, pauseBeforeNextTick, withPollEvents, } from "./poll-events.mjs";
|
|
@@ -80,7 +81,8 @@ async function readPollSummaryTick(opts) {
|
|
|
80
81
|
return { result: escalated, repo };
|
|
81
82
|
}
|
|
82
83
|
const addedLayers = await stackAddedLayers(summary, scope, rerunCommand);
|
|
83
|
-
const
|
|
84
|
+
const withBehind = await withTrunkBehind(summary, scope);
|
|
85
|
+
const planned = planPollSummary({ ...withBehind, ...(addedLayers.length > 0 && { addedLayers }) }, scope !== undefined, rerunCommand, scope, (extra) => stackApprovalCommands(`${repo.owner}/${repo.name}`, fetched.selection, opts, extra));
|
|
84
86
|
const result = await applyStackStallGuard(planned, repo, opts.stallTimeoutSeconds ?? loadConfig().iterate["stall-timeout-minutes"] * 60);
|
|
85
87
|
return { result, repo, ...(fetched.handoffSource && { handoffSource: fetched.handoffSource }) };
|
|
86
88
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Review } from "../types/github.mts";
|
|
2
2
|
/**
|
|
3
3
|
* Surface where each changes-requested review was submitted relative to the PR head.
|
|
4
|
-
* `commitOid` stays only when it differs from the head, and then `headOid` carries the head;
|
|
5
|
-
* a review on the head carries neither (lean output). Raw data only — no staleness verdict.
|
|
4
|
+
* `commitOid` stays only when it differs from the head, and then `headOid` carries the head and `commitsSince` the commit count between them when known;
|
|
5
|
+
* a review on the head carries neither. Both OIDs are shortened to 7 characters; (lean output). Raw data only — no staleness verdict.
|
|
6
6
|
*/
|
|
7
7
|
export declare function withHeadOid(reviews: Review[], headOid: string): Review[];
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Surface where each changes-requested review was submitted relative to the PR head.
|
|
3
|
-
* `commitOid` stays only when it differs from the head, and then `headOid` carries the head;
|
|
4
|
-
* a review on the head carries neither (lean output). Raw data only — no staleness verdict.
|
|
3
|
+
* `commitOid` stays only when it differs from the head, and then `headOid` carries the head and `commitsSince` the commit count between them when known;
|
|
4
|
+
* a review on the head carries neither. Both OIDs are shortened to 7 characters; (lean output). Raw data only — no staleness verdict.
|
|
5
5
|
*/
|
|
6
6
|
export function withHeadOid(reviews, headOid) {
|
|
7
7
|
return reviews.map((review) => {
|
|
8
|
-
const { commitOid, ...rest } = review;
|
|
9
|
-
return commitOid && commitOid !== headOid
|
|
8
|
+
const { commitOid, commitsSince, ...rest } = review;
|
|
9
|
+
return commitOid && commitOid !== headOid
|
|
10
|
+
? {
|
|
11
|
+
...rest,
|
|
12
|
+
commitOid: commitOid.slice(0, 7),
|
|
13
|
+
headOid: headOid.slice(0, 7),
|
|
14
|
+
...(commitsSince !== undefined && { commitsSince }),
|
|
15
|
+
}
|
|
16
|
+
: rest;
|
|
10
17
|
});
|
|
11
18
|
}
|
|
@@ -3,6 +3,7 @@ import { buildMergeCommandPlan, renderMergeCommand } from "./iterate/merge.mjs";
|
|
|
3
3
|
import { appendAutonomousInstructions, idleWaitPlan, appendHumanHandoffInstructions, findHumanHandoffs, hasListedOwnership, } from "./stack-drain.mjs";
|
|
4
4
|
import { isStackLayerReady, aboveThroughTarget, closedInScope, mergeScopeLayers, openLayers, readyPrefix, stackPosition, } from "./stack-merge-scope.mjs";
|
|
5
5
|
import { stackMergeFlag } from "./stack-merge-flag.mjs";
|
|
6
|
+
import { MERGE_CONFLICT_NOTE, trunkPreCheck } from "./stack-merge-trunk-check.mjs";
|
|
6
7
|
import { addedLayersEscalation, escalation, list, scopeDone, unlistedEscalation, } from "./stack-merge-escalations.mjs";
|
|
7
8
|
import { splitStackWork, stackRerunTarget } from "./stack-work.mjs";
|
|
8
9
|
const NO_PER_LAYER = "One command lands every listed layer. Do not merge the layers one at a time with `gh pr merge`, and do not rebase or push between layers; GitHub retargets the remaining layers itself.";
|
|
@@ -77,7 +78,8 @@ function mergePlan(result, top, scope, rerunCommand) {
|
|
|
77
78
|
const waiting = idleWaitPlan(lands);
|
|
78
79
|
return { ...waiting, instructions: [`1. ${first.unavailable}`] };
|
|
79
80
|
}
|
|
80
|
-
const
|
|
81
|
+
const check = trunkPreCheck(result, top);
|
|
82
|
+
const instructions = check ? [`1. ${check}`, `2. ${first.text}`] : [`1. ${first.text}`];
|
|
81
83
|
appendAutonomousInstructions(instructions, work.sessions, hasListedOwnership(result));
|
|
82
84
|
const handoffs = findHumanHandoffs(result);
|
|
83
85
|
if (handoffs)
|
|
@@ -120,13 +122,13 @@ function mergeStep(result, top, landing, left) {
|
|
|
120
122
|
if ("unavailable" in plan)
|
|
121
123
|
return { unavailable: plan.unavailable, ...(plan.refresh && { refresh: true }) };
|
|
122
124
|
return {
|
|
123
|
-
text: `
|
|
125
|
+
text: `Run \`${renderMergeCommand(plan.command)}\` to request merging ${landing} of native stack #${stack.number}.${left} ${NO_PER_LAYER} If status is \`pending\`, rerun that command at the configured cadence to resume its UUID. \`enqueued\` is not merged. Shepherd revalidates every open lower layer's READY receipt before submission.`,
|
|
124
126
|
};
|
|
125
127
|
}
|
|
126
128
|
const method = stackMergeFlag(result.allowedMergeMethods);
|
|
127
129
|
if ("unavailable" in method)
|
|
128
130
|
return { unavailable: method.unavailable };
|
|
129
131
|
return {
|
|
130
|
-
text: `
|
|
132
|
+
text: `Run \`GH_REPO=${result.repo} gh stack merge ${top.pr} --yes ${method.flag}\` in \`${result.repo}\` to merge ${landing} of stack #${stack.number}.${left} ${NO_PER_LAYER} If \`gh stack\` is an unknown command, run \`gh extension install github/gh-stack\`, then rerun that merge command. ${MERGE_CONFLICT_NOTE}`,
|
|
131
133
|
};
|
|
132
134
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PollSummaryItem, PollSummaryResult } from "../types.mts";
|
|
2
|
+
/**
|
|
3
|
+
* The read-only trunk check printed before a stack merge whose top layer is not the bottom one.
|
|
4
|
+
* GitHub's per-layer `mergeable` compares an upper layer only with its parent, so trunk commits
|
|
5
|
+
* that conflict with the top head are invisible until the atomic merge fails. The CLI cannot
|
|
6
|
+
* fetch, so the caller runs `git merge-tree`, which writes nothing to the work tree or refs.
|
|
7
|
+
* Present only when Shepherd saw trunk ahead of the head (`trunkBehindBy`) or could not compare
|
|
8
|
+
* (`trunkBehindUnknown`); otherwise the merge step stays as it was.
|
|
9
|
+
*/
|
|
10
|
+
export declare function trunkPreCheck(result: PollSummaryResult, top: PollSummaryItem): string | undefined;
|
|
11
|
+
/** Appended to the `gh stack merge` step: that merge is atomic, so a conflict merges nothing. */
|
|
12
|
+
export declare const MERGE_CONFLICT_NOTE = "If `gh stack merge` reports `Merge conflict detected`, nothing was merged. Do not rerun the merge; update the stack from its bottom layer onto trunk with `gh stack rebase`, then `gh stack push`, following the Branch update playbook, and rerun the stack command.";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { buildNativeStackRebaseInstruction } from "./iterate/native-stack-rebase.mjs";
|
|
2
|
+
import { openLayers } from "./stack-merge-scope.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* The read-only trunk check printed before a stack merge whose top layer is not the bottom one.
|
|
5
|
+
* GitHub's per-layer `mergeable` compares an upper layer only with its parent, so trunk commits
|
|
6
|
+
* that conflict with the top head are invisible until the atomic merge fails. The CLI cannot
|
|
7
|
+
* fetch, so the caller runs `git merge-tree`, which writes nothing to the work tree or refs.
|
|
8
|
+
* Present only when Shepherd saw trunk ahead of the head (`trunkBehindBy`) or could not compare
|
|
9
|
+
* (`trunkBehindUnknown`); otherwise the merge step stays as it was.
|
|
10
|
+
*/
|
|
11
|
+
export function trunkPreCheck(result, top) {
|
|
12
|
+
if (!top.trunkBehindBy && !top.trunkBehindUnknown)
|
|
13
|
+
return undefined;
|
|
14
|
+
const stack = top.stack;
|
|
15
|
+
const trunk = stack.baseRefName;
|
|
16
|
+
const bottom = openLayers(result)[0] ?? top;
|
|
17
|
+
const why = top.trunkBehindBy
|
|
18
|
+
? `Trunk \`${trunk}\` has ${top.trunkBehindBy} commit${top.trunkBehindBy === 1 ? "" : "s"} that PR #${top.pr} lacks`
|
|
19
|
+
: `Shepherd could not compare trunk \`${trunk}\` with PR #${top.pr}`;
|
|
20
|
+
const rebase = buildNativeStackRebaseInstruction(result.repo, stack.number, {
|
|
21
|
+
bottomPr: bottom.pr,
|
|
22
|
+
});
|
|
23
|
+
return `Before merging, check the top layer against trunk, because GitHub's \`mergeable\` compares an upper layer only with its parent layer. ${why}. From a checkout of \`${result.repo}\`, run \`git fetch <remote> ${trunk}\` (\`<remote>\` is the remote that points at \`${result.repo}\`), then \`git merge-tree --write-tree FETCH_HEAD ${top.headRefOid}\`. This writes no files and no refs. If it exits 0, continue with the next step. If it exits 1, it lists the conflicts: do not merge, and do not merge layer by layer. Update the whole stack from its bottom layer onto \`${trunk}\`, then push it. ${rebase} Then rerun the stack command.`;
|
|
24
|
+
}
|
|
25
|
+
/** Appended to the `gh stack merge` step: that merge is atomic, so a conflict merges nothing. */
|
|
26
|
+
export const MERGE_CONFLICT_NOTE = "If `gh stack merge` reports `Merge conflict detected`, nothing was merged. Do not rerun the merge; update the stack from its bottom layer onto trunk with `gh stack rebase`, then `gh stack push`, following the Branch update playbook, and rerun the stack command.";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PollSummaryResult, StackMergeScope } from "../types.mts";
|
|
2
|
+
/**
|
|
3
|
+
* GitHub compares an upper layer's `mergeable` only with its parent layer, so a conflict with
|
|
4
|
+
* trunk stays invisible until `gh stack merge` fails. Compare trunk with the top landing layer's
|
|
5
|
+
* head once and record the result on that row: `trunkBehindBy` when trunk has commits the head
|
|
6
|
+
* lacks, `trunkBehindUnknown` when the compare failed. A failure never blocks the merge; the
|
|
7
|
+
* printed pre-check still runs, because a missed conflict costs a failed atomic merge.
|
|
8
|
+
*/
|
|
9
|
+
export declare function withTrunkBehind(result: PollSummaryResult, scope: StackMergeScope | undefined): Promise<PollSummaryResult>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { loadBaseBehindBy } from "../github/merge-target-rules.mjs";
|
|
2
|
+
import { pollRateLimitRetryAfterMs } from "./poll-quota.mjs";
|
|
3
|
+
import { mergeScopeLayers, openLayers, readyPrefix } from "./stack-merge-scope.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* The layer a stack merge would target, or undefined when none is ready to land. Mirrors the
|
|
6
|
+
* choice `planStackMerge` makes: the highest ready owned layer for `ready`, otherwise the scope
|
|
7
|
+
* target once it sits inside the ready prefix.
|
|
8
|
+
*/
|
|
9
|
+
function stackMergeTop(result, scope) {
|
|
10
|
+
if (openLayers(result).length === 0)
|
|
11
|
+
return undefined;
|
|
12
|
+
if (scope.kind === "ready")
|
|
13
|
+
return readyPrefix(result, true).at(-1);
|
|
14
|
+
const { target } = mergeScopeLayers(result, scope);
|
|
15
|
+
return target && readyPrefix(result, false).some((item) => item.pr === target.pr)
|
|
16
|
+
? target
|
|
17
|
+
: undefined;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* GitHub compares an upper layer's `mergeable` only with its parent layer, so a conflict with
|
|
21
|
+
* trunk stays invisible until `gh stack merge` fails. Compare trunk with the top landing layer's
|
|
22
|
+
* head once and record the result on that row: `trunkBehindBy` when trunk has commits the head
|
|
23
|
+
* lacks, `trunkBehindUnknown` when the compare failed. A failure never blocks the merge; the
|
|
24
|
+
* printed pre-check still runs, because a missed conflict costs a failed atomic merge.
|
|
25
|
+
*/
|
|
26
|
+
export async function withTrunkBehind(result, scope) {
|
|
27
|
+
if (!scope || result.selection.kind !== "stack")
|
|
28
|
+
return result;
|
|
29
|
+
const top = stackMergeTop(result, scope);
|
|
30
|
+
const trunk = top?.stack?.baseRefName;
|
|
31
|
+
if (!top || !trunk || top.baseRefName === trunk)
|
|
32
|
+
return result;
|
|
33
|
+
const [owner, name] = result.repo.split("/");
|
|
34
|
+
let mark;
|
|
35
|
+
try {
|
|
36
|
+
const behind = await loadBaseBehindBy(owner, name, trunk, top.headRefOid);
|
|
37
|
+
if (behind <= 0)
|
|
38
|
+
return result;
|
|
39
|
+
mark = { trunkBehindBy: behind };
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
if (pollRateLimitRetryAfterMs(err) !== null)
|
|
43
|
+
throw err;
|
|
44
|
+
process.stderr.write(`pr-shepherd: trunk compare unavailable for PR #${top.pr} (ignored): ${err instanceof Error ? err.message : String(err)}\n`);
|
|
45
|
+
mark = { trunkBehindUnknown: true };
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
...result,
|
|
49
|
+
prs: result.prs.map((item) => (item.pr === top.pr ? { ...item, ...mark } : item)),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -14,6 +14,8 @@ export declare function chooseMergeMethod(input: {
|
|
|
14
14
|
allowed: readonly MergeMethod[] | undefined;
|
|
15
15
|
configured: MergeMethod | null;
|
|
16
16
|
fallback: MergeMethod;
|
|
17
|
+
/** Branch policy requires linear history: a merge commit can never satisfy it. */
|
|
18
|
+
linearHistory?: boolean;
|
|
17
19
|
}): {
|
|
18
20
|
method: MergeMethod;
|
|
19
21
|
} | {
|
|
@@ -22,6 +22,23 @@ export function configuredMergeMethod(merge) {
|
|
|
22
22
|
return merge.method ?? fromArgs ?? null;
|
|
23
23
|
}
|
|
24
24
|
export function chooseMergeMethod(input) {
|
|
25
|
+
if (input.linearHistory) {
|
|
26
|
+
const linear = (input.allowed ?? METHOD_ORDER).filter((method) => method !== "merge");
|
|
27
|
+
if (input.allowed !== undefined && linear.length === 0)
|
|
28
|
+
return {
|
|
29
|
+
unavailable: "Required linear history excludes merge commits, and this repository allows no squash or rebase merge.",
|
|
30
|
+
};
|
|
31
|
+
if (input.configured === "merge")
|
|
32
|
+
return {
|
|
33
|
+
unavailable: "Configured merge method `merge` conflicts with the required linear history; use `squash` or `rebase`.",
|
|
34
|
+
};
|
|
35
|
+
if (input.allowed === undefined) {
|
|
36
|
+
return {
|
|
37
|
+
method: input.configured ?? (input.fallback === "merge" ? "squash" : input.fallback),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return chooseMergeMethod({ ...input, allowed: linear, linearHistory: false });
|
|
41
|
+
}
|
|
25
42
|
if (input.allowed === undefined)
|
|
26
43
|
return { method: input.configured ?? input.fallback };
|
|
27
44
|
if (input.configured) {
|
|
@@ -22,6 +22,12 @@ function parseReviewNode(r) {
|
|
|
22
22
|
}
|
|
23
23
|
return base;
|
|
24
24
|
}
|
|
25
|
+
function commitsSince(oid, commits) {
|
|
26
|
+
if (!oid || !commits)
|
|
27
|
+
return undefined;
|
|
28
|
+
const index = commits.nodes.findIndex((node) => node.commit.oid === oid);
|
|
29
|
+
return index < 0 ? undefined : commits.nodes.length - 1 - index;
|
|
30
|
+
}
|
|
25
31
|
export function parseRawPr(raw, rawThreadPages, rawCommentNodes, rawReviewNodes, rawReviewSummaryNodes, rawApprovedReviewNodes, rawCheckNodes, repository) {
|
|
26
32
|
const reviewRequests = (raw.reviewRequests?.nodes ?? []).flatMap((n) => {
|
|
27
33
|
const login = n.requestedReviewer?.login ?? n.requestedReviewer?.name;
|
|
@@ -82,6 +88,9 @@ export function parseRawPr(raw, rawThreadPages, rawCommentNodes, rawReviewNodes,
|
|
|
82
88
|
}));
|
|
83
89
|
const allChangesRequestedReviews = rawReviewNodes.map((r) => {
|
|
84
90
|
const review = parseReviewNode(r);
|
|
91
|
+
const since = commitsSince(review.commitOid, raw.prCommitOids);
|
|
92
|
+
if (since !== undefined)
|
|
93
|
+
review.commitsSince = since;
|
|
85
94
|
if (isReviewStale(review, raw.headRefOid, reviewThreads)) {
|
|
86
95
|
review.staleReview = true;
|
|
87
96
|
}
|
|
@@ -96,6 +96,14 @@ export interface RawPr extends RawPrMergeFields {
|
|
|
96
96
|
};
|
|
97
97
|
nodes: RawReviewSummary[];
|
|
98
98
|
};
|
|
99
|
+
/** Last 100 commit OIDs, oldest first. GraphQL only. */
|
|
100
|
+
prCommitOids?: {
|
|
101
|
+
nodes: Array<{
|
|
102
|
+
commit: {
|
|
103
|
+
oid: string;
|
|
104
|
+
};
|
|
105
|
+
}>;
|
|
106
|
+
};
|
|
99
107
|
commits: {
|
|
100
108
|
totalCount?: number;
|
|
101
109
|
nodes: Array<{
|
|
@@ -307,6 +307,14 @@ query BatchPr($owner: String!, $repo: String!, $pr: Int!) {
|
|
|
307
307
|
url
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
|
+
# Chronological OIDs only: positions a changes-requested review's commit relative to the head.
|
|
311
|
+
prCommitOids: commits(last: 100) {
|
|
312
|
+
nodes {
|
|
313
|
+
commit {
|
|
314
|
+
oid
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
310
318
|
commits(last: 1) {
|
|
311
319
|
totalCount
|
|
312
320
|
nodes {
|
|
@@ -26,7 +26,8 @@ export function isCurrentSummaryReady(raw, checks, review, options = {}) {
|
|
|
26
26
|
// alone is not that proof.
|
|
27
27
|
const requiresConversationResolution = parseBranchRules(raw.baseRef).requiresConversationResolution;
|
|
28
28
|
return (isKnownMergeStateStatus(raw.mergeStateStatus) &&
|
|
29
|
-
transportReadinessGaps(raw, raw.mergeStateStatus).length ===
|
|
29
|
+
transportReadinessGaps(raw, raw.mergeStateStatus, requiresConversationResolution).length ===
|
|
30
|
+
0 &&
|
|
30
31
|
checks.incomplete !== true &&
|
|
31
32
|
sourceChecks.incomplete !== true &&
|
|
32
33
|
(review.incomplete !== true ||
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { loadConfig } from "../config/load.mjs";
|
|
2
2
|
import { hasNoRelevantChecks } from "./poll-summary-unreported.mjs";
|
|
3
3
|
import { isKnownMergeStateStatus, transportReadinessGaps } from "./transport-evidence.mjs";
|
|
4
|
+
import { parseBranchRules } from "./batch-parsers-rules.mjs";
|
|
4
5
|
import { canGenerateGithubMutation } from "./mutation-policy.mjs";
|
|
5
6
|
import { getGithubTransport, isCcrTransport } from "./transport.mjs";
|
|
6
7
|
export function routePollSummary(raw, checks, review, opts) {
|
|
@@ -31,7 +32,7 @@ export function routePollSummary(raw, checks, review, opts) {
|
|
|
31
32
|
raw.mergeable === "UNKNOWN" ||
|
|
32
33
|
raw.mergeStateStatus === "UNKNOWN")
|
|
33
34
|
return { action: "wait", reasons: ["pending-or-unknown"] };
|
|
34
|
-
if (transportReadinessGaps(raw, raw.mergeStateStatus).length > 0)
|
|
35
|
+
if (transportReadinessGaps(raw, raw.mergeStateStatus, parseBranchRules(raw.baseRef).requiresConversationResolution).length > 0)
|
|
35
36
|
return { action: "escalate", reasons: ["transport-unsupported"] };
|
|
36
37
|
if (raw.mergeable === "UNKNOWN" ||
|
|
37
38
|
raw.mergeStateStatus === "UNKNOWN" ||
|
|
@@ -27,3 +27,13 @@ export declare function requestRestMerge(repo: RepoInfo, pr: number, options: Re
|
|
|
27
27
|
export declare function getRestMerge(repo: RepoInfo, pr: number, uuid: string): Promise<RestMergeResponse>;
|
|
28
28
|
/** Conflict requests must match the caller's guarded options before their UUID can be adopted. */
|
|
29
29
|
export declare function matchesRestMergeRequest(result: RestMergeResponse, options: RestMergeOptions): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Synchronous `PUT /pulls/{n}/merge`, guarded by the head SHA. It is the fallback when the
|
|
32
|
+
* asynchronous request's status cannot be read (403 for tokens without access, or an expired
|
|
33
|
+
* UUID): GitHub refuses it with 405/409 unless the guarded head is mergeable, so repeating it
|
|
34
|
+
* after an unknown outcome cannot merge anything the caller did not guard.
|
|
35
|
+
*/
|
|
36
|
+
export declare function requestRestSyncMerge(repo: RepoInfo, pr: number, options: {
|
|
37
|
+
requireSha: string;
|
|
38
|
+
mergeMethod: MergeMethod;
|
|
39
|
+
}): Promise<RestMergeResponse>;
|
|
@@ -54,3 +54,29 @@ export function matchesRestMergeRequest(result, options) {
|
|
|
54
54
|
typeof details.uuid === "string" &&
|
|
55
55
|
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(details.uuid));
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Synchronous `PUT /pulls/{n}/merge`, guarded by the head SHA. It is the fallback when the
|
|
59
|
+
* asynchronous request's status cannot be read (403 for tokens without access, or an expired
|
|
60
|
+
* UUID): GitHub refuses it with 405/409 unless the guarded head is mergeable, so repeating it
|
|
61
|
+
* after an unknown outcome cannot merge anything the caller did not guard.
|
|
62
|
+
*/
|
|
63
|
+
export async function requestRestSyncMerge(repo, pr, options) {
|
|
64
|
+
const { data } = await restWithRateLimit("PUT", `${restRepoPath(repo)}/pulls/${pr}/merge`, {
|
|
65
|
+
sha: options.requireSha,
|
|
66
|
+
merge_method: options.mergeMethod,
|
|
67
|
+
});
|
|
68
|
+
const body = (data ?? {});
|
|
69
|
+
const message = typeof body.message === "string" ? body.message : undefined;
|
|
70
|
+
if (body.merged !== true)
|
|
71
|
+
return {
|
|
72
|
+
status: "failed",
|
|
73
|
+
details: { message: message ?? "GitHub did not merge the pull request." },
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
status: "merged",
|
|
77
|
+
details: {
|
|
78
|
+
message: message ?? "Pull request merged.",
|
|
79
|
+
...(typeof body.sha === "string" && { sha: body.sha }),
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -7,13 +7,20 @@ interface TransportEvidence {
|
|
|
7
7
|
}
|
|
8
8
|
/** A future GitHub state cannot prove readiness through a negative blocker list. */
|
|
9
9
|
export declare function isKnownMergeStateStatus(status: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* REST has no resolved/outdated thread state. When branch policy requires conversation resolution,
|
|
12
|
+
* GitHub's CLEAN merge state proves no unresolved thread exists, so the unknown status is not a
|
|
13
|
+
* readiness gap. Without that policy, or on any other merge state, the gap stands.
|
|
14
|
+
*/
|
|
15
|
+
export declare function conversationResolutionProven(mergeStateStatus: string, requiresConversationResolution: boolean | undefined): boolean;
|
|
10
16
|
/**
|
|
11
17
|
* Missing feedback cannot certify readiness, even when GitHub reports CLEAN. Missing branch policy
|
|
12
18
|
* blocks only a non-CLEAN state, whose unmet requirements Shepherd derives from that policy. The
|
|
13
19
|
* aggregate `reviewDecision` is never a readiness input on either transport (approvals come from
|
|
14
|
-
* branch policy plus latest reviews), so its absence alone is not a gap.
|
|
20
|
+
* branch policy plus latest reviews), so its absence alone is not a gap. Unknown thread status
|
|
21
|
+
* (`reviewThreads.status`) is cleared by `conversationResolutionProven`.
|
|
15
22
|
*/
|
|
16
|
-
export declare function transportReadinessGaps(value: TransportEvidence, mergeStateStatus: string): Array<{
|
|
23
|
+
export declare function transportReadinessGaps(value: TransportEvidence, mergeStateStatus: string, requiresConversationResolution?: boolean): Array<{
|
|
17
24
|
field: string;
|
|
18
25
|
reason: string;
|
|
19
26
|
}>;
|
|
@@ -11,16 +11,28 @@ export function isKnownMergeStateStatus(status) {
|
|
|
11
11
|
"UNSTABLE",
|
|
12
12
|
].includes(status);
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* REST has no resolved/outdated thread state. When branch policy requires conversation resolution,
|
|
16
|
+
* GitHub's CLEAN merge state proves no unresolved thread exists, so the unknown status is not a
|
|
17
|
+
* readiness gap. Without that policy, or on any other merge state, the gap stands.
|
|
18
|
+
*/
|
|
19
|
+
export function conversationResolutionProven(mergeStateStatus, requiresConversationResolution) {
|
|
20
|
+
return mergeStateStatus === "CLEAN" && requiresConversationResolution === true;
|
|
21
|
+
}
|
|
14
22
|
/**
|
|
15
23
|
* Missing feedback cannot certify readiness, even when GitHub reports CLEAN. Missing branch policy
|
|
16
24
|
* blocks only a non-CLEAN state, whose unmet requirements Shepherd derives from that policy. The
|
|
17
25
|
* aggregate `reviewDecision` is never a readiness input on either transport (approvals come from
|
|
18
|
-
* branch policy plus latest reviews), so its absence alone is not a gap.
|
|
26
|
+
* branch policy plus latest reviews), so its absence alone is not a gap. Unknown thread status
|
|
27
|
+
* (`reviewThreads.status`) is cleared by `conversationResolutionProven`.
|
|
19
28
|
*/
|
|
20
|
-
export function transportReadinessGaps(value, mergeStateStatus) {
|
|
29
|
+
export function transportReadinessGaps(value, mergeStateStatus, requiresConversationResolution) {
|
|
21
30
|
if (value.transport !== "rest")
|
|
22
31
|
return [];
|
|
23
|
-
|
|
32
|
+
const threadStatusProven = conversationResolutionProven(mergeStateStatus, requiresConversationResolution);
|
|
33
|
+
return (value.transportUnavailable ?? []).filter(({ field }) => (field === "reviewThreads.status" && !threadStatusProven) ||
|
|
34
|
+
(field !== "reviewThreads.status" &&
|
|
35
|
+
/^(reviewThreads|reviewTranscripts|changesRequestedReviews|reviewSummaries|checks|checkRuns|checkSuites|checkAnnotations|annotations|nativeStack)(?:\.|$)/.test(field)) ||
|
|
24
36
|
(mergeStateStatus !== "CLEAN" &&
|
|
25
37
|
["branchProtection", "branchRules", "mergeRequirements"].some((policy) => field === policy || field.startsWith(`${policy}.`))));
|
|
26
38
|
}
|
|
@@ -19,6 +19,12 @@ export declare function readMergeRequest(key: Key): Promise<MergeRequestRecord |
|
|
|
19
19
|
export declare function claimMergeRequest(key: Key, record: MergeRequestRecord): Promise<boolean>;
|
|
20
20
|
/** Consume one durable successor of a failed request or an enqueue guarded by an older head. */
|
|
21
21
|
export declare function replaceFailedMergeRequest(key: Key, previous: MergeRequestRecord, next: MergeRequestRecord): Promise<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
* Retire a request whose asynchronous status can no longer be read, once the synchronous fallback
|
|
24
|
+
* has answered. A merged PR is detected from the pull itself, so no record is needed; a refusal is
|
|
25
|
+
* surfaced to the caller, and a rerun starts a fresh guarded attempt instead of replaying it.
|
|
26
|
+
*/
|
|
27
|
+
export declare function clearMergeRequest(key: Key): Promise<void>;
|
|
22
28
|
export declare function writeMergeRequest(key: Key, record: MergeRequestRecord): Promise<void>;
|
|
23
29
|
/** A delayed status poll can update only its own intent, never a later main request. */
|
|
24
30
|
export declare function writeMergeRequestStatus(key: Key, record: MergeRequestRecord): Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
-
import { link, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
2
|
+
import { link, mkdir, readFile, rename, rm, unlink, writeFile } from "node:fs/promises";
|
|
3
3
|
import { dirname } from "node:path";
|
|
4
4
|
import { resolvePrStatePath } from "./base.mjs";
|
|
5
5
|
import { restMergeStackGuardKey, validateRestMergeStackGuard, } from "../github/rest-merge-stack-guard.mjs";
|
|
@@ -126,6 +126,14 @@ export async function replaceFailedMergeRequest(key, previous, next) {
|
|
|
126
126
|
await unlink(source).catch(() => { });
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Retire a request whose asynchronous status can no longer be read, once the synchronous fallback
|
|
131
|
+
* has answered. A merged PR is detected from the pull itself, so no record is needed; a refusal is
|
|
132
|
+
* surfaced to the caller, and a rerun starts a fresh guarded attempt instead of replaying it.
|
|
133
|
+
*/
|
|
134
|
+
export async function clearMergeRequest(key) {
|
|
135
|
+
await rm(path(key), { force: true });
|
|
136
|
+
}
|
|
129
137
|
export async function writeMergeRequest(key, record) {
|
|
130
138
|
await writeRecord(path(key), record);
|
|
131
139
|
}
|
package/bin/types/github.d.mts
CHANGED
|
@@ -160,6 +160,8 @@ export interface Review {
|
|
|
160
160
|
commitOid?: string;
|
|
161
161
|
/** PR head OID, set on changes-requested reviews only when `commitOid` differs from it. Raw data, not a staleness verdict. */
|
|
162
162
|
headOid?: string;
|
|
163
|
+
/** Commits pushed after `commitOid` up to the head. Set with `headOid`, GraphQL only, and only when `commitOid` is among the PR's last 100 commits. */
|
|
164
|
+
commitsSince?: number;
|
|
163
165
|
/** Review HTML URL, when the batch query selected it. */
|
|
164
166
|
url?: string;
|
|
165
167
|
/** True when commitOid !== headRefOid AND all associated threads are resolved/outdated. Distinct from `staleBotCr` (time-based). Reviews with no threads are not marked stale. */
|
|
@@ -8,5 +8,11 @@ export interface MergeCommandPlan {
|
|
|
8
8
|
fallbackCommand?: ShellCommand;
|
|
9
9
|
/** Direct enqueuePullRequest fallback for the known gh CLI queue limitation. */
|
|
10
10
|
queueApiFallbackCommand?: ShellCommand;
|
|
11
|
+
/**
|
|
12
|
+
* GraphQL-mode commands (`gh pr merge`, `gh api graphql`) all spend GraphQL quota. This REST
|
|
13
|
+
* equivalent is for when that quota is exhausted: `gh api` PUT for an ordinary merge, or
|
|
14
|
+
* `apply merge --transport rest` for a queue.
|
|
15
|
+
*/
|
|
16
|
+
restFallbackCommand?: ShellCommand;
|
|
11
17
|
}
|
|
12
18
|
export {};
|
|
@@ -104,6 +104,10 @@ export interface PollSummaryItem {
|
|
|
104
104
|
pollProbe?: true;
|
|
105
105
|
/** A current one-PR READY-after-delay completion was verified. */
|
|
106
106
|
readyReceipt?: true;
|
|
107
|
+
/** Stack merge top only: commits on the stack trunk that this head lacks (omitted when 0). */
|
|
108
|
+
trunkBehindBy?: number;
|
|
109
|
+
/** Stack merge top only: the trunk compare failed, so the conflict check is unverified. */
|
|
110
|
+
trunkBehindUnknown?: true;
|
|
107
111
|
}
|
|
108
112
|
export type PollSummarySelection = {
|
|
109
113
|
kind: "prs";
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@ allowed-tools: Bash(npx pr-shepherd:*), Bash(pnpm exec pr-shepherd:*), Bash(pnpm
|
|
|
13
13
|
- To make, create, or open a PR, read the "Create a PR" playbook, then pass its URL on.
|
|
14
14
|
- External shepherd: read the "Draft handoff" playbook, not an in-session loop.
|
|
15
15
|
- `$ARGUMENTS`: PR numbers, PR URLs, or `'owner/repo#N'` (quoted), or `stack PR...` / `stack owner/repo#N` (the number owns all layers), plus one optional merge flag: `--merge`, `--merge-ready`, `--merge-through PR`; reject anything else. Use `stack` only when asked or routed. With no PR, pass none. A qualified PR picks the GitHub target; this checkout supplies git and config.
|
|
16
|
-
- Stack merge: "the stack" -> `stack owner/repo#N --merge
|
|
16
|
+
- Stack merge: "the stack" -> `stack owner/repo#N --merge` (given only a PR, `stack PR --merge`, then on `unowned-stack-layers` run its printed stack-number command); "as they're ready"/"drain" -> `--merge-ready`; "#N" -> one-PR `--merge`, but if they claim other layers or say "up to #N" -> `stack <claimed PRs incl. N> --merge-through N`; "ship it" -> ask.
|
|
17
17
|
- Follow printed branch-update steps without asking: rebase or merge the base, resolve conflicts, push your own PR head with `--force-with-lease`.
|
|
18
18
|
- A merge flag, or a request to merge, land, enqueue, or requeue after an ejection, allows the printed merge/enqueue/dequeue commands. Run Shepherd first: never merge, enqueue or retarget with `gh` or a GitHub MCP tool before Shepherd prints that step. Run them without asking again; escalate only when the host requires it.
|
|
19
19
|
- Run `pr-shepherd [PR ...]` or `pr-shepherd stack PR...`, plus any merge flag, with `--until-terminal` in the background only if its exit wakes you, else in the foreground ([Waiting](references/waiting.md)). Requeue commands print only under `--merge`. PRs with the same flags share one command; if the set changes, stop and rerun with the new list. Do not run `pr-shepherd iterate`, except once for a one-time status question.
|
|
@@ -11,4 +11,4 @@ Then:
|
|
|
11
11
|
|
|
12
12
|
1. Cause within this PR: fix it and push.
|
|
13
13
|
2. Transient and the output printed a rerun command for it: run that command. Without one, do not rerun; the allowance is spent or the check is not rerunnable.
|
|
14
|
-
3. Otherwise
|
|
14
|
+
3. Otherwise investigate first, including the check's details URL. If you are still unsure of the cause, or it is outside this PR (CI configuration, repository settings, approving a gated run), change nothing, rerun Shepherd so it escalates `check-follow-up-unavailable` if the checks are unchanged, and report your findings.
|
|
@@ -12,4 +12,4 @@ Then act on what you found:
|
|
|
12
12
|
|
|
13
13
|
1. If the cause is within this PR (a `runs-on` label that matches no runner, a workflow change that breaks scheduling, a wrong base), fix it and push.
|
|
14
14
|
2. If a run is only waiting on an approval you can legitimately grant, grant it. An approval that needs a human reviewer is not yours to grant.
|
|
15
|
-
3. Otherwise make no change and keep what you found. Runner capacity, billing, repository settings, and GitHub incidents are human decisions. If the same checks are still not started on the next poll, Shepherd escalates with `stall-timeout`; report your diagnosis then.
|
|
15
|
+
3. Otherwise investigate first. If you are still unsure of the cause, or it is outside this PR, make no change and keep what you found. Runner capacity, billing, repository settings, and GitHub incidents are human decisions. If the same checks are still not started on the next poll, Shepherd escalates with `stall-timeout`; report your diagnosis then.
|
|
@@ -13,4 +13,4 @@ Then act on what you found:
|
|
|
13
13
|
|
|
14
14
|
1. If the cause is within this PR (wrong base or stack parent, a changed file that breaks the workflow, configuration the PR should carry), fix it and push.
|
|
15
15
|
2. If the workflows should have run and the PR is fine, run the printed close and reopen commands once for this head. Do not close it again.
|
|
16
|
-
3. Otherwise make no change and keep what you found. Changing CI configuration, repository settings, or branch rules is a human decision. If the checks are still missing on the next poll, Shepherd escalates with `required-checks-unreported`; report your diagnosis then.
|
|
16
|
+
3. Otherwise investigate first. If you are still unsure of the cause, or it is outside this PR, make no change and keep what you found. Changing CI configuration, repository settings, or branch rules is a human decision. If the checks are still missing on the next poll, Shepherd escalates with `required-checks-unreported`; report your diagnosis then.
|