pr-shepherd 2.2.18 → 2.3.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/.claude-plugin/plugin.json +1 -1
- package/README.md +1 -0
- package/bin/cli/triage-formatter.mjs +2 -0
- package/bin/cli/workflow-elsewhere-format.d.mts +3 -0
- package/bin/cli/workflow-elsewhere-format.mjs +112 -0
- package/bin/commands/iterate/queue-recovery-instructions.d.mts +1 -1
- package/bin/commands/iterate/queue-recovery-instructions.mjs +7 -4
- package/bin/commands/iterate/render.mjs +2 -1
- package/bin/commands/iterate/triage.mjs +24 -7
- package/bin/commands/iterate/workflow-elsewhere.d.mts +19 -0
- package/bin/commands/iterate/workflow-elsewhere.mjs +144 -0
- package/bin/config/schema.d.mts +6 -0
- package/bin/config/schema.mjs +3 -0
- package/bin/github/gql/default-branch-workflow-runs.gql +71 -0
- package/bin/github/queries.d.mts +2 -0
- package/bin/github/queries.mjs +2 -0
- package/bin/github/workflow-elsewhere-parse.d.mts +19 -0
- package/bin/github/workflow-elsewhere-parse.mjs +172 -0
- package/bin/github/workflow-elsewhere-queue.d.mts +28 -0
- package/bin/github/workflow-elsewhere-queue.mjs +137 -0
- package/bin/github/workflow-elsewhere-read.d.mts +26 -0
- package/bin/github/workflow-elsewhere-read.mjs +120 -0
- package/bin/github/workflow-elsewhere-rest-runs.d.mts +20 -0
- package/bin/github/workflow-elsewhere-rest-runs.mjs +54 -0
- package/bin/github/workflow-elsewhere-rest.d.mts +3 -0
- package/bin/github/workflow-elsewhere-rest.mjs +126 -0
- package/bin/types/report.d.mts +7 -0
- package/bin/types/workflow-elsewhere-raw.d.mts +108 -0
- package/bin/types/workflow-elsewhere-raw.mjs +1 -0
- package/bin/types/workflow-elsewhere.d.mts +55 -0
- package/bin/types/workflow-elsewhere.mjs +1 -0
- package/bin/types.d.mts +1 -0
- package/bin/types.mjs +1 -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/references/merge-queue-ejection.md +1 -1
- package/pr-shepherd.schema.json +13 -0
package/README.md
CHANGED
|
@@ -107,6 +107,7 @@ Requirements:
|
|
|
107
107
|
|
|
108
108
|
- Node.js >= 22.19.0, Bun, or Deno, and `git`
|
|
109
109
|
- A GitHub token or authenticated `gh` CLI with [the required access](docs/authentication.md)
|
|
110
|
+
- A repository where every check is expected to pass. Shepherd treats each failing check as work, required or not; list checks that may fail in [`checks.ignore`](docs/configuration.md#checksignore--default-) ([workflow assumptions](docs/features.md#workflow-assumptions))
|
|
110
111
|
|
|
111
112
|
## Documentation
|
|
112
113
|
|
|
@@ -7,6 +7,7 @@ import { numberInstructions } from "./iterate-instructions.mjs";
|
|
|
7
7
|
import { renderCheckAnnotation } from "./triage-formatter-extra.mjs";
|
|
8
8
|
import { renderRelatedJobLines } from "./related-jobs-format.mjs";
|
|
9
9
|
import { renderPendingDeploymentLines } from "./pending-deployments-format.mjs";
|
|
10
|
+
import { renderWorkflowElsewhereLines } from "./workflow-elsewhere-format.mjs";
|
|
10
11
|
import { renderStalledCheckLines } from "./stalled-check-format.mjs";
|
|
11
12
|
import { renderInProgressRun } from "./in-progress-run-format.mjs";
|
|
12
13
|
import { isFailingAgentCheck } from "../checks/conclusions.mjs";
|
|
@@ -111,6 +112,7 @@ export function formatTriageResult(header, result, opts = {}) {
|
|
|
111
112
|
lines.push(...renderRelatedJobLines(ch.relatedJobs));
|
|
112
113
|
}
|
|
113
114
|
lines.push(...renderPendingDeploymentLines(ch.pendingDeployments));
|
|
115
|
+
lines.push(...renderWorkflowElsewhereLines(ch));
|
|
114
116
|
if (ch.rerunCommand && ch.runId && !seenRerunRunIds.has(ch.runId)) {
|
|
115
117
|
seenRerunRunIds.add(ch.runId);
|
|
116
118
|
lines.push(` rerun: \`${ch.rerunCommand}\``);
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/** Format an ISO UTC timestamp as `HH:MMZ` for compact text output. */
|
|
2
|
+
function formatElsewhereShortTime(iso) {
|
|
3
|
+
if (!iso)
|
|
4
|
+
return "unknown";
|
|
5
|
+
const match = /T(\d{2}:\d{2}):\d{2}/.exec(iso);
|
|
6
|
+
return match?.[1] ? `${match[1]}Z` : iso;
|
|
7
|
+
}
|
|
8
|
+
function sanitizeInline(value) {
|
|
9
|
+
return value.replace(/[`\r\n]+/g, " ").trim();
|
|
10
|
+
}
|
|
11
|
+
function plural(n, singular, pluralForm) {
|
|
12
|
+
return `${n} ${n === 1 ? singular : pluralForm}`;
|
|
13
|
+
}
|
|
14
|
+
function formatAnnotation(ann) {
|
|
15
|
+
const path = sanitizeInline(ann.path);
|
|
16
|
+
const loc = path ? `\`${ann.line !== null ? `${path}:${ann.line}` : path}\`` : "";
|
|
17
|
+
const message = sanitizeInline(ann.message);
|
|
18
|
+
if (loc && message)
|
|
19
|
+
return `${loc} — ${message}`;
|
|
20
|
+
return loc || message;
|
|
21
|
+
}
|
|
22
|
+
function formatMoreAnnotations(count) {
|
|
23
|
+
if (!count || count <= 0)
|
|
24
|
+
return "";
|
|
25
|
+
return `(+${count} more ${count === 1 ? "annotation" : "annotations"})`;
|
|
26
|
+
}
|
|
27
|
+
function renderFailedJob(job, runConclusion, indent) {
|
|
28
|
+
const name = sanitizeInline(job.name);
|
|
29
|
+
const sameJob = job.sameJob ? " ← same job" : "";
|
|
30
|
+
const showConclusion = job.annotations.length === 0 || job.conclusion !== runConclusion;
|
|
31
|
+
const conclusionTag = showConclusion ? ` [conclusion: ${job.conclusion}]` : "";
|
|
32
|
+
const more = formatMoreAnnotations(job.moreAnnotations);
|
|
33
|
+
if (job.annotations.length === 0) {
|
|
34
|
+
return [`${indent}- ${name}${conclusionTag}${sameJob}${more ? ` ${more}` : ""}`];
|
|
35
|
+
}
|
|
36
|
+
if (job.annotations.length === 1) {
|
|
37
|
+
return [
|
|
38
|
+
`${indent}- ${name}${conclusionTag}${sameJob}: ${formatAnnotation(job.annotations[0])}${more ? ` ${more}` : ""}`,
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
const lines = [
|
|
42
|
+
`${indent}- ${name}${conclusionTag}${sameJob}:`,
|
|
43
|
+
...job.annotations.map((ann) => `${indent} - ${formatAnnotation(ann)}`),
|
|
44
|
+
];
|
|
45
|
+
if (more)
|
|
46
|
+
lines.push(`${indent} - ${more}`);
|
|
47
|
+
return lines;
|
|
48
|
+
}
|
|
49
|
+
function formatRunHeader(run) {
|
|
50
|
+
const target = run.source === "default-branch"
|
|
51
|
+
? `\`${sanitizeInline(run.branch ?? "default branch")}\``
|
|
52
|
+
: run.pr !== undefined
|
|
53
|
+
? `merge queue #${run.pr}`
|
|
54
|
+
: "merge queue";
|
|
55
|
+
return `${target} \`${run.headSha}\` run \`${run.runId}\` [conclusion: ${run.conclusion}]`;
|
|
56
|
+
}
|
|
57
|
+
function formatWorkflowLabel(scope) {
|
|
58
|
+
const name = scope?.workflowName ? sanitizeInline(scope.workflowName) : "";
|
|
59
|
+
const path = scope?.workflowPath ? sanitizeInline(scope.workflowPath) : "";
|
|
60
|
+
if (name && path)
|
|
61
|
+
return ` — \`${name}\` (${path})`;
|
|
62
|
+
if (name)
|
|
63
|
+
return ` — \`${name}\``;
|
|
64
|
+
if (path)
|
|
65
|
+
return ` — (${path})`;
|
|
66
|
+
return "";
|
|
67
|
+
}
|
|
68
|
+
function formatCheckedLine(scope, indent) {
|
|
69
|
+
const branch = `\`${sanitizeInline(scope.defaultBranch.branch)}\``;
|
|
70
|
+
const defaultPart = scope.defaultBranch.commitsRead !== undefined
|
|
71
|
+
? `${branch} last ${plural(scope.defaultBranch.commitsRead, "commit", "commits")}`
|
|
72
|
+
: `${branch} newest ${plural(scope.defaultBranch.runsRead ?? 0, "run", "runs")}`;
|
|
73
|
+
const queuePart = `merge queue newest ${plural(scope.mergeQueue.runsRead, "run", "runs")}`;
|
|
74
|
+
return `${indent} checked: ${defaultPart} · ${queuePart}`;
|
|
75
|
+
}
|
|
76
|
+
function formatShowingLine(scope, indent) {
|
|
77
|
+
const branch = `\`${sanitizeInline(scope.defaultBranch.branch)}\``;
|
|
78
|
+
const { defaultBranch: def, mergeQueue: mq } = scope;
|
|
79
|
+
const defMatched = `${def.matched}${def.matchedComplete ? "" : "+"}`;
|
|
80
|
+
const mqMatched = `${mq.matched}${mq.matchedComplete ? "" : "+"}`;
|
|
81
|
+
return `${indent} showing newest ${def.shown} of ${defMatched} on ${branch}, ${mq.shown} of ${mqMatched} in the merge queue`;
|
|
82
|
+
}
|
|
83
|
+
/** Render the `Same workflow elsewhere` sub-lines for a failing merge-group Actions check. */
|
|
84
|
+
export function renderWorkflowElsewhereLines(check, indent = " ") {
|
|
85
|
+
if (check.elsewhereUnread !== undefined) {
|
|
86
|
+
return [
|
|
87
|
+
`${indent}Same workflow elsewhere: not read (${sanitizeInline(check.elsewhereUnread)})`,
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
if (check.elsewhere === undefined)
|
|
91
|
+
return [];
|
|
92
|
+
const scope = check.elsewhereScope;
|
|
93
|
+
const since = formatElsewhereShortTime(scope?.since);
|
|
94
|
+
const wfLabel = formatWorkflowLabel(scope);
|
|
95
|
+
if (check.elsewhere.length === 0) {
|
|
96
|
+
const lines = [`${indent}Same workflow elsewhere${wfLabel}, since ${since}: none found`];
|
|
97
|
+
if (scope)
|
|
98
|
+
lines.push(formatCheckedLine(scope, indent));
|
|
99
|
+
return lines;
|
|
100
|
+
}
|
|
101
|
+
const lines = [`${indent}Same workflow elsewhere${wfLabel}, since ${since}:`];
|
|
102
|
+
if (scope) {
|
|
103
|
+
lines.push(formatCheckedLine(scope, indent), formatShowingLine(scope, indent));
|
|
104
|
+
}
|
|
105
|
+
for (const run of check.elsewhere) {
|
|
106
|
+
lines.push(`${indent}- ${formatRunHeader(run)}`);
|
|
107
|
+
for (const job of run.failedJobs) {
|
|
108
|
+
lines.push(...renderFailedJob(job, run.conclusion, `${indent} `));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return lines;
|
|
112
|
+
}
|
|
@@ -5,4 +5,4 @@ export type QueueEjectionRecovery = "requeue" | "acknowledge" | "none";
|
|
|
5
5
|
/** The removed queue commit whose failed checks this tick surfaces, if the removal is current. */
|
|
6
6
|
export declare function currentEjectionCommit(report: ShepherdReport, checks: AgentCheck[]): string | undefined;
|
|
7
7
|
/** The ejection step after failing-check triage; points at a stack route already printed. */
|
|
8
|
-
export declare function queueEjectionSteps(recovery: QueueEjectionRecovery | undefined, stackRebase: string | undefined, routePrinted: boolean): string[];
|
|
8
|
+
export declare function queueEjectionSteps(recovery: QueueEjectionRecovery | undefined, stackRebase: string | undefined, routePrinted: boolean, hasElsewhere?: boolean): string[];
|
|
@@ -11,20 +11,23 @@ export function currentEjectionCommit(report, checks) {
|
|
|
11
11
|
: undefined;
|
|
12
12
|
}
|
|
13
13
|
/** The ejection step after failing-check triage; points at a stack route already printed. */
|
|
14
|
-
export function queueEjectionSteps(recovery, stackRebase, routePrinted) {
|
|
14
|
+
export function queueEjectionSteps(recovery, stackRebase, routePrinted, hasElsewhere = false) {
|
|
15
15
|
if (!recovery)
|
|
16
16
|
return [];
|
|
17
17
|
const route = stackRebase && routePrinted ? "use the stack route printed above." : stackRebase;
|
|
18
|
-
return [buildQueueEjectionInstruction(recovery, route)];
|
|
18
|
+
return [buildQueueEjectionInstruction(recovery, route, hasElsewhere)];
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* The trigger, update route, and command guard; the fixed procedure lives in the playbook.
|
|
22
22
|
* A printed command implies a `failed_checks` removal. Without one, the agent reads the raw
|
|
23
23
|
* removal reason, since a person's dequeue must not be undone by a branch update.
|
|
24
24
|
*/
|
|
25
|
-
function buildQueueEjectionInstruction(recovery, stackRoute) {
|
|
25
|
+
function buildQueueEjectionInstruction(recovery, stackRoute, hasElsewhere = false) {
|
|
26
26
|
const target = stackRoute ? "the stack" : "the PR head";
|
|
27
27
|
const route = stackRoute ? `: ${stackRoute}` : ".";
|
|
28
|
+
const elsewhere = hasElsewhere
|
|
29
|
+
? " Check `Same workflow elsewhere` under `## Failing checks` for recent runs of this workflow on the default branch and other merge-queue entries."
|
|
30
|
+
: "";
|
|
28
31
|
const update = recovery === "none"
|
|
29
32
|
? `If the \`**queue removal**\` reason shows GitHub removed the entry itself, update ${target} from the latest base first${route} If a person may have dequeued the PR, skip that update unless a conflict step above requires it.`
|
|
30
33
|
: `Update ${target} from the latest base first${route}`;
|
|
@@ -34,5 +37,5 @@ function buildQueueEjectionInstruction(recovery, stackRoute) {
|
|
|
34
37
|
: recovery === "acknowledge"
|
|
35
38
|
? `Run \`acknowledge queue removal:\` ${reproduce}`
|
|
36
39
|
: "Shepherd printed no queue command for this session, so do not enqueue the PR.";
|
|
37
|
-
return `Triage the merge-queue ejection before any requeue
|
|
40
|
+
return `Triage the merge-queue ejection before any requeue.${elsewhere} ${update} ${guard} ${playbookPointer("Merge queue ejection")}`;
|
|
38
41
|
}
|
|
@@ -68,7 +68,8 @@ cancelRunsStep) {
|
|
|
68
68
|
instructions.push(pathA(buildCommitSuggestionInstruction(prReference, "## Review threads")));
|
|
69
69
|
if (resolutionOnlyThreads.length > 0)
|
|
70
70
|
instructions.push("Review the threads under `## Review threads to resolve` before running the generated mutations.");
|
|
71
|
-
|
|
71
|
+
const hasElsewhere = failingChecks.some((c) => c.elsewhere !== undefined || c.elsewhereUnread !== undefined);
|
|
72
|
+
instructions.push(...buildFailingCheckInstructions(failingChecks), ...repeatedWorkflowBranchRecoveryInstructions.map(pathA), ...queueEjectionSteps(queueEjection, stackRebase, branchRecovery, hasElsewhere));
|
|
72
73
|
if (hasAnnotations)
|
|
73
74
|
instructions.push(pathA("Inspect every referenced range under `## Check annotations` and apply any warranted change."));
|
|
74
75
|
// The first step already covers applying changes-requested bodies; only stale CRs add a step.
|
|
@@ -12,6 +12,7 @@ import { buildCheckFollowUpInstructions, buildEvidenceFollowUpInstruction, check
|
|
|
12
12
|
import { checkFollowUpKeys, readCheckFollowUp, readShownRunFailures, sameCheckFollowUp, writeCheckFollowUp, writeShownRunFailures, } from "../../state/check-follow-up.mjs";
|
|
13
13
|
import { activeRunFailures, buildRunFailureWait, runFailureKeys, runFailuresShown, } from "./run-failure-wait.mjs";
|
|
14
14
|
import { currentEjectionCommit, } from "./queue-recovery-instructions.mjs";
|
|
15
|
+
import { attachWorkflowElsewhere } from "./workflow-elsewhere.mjs";
|
|
15
16
|
import { buildReleasedBlockerInstruction, buildReviewSubsetInstruction, } from "./check-instructions.mjs";
|
|
16
17
|
import { buildNativeStackLayerRebase } from "./native-stack-rebase.mjs";
|
|
17
18
|
import { buildDequeueCommand } from "./merge-plan.mjs";
|
|
@@ -183,10 +184,11 @@ async function handleTriageTick(ctx) {
|
|
|
183
184
|
? { ...c, rerunCommand: `gh run rerun ${c.runId} -R ${report.repo}` }
|
|
184
185
|
: c;
|
|
185
186
|
});
|
|
186
|
-
const
|
|
187
|
-
...
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
const annotatedAgentChecks = toAgentChecks(annotatedExtra).map((c) => ({
|
|
188
|
+
...c,
|
|
189
|
+
annotationOnly: true,
|
|
190
|
+
}));
|
|
191
|
+
const checks = [...failingAgentChecks, ...annotatedAgentChecks];
|
|
190
192
|
const { changesRequestedReviews } = report;
|
|
191
193
|
const hasConflicts = report.mergeStatus.status === "CONFLICTS";
|
|
192
194
|
const queuedConflict = isQueuedConflict(report.mergeQueue?.inQueue, report.mergeStatus.status);
|
|
@@ -325,13 +327,28 @@ async function handleTriageTick(ctx) {
|
|
|
325
327
|
const queueRemovalAcknowledgment = acknowledgmentRecovery && !("unavailable" in acknowledgmentRecovery)
|
|
326
328
|
? acknowledgmentRecovery
|
|
327
329
|
: undefined;
|
|
328
|
-
const
|
|
330
|
+
const ejectionCommit = currentEjectionCommit(report, failingAgentChecks);
|
|
331
|
+
const queueEjection = !ejectionCommit
|
|
329
332
|
? undefined
|
|
330
333
|
: requeue
|
|
331
334
|
? "requeue"
|
|
332
335
|
: queueRemovalAcknowledgment
|
|
333
336
|
? "acknowledge"
|
|
334
337
|
: "none";
|
|
338
|
+
const triageChecks = ejectionCommit
|
|
339
|
+
? [
|
|
340
|
+
...(await attachWorkflowElsewhere({
|
|
341
|
+
checks: failingAgentChecks,
|
|
342
|
+
rawFailing: failingChecks,
|
|
343
|
+
report,
|
|
344
|
+
repo: { owner: repoOwner, name: repoName },
|
|
345
|
+
stateKey: stallKey,
|
|
346
|
+
ejectionCommit,
|
|
347
|
+
compareWindowHours: loadConfig()["merge-queue"]["compare-window-hours"],
|
|
348
|
+
})),
|
|
349
|
+
...annotatedAgentChecks,
|
|
350
|
+
]
|
|
351
|
+
: checks;
|
|
335
352
|
// Conflicts, a behind branch whose rerun already failed, and a queue ejection that may be
|
|
336
353
|
// reproduced on the latest base all print the branch update route.
|
|
337
354
|
const stackRebase = hasConflicts || (isBehind && exhaustedAttempts.length > 0) || queueEjection
|
|
@@ -341,7 +358,7 @@ async function handleTriageTick(ctx) {
|
|
|
341
358
|
? renderShellCommand(buildDequeueCommand(report.nodeId))
|
|
342
359
|
: undefined;
|
|
343
360
|
const inProgressRuns = await buildInProgressRuns(report, rerunAuthorized);
|
|
344
|
-
const instructions = buildFixInstructions(threads, actionableComments,
|
|
361
|
+
const instructions = buildFixInstructions(threads, actionableComments, triageChecks.filter((check) => !releasedCheckNames.has(check.name)), changesRequestedReviews, baseLookup.branch, resolveCommand, hasConflicts, prReference, firstLookThreads, firstLookComments, firstLookSummaries, editedSummaries, resolutionOnlyThreads, resolveOnlyCommand, behindBaseHint, isBehind, canGenerateGithubMutation(report.viewerAuthorization?.viewerCanUpdate, "ready"), exhaustedAttempts.length > 0, stackRebase, queueEjection, opts.instructions ?? configuredInstructions, dequeueCommand, buildCancelRunsInstruction(inProgressRuns));
|
|
345
362
|
if (investigate) {
|
|
346
363
|
// The failing-checks pointer is replaced: these checks have no excerpt for the CI playbook.
|
|
347
364
|
const triageStep = instructions.findIndex((step) => step.startsWith("Triage `## Failing checks`."));
|
|
@@ -426,7 +443,7 @@ async function handleTriageTick(ctx) {
|
|
|
426
443
|
firstLookSummaries,
|
|
427
444
|
editedSummaries,
|
|
428
445
|
surfacedApprovals,
|
|
429
|
-
checks,
|
|
446
|
+
checks: triageChecks,
|
|
430
447
|
...(inProgressRuns.length > 0 && { inProgressRuns }),
|
|
431
448
|
...(requeue && { requeue }),
|
|
432
449
|
...(queueRemovalAcknowledgment && { queueRemovalAcknowledgment }),
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RepoInfo } from "../../github/client.mts";
|
|
2
|
+
import { type StateKey } from "../../state/rest-cache.mts";
|
|
3
|
+
import type { AgentCheck, ShepherdReport, TriagedCheck } from "../../types.mts";
|
|
4
|
+
export interface AttachWorkflowElsewhereInput {
|
|
5
|
+
checks: AgentCheck[];
|
|
6
|
+
rawFailing: TriagedCheck[];
|
|
7
|
+
report: ShepherdReport;
|
|
8
|
+
repo: RepoInfo;
|
|
9
|
+
stateKey: StateKey;
|
|
10
|
+
ejectionCommit: string;
|
|
11
|
+
compareWindowHours: number;
|
|
12
|
+
nowMs?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Enrich failing `merge_group` Actions checks belonging to the current queue removal with recent
|
|
16
|
+
* runs of the same workflow on the default branch and other queue entries. Cached briefly per
|
|
17
|
+
* removal; incomplete or failed reads are never cached and surface `elsewhereUnread`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function attachWorkflowElsewhere(input: AttachWorkflowElsewhereInput): Promise<AgentCheck[]>;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { readWorkflowElsewhere, resolveWorkflowId, summarizeElsewhereError, } from "../../github/workflow-elsewhere-read.mjs";
|
|
2
|
+
import { stampSameJob } from "../../github/workflow-elsewhere-parse.mjs";
|
|
3
|
+
import { queueRemovalSignature } from "../../state/queue-removal-follow-up.mjs";
|
|
4
|
+
import { loadDerived, storeDerived } from "../../state/rest-cache.mjs";
|
|
5
|
+
/** Cache TTL so later default-branch failures/recoveries appear on subsequent ticks. */
|
|
6
|
+
const ELSEWHERE_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
7
|
+
function isActionsProvenance(raw) {
|
|
8
|
+
return Boolean(raw &&
|
|
9
|
+
(raw.source === "startup_failure" ||
|
|
10
|
+
raw.workflowId !== undefined ||
|
|
11
|
+
raw.workflowName !== undefined));
|
|
12
|
+
}
|
|
13
|
+
function isFreshCached(value, nowMs) {
|
|
14
|
+
const e = value;
|
|
15
|
+
return Boolean(e &&
|
|
16
|
+
Array.isArray(e.runs) &&
|
|
17
|
+
typeof e.scope?.since === "string" &&
|
|
18
|
+
typeof e.scope?.defaultBranch?.branch === "string" &&
|
|
19
|
+
typeof e.scope?.defaultBranch?.matchedComplete === "boolean" &&
|
|
20
|
+
typeof e.scope?.mergeQueue?.runsRead === "number" &&
|
|
21
|
+
typeof e.scope?.mergeQueue?.matchedComplete === "boolean" &&
|
|
22
|
+
typeof e.cachedAtMs === "number" &&
|
|
23
|
+
nowMs - e.cachedAtMs >= 0 &&
|
|
24
|
+
nowMs - e.cachedAtMs < ELSEWHERE_CACHE_TTL_MS);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Enrich failing `merge_group` Actions checks belonging to the current queue removal with recent
|
|
28
|
+
* runs of the same workflow on the default branch and other queue entries. Cached briefly per
|
|
29
|
+
* removal; incomplete or failed reads are never cached and surface `elsewhereUnread`.
|
|
30
|
+
*/
|
|
31
|
+
export async function attachWorkflowElsewhere(input) {
|
|
32
|
+
const { checks, rawFailing, report, repo, stateKey, ejectionCommit, compareWindowHours } = input;
|
|
33
|
+
const nowMs = input.nowMs ?? Date.now();
|
|
34
|
+
const removal = report.mergeQueue?.latestRemoval;
|
|
35
|
+
if (compareWindowHours <= 0 || !removal)
|
|
36
|
+
return checks;
|
|
37
|
+
const windowStartMs = Math.floor((removal.createdAtUnix - compareWindowHours * 3600) * 1000);
|
|
38
|
+
const since = new Date(windowStartMs).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
39
|
+
const signature = queueRemovalSignature({
|
|
40
|
+
headSha: report.headSha ?? "unknown",
|
|
41
|
+
createdAtUnix: removal.createdAtUnix,
|
|
42
|
+
beforeCommitOid: ejectionCommit,
|
|
43
|
+
});
|
|
44
|
+
const rawByRunId = new Map();
|
|
45
|
+
for (const raw of rawFailing) {
|
|
46
|
+
if (raw.runId !== null &&
|
|
47
|
+
raw.scope === "merge_group" &&
|
|
48
|
+
raw.commitOid === ejectionCommit &&
|
|
49
|
+
(!rawByRunId.has(raw.runId) || raw.workflowId !== undefined)) {
|
|
50
|
+
rawByRunId.set(raw.runId, raw);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const workflowIdByRunId = new Map();
|
|
54
|
+
const outcomeByWorkflowId = new Map();
|
|
55
|
+
const resolveForRun = async (runId, raw) => {
|
|
56
|
+
const cached = workflowIdByRunId.get(runId);
|
|
57
|
+
if (cached)
|
|
58
|
+
return cached;
|
|
59
|
+
if (raw.workflowId && /^\d+$/.test(raw.workflowId)) {
|
|
60
|
+
const hit = { id: raw.workflowId };
|
|
61
|
+
workflowIdByRunId.set(runId, hit);
|
|
62
|
+
return hit;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const id = await resolveWorkflowId(repo, runId, stateKey);
|
|
66
|
+
const outcome = id ? { id } : { unread: "workflow ID unavailable" };
|
|
67
|
+
workflowIdByRunId.set(runId, outcome);
|
|
68
|
+
return outcome;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
const outcome = { unread: summarizeElsewhereError(error) };
|
|
72
|
+
workflowIdByRunId.set(runId, outcome);
|
|
73
|
+
return outcome;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const fetchForWorkflow = async (workflowId, currentRunId, raw, check) => {
|
|
77
|
+
const memoized = outcomeByWorkflowId.get(workflowId);
|
|
78
|
+
if (memoized)
|
|
79
|
+
return memoized;
|
|
80
|
+
const cacheName = `workflow-elsewhere:${signature}:wf:${workflowId}:h=${compareWindowHours}`;
|
|
81
|
+
const stored = await loadDerived(stateKey, cacheName);
|
|
82
|
+
if (stored && isFreshCached(stored.value, nowMs)) {
|
|
83
|
+
const hit = {
|
|
84
|
+
runs: stored.value.runs,
|
|
85
|
+
scope: stored.value.scope,
|
|
86
|
+
};
|
|
87
|
+
outcomeByWorkflowId.set(workflowId, hit);
|
|
88
|
+
return hit;
|
|
89
|
+
}
|
|
90
|
+
const workflowName = raw.workflowName ?? check.workflowName;
|
|
91
|
+
const workflowPath = raw.workflowPath ?? check.workflowPath;
|
|
92
|
+
let outcome;
|
|
93
|
+
try {
|
|
94
|
+
outcome = await readWorkflowElsewhere({
|
|
95
|
+
repo,
|
|
96
|
+
prNumber: report.pr,
|
|
97
|
+
workflowId,
|
|
98
|
+
...(workflowName !== undefined && { workflowName }),
|
|
99
|
+
...(workflowPath !== undefined && { workflowPath }),
|
|
100
|
+
currentRunId,
|
|
101
|
+
currentCommitOid: ejectionCommit,
|
|
102
|
+
windowStartMs,
|
|
103
|
+
since,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
outcome = { unread: summarizeElsewhereError(error) };
|
|
108
|
+
}
|
|
109
|
+
outcomeByWorkflowId.set(workflowId, outcome);
|
|
110
|
+
if ("runs" in outcome) {
|
|
111
|
+
await storeDerived(stateKey, cacheName, { runs: outcome.runs, scope: outcome.scope, cachedAtMs: nowMs }, report.headSha);
|
|
112
|
+
}
|
|
113
|
+
return outcome;
|
|
114
|
+
};
|
|
115
|
+
const enriched = [];
|
|
116
|
+
for (const check of checks) {
|
|
117
|
+
const raw = check.scope === "merge_group" && check.commitOid === ejectionCommit && check.runId
|
|
118
|
+
? rawByRunId.get(check.runId)
|
|
119
|
+
: undefined;
|
|
120
|
+
if (!isActionsProvenance(raw)) {
|
|
121
|
+
enriched.push(check);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
// eslint-disable-next-line no-await-in-loop
|
|
125
|
+
const resolved = await resolveForRun(check.runId, raw);
|
|
126
|
+
if ("unread" in resolved) {
|
|
127
|
+
enriched.push({ ...check, elsewhereUnread: resolved.unread });
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
// eslint-disable-next-line no-await-in-loop
|
|
131
|
+
const outcome = await fetchForWorkflow(resolved.id, check.runId, raw, check);
|
|
132
|
+
if ("unread" in outcome) {
|
|
133
|
+
enriched.push({ ...check, elsewhereUnread: outcome.unread });
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
enriched.push({
|
|
137
|
+
...check,
|
|
138
|
+
elsewhere: stampSameJob(outcome.runs, check.name),
|
|
139
|
+
elsewhereScope: outcome.scope,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return enriched;
|
|
144
|
+
}
|
package/bin/config/schema.d.mts
CHANGED
|
@@ -77,6 +77,9 @@ export declare const configSchema: z.ZodObject<{
|
|
|
77
77
|
}>>;
|
|
78
78
|
"command-args": z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
79
79
|
}, z.core.$strict>>;
|
|
80
|
+
"merge-queue": z.ZodPrefault<z.ZodObject<{
|
|
81
|
+
"compare-window-hours": z.ZodDefault<z.ZodNumber>;
|
|
82
|
+
}, z.core.$strict>>;
|
|
80
83
|
actions: z.ZodPrefault<z.ZodObject<{
|
|
81
84
|
"auto-minimize-suppressed": z.ZodDefault<z.ZodBoolean>;
|
|
82
85
|
"work-while-queued": z.ZodDefault<z.ZodBoolean>;
|
|
@@ -164,6 +167,9 @@ export declare const configFileSchema: z.ZodObject<{
|
|
|
164
167
|
}>>;
|
|
165
168
|
"command-args": z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
166
169
|
}, z.core.$strict>>;
|
|
170
|
+
"merge-queue": z.ZodPrefault<z.ZodObject<{
|
|
171
|
+
"compare-window-hours": z.ZodDefault<z.ZodNumber>;
|
|
172
|
+
}, z.core.$strict>>;
|
|
167
173
|
actions: z.ZodPrefault<z.ZodObject<{
|
|
168
174
|
"auto-minimize-suppressed": z.ZodDefault<z.ZodBoolean>;
|
|
169
175
|
"work-while-queued": z.ZodDefault<z.ZodBoolean>;
|
package/bin/config/schema.mjs
CHANGED
|
@@ -159,6 +159,9 @@ export const configSchema = z.strictObject({
|
|
|
159
159
|
"command-args": mergeCommandArgs.default(() => []),
|
|
160
160
|
})
|
|
161
161
|
.prefault({}),
|
|
162
|
+
"merge-queue": z
|
|
163
|
+
.strictObject({ "compare-window-hours": nonNegative().max(720).default(6) })
|
|
164
|
+
.prefault({}),
|
|
162
165
|
actions: z
|
|
163
166
|
.strictObject({
|
|
164
167
|
"auto-minimize-suppressed": z.boolean().default(true),
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
query DefaultBranchWorkflowRuns($owner: String!, $repo: String!) {
|
|
2
|
+
_shepherdRateLimit: rateLimit {
|
|
3
|
+
cost
|
|
4
|
+
limit
|
|
5
|
+
nodeCount
|
|
6
|
+
remaining
|
|
7
|
+
resetAt
|
|
8
|
+
used
|
|
9
|
+
}
|
|
10
|
+
repository(owner: $owner, name: $repo) {
|
|
11
|
+
defaultBranchRef {
|
|
12
|
+
name
|
|
13
|
+
target {
|
|
14
|
+
... on Commit {
|
|
15
|
+
history(first: 20) {
|
|
16
|
+
pageInfo {
|
|
17
|
+
hasNextPage
|
|
18
|
+
}
|
|
19
|
+
nodes {
|
|
20
|
+
oid
|
|
21
|
+
committedDate
|
|
22
|
+
checkSuites(first: 20) {
|
|
23
|
+
pageInfo {
|
|
24
|
+
hasNextPage
|
|
25
|
+
}
|
|
26
|
+
nodes {
|
|
27
|
+
status
|
|
28
|
+
conclusion
|
|
29
|
+
updatedAt
|
|
30
|
+
branch {
|
|
31
|
+
name
|
|
32
|
+
}
|
|
33
|
+
workflowRun {
|
|
34
|
+
databaseId
|
|
35
|
+
event
|
|
36
|
+
updatedAt
|
|
37
|
+
file {
|
|
38
|
+
path
|
|
39
|
+
}
|
|
40
|
+
workflow {
|
|
41
|
+
databaseId
|
|
42
|
+
name
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
checkRuns(first: 15, filterBy: { conclusions: [FAILURE, TIMED_OUT] }) {
|
|
46
|
+
nodes {
|
|
47
|
+
name
|
|
48
|
+
conclusion
|
|
49
|
+
annotations(first: 3) {
|
|
50
|
+
totalCount
|
|
51
|
+
nodes {
|
|
52
|
+
path
|
|
53
|
+
location {
|
|
54
|
+
start {
|
|
55
|
+
line
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
message
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
package/bin/github/queries.d.mts
CHANGED
|
@@ -80,3 +80,5 @@ export declare const GET_PR_BODY_QUERY: string;
|
|
|
80
80
|
export declare const UPDATE_PR_BODY_MUTATION: string;
|
|
81
81
|
/** CheckRun titles, summaries, and first annotations for routed stack-layer handoffs. */
|
|
82
82
|
export declare const STACK_HANDOFF_CHECK_RUNS_QUERY: string;
|
|
83
|
+
/** Recent default-branch commits and workflow check suites for merge-queue ejection comparison. */
|
|
84
|
+
export declare const DEFAULT_BRANCH_WORKFLOW_RUNS_QUERY: string;
|
package/bin/github/queries.mjs
CHANGED
|
@@ -86,3 +86,5 @@ export const GET_PR_BODY_QUERY = gql("get-pr-body.gql");
|
|
|
86
86
|
export const UPDATE_PR_BODY_MUTATION = gql("update-pr-body.gql");
|
|
87
87
|
/** CheckRun titles, summaries, and first annotations for routed stack-layer handoffs. */
|
|
88
88
|
export const STACK_HANDOFF_CHECK_RUNS_QUERY = gql("stack-handoff-check-runs.gql");
|
|
89
|
+
/** Recent default-branch commits and workflow check suites for merge-queue ejection comparison. */
|
|
90
|
+
export const DEFAULT_BRANCH_WORKFLOW_RUNS_QUERY = gql("default-branch-workflow-runs.gql");
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ElsewhereFailedJob, ElsewhereRun } from "../types/workflow-elsewhere.mts";
|
|
2
|
+
import type { ParsedDefaultBranchRuns, RawDefaultBranchRunsResponse, RawElsewhereSuite } from "../types/workflow-elsewhere-raw.mts";
|
|
3
|
+
export declare const MAX_ELSEWHERE_RUNS_PER_SOURCE = 3;
|
|
4
|
+
export declare const MAX_ELSEWHERE_FAILED_JOBS = 15;
|
|
5
|
+
export declare const MAX_ELSEWHERE_ANNOTATIONS = 3;
|
|
6
|
+
export declare const NON_DEFAULT_BRANCH_EVENTS: Set<string>;
|
|
7
|
+
/** Collapse newlines and whitespace and bound an annotation message for single-line display. */
|
|
8
|
+
export declare function normalizeAnnotationMessage(raw: string | null | undefined): string;
|
|
9
|
+
/** Remove null annotation entries in place and report whether any were present. */
|
|
10
|
+
export declare function stripNullAnnotations(suites: Array<RawElsewhereSuite | null> | undefined): boolean;
|
|
11
|
+
/** Extract failed/timed-out check runs and up to 3 annotations per job from one GraphQL suite. */
|
|
12
|
+
export declare function mapFailedJobs(suite: RawElsewhereSuite | undefined): ElsewhereFailedJob[];
|
|
13
|
+
/** Sort runs newest-first by completion timestamp, breaking ties by numeric run ID descending. */
|
|
14
|
+
export declare function sortNewestFirst<T extends {
|
|
15
|
+
completedAt: string;
|
|
16
|
+
runId: string;
|
|
17
|
+
}>(items: T[]): T[];
|
|
18
|
+
export declare function parseDefaultBranchRuns(data: RawDefaultBranchRunsResponse, workflowId: string, windowStartMs: number): ParsedDefaultBranchRuns;
|
|
19
|
+
export declare function stampSameJob(runs: readonly ElsewhereRun[], checkName: string): ElsewhereRun[];
|