co-maintainer 0.7.6 → 0.7.7-beta.1
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/cli/commands/serve.js +2 -0
- package/dist/src/server/pages/repo_settings.js +8 -0
- package/dist/src/services/review.d.ts +2 -0
- package/dist/src/services/review.js +11 -6
- package/dist/src/services/review_policy.d.ts +12 -0
- package/dist/src/services/review_policy.js +29 -1
- package/dist/src/services/skip_commands.d.ts +27 -0
- package/dist/src/services/skip_commands.js +132 -0
- package/dist/src/services/webhook.js +61 -1
- package/dist/src/store/migrations.js +6 -0
- package/dist/src/store/rows.d.ts +4 -0
- package/dist/src/store/subjects.d.ts +9 -0
- package/dist/src/store/subjects.js +18 -0
- package/package.json +1 -1
package/dist/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { registerSkipJobHandler } from "../../services/skip_commands.js";
|
|
1
2
|
import { readConfig, resolveAppPrivateKey, appPrivateKeyFileMissing, } from "../../config.js";
|
|
2
3
|
import { appDbPath, closeAppDb, openAppDb } from "../../store/app_db.js";
|
|
3
4
|
import { createApp } from "../../server/app.js";
|
|
@@ -179,6 +180,7 @@ export async function runServe(args) {
|
|
|
179
180
|
registerReplyJobHandler();
|
|
180
181
|
registerPushReviewHandlers();
|
|
181
182
|
registerWatchCommentHandler();
|
|
183
|
+
registerSkipJobHandler();
|
|
182
184
|
// Before the orphans run again: a job still marked running keeps its
|
|
183
185
|
// extension folder, which tells its rerun what the restart cut off.
|
|
184
186
|
await removeServeRunFolders(new Set(listJobs({ status: "running" }).map((job) => job.id)));
|
|
@@ -242,6 +242,9 @@ export function renderRepoSettings(username, repo, config, probeReport) {
|
|
|
242
242
|
<fieldset id="p-requesters" class="ticks">
|
|
243
243
|
<legend>Who can ask for a review</legend>
|
|
244
244
|
</fieldset>
|
|
245
|
+
<fieldset id="p-skippers" class="ticks">
|
|
246
|
+
<legend>Who else can skip a failed review or turn reviews off (the owner always can)</legend>
|
|
247
|
+
</fieldset>
|
|
245
248
|
</details>
|
|
246
249
|
</div>
|
|
247
250
|
</div>
|
|
@@ -443,6 +446,7 @@ function fromPolicy(policy) {
|
|
|
443
446
|
def: policy.default, label: policy.requestLabel,
|
|
444
447
|
command: policy.requestCommand,
|
|
445
448
|
requesters: policy.requesters.slice(), scope: policy.approvalScope,
|
|
449
|
+
skippers: (policy.skippers || []).slice(),
|
|
446
450
|
max: policy.maxRounds === undefined ? "" : String(policy.maxRounds)
|
|
447
451
|
};
|
|
448
452
|
}
|
|
@@ -467,6 +471,7 @@ function toPolicy() {
|
|
|
467
471
|
}),
|
|
468
472
|
default: state.def, requestLabel: state.label,
|
|
469
473
|
requestCommand: state.command, requesters: state.requesters,
|
|
474
|
+
skippers: state.skippers,
|
|
470
475
|
approvalScope: state.scope,
|
|
471
476
|
maxRounds: state.max.trim() === "" ? undefined : Number(state.max)
|
|
472
477
|
};
|
|
@@ -607,6 +612,9 @@ function renderSettings() {
|
|
|
607
612
|
var box = document.getElementById("p-requesters");
|
|
608
613
|
box.querySelectorAll("label").forEach(function(n) { n.remove(); });
|
|
609
614
|
tickList(box, "p-req-", function() { return state.requesters; }, function(next) { state.requesters = next; });
|
|
615
|
+
var skipBox = document.getElementById("p-skippers");
|
|
616
|
+
skipBox.querySelectorAll("label").forEach(function(n) { n.remove(); });
|
|
617
|
+
tickList(skipBox, "p-skip-", function() { return state.skippers; }, function(next) { state.skippers = next; });
|
|
610
618
|
syncPolicyVisibility();
|
|
611
619
|
}
|
|
612
620
|
function syncPolicyVisibility() {
|
|
@@ -15,6 +15,8 @@ export declare function humanCopy(text: string): string;
|
|
|
15
15
|
/** The one note a failed review leaves on the pull request: the short line a
|
|
16
16
|
* maintainer sees and a link to the job on the dashboard, where the provider's
|
|
17
17
|
* own reason is kept. Never the raw provider body, never a retry command. */
|
|
18
|
+
/** The paragraph a failed review's note ends with. */
|
|
19
|
+
export declare const SKIP_HINT = "To merge without this review, the repository owner can comment `/co-maintainer skip-this-commit`. The next commit is reviewed again. `/co-maintainer skip-this-pr` turns reviews off for this pull request.";
|
|
18
20
|
export declare function failedNoteBody(job: JobRow): string;
|
|
19
21
|
export declare function splitInline(findings: ParsedFinding[], files: Json[]): {
|
|
20
22
|
inline: {
|
|
@@ -78,9 +78,11 @@ function dashboardOrigin() {
|
|
|
78
78
|
/** The one note a failed review leaves on the pull request: the short line a
|
|
79
79
|
* maintainer sees and a link to the job on the dashboard, where the provider's
|
|
80
80
|
* own reason is kept. Never the raw provider body, never a retry command. */
|
|
81
|
+
/** The paragraph a failed review's note ends with. */
|
|
82
|
+
export const SKIP_HINT = "To merge without this review, the repository owner can comment `/co-maintainer skip-this-commit`. The next commit is reviewed again. `/co-maintainer skip-this-pr` turns reviews off for this pull request.";
|
|
81
83
|
export function failedNoteBody(job) {
|
|
82
84
|
return (`${REVIEW_FAILED_NOTE_START}. See the error on the dashboard: ` +
|
|
83
|
-
`${dashboardOrigin()}/activity/${job.id}`);
|
|
85
|
+
`${dashboardOrigin()}/activity/${job.id}\n\n${SKIP_HINT}`);
|
|
84
86
|
}
|
|
85
87
|
/** The note already left for this push, if any, so a second failure or a retry
|
|
86
88
|
* edits that one instead of opening a duplicate. */
|
|
@@ -489,7 +491,9 @@ async function stoppedReview(client, job, reviewId, checkRunId, log) {
|
|
|
489
491
|
}, log);
|
|
490
492
|
log("info", "stopped, nothing was posted");
|
|
491
493
|
}
|
|
492
|
-
async function finishCheck(client, job, checkRunId, conclusion, title, findings, log
|
|
494
|
+
async function finishCheck(client, job, checkRunId, conclusion, title, findings, log,
|
|
495
|
+
/** Replaces the findings count, for a check that reviewed nothing. */
|
|
496
|
+
summary) {
|
|
493
497
|
// A closed finding was fixed. Counting it would report work that is done.
|
|
494
498
|
const open = findings.filter((finding) => finding.state !== "closed");
|
|
495
499
|
await updateCheck(client, job, checkRunId, {
|
|
@@ -498,9 +502,10 @@ async function finishCheck(client, job, checkRunId, conclusion, title, findings,
|
|
|
498
502
|
completed_at: new Date().toISOString(),
|
|
499
503
|
output: {
|
|
500
504
|
title: humanCopy(title),
|
|
501
|
-
summary: humanCopy(
|
|
502
|
-
|
|
503
|
-
|
|
505
|
+
summary: humanCopy(summary ??
|
|
506
|
+
(open.length === 0
|
|
507
|
+
? "No actionable findings."
|
|
508
|
+
: `${open.length} finding(s) reported.`)),
|
|
504
509
|
annotations: checkAnnotations(open),
|
|
505
510
|
},
|
|
506
511
|
}, log);
|
|
@@ -677,7 +682,7 @@ export async function runReviewJob(job, log, client, ai, signal) {
|
|
|
677
682
|
}
|
|
678
683
|
}
|
|
679
684
|
if (github && review?.check_run_id) {
|
|
680
|
-
await finishCheck(github, job, review.check_run_id, "failure", "Review job failed.", listFindingsForReview(review.id), log);
|
|
685
|
+
await finishCheck(github, job, review.check_run_id, "failure", "Review job failed.", listFindingsForReview(review.id), log, `This commit was not reviewed. See the error on the dashboard: ${dashboardOrigin()}/activity/${job.id}\n\n${SKIP_HINT}`);
|
|
681
686
|
}
|
|
682
687
|
throw error;
|
|
683
688
|
}
|
|
@@ -37,6 +37,10 @@ export type ReviewPolicy = {
|
|
|
37
37
|
requestLabel: string;
|
|
38
38
|
requestCommand: string;
|
|
39
39
|
requesters: Association[];
|
|
40
|
+
/** Who besides the repository owner may comment `/co-maintainer
|
|
41
|
+
* skip-this-commit` or `/co-maintainer skip-this-pr`. The owner always
|
|
42
|
+
* may. Empty by default. */
|
|
43
|
+
skippers: Association[];
|
|
40
44
|
/** `head`: a request covers the commit it was made on. `pull-request`: the
|
|
41
45
|
* first request covers every later push. */
|
|
42
46
|
approvalScope: "head" | "pull-request";
|
|
@@ -65,6 +69,7 @@ export declare const DEFAULT_POLICY_SETTINGS: {
|
|
|
65
69
|
readonly requestLabel: "co-maintainer:review";
|
|
66
70
|
readonly requestCommand: "/co-maintainer review";
|
|
67
71
|
readonly requesters: ("OWNER" | "MEMBER" | "COLLABORATOR" | "CONTRIBUTOR" | "FIRST_TIME_CONTRIBUTOR" | "FIRST_TIMER" | "NONE")[];
|
|
72
|
+
readonly skippers: readonly [];
|
|
68
73
|
readonly approvalScope: "head";
|
|
69
74
|
};
|
|
70
75
|
export declare const TEMPLATES: Record<string, PolicyInput>;
|
|
@@ -85,6 +90,13 @@ export declare function evaluatePolicy(policy: ReviewPolicy, facts: PolicyFacts)
|
|
|
85
90
|
* request forward, and only once something was actually reviewed or queued. */
|
|
86
91
|
export declare function carriesEarlierRequest(policy: ReviewPolicy, hasEarlierReview: boolean): boolean;
|
|
87
92
|
/** Whether `body` starts with the request command as a whole word. */
|
|
93
|
+
export type SkipCommand = "skip-this-commit" | "skip-this-pr";
|
|
94
|
+
/** `/co-maintainer skip-this-commit` or `/co-maintainer skip-this-pr` at the
|
|
95
|
+
* start of a comment. The words are fixed, unlike the request command. */
|
|
96
|
+
export declare function skipCommandOf(body: string): SkipCommand | undefined;
|
|
97
|
+
/** The repository owner always may skip. Anyone else only when the
|
|
98
|
+
* repository's policy lists their association. */
|
|
99
|
+
export declare function maySkip(policy: ReviewPolicy, association: string): boolean;
|
|
88
100
|
export declare function isRequestCommand(body: string, command: string): boolean;
|
|
89
101
|
type Check<T> = {
|
|
90
102
|
ok: true;
|
|
@@ -20,6 +20,7 @@ export const DEFAULT_POLICY_SETTINGS = {
|
|
|
20
20
|
requestLabel: "co-maintainer:review",
|
|
21
21
|
requestCommand: "/co-maintainer review",
|
|
22
22
|
requesters: TRUSTED,
|
|
23
|
+
skippers: [],
|
|
23
24
|
approvalScope: "head",
|
|
24
25
|
};
|
|
25
26
|
const SKIP_DRAFTS = {
|
|
@@ -144,7 +145,21 @@ export function evaluatePolicy(policy, facts) {
|
|
|
144
145
|
export function carriesEarlierRequest(policy, hasEarlierReview) {
|
|
145
146
|
return policy.approvalScope === "pull-request" && hasEarlierReview;
|
|
146
147
|
}
|
|
147
|
-
/**
|
|
148
|
+
/** `/co-maintainer skip-this-commit` or `/co-maintainer skip-this-pr` at the
|
|
149
|
+
* start of a comment. The words are fixed, unlike the request command. */
|
|
150
|
+
export function skipCommandOf(body) {
|
|
151
|
+
for (const command of ["skip-this-commit", "skip-this-pr"]) {
|
|
152
|
+
if (isRequestCommand(body, `/co-maintainer ${command}`))
|
|
153
|
+
return command;
|
|
154
|
+
}
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
/** The repository owner always may skip. Anyone else only when the
|
|
158
|
+
* repository's policy lists their association. */
|
|
159
|
+
export function maySkip(policy, association) {
|
|
160
|
+
return (association === "OWNER" ||
|
|
161
|
+
(policy.skippers ?? []).includes(association));
|
|
162
|
+
}
|
|
148
163
|
export function isRequestCommand(body, command) {
|
|
149
164
|
const text = body.trim().toLowerCase();
|
|
150
165
|
const wanted = command.trim().toLowerCase();
|
|
@@ -270,6 +285,7 @@ export function parsePolicy(value) {
|
|
|
270
285
|
"requestLabel",
|
|
271
286
|
"requestCommand",
|
|
272
287
|
"requesters",
|
|
288
|
+
"skippers",
|
|
273
289
|
"approvalScope",
|
|
274
290
|
"maxRounds",
|
|
275
291
|
], "policy");
|
|
@@ -323,6 +339,12 @@ export function parsePolicy(value) {
|
|
|
323
339
|
return parsed;
|
|
324
340
|
input.requesters = parsed.value;
|
|
325
341
|
}
|
|
342
|
+
if (value.skippers !== undefined) {
|
|
343
|
+
const parsed = associations(value.skippers, "skippers");
|
|
344
|
+
if (!parsed.ok)
|
|
345
|
+
return parsed;
|
|
346
|
+
input.skippers = parsed.value;
|
|
347
|
+
}
|
|
326
348
|
if (value.approvalScope !== undefined) {
|
|
327
349
|
if (value.approvalScope !== "head" &&
|
|
328
350
|
value.approvalScope !== "pull-request") {
|
|
@@ -449,6 +471,12 @@ export function describePolicy(policy) {
|
|
|
449
471
|
if (policy.maxRounds !== undefined) {
|
|
450
472
|
lines.push(`A pull request gets at most ${policy.maxRounds} ${policy.maxRounds === 1 ? "review" : "reviews"} from the webhook.`);
|
|
451
473
|
}
|
|
474
|
+
// The owner always may, so only a widened list is worth a line.
|
|
475
|
+
const skippers = (policy.skippers ?? []).filter((a) => a !== "OWNER");
|
|
476
|
+
if (skippers.length > 0) {
|
|
477
|
+
const who = joinWords(["OWNER", ...skippers].map((a) => ASSOCIATION_WORDS[a]), "and");
|
|
478
|
+
lines.push(`${who.charAt(0).toUpperCase()}${who.slice(1)} can skip a failed review or turn reviews off for a pull request.`);
|
|
479
|
+
}
|
|
452
480
|
return lines;
|
|
453
481
|
}
|
|
454
482
|
function canonical(value) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** `/co-maintainer skip-this-commit` and `/co-maintainer skip-this-pr`.
|
|
2
|
+
*
|
|
3
|
+
* A failed App review ends its check run as `failure`, which blocks a merge
|
|
4
|
+
* where the check is required. These commands let the owner, and whoever the
|
|
5
|
+
* repository's policy names, get past it. The skipped check run ends as
|
|
6
|
+
* `skipped` and not `success`: both let a required check pass, but `skipped`
|
|
7
|
+
* does not claim a review happened. The webhook decides who may run them and
|
|
8
|
+
* ignores anyone else. This job does the GitHub side. */
|
|
9
|
+
import type { GitHubClient } from "../types.ts";
|
|
10
|
+
import type { JobRow } from "../store/rows.ts";
|
|
11
|
+
import { type LogFn } from "./jobs.ts";
|
|
12
|
+
export declare const SKIP_JOB = "skip";
|
|
13
|
+
export type SkipJobArgs = {
|
|
14
|
+
/** The two comment commands, `reviews-on` for a request that turned a
|
|
15
|
+
* pull request's reviews back on, and `pr-off` for a new commit on a pull
|
|
16
|
+
* request whose reviews are off. */
|
|
17
|
+
command: "skip-this-commit" | "skip-this-pr" | "reviews-on" | "pr-off";
|
|
18
|
+
by: string | null;
|
|
19
|
+
headSha?: string | null;
|
|
20
|
+
};
|
|
21
|
+
export declare function skippedCommitText(sha: string, by: string | null): string;
|
|
22
|
+
export declare function nothingToSkipText(sha: string): string;
|
|
23
|
+
export declare function reviewsOffText(by: string | null): string;
|
|
24
|
+
export declare const ALREADY_OFF_TEXT = "Reviews are already off for this pull request. Comment `/co-maintainer review` to turn them back on.";
|
|
25
|
+
export declare function reviewsOnText(by: string | null): string;
|
|
26
|
+
export declare function runSkipJob(job: JobRow, log: LogFn, client?: GitHubClient): Promise<void>;
|
|
27
|
+
export declare function registerSkipJobHandler(): void;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { getRepo } from "../store/repos.js";
|
|
2
|
+
import { findNoteCommentId, listReviewsForPr } from "../store/reviews.js";
|
|
3
|
+
import { getQueuedJob, getRunningJobByKey } from "../store/jobs.js";
|
|
4
|
+
import { prReviewsOff, setPrReviewsOff } from "../store/subjects.js";
|
|
5
|
+
import { cancel, registerHandler } from "./jobs.js";
|
|
6
|
+
import { clientFor, resolveInstallationId } from "./review.js";
|
|
7
|
+
import { redact } from "../util/redact.js";
|
|
8
|
+
export const SKIP_JOB = "skip";
|
|
9
|
+
const CHECK_NAME = "co-maintainer review";
|
|
10
|
+
const short = (sha) => sha.slice(0, 7);
|
|
11
|
+
const who = (by) => (by ? `\`@${by}\`` : "A maintainer");
|
|
12
|
+
export function skippedCommitText(sha, by) {
|
|
13
|
+
return `co-maintainer skipped the review of \`${short(sha)}\` at the request of ${by ? `\`@${by}\`` : "a maintainer"}. The next commit is reviewed again.`;
|
|
14
|
+
}
|
|
15
|
+
export function nothingToSkipText(sha) {
|
|
16
|
+
return `Nothing to skip. Only a failed review of the latest commit can be skipped, and the review of \`${short(sha)}\` did not fail.`;
|
|
17
|
+
}
|
|
18
|
+
export function reviewsOffText(by) {
|
|
19
|
+
return `${who(by)} turned co-maintainer reviews off for this pull request. Comment \`/co-maintainer review\` to turn them back on.`;
|
|
20
|
+
}
|
|
21
|
+
export const ALREADY_OFF_TEXT = "Reviews are already off for this pull request. Comment `/co-maintainer review` to turn them back on.";
|
|
22
|
+
export function reviewsOnText(by) {
|
|
23
|
+
return `${who(by)} turned co-maintainer reviews back on for this pull request.`;
|
|
24
|
+
}
|
|
25
|
+
async function comment(client, job, body) {
|
|
26
|
+
if (!client.write)
|
|
27
|
+
throw new Error("this GitHub client cannot post");
|
|
28
|
+
await client.write(`repos/${job.repo}/issues/${job.pr_number}/comments`, { body });
|
|
29
|
+
}
|
|
30
|
+
/** A check run for `sha` that is already done as `skipped`. It is the newest
|
|
31
|
+
* run of the check on that commit, so it is the one a required check reads. */
|
|
32
|
+
async function skippedCheck(client, job, sha, title, summary, log) {
|
|
33
|
+
if (!client.createCheckRun) {
|
|
34
|
+
log("info", "this GitHub client cannot create check runs");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
await client.createCheckRun(`repos/${job.repo}/check-runs`, {
|
|
38
|
+
name: CHECK_NAME,
|
|
39
|
+
head_sha: sha,
|
|
40
|
+
status: "completed",
|
|
41
|
+
conclusion: "skipped",
|
|
42
|
+
completed_at: new Date().toISOString(),
|
|
43
|
+
output: { title, summary },
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async function githubFor(job, client) {
|
|
47
|
+
if (client)
|
|
48
|
+
return client;
|
|
49
|
+
const id = getRepo(job.repo)?.installation_id ??
|
|
50
|
+
(await resolveInstallationId(job.repo));
|
|
51
|
+
if (id === undefined || id === null) {
|
|
52
|
+
throw new Error(`no GitHub App installation stored for ${job.repo}`);
|
|
53
|
+
}
|
|
54
|
+
return clientFor(id);
|
|
55
|
+
}
|
|
56
|
+
export async function runSkipJob(job, log, client) {
|
|
57
|
+
if (job.pr_number === null)
|
|
58
|
+
throw new Error("skip job has no pull request");
|
|
59
|
+
const args = JSON.parse(job.args || "{}");
|
|
60
|
+
const github = await githubFor(job, client);
|
|
61
|
+
const pull = await github.request(`repos/${job.repo}/pulls/${job.pr_number}`);
|
|
62
|
+
const head = args.headSha || String(pull.head?.sha ?? "");
|
|
63
|
+
if (!head)
|
|
64
|
+
throw new Error("the pull request has no head commit");
|
|
65
|
+
switch (args.command) {
|
|
66
|
+
case "skip-this-commit": {
|
|
67
|
+
const review = listReviewsForPr(job.repo, job.pr_number).find((row) => row.head_sha === head);
|
|
68
|
+
if (review?.status !== "failed") {
|
|
69
|
+
await comment(github, job, nothingToSkipText(head));
|
|
70
|
+
log("info", `nothing to skip on ${short(head)}`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const text = skippedCommitText(head, args.by);
|
|
74
|
+
await skippedCheck(github, job, head, "Review skipped.", text, log);
|
|
75
|
+
// The failed note says the review was skipped. Without a note, or a
|
|
76
|
+
// client that cannot edit one, the text is a new comment.
|
|
77
|
+
const note = review.note_comment_id ??
|
|
78
|
+
findNoteCommentId(job.repo, job.pr_number, head);
|
|
79
|
+
if (note && github.patch) {
|
|
80
|
+
try {
|
|
81
|
+
await github.patch(`repos/${job.repo}/issues/comments/${note}`, { body: text });
|
|
82
|
+
log("info", `skipped ${short(head)}, the failed note says so`);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
log("info", `could not edit the failed note: ${redact(String(error))}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
await comment(github, job, text);
|
|
90
|
+
log("info", `skipped ${short(head)}`);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
case "skip-this-pr": {
|
|
94
|
+
if (prReviewsOff(job.repo, job.pr_number)) {
|
|
95
|
+
await comment(github, job, ALREADY_OFF_TEXT);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
setPrReviewsOff(job.repo, job.pr_number, args.by ?? "unknown");
|
|
99
|
+
// A review that is waiting or running posts nothing.
|
|
100
|
+
const key = `review:${job.repo}:${job.pr_number}`;
|
|
101
|
+
for (const pending of [
|
|
102
|
+
getQueuedJob(job.repo, job.pr_number),
|
|
103
|
+
getRunningJobByKey(key),
|
|
104
|
+
]) {
|
|
105
|
+
if (pending)
|
|
106
|
+
cancel(pending.id, "reviews_off");
|
|
107
|
+
}
|
|
108
|
+
const text = reviewsOffText(args.by);
|
|
109
|
+
await skippedCheck(github, job, head, "Reviews are off for this pull request.", text, log);
|
|
110
|
+
await comment(github, job, text);
|
|
111
|
+
log("info", "reviews are off for this pull request");
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
case "pr-off": {
|
|
115
|
+
await skippedCheck(github, job, head, "Reviews are off for this pull request.", reviewsOffText(args.by), log);
|
|
116
|
+
log("info", `skipped ${short(head)}, reviews are off`);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
case "reviews-on": {
|
|
120
|
+
await comment(github, job, reviewsOnText(args.by));
|
|
121
|
+
log("info", "reviews are back on for this pull request");
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export function registerSkipJobHandler() {
|
|
127
|
+
registerHandler(SKIP_JOB, {
|
|
128
|
+
run(job, log) {
|
|
129
|
+
return runSkipJob(job, log);
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
@@ -12,7 +12,9 @@ import { getWatchIssue } from "../store/watch.js";
|
|
|
12
12
|
import { canonicalRepoName } from "../util/repo_name.js";
|
|
13
13
|
import { isSha, isZeroSha, queuePush } from "./push_review.js";
|
|
14
14
|
import { WATCH_COMMENT_JOB } from "./watch_comments.js";
|
|
15
|
-
import {
|
|
15
|
+
import { SKIP_JOB } from "./skip_commands.js";
|
|
16
|
+
import { prReviewsOff, setPrReviewsOff } from "../store/subjects.js";
|
|
17
|
+
import { carriesEarlierRequest, evaluatePolicy, isRequestCommand, legacyPolicy, maySkip, skipCommandOf, parsePolicy, } from "./review_policy.js";
|
|
16
18
|
export const REVIEW_DEBOUNCE_MS = 20_000;
|
|
17
19
|
/** Who may talk to commit watch on its issues: people with write access. */
|
|
18
20
|
const WRITE_ASSOCIATIONS = new Set(["OWNER", "MEMBER", "COLLABORATOR"]);
|
|
@@ -139,6 +141,26 @@ export function maybeEnqueueReview(input) {
|
|
|
139
141
|
prNumber: input.prNumber,
|
|
140
142
|
};
|
|
141
143
|
}
|
|
144
|
+
// Turned off with skip-this-pr: no review. Each new commit gets a check
|
|
145
|
+
// run that passes as skipped, so a required check does not block the merge.
|
|
146
|
+
const off = prReviewsOff(input.repo, input.prNumber);
|
|
147
|
+
if (off) {
|
|
148
|
+
enqueue({
|
|
149
|
+
type: SKIP_JOB,
|
|
150
|
+
repo: input.repo,
|
|
151
|
+
prNumber: input.prNumber,
|
|
152
|
+
deliveryId: input.deliveryId,
|
|
153
|
+
args: { command: "pr-off", by: off.by, headSha: input.headSha ?? null },
|
|
154
|
+
// One job per commit, so each pushed commit gets its own skipped check.
|
|
155
|
+
queueKey: `skip:${input.repo}:${input.prNumber}:pr-off:${input.headSha ?? ""}`,
|
|
156
|
+
});
|
|
157
|
+
return {
|
|
158
|
+
outcome: "skipped",
|
|
159
|
+
reason: "Reviews are off for this pull request.",
|
|
160
|
+
repo: input.repo,
|
|
161
|
+
prNumber: input.prNumber,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
142
164
|
const policy = policyForRepo(row);
|
|
143
165
|
const decision = evaluatePolicy(policy, {
|
|
144
166
|
association: input.association,
|
|
@@ -471,6 +493,31 @@ function issueCommentEvent(payload, deliveryId) {
|
|
|
471
493
|
const row = getRepo(repo);
|
|
472
494
|
if (row?.active === 1) {
|
|
473
495
|
const policy = policyForRepo(row);
|
|
496
|
+
const skip = skipCommandOf(body);
|
|
497
|
+
if (skip) {
|
|
498
|
+
const commenter = asString(comment?.author_association) ?? "NONE";
|
|
499
|
+
// Anyone else is ignored without a reply or a reaction.
|
|
500
|
+
if (!maySkip(policy, commenter)) {
|
|
501
|
+
return {
|
|
502
|
+
outcome: "skipped",
|
|
503
|
+
reason: `Not allowed to skip: ${commenter} is not the owner or one of ${(policy.skippers ?? []).join(", ") || "nobody else"}.`,
|
|
504
|
+
repo,
|
|
505
|
+
prNumber,
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
const installationId = asNumber(asRecord(payload.installation)?.id);
|
|
509
|
+
if (installationId !== undefined)
|
|
510
|
+
setInstallationId(repo, installationId);
|
|
511
|
+
const { id } = enqueue({
|
|
512
|
+
type: SKIP_JOB,
|
|
513
|
+
repo,
|
|
514
|
+
prNumber,
|
|
515
|
+
deliveryId,
|
|
516
|
+
args: { command: skip, by: asString(author?.login) ?? null },
|
|
517
|
+
queueKey: `skip:${repo}:${prNumber}:${String(sourceId)}`,
|
|
518
|
+
});
|
|
519
|
+
return { outcome: "enqueued", repo, prNumber, jobId: id };
|
|
520
|
+
}
|
|
474
521
|
if (isRequestCommand(body, policy.requestCommand)) {
|
|
475
522
|
const commenter = asString(comment?.author_association) ?? "NONE";
|
|
476
523
|
if (!policy.requesters.includes(commenter)) {
|
|
@@ -484,6 +531,19 @@ function issueCommentEvent(payload, deliveryId) {
|
|
|
484
531
|
const installationId = asNumber(asRecord(payload.installation)?.id);
|
|
485
532
|
if (installationId !== undefined)
|
|
486
533
|
setInstallationId(repo, installationId);
|
|
534
|
+
// On a pull request turned off with skip-this-pr, the request turns
|
|
535
|
+
// reviews back on. The policy then decides as for any request.
|
|
536
|
+
if (prReviewsOff(repo, prNumber)) {
|
|
537
|
+
setPrReviewsOff(repo, prNumber, null);
|
|
538
|
+
enqueue({
|
|
539
|
+
type: SKIP_JOB,
|
|
540
|
+
repo,
|
|
541
|
+
prNumber,
|
|
542
|
+
deliveryId,
|
|
543
|
+
args: { command: "reviews-on", by: asString(author?.login) ?? null },
|
|
544
|
+
queueKey: `skip:${repo}:${prNumber}:${String(sourceId)}`,
|
|
545
|
+
});
|
|
546
|
+
}
|
|
487
547
|
// An issue payload carries no head, base or diff size, so rules about
|
|
488
548
|
// the fork, the target branch and the size do not match here.
|
|
489
549
|
return maybeEnqueueReview({
|
|
@@ -409,4 +409,10 @@ export const migrations = [
|
|
|
409
409
|
)`,
|
|
410
410
|
`CREATE INDEX idx_rule_events_repo ON rule_events(repo, at)`,
|
|
411
411
|
],
|
|
412
|
+
// 18: a pull request whose reviews were turned off with
|
|
413
|
+
// `/co-maintainer skip-this-pr`, and who turned them off.
|
|
414
|
+
[
|
|
415
|
+
`ALTER TABLE subjects ADD COLUMN reviews_off_at TEXT`,
|
|
416
|
+
`ALTER TABLE subjects ADD COLUMN reviews_off_by TEXT`,
|
|
417
|
+
],
|
|
412
418
|
];
|
package/dist/src/store/rows.d.ts
CHANGED
|
@@ -127,6 +127,10 @@ export type SubjectRow = {
|
|
|
127
127
|
token_id: string | null;
|
|
128
128
|
created_at: string;
|
|
129
129
|
updated_at: string;
|
|
130
|
+
/** Set while `/co-maintainer skip-this-pr` keeps this pull request's
|
|
131
|
+
* reviews off. */
|
|
132
|
+
reviews_off_at?: string | null;
|
|
133
|
+
reviews_off_by?: string | null;
|
|
130
134
|
};
|
|
131
135
|
export type SubjectRevisionRow = {
|
|
132
136
|
subject_id: string;
|
|
@@ -13,3 +13,12 @@ export declare function saveSubjectRevision(input: {
|
|
|
13
13
|
}): void;
|
|
14
14
|
export declare function parseRevisionFiles(row: SubjectRevisionRow): RevisionFile[];
|
|
15
15
|
export declare function parseVisiblePaths(row: SubjectRevisionRow): Set<string>;
|
|
16
|
+
/** Who turned reviews off for this pull request, or `undefined` while they
|
|
17
|
+
* are on. */
|
|
18
|
+
export declare function prReviewsOff(repo: string, prNumber: number): {
|
|
19
|
+
at: string;
|
|
20
|
+
by: string | null;
|
|
21
|
+
} | undefined;
|
|
22
|
+
/** `/co-maintainer skip-this-pr` turns reviews off, `/co-maintainer review`
|
|
23
|
+
* turns them back on (`by` null). */
|
|
24
|
+
export declare function setPrReviewsOff(repo: string, prNumber: number, by: string | null): void;
|
|
@@ -76,3 +76,21 @@ export function parseRevisionFiles(row) {
|
|
|
76
76
|
export function parseVisiblePaths(row) {
|
|
77
77
|
return new Set(JSON.parse(row.visible_paths_json));
|
|
78
78
|
}
|
|
79
|
+
/** Who turned reviews off for this pull request, or `undefined` while they
|
|
80
|
+
* are on. */
|
|
81
|
+
export function prReviewsOff(repo, prNumber) {
|
|
82
|
+
const row = getAppDb()
|
|
83
|
+
.prepare(`SELECT * FROM subjects WHERE kind = 'pr' AND repo = ? AND pr_number = ?`)
|
|
84
|
+
.get(repo, prNumber);
|
|
85
|
+
return row?.reviews_off_at
|
|
86
|
+
? { at: row.reviews_off_at, by: row.reviews_off_by ?? null }
|
|
87
|
+
: undefined;
|
|
88
|
+
}
|
|
89
|
+
/** `/co-maintainer skip-this-pr` turns reviews off, `/co-maintainer review`
|
|
90
|
+
* turns them back on (`by` null). */
|
|
91
|
+
export function setPrReviewsOff(repo, prNumber, by) {
|
|
92
|
+
const subject = getOrCreatePrSubject(repo, prNumber);
|
|
93
|
+
getAppDb()
|
|
94
|
+
.prepare(`UPDATE subjects SET reviews_off_at = ?, reviews_off_by = ?, updated_at = ? WHERE id = ?`)
|
|
95
|
+
.run(by === null ? null : nowIso(), by, nowIso(), subject.id);
|
|
96
|
+
}
|