co-maintainer 0.6.9 → 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/ai/fake.d.ts +10 -1
- package/dist/src/ai/fake.js +39 -4
- package/dist/src/cli/args.js +2 -0
- package/dist/src/cli/command_json.d.ts +6 -0
- package/dist/src/cli/command_json.js +1 -0
- package/dist/src/cli/commands/probe.js +25 -0
- package/dist/src/cli/commands/registry.js +11 -0
- package/dist/src/cli/commands/review.js +5 -1
- package/dist/src/cli/commands/serve.js +4 -0
- package/dist/src/cli/commands/set.js +4 -2
- package/dist/src/cli/review_args.d.ts +9 -0
- package/dist/src/cli/review_args.js +36 -1
- package/dist/src/github/app.d.ts +4 -0
- package/dist/src/github/app.js +10 -1
- package/dist/src/github/permissions.js +40 -0
- package/dist/src/github/write_access.d.ts +7 -0
- package/dist/src/github/write_access.js +12 -0
- package/dist/src/local/git_ops.js +3 -2
- package/dist/src/local/git_revision.d.ts +5 -2
- package/dist/src/local/git_revision.js +17 -10
- package/dist/src/pr/reviewer.d.ts +2 -0
- package/dist/src/pr/reviewer.js +1 -1
- package/dist/src/remote/push_client.d.ts +7 -0
- package/dist/src/remote/push_client.js +287 -0
- package/dist/src/remote/server/routes.d.ts +1 -0
- package/dist/src/remote/server/routes.js +61 -4
- package/dist/src/remote/server/sync.js +11 -3
- package/dist/src/remote/validate.js +17 -0
- package/dist/src/review/carry_over.d.ts +2 -0
- package/dist/src/review/carry_over.js +33 -26
- package/dist/src/server/api/repos.js +13 -2
- package/dist/src/server/pages/layout.js +1 -0
- package/dist/src/server/pages/repo.d.ts +3 -1
- package/dist/src/server/pages/repo.js +4 -1
- package/dist/src/server/pages/repo_pushes.d.ts +7 -0
- package/dist/src/server/pages/repo_pushes.js +144 -0
- package/dist/src/server/pages/repo_settings.js +45 -1
- package/dist/src/server/pages/router.js +22 -3
- package/dist/src/server/webhook/index.js +8 -1
- package/dist/src/services/dashboard.d.ts +46 -0
- package/dist/src/services/dashboard.js +24 -0
- package/dist/src/services/jobs.js +10 -0
- package/dist/src/services/push_review.d.ts +51 -0
- package/dist/src/services/push_review.js +878 -0
- package/dist/src/services/review.d.ts +20 -3
- package/dist/src/services/review.js +112 -39
- package/dist/src/services/setup.js +21 -0
- package/dist/src/services/watch_comments.d.ts +10 -0
- package/dist/src/services/watch_comments.js +166 -0
- package/dist/src/services/watch_issues.d.ts +70 -0
- package/dist/src/services/watch_issues.js +266 -0
- package/dist/src/services/watch_notes.d.ts +8 -0
- package/dist/src/services/watch_notes.js +80 -0
- package/dist/src/services/watch_status.d.ts +25 -0
- package/dist/src/services/watch_status.js +101 -0
- package/dist/src/services/webhook.js +108 -8
- package/dist/src/store/migrations.js +63 -0
- package/dist/src/store/repos.d.ts +1 -1
- package/dist/src/store/rows.d.ts +6 -0
- package/dist/src/store/watch.d.ts +108 -0
- package/dist/src/store/watch.js +186 -0
- package/dist/src/types.d.ts +2 -0
- package/dist/src/util/repo_name.d.ts +2 -0
- package/dist/src/util/repo_name.js +56 -0
- package/package.json +1 -1
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/** `co-maintainer review --remote --range=<before>..<after>`: commit watch
|
|
2
|
+
* from CI.
|
|
3
|
+
*
|
|
4
|
+
* The step sends the push's diff and waits for the server's review. What it
|
|
5
|
+
* reports and how it exits:
|
|
6
|
+
* - findings are warnings, and the step stays green: the push is already in,
|
|
7
|
+
* so there is nothing to block.
|
|
8
|
+
* - a review still running after `--timeout-minutes` (default 10) leaves a
|
|
9
|
+
* notice and stays green. The server finishes the review on its own.
|
|
10
|
+
* - a push merged into a newer push's review leaves a notice and stays green.
|
|
11
|
+
* - a repository that is not initialized is red, unless the GitHub App gave
|
|
12
|
+
* the commit a skipped check run: then it is a notice.
|
|
13
|
+
* - a server that cannot be reached or rejects the token is red. */
|
|
14
|
+
import { VERSION } from "../version.js";
|
|
15
|
+
import { exitWith } from "../cli/error.js";
|
|
16
|
+
import { formatHumanReview, humanFindingsFromJson, } from "../cli/review_result.js";
|
|
17
|
+
import { baseUrl, die, readApiError, remoteFetch, remoteFromEnv, } from "./http.js";
|
|
18
|
+
import { readConfig } from "../config.js";
|
|
19
|
+
import { stripControlChars } from "../util/sanitize.js";
|
|
20
|
+
import { runCommand } from "../pr/checkout.js";
|
|
21
|
+
import { assertGitQuiet, currentBranch, detectRemoteRepo, gitRoot, } from "../local/git_ops.js";
|
|
22
|
+
import { buildLocalRevision } from "../local/git_revision.js";
|
|
23
|
+
import { withCliLogsToStderr } from "../util/log.js";
|
|
24
|
+
import { emitGithubOutput, escapeData, neutralizeCommands, } from "../cli/review_github.js";
|
|
25
|
+
import { setCliInteractive } from "../cli/args.js";
|
|
26
|
+
import { MIN_SERVER_SCHEMA, REMOTE_CLI_UPGRADE_COMMAND, REMOTE_SCHEMA_VERSION, } from "./schema.js";
|
|
27
|
+
export const DEFAULT_PUSH_TIMEOUT_MINUTES = 10;
|
|
28
|
+
const ZERO = /^0+$/;
|
|
29
|
+
/** A notice the step shows and that never fails it. */
|
|
30
|
+
function notice(cli, message) {
|
|
31
|
+
if (cli.json) {
|
|
32
|
+
console.log(JSON.stringify({ schemaVersion: 1, ok: true, mode: "push", message }));
|
|
33
|
+
}
|
|
34
|
+
else if (cli.output === "github") {
|
|
35
|
+
console.log(`::notice title=co-maintainer::${escapeData(message)}`);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
console.log(message);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function git(root, args) {
|
|
42
|
+
return await runCommand("git", args, root);
|
|
43
|
+
}
|
|
44
|
+
async function resolveCommit(root, rev) {
|
|
45
|
+
const result = await git(root, [
|
|
46
|
+
"rev-parse",
|
|
47
|
+
"--verify",
|
|
48
|
+
"--quiet",
|
|
49
|
+
`${rev}^{commit}`,
|
|
50
|
+
]);
|
|
51
|
+
return result.code === 0 ? result.stdout.trim() : undefined;
|
|
52
|
+
}
|
|
53
|
+
/** `rev` as a full sha, fetching it from the remote when the checkout does
|
|
54
|
+
* not have it (a shallow CI checkout usually holds only `after`). */
|
|
55
|
+
async function ensureCommit(root, remote, rev) {
|
|
56
|
+
const local = await resolveCommit(root, rev);
|
|
57
|
+
if (local)
|
|
58
|
+
return local;
|
|
59
|
+
await git(root, ["fetch", "--quiet", "--no-tags", remote, rev]);
|
|
60
|
+
return await resolveCommit(root, rev);
|
|
61
|
+
}
|
|
62
|
+
/** Where the diff starts. `before` itself after a normal push. After a
|
|
63
|
+
* force-push `before` is no longer an ancestor, so the commits since the
|
|
64
|
+
* merge base. When `before` cannot be fetched at all, the last commit, with
|
|
65
|
+
* a warning. */
|
|
66
|
+
async function diffBase(root, remote, before, after) {
|
|
67
|
+
const have = await ensureCommit(root, remote, before);
|
|
68
|
+
if (have) {
|
|
69
|
+
let base = await git(root, ["merge-base", have, after]);
|
|
70
|
+
if (base.code !== 0) {
|
|
71
|
+
// A shallow checkout can hold both commits and still not their history.
|
|
72
|
+
await git(root, ["fetch", "--quiet", "--no-tags", "--unshallow", remote]);
|
|
73
|
+
base = await git(root, ["merge-base", have, after]);
|
|
74
|
+
}
|
|
75
|
+
if (base.code === 0 && base.stdout.trim())
|
|
76
|
+
return base.stdout.trim();
|
|
77
|
+
}
|
|
78
|
+
console.error(`Warning: could not fetch ${before.slice(0, 7)}, so only the last commit of this push is reviewed.`);
|
|
79
|
+
// `after^` is no refspec git can fetch, so a depth-one checkout is deepened
|
|
80
|
+
// by one commit to bring the parent in.
|
|
81
|
+
let parent = await resolveCommit(root, `${after}^`);
|
|
82
|
+
if (!parent) {
|
|
83
|
+
await git(root, ["fetch", "--quiet", "--no-tags", "--deepen=1", remote]);
|
|
84
|
+
parent = await resolveCommit(root, `${after}^`);
|
|
85
|
+
}
|
|
86
|
+
if (!parent) {
|
|
87
|
+
die("push_base_missing", "Could not find the commit this push starts from.");
|
|
88
|
+
}
|
|
89
|
+
return parent;
|
|
90
|
+
}
|
|
91
|
+
async function readError(response) {
|
|
92
|
+
try {
|
|
93
|
+
const body = (await response.clone().json());
|
|
94
|
+
return body.error ?? {};
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return { message: await readApiError(response) };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export async function runRemotePushReview(cli) {
|
|
101
|
+
const range = cli.range;
|
|
102
|
+
const config = readConfig();
|
|
103
|
+
const fromEnv = remoteFromEnv();
|
|
104
|
+
const host = cli.remoteHost ?? fromEnv.host ?? config.remoteHost;
|
|
105
|
+
const token = cli.remoteToken ?? fromEnv.token ?? config.remoteToken;
|
|
106
|
+
if (!host || !token) {
|
|
107
|
+
die("remote_not_configured", "Remote review is not configured.", "set CM_REMOTE_HOST and CM_REMOTE_TOKEN, or pass --remote-host=... --remote-token=...");
|
|
108
|
+
}
|
|
109
|
+
setCliInteractive(!cli.json);
|
|
110
|
+
await withCliLogsToStderr(async () => {
|
|
111
|
+
// A push that creates the branch has no "before": there is nothing it
|
|
112
|
+
// changed to compare with.
|
|
113
|
+
if (ZERO.test(range.before)) {
|
|
114
|
+
notice(cli, "No changes to review.");
|
|
115
|
+
exitWith(0);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const root = await gitRoot(process.cwd());
|
|
119
|
+
await assertGitQuiet(root);
|
|
120
|
+
const repo = await detectRemoteRepo(root, cli.repoOverride);
|
|
121
|
+
const branch = await currentBranch(root, cli.branch);
|
|
122
|
+
const remotes = (await git(root, ["remote"])).stdout
|
|
123
|
+
.split("\n")
|
|
124
|
+
.map((line) => line.trim())
|
|
125
|
+
.filter(Boolean);
|
|
126
|
+
const remoteName = ["upstream", "origin"].find((name) => remotes.includes(name)) ??
|
|
127
|
+
remotes[0];
|
|
128
|
+
const after = await ensureCommit(root, remoteName, range.after);
|
|
129
|
+
if (!after)
|
|
130
|
+
die("push_after_missing", `Could not find ${range.after} in this checkout.`);
|
|
131
|
+
let before = (await resolveCommit(root, range.before)) ?? range.before;
|
|
132
|
+
const handshake = await remoteFetch(host, token, "/api/remote/handshake", {
|
|
133
|
+
method: "POST",
|
|
134
|
+
body: JSON.stringify({
|
|
135
|
+
schemaVersion: REMOTE_SCHEMA_VERSION,
|
|
136
|
+
clientVersion: VERSION,
|
|
137
|
+
repo,
|
|
138
|
+
purpose: "push",
|
|
139
|
+
}),
|
|
140
|
+
});
|
|
141
|
+
if (!handshake.ok)
|
|
142
|
+
die("remote_handshake_failed", await readApiError(handshake));
|
|
143
|
+
const hs = (await handshake.json());
|
|
144
|
+
if (REMOTE_SCHEMA_VERSION < hs.minClientSchema) {
|
|
145
|
+
die("upgrade_required", "This co-maintainer CLI is too old for the server.", REMOTE_CLI_UPGRADE_COMMAND, 4);
|
|
146
|
+
}
|
|
147
|
+
if (hs.schemaVersion < MIN_SERVER_SCHEMA ||
|
|
148
|
+
!hs.features?.includes("push")) {
|
|
149
|
+
die("server_too_old", `This server (version ${hs.serverVersion}) cannot review pushes.`, "Upgrade the server to 0.6.10 or later.", 4);
|
|
150
|
+
}
|
|
151
|
+
let submitted;
|
|
152
|
+
// At most one retry: the server asks for a wider range when this push
|
|
153
|
+
// was merged into a waiting review that only this step can diff.
|
|
154
|
+
for (let attempt = 0; attempt < 2 && !submitted; attempt++) {
|
|
155
|
+
const base = await diffBase(root, remoteName, before, after);
|
|
156
|
+
const built = await buildLocalRevision(root, base, branch, runCommand, after);
|
|
157
|
+
if (built.revision.files.length === 0 && attempt === 0) {
|
|
158
|
+
notice(cli, "No changes to review.");
|
|
159
|
+
exitWith(0);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const body = JSON.stringify({
|
|
163
|
+
schemaVersion: REMOTE_SCHEMA_VERSION,
|
|
164
|
+
requestId: crypto.randomUUID(),
|
|
165
|
+
repo: hs.repo.fullName,
|
|
166
|
+
branch,
|
|
167
|
+
revision: {
|
|
168
|
+
title: "",
|
|
169
|
+
description: "",
|
|
170
|
+
baseLabel: branch,
|
|
171
|
+
files: built.revision.files,
|
|
172
|
+
},
|
|
173
|
+
push: { before, after, ref: `refs/heads/${branch}` },
|
|
174
|
+
});
|
|
175
|
+
if (body.length > hs.limits.maxBodyBytes) {
|
|
176
|
+
die("payload_too_large", "This push is too large for the remote server limit.");
|
|
177
|
+
}
|
|
178
|
+
const submit = await remoteFetch(host, token, "/api/remote/reviews", {
|
|
179
|
+
method: "POST",
|
|
180
|
+
body,
|
|
181
|
+
});
|
|
182
|
+
if (submit.status === 202) {
|
|
183
|
+
submitted = (await submit.json());
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
if (submit.status === 200) {
|
|
187
|
+
notice(cli, "No changes to review.");
|
|
188
|
+
exitWith(0);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const error = await readError(submit);
|
|
192
|
+
if (error.code === "range_extend" &&
|
|
193
|
+
error.detail?.before &&
|
|
194
|
+
attempt === 0) {
|
|
195
|
+
before = error.detail.before;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (error.code === "not_initialized_skipped") {
|
|
199
|
+
notice(cli, `${error.message ?? "This repository is not initialized."} The commit got a skipped check run.`);
|
|
200
|
+
exitWith(0);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (error.code === "not_default_branch") {
|
|
204
|
+
notice(cli, error.message ?? "Commit watch reviews the default branch only.");
|
|
205
|
+
exitWith(0);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
die(error.code ?? "remote_submit_failed", error.message ?? "The server refused the push.");
|
|
209
|
+
}
|
|
210
|
+
if (!submitted)
|
|
211
|
+
die("remote_submit_failed", "The server refused the push.");
|
|
212
|
+
if (submitted.attached && !cli.json) {
|
|
213
|
+
console.error("The GitHub App is already reviewing this push, waiting for that review.");
|
|
214
|
+
}
|
|
215
|
+
const deadline = Date.now() +
|
|
216
|
+
(cli.timeoutMinutes ?? DEFAULT_PUSH_TIMEOUT_MINUTES) * 60_000;
|
|
217
|
+
const intervalMs = hs.sync.intervalSeconds * 1000;
|
|
218
|
+
let afterLogSeq = 0;
|
|
219
|
+
for (;;) {
|
|
220
|
+
const sync = await remoteFetch(host, token, `/api/remote/reviews/${submitted.jobId}/sync`, {
|
|
221
|
+
method: "POST",
|
|
222
|
+
body: JSON.stringify({
|
|
223
|
+
schemaVersion: REMOTE_SCHEMA_VERSION,
|
|
224
|
+
afterLogSeq,
|
|
225
|
+
toolResults: [],
|
|
226
|
+
}),
|
|
227
|
+
});
|
|
228
|
+
if (!sync.ok)
|
|
229
|
+
die("remote_sync_failed", await readApiError(sync));
|
|
230
|
+
const payload = (await sync.json());
|
|
231
|
+
for (const line of payload.logs ?? []) {
|
|
232
|
+
afterLogSeq = Math.max(afterLogSeq, line.seq);
|
|
233
|
+
if (!cli.json) {
|
|
234
|
+
console.error(cli.output === "github"
|
|
235
|
+
? neutralizeCommands(line.message)
|
|
236
|
+
: stripControlChars(line.message));
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (payload.status === "done" && payload.result) {
|
|
240
|
+
const findings = (payload.result.findings ?? []);
|
|
241
|
+
const title = `${repo} · ${branch} · ${before.slice(0, 7)}..${after.slice(0, 7)}`;
|
|
242
|
+
// A push review never blocks, so every finding is a warning.
|
|
243
|
+
const human = humanFindingsFromJson(findings).map((row) => ({
|
|
244
|
+
...row,
|
|
245
|
+
blocking: false,
|
|
246
|
+
}));
|
|
247
|
+
if (cli.json) {
|
|
248
|
+
console.log(JSON.stringify({
|
|
249
|
+
schemaVersion: 1,
|
|
250
|
+
ok: true,
|
|
251
|
+
mode: "push",
|
|
252
|
+
...payload.result,
|
|
253
|
+
}));
|
|
254
|
+
}
|
|
255
|
+
else if (cli.output === "github") {
|
|
256
|
+
emitGithubOutput({ title, findings: human });
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
console.log("\n" +
|
|
260
|
+
formatHumanReview({
|
|
261
|
+
title: `co-maintainer commit watch · ${title}`,
|
|
262
|
+
guideBuiltAt: null,
|
|
263
|
+
codegraphState: null,
|
|
264
|
+
findings: human,
|
|
265
|
+
}) +
|
|
266
|
+
"\n");
|
|
267
|
+
}
|
|
268
|
+
exitWith(0);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
if (payload.status === "canceled" && payload.abort?.reason === "merged") {
|
|
272
|
+
notice(cli, `${stripControlChars(payload.abort.message)} The result is on the dashboard.`);
|
|
273
|
+
exitWith(0);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
if (payload.status === "failed" || payload.status === "canceled") {
|
|
277
|
+
die(stripControlChars(payload.abort?.reason ?? "remote_failed"), stripControlChars(payload.abort?.message ?? "The push review did not complete."));
|
|
278
|
+
}
|
|
279
|
+
if (Date.now() >= deadline) {
|
|
280
|
+
notice(cli, `The review is still running on ${baseUrl(host)}. The result will be on the dashboard.`);
|
|
281
|
+
exitWith(0);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|
|
@@ -10,6 +10,8 @@ import { findRepoByFullName } from "../../store/repos.js";
|
|
|
10
10
|
import { MIN_CLIENT_SCHEMA, REMOTE_CLI_UPGRADE_COMMAND, REMOTE_MAX_BODY_BYTES, REMOTE_SCHEMA_VERSION, REMOTE_SYNC_INTERVAL_SECONDS, } from "../schema.js";
|
|
11
11
|
import { readBoundedJson } from "./body.js";
|
|
12
12
|
import { submitRemoteReview } from "../../services/remote_review.js";
|
|
13
|
+
import { queuePush } from "../../services/push_review.js";
|
|
14
|
+
import { revisionFromSubmitJson } from "../revision_from_submit.js";
|
|
13
15
|
import { handleRemoteCancel, handleRemoteSync } from "./sync.js";
|
|
14
16
|
import { parseRepoQuery, readRemoteGuides } from "./guides.js";
|
|
15
17
|
import { validateHandshakeRequest, validateSubmitRequest, } from "../validate.js";
|
|
@@ -34,7 +36,7 @@ async function authenticateRemote(request, ip) {
|
|
|
34
36
|
}
|
|
35
37
|
return status;
|
|
36
38
|
}
|
|
37
|
-
async function defaultBranchForRepo(fullName) {
|
|
39
|
+
export async function defaultBranchForRepo(fullName) {
|
|
38
40
|
try {
|
|
39
41
|
const dir = cloneDir(fullName);
|
|
40
42
|
await stat(dir);
|
|
@@ -71,7 +73,9 @@ async function handleHandshake(request, ip) {
|
|
|
71
73
|
return errorResponse(404, "repo_unavailable", REPO_UNAVAILABLE);
|
|
72
74
|
}
|
|
73
75
|
const guides = await loadGuides(repoRow.full_name);
|
|
74
|
-
|
|
76
|
+
// A push review decides about a repository with no guides itself, so the
|
|
77
|
+
// commit can get a skipped check run when the App covers it.
|
|
78
|
+
if (!guides.shortGuide && !guides.skill && record.purpose !== "push") {
|
|
75
79
|
return errorResponse(409, "not_initialized", REPO_UNAVAILABLE);
|
|
76
80
|
}
|
|
77
81
|
const config = readConfig();
|
|
@@ -99,7 +103,7 @@ async function handleHandshake(request, ip) {
|
|
|
99
103
|
// Additive advertisement: a 0.5.0 client ignores these, and an
|
|
100
104
|
// older server never sends them, so the client gates on `features`. No key,
|
|
101
105
|
// model, or other secret is ever echoed here.
|
|
102
|
-
features: ["byok"],
|
|
106
|
+
features: ["byok", "push"],
|
|
103
107
|
byok: { policy },
|
|
104
108
|
ai: { provider: config.ai ?? "openrouter" },
|
|
105
109
|
});
|
|
@@ -126,7 +130,10 @@ async function handleSubmit(request, ip) {
|
|
|
126
130
|
if (validation) {
|
|
127
131
|
return errorResponse(400, "bad_request", validation);
|
|
128
132
|
}
|
|
129
|
-
const
|
|
133
|
+
const record = parsed.value;
|
|
134
|
+
if (record.push !== undefined)
|
|
135
|
+
return await submitPush(record);
|
|
136
|
+
const result = submitRemoteReview(auth, record);
|
|
130
137
|
if ("error" in result) {
|
|
131
138
|
return errorResponse(result.status, result.code, result.error);
|
|
132
139
|
}
|
|
@@ -136,6 +143,56 @@ async function handleSubmit(request, ip) {
|
|
|
136
143
|
reviewId: result.reviewId,
|
|
137
144
|
}, { status: 202 });
|
|
138
145
|
}
|
|
146
|
+
/** `review --remote --range`: a push to review on the server. The review
|
|
147
|
+
* does not depend on this client staying connected, so it opens no remote
|
|
148
|
+
* session and offers no tool bridge. */
|
|
149
|
+
async function submitPush(record) {
|
|
150
|
+
const push = record.push;
|
|
151
|
+
const repoRow = findRepoByFullName(String(record.repo));
|
|
152
|
+
if (!repoRow || repoRow.active !== 1) {
|
|
153
|
+
return errorResponse(404, "repo_unavailable", REPO_UNAVAILABLE);
|
|
154
|
+
}
|
|
155
|
+
// Commit watch reviews the default branch only, as the App webhook does.
|
|
156
|
+
// A feature branch would open and close issues against unmerged code.
|
|
157
|
+
const defaultBranch = await defaultBranchForRepo(repoRow.full_name);
|
|
158
|
+
if (defaultBranch && push.ref !== `refs/heads/${defaultBranch}`) {
|
|
159
|
+
return errorResponse(409, "not_default_branch", `Commit watch reviews pushes to ${defaultBranch} only.`);
|
|
160
|
+
}
|
|
161
|
+
let revision;
|
|
162
|
+
try {
|
|
163
|
+
revision = revisionFromSubmitJson(record.revision);
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
return errorResponse(400, "bad_request", String(error));
|
|
167
|
+
}
|
|
168
|
+
const outcome = queuePush({
|
|
169
|
+
repo: repoRow.full_name,
|
|
170
|
+
before: push.before,
|
|
171
|
+
after: push.after,
|
|
172
|
+
ref: push.ref,
|
|
173
|
+
source: "ci",
|
|
174
|
+
revision,
|
|
175
|
+
});
|
|
176
|
+
switch (outcome.kind) {
|
|
177
|
+
case "enqueued":
|
|
178
|
+
case "attached":
|
|
179
|
+
return Response.json({
|
|
180
|
+
schemaVersion: REMOTE_SCHEMA_VERSION,
|
|
181
|
+
jobId: outcome.jobId,
|
|
182
|
+
reviewId: outcome.reviewId,
|
|
183
|
+
attached: outcome.kind === "attached",
|
|
184
|
+
}, { status: 202 });
|
|
185
|
+
case "no_changes":
|
|
186
|
+
return Response.json({ schemaVersion: REMOTE_SCHEMA_VERSION, noChanges: true }, { status: 200 });
|
|
187
|
+
case "extend":
|
|
188
|
+
return errorResponse(409, "range_extend", "A waiting push review was merged into this one. Send the wider range.", { before: outcome.before });
|
|
189
|
+
case "skipped":
|
|
190
|
+
if (outcome.reason === "not-initialized") {
|
|
191
|
+
return errorResponse(409, outcome.checkRun ? "not_initialized_skipped" : "not_initialized", outcome.message);
|
|
192
|
+
}
|
|
193
|
+
return errorResponse(409, "push_skipped", outcome.message);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
139
196
|
async function handleGuides(request, ip, url) {
|
|
140
197
|
const auth = await authenticateRemote(request, ip);
|
|
141
198
|
if (auth instanceof Response)
|
|
@@ -3,6 +3,7 @@ import { errorResponse } from "../../server/errors.js";
|
|
|
3
3
|
import { redact } from "../../util/redact.js";
|
|
4
4
|
import { getJob } from "../../store/jobs.js";
|
|
5
5
|
import { getReviewByJobId } from "../../store/reviews.js";
|
|
6
|
+
import { getPushResult } from "../../store/watch.js";
|
|
6
7
|
import { REMOTE_SCHEMA_VERSION } from "../schema.js";
|
|
7
8
|
import { validateSyncRequest, validateSyncResponseStatus, } from "../validate.js";
|
|
8
9
|
import { getRemoteSyncResult, touchRemoteSession, } from "./sessions.js";
|
|
@@ -30,7 +31,10 @@ export function handleRemoteSync(jobId, token, body) {
|
|
|
30
31
|
}
|
|
31
32
|
const job = getJob(jobId);
|
|
32
33
|
const review = getReviewByJobId(jobId);
|
|
33
|
-
|
|
34
|
+
// A push review belongs to the repository, not to one token: the App may
|
|
35
|
+
// have started it and a CI step waits on it.
|
|
36
|
+
const push = review?.kind === "push";
|
|
37
|
+
if (!job || !review || (!push && review.token_id !== token.id)) {
|
|
34
38
|
return errorResponse(404, "not_found", "review not found");
|
|
35
39
|
}
|
|
36
40
|
touchRemoteSession(jobId);
|
|
@@ -53,7 +57,9 @@ export function handleRemoteSync(jobId, token, body) {
|
|
|
53
57
|
let abort = null;
|
|
54
58
|
let result = null;
|
|
55
59
|
if (status === "done") {
|
|
56
|
-
result =
|
|
60
|
+
result = push
|
|
61
|
+
? (getPushResult(review.id) ?? null)
|
|
62
|
+
: (getRemoteSyncResult(jobId) ?? null);
|
|
57
63
|
}
|
|
58
64
|
else if (status === "canceled") {
|
|
59
65
|
const reason = job.cancel_reason ?? "canceled";
|
|
@@ -61,7 +67,9 @@ export function handleRemoteSync(jobId, token, body) {
|
|
|
61
67
|
reason,
|
|
62
68
|
message: reason === "client_timeout"
|
|
63
69
|
? "No sync received for the configured timeout."
|
|
64
|
-
:
|
|
70
|
+
: reason === "merged"
|
|
71
|
+
? "This push was merged into the review of a newer push."
|
|
72
|
+
: "Review was canceled.",
|
|
65
73
|
};
|
|
66
74
|
}
|
|
67
75
|
else if (status === "failed") {
|
|
@@ -188,6 +188,23 @@ export function validateSubmitRequest(body) {
|
|
|
188
188
|
const revisionErr = validateRevisionPayload(body.revision);
|
|
189
189
|
if (revisionErr)
|
|
190
190
|
return revisionErr;
|
|
191
|
+
if (body.push !== undefined) {
|
|
192
|
+
if (!isRecord(body.push))
|
|
193
|
+
return bad("push", "must be an object");
|
|
194
|
+
for (const field of ["before", "after"]) {
|
|
195
|
+
const value = body.push[field];
|
|
196
|
+
if (typeof value !== "string" || !/^[0-9a-f]{40}$/.test(value)) {
|
|
197
|
+
return bad(`push.${field}`, "must be a full commit sha");
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const ref = body.push.ref;
|
|
201
|
+
if (typeof ref !== "string" || !ref.startsWith("refs/heads/")) {
|
|
202
|
+
return bad("push.ref", "must be refs/heads/<branch>");
|
|
203
|
+
}
|
|
204
|
+
const refErr = validateBranch("push.ref", ref.slice("refs/heads/".length));
|
|
205
|
+
if (refErr)
|
|
206
|
+
return refErr;
|
|
207
|
+
}
|
|
191
208
|
for (const field of ["systemPromptAdd", "systemPromptOverride"]) {
|
|
192
209
|
const value = body[field];
|
|
193
210
|
if (value === undefined)
|
|
@@ -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,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { errorResponse } from "../errors.js";
|
|
2
|
+
import { canonicalRepoName } from "../../util/repo_name.js";
|
|
2
3
|
import { AppClient, findInstallationForRepo } from "../../github/app.js";
|
|
3
4
|
import { activateRepo, deactivateRepo, getRepo, listActiveRepos, updateRepoSettings, } from "../../store/repos.js";
|
|
4
5
|
import { readConfig, writeRepoConfig } from "../../config.js";
|
|
@@ -52,7 +53,7 @@ export async function handleReposRoute(request, url, githubApp) {
|
|
|
52
53
|
catch {
|
|
53
54
|
return errorResponse(400, "bad_request", "expected a JSON body");
|
|
54
55
|
}
|
|
55
|
-
const repo = String(body.repo ?? "");
|
|
56
|
+
const repo = canonicalRepoName(String(body.repo ?? ""));
|
|
56
57
|
if (!/^[^/]+\/[^/]+$/.test(repo)) {
|
|
57
58
|
return errorResponse(400, "bad_request", "repo must look like owner/repo");
|
|
58
59
|
}
|
|
@@ -120,7 +121,7 @@ export async function handleReposRoute(request, url, githubApp) {
|
|
|
120
121
|
catch {
|
|
121
122
|
return errorResponse(400, "bad_request", "expected a JSON body");
|
|
122
123
|
}
|
|
123
|
-
const repo = String(body.repo ?? "");
|
|
124
|
+
const repo = canonicalRepoName(String(body.repo ?? ""));
|
|
124
125
|
if (!/^[^/]+\/[^/]+$/.test(repo)) {
|
|
125
126
|
return errorResponse(400, "bad_request", "repo must look like owner/repo");
|
|
126
127
|
}
|
|
@@ -326,6 +327,16 @@ export async function handleReposRoute(request, url, githubApp) {
|
|
|
326
327
|
body.reviewScope === "incremental") {
|
|
327
328
|
patch.review_scope = body.reviewScope;
|
|
328
329
|
}
|
|
330
|
+
if (typeof body.watchOpenIssues === "boolean") {
|
|
331
|
+
patch.watch_open_issues = body.watchOpenIssues ? 1 : 0;
|
|
332
|
+
}
|
|
333
|
+
if (body.watchPushMode !== undefined) {
|
|
334
|
+
if (body.watchPushMode !== "queue" &&
|
|
335
|
+
body.watchPushMode !== "cancel-and-merge") {
|
|
336
|
+
return errorResponse(422, "invalid_watch_push_mode", "watchPushMode must be queue or cancel-and-merge.");
|
|
337
|
+
}
|
|
338
|
+
patch.watch_push_mode = body.watchPushMode;
|
|
339
|
+
}
|
|
329
340
|
updateRepoSettings(fullName, patch);
|
|
330
341
|
const init = {};
|
|
331
342
|
for (const key of [
|
|
@@ -335,6 +335,7 @@ export function repoTabs(fullName, on) {
|
|
|
335
335
|
{ id: "pulls", label: "Pull requests", path: `${href}/pulls` },
|
|
336
336
|
{ id: "knowledge", label: "Knowledge", path: `${href}/knowledge` },
|
|
337
337
|
{ id: "remote", label: "Remote reviews", path: `${href}/remote` },
|
|
338
|
+
{ id: "pushes", label: "Pushes", path: `${href}/pushes` },
|
|
338
339
|
{
|
|
339
340
|
id: "settings",
|
|
340
341
|
label: "Repository settings",
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import type { repoOverview } from "../../services/dashboard.ts";
|
|
2
|
-
export declare function renderRepo(username: string, data: ReturnType<typeof repoOverview>, webhookUrl: string
|
|
2
|
+
export declare function renderRepo(username: string, data: ReturnType<typeof repoOverview>, webhookUrl: string,
|
|
3
|
+
/** The commit watch card, rendered by `repo_pushes.ts`. */
|
|
4
|
+
commitWatch?: string): Response;
|