pr-shepherd 2.4.0 → 2.5.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 +3 -3
- package/.grok-plugin/marketplace.json +1 -1
- package/README.md +7 -9
- package/bin/classify/apply.d.mts +8 -1
- package/bin/classify/apply.mjs +37 -47
- package/bin/classify/items.d.mts +7 -0
- package/bin/classify/items.mjs +57 -0
- package/bin/classify/standard/coderabbit-notices.d.mts +2 -1
- package/bin/classify/standard/coderabbit-notices.mjs +33 -1
- package/bin/classify/standard/index.d.mts +2 -1
- package/bin/classify/standard/index.mjs +2 -1
- package/bin/classify/types.d.mts +8 -3
- package/bin/cli/iterate-lean.mjs +3 -0
- package/bin/cli/list-formatters.d.mts +1 -0
- package/bin/cli/list-formatters.mjs +3 -1
- package/bin/cli/triage-formatter.mjs +6 -1
- package/bin/commands/check-activity.mjs +2 -1
- package/bin/commands/check-fingerprint.mjs +1 -0
- package/bin/commands/check.mjs +39 -9
- package/bin/commands/iterate/check-instructions.d.mts +2 -0
- package/bin/commands/iterate/check-instructions.mjs +14 -0
- package/bin/commands/iterate/classify.d.mts +17 -3
- package/bin/commands/iterate/classify.mjs +105 -66
- package/bin/commands/iterate/escalate.mjs +6 -1
- package/bin/commands/iterate/index.mjs +16 -24
- package/bin/commands/iterate/render.d.mts +2 -11
- package/bin/commands/iterate/render.mjs +10 -19
- package/bin/commands/iterate/stall.mjs +3 -0
- package/bin/commands/iterate/triage.d.mts +1 -0
- package/bin/commands/iterate/triage.mjs +18 -13
- package/bin/commands/poll-summary-instructions.d.mts +1 -1
- package/bin/commands/poll-summary-instructions.mjs +2 -2
- package/bin/commands/poll-summary.mjs +1 -1
- package/bin/commands/resolve-mutate.mjs +39 -4
- package/bin/commands/resolve-review-guard.d.mts +19 -0
- package/bin/commands/resolve-review-guard.mjs +61 -0
- package/bin/commands/stack-merge-escalations.d.mts +6 -0
- package/bin/commands/stack-merge-escalations.mjs +17 -0
- package/bin/commands/stack-merge-plan.mjs +10 -6
- package/bin/comments/resolve.mjs +4 -4
- package/bin/comments/review-thread-markers.d.mts +1 -1
- package/bin/comments/review-thread-markers.mjs +23 -9
- package/bin/comments/superseded-approvals.d.mts +28 -0
- package/bin/comments/superseded-approvals.mjs +99 -0
- package/bin/config/schema.d.mts +2 -0
- package/bin/config/schema.mjs +1 -0
- package/bin/github/batch-parsers.mjs +31 -0
- package/bin/github/batch-raw-types.d.mts +3 -0
- package/bin/github/batch-viewer.d.mts +2 -2
- package/bin/github/batch.mjs +1 -1
- package/bin/github/gql/batch-pr-page.gql +8 -2
- package/bin/github/gql/batch-pr.gql +4 -1
- package/bin/github/poll-summary-review-helpers.d.mts +20 -0
- package/bin/github/poll-summary-review-helpers.mjs +81 -0
- package/bin/github/poll-summary-review.mjs +37 -46
- package/bin/github/poll-summary-rule-auto-resolve.mjs +1 -0
- package/bin/github/poll-summary-rule-items.d.mts +1 -1
- package/bin/github/poll-summary-rule-items.mjs +3 -2
- package/bin/github/rest-batch-snapshot.mjs +25 -1
- package/bin/github/review-unresolved-threads.d.mts +13 -0
- package/bin/github/review-unresolved-threads.mjs +152 -0
- package/bin/github/stack-handoff-page.mjs +5 -1
- package/bin/state/seen-comments.d.mts +3 -1
- package/bin/state/seen-comments.mjs +28 -2
- package/bin/types/escalate.d.mts +1 -0
- package/bin/types/github.d.mts +7 -1
- package/bin/types/iterate.d.mts +4 -2
- package/bin/types/report.d.mts +8 -0
- package/package.json +5 -5
- package/plugins/pr-shepherd/.claude-plugin/plugin.json +3 -3
- package/plugins/pr-shepherd/.codex-plugin/plugin.json +6 -6
- package/plugins/pr-shepherd/skills/setup-pr-shepherd/SKILL.md +1 -1
- package/plugins/pr-shepherd/skills/setup-pr-shepherd/references/classifiers.md +3 -3
- package/plugins/pr-shepherd/skills/setup-pr-shepherd/references/upstream-standard-rule.md +2 -2
- package/pr-shepherd.schema.json +4 -0
- package/src/classify/types.mts +9 -1
|
@@ -251,6 +251,8 @@ query BatchPr($owner: String!, $repo: String!, $pr: Int!) {
|
|
|
251
251
|
}
|
|
252
252
|
nodes {
|
|
253
253
|
id
|
|
254
|
+
isMinimized
|
|
255
|
+
viewerCanMinimize
|
|
254
256
|
authorAssociation
|
|
255
257
|
author {
|
|
256
258
|
__typename
|
|
@@ -263,13 +265,14 @@ query BatchPr($owner: String!, $repo: String!, $pr: Int!) {
|
|
|
263
265
|
}
|
|
264
266
|
}
|
|
265
267
|
}
|
|
266
|
-
reviewSummaries: reviews(states: COMMENTED, last: 50) {
|
|
268
|
+
reviewSummaries: reviews(states: [COMMENTED, DISMISSED], last: 50) {
|
|
267
269
|
pageInfo {
|
|
268
270
|
hasPreviousPage
|
|
269
271
|
startCursor
|
|
270
272
|
}
|
|
271
273
|
nodes {
|
|
272
274
|
id
|
|
275
|
+
state
|
|
273
276
|
isMinimized
|
|
274
277
|
viewerCanMinimize
|
|
275
278
|
authorAssociation
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ClassifyAction } from "../classify/types.mts";
|
|
2
|
+
import type { LoadedRule } from "../classify/loader.mts";
|
|
3
|
+
import { type NormalizedBotUsernames } from "../comments/authors.mts";
|
|
4
|
+
import { type SeenMarker } from "../state/seen-comments.mts";
|
|
5
|
+
import type { MinimizeCommentsPolicy } from "../config/load.mts";
|
|
6
|
+
import type { RawSummaryPr } from "./poll-summary-raw.mts";
|
|
7
|
+
export declare function countActionableSummaryReviews(input: {
|
|
8
|
+
raw: RawSummaryPr;
|
|
9
|
+
summaryActions: ReadonlyMap<string, ClassifyAction>;
|
|
10
|
+
rules: LoadedRule[];
|
|
11
|
+
confirmed: ReadonlySet<string>;
|
|
12
|
+
unconfirmed: ReadonlySet<string>;
|
|
13
|
+
blockedReviewIds: ReadonlySet<string>;
|
|
14
|
+
seen: Map<string, SeenMarker>;
|
|
15
|
+
viewerCanAdminister: boolean | undefined;
|
|
16
|
+
minimizeApprovals: boolean;
|
|
17
|
+
minimizeSupersededApprovals: boolean;
|
|
18
|
+
minimizeComments: MinimizeCommentsPolicy;
|
|
19
|
+
bots: NormalizedBotUsernames;
|
|
20
|
+
}): number;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { findSupersededApprovalIds } from "../comments/superseded-approvals.mjs";
|
|
2
|
+
import { shouldMinimizeAuthor } from "../comments/minimize-policy.mjs";
|
|
3
|
+
import { isConfiguredBotAuthor, isHumanAuthor, normalizeAuthorType, } from "../comments/authors.mjs";
|
|
4
|
+
import { classifyItem, mutationWasDenied } from "../state/seen-comments.mjs";
|
|
5
|
+
import { canGenerateGithubMutation } from "./mutation-policy.mjs";
|
|
6
|
+
import { parseCreatedAt } from "./batch-parser-helpers.mjs";
|
|
7
|
+
import { ruleHides, summaryRuleAction } from "./poll-summary-rule-items.mjs";
|
|
8
|
+
const authorOf = (author) => ({
|
|
9
|
+
login: author?.login ?? "",
|
|
10
|
+
authorType: normalizeAuthorType(author?.__typename, author?.login),
|
|
11
|
+
});
|
|
12
|
+
function summarySupersededApprovalIds(raw) {
|
|
13
|
+
return findSupersededApprovalIds({
|
|
14
|
+
reviews: raw.reviews.nodes
|
|
15
|
+
.filter((review) => review.state === "APPROVED" ||
|
|
16
|
+
review.state === "CHANGES_REQUESTED" ||
|
|
17
|
+
review.state === "DISMISSED" ||
|
|
18
|
+
review.state === "COMMENTED")
|
|
19
|
+
.map((review) => ({
|
|
20
|
+
id: review.id,
|
|
21
|
+
author: review.author?.login ?? "unknown",
|
|
22
|
+
state: review.state,
|
|
23
|
+
body: review.body,
|
|
24
|
+
createdAtUnix: review.createdAt ? parseCreatedAt(review.createdAt) : 0,
|
|
25
|
+
})),
|
|
26
|
+
latestReviews: (raw.latestReviews?.nodes ?? []).map((review) => ({
|
|
27
|
+
login: review.author?.login ?? "unknown",
|
|
28
|
+
state: review.state,
|
|
29
|
+
})),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function canMinimizeSummaryReview(review, blockedReviewIds, seen, minimizeComments, bots) {
|
|
33
|
+
const author = authorOf(review.author);
|
|
34
|
+
return (!review.isMinimized &&
|
|
35
|
+
!blockedReviewIds.has(review.id) &&
|
|
36
|
+
!mutationWasDenied(review.id, review.body, seen) &&
|
|
37
|
+
canGenerateGithubMutation(review.viewerCanMinimize, "minimize") &&
|
|
38
|
+
shouldMinimizeAuthor(author.authorType, minimizeComments, author.login, bots));
|
|
39
|
+
}
|
|
40
|
+
export function countActionableSummaryReviews(input) {
|
|
41
|
+
const { raw, summaryActions, rules, confirmed, unconfirmed, blockedReviewIds, seen, viewerCanAdminister, minimizeApprovals, minimizeSupersededApprovals, minimizeComments, bots, } = input;
|
|
42
|
+
const latestStateByAuthor = new Map((raw.latestReviews?.nodes ?? []).flatMap((review) => review.author ? [[review.author.login.toLowerCase(), review.state]] : []));
|
|
43
|
+
const supersededApprovalIds = summarySupersededApprovalIds(raw);
|
|
44
|
+
const canMinimize = (review) => canMinimizeSummaryReview(review, blockedReviewIds, seen, minimizeComments, bots);
|
|
45
|
+
let actionable = 0;
|
|
46
|
+
for (const review of raw.reviews.nodes) {
|
|
47
|
+
if (review.state === "COMMENTED" || review.state === "DISMISSED") {
|
|
48
|
+
const action = summaryActions.get(review.id);
|
|
49
|
+
if (!action || ruleHides(action, "review-summary", confirmed.has(review.id)))
|
|
50
|
+
continue;
|
|
51
|
+
if (unconfirmed.has(review.id) ||
|
|
52
|
+
classifyItem(review.id, review.body, seen) !== "unchanged" ||
|
|
53
|
+
canMinimize(review))
|
|
54
|
+
actionable += 1;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (review.state === "APPROVED") {
|
|
58
|
+
if ((minimizeApprovals &&
|
|
59
|
+
!review.isMinimized &&
|
|
60
|
+
(classifyItem(review.id, review.body, seen) !== "unchanged" || canMinimize(review))) ||
|
|
61
|
+
(minimizeSupersededApprovals && supersededApprovalIds.has(review.id) && canMinimize(review)))
|
|
62
|
+
actionable += 1;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (review.state !== "CHANGES_REQUESTED")
|
|
66
|
+
continue;
|
|
67
|
+
const login = review.author?.login.toLowerCase();
|
|
68
|
+
if (login && latestStateByAuthor.get(login) === "APPROVED")
|
|
69
|
+
continue;
|
|
70
|
+
if (ruleHides(summaryRuleAction(rules, "changes-requested", review), "changes-requested", false))
|
|
71
|
+
continue;
|
|
72
|
+
const author = authorOf(review.author);
|
|
73
|
+
const isBot = !isHumanAuthor(author) || isConfiguredBotAuthor(author, bots);
|
|
74
|
+
if (!isBot ||
|
|
75
|
+
(canGenerateGithubMutation(viewerCanAdminister, "dismiss") &&
|
|
76
|
+
!mutationWasDenied(review.id, review.body, seen)) ||
|
|
77
|
+
classifyItem(review.id, review.body, seen) !== "unchanged")
|
|
78
|
+
actionable += 1;
|
|
79
|
+
}
|
|
80
|
+
return actionable;
|
|
81
|
+
}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { normalizeBotUsernames } from "../comments/authors.mjs";
|
|
2
2
|
import { loadClassifyRules } from "../classify/loader.mjs";
|
|
3
3
|
import { loadConfig } from "../config/load.mjs";
|
|
4
4
|
import { getEffectiveCwd } from "../execution-context.mjs";
|
|
5
|
-
import { classifyItem
|
|
5
|
+
import { classifyItem } from "../state/seen-comments.mjs";
|
|
6
6
|
import { threadEndedByShepherd } from "../comments/marker.mjs";
|
|
7
7
|
import { threadTranscriptBodies } from "../threads/transcript.mjs";
|
|
8
|
-
import { canGenerateGithubMutation } from "./mutation-policy.mjs";
|
|
9
8
|
import { applySummaryRuleAutoResolve, } from "./poll-summary-rule-auto-resolve.mjs";
|
|
10
9
|
import { countCommentWork, repeatingThreadIds } from "./poll-summary-review-parity.mjs";
|
|
11
10
|
import { ruleHides, summaryRuleAction } from "./poll-summary-rule-items.mjs";
|
|
12
|
-
|
|
13
|
-
login: author?.login ?? "",
|
|
14
|
-
authorType: normalizeAuthorType(author?.__typename, author?.login),
|
|
15
|
-
});
|
|
11
|
+
import { countActionableSummaryReviews } from "./poll-summary-review-helpers.mjs";
|
|
16
12
|
/**
|
|
17
13
|
* Count the review work a compact row routes to the full check. With `autoResolveKey` and
|
|
18
14
|
* `actions.auto-minimize-suppressed` on, rule-driven auto-resolve runs first, exactly as in the
|
|
@@ -37,21 +33,31 @@ export async function evaluatePollSummaryReview(raw, seen, viewerCanAdminister,
|
|
|
37
33
|
if (!comment.isMinimized)
|
|
38
34
|
actions.comments.set(comment.id, summaryRuleAction(rules, "pr-comment", comment));
|
|
39
35
|
for (const review of raw.reviews.nodes)
|
|
40
|
-
if (review.state === "COMMENTED"
|
|
36
|
+
if ((review.state === "COMMENTED" || review.state === "DISMISSED") &&
|
|
37
|
+
review.body.trim() !== "" &&
|
|
38
|
+
!review.isMinimized)
|
|
41
39
|
actions.summaries.set(review.id, summaryRuleAction(rules, "review-summary", review));
|
|
42
40
|
const threadView = raw.reviewThreads.nodes.map((thread) => {
|
|
43
41
|
const truncated = thread.comments.pageInfo.hasPreviousPage;
|
|
44
42
|
if (truncated)
|
|
45
43
|
incomplete = true;
|
|
46
44
|
const root = thread.comments.nodes[0];
|
|
47
|
-
const
|
|
45
|
+
const path = thread.path ?? root?.path ?? null;
|
|
46
|
+
const replies = thread.comments.nodes
|
|
47
|
+
.slice(1)
|
|
48
|
+
.filter((reply) => !summaryRuleAction(rules, "review-thread-reply", reply, reply.id, path, reply.body, thread.id).suppress);
|
|
49
|
+
const visibleComments = root ? [root, ...replies] : [];
|
|
50
|
+
const filteredThread = visibleComments.length === thread.comments.nodes.length
|
|
51
|
+
? thread
|
|
52
|
+
: { ...thread, comments: { ...thread.comments, nodes: visibleComments } };
|
|
53
|
+
const transcript = threadTranscriptBodies(visibleComments.map((c) => c.body));
|
|
48
54
|
// The window's last comment is the thread's last only when nothing lies beyond it.
|
|
49
55
|
const ended = thread.isResolved === true &&
|
|
50
56
|
!truncated &&
|
|
51
|
-
threadEndedByShepherd({ body: root?.body ?? "", comments:
|
|
57
|
+
threadEndedByShepherd({ body: root?.body ?? "", comments: visibleComments });
|
|
52
58
|
if (!ended)
|
|
53
|
-
actions.threads.set(thread.id, summaryRuleAction(rules, "review-thread", root, thread.id,
|
|
54
|
-
return { thread, truncated, root, transcript, ended };
|
|
59
|
+
actions.threads.set(thread.id, summaryRuleAction(rules, "review-thread", root, thread.id, path, root?.body ?? ""));
|
|
60
|
+
return { thread: filteredThread, truncated, root, transcript, ended };
|
|
55
61
|
});
|
|
56
62
|
const handled = autoResolveKey && config.actions["auto-minimize-suppressed"]
|
|
57
63
|
? await applySummaryRuleAutoResolve({ raw, actions, seen, key: autoResolveKey })
|
|
@@ -61,40 +67,25 @@ export async function evaluatePollSummaryReview(raw, seen, viewerCanAdminister,
|
|
|
61
67
|
const action = actions.comments.get(comment.id);
|
|
62
68
|
return action !== undefined && !ruleHides(action, "pr-comment", confirmed.has(comment.id));
|
|
63
69
|
}), unconfirmed, seen, config.iterate["minimize-comments"], bots);
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
continue;
|
|
84
|
-
const login = review.author?.login.toLowerCase();
|
|
85
|
-
if (login && latestStateByAuthor.get(login) === "APPROVED")
|
|
86
|
-
continue;
|
|
87
|
-
if (ruleHides(summaryRuleAction(rules, "changes-requested", review), "changes-requested", false))
|
|
88
|
-
continue;
|
|
89
|
-
const author = authorOf(review.author);
|
|
90
|
-
const isBot = !isHumanAuthor(author) || isConfiguredBotAuthor(author, bots);
|
|
91
|
-
// The full check counts a human changes-requested review whether or not it was seen.
|
|
92
|
-
if (!isBot ||
|
|
93
|
-
(canGenerateGithubMutation(viewerCanAdminister, "dismiss") &&
|
|
94
|
-
!mutationWasDenied(review.id, review.body, seen)) ||
|
|
95
|
-
classifyItem(review.id, review.body, seen) !== "unchanged")
|
|
96
|
-
actionable += 1;
|
|
97
|
-
}
|
|
70
|
+
const blockedReviewIds = new Set(threadView.flatMap(({ thread, root }) => thread.isResolved === false &&
|
|
71
|
+
!confirmed.has(thread.id) &&
|
|
72
|
+
root?.pullRequestReview?.id !== undefined
|
|
73
|
+
? [root.pullRequestReview.id]
|
|
74
|
+
: []));
|
|
75
|
+
actionable += countActionableSummaryReviews({
|
|
76
|
+
raw,
|
|
77
|
+
summaryActions: actions.summaries,
|
|
78
|
+
rules,
|
|
79
|
+
confirmed,
|
|
80
|
+
unconfirmed,
|
|
81
|
+
blockedReviewIds,
|
|
82
|
+
seen,
|
|
83
|
+
viewerCanAdminister,
|
|
84
|
+
minimizeApprovals: config.iterate["minimize-approvals"],
|
|
85
|
+
minimizeSupersededApprovals: config.iterate["minimize-superseded-approvals"],
|
|
86
|
+
minimizeComments: config.iterate["minimize-comments"],
|
|
87
|
+
bots,
|
|
88
|
+
});
|
|
98
89
|
const repeating = repeatingThreadIds(threadView, seen, bots, config.iterate["resolve-other-human-threads"]);
|
|
99
90
|
for (const { thread, truncated, transcript, ended } of threadView) {
|
|
100
91
|
const action = actions.threads.get(thread.id);
|
|
@@ -82,6 +82,7 @@ export async function applySummaryRuleAutoResolve(input) {
|
|
|
82
82
|
const partition = {
|
|
83
83
|
suppressedCommentIds: new Set(comments.map((item) => item.id)),
|
|
84
84
|
suppressedThreadIds: new Set(threads.map((item) => item.id)),
|
|
85
|
+
suppressedThreadReplyIds: new Set(),
|
|
85
86
|
suppressedReviewSummaryIds: new Set(summaries.map((item) => item.id)),
|
|
86
87
|
suppressedChangesRequestedIds: new Set(),
|
|
87
88
|
ruleAutoResolveCommentIds: comments.map((item) => item.id),
|
|
@@ -11,7 +11,7 @@ export interface RuleSource {
|
|
|
11
11
|
path?: string | null;
|
|
12
12
|
}
|
|
13
13
|
/** The rule action for one compact item, built like the full check builds its rule items. */
|
|
14
|
-
export declare function summaryRuleAction(rules: Rules, kind: ClassifyItem["kind"], raw: RuleSource | undefined, id?: string, path?: string | null, body?: string): ClassifyAction;
|
|
14
|
+
export declare function summaryRuleAction(rules: Rules, kind: ClassifyItem["kind"], raw: RuleSource | undefined, id?: string, path?: string | null, body?: string, threadId?: string): ClassifyAction;
|
|
15
15
|
/**
|
|
16
16
|
* An auto-resolve match is hidden only once its mutation is confirmed or the item is already
|
|
17
17
|
* resolved; until then it stays visible so the full check can run or surface it.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { applyRules } from "../classify/apply.mjs";
|
|
2
2
|
import { normalizeAuthorType } from "../comments/authors.mjs";
|
|
3
3
|
/** The rule action for one compact item, built like the full check builds its rule items. */
|
|
4
|
-
export function summaryRuleAction(rules, kind, raw, id = raw?.id ?? "unknown", path, body = raw?.body ?? "") {
|
|
4
|
+
export function summaryRuleAction(rules, kind, raw, id = raw?.id ?? "unknown", path, body = raw?.body ?? "", threadId) {
|
|
5
5
|
const item = {
|
|
6
6
|
kind,
|
|
7
7
|
id,
|
|
@@ -14,7 +14,8 @@ export function summaryRuleAction(rules, kind, raw, id = raw?.id ?? "unknown", p
|
|
|
14
14
|
...(kind !== "review-thread" && kind !== "changes-requested" && raw?.url
|
|
15
15
|
? { url: raw.url }
|
|
16
16
|
: {}),
|
|
17
|
-
...(kind === "review-thread" && { path }),
|
|
17
|
+
...((kind === "review-thread" || kind === "review-thread-reply") && { path }),
|
|
18
|
+
...(kind === "review-thread-reply" && threadId !== undefined && { threadId }),
|
|
18
19
|
};
|
|
19
20
|
return applyRules(rules, item);
|
|
20
21
|
}
|
|
@@ -8,6 +8,7 @@ import { mergeStartupFailureChecks } from "../checks/startup-failures.mjs";
|
|
|
8
8
|
import { parseCheckNodes } from "./batch-parse-checks.mjs";
|
|
9
9
|
import { parseBranchRules } from "./batch-parsers-rules.mjs";
|
|
10
10
|
import { isReviewStale } from "./batch-parser-helpers.mjs";
|
|
11
|
+
import { findSupersededApprovalIds } from "../comments/superseded-approvals.mjs";
|
|
11
12
|
import { readRest as rest, restRepoPath, restObject, restString } from "./rest-reader-core.mjs";
|
|
12
13
|
import { restLatestReviews, restPendingReviews } from "./rest-review-read.mjs";
|
|
13
14
|
import { headFreshAtUnix } from "./head-freshness.mjs";
|
|
@@ -73,11 +74,34 @@ export async function readRestSnapshot(pull, repo, context, knownViewerLogin) {
|
|
|
73
74
|
return mapped;
|
|
74
75
|
}),
|
|
75
76
|
reviewSummaries: feedback.reviews
|
|
76
|
-
.filter((review) => review.state === "COMMENTED" && review.body?.trim())
|
|
77
|
+
.filter((review) => (review.state === "COMMENTED" || review.state === "DISMISSED") && review.body?.trim())
|
|
77
78
|
.map(restReviewToReview),
|
|
78
79
|
approvedReviews: feedback.reviews
|
|
79
80
|
.filter((review) => review.state === "APPROVED")
|
|
80
81
|
.map(restReviewToReview),
|
|
82
|
+
...(() => {
|
|
83
|
+
const supersededApprovalIds = [
|
|
84
|
+
...findSupersededApprovalIds({
|
|
85
|
+
reviews: feedback.reviews
|
|
86
|
+
.filter((review) => review.state === "APPROVED" ||
|
|
87
|
+
review.state === "CHANGES_REQUESTED" ||
|
|
88
|
+
review.state === "DISMISSED" ||
|
|
89
|
+
review.state === "COMMENTED")
|
|
90
|
+
.map((review) => {
|
|
91
|
+
const mapped = restReviewToReview(review);
|
|
92
|
+
return {
|
|
93
|
+
id: mapped.id,
|
|
94
|
+
author: mapped.author,
|
|
95
|
+
state: review.state,
|
|
96
|
+
body: mapped.body,
|
|
97
|
+
createdAtUnix: mapped.createdAtUnix,
|
|
98
|
+
};
|
|
99
|
+
}),
|
|
100
|
+
latestReviews: [...latestReviews.values()],
|
|
101
|
+
}),
|
|
102
|
+
];
|
|
103
|
+
return supersededApprovalIds.length > 0 ? { supersededApprovalIds } : {};
|
|
104
|
+
})(),
|
|
81
105
|
checks: mergeStartupFailureChecks(parseCheckNodes(checks.nodes), checks.suites.flatMap((suite) => {
|
|
82
106
|
const run = checks.workflowRuns.find((run) => run.check_suite_id === suite.id);
|
|
83
107
|
if (suite.conclusion?.toUpperCase() !== "STARTUP_FAILURE" || !run)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type RepoInfo } from "./client.mts";
|
|
2
|
+
/** True when a node ID identifies a GitHub PullRequestReview (next-gen `PRR_` or legacy base64). */
|
|
3
|
+
export declare function isReviewNodeId(id: string): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Re-check only the specific thread IDs that local state last saw as unresolved, in case a
|
|
6
|
+
* reviewer or human resolved them outside `pr-shepherd`. Returns the subset still unresolved.
|
|
7
|
+
*/
|
|
8
|
+
export declare function checkThreadsStillUnresolved(pr: number, repo: RepoInfo, threadIds: readonly string[]): Promise<Set<string>>;
|
|
9
|
+
/**
|
|
10
|
+
* Cold-cache fallback when no local `unresolvedInlineThreadIds` record exists for a review:
|
|
11
|
+
* scan the PR's review threads and return `reviewId -> unresolvedThreadIds[]`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function findUnresolvedThreadsByReviewId(pr: number, repo: RepoInfo, reviewIds: readonly string[]): Promise<Map<string, string[]>>;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { graphqlWithRateLimit } from "./client.mjs";
|
|
2
|
+
import { githubOperation } from "./transport.mjs";
|
|
3
|
+
import { readRestFeedback } from "./rest-feedback-read.mjs";
|
|
4
|
+
import { resolveGraphqlThreadId, resolveRestIdentity } from "./rest-identities.mjs";
|
|
5
|
+
import { chunksOf } from "../util/chunks.mjs";
|
|
6
|
+
const REVIEW_THREADS_QUERY = `query ReviewUnresolvedThreads($owner: String!, $repo: String!, $pr: Int!, $cursor: String) {
|
|
7
|
+
_shepherdRateLimit: rateLimit { cost limit nodeCount remaining resetAt used }
|
|
8
|
+
repository(owner: $owner, name: $repo) {
|
|
9
|
+
pullRequest(number: $pr) {
|
|
10
|
+
reviewThreads(first: 100, after: $cursor) {
|
|
11
|
+
pageInfo { hasNextPage endCursor }
|
|
12
|
+
nodes {
|
|
13
|
+
id
|
|
14
|
+
isResolved
|
|
15
|
+
comments(first: 1) {
|
|
16
|
+
nodes {
|
|
17
|
+
pullRequestReview { id }
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}`;
|
|
25
|
+
const THREAD_STATES_QUERY = `query ReviewThreadStates($ids: [ID!]!) {
|
|
26
|
+
_shepherdRateLimit: rateLimit { cost limit nodeCount remaining resetAt used }
|
|
27
|
+
nodes(ids: $ids) {
|
|
28
|
+
... on PullRequestReviewThread {
|
|
29
|
+
id
|
|
30
|
+
isResolved
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}`;
|
|
34
|
+
/** True when a node ID identifies a GitHub PullRequestReview (next-gen `PRR_` or legacy base64). */
|
|
35
|
+
export function isReviewNodeId(id) {
|
|
36
|
+
if (id.startsWith("PRR_"))
|
|
37
|
+
return true;
|
|
38
|
+
if (id.length < 24 || !/^[A-Za-z0-9+/=]+$/.test(id))
|
|
39
|
+
return false;
|
|
40
|
+
return Buffer.from(id, "base64").toString("utf8").includes("PullRequestReview");
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Re-check only the specific thread IDs that local state last saw as unresolved, in case a
|
|
44
|
+
* reviewer or human resolved them outside `pr-shepherd`. Returns the subset still unresolved.
|
|
45
|
+
*/
|
|
46
|
+
export async function checkThreadsStillUnresolved(pr, repo, threadIds) {
|
|
47
|
+
const unique = [...new Set(threadIds)];
|
|
48
|
+
const unresolved = new Set();
|
|
49
|
+
if (unique.length === 0)
|
|
50
|
+
return unresolved;
|
|
51
|
+
await githubOperation("ReviewThreadStates", async () => {
|
|
52
|
+
const gqlToOriginal = new Map();
|
|
53
|
+
for (const id of unique) {
|
|
54
|
+
try {
|
|
55
|
+
// eslint-disable-next-line no-await-in-loop
|
|
56
|
+
const gqlId = await resolveGraphqlThreadId(id);
|
|
57
|
+
const list = gqlToOriginal.get(gqlId) ?? [];
|
|
58
|
+
list.push(id);
|
|
59
|
+
gqlToOriginal.set(gqlId, list);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
unresolved.add(id);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
for (const batch of chunksOf([...gqlToOriginal.keys()], 100)) {
|
|
66
|
+
// eslint-disable-next-line no-await-in-loop
|
|
67
|
+
const res = await graphqlWithRateLimit(THREAD_STATES_QUERY, { ids: batch });
|
|
68
|
+
const byId = new Map(res.data.nodes.flatMap((node) => (node?.id ? [[node.id, node.isResolved]] : [])));
|
|
69
|
+
for (const gqlId of batch) {
|
|
70
|
+
if (byId.get(gqlId) !== true) {
|
|
71
|
+
for (const origId of gqlToOriginal.get(gqlId))
|
|
72
|
+
unresolved.add(origId);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}, async () => {
|
|
77
|
+
const feedback = await readRestFeedback(pr, repo);
|
|
78
|
+
const resolvedIds = new Set();
|
|
79
|
+
for (const thread of feedback.threads) {
|
|
80
|
+
if (thread.isResolved !== true)
|
|
81
|
+
continue;
|
|
82
|
+
resolvedIds.add(thread.id);
|
|
83
|
+
try {
|
|
84
|
+
// eslint-disable-next-line no-await-in-loop
|
|
85
|
+
const entry = await resolveRestIdentity(thread.id, "thread");
|
|
86
|
+
if (entry.graphqlThreadId)
|
|
87
|
+
resolvedIds.add(entry.graphqlThreadId);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// No recorded GraphQL alias for this REST thread; match by REST thread ID only.
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
for (const id of unique) {
|
|
94
|
+
if (!resolvedIds.has(id))
|
|
95
|
+
unresolved.add(id);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return unresolved;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Cold-cache fallback when no local `unresolvedInlineThreadIds` record exists for a review:
|
|
102
|
+
* scan the PR's review threads and return `reviewId -> unresolvedThreadIds[]`.
|
|
103
|
+
*/
|
|
104
|
+
export async function findUnresolvedThreadsByReviewId(pr, repo, reviewIds) {
|
|
105
|
+
const wanted = new Set(reviewIds);
|
|
106
|
+
const blocked = new Map();
|
|
107
|
+
if (wanted.size === 0)
|
|
108
|
+
return blocked;
|
|
109
|
+
const record = (reviewId, threadId) => {
|
|
110
|
+
if (!reviewId || !wanted.has(reviewId))
|
|
111
|
+
return;
|
|
112
|
+
const list = blocked.get(reviewId) ?? [];
|
|
113
|
+
if (!list.includes(threadId))
|
|
114
|
+
list.push(threadId);
|
|
115
|
+
blocked.set(reviewId, list);
|
|
116
|
+
};
|
|
117
|
+
await githubOperation("ReviewUnresolvedThreads", async () => {
|
|
118
|
+
let cursor = null;
|
|
119
|
+
for (;;) {
|
|
120
|
+
// eslint-disable-next-line no-await-in-loop
|
|
121
|
+
const res = await graphqlWithRateLimit(REVIEW_THREADS_QUERY, {
|
|
122
|
+
owner: repo.owner,
|
|
123
|
+
repo: repo.name,
|
|
124
|
+
pr,
|
|
125
|
+
cursor,
|
|
126
|
+
});
|
|
127
|
+
const connection = res.data.repository?.pullRequest?.reviewThreads;
|
|
128
|
+
if (!connection)
|
|
129
|
+
break;
|
|
130
|
+
for (const thread of connection.nodes) {
|
|
131
|
+
if (!thread || thread.isResolved !== false)
|
|
132
|
+
continue;
|
|
133
|
+
const reviewId = thread.comments.nodes[0]?.pullRequestReview?.id;
|
|
134
|
+
record(reviewId, thread.id);
|
|
135
|
+
}
|
|
136
|
+
if (!connection.pageInfo.hasNextPage)
|
|
137
|
+
break;
|
|
138
|
+
const nextCursor = connection.pageInfo.endCursor;
|
|
139
|
+
if (!nextCursor || nextCursor === cursor) {
|
|
140
|
+
throw new Error("Review thread pagination returned hasNextPage without advancing endCursor");
|
|
141
|
+
}
|
|
142
|
+
cursor = nextCursor;
|
|
143
|
+
}
|
|
144
|
+
}, async () => {
|
|
145
|
+
const feedback = await readRestFeedback(pr, repo);
|
|
146
|
+
for (const thread of feedback.threads) {
|
|
147
|
+
if (thread.isResolved !== true)
|
|
148
|
+
record(thread.reviewId, thread.id);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
return blocked;
|
|
152
|
+
}
|
|
@@ -246,6 +246,8 @@ export function batchResponseFromSummary(layer, source, runs) {
|
|
|
246
246
|
pageInfo: firstPage,
|
|
247
247
|
nodes: reviewsIn(layer, "CHANGES_REQUESTED").map((review) => ({
|
|
248
248
|
id: review.id,
|
|
249
|
+
isMinimized: review.isMinimized === true,
|
|
250
|
+
viewerCanMinimize: review.viewerCanMinimize === true,
|
|
249
251
|
authorAssociation: review.authorAssociation,
|
|
250
252
|
author: review.author,
|
|
251
253
|
body: review.body,
|
|
@@ -255,7 +257,9 @@ export function batchResponseFromSummary(layer, source, runs) {
|
|
|
255
257
|
},
|
|
256
258
|
reviewSummaries: {
|
|
257
259
|
pageInfo: firstPage,
|
|
258
|
-
nodes:
|
|
260
|
+
nodes: layer.reviews.nodes
|
|
261
|
+
.filter((review) => review.state === "COMMENTED" || review.state === "DISMISSED")
|
|
262
|
+
.map((review) => ({ ...reviewSummary(review), state: review.state })),
|
|
259
263
|
},
|
|
260
264
|
allReviews: {
|
|
261
265
|
totalCount: layer.reviews.totalCount,
|
|
@@ -51,7 +51,9 @@ export declare function markSeen(key: StateKey, id: string, body: string): Promi
|
|
|
51
51
|
/** A definite permission denial suppresses generated retries until the feedback changes. */
|
|
52
52
|
export declare function markMutationDenied(key: StateKey, id: string, body?: string): Promise<void>;
|
|
53
53
|
export declare function mutationWasDenied(id: string, body: string, map: Map<string, SeenMarker>): boolean;
|
|
54
|
-
export declare function markReviewInlineThreads(key: StateKey, reviewId: string, inlineThreadIds: readonly string[]): Promise<void>;
|
|
54
|
+
export declare function markReviewInlineThreads(key: StateKey, reviewId: string, inlineThreadIds: readonly string[], unresolvedInlineThreadIds?: readonly string[]): Promise<void>;
|
|
55
|
+
export declare function markReviewUnresolvedThreads(key: StateKey, reviewId: string, unresolvedInlineThreadIds: readonly string[]): Promise<void>;
|
|
56
|
+
export declare function pruneResolvedReviewThreads(key: StateKey, resolvedThreadIds: readonly string[]): Promise<void>;
|
|
55
57
|
/**
|
|
56
58
|
* Write a marker after Shepherd successfully replies to a review thread.
|
|
57
59
|
*
|
|
@@ -31,7 +31,8 @@ export function classifyItem(id, body, map) {
|
|
|
31
31
|
}
|
|
32
32
|
if (typeof m.bodyHash === "string" && m.bodyHash !== currentHash)
|
|
33
33
|
return "edited";
|
|
34
|
-
if (m.bodyHash === undefined &&
|
|
34
|
+
if (m.bodyHash === undefined &&
|
|
35
|
+
(Array.isArray(m.inlineThreadIds) || Array.isArray(m.unresolvedInlineThreadIds)))
|
|
35
36
|
return "new";
|
|
36
37
|
return "unchanged";
|
|
37
38
|
}
|
|
@@ -117,11 +118,36 @@ export async function markMutationDenied(key, id, body) {
|
|
|
117
118
|
export function mutationWasDenied(id, body, map) {
|
|
118
119
|
return map.get(id)?.deniedMutationBodyHash === hashBody(body);
|
|
119
120
|
}
|
|
120
|
-
export async function markReviewInlineThreads(key, reviewId, inlineThreadIds) {
|
|
121
|
+
export async function markReviewInlineThreads(key, reviewId, inlineThreadIds, unresolvedInlineThreadIds) {
|
|
121
122
|
await writeSeenMarker(key, reviewId, {
|
|
122
123
|
inlineThreadIds: [...new Set(inlineThreadIds)].sort((a, b) => a.localeCompare(b)),
|
|
124
|
+
...(unresolvedInlineThreadIds !== undefined && {
|
|
125
|
+
unresolvedInlineThreadIds: [...new Set(unresolvedInlineThreadIds)].sort((a, b) => a.localeCompare(b)),
|
|
126
|
+
}),
|
|
123
127
|
});
|
|
124
128
|
}
|
|
129
|
+
export async function markReviewUnresolvedThreads(key, reviewId, unresolvedInlineThreadIds) {
|
|
130
|
+
await writeSeenMarker(key, reviewId, {
|
|
131
|
+
unresolvedInlineThreadIds: [...new Set(unresolvedInlineThreadIds)].sort((a, b) => a.localeCompare(b)),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
export async function pruneResolvedReviewThreads(key, resolvedThreadIds) {
|
|
135
|
+
if (resolvedThreadIds.length === 0)
|
|
136
|
+
return;
|
|
137
|
+
const resolved = new Set(resolvedThreadIds);
|
|
138
|
+
const seen = await loadSeenMap(key);
|
|
139
|
+
const updates = [];
|
|
140
|
+
for (const [reviewId, marker] of seen) {
|
|
141
|
+
if (!Array.isArray(marker.unresolvedInlineThreadIds))
|
|
142
|
+
continue;
|
|
143
|
+
const current = marker.unresolvedInlineThreadIds.filter((id) => typeof id === "string");
|
|
144
|
+
const remaining = current.filter((id) => !resolved.has(id));
|
|
145
|
+
if (remaining.length !== current.length) {
|
|
146
|
+
updates.push(markReviewUnresolvedThreads(key, reviewId, remaining));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
await Promise.allSettled(updates);
|
|
150
|
+
}
|
|
125
151
|
/**
|
|
126
152
|
* Write a marker after Shepherd successfully replies to a review thread.
|
|
127
153
|
*
|
package/bin/types/escalate.d.mts
CHANGED
package/bin/types/github.d.mts
CHANGED
|
@@ -149,13 +149,17 @@ export interface Review {
|
|
|
149
149
|
author: string;
|
|
150
150
|
authorType: AuthorType;
|
|
151
151
|
authorAssociation?: CommentAuthorAssociation;
|
|
152
|
-
/** Present
|
|
152
|
+
/** Present when GitHub reports the review is already minimized. */
|
|
153
|
+
isMinimized?: boolean;
|
|
154
|
+
/** Present for minimizable reviews; false for non-minimizable review rows. */
|
|
153
155
|
viewerCanMinimize?: boolean;
|
|
154
156
|
body: string;
|
|
155
157
|
createdAtUnix?: number;
|
|
156
158
|
edited?: boolean;
|
|
157
159
|
/** True for bot CR re-surfaced after first look (body unchanged). Terse render. */
|
|
158
160
|
staleBotCr?: boolean;
|
|
161
|
+
/** True when a re-surfaced bot CR is still held back from dismissal by unresolved inline threads. */
|
|
162
|
+
pendingInlineThreads?: boolean;
|
|
159
163
|
/** Commit OID the review was made against, when available from GraphQL. */
|
|
160
164
|
commitOid?: string;
|
|
161
165
|
/** PR head OID, set on changes-requested reviews only when `commitOid` differs from it. Raw data, not a staleness verdict. */
|
|
@@ -241,6 +245,8 @@ export interface BatchPrData extends BatchPrMergeFields {
|
|
|
241
245
|
changesRequestedReviews: Review[];
|
|
242
246
|
reviewSummaries: Review[];
|
|
243
247
|
approvedReviews: Review[];
|
|
248
|
+
/** Internal: APPROVED review IDs superseded by a newer review from the same author (including already-minimized reviews). */
|
|
249
|
+
supersededApprovalIds?: string[];
|
|
244
250
|
checks: CheckRun[];
|
|
245
251
|
mergeQueueChecks?: CheckRun[];
|
|
246
252
|
mergeQueueChecksIncomplete?: true;
|
package/bin/types/iterate.d.mts
CHANGED
|
@@ -138,10 +138,12 @@ interface TriageDetails {
|
|
|
138
138
|
/** Checks still unstarted after the CI-start stall timeout, on the one investigation tick. Omitted otherwise. */
|
|
139
139
|
stalledChecks?: AgentStalledCheck[];
|
|
140
140
|
changesRequestedReviews: Review[];
|
|
141
|
-
/** Pre-built apply command. Run after committing and pushing. */
|
|
141
|
+
/** Pre-built apply command for inline thread replies/resolves and PR-level comments. Run after committing and pushing. */
|
|
142
142
|
resolveCommand: ResolveCommand;
|
|
143
|
-
/** When present, run this command first (no SHA substitution needed) for standalone thread resolves and comment minimization, independent of any push. */
|
|
143
|
+
/** When present, run this command first (no SHA substitution needed) for standalone thread resolves and PR-comment minimization, independent of any push. */
|
|
144
144
|
resolveOnlyCommand?: ResolveCommand;
|
|
145
|
+
/** Separate command to dismiss and/or hide reviews (`CHANGES_REQUESTED`, `COMMENTED`/`DISMISSED`, and eligible `APPROVED` reviews) whose inline items are all resolved. */
|
|
146
|
+
dismissReviewsCommand?: ResolveCommand;
|
|
145
147
|
/** Ordered steps for the model to follow. */
|
|
146
148
|
instructions: string[];
|
|
147
149
|
/** Requeue command emitted after merge-group remediation. */
|