co-maintainer 0.6.8 → 0.6.10
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 +10 -0
- package/dist/src/cli/commands/set.js +23 -2
- package/dist/src/cli/review_args.d.ts +9 -0
- package/dist/src/cli/review_args.js +36 -1
- package/dist/src/cli/review_github.js +6 -2
- package/dist/src/cli/review_result.js +6 -5
- 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/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/checkout.js +14 -5
- package/dist/src/pr/codegraph_tools.js +5 -3
- package/dist/src/pr/reviewer.d.ts +2 -0
- package/dist/src/pr/reviewer.js +1 -1
- package/dist/src/remote/client.js +14 -4
- package/dist/src/remote/push_client.d.ts +7 -0
- package/dist/src/remote/push_client.js +287 -0
- package/dist/src/remote/server/body.d.ts +11 -0
- package/dist/src/remote/server/body.js +14 -5
- 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/server/api/repos.js +13 -2
- package/dist/src/server/app.js +5 -6
- package/dist/src/server/http.js +5 -0
- 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 +34 -5
- package/dist/src/server/pages/settings.js +1 -1
- package/dist/src/server/webhook/index.js +24 -7
- package/dist/src/services/dashboard.d.ts +46 -0
- package/dist/src/services/dashboard.js +24 -0
- package/dist/src/services/jobs.js +18 -3
- package/dist/src/services/push_review.d.ts +51 -0
- package/dist/src/services/push_review.js +878 -0
- 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 +179 -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 +107 -3
- 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/sessions.d.ts +3 -0
- package/dist/src/store/sessions.js +5 -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/dist/src/util/runtime.js +7 -0
- package/dist/src/util/sanitize.d.ts +6 -0
- package/dist/src/util/sanitize.js +10 -0
- package/package.json +1 -1
|
@@ -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)
|
|
@@ -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 [
|
package/dist/src/server/app.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* with a plain `Request`. */
|
|
3
3
|
import { VERSION } from "../version.js";
|
|
4
4
|
import { errorResponse } from "./errors.js";
|
|
5
|
+
import { readBoundedJson } from "../remote/server/body.js";
|
|
5
6
|
import { hasCsrfHeader, login, logout, readSessionToken, sessionCookieHeader, verifySession, } from "./auth.js";
|
|
6
7
|
import { memoryPasswordStore } from "./auth.js";
|
|
7
8
|
import { clientAddress, forwardedHttps } from "./proxy_headers.js";
|
|
@@ -43,13 +44,11 @@ async function handleLogin(request, deps, passwords, ip) {
|
|
|
43
44
|
if (deps.auth?.password === false) {
|
|
44
45
|
return errorResponse(403, "password_disabled", "password sign-in is disabled");
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
return errorResponse(400, "bad_request", "expected a JSON body");
|
|
47
|
+
const parsed = await readBoundedJson(request, 64 * 1024);
|
|
48
|
+
if (!parsed.ok) {
|
|
49
|
+
return errorResponse(parsed.status, parsed.code, parsed.message);
|
|
52
50
|
}
|
|
51
|
+
const body = parsed.value;
|
|
53
52
|
const result = await login(String(body.password ?? ""), passwords, ip);
|
|
54
53
|
if (!result)
|
|
55
54
|
return errorResponse(401, "unauthorized", "wrong password");
|
package/dist/src/server/http.js
CHANGED
|
@@ -103,6 +103,11 @@ export function serveHttp(app, port) {
|
|
|
103
103
|
server.once("listening", () => resolve());
|
|
104
104
|
server.once("error", reject);
|
|
105
105
|
});
|
|
106
|
+
// Slow-loris defence: cap how long a client may take to send headers and
|
|
107
|
+
// the full request. Responses (SSE) are unaffected — those are measured on
|
|
108
|
+
// the response side, not here.
|
|
109
|
+
server.headersTimeout = 20_000;
|
|
110
|
+
server.requestTimeout = 120_000;
|
|
106
111
|
server.listen(port);
|
|
107
112
|
return {
|
|
108
113
|
port,
|
|
@@ -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;
|
|
@@ -42,7 +42,9 @@ function seconds(ms) {
|
|
|
42
42
|
const s = Math.round(ms / 1000);
|
|
43
43
|
return s < 60 ? `${s} s` : `${Math.round(s / 60)} min`;
|
|
44
44
|
}
|
|
45
|
-
export function renderRepo(username, data, webhookUrl
|
|
45
|
+
export function renderRepo(username, data, webhookUrl,
|
|
46
|
+
/** The commit watch card, rendered by `repo_pushes.ts`. */
|
|
47
|
+
commitWatch = "") {
|
|
46
48
|
const name = data.repo.full_name;
|
|
47
49
|
const stats = data.stats;
|
|
48
50
|
const drift = data.drift;
|
|
@@ -134,6 +136,7 @@ export function renderRepo(username, data, webhookUrl) {
|
|
|
134
136
|
action: `<a class="btn gh sm" href="/repos/${text(name)}/settings">Change</a>`,
|
|
135
137
|
})}</div>
|
|
136
138
|
</div>
|
|
139
|
+
${commitWatch}
|
|
137
140
|
</div>
|
|
138
141
|
<script>
|
|
139
142
|
var repo = ${JSON.stringify(name)};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { repoPushes } from "../../services/dashboard.ts";
|
|
2
|
+
import type { WatchStatus } from "../../services/watch_status.ts";
|
|
3
|
+
/** The workflow a CI user copies, with this server's address filled in. */
|
|
4
|
+
export declare function commitWatchWorkflow(serverUrl: string, branch: string): string;
|
|
5
|
+
/** The overview card. */
|
|
6
|
+
export declare function commitWatchCard(fullName: string, status: WatchStatus, serverUrl: string, branch: string): string;
|
|
7
|
+
export declare function renderRepoPushes(username: string, fullName: string, data: ReturnType<typeof repoPushes>, status: WatchStatus): Response;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/** Commit watch on the dashboard: the card on a repository's overview that
|
|
2
|
+
* says whether pushes are watched and how to turn it on, and the Pushes tab
|
|
3
|
+
* that lists each push review. */
|
|
4
|
+
import { escapeHtml, empty, html, layout, repoTabs, text, when, } from "./layout.js";
|
|
5
|
+
import { badge, icon, section } from "./ui.js";
|
|
6
|
+
import { formatCost } from "./cost.js";
|
|
7
|
+
function short(sha) {
|
|
8
|
+
return (sha ?? "").slice(0, 7);
|
|
9
|
+
}
|
|
10
|
+
function viaLabel(via) {
|
|
11
|
+
if (via.includes("app") && via.includes("ci"))
|
|
12
|
+
return "App and CI";
|
|
13
|
+
if (via.includes("app"))
|
|
14
|
+
return "App";
|
|
15
|
+
if (via.includes("ci"))
|
|
16
|
+
return "CI";
|
|
17
|
+
return "unknown";
|
|
18
|
+
}
|
|
19
|
+
/** The workflow a CI user copies, with this server's address filled in. */
|
|
20
|
+
export function commitWatchWorkflow(serverUrl, branch) {
|
|
21
|
+
return `name: co-maintainer commit watch
|
|
22
|
+
on:
|
|
23
|
+
push:
|
|
24
|
+
branches: [${branch}]
|
|
25
|
+
|
|
26
|
+
permissions:
|
|
27
|
+
contents: read
|
|
28
|
+
|
|
29
|
+
jobs:
|
|
30
|
+
review:
|
|
31
|
+
runs-on: ubuntu-latest
|
|
32
|
+
steps:
|
|
33
|
+
- uses: actions/checkout@v4
|
|
34
|
+
- uses: GroophyLifefor/co-maintainer@v0
|
|
35
|
+
with:
|
|
36
|
+
remote-host: ${serverUrl || "https://your-server"}
|
|
37
|
+
remote-token: \${{ secrets.CO_MAINTAINER_TOKEN }}`;
|
|
38
|
+
}
|
|
39
|
+
function statusBadge(status) {
|
|
40
|
+
const app = status.app === "on";
|
|
41
|
+
if (app && status.ci)
|
|
42
|
+
return badge("emerald", "Watching via App and CI", {
|
|
43
|
+
icon: "circle-check",
|
|
44
|
+
});
|
|
45
|
+
if (app)
|
|
46
|
+
return badge("emerald", "Watching via GitHub App", {
|
|
47
|
+
icon: "circle-check",
|
|
48
|
+
});
|
|
49
|
+
if (status.ci)
|
|
50
|
+
return badge("emerald", "Watching via CI", { icon: "circle-check" });
|
|
51
|
+
return badge("neutral", "Off");
|
|
52
|
+
}
|
|
53
|
+
function statusLine(status) {
|
|
54
|
+
const last = status.lastPush;
|
|
55
|
+
const watching = status.app === "on" || status.ci;
|
|
56
|
+
if (!watching) {
|
|
57
|
+
return `<p class="muted" style="font-size:13px">Turn it on one of the two ways below. Nothing is reviewed until then.</p>`;
|
|
58
|
+
}
|
|
59
|
+
if (!last) {
|
|
60
|
+
return `<p class="muted" style="font-size:13px">Waiting for the first push…</p>`;
|
|
61
|
+
}
|
|
62
|
+
return `<p class="muted" style="font-size:13px">${icon("circle-check")} Last push <code>${text(short(last.head_sha))}</code> via ${text(viaLabel(last.via))}, ${when(last.created_at)}</p>`;
|
|
63
|
+
}
|
|
64
|
+
function appRow(status) {
|
|
65
|
+
const state = status.app === "on"
|
|
66
|
+
? "The Push event is on."
|
|
67
|
+
: status.app === "off"
|
|
68
|
+
? "The App is installed here, the Push event is off."
|
|
69
|
+
: status.app === "not-installed"
|
|
70
|
+
? "The App is not installed on this repository."
|
|
71
|
+
: "The events of the App could not be read.";
|
|
72
|
+
return `<div class="row"><div class="b">
|
|
73
|
+
<p class="strong">GitHub App</p>
|
|
74
|
+
<p class="muted" style="font-size:13px">${text(state)} In the App's settings open the
|
|
75
|
+
permissions and events page and tick <b>Push</b> under Subscribe to events. It applies to
|
|
76
|
+
every repository the App is installed on.</p>
|
|
77
|
+
</div><a class="btn out sm" href="https://github.com/settings/apps" target="_blank" rel="noopener">${icon("external-link")}App settings</a></div>`;
|
|
78
|
+
}
|
|
79
|
+
function ciRow(serverUrl, branch) {
|
|
80
|
+
return `<div class="row" style="display:block"><div class="b">
|
|
81
|
+
<p class="strong">CI</p>
|
|
82
|
+
<p class="muted" style="font-size:13px">Add this workflow and a <code>CO_MAINTAINER_TOKEN</code>
|
|
83
|
+
secret with a remote review token from Settings.</p>
|
|
84
|
+
</div>
|
|
85
|
+
<div class="code" data-commit-watch-yaml><span style="white-space:pre;overflow-x:auto;display:block">${escapeHtml(commitWatchWorkflow(serverUrl, branch))}</span><button type="button" data-copy title="Copy">${icon("copy")}</button></div></div>`;
|
|
86
|
+
}
|
|
87
|
+
/** The overview card. */
|
|
88
|
+
export function commitWatchCard(fullName, status, serverUrl, branch) {
|
|
89
|
+
return `<div class="card" id="commit-watch">${section(`${statusLine(status)}${appRow(status)}${ciRow(serverUrl, branch)}`, {
|
|
90
|
+
title: "Commit watch",
|
|
91
|
+
lead: `Review pushes to ${branch}.`,
|
|
92
|
+
action: `${statusBadge(status)} <a class="btn gh sm" href="/repos/${text(fullName)}/pushes">Pushes</a>`,
|
|
93
|
+
})}</div>`;
|
|
94
|
+
}
|
|
95
|
+
export function renderRepoPushes(username, fullName, data, status) {
|
|
96
|
+
const watched = status.app === "on" && status.ci
|
|
97
|
+
? "via the GitHub App and CI"
|
|
98
|
+
: status.app === "on"
|
|
99
|
+
? "via the GitHub App"
|
|
100
|
+
: status.ci
|
|
101
|
+
? "via CI"
|
|
102
|
+
: "not watched";
|
|
103
|
+
const rows = data.items.length === 0
|
|
104
|
+
? empty("No pushes reviewed yet", "Turn on commit watch on the overview of this repository. Only pushes after that are reviewed.")
|
|
105
|
+
: `<table>
|
|
106
|
+
<thead><tr><th>Push</th><th>Via</th><th>Status</th><th class="num">P0</th>
|
|
107
|
+
<th class="num">P1</th><th class="num">P2</th><th class="num">P3</th>
|
|
108
|
+
<th class="num">Issues opened</th><th class="num">Cost</th><th>When</th></tr></thead>
|
|
109
|
+
<tbody>
|
|
110
|
+
${data.items
|
|
111
|
+
.map((review) => `<tr>
|
|
112
|
+
<td><code>${text(short(review.base_sha))}..${text(short(review.head_sha))}</code></td>
|
|
113
|
+
<td>${text(viaLabel(review.via))}</td>
|
|
114
|
+
<td>${text(review.status)}</td>
|
|
115
|
+
<td class="num">${review.p0}</td>
|
|
116
|
+
<td class="num">${review.p1}</td>
|
|
117
|
+
<td class="num">${review.p2}</td>
|
|
118
|
+
<td class="num">${review.p3}</td>
|
|
119
|
+
<td class="num">${review.issuesOpened}</td>
|
|
120
|
+
<td class="num">${formatCost(review)}</td>
|
|
121
|
+
<td class="muted">${when(review.created_at)}</td>
|
|
122
|
+
</tr>`)
|
|
123
|
+
.join("")}
|
|
124
|
+
</tbody>
|
|
125
|
+
</table>`;
|
|
126
|
+
return html(layout({
|
|
127
|
+
title: `${fullName} · Pushes · co-maintainer`,
|
|
128
|
+
username,
|
|
129
|
+
active: "/",
|
|
130
|
+
body: `<div class="wrap">
|
|
131
|
+
${repoTabs(fullName, "pushes")}
|
|
132
|
+
<div>
|
|
133
|
+
<div class="crumbs"><a href="/">Repositories</a> / ${text(fullName)}</div>
|
|
134
|
+
<div class="pagehead">
|
|
135
|
+
<div>
|
|
136
|
+
<h1>Pushes</h1>
|
|
137
|
+
<p class="lead">Commit watch reviews of pushes to the default branch. This repository is ${text(watched)}. ${data.openIssues} open ${data.openIssues === 1 ? "issue" : "issues"}.</p>
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
<div class="card"><div class="bd flush">${rows}</div></div>
|
|
141
|
+
</div>
|
|
142
|
+
</div>`,
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
@@ -290,6 +290,25 @@ export function renderRepoSettings(username, repo, config, probeReport) {
|
|
|
290
290
|
</div>
|
|
291
291
|
<div class="ft"><button class="primary" id="save-auto">Save</button></div>
|
|
292
292
|
</div>
|
|
293
|
+
<div class="card" data-async id="commit-watch-settings">
|
|
294
|
+
${skSlot()}
|
|
295
|
+
<div class="hd"><h2>Commit watch</h2></div>
|
|
296
|
+
<div class="bd">
|
|
297
|
+
<div style="display:flex;align-items:center;gap:14px;margin-bottom:22px">
|
|
298
|
+
<button class="tg${repo.watch_open_issues === 0 ? "" : " on"}" id="watch-issues"></button>
|
|
299
|
+
<div>Open a GitHub issue for each P0 and P1 finding</div>
|
|
300
|
+
</div>
|
|
301
|
+
<div class="field">
|
|
302
|
+
<label>When pushes come in a row</label>
|
|
303
|
+
<div class="seg" id="watch-mode-seg">
|
|
304
|
+
<button type="button" data-v="queue" class="${repo.watch_push_mode === "cancel-and-merge" ? "" : "on"}">Review each push in turn</button>
|
|
305
|
+
<button type="button" data-v="cancel-and-merge" class="${repo.watch_push_mode === "cancel-and-merge" ? "on" : ""}">Cancel and merge into the newest</button>
|
|
306
|
+
</div>
|
|
307
|
+
<div class="hint">Cancel and merge stops a waiting or running review and reviews the pushes together.</div>
|
|
308
|
+
</div>
|
|
309
|
+
</div>
|
|
310
|
+
<div class="ft"><button class="primary" id="save-watch">Save</button></div>
|
|
311
|
+
</div>
|
|
293
312
|
<div class="card" data-async>
|
|
294
313
|
${skSlot()}
|
|
295
314
|
<div class="hd"><h2>Custom review instructions</h2></div>
|
|
@@ -794,6 +813,29 @@ if (document.getElementById("auto")) {
|
|
|
794
813
|
document.getElementById("codegraph").addEventListener("click", function() {
|
|
795
814
|
this.classList.toggle("on");
|
|
796
815
|
});
|
|
816
|
+
document.getElementById("watch-issues").addEventListener("click", function() {
|
|
817
|
+
this.classList.toggle("on");
|
|
818
|
+
});
|
|
819
|
+
function selectedWatchMode() {
|
|
820
|
+
var on = document.querySelector("#watch-mode-seg button.on");
|
|
821
|
+
return on ? on.getAttribute("data-v") : "queue";
|
|
822
|
+
}
|
|
823
|
+
document.querySelectorAll("#watch-mode-seg button").forEach(function(btn) {
|
|
824
|
+
btn.addEventListener("click", function() {
|
|
825
|
+
document.querySelectorAll("#watch-mode-seg button").forEach(function(b) {
|
|
826
|
+
b.classList.toggle("on", b === btn);
|
|
827
|
+
});
|
|
828
|
+
});
|
|
829
|
+
});
|
|
830
|
+
function watchBody() {
|
|
831
|
+
return {
|
|
832
|
+
watchOpenIssues: document.getElementById("watch-issues").classList.contains("on"),
|
|
833
|
+
watchPushMode: selectedWatchMode()
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
document.getElementById("save-watch").addEventListener("click", function() {
|
|
837
|
+
save(this, watchBody());
|
|
838
|
+
});
|
|
797
839
|
document.getElementById("save-init").addEventListener("click", function() {
|
|
798
840
|
save(this, {
|
|
799
841
|
maxPrMonths: initNumber("months"),
|
|
@@ -848,7 +890,9 @@ document.getElementById("save-changes").addEventListener("click", function() {
|
|
|
848
890
|
maxPrMonths: initNumber("months"),
|
|
849
891
|
maxCommits: initNumber("commits"),
|
|
850
892
|
maxPullRequestChangeLines: initNumber("lines"),
|
|
851
|
-
maxComments: initNumber("comments")
|
|
893
|
+
maxComments: initNumber("comments"),
|
|
894
|
+
watchOpenIssues: watchBody().watchOpenIssues,
|
|
895
|
+
watchPushMode: watchBody().watchPushMode
|
|
852
896
|
};
|
|
853
897
|
if (select.value === "legacy") {
|
|
854
898
|
var auto = document.getElementById("auto");
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { clearOauthStateCookieHeader, clearSessionCookieHeader, createSession, login, logout, oauthStateCookieHeader, randomToken, readOauthState, readSessionToken, sessionCookieHeader, verifySession, } from "../auth.js";
|
|
2
2
|
import { githubAuthorizeUrl, githubLoginFromCode } from "../../github/oauth.js";
|
|
3
|
+
import { readBoundedUtf8 } from "../../remote/server/body.js";
|
|
3
4
|
import { handleClient, handleLogo, handleStyles } from "../assets.js";
|
|
4
|
-
import { activityFeed, listReposForHome, prDetail, repoKnowledge, RepoNotFound, repoOverview, repoPulls, repoRemoteReviews, runningJobs, skippedDeliveries, statsForRange, } from "../../services/dashboard.js";
|
|
5
|
+
import { activityFeed, listReposForHome, prDetail, repoKnowledge, RepoNotFound, repoOverview, repoPulls, repoPushes, repoRemoteReviews, runningJobs, skippedDeliveries, statsForRange, } from "../../services/dashboard.js";
|
|
5
6
|
import { escapeHtml, html, notFound } from "./layout.js";
|
|
6
7
|
import { formatCostTotal } from "./cost.js";
|
|
7
8
|
import { readConfig, writeUserConfig } from "../../config.js";
|
|
@@ -13,6 +14,9 @@ import { renderAddRepo } from "./add_repo.js";
|
|
|
13
14
|
import { renderRepo } from "./repo.js";
|
|
14
15
|
import { renderRepoPulls } from "./repo_prs.js";
|
|
15
16
|
import { renderRepoRemote } from "./repo_remote.js";
|
|
17
|
+
import { commitWatchCard, renderRepoPushes } from "./repo_pushes.js";
|
|
18
|
+
import { watchStatus } from "../../services/watch_status.js";
|
|
19
|
+
import { defaultBranchForRepo } from "../../remote/server/routes.js";
|
|
16
20
|
import { renderPr } from "./pr.js";
|
|
17
21
|
import { renderKnowledge } from "./knowledge.js";
|
|
18
22
|
import { renderRepoSettings } from "./repo_settings.js";
|
|
@@ -27,7 +31,19 @@ import { getLogsSince } from "../../services/jobs.js";
|
|
|
27
31
|
import { listInstallationsWithRepos, listOpenPulls } from "../../github/app.js";
|
|
28
32
|
import { setupChecklist } from "../../services/setup_checklist.js";
|
|
29
33
|
import { appReady, filterRepoList, repoState, } from "../../services/repo_list.js";
|
|
30
|
-
|
|
34
|
+
/** The address a CI step reaches this server at: the saved webhook URL's
|
|
35
|
+
* origin, otherwise the address this page was opened at. */
|
|
36
|
+
function serverOrigin(webhookUrl, url) {
|
|
37
|
+
try {
|
|
38
|
+
if (webhookUrl)
|
|
39
|
+
return new URL(webhookUrl).origin;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// fall through to the page's own origin
|
|
43
|
+
}
|
|
44
|
+
return url.origin;
|
|
45
|
+
}
|
|
46
|
+
const REPO = /^\/repos\/([^/]+)\/([^/]+)(?:\/(pulls|knowledge|settings|remote|pushes)(?:\/(\d+))?)?$/;
|
|
31
47
|
/** Matches a repository page URL. Only `pulls` is keyed by a number, so a stray
|
|
32
48
|
* suffix such as `/repos/o/r/remote/7` must fall through to a 404 rather than
|
|
33
49
|
* render the listing and silently drop the number. */
|
|
@@ -183,7 +199,11 @@ export async function handlePageRequest(request, deps, ip) {
|
|
|
183
199
|
const pr = match[4] ? Number(match[4]) : undefined;
|
|
184
200
|
if (!sub) {
|
|
185
201
|
const config = readConfig();
|
|
186
|
-
|
|
202
|
+
const webhookUrl = config.webhookUrl || deps.webhookUrl || "";
|
|
203
|
+
return renderRepo(username, repoOverview(fullName), webhookUrl, commitWatchCard(fullName, await watchStatus(fullName), serverOrigin(webhookUrl, url), (await defaultBranchForRepo(fullName)) ?? "main"));
|
|
204
|
+
}
|
|
205
|
+
if (sub === "pushes") {
|
|
206
|
+
return renderRepoPushes(username, fullName, repoPushes(fullName), await watchStatus(fullName));
|
|
187
207
|
}
|
|
188
208
|
if (sub === "pulls" && pr) {
|
|
189
209
|
return renderPr(username, fullName, prDetail(fullName, pr));
|
|
@@ -331,8 +351,16 @@ async function sessionOf(request) {
|
|
|
331
351
|
return await verifySession(token);
|
|
332
352
|
}
|
|
333
353
|
function safeNext(value) {
|
|
354
|
+
// A path-only redirect. It must start with a single "/", and may not hold a
|
|
355
|
+
// backslash (browsers read "/\host" as "//host") or a control character (a
|
|
356
|
+
// tab or newline is stripped, turning "/\t/host" into "//host") — both would
|
|
357
|
+
// send the browser to another origin.
|
|
334
358
|
if (!value || !value.startsWith("/") || value.startsWith("//"))
|
|
335
359
|
return "/";
|
|
360
|
+
for (let i = 0; i < value.length; i++) {
|
|
361
|
+
if (value.charCodeAt(i) <= 0x1f || value[i] === "\\")
|
|
362
|
+
return "/";
|
|
363
|
+
}
|
|
336
364
|
return value;
|
|
337
365
|
}
|
|
338
366
|
/** The externally visible origin. Behind a trusted proxy the browser reached
|
|
@@ -426,7 +454,8 @@ async function finishAppManifest(request, url) {
|
|
|
426
454
|
return Response.redirect(installUrl, 303);
|
|
427
455
|
}
|
|
428
456
|
async function handleLoginForm(request, deps, ip, auth) {
|
|
429
|
-
const
|
|
457
|
+
const bounded = await readBoundedUtf8(request, 64 * 1024);
|
|
458
|
+
const form = new URLSearchParams(bounded.ok ? bounded.text : "");
|
|
430
459
|
const password = String(form.get("password") ?? "");
|
|
431
460
|
const next = safeNext(String(form.get("next") ?? "/"));
|
|
432
461
|
if (!auth.password) {
|
|
@@ -487,7 +516,7 @@ async function handleGithubCallback(request, url, githubOAuth, deps) {
|
|
|
487
516
|
return new Response(null, {
|
|
488
517
|
status: 303,
|
|
489
518
|
headers: {
|
|
490
|
-
location: saved.next,
|
|
519
|
+
location: safeNext(saved.next),
|
|
491
520
|
"set-cookie": sessionCookieHeader(result.token, Boolean(deps.secureCookie)),
|
|
492
521
|
},
|
|
493
522
|
});
|
|
@@ -225,7 +225,7 @@ function remoteCard(config) {
|
|
|
225
225
|
${skSlot()}
|
|
226
226
|
<div class="hd"><h2>Remote review tokens</h2></div>
|
|
227
227
|
<div class="bd">
|
|
228
|
-
<p class="muted" style="margin:0 0 16px">Bearer tokens for <code>co-maintainer review --remote</code>. The secret is shown once when created.</p>
|
|
228
|
+
<p class="muted" style="margin:0 0 16px">Bearer tokens for <code>co-maintainer review --remote</code>. The secret is shown once when created. Each token can review and read the guides of <strong>every active repository</strong> on this server, so treat a token as server-wide and revoke a leaked one.</p>
|
|
229
229
|
<div id="remote-token-secret" class="secret" hidden></div>
|
|
230
230
|
<div id="remote-token-list" class="muted">Loading…</div>
|
|
231
231
|
<div class="two" style="max-width:none;margin-top:16px">
|