pr-shepherd 2.2.17 → 2.2.18
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 +3 -1
- package/bin/commands/check-annotations.d.mts +2 -0
- package/bin/commands/check-annotations.mjs +22 -7
- package/bin/commands/check-unread-readiness.d.mts +6 -0
- package/bin/commands/check-unread-readiness.mjs +7 -0
- package/bin/commands/check.mjs +5 -0
- package/bin/github/batch-page-helpers.d.mts +3 -0
- package/bin/github/batch-page-helpers.mjs +5 -2
- package/bin/github/batch-page.mjs +2 -4
- package/bin/github/batch-parser-helpers.mjs +2 -0
- package/bin/github/batch-parsers.mjs +3 -3
- package/bin/github/batch-raw-types.d.mts +4 -2
- package/bin/github/batch-receipt-evidence.mjs +1 -0
- package/bin/github/batch-response.d.mts +2 -1
- package/bin/github/batch-response.mjs +8 -11
- package/bin/github/batch.mjs +8 -3
- package/bin/github/check-annotation-pages.d.mts +10 -1
- package/bin/github/check-annotation-pages.mjs +26 -2
- package/bin/github/merge-queue-checks.mjs +8 -4
- package/bin/github/null-nodes.d.mts +19 -0
- package/bin/github/null-nodes.mjs +68 -0
- package/bin/github/poll-summary-annotation-probe.mjs +3 -1
- package/bin/github/poll-summary-check-hydration.mjs +8 -5
- package/bin/github/poll-summary-checks.mjs +2 -0
- package/bin/github/poll-summary-fingerprint.mjs +2 -0
- package/bin/github/poll-summary-raw.d.mts +2 -0
- package/bin/github/poll-summary-readiness.mjs +2 -0
- package/bin/github/poll-summary-review.mjs +2 -1
- package/bin/github/stack-handoff-page.mjs +2 -2
- package/bin/github/stack-read.mjs +1 -1
- package/bin/github/thread-comments.d.mts +6 -2
- package/bin/github/thread-comments.mjs +12 -1
- package/bin/types/github.d.mts +2 -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/bin/github/check-suite-nodes.d.mts +0 -17
- package/bin/github/check-suite-nodes.mjs +0 -14
package/README.md
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Take pull requests from scratch to merge-ready with a coding agent, as a [Code Mode-style](https://code.claude.com/docs/en/code-mode) plugin. It works with Claude Code, Codex, and Grok.
|
|
4
4
|
|
|
5
|
+
A local CLI, harness-agnostic version of [PR Steward](https://code.claude.com/docs/en/pr-steward). See [comparisons](docs/comparison.md).
|
|
6
|
+
|
|
5
7
|
## Benefits
|
|
6
8
|
|
|
7
9
|
- **Better decisions:** across 71 PR states, it scores 0.95 with the plugin vs. 0.57 with `gh` + the GitHub MCP server ([outcome evals](evals/README.md), 2026-11-23).
|
|
8
10
|
- **Lower cost:** modeled cost per PR session is about 34% lower than `gh` and 75% lower than the GitHub MCP server, with 18% / 69% fewer turns ([token bench](evals/tokens/README.md); assumes a warm prompt cache).
|
|
9
11
|
- **More PRs on one GitHub quota:** 65% fewer GraphQL points than `gh` per PR session. While CI runs, a 5,000-point hourly budget covers about 80 waiting PRs, vs. about 13 with `gh pr checks --watch` ([GitHub API](docs/github-api.md), [GraphQL usage](docs/graphql-usage.md)). A [GitHub App](docs/github-app.md) and [webhook events](docs/hook-harness.md) cut it more.
|
|
10
|
-
- **
|
|
12
|
+
- **79 GitHub edge cases handled:** outdated or resolved threads are still shown once, edited comments come back, and conflicts that GraphQL reports as `CLEAN` are caught ([handled cases](docs/handled-cases.md)).
|
|
11
13
|
- **Tidy PRs, less context:** bot and outdated comments are triaged and resolved, human reviews get replies, and known bot noise is minimized and filtered out before it reaches the agent.
|
|
12
14
|
- **Review hygiene:** it never answers its own replies or minimizes human comments, skips a denied reply once, and hands a repeatedly rejected fix to a human ([comments and reviews](docs/handled-cases.md#comments-and-reviews)).
|
|
13
15
|
- **CI failures, pre-read:** each failing check comes with its failed step, summary, and log excerpt, so the agent rarely fetches logs. Superseded runs, unstarted required checks, and approval gates are recognized ([failing checks](docs/actions.md#failing-checks-and-reruns), [CI cases](docs/handled-cases.md#ci-checks)).
|
|
@@ -35,5 +35,7 @@ export declare function attachAndMergeCheckAnnotations(buckets: {
|
|
|
35
35
|
failing: TriagedCheck[];
|
|
36
36
|
skipped: ClassifiedCheck[];
|
|
37
37
|
filtered: ClassifiedCheck[];
|
|
38
|
+
/** A fetched annotation page held a null entry: CI is not fully known this tick. */
|
|
39
|
+
annotationsUnread?: true;
|
|
38
40
|
}>;
|
|
39
41
|
export declare function annotationMarkerBody(a: CheckAnnotation): string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fetchCheckRunAnnotationsBatch } from "../github/check-annotations-batch.mjs";
|
|
2
|
+
import { NullAnnotationNodeError } from "../github/check-annotation-pages.mjs";
|
|
2
3
|
import { pollRateLimitRetryAfterMs } from "./poll-quota.mjs";
|
|
3
4
|
function shouldFetchCheckAnnotations(check) {
|
|
4
5
|
return check.id != null && check.status === "COMPLETED" && check.hasAnnotations === true;
|
|
@@ -45,7 +46,7 @@ export async function attachAndMergeCheckAnnotations(buckets, seenMap, prNumber,
|
|
|
45
46
|
...buckets.filtered,
|
|
46
47
|
].filter(shouldFetchCheckAnnotations);
|
|
47
48
|
const expectedCounts = new Map(candidates.flatMap((c) => c.id != null && c.annotationCount ? [[c.id, c.annotationCount]] : []));
|
|
48
|
-
const annotated = await attachUnseenCheckAnnotations(candidates, seenMap, prNumber, cacheOpts && { ...cacheOpts, expectedCounts });
|
|
49
|
+
const { checks: annotated, unread } = await attachUnseenCheckAnnotations(candidates, seenMap, prNumber, cacheOpts && { ...cacheOpts, expectedCounts });
|
|
49
50
|
const byId = new Map(annotated.flatMap((c) => (c.id != null ? [[c.id, c]] : [])));
|
|
50
51
|
const apply = (list) => list.map((c) => {
|
|
51
52
|
const next = (c.id == null ? undefined : byId.get(c.id)) ?? c;
|
|
@@ -59,12 +60,14 @@ export async function attachAndMergeCheckAnnotations(buckets, seenMap, prNumber,
|
|
|
59
60
|
failing: apply(buckets.failing),
|
|
60
61
|
skipped: apply(buckets.skipped),
|
|
61
62
|
filtered: apply(buckets.filtered),
|
|
63
|
+
...(unread && { annotationsUnread: true }),
|
|
62
64
|
};
|
|
63
65
|
}
|
|
64
66
|
async function attachUnseenCheckAnnotations(checks, seenMap, prNumber, cacheOpts) {
|
|
65
67
|
if (checks.length === 0)
|
|
66
|
-
return checks;
|
|
68
|
+
return { checks, unread: false };
|
|
67
69
|
const annotations = new Map();
|
|
70
|
+
let unread = false;
|
|
68
71
|
for (const check of checks) {
|
|
69
72
|
if (check.id != null && check.inlineAnnotations)
|
|
70
73
|
annotations.set(check.id, check.inlineAnnotations);
|
|
@@ -79,16 +82,28 @@ async function attachUnseenCheckAnnotations(checks, seenMap, prNumber, cacheOpts
|
|
|
79
82
|
if (pollRateLimitRetryAfterMs(err) !== null)
|
|
80
83
|
throw err;
|
|
81
84
|
writeAnnotationFailureSummary(prNumber, ids.length, err);
|
|
82
|
-
return
|
|
85
|
+
return {
|
|
86
|
+
checks: checks.map((check) => withUnseenAnnotations(check, annotations, seenMap)),
|
|
87
|
+
unread: false,
|
|
88
|
+
};
|
|
83
89
|
}
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
90
|
+
const nullFailures = batch.failures.filter((f) => f.error instanceof NullAnnotationNodeError);
|
|
91
|
+
unread = nullFailures.length > 0;
|
|
92
|
+
// Entries read from a page that also held a null still surface; the run is held unread.
|
|
93
|
+
for (const failure of nullFailures) {
|
|
94
|
+
annotations.set(failure.checkRunId, failure.error.readable);
|
|
95
|
+
}
|
|
96
|
+
const otherFailures = batch.failures.filter((f) => !nullFailures.includes(f));
|
|
97
|
+
if (otherFailures[0] !== undefined) {
|
|
98
|
+
writeAnnotationFailureSummary(prNumber, otherFailures.length, otherFailures[0].error);
|
|
87
99
|
}
|
|
88
100
|
for (const [id, list] of batch.annotations)
|
|
89
101
|
annotations.set(id, list);
|
|
90
102
|
}
|
|
91
|
-
return
|
|
103
|
+
return {
|
|
104
|
+
checks: checks.map((check) => withUnseenAnnotations(check, annotations, seenMap)),
|
|
105
|
+
unread,
|
|
106
|
+
};
|
|
92
107
|
}
|
|
93
108
|
function withUnseenAnnotations(check, annotations, seenMap) {
|
|
94
109
|
const fetched = check.id == null ? undefined : annotations.get(check.id);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BatchPrData, ShepherdStatus } from "../types.mts";
|
|
2
|
+
/**
|
|
3
|
+
* A snapshot with unreadable (null) nodes cannot prove CI or feedback is clear, so it is never
|
|
4
|
+
* READY: the PR waits and the next tick re-reads it.
|
|
5
|
+
*/
|
|
6
|
+
export declare function holdUnreadReadiness(status: ShepherdStatus, data: BatchPrData): ShepherdStatus;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A snapshot with unreadable (null) nodes cannot prove CI or feedback is clear, so it is never
|
|
3
|
+
* READY: the PR waits and the next tick re-reads it.
|
|
4
|
+
*/
|
|
5
|
+
export function holdUnreadReadiness(status, data) {
|
|
6
|
+
return status === "READY" && data.unreadNodes ? "PENDING" : status;
|
|
7
|
+
}
|
package/bin/commands/check.mjs
CHANGED
|
@@ -21,6 +21,7 @@ import { loadConfig } from "../config/load.mjs";
|
|
|
21
21
|
import { classifyVisibleComments } from "../comments/visible-comments.mjs";
|
|
22
22
|
import { withHeadOid } from "./review-commit.mjs";
|
|
23
23
|
import { computeStatus } from "./check-status.mjs";
|
|
24
|
+
import { holdUnreadReadiness } from "./check-unread-readiness.mjs";
|
|
24
25
|
import { annotationMarkerBody, attachAndMergeCheckAnnotations, hasCheckDrivenActionableWork, isQueuedConflict, } from "./check-annotations.mjs";
|
|
25
26
|
import { buildTerminalReport } from "./check-terminal-report.mjs";
|
|
26
27
|
import { headStillSettling } from "./check-settle.mjs";
|
|
@@ -43,6 +44,7 @@ import { buildClassifyIndex, partitionBatch } from "../classify/apply.mjs";
|
|
|
43
44
|
import { EXIT, ShepherdError } from "../exit-codes.mjs";
|
|
44
45
|
import { getEffectiveCwd } from "../execution-context.mjs";
|
|
45
46
|
function enforceTransportReadiness(status, data) {
|
|
47
|
+
status = holdUnreadReadiness(status, data);
|
|
46
48
|
if (status !== "READY" || data.transport !== "rest")
|
|
47
49
|
return status;
|
|
48
50
|
const conversationsGated = data.branchRules?.requiresConversationResolution;
|
|
@@ -281,6 +283,9 @@ async function runScopedCheck(opts, context, repo, prNumber, stateKey) {
|
|
|
281
283
|
settling;
|
|
282
284
|
let status = computeStatus(verdict, threadVisibility.activeThreads.length + threadVisibility.resolutionOnlyThreads.length, visibleCommentClassification.actionable.length, mergeStatus, changesRequestedReviewCount, awaitingChecks);
|
|
283
285
|
status = enforceTransportReadiness(status, batchData);
|
|
286
|
+
// A null annotation entry means CI is not fully known: wait a tick instead of READY.
|
|
287
|
+
if (merged.annotationsUnread && status === "READY")
|
|
288
|
+
status = "PENDING";
|
|
284
289
|
// Resolve any pending mergeability refresh (and the resulting MERGED/CLOSED short-circuit)
|
|
285
290
|
// before deciding what to persist below — deferWhileQueued must see the same final,
|
|
286
291
|
// possibly-refreshed mergeStatus that commands/iterate/index.mts acts on, not the pre-refresh
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type UnreadNodes } from "./null-nodes.mts";
|
|
1
2
|
import type { RawContextNode, RawComment, RawPr, RawReview, RawReviewSummary, RawThread } from "./batch-raw-types.mts";
|
|
2
3
|
export interface RawPageResponse {
|
|
3
4
|
repository: {
|
|
@@ -38,6 +39,8 @@ export interface PageAccumulator {
|
|
|
38
39
|
reviewSummaries: RawReviewSummary[];
|
|
39
40
|
approvedReviews: RawReviewSummary[];
|
|
40
41
|
checks: RawContextNode[];
|
|
42
|
+
/** What a page returned as null, dropped before it joined the lists above. */
|
|
43
|
+
unreadNodes?: UnreadNodes;
|
|
41
44
|
}
|
|
42
45
|
export declare function applyIncludedPage(dest: PageAccumulator, pr2: NonNullable<RawPageResponse["repository"]["pullRequest"]>, cursors: PageCursors, firstOid: string | undefined, pageCount: number, pr: number): {
|
|
43
46
|
cursors: PageCursors;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { contextNodes } from "./batch-response.mjs";
|
|
2
|
+
import { dropNullNodes, mergeUnread } from "./null-nodes.mjs";
|
|
2
3
|
export function backwardCursor(conn) {
|
|
3
4
|
if (conn?.pageInfo.hasPreviousPage === true && conn.pageInfo.startCursor) {
|
|
4
5
|
return conn.pageInfo.startCursor;
|
|
@@ -28,9 +29,11 @@ function takeCheckPage(pr2, firstOid, pageCount) {
|
|
|
28
29
|
if (!ctxs) {
|
|
29
30
|
return { pageInfo: { hasNextPage: false, endCursor: null }, nodes: [] };
|
|
30
31
|
}
|
|
31
|
-
return { ...ctxs, nodes:
|
|
32
|
+
return { ...ctxs, nodes: contextNodes(ctxs.nodes) };
|
|
32
33
|
}
|
|
33
34
|
export function applyIncludedPage(dest, pr2, cursors, firstOid, pageCount, pr) {
|
|
35
|
+
// A null in a page is dropped, never skipped silently: the caller learns the lists are partial.
|
|
36
|
+
dest.unreadNodes = mergeUnread(dest.unreadNodes, dropNullNodes(pr2));
|
|
34
37
|
const next = {};
|
|
35
38
|
let nextPageCount = pageCount;
|
|
36
39
|
if (cursors.threads !== undefined) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { graphqlWithRateLimit } from "./client.mjs";
|
|
2
2
|
import { GitHubRequestError } from "./errors.mjs";
|
|
3
3
|
import { BATCH_PR_PAGE_DATA_QUERY, BATCH_PR_PAGE_QUERY } from "./queries.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { contextNodes } from "./batch-response.mjs";
|
|
5
5
|
import { applyIncludedPage, backwardCursor, forwardCursor, } from "./batch-page-helpers.mjs";
|
|
6
6
|
/**
|
|
7
7
|
* Fetch remaining connection pages with a slim `@include` query. Independent
|
|
@@ -14,9 +14,7 @@ export async function paginateBatchConnections(pr, repo, raw, opts, initialRateL
|
|
|
14
14
|
changesRequested: [...raw.changesRequestedReviews.nodes],
|
|
15
15
|
reviewSummaries: [...raw.reviewSummaries.nodes],
|
|
16
16
|
approvedReviews: [...raw.approvedReviews.nodes],
|
|
17
|
-
checks: [
|
|
18
|
-
...requireContextNodes(raw.commits.nodes[0]?.commit.statusCheckRollup?.contexts.nodes ?? []),
|
|
19
|
-
],
|
|
17
|
+
checks: [...contextNodes(raw.commits.nodes[0]?.commit.statusCheckRollup?.contexts.nodes ?? [])],
|
|
20
18
|
};
|
|
21
19
|
const firstOid = raw.commits.nodes[0]?.commit.oid;
|
|
22
20
|
let cursors = {
|
|
@@ -79,6 +79,8 @@ function inlineAnnotationsField(checkRunId, annotations) {
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
function fullRawAnnotation(node) {
|
|
82
|
+
if (node == null)
|
|
83
|
+
return null;
|
|
82
84
|
if (typeof node.path !== "string" || typeof node.annotationLevel !== "string")
|
|
83
85
|
return null;
|
|
84
86
|
if (node.location === undefined || node.fullDatabaseId === undefined)
|
|
@@ -2,7 +2,7 @@ import { mapAuthorType, parseCreatedAt, latestApprovedLogins, isReviewStale, } f
|
|
|
2
2
|
import { parseCheckNodes } from "./batch-parse-checks.mjs";
|
|
3
3
|
import { headFreshAtUnix } from "./head-freshness.mjs";
|
|
4
4
|
import { headPushUnixFromCheckNodes } from "./queue-removal-freshness.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { contextNodes } from "./batch-response.mjs";
|
|
6
6
|
import { buildPrActivitySummary } from "./activity.mjs";
|
|
7
7
|
import { parseBranchProtection } from "./branch-protection.mjs";
|
|
8
8
|
import { readAllowedMergeMethods } from "../config/merge-method.mjs";
|
|
@@ -111,7 +111,7 @@ export function parseRawPr(raw, rawThreadPages, rawCommentNodes, rawReviewNodes,
|
|
|
111
111
|
const queueHead = raw.mergeQueueEntry?.headCommit;
|
|
112
112
|
const removedQueueHead = raw.mergeQueueRemovals?.nodes[0]?.beforeCommit;
|
|
113
113
|
const mergeQueueChecks = parseCheckNodes(queueHead?.statusCheckRollup
|
|
114
|
-
?
|
|
114
|
+
? contextNodes(queueHead.statusCheckRollup.contexts.nodes)
|
|
115
115
|
: undefined, queueHead?.oid);
|
|
116
116
|
const headPushedAtUnix = headPushUnixFromCheckNodes(rawCheckNodes);
|
|
117
117
|
const headForcePushedAt = raw.headRefForcePushes?.nodes[0]?.createdAt;
|
|
@@ -122,7 +122,7 @@ export function parseRawPr(raw, rawThreadPages, rawCommentNodes, rawReviewNodes,
|
|
|
122
122
|
committedAt: raw.commits.nodes[0]?.commit.committedDate,
|
|
123
123
|
});
|
|
124
124
|
const removedMergeQueueChecks = parseCheckNodes(removedQueueHead?.statusCheckRollup
|
|
125
|
-
?
|
|
125
|
+
? contextNodes(removedQueueHead.statusCheckRollup.contexts.nodes)
|
|
126
126
|
: undefined, removedQueueHead?.oid);
|
|
127
127
|
const allowedMergeMethods = readAllowedMergeMethods(repository);
|
|
128
128
|
return {
|
|
@@ -16,6 +16,8 @@ export interface RawBatchResponse {
|
|
|
16
16
|
} | null;
|
|
17
17
|
}
|
|
18
18
|
export interface RawPr extends RawPrMergeFields {
|
|
19
|
+
/** Set when GitHub returned null connection nodes (dropped); see `null-nodes.mts`. */
|
|
20
|
+
unreadNodes?: import("./null-nodes.mts").UnreadNodes;
|
|
19
21
|
id: string;
|
|
20
22
|
number: number;
|
|
21
23
|
createdAt?: string;
|
|
@@ -245,9 +247,9 @@ export type RawContextNode = {
|
|
|
245
247
|
summary: string | null;
|
|
246
248
|
annotations?: {
|
|
247
249
|
totalCount?: number;
|
|
248
|
-
nodes: Array<Partial<RawCheckAnnotation> & {
|
|
250
|
+
nodes: Array<(Partial<RawCheckAnnotation> & {
|
|
249
251
|
message: string;
|
|
250
|
-
}>;
|
|
252
|
+
}) | null>;
|
|
251
253
|
};
|
|
252
254
|
checkSuite: {
|
|
253
255
|
status?: string | null;
|
|
@@ -3,6 +3,7 @@ import { markReadyAnnotationProbeComplete } from "./poll-summary-annotation-prob
|
|
|
3
3
|
/** Keep the exact PollSummaryPr shape used by v1 receipts; add only complete annotation totals. */
|
|
4
4
|
export async function prepareBatchReceiptEvidence(summary, batch, checks, repo) {
|
|
5
5
|
if (!summary ||
|
|
6
|
+
summary.unreadNodes ||
|
|
6
7
|
summary.number !== batch.number ||
|
|
7
8
|
summary.headRefOid !== batch.headRefOid ||
|
|
8
9
|
summary.baseRefOid !== batch.baseRefOid)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { RepoInfo } from "./client.mts";
|
|
2
2
|
import type { RawBatchResponse, RawContextNode, RawPr } from "./batch-raw-types.mts";
|
|
3
3
|
export declare function requireRawPr(response: RawBatchResponse | null | undefined, pr: number, repo: RepoInfo): RawPr;
|
|
4
|
-
|
|
4
|
+
/** The context nodes of a page that `dropNullNodes` already cleaned. */
|
|
5
|
+
export declare function contextNodes(nodes: Array<RawContextNode | null>): RawContextNode[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EXIT, ShepherdError } from "../exit-codes.mjs";
|
|
2
2
|
import { GitHubRequestError } from "./errors.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { dropNullNodes } from "./null-nodes.mjs";
|
|
4
4
|
export function requireRawPr(response, pr, repo) {
|
|
5
5
|
if (!response?.repository) {
|
|
6
6
|
throw new GitHubRequestError(`GitHub GraphQL response did not include repository ${repo.owner}/${repo.name} (not found or access denied)`, { status: 200 });
|
|
@@ -9,16 +9,13 @@ export function requireRawPr(response, pr, repo) {
|
|
|
9
9
|
throw new ShepherdError(`PR #${pr} not found`, EXIT.UNAVAILABLE);
|
|
10
10
|
}
|
|
11
11
|
const raw = response.repository.pullRequest;
|
|
12
|
-
|
|
12
|
+
raw.unreadNodes = dropNullNodes(raw);
|
|
13
|
+
const receipt = response.repository.receiptSummary;
|
|
14
|
+
if (receipt)
|
|
15
|
+
receipt.unreadNodes = dropNullNodes(receipt);
|
|
13
16
|
return raw;
|
|
14
17
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// A null context node is an unexpected/malformed shape, not a precondition or
|
|
19
|
-
// permission problem — force EX_SOFTWARE rather than falling through to the
|
|
20
|
-
// (200-status-derived) EX_UNAVAILABLE default.
|
|
21
|
-
throw new GitHubRequestError(`Malformed GitHub GraphQL response: null check context at repository.pullRequest.commits.nodes.0.commit.statusCheckRollup.contexts.nodes.${nullIndex}`, { status: 200, exitCodeOverride: EXIT.SOFTWARE });
|
|
22
|
-
}
|
|
23
|
-
return nodes;
|
|
18
|
+
/** The context nodes of a page that `dropNullNodes` already cleaned. */
|
|
19
|
+
export function contextNodes(nodes) {
|
|
20
|
+
return nodes.filter((node) => node !== null);
|
|
24
21
|
}
|
package/bin/github/batch.mjs
CHANGED
|
@@ -15,6 +15,7 @@ import { hydrateMergeQueueChecks } from "./merge-queue-checks.mjs";
|
|
|
15
15
|
import { fingerprintFromRaw } from "./fingerprint.mjs";
|
|
16
16
|
import { stackEvidenceFromRaw } from "./batch-stack-evidence.mjs";
|
|
17
17
|
import { takeStackHandoff } from "./stack-handoff.mjs";
|
|
18
|
+
import { mergeUnread } from "./null-nodes.mjs";
|
|
18
19
|
/**
|
|
19
20
|
* Fetch all PR data needed for a `shepherd check` in one (or a few, if paginating) GraphQL requests.
|
|
20
21
|
*/
|
|
@@ -29,7 +30,8 @@ async function fetchGraphqlPrBatch(pr, repo, opts = {}, reuse) {
|
|
|
29
30
|
// place of the viewer login: another token never matches a stored one.
|
|
30
31
|
const fingerprint = fingerprintFromRaw(raw, result.data.repository?.viewerPermission ?? null, result.data.viewer?.login ?? (split ? `token:${(await makeAuthHeaders()).fingerprint}` : null));
|
|
31
32
|
// Decide reuse from the first page alone, before any supplement is paid for.
|
|
32
|
-
|
|
33
|
+
// A page with an unreadable node cannot vouch for a stored report.
|
|
34
|
+
const reused = reuse && !raw.unreadNodes && (await reuse(fingerprint));
|
|
33
35
|
const baseTipOid = raw.baseRef?.target?.oid;
|
|
34
36
|
// A split read has no viewer fields yet, so a reused tick carries only the trunk rules.
|
|
35
37
|
let stackEvidence = stackEvidenceFromRaw(raw, result.data, split);
|
|
@@ -49,7 +51,7 @@ async function fetchGraphqlPrBatch(pr, repo, opts = {}, reuse) {
|
|
|
49
51
|
stackEvidence = stackEvidenceFromRaw(raw, { viewer, repository: viewer.repository });
|
|
50
52
|
}
|
|
51
53
|
let receiptSummary = null;
|
|
52
|
-
if (opts.includeReceiptSummary) {
|
|
54
|
+
if (opts.includeReceiptSummary && !raw.unreadNodes) {
|
|
53
55
|
try {
|
|
54
56
|
receiptSummary = await prepareBatchReceiptEvidence(result.data.repository?.receiptSummary, raw, paged.checks, repo);
|
|
55
57
|
}
|
|
@@ -63,14 +65,17 @@ async function fetchGraphqlPrBatch(pr, repo, opts = {}, reuse) {
|
|
|
63
65
|
if (numericId)
|
|
64
66
|
await recordThreadIdentity(repo, pr, thread.id, numericId);
|
|
65
67
|
}
|
|
68
|
+
const unreadNodes = mergeUnread(raw.unreadNodes, paged.unreadNodes, threadPages.unreadNodes);
|
|
66
69
|
const data = parseRawPr(raw, threadPages.threads, paged.comments, paged.changesRequested, paged.reviewSummaries, paged.approvedReviews, paged.checks, viewer ? { ...result.data.repository, ...viewer.repository } : result.data.repository);
|
|
67
70
|
const viewerLogin = viewer ? viewer.login : result.data.viewer?.login;
|
|
68
71
|
if (viewerLogin)
|
|
69
72
|
data.viewerLogin = viewerLogin;
|
|
73
|
+
if (unreadNodes)
|
|
74
|
+
data.unreadNodes = unreadNodes;
|
|
70
75
|
data.checks = mergeStartupFailureChecks(data.checks, parseSuiteStartupFailures(raw));
|
|
71
76
|
return {
|
|
72
77
|
data,
|
|
73
|
-
fingerprint,
|
|
78
|
+
...(!unreadNodes && { fingerprint }),
|
|
74
79
|
// A split read's other samples are the app's buckets; only the viewer read is the user's.
|
|
75
80
|
rateLimit: viewer
|
|
76
81
|
? viewer.rateLimit
|
|
@@ -5,7 +5,16 @@ export interface AnnotationPage {
|
|
|
5
5
|
hasNextPage: boolean;
|
|
6
6
|
endCursor: string | null;
|
|
7
7
|
};
|
|
8
|
-
nodes: RawCheckAnnotation
|
|
8
|
+
nodes: Array<RawCheckAnnotation | null>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A fetched page held a null annotation entry. `readable` is every annotation that was read, so a
|
|
12
|
+
* caller can still surface them while treating the run as unread (never cached, READY held).
|
|
13
|
+
*/
|
|
14
|
+
export declare class NullAnnotationNodeError extends Error {
|
|
15
|
+
readonly checkRunId: string;
|
|
16
|
+
readonly readable: CheckAnnotation[];
|
|
17
|
+
constructor(checkRunId: string, readable: CheckAnnotation[]);
|
|
9
18
|
}
|
|
10
19
|
/** Pages a single check run. `firstPage` skips the initial `node(id:)` request. */
|
|
11
20
|
export declare function collectAnnotations(checkRunId: string, firstPage?: AnnotationPage): Promise<CheckAnnotation[]>;
|
|
@@ -3,16 +3,37 @@ import { toCheckAnnotation } from "./check-annotation-shape.mjs";
|
|
|
3
3
|
import { CHECK_RUN_ANNOTATIONS_QUERY } from "./queries.mjs";
|
|
4
4
|
const ANNOTATIONS_PER_PAGE = 100;
|
|
5
5
|
const MAX_ANNOTATION_PAGES = 10;
|
|
6
|
+
/**
|
|
7
|
+
* A fetched page held a null annotation entry. `readable` is every annotation that was read, so a
|
|
8
|
+
* caller can still surface them while treating the run as unread (never cached, READY held).
|
|
9
|
+
*/
|
|
10
|
+
export class NullAnnotationNodeError extends Error {
|
|
11
|
+
checkRunId;
|
|
12
|
+
readable;
|
|
13
|
+
constructor(checkRunId, readable) {
|
|
14
|
+
super(`check run ${checkRunId} annotation page contains a null node`);
|
|
15
|
+
this.checkRunId = checkRunId;
|
|
16
|
+
this.readable = readable;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
6
19
|
/** Pages a single check run. `firstPage` skips the initial `node(id:)` request. */
|
|
7
20
|
export async function collectAnnotations(checkRunId, firstPage) {
|
|
8
21
|
const nodes = [];
|
|
22
|
+
let sawNull = false;
|
|
9
23
|
let cursor = null;
|
|
10
24
|
let seeded = firstPage;
|
|
11
25
|
for (let pageNumber = 1; pageNumber <= MAX_ANNOTATION_PAGES; pageNumber++) {
|
|
12
26
|
// eslint-disable-next-line no-await-in-loop
|
|
13
27
|
const current = seeded ?? (await fetchAnnotationPage(checkRunId, cursor));
|
|
14
28
|
seeded = undefined;
|
|
15
|
-
|
|
29
|
+
// A null entry is an annotation GitHub has not served yet. Keep reading, then fail with the
|
|
30
|
+
// readable entries so the caller holds READY and rereads next tick (never caches the run).
|
|
31
|
+
for (const node of current.nodes) {
|
|
32
|
+
if (node == null)
|
|
33
|
+
sawNull = true;
|
|
34
|
+
else
|
|
35
|
+
nodes.push(node);
|
|
36
|
+
}
|
|
16
37
|
if (!current.pageInfo.hasNextPage || !current.pageInfo.endCursor)
|
|
17
38
|
break;
|
|
18
39
|
if (pageNumber === MAX_ANNOTATION_PAGES) {
|
|
@@ -21,7 +42,10 @@ export async function collectAnnotations(checkRunId, firstPage) {
|
|
|
21
42
|
}
|
|
22
43
|
cursor = current.pageInfo.endCursor;
|
|
23
44
|
}
|
|
24
|
-
|
|
45
|
+
const annotations = nodes.map((node) => toCheckAnnotation(checkRunId, node));
|
|
46
|
+
if (sawNull)
|
|
47
|
+
throw new NullAnnotationNodeError(checkRunId, annotations);
|
|
48
|
+
return annotations;
|
|
25
49
|
}
|
|
26
50
|
async function fetchAnnotationPage(checkRunId, cursor) {
|
|
27
51
|
const res = await graphql(CHECK_RUN_ANNOTATIONS_QUERY, {
|
|
@@ -2,7 +2,8 @@ import { parseCreatedAt } from "./batch-parser-helpers.mjs";
|
|
|
2
2
|
import { graphqlWithRateLimit } from "./client.mjs";
|
|
3
3
|
import { GitHubRequestError } from "./errors.mjs";
|
|
4
4
|
import { forcePushUnix, headPushUnixFromCheckNodes, queueRemovalAppliesToHead, } from "./queue-removal-freshness.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { contextNodes } from "./batch-response.mjs";
|
|
6
|
+
import { dropNullNodes, mergeUnread } from "./null-nodes.mjs";
|
|
6
7
|
import { COMMIT_CHECK_CONTEXTS_QUERY } from "./queries.mjs";
|
|
7
8
|
function omittedCursorError(oid) {
|
|
8
9
|
return new Error(`Merge queue check pagination interrupted: GitHub omitted the next cursor for ${oid}. Retry.`);
|
|
@@ -39,11 +40,13 @@ async function fetchQueuePage(oid, repo, cursor, gate) {
|
|
|
39
40
|
return null;
|
|
40
41
|
throw new Error(`Merge queue check pagination interrupted: commit ${oid} disappeared or changed. Retry.`);
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
+
const contexts = object.statusCheckRollup?.contexts;
|
|
44
|
+
gate.unreadNodes = mergeUnread(gate.unreadNodes, dropNullNodes({ contexts }));
|
|
45
|
+
return contexts ?? null;
|
|
43
46
|
}
|
|
44
47
|
async function hydrateCommitContexts(commit, repo, gate) {
|
|
45
48
|
const existing = commit.statusCheckRollup?.contexts;
|
|
46
|
-
const nodes = existing ? [...
|
|
49
|
+
const nodes = existing ? [...contextNodes(existing.nodes)] : [];
|
|
47
50
|
let cursor = initialQueueCursor(existing, commit.oid);
|
|
48
51
|
while (cursor !== undefined) {
|
|
49
52
|
// eslint-disable-next-line no-await-in-loop
|
|
@@ -55,7 +58,7 @@ async function hydrateCommitContexts(commit, repo, gate) {
|
|
|
55
58
|
}
|
|
56
59
|
throw new Error(`Merge queue check pagination interrupted: statusCheckRollup disappeared for ${commit.oid}. Retry.`);
|
|
57
60
|
}
|
|
58
|
-
nodes.push(...
|
|
61
|
+
nodes.push(...contextNodes(next.nodes));
|
|
59
62
|
cursor = nextPageCursor(next, commit.oid);
|
|
60
63
|
}
|
|
61
64
|
commit.statusCheckRollup = {
|
|
@@ -95,5 +98,6 @@ export async function hydrateMergeQueueChecks(raw, repo, initialRateLimit) {
|
|
|
95
98
|
await hydrateCommitContexts(active, repo, gate);
|
|
96
99
|
if (removed && removed.oid !== active?.oid)
|
|
97
100
|
await hydrateCommitContexts(removed, repo, gate);
|
|
101
|
+
raw.unreadNodes = mergeUnread(raw.unreadNodes, gate.unreadNodes);
|
|
98
102
|
return gate.rateLimit;
|
|
99
103
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a read could not see because GitHub returned `null` in place of a connection node
|
|
3
|
+
* (seen right after a push, with no GraphQL error). Internal only: it gates readiness and
|
|
4
|
+
* reuse and is never printed.
|
|
5
|
+
*/
|
|
6
|
+
export interface UnreadNodes {
|
|
7
|
+
/** A check context, commit or queue entry was unreadable: CI state is not fully known. */
|
|
8
|
+
checks?: true;
|
|
9
|
+
/** A review thread, comment, review or rule was unreadable: feedback is not fully known. */
|
|
10
|
+
feedback?: true;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Remove `null` from every connection under `root`, in place, so no later reader dereferences
|
|
14
|
+
* one. Returns what was unreadable, or undefined when nothing was. Never use this on a root
|
|
15
|
+
* `nodes(ids: ...)` lookup, where null is the meaningful "not found" answer.
|
|
16
|
+
*/
|
|
17
|
+
export declare function dropNullNodes(root: object | null | undefined): UnreadNodes | undefined;
|
|
18
|
+
/** The union of several reads' unreadable parts. */
|
|
19
|
+
export declare function mergeUnread(...parts: Array<UnreadNodes | undefined>): UnreadNodes | undefined;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Connections whose nodes only describe history; a null there changes no decision. */
|
|
2
|
+
const INFORMATIONAL = new Set([
|
|
3
|
+
"parents",
|
|
4
|
+
"mergeQueueRemovalTimes",
|
|
5
|
+
"headRefForcePushes",
|
|
6
|
+
"prCommitOids",
|
|
7
|
+
]);
|
|
8
|
+
/** Keys that put the connections under them on the CI side of the split. */
|
|
9
|
+
const CHECK_KEYS = new Set(["commits", "statusCheckRollup", "contexts", "checkSuites"]);
|
|
10
|
+
function hasNullComment(thread) {
|
|
11
|
+
const comments = thread.comments?.nodes;
|
|
12
|
+
return comments?.includes(null) === true;
|
|
13
|
+
}
|
|
14
|
+
function tidyConnection(connection, key, inChecks, found) {
|
|
15
|
+
let kept = connection.nodes.filter((node) => node !== null);
|
|
16
|
+
// A thread missing one comment would hash a partial transcript and could point replies at the
|
|
17
|
+
// wrong root, so the whole thread counts as unread.
|
|
18
|
+
if (key === "reviewThreads")
|
|
19
|
+
kept = kept.filter((thread) => !hasNullComment(thread));
|
|
20
|
+
if (kept.length === connection.nodes.length)
|
|
21
|
+
return;
|
|
22
|
+
connection.nodes = kept;
|
|
23
|
+
// Consumers already treat an unread suite page as unverified.
|
|
24
|
+
if (key === "checkSuites")
|
|
25
|
+
connection.pageInfo = { ...connection.pageInfo, hasNextPage: true };
|
|
26
|
+
if (!INFORMATIONAL.has(key))
|
|
27
|
+
found[inChecks ? "checks" : "feedback"] = true;
|
|
28
|
+
}
|
|
29
|
+
function visit(value, key, inChecks, found) {
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
for (const item of value)
|
|
32
|
+
visit(item, key, inChecks, found);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
// Inline annotation nulls mean "read the annotations separately" and are handled there.
|
|
36
|
+
if (typeof value !== "object" || value === null || key === "annotations")
|
|
37
|
+
return;
|
|
38
|
+
const record = value;
|
|
39
|
+
const checks = inChecks || CHECK_KEYS.has(key);
|
|
40
|
+
if (Array.isArray(record["nodes"])) {
|
|
41
|
+
tidyConnection(record, key, checks, found);
|
|
42
|
+
}
|
|
43
|
+
for (const [child, node] of Object.entries(record))
|
|
44
|
+
visit(node, child, checks, found);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Remove `null` from every connection under `root`, in place, so no later reader dereferences
|
|
48
|
+
* one. Returns what was unreadable, or undefined when nothing was. Never use this on a root
|
|
49
|
+
* `nodes(ids: ...)` lookup, where null is the meaningful "not found" answer.
|
|
50
|
+
*/
|
|
51
|
+
export function dropNullNodes(root) {
|
|
52
|
+
if (!root)
|
|
53
|
+
return undefined;
|
|
54
|
+
const found = {};
|
|
55
|
+
visit(root, "", false, found);
|
|
56
|
+
return found.checks || found.feedback ? found : undefined;
|
|
57
|
+
}
|
|
58
|
+
/** The union of several reads' unreadable parts. */
|
|
59
|
+
export function mergeUnread(...parts) {
|
|
60
|
+
const merged = {};
|
|
61
|
+
for (const part of parts) {
|
|
62
|
+
if (part?.checks)
|
|
63
|
+
merged.checks = true;
|
|
64
|
+
if (part?.feedback)
|
|
65
|
+
merged.feedback = true;
|
|
66
|
+
}
|
|
67
|
+
return merged.checks || merged.feedback ? merged : undefined;
|
|
68
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { dropNullNodes } from "./null-nodes.mjs";
|
|
1
2
|
import { githubOperation } from "./transport.mjs";
|
|
2
3
|
import { readRestAnnotationCounts } from "./rest-check-read.mjs";
|
|
3
4
|
import { graphqlWithRateLimit } from "./client.mjs";
|
|
@@ -79,7 +80,8 @@ async function collectProbePages(oid, repo) {
|
|
|
79
80
|
const seen = new Set();
|
|
80
81
|
for (;;) {
|
|
81
82
|
const contexts = await fetchProbePage(oid, repo, before);
|
|
82
|
-
|
|
83
|
+
// An unreadable context leaves its annotation total unknown: no total is trustworthy.
|
|
84
|
+
if (!contexts || dropNullNodes({ contexts }))
|
|
83
85
|
return null;
|
|
84
86
|
pages.push(...contexts.nodes);
|
|
85
87
|
const pageInfo = contexts.pageInfo;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { githubOperation } from "./transport.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { dropNullNodes, mergeUnread } from "./null-nodes.mjs";
|
|
3
3
|
import { readRestCommitChecks } from "./rest-check-read.mjs";
|
|
4
4
|
import { graphqlWithRateLimit } from "./client.mjs";
|
|
5
5
|
import { POLL_SUMMARY_CHECK_PAGE_QUERY } from "./queries.mjs";
|
|
@@ -14,14 +14,16 @@ import { POLL_SUMMARY_CHECK_PAGE_QUERY } from "./queries.mjs";
|
|
|
14
14
|
*/
|
|
15
15
|
export async function hydratePollSummaryChecks(raw, repo) {
|
|
16
16
|
const headCommit = raw.commits.nodes[0]?.commit;
|
|
17
|
-
|
|
17
|
+
raw.unreadNodes = mergeUnread(raw.unreadNodes, dropNullNodes(raw));
|
|
18
|
+
const pages = {};
|
|
18
19
|
if (headCommit)
|
|
19
|
-
await hydrateCommitContexts(headCommit, repo);
|
|
20
|
+
await hydrateCommitContexts(headCommit, repo, pages);
|
|
20
21
|
const queueCommit = raw.mergeQueueEntry?.headCommit;
|
|
21
22
|
if (queueCommit)
|
|
22
|
-
await hydrateCommitContexts(queueCommit, repo);
|
|
23
|
+
await hydrateCommitContexts(queueCommit, repo, pages);
|
|
24
|
+
raw.unreadNodes = mergeUnread(raw.unreadNodes, pages.unreadNodes);
|
|
23
25
|
}
|
|
24
|
-
async function hydrateCommitContexts(commit, repo) {
|
|
26
|
+
async function hydrateCommitContexts(commit, repo, pages) {
|
|
25
27
|
const contexts = commit.statusCheckRollup?.contexts;
|
|
26
28
|
if (!contexts)
|
|
27
29
|
return;
|
|
@@ -31,6 +33,7 @@ async function hydrateCommitContexts(commit, repo) {
|
|
|
31
33
|
const older = await fetchOlderContexts(commit.oid, pageInfo.startCursor, repo);
|
|
32
34
|
if (!older)
|
|
33
35
|
break;
|
|
36
|
+
pages.unreadNodes = mergeUnread(pages.unreadNodes, dropNullNodes({ contexts: older }));
|
|
34
37
|
if (older.fullSnapshot)
|
|
35
38
|
nodes.splice(0, nodes.length, ...older.nodes);
|
|
36
39
|
else
|
|
@@ -18,6 +18,8 @@ export function summarizePollSummaryChecks(raw, requiredContexts) {
|
|
|
18
18
|
counts[key] = (counts[key] ?? 0) + 1;
|
|
19
19
|
}
|
|
20
20
|
const summary = counts;
|
|
21
|
+
if (raw.unreadNodes?.checks)
|
|
22
|
+
summary.incomplete = true;
|
|
21
23
|
if (rollups.some(({ rollup }) => rollup.contexts.pageInfo.hasPreviousPage)) {
|
|
22
24
|
summary.incomplete = true;
|
|
23
25
|
}
|
|
@@ -14,6 +14,8 @@ import { withoutHandoffFields } from "./poll-summary-handoff-fields.mjs";
|
|
|
14
14
|
* to post-rule state unless the one-PR check hashes the same projection.
|
|
15
15
|
*/
|
|
16
16
|
export function fingerprintRawSummaryPr(summary) {
|
|
17
|
+
if (summary.unreadNodes)
|
|
18
|
+
return null;
|
|
17
19
|
const raw = withoutHandoffFields(summary);
|
|
18
20
|
if (!raw.updatedAt || !raw.headRefOid || !raw.baseRefOid)
|
|
19
21
|
return null;
|
|
@@ -112,6 +112,8 @@ export interface RawSummaryCommit {
|
|
|
112
112
|
} | null;
|
|
113
113
|
}
|
|
114
114
|
export interface RawSummaryPr {
|
|
115
|
+
/** Set when GitHub returned null connection nodes (dropped); see `null-nodes.mts`. */
|
|
116
|
+
unreadNodes?: import("./null-nodes.mts").UnreadNodes;
|
|
115
117
|
transport?: "rest";
|
|
116
118
|
transportUnavailable?: Array<{
|
|
117
119
|
field: string;
|
|
@@ -28,6 +28,8 @@ export function isCurrentSummaryReady(raw, checks, review, options = {}) {
|
|
|
28
28
|
return (isKnownMergeStateStatus(raw.mergeStateStatus) &&
|
|
29
29
|
transportReadinessGaps(raw, raw.mergeStateStatus, requiresConversationResolution).length ===
|
|
30
30
|
0 &&
|
|
31
|
+
// A null review node is unknown, never settled by CLEAN or branch rules: reread next tick.
|
|
32
|
+
raw.unreadNodes?.feedback !== true &&
|
|
31
33
|
checks.incomplete !== true &&
|
|
32
34
|
sourceChecks.incomplete !== true &&
|
|
33
35
|
(review.incomplete !== true ||
|
|
@@ -23,7 +23,8 @@ export async function evaluatePollSummaryReview(raw, seen, viewerCanAdminister,
|
|
|
23
23
|
const bots = normalizeBotUsernames(config["bot-usernames"]);
|
|
24
24
|
const rules = await loadClassifyRules(getEffectiveCwd(), config.standardRules);
|
|
25
25
|
let actionable = 0;
|
|
26
|
-
let incomplete = raw.
|
|
26
|
+
let incomplete = raw.unreadNodes?.feedback === true ||
|
|
27
|
+
raw.comments.pageInfo.hasPreviousPage ||
|
|
27
28
|
raw.reviews.pageInfo.hasPreviousPage ||
|
|
28
29
|
raw.reviewThreads.pageInfo.hasPreviousPage;
|
|
29
30
|
// A pre-minimized comment is a first-look acknowledgement, never readiness work.
|
|
@@ -19,6 +19,8 @@ function reviewsIn(layer, state) {
|
|
|
19
19
|
/** True when every window `BatchPr`'s first page reads is complete in this summary. */
|
|
20
20
|
export function summaryComplete(layer, source) {
|
|
21
21
|
const { read } = source;
|
|
22
|
+
if (layer.unreadNodes)
|
|
23
|
+
return false;
|
|
22
24
|
if (!read.stack || read.viewerPermission === undefined || !read.mergeSettings)
|
|
23
25
|
return false;
|
|
24
26
|
if (source.layers.length > MAX_STACK_ENTRIES || !layer.stack || !layer.stackEntry)
|
|
@@ -42,8 +44,6 @@ export function summaryComplete(layer, source) {
|
|
|
42
44
|
const commit = headCommit(layer);
|
|
43
45
|
if (!commit || commit.oid !== layer.headRefOid || !commit.checkSuites?.pageInfo)
|
|
44
46
|
return false;
|
|
45
|
-
if (commit.checkSuites.nodes.includes(null))
|
|
46
|
-
return false;
|
|
47
47
|
const contexts = commit.statusCheckRollup?.contexts;
|
|
48
48
|
if (contexts &&
|
|
49
49
|
(contexts.pageInfo.hasPreviousPage ||
|
|
@@ -51,7 +51,7 @@ pageCeiling) {
|
|
|
51
51
|
stackNumber = stack.number;
|
|
52
52
|
stackSize = stack.size;
|
|
53
53
|
for (const entry of stack.entries.nodes) {
|
|
54
|
-
if (!entry
|
|
54
|
+
if (!entry?.pullRequest) {
|
|
55
55
|
throw new ShepherdError("GitHub returned an incomplete pull-request stack entry", EXIT.TEMPFAIL);
|
|
56
56
|
}
|
|
57
57
|
entries.push({ position: entry.position, pullRequest: entry.pullRequest });
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { type RateLimitInfo } from "./client.mts";
|
|
2
|
+
import { type UnreadNodes } from "./null-nodes.mts";
|
|
2
3
|
import type { RawThread } from "./batch-raw-types.mts";
|
|
3
|
-
export
|
|
4
|
+
export interface ThreadPages {
|
|
4
5
|
threads: RawThread[];
|
|
5
6
|
rateLimit?: RateLimitInfo;
|
|
6
|
-
|
|
7
|
+
/** Set when a thread was withheld because one of its comments came back null. */
|
|
8
|
+
unreadNodes?: UnreadNodes;
|
|
9
|
+
}
|
|
10
|
+
export declare function hydrateThreadCommentPages(threads: RawThread[], initialRateLimit?: RateLimitInfo, viewerFree?: boolean): Promise<ThreadPages>;
|
|
@@ -5,6 +5,7 @@ import { GitHubRequestError } from "./errors.mjs";
|
|
|
5
5
|
import { paginateForward } from "./pagination.mjs";
|
|
6
6
|
import { REVIEW_THREAD_COMMENTS_DATA_QUERY, REVIEW_THREAD_COMMENTS_QUERY } from "./queries.mjs";
|
|
7
7
|
import { mapPool } from "../util/pool.mjs";
|
|
8
|
+
import { dropNullNodes } from "./null-nodes.mjs";
|
|
8
9
|
const THREAD_COMMENT_PAGE_CONCURRENCY = 4;
|
|
9
10
|
async function hydrateGraphqlThreadCommentPages(threads, initialRateLimit, viewerFree = false) {
|
|
10
11
|
const gate = {
|
|
@@ -24,9 +25,16 @@ async function hydrateGraphqlThreadCommentPages(threads, initialRateLimit, viewe
|
|
|
24
25
|
});
|
|
25
26
|
if (gate.error !== undefined)
|
|
26
27
|
throw gate.error;
|
|
27
|
-
|
|
28
|
+
// A thread with an unreadable comment is withheld whole: a partial transcript is not its own.
|
|
29
|
+
const threadsRead = hydrated.filter((thread) => thread !== null);
|
|
30
|
+
return {
|
|
31
|
+
threads: threadsRead,
|
|
32
|
+
rateLimit: gate.rateLimit,
|
|
33
|
+
...(threadsRead.length < hydrated.length && { unreadNodes: { feedback: true } }),
|
|
34
|
+
};
|
|
28
35
|
}
|
|
29
36
|
async function hydrateThreadCommentPage(thread, gate, viewerFree) {
|
|
37
|
+
let unread = false;
|
|
30
38
|
const pageInfo = thread.comments.pageInfo;
|
|
31
39
|
if (!pageInfo?.hasNextPage || !pageInfo.endCursor)
|
|
32
40
|
return thread;
|
|
@@ -52,8 +60,11 @@ async function hydrateThreadCommentPage(thread, gate, viewerFree) {
|
|
|
52
60
|
const nodeType = node?.__typename ?? "null";
|
|
53
61
|
throw new Error(`Review thread ${thread.id} did not resolve to PullRequestReviewThread while paginating comments (node type: ${nodeType})`);
|
|
54
62
|
}
|
|
63
|
+
unread ||= dropNullNodes(node) !== undefined;
|
|
55
64
|
return node.comments;
|
|
56
65
|
}, pageInfo.endCursor);
|
|
66
|
+
if (unread)
|
|
67
|
+
return null;
|
|
57
68
|
return {
|
|
58
69
|
...thread,
|
|
59
70
|
comments: {
|
package/bin/types/github.d.mts
CHANGED
|
@@ -194,6 +194,8 @@ export interface BatchPrData extends BatchPrMergeFields {
|
|
|
194
194
|
field: string;
|
|
195
195
|
reason: string;
|
|
196
196
|
}>;
|
|
197
|
+
/** Internal: GitHub returned null nodes, so this snapshot is partial. Never printed. */
|
|
198
|
+
unreadNodes?: import("../github/null-nodes.mts").UnreadNodes;
|
|
197
199
|
nodeId: string;
|
|
198
200
|
number: number;
|
|
199
201
|
state: "OPEN" | "CLOSED" | "MERGED";
|
package/package.json
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
interface SuiteCommit {
|
|
2
|
-
checkSuites?: {
|
|
3
|
-
pageInfo?: {
|
|
4
|
-
hasNextPage: boolean;
|
|
5
|
-
};
|
|
6
|
-
nodes: unknown[];
|
|
7
|
-
} | null;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* GitHub can return `null` in place of a check suite it has not finished
|
|
11
|
-
* creating or cannot read (seen in a PR's first seconds, with no GraphQL error).
|
|
12
|
-
* Nothing is known about such a suite, so it is dropped rather than guessed at,
|
|
13
|
-
* and the page is marked as not fully read: consumers already treat an unread
|
|
14
|
-
* suite page as unverified, which fails readiness closed instead of crashing.
|
|
15
|
-
*/
|
|
16
|
-
export declare function dropUnreadableSuites(commit: SuiteCommit | null | undefined): void;
|
|
17
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GitHub can return `null` in place of a check suite it has not finished
|
|
3
|
-
* creating or cannot read (seen in a PR's first seconds, with no GraphQL error).
|
|
4
|
-
* Nothing is known about such a suite, so it is dropped rather than guessed at,
|
|
5
|
-
* and the page is marked as not fully read: consumers already treat an unread
|
|
6
|
-
* suite page as unverified, which fails readiness closed instead of crashing.
|
|
7
|
-
*/
|
|
8
|
-
export function dropUnreadableSuites(commit) {
|
|
9
|
-
const suites = commit?.checkSuites;
|
|
10
|
-
if (!suites || !suites.nodes.includes(null))
|
|
11
|
-
return;
|
|
12
|
-
suites.nodes = suites.nodes.filter((node) => node !== null);
|
|
13
|
-
suites.pageInfo = { ...suites.pageInfo, hasNextPage: true };
|
|
14
|
-
}
|