co-maintainer 0.6.10 → 0.6.11
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/dist/package.json +1 -1
- package/dist/src/github/permissions.js +1 -1
- package/dist/src/github/write_access.d.ts +7 -0
- package/dist/src/github/write_access.js +12 -0
- package/dist/src/review/carry_over.d.ts +2 -0
- package/dist/src/review/carry_over.js +33 -26
- package/dist/src/services/review.d.ts +20 -3
- package/dist/src/services/review.js +112 -39
- package/dist/src/services/watch_comments.js +1 -14
- package/dist/src/services/webhook.js +1 -5
- package/package.json +1 -1
package/dist/package.json
CHANGED
|
@@ -118,7 +118,7 @@ export const ENDPOINTS = [
|
|
|
118
118
|
permission: "metadata",
|
|
119
119
|
level: "read",
|
|
120
120
|
identities: APP_ONLY,
|
|
121
|
-
feature: "Check a commenter
|
|
121
|
+
feature: "Check a commenter has write access before acting on a comment",
|
|
122
122
|
},
|
|
123
123
|
{
|
|
124
124
|
method: "PATCH",
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Who may steer co-maintainer from a comment. A webhook's
|
|
2
|
+
* author_association is only a first filter: MEMBER means a member of the
|
|
3
|
+
* organization and COLLABORATOR may be read-only, so the repository
|
|
4
|
+
* permission is asked from GitHub. */
|
|
5
|
+
import type { GitHubClient } from "../types.ts";
|
|
6
|
+
/** True when `login` can write to `repo`. Any error counts as no. */
|
|
7
|
+
export declare function hasWriteAccess(client: GitHubClient, repo: string, login: string | null | undefined): Promise<boolean>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** True when `login` can write to `repo`. Any error counts as no. */
|
|
2
|
+
export async function hasWriteAccess(client, repo, login) {
|
|
3
|
+
if (!login)
|
|
4
|
+
return false;
|
|
5
|
+
try {
|
|
6
|
+
const result = await client.request(`repos/${repo}/collaborators/${encodeURIComponent(login)}/permission`);
|
|
7
|
+
return ["admin", "maintain", "write"].includes(String(result.role_name ?? result.permission ?? ""));
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -10,6 +10,8 @@ export type StoredFinding = {
|
|
|
10
10
|
anchorText: string | null;
|
|
11
11
|
severity: string;
|
|
12
12
|
firstSeenReviewId: string | null;
|
|
13
|
+
/** What maintainers wrote on the finding's inline thread, oldest first. */
|
|
14
|
+
replies?: string[];
|
|
13
15
|
};
|
|
14
16
|
export type CarryPrevious = {
|
|
15
17
|
files: RevisionFile[];
|
|
@@ -161,42 +161,40 @@ const VERIFY_HINT = {
|
|
|
161
161
|
file_removed: "",
|
|
162
162
|
unverifiable: "",
|
|
163
163
|
verify_guide_changed: "review guide was rebuilt",
|
|
164
|
-
unchanged: "",
|
|
164
|
+
unchanged: "file unchanged since the last review, the fix may be in another file",
|
|
165
165
|
verify_present: "still present in changed code",
|
|
166
166
|
verify_likely_fixed: "anchored code no longer found",
|
|
167
167
|
verify_unlocated: "could not locate",
|
|
168
168
|
};
|
|
169
169
|
export function buildCarryPromptSection(items, current) {
|
|
170
170
|
const verify = [];
|
|
171
|
-
const unchanged = [];
|
|
172
171
|
let index = 0;
|
|
173
172
|
for (const item of items) {
|
|
174
|
-
if (item.class === "file_reverted" ||
|
|
173
|
+
if (item.class === "file_reverted" ||
|
|
174
|
+
item.class === "file_removed" ||
|
|
175
|
+
item.class === "unverifiable") {
|
|
175
176
|
continue;
|
|
176
177
|
}
|
|
178
|
+
index++;
|
|
179
|
+
const label = `F${index}`;
|
|
180
|
+
item.promptId = label;
|
|
181
|
+
let from = item.lineFrom;
|
|
182
|
+
let to = item.lineTo;
|
|
177
183
|
if (item.class === "unchanged") {
|
|
178
184
|
const file = current.files.find((f) => normalizePath(f.path) === normalizePath(item.targetPath ?? ""));
|
|
179
185
|
const relocated = file
|
|
180
186
|
? relocate(item.finding.anchorText, item.lineFrom, file.patch)
|
|
181
187
|
: null;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
unchanged.push(`- ${item.targetPath}:${from}${to !== from ? `-${to}` : ""} · ${item.finding.title}`);
|
|
185
|
-
continue;
|
|
188
|
+
from = relocated?.from ?? from;
|
|
189
|
+
to = relocated?.to ?? to;
|
|
186
190
|
}
|
|
187
|
-
if (item.class === "unverifiable") {
|
|
188
|
-
continue;
|
|
189
|
-
}
|
|
190
|
-
index++;
|
|
191
|
-
const label = `F${index}`;
|
|
192
|
-
item.promptId = label;
|
|
193
191
|
const loc = item.targetPath
|
|
194
|
-
? `${item.targetPath}:${
|
|
192
|
+
? `${item.targetPath}:${from}${to !== from ? `-${to}` : ""}`
|
|
195
193
|
: "";
|
|
196
194
|
const body = item.finding.bodyMd.slice(0, 600);
|
|
197
|
-
verify.push(`${label} · ${VERIFY_HINT[item.class]} · ${loc}\n${item.finding.title}\n${body}`);
|
|
195
|
+
verify.push(`${label} · ${VERIFY_HINT[item.class]} · ${loc}\n${item.finding.title}\n${body}${repliesBlock(item.finding.replies)}`);
|
|
198
196
|
}
|
|
199
|
-
if (verify.length === 0
|
|
197
|
+
if (verify.length === 0)
|
|
200
198
|
return "";
|
|
201
199
|
const lines = [
|
|
202
200
|
"PREVIOUS FINDINGS (this run has two separate jobs):",
|
|
@@ -205,21 +203,28 @@ export function buildCarryPromptSection(items, current) {
|
|
|
205
203
|
" list below shorten or replace that scan. A changed file can contain a",
|
|
206
204
|
" new finding even when a previous finding already covers its location.",
|
|
207
205
|
"2. For each entry under VERIFY, decide whether the code in the DIFF still",
|
|
208
|
-
" has that problem.
|
|
206
|
+
" has that problem. An entry whose file is unchanged stays open unless",
|
|
207
|
+
" the DIFF fixes it in another file. A maintainer reply that shows the",
|
|
208
|
+
" finding is wrong is a reason to close it, an unexplained objection is",
|
|
209
|
+
" not. Report every decision in a final section headed",
|
|
209
210
|
' exactly "## Previous findings", one line per id, exactly as',
|
|
210
211
|
' "- F1: open path:from-to" or "- F1: closed".',
|
|
211
212
|
'Do not repeat an open previous finding under "## Findings"; report there',
|
|
212
213
|
"only findings from job 1 that are not already covered below.",
|
|
213
214
|
"",
|
|
214
215
|
];
|
|
215
|
-
|
|
216
|
-
lines.push("VERIFY:", verify.join("\n\n"), "");
|
|
217
|
-
}
|
|
218
|
-
if (unchanged.length) {
|
|
219
|
-
lines.push("STILL OPEN, UNCHANGED (do not report again):", unchanged.join("\n"), "");
|
|
220
|
-
}
|
|
216
|
+
lines.push("VERIFY:", verify.join("\n\n"), "");
|
|
221
217
|
return lines.join("\n");
|
|
222
218
|
}
|
|
219
|
+
/** At most the last three replies, 1000 characters each. */
|
|
220
|
+
function repliesBlock(replies) {
|
|
221
|
+
if (!replies?.length)
|
|
222
|
+
return "";
|
|
223
|
+
const quoted = replies
|
|
224
|
+
.slice(-3)
|
|
225
|
+
.map((reply) => `> ${reply.slice(0, 1000).replace(/\n/g, "\n> ")}`);
|
|
226
|
+
return `\nMaintainer replies on this finding:\n${quoted.join("\n\n")}`;
|
|
227
|
+
}
|
|
223
228
|
export function parsePreviousVerdicts(markdown) {
|
|
224
229
|
const heading = markdown.search(/^## Previous findings\b/im);
|
|
225
230
|
if (heading === -1)
|
|
@@ -252,7 +257,6 @@ export function resolveCarryOutcomes(items, current, visiblePaths, verdicts, par
|
|
|
252
257
|
for (const item of items) {
|
|
253
258
|
if (item.class === "file_reverted" ||
|
|
254
259
|
item.class === "file_removed" ||
|
|
255
|
-
item.class === "unchanged" ||
|
|
256
260
|
item.class === "unverifiable") {
|
|
257
261
|
continue;
|
|
258
262
|
}
|
|
@@ -309,7 +313,7 @@ export function resolveCarryOutcomes(items, current, visiblePaths, verdicts, par
|
|
|
309
313
|
lineTo = moved.to;
|
|
310
314
|
}
|
|
311
315
|
}
|
|
312
|
-
if (item.class === "
|
|
316
|
+
if (item.class === "unverifiable") {
|
|
313
317
|
const row = {
|
|
314
318
|
id: crypto.randomUUID(),
|
|
315
319
|
state: "open",
|
|
@@ -332,9 +336,12 @@ export function resolveCarryOutcomes(items, current, visiblePaths, verdicts, par
|
|
|
332
336
|
const promptId = promptIds.get(base.id);
|
|
333
337
|
const verdict = promptId ? verdictByPromptId.get(promptId) : undefined;
|
|
334
338
|
const state = verdict?.state ?? "open";
|
|
339
|
+
// An unchanged file's anchor is read again at the relocated lines.
|
|
335
340
|
const anchor = file && verdict?.path
|
|
336
341
|
? anchorTextFromPatch(file.patch, verdict.from ?? lineFrom, verdict.to ?? verdict.from ?? lineTo)
|
|
337
|
-
:
|
|
342
|
+
: item.class === "unchanged" && file
|
|
343
|
+
? anchorTextFromPatch(file.patch, lineFrom, lineTo)
|
|
344
|
+
: base.anchorText;
|
|
338
345
|
const row = {
|
|
339
346
|
id: crypto.randomUUID(),
|
|
340
347
|
state,
|
|
@@ -47,9 +47,16 @@ export interface ReviewMetadata {
|
|
|
47
47
|
durationMs: number;
|
|
48
48
|
}
|
|
49
49
|
export declare function formatDuration(ms: number): string;
|
|
50
|
-
/**
|
|
51
|
-
*
|
|
52
|
-
export
|
|
50
|
+
/** A finding an earlier round reported that this round still finds, with the
|
|
51
|
+
* commit that first found it when known. */
|
|
52
|
+
export type StillOpenFinding = {
|
|
53
|
+
finding: ParsedFinding;
|
|
54
|
+
since?: string;
|
|
55
|
+
};
|
|
56
|
+
/** Short summary on the review itself, one line per open finding, split
|
|
57
|
+
* into what this round found and what earlier rounds found that still
|
|
58
|
+
* holds, so a repeat never reads as a new problem. */
|
|
59
|
+
export declare function reviewBody(findings: ParsedFinding[], metadata: ReviewMetadata, stillOpen?: StillOpenFinding[]): string;
|
|
53
60
|
/** A review job's options: the config, with the job's pinned model (a
|
|
54
61
|
* "Retry with the same model") over the configured one. */
|
|
55
62
|
export declare function reviewOptionsForJob(repo: string, prNumber: number, args: {
|
|
@@ -71,3 +78,13 @@ export declare function enqueueManualReview(repo: string, prNumber: number, pin?
|
|
|
71
78
|
id: string;
|
|
72
79
|
debounced: boolean;
|
|
73
80
|
};
|
|
81
|
+
/** The round, scope and base of the next review after `last`. A job queued
|
|
82
|
+
* without them works them out when it starts. */
|
|
83
|
+
export declare function roundArgs(repo: string, last: {
|
|
84
|
+
head_sha: string | null;
|
|
85
|
+
round: number;
|
|
86
|
+
} | undefined): {
|
|
87
|
+
scope: string;
|
|
88
|
+
sinceCommit?: string;
|
|
89
|
+
round: number;
|
|
90
|
+
};
|
|
@@ -17,12 +17,13 @@ import { matchRepeat } from "../pr/rounds.js";
|
|
|
17
17
|
import { readConfig, resolveAppPrivateKey, resolvedAiToken, } from "../config.js";
|
|
18
18
|
import { outsideCode, redact } from "../util/redact.js";
|
|
19
19
|
import { getRepo, setInstallationId } from "../store/repos.js";
|
|
20
|
-
import { findNoteCommentId, getReviewByJobId, insertReview, latestPostedReview, setReviewScope, setReviewStatus, } from "../store/reviews.js";
|
|
20
|
+
import { findNoteCommentId, getReview, getReviewByJobId, insertReview, latestPostedReview, setReviewScope, setReviewStatus, } from "../store/reviews.js";
|
|
21
21
|
import { insertFinding, listCarryableFindingsForReview, listFindingsForPr, listFindingsForReview, setFindingPosted, } from "../store/findings.js";
|
|
22
22
|
import { getOrCreatePrSubject, getSubjectRevision, parseRevisionFiles, parseVisiblePaths, saveSubjectRevision, } from "../store/subjects.js";
|
|
23
23
|
import { enqueue, registerHandler } from "./jobs.js";
|
|
24
24
|
import { requestedReviewBlocked } from "./webhook.js";
|
|
25
25
|
import { getEnv } from "../util/runtime.js";
|
|
26
|
+
import { hasWriteAccess } from "../github/write_access.js";
|
|
26
27
|
const ACCESS_DENIED_BODY = "The App does not have access to review this pull request.";
|
|
27
28
|
/** The first words of the single note a failed review leaves on the pull
|
|
28
29
|
* request. The note names no provider error and no retry command: both live
|
|
@@ -177,19 +178,32 @@ function metadataBlock({ jobId, model, durationMs }) {
|
|
|
177
178
|
`- Duration: ${formatDuration(durationMs)}\n` +
|
|
178
179
|
`</details>`);
|
|
179
180
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
function summaryLine(finding, since) {
|
|
182
|
+
const title = humanCopy(finding.heading || finding.path);
|
|
183
|
+
const summary = humanCopy(finding.summary ??
|
|
184
|
+
finding.excerpt.split(/\r?\n/).find((line) => line.trim()) ??
|
|
185
|
+
"");
|
|
186
|
+
const first = since ? ` (first found in ${since.slice(0, 7)})` : "";
|
|
187
|
+
return `- ${title}${summary ? `: ${summary}` : ""}${first}`;
|
|
188
|
+
}
|
|
189
|
+
/** Short summary on the review itself, one line per open finding, split
|
|
190
|
+
* into what this round found and what earlier rounds found that still
|
|
191
|
+
* holds, so a repeat never reads as a new problem. */
|
|
192
|
+
export function reviewBody(findings, metadata, stillOpen = []) {
|
|
193
|
+
if (findings.length === 0 && stillOpen.length === 0) {
|
|
184
194
|
return `No actionable findings.${metadataBlock(metadata)}`;
|
|
185
195
|
}
|
|
186
|
-
const lines = ["Review summary"
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
196
|
+
const lines = ["Review summary"];
|
|
197
|
+
if (findings.length) {
|
|
198
|
+
lines.push("", `New (${findings.length})`);
|
|
199
|
+
for (const finding of findings)
|
|
200
|
+
lines.push(summaryLine(finding));
|
|
201
|
+
}
|
|
202
|
+
if (stillOpen.length) {
|
|
203
|
+
lines.push("", `Still open (${stillOpen.length})`);
|
|
204
|
+
for (const { finding, since } of stillOpen) {
|
|
205
|
+
lines.push(summaryLine(finding, since));
|
|
206
|
+
}
|
|
193
207
|
}
|
|
194
208
|
return lines.join("\n") + metadataBlock(metadata);
|
|
195
209
|
}
|
|
@@ -237,6 +251,49 @@ async function postedCommentBodies(client, job, log) {
|
|
|
237
251
|
return new Map();
|
|
238
252
|
}
|
|
239
253
|
}
|
|
254
|
+
/** What people with write access replied on each finding's inline thread,
|
|
255
|
+
* oldest first, keyed by finding id. The next round weighs them when it
|
|
256
|
+
* decides whether the finding still holds. */
|
|
257
|
+
async function findingReplies(client, job, rows, log) {
|
|
258
|
+
const byThread = new Map();
|
|
259
|
+
for (const row of rows) {
|
|
260
|
+
for (const id of [row.posted_comment_id, row.thread_comment_id]) {
|
|
261
|
+
if (id)
|
|
262
|
+
byThread.set(id, row.id);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const replies = new Map();
|
|
266
|
+
if (byThread.size === 0)
|
|
267
|
+
return replies;
|
|
268
|
+
let listed;
|
|
269
|
+
try {
|
|
270
|
+
listed = await client.pages(`repos/${job.repo}/pulls/${job.pr_number}/comments`);
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
log("info", `could not read the review threads: ${redact(String(error))}`);
|
|
274
|
+
return replies;
|
|
275
|
+
}
|
|
276
|
+
const access = new Map();
|
|
277
|
+
const sorted = [...listed].sort((a, b) => String(a.created_at ?? "").localeCompare(String(b.created_at ?? "")));
|
|
278
|
+
for (const comment of sorted) {
|
|
279
|
+
const findingId = byThread.get(String(comment.in_reply_to_id ?? ""));
|
|
280
|
+
const user = comment.user;
|
|
281
|
+
const login = String(user?.login ?? "");
|
|
282
|
+
if (!findingId || !login)
|
|
283
|
+
continue;
|
|
284
|
+
if (user?.type === "Bot" || login.endsWith("[bot]"))
|
|
285
|
+
continue;
|
|
286
|
+
if (!access.has(login)) {
|
|
287
|
+
access.set(login, hasWriteAccess(client, job.repo, login));
|
|
288
|
+
}
|
|
289
|
+
if (!(await access.get(login)))
|
|
290
|
+
continue;
|
|
291
|
+
const list = replies.get(findingId) ?? [];
|
|
292
|
+
list.push(String(comment.body ?? ""));
|
|
293
|
+
replies.set(findingId, list);
|
|
294
|
+
}
|
|
295
|
+
return replies;
|
|
296
|
+
}
|
|
240
297
|
/** A review job's options: the config, with the job's pinned model (a
|
|
241
298
|
* "Retry with the same model") over the configured one. */
|
|
242
299
|
export function reviewOptionsForJob(repo, prNumber, args) {
|
|
@@ -402,7 +459,7 @@ async function publish(client, job, reviewId, headSha, files, log, metadata, mod
|
|
|
402
459
|
});
|
|
403
460
|
const freshRows = stored.filter((row) => !repeats.includes(row) && (row.state === "new" || row.thread_comment_id));
|
|
404
461
|
const fresh = freshRows.map(rowFinding);
|
|
405
|
-
const { inline
|
|
462
|
+
const { inline } = splitInline(fresh, files);
|
|
406
463
|
const commentByRow = new Map();
|
|
407
464
|
for (const { finding, anchor, suggestion } of inline) {
|
|
408
465
|
const row = freshRows.find((item) => item.path === finding.path &&
|
|
@@ -415,25 +472,20 @@ async function publish(client, job, reviewId, headSha, files, log, metadata, mod
|
|
|
415
472
|
});
|
|
416
473
|
}
|
|
417
474
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
heading: row.title,
|
|
433
|
-
excerpt: row.body_md,
|
|
434
|
-
})),
|
|
435
|
-
];
|
|
436
|
-
const body = reviewBody(summaryFindings, metadata, inline.length + repeats.length);
|
|
475
|
+
// The summary lists every open finding once, by what this round made of
|
|
476
|
+
// it: found now, or found by an earlier round and still there.
|
|
477
|
+
const summaryFindings = stored
|
|
478
|
+
.filter((row) => row.state === "new")
|
|
479
|
+
.map(rowFinding);
|
|
480
|
+
const stillOpen = stored
|
|
481
|
+
.filter((row) => row.state === "open")
|
|
482
|
+
.map((row) => ({
|
|
483
|
+
finding: rowFinding(row),
|
|
484
|
+
since: row.first_seen_review_id
|
|
485
|
+
? (getReview(row.first_seen_review_id)?.head_sha ?? undefined)
|
|
486
|
+
: undefined,
|
|
487
|
+
}));
|
|
488
|
+
const body = reviewBody(summaryFindings, metadata, stillOpen);
|
|
437
489
|
const comments = inline.map(({ finding, anchor, suggestion }) => ({
|
|
438
490
|
path: finding.path,
|
|
439
491
|
body: inlineCommentBody(finding, suggestion),
|
|
@@ -489,7 +541,7 @@ async function publish(client, job, reviewId, headSha, files, log, metadata, mod
|
|
|
489
541
|
if (error instanceof GitHubHttpError && error.status === 422) {
|
|
490
542
|
log("info", "inline comments rejected, falling back to an issue comment");
|
|
491
543
|
const posted = await post(client, `repos/${job.repo}/issues/${job.pr_number}/comments`, {
|
|
492
|
-
body: reviewBody(summaryFindings, metadata),
|
|
544
|
+
body: reviewBody(summaryFindings, metadata, stillOpen),
|
|
493
545
|
});
|
|
494
546
|
setReviewStatus(reviewId, "posted", {
|
|
495
547
|
posted_review_id: String(posted.id ?? ""),
|
|
@@ -604,6 +656,21 @@ async function runReviewJobCore(job, log, client, ai) {
|
|
|
604
656
|
}
|
|
605
657
|
const headSha = String(pr.head?.sha ?? "");
|
|
606
658
|
const mergeBase = String(pr.base?.sha ?? "");
|
|
659
|
+
if (!existing) {
|
|
660
|
+
const last = latestPostedReview(job.repo, job.pr_number);
|
|
661
|
+
// A review or comment that arrived while a review of this head was
|
|
662
|
+
// running queued this job. That review has posted by now.
|
|
663
|
+
if ((args.trigger === "review" || args.trigger === "review-comment") &&
|
|
664
|
+
last?.head_sha === headSha) {
|
|
665
|
+
log("info", "this head was already reviewed, nothing new to review");
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
// Round and base come from the review that posted last, read now rather
|
|
669
|
+
// than when the job was queued: a review may have posted in between.
|
|
670
|
+
if (args.round === undefined) {
|
|
671
|
+
Object.assign(args, roundArgs(job.repo, last));
|
|
672
|
+
}
|
|
673
|
+
}
|
|
607
674
|
let scope = args.scope === "incremental" ? "incremental" : "whole-pr";
|
|
608
675
|
if (scope === "incremental" && !args.sinceCommit) {
|
|
609
676
|
scope = "whole-pr";
|
|
@@ -700,6 +767,7 @@ async function runReviewJobCore(job, log, client, ai) {
|
|
|
700
767
|
const { unchanged } = incrementalDiffPaths(revision, prevFiles);
|
|
701
768
|
extras.unchangedPaths = scope === "incremental" ? unchanged : undefined;
|
|
702
769
|
const storedRows = listCarryableFindingsForReview(subjectRevision.review_id);
|
|
770
|
+
const replies = await findingReplies(github, job, storedRows, log);
|
|
703
771
|
carryPrevious = {
|
|
704
772
|
files: prevFiles,
|
|
705
773
|
visiblePaths: parseVisiblePaths(subjectRevision),
|
|
@@ -713,6 +781,7 @@ async function runReviewJobCore(job, log, client, ai) {
|
|
|
713
781
|
anchorText: row.anchor_text,
|
|
714
782
|
severity: row.severity,
|
|
715
783
|
firstSeenReviewId: row.first_seen_review_id ?? subjectRevision.review_id,
|
|
784
|
+
replies: replies.get(row.id),
|
|
716
785
|
})),
|
|
717
786
|
guideBuiltAt: subjectRevision.guide_built_at,
|
|
718
787
|
};
|
|
@@ -843,19 +912,23 @@ export function registerReviewJobHandler() {
|
|
|
843
912
|
* model" asks; without it the job resolves the model from config when it
|
|
844
913
|
* runs. */
|
|
845
914
|
export function enqueueManualReview(repo, prNumber, pin = {}) {
|
|
846
|
-
const last = latestPostedReview(repo, prNumber);
|
|
847
|
-
const row = getRepo(repo);
|
|
848
|
-
const incremental = row?.review_scope === "incremental" && Boolean(last?.head_sha);
|
|
849
915
|
return enqueue({
|
|
850
916
|
type: "review",
|
|
851
917
|
repo,
|
|
852
918
|
prNumber,
|
|
853
919
|
args: {
|
|
854
920
|
trigger: "manual",
|
|
855
|
-
scope: incremental ? "incremental" : "whole-pr",
|
|
856
|
-
sinceCommit: incremental ? last.head_sha : undefined,
|
|
857
|
-
round: last ? last.round + 1 : 1,
|
|
858
921
|
...(pin.model ? { model: pin.model } : {}),
|
|
859
922
|
},
|
|
860
923
|
});
|
|
861
924
|
}
|
|
925
|
+
/** The round, scope and base of the next review after `last`. A job queued
|
|
926
|
+
* without them works them out when it starts. */
|
|
927
|
+
export function roundArgs(repo, last) {
|
|
928
|
+
const incremental = getRepo(repo)?.review_scope === "incremental" && Boolean(last?.head_sha);
|
|
929
|
+
return {
|
|
930
|
+
scope: incremental ? "incremental" : "whole-pr",
|
|
931
|
+
sinceCommit: incremental ? last.head_sha : undefined,
|
|
932
|
+
round: last ? last.round + 1 : 1,
|
|
933
|
+
};
|
|
934
|
+
}
|
|
@@ -13,6 +13,7 @@ import { FakeAiProvider } from "../ai/fake.js";
|
|
|
13
13
|
import { completeWithMermaidTools } from "../ai/mermaid_loop.js";
|
|
14
14
|
import { loadGuides } from "../review/guides.js";
|
|
15
15
|
import { getEnv } from "../util/runtime.js";
|
|
16
|
+
import { hasWriteAccess } from "../github/write_access.js";
|
|
16
17
|
import { getWatchIssue, insertWatchNote } from "../store/watch.js";
|
|
17
18
|
import { registerHandler } from "./jobs.js";
|
|
18
19
|
import { recordAiCost } from "./setup.js";
|
|
@@ -83,20 +84,6 @@ async function alreadyAnswered(client, repo, issueNumber, commentId) {
|
|
|
83
84
|
return false;
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
|
-
/** True when `login` can write to the repository. The webhook's
|
|
87
|
-
* author_association is only a first filter: MEMBER means a member of the
|
|
88
|
-
* organization and COLLABORATOR may be read-only. Any error counts as no. */
|
|
89
|
-
async function hasWriteAccess(client, repo, login) {
|
|
90
|
-
if (!login)
|
|
91
|
-
return false;
|
|
92
|
-
try {
|
|
93
|
-
const result = await client.request(`repos/${repo}/collaborators/${encodeURIComponent(login)}/permission`);
|
|
94
|
-
return ["admin", "maintain", "write"].includes(String(result.role_name ?? result.permission ?? ""));
|
|
95
|
-
}
|
|
96
|
-
catch {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
87
|
async function runWatchComment(job, log) {
|
|
101
88
|
const args = JSON.parse(job.args);
|
|
102
89
|
const issue = getWatchIssue(job.repo, args.issueNumber);
|
|
@@ -201,8 +201,7 @@ export function maybeEnqueueReview(input) {
|
|
|
201
201
|
earlier.round >= policy.maxRounds) {
|
|
202
202
|
return skipped(`Round limit reached: ${earlier.round} of ${policy.maxRounds} reviews.`);
|
|
203
203
|
}
|
|
204
|
-
|
|
205
|
-
const incremental = row.review_scope === "incremental" && Boolean(last?.head_sha);
|
|
204
|
+
// Round, scope and base are worked out when the job starts.
|
|
206
205
|
const { id } = enqueue({
|
|
207
206
|
type: "review",
|
|
208
207
|
repo: input.repo,
|
|
@@ -211,9 +210,6 @@ export function maybeEnqueueReview(input) {
|
|
|
211
210
|
debounceMs: REVIEW_DEBOUNCE_MS,
|
|
212
211
|
args: {
|
|
213
212
|
trigger: input.trigger,
|
|
214
|
-
scope: incremental ? "incremental" : "whole-pr",
|
|
215
|
-
sinceCommit: incremental ? last.head_sha : undefined,
|
|
216
|
-
round: last ? last.round + 1 : 1,
|
|
217
213
|
requestReaction: input.request?.reaction,
|
|
218
214
|
},
|
|
219
215
|
});
|