@fullstackhouse/cerber 1.1.0-pr.80.e038e96 → 1.2.0-pr.81.58d1702
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/README.md +10 -0
- package/dist/cli/index.js +14 -7
- package/dist/core/autoreview.js +20 -0
- package/dist/core/autosend.js +13 -1
- package/dist/core/config.js +12 -0
- package/dist/core/gh.js +24 -3
- package/dist/core/own.js +20 -0
- package/dist/core/send.js +21 -0
- package/dist/server/daemon.js +115 -35
- package/dist/server/index.js +75 -2
- package/package.json +1 -1
- package/web/dist/assets/index-D6g42mO9.js +250 -0
- package/web/dist/assets/index-JYCx7Rxo.css +1 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-DPt1TcJ6.css +0 -1
- package/web/dist/assets/index-DYSObAz4.js +0 -250
package/README.md
CHANGED
|
@@ -157,6 +157,16 @@ ones you marked reviewed or skipped, merged and closed PRs — each tab appearin
|
|
|
157
157
|
only while it holds something. PRs in archived repos are never picked up at
|
|
158
158
|
all, since the repo is read-only and a review could never be sent.
|
|
159
159
|
|
|
160
|
+
### Your own PRs
|
|
161
|
+
|
|
162
|
+
Your own open PRs are in the inbox too, under **your PRs** below the ones
|
|
163
|
+
awaiting you — GitHub never asks you to review them, so they would otherwise
|
|
164
|
+
need their URL pasted every time. Cerber never drafts one on its own and never
|
|
165
|
+
taps you about one: press `r` when you want a self-review. Send posts it as a
|
|
166
|
+
comment, since GitHub takes no approve or change request from a PR's author,
|
|
167
|
+
and auto-send leaves it alone. Skip one to hide it; it leaves for good once it
|
|
168
|
+
merges or closes.
|
|
169
|
+
|
|
160
170
|
### Settled means you settled it
|
|
161
171
|
|
|
162
172
|
Settling a review is your decision, not GitHub's: skip a PR, or mark one
|
package/dist/cli/index.js
CHANGED
|
@@ -5,13 +5,13 @@ import readline from "node:readline/promises";
|
|
|
5
5
|
import { artifactId, artifactKey } from "../core/artifact.js";
|
|
6
6
|
import { listCheckouts, removeCheckout } from "../core/checkout.js";
|
|
7
7
|
import { toMarkdown } from "../core/export.js";
|
|
8
|
-
import { anyAutoReview } from "../core/autoreview.js";
|
|
8
|
+
import { anyAutoReview, capAutoReview } from "../core/autoreview.js";
|
|
9
9
|
import { configPath, loadConfig, saveConfig } from "../core/config.js";
|
|
10
10
|
import { formatBlockers, isBlocking, preflight } from "../core/preflight.js";
|
|
11
11
|
import { withWriter } from "../core/history.js";
|
|
12
12
|
import { TrustRuleError, describeRule, explainRule, parseTrustRule } from "../core/trust.js";
|
|
13
|
-
import { parsePrRef, postReplies, searchAwaitingMe, submitReview } from "../core/gh.js";
|
|
14
|
-
import { buildReviewPayload, computeCalibration, describeReplyFailures, eventForRecommendation, recordReplies, } from "../core/send.js";
|
|
13
|
+
import { currentLogin, parsePrRef, postReplies, searchAwaitingMe, submitReview } from "../core/gh.js";
|
|
14
|
+
import { buildReviewPayload, computeCalibration, defaultSendEvent, describeReplyFailures, eventForRecommendation, ownPrRefusal, recordReplies, } from "../core/send.js";
|
|
15
15
|
import { cerberHome, listArtifacts, loadArtifact, readAutoSendLog, reconcileRunning, updateArtifactByKey, } from "../core/state.js";
|
|
16
16
|
import { pool, reviewPr } from "../runner/review.js";
|
|
17
17
|
import { isReviewRunning } from "../runner/inflight.js";
|
|
@@ -211,12 +211,19 @@ program
|
|
|
211
211
|
`If nothing is running, restart \`cerber serve\`, which clears a check that died mid-flight.`);
|
|
212
212
|
process.exit(1);
|
|
213
213
|
}
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
// Your own PR defaults to a comment, the one event GitHub takes from its
|
|
215
|
+
// author — the same rule the cockpit's send button follows.
|
|
216
|
+
const me = await currentLogin().catch(() => null);
|
|
217
|
+
const event = (opts.event ?? defaultSendEvent(artifact, me)).toUpperCase();
|
|
216
218
|
if (!["APPROVE", "COMMENT", "REQUEST_CHANGES"].includes(event)) {
|
|
217
219
|
console.error(`Invalid event: ${event}`);
|
|
218
220
|
process.exit(1);
|
|
219
221
|
}
|
|
222
|
+
const refusal = ownPrRefusal(artifact.pr, event, me);
|
|
223
|
+
if (refusal) {
|
|
224
|
+
console.error(`Not sent: ${refusal}.`);
|
|
225
|
+
process.exit(1);
|
|
226
|
+
}
|
|
220
227
|
const payload = buildReviewPayload(artifact, event);
|
|
221
228
|
console.log(`About to send to ${artifact.pr.url}:`);
|
|
222
229
|
// Said before anything else about the payload: on a PR you have already
|
|
@@ -447,7 +454,7 @@ program
|
|
|
447
454
|
.option("-H, --host <host>", "host to bind (0.0.0.0 for VPS — requires --token)", "127.0.0.1")
|
|
448
455
|
.option("-t, --token <token>", "require this token on every request (env: CERBER_TOKEN)")
|
|
449
456
|
.option("--no-poll", "don't poll GitHub for PRs awaiting your review (also disables auto-review)")
|
|
450
|
-
.option("--no-auto-review", "list awaiting PRs but don't review them until you click review (
|
|
457
|
+
.option("--no-auto-review", "list awaiting PRs but don't review them until you click review (per-repo exceptions included)")
|
|
451
458
|
.option("--no-notify", "don't notify this machine when a review is ready for you")
|
|
452
459
|
.option("-d, --daemon", "(deprecated no-op — polling and auto-review are now the default)")
|
|
453
460
|
.option("-i, --interval <minutes>", "poll interval (default: config daemon.intervalMinutes, 5)")
|
|
@@ -485,7 +492,7 @@ program
|
|
|
485
492
|
const d = config.daemon;
|
|
486
493
|
// Trust means "run this PR's code". A human clicking review accepted that
|
|
487
494
|
// per PR; auto-review does it unattended, on whatever lands in the queue.
|
|
488
|
-
const drafting = anyAutoReview(
|
|
495
|
+
const drafting = anyAutoReview(capAutoReview(d, opts.autoReview));
|
|
489
496
|
if (opts.poll && d.poll && drafting && opts.trust && config.trust.length > 0) {
|
|
490
497
|
console.log(`⚠ ${config.trust.length} trust rule(s) in ${configPath()}: unattended reviews will run commands from ` +
|
|
491
498
|
`matching PRs, with nobody watching. Pass --no-trust to keep every review read-only, ` +
|
package/dist/core/autoreview.js
CHANGED
|
@@ -11,3 +11,23 @@ export function autoReviewFor(knobs, owner, repo) {
|
|
|
11
11
|
export function anyAutoReview(knobs) {
|
|
12
12
|
return knobs.autoReview || Object.values(knobs.autoReviewRepos).some(Boolean);
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* What a process actually drafts: `--no-auto-review` caps the default and the
|
|
16
|
+
* exceptions alike, so the flag means "this process starts no AI runs" and the
|
|
17
|
+
* trust warning's advice to pass it holds. A `true` exception still outranks
|
|
18
|
+
* the config's own `autoReview: false` — never the flag.
|
|
19
|
+
*/
|
|
20
|
+
export function capAutoReview(knobs, flag) {
|
|
21
|
+
return flag ? knobs : { autoReview: false, autoReviewRepos: {} };
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* One exception set (`true`/`false`) or removed (`null`), the rest left as they
|
|
25
|
+
* are. Any spelling of the same repo is replaced rather than kept beside it,
|
|
26
|
+
* since the match ignores case. One repo per write, so an edit made from a stale
|
|
27
|
+
* view can't take a concurrent one with it.
|
|
28
|
+
*/
|
|
29
|
+
export function setException(repos, repo, on) {
|
|
30
|
+
const want = repo.toLowerCase();
|
|
31
|
+
const rest = Object.fromEntries(Object.entries(repos).filter(([k]) => k.toLowerCase() !== want));
|
|
32
|
+
return on === null ? rest : { ...rest, [repo]: on };
|
|
33
|
+
}
|
package/dist/core/autosend.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isOwnPr } from "./own.js";
|
|
1
2
|
import { sendTreatment } from "./raised.js";
|
|
2
3
|
/**
|
|
3
4
|
* Auto-send policy — deliberately narrow:
|
|
@@ -9,10 +10,21 @@ import { sendTreatment } from "./raised.js";
|
|
|
9
10
|
* there to decide, and the default is the side that posts less. A reply into
|
|
10
11
|
* someone's thread is never auto-sent — that is a decision only a person makes,
|
|
11
12
|
* and auto-send posts one review and nothing else.
|
|
13
|
+
*
|
|
14
|
+
* Never on your own PR. GitHub refuses an approve from a PR's author, and the
|
|
15
|
+
* poll never drafts one of yours to begin with — this is the line that holds
|
|
16
|
+
* if anything ever does. `login` is who you are; null is "gh could not say",
|
|
17
|
+
* and a post nobody is watching does not go out on a guess.
|
|
12
18
|
*/
|
|
13
|
-
export function evaluateAutoSend(artifact, threshold) {
|
|
19
|
+
export function evaluateAutoSend(artifact, threshold, login) {
|
|
14
20
|
if (artifact.sent)
|
|
15
21
|
return { eligible: false, reason: "already sent" };
|
|
22
|
+
if (login === null) {
|
|
23
|
+
return { eligible: false, reason: "could not ask gh who you are, so whether this PR is your own is unknown" };
|
|
24
|
+
}
|
|
25
|
+
if (isOwnPr(artifact.pr, login)) {
|
|
26
|
+
return { eligible: false, reason: "this is your own PR — GitHub takes no approve from its author" };
|
|
27
|
+
}
|
|
16
28
|
// The same rule, for a send a re-review has since superseded. `sent` only
|
|
17
29
|
// ever describes the draft on the row, so once one moves to `priorSends`
|
|
18
30
|
// that guard stops seeing it — and "never a re-send" would quietly come to
|
package/dist/core/config.js
CHANGED
|
@@ -29,6 +29,18 @@ export const DaemonConfigSchema = z.object({
|
|
|
29
29
|
*/
|
|
30
30
|
autoReviewRepos: z
|
|
31
31
|
.record(z.string().regex(/^[\w.-]+\/[\w.-]+$/, "expected owner/repo"), z.boolean())
|
|
32
|
+
// The match ignores case, so two spellings of one repo would leave the
|
|
33
|
+
// answer to key order — refused, like any other key that can't mean one thing.
|
|
34
|
+
.superRefine((repos, ctx) => {
|
|
35
|
+
const seen = new Map();
|
|
36
|
+
for (const key of Object.keys(repos)) {
|
|
37
|
+
const first = seen.get(key.toLowerCase());
|
|
38
|
+
if (first !== undefined)
|
|
39
|
+
ctx.addIssue({ code: "custom", path: [key], message: `same repo as ${first}` });
|
|
40
|
+
else
|
|
41
|
+
seen.set(key.toLowerCase(), key);
|
|
42
|
+
}
|
|
43
|
+
})
|
|
32
44
|
.default({}),
|
|
33
45
|
/**
|
|
34
46
|
* Tap this machine's notification centre when a PR is worth coming back for
|
package/dist/core/gh.js
CHANGED
|
@@ -186,7 +186,9 @@ export function assembleDiff(files) {
|
|
|
186
186
|
* pressed the button, which makes it a review someone is waiting on rather than
|
|
187
187
|
* work-in-progress to leave alone. Filtering drafts here would be redundant with
|
|
188
188
|
* a stronger filter that already ran, and it would contradict the promise the
|
|
189
|
-
* daemon config makes: the inbox holds what awaits you, drafts and all.
|
|
189
|
+
* daemon config makes: the inbox holds what awaits you, drafts and all. The
|
|
190
|
+
* `author:@me` search keeps them for a plainer reason: your own draft is where
|
|
191
|
+
* a self-review is most worth having, and nothing is drafted there unasked.
|
|
190
192
|
*/
|
|
191
193
|
export function mapSearchResults(raw) {
|
|
192
194
|
return raw.flatMap((r) => {
|
|
@@ -523,14 +525,24 @@ export async function fetchPriorRemarks(ref, people) {
|
|
|
523
525
|
throw new Error(`GitHub returned no pull request for ${ref.owner}/${ref.repo}#${ref.number}`);
|
|
524
526
|
return priorRemarks({ threads: pr.reviewThreads?.nodes ?? [], reviews: pr.reviews?.nodes ?? [] }, people);
|
|
525
527
|
}
|
|
526
|
-
|
|
528
|
+
/**
|
|
529
|
+
* The two questions the inbox asks GitHub, as `gh search prs` qualifiers.
|
|
530
|
+
*
|
|
531
|
+
* `review-requested` is the inbox proper: PRs somebody is waiting on you for.
|
|
532
|
+
* `author` is your own open PRs, which that search returns only when a team
|
|
533
|
+
* you are on was requested — GitHub will not let anyone request a review from
|
|
534
|
+
* a PR's author — so self-reviewing one would otherwise mean pasting its URL
|
|
535
|
+
* every time. Both are the same search with one flag changed, so they cannot
|
|
536
|
+
* drift apart on what "open" means or which repos are read-only.
|
|
537
|
+
*/
|
|
538
|
+
export function searchPrsArgs(search, repoFilter, limit = 50) {
|
|
527
539
|
const args = [
|
|
528
540
|
"search",
|
|
529
541
|
"prs",
|
|
530
542
|
// An archived repo is read-only: its PRs can never merge, close, or take a
|
|
531
543
|
// review. Without this they'd sit in the inbox forever — nothing retires them.
|
|
532
544
|
"archived:false",
|
|
533
|
-
|
|
545
|
+
`--${search}=@me`,
|
|
534
546
|
"--state=open",
|
|
535
547
|
"--limit",
|
|
536
548
|
String(limit),
|
|
@@ -541,11 +553,20 @@ export function searchAwaitingArgs(repoFilter, limit = 50) {
|
|
|
541
553
|
args.push("--repo", repoFilter);
|
|
542
554
|
return args;
|
|
543
555
|
}
|
|
556
|
+
export const searchAwaitingArgs = (repoFilter, limit = 50) => searchPrsArgs("review-requested", repoFilter, limit);
|
|
544
557
|
/** Open PRs where the current gh user's review is requested, drafts included. */
|
|
545
558
|
export async function searchAwaitingMe(repoFilter, limit = 50) {
|
|
546
559
|
const out = await gh(searchAwaitingArgs(repoFilter, limit));
|
|
547
560
|
return mapSearchResults(JSON.parse(out));
|
|
548
561
|
}
|
|
562
|
+
/**
|
|
563
|
+
* Open PRs the current gh user opened, drafts included. They come to the inbox
|
|
564
|
+
* to be reviewed on demand and never automatically — see `isOwnPr` (`own.ts`).
|
|
565
|
+
*/
|
|
566
|
+
export async function searchAuthoredByMe(repoFilter, limit = 50) {
|
|
567
|
+
const out = await gh(searchPrsArgs("author", repoFilter, limit));
|
|
568
|
+
return mapSearchResults(JSON.parse(out));
|
|
569
|
+
}
|
|
549
570
|
/**
|
|
550
571
|
* Who this repo will let you put on a PR — the list behind the handoff's
|
|
551
572
|
* suggestions.
|
package/dist/core/own.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Your own PRs — the one test for "is this PR yours", kept free of imports so
|
|
2
|
+
// the cockpit's bundle can share it with the server without pulling in `gh`.
|
|
3
|
+
/**
|
|
4
|
+
* Whether this PR is one you opened yourself.
|
|
5
|
+
*
|
|
6
|
+
* The one test for it, used by everything that treats your own PRs
|
|
7
|
+
* differently: the poll never drafts or announces one, auto-send never fires on
|
|
8
|
+
* one, Send refuses an approve or a change request on one (GitHub refuses both
|
|
9
|
+
* from the author anyway), and the cockpit lists them apart from the PRs
|
|
10
|
+
* somebody is waiting on you for. Derived from the PR's author rather than
|
|
11
|
+
* stored, so there is no field to drift out of step with GitHub.
|
|
12
|
+
*
|
|
13
|
+
* A login nobody could fetch claims nothing (false), and so does an author the
|
|
14
|
+
* row never recorded. GitHub logins are case-insensitive.
|
|
15
|
+
*/
|
|
16
|
+
export function isOwnPr(pr, login) {
|
|
17
|
+
if (!login || !pr.author)
|
|
18
|
+
return false;
|
|
19
|
+
return pr.author.toLowerCase() === login.toLowerCase();
|
|
20
|
+
}
|
package/dist/core/send.js
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
|
+
import { isOwnPr } from "./own.js";
|
|
1
2
|
import { newSideLines } from "./diff.js";
|
|
2
3
|
import { sendTreatment } from "./raised.js";
|
|
3
4
|
import { withGrade } from "./severity.js";
|
|
4
5
|
export function eventForRecommendation(rec) {
|
|
5
6
|
return { approve: "APPROVE", comment: "COMMENT", request_changes: "REQUEST_CHANGES" }[rec];
|
|
6
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Why Send refuses this event on this PR, or null when it may go.
|
|
10
|
+
*
|
|
11
|
+
* Your own PR takes a comment and nothing else: GitHub refuses an approve or a
|
|
12
|
+
* change request from a PR's author, and GitHub's error after the click is a
|
|
13
|
+
* worse place to learn that than here.
|
|
14
|
+
* A login nobody could fetch refuses nothing; GitHub is still the last word.
|
|
15
|
+
*/
|
|
16
|
+
export function ownPrRefusal(pr, event, login) {
|
|
17
|
+
if (event === "COMMENT" || !isOwnPr(pr, login))
|
|
18
|
+
return null;
|
|
19
|
+
const what = event === "APPROVE" ? "an approve" : "a change request";
|
|
20
|
+
return `this is your own PR, and GitHub takes no ${what} from its author — send it as a comment`;
|
|
21
|
+
}
|
|
22
|
+
/** What Send posts by default: the verdict's event, except on your own PR. */
|
|
23
|
+
export function defaultSendEvent(artifact, login) {
|
|
24
|
+
if (isOwnPr(artifact.pr, login))
|
|
25
|
+
return "COMMENT";
|
|
26
|
+
return artifact.verdict ? eventForRecommendation(artifact.verdict.recommendation) : "COMMENT";
|
|
27
|
+
}
|
|
7
28
|
function graded(c) {
|
|
8
29
|
return withGrade(c.body, c.severity);
|
|
9
30
|
}
|
package/dist/server/daemon.js
CHANGED
|
@@ -1,21 +1,48 @@
|
|
|
1
1
|
import { SCHEMA_VERSION, artifactId, artifactKey } from "../core/artifact.js";
|
|
2
2
|
import { evaluateAutoSend } from "../core/autosend.js";
|
|
3
|
-
import { anyAutoReview, autoReviewFor } from "../core/autoreview.js";
|
|
3
|
+
import { anyAutoReview, autoReviewFor, capAutoReview } from "../core/autoreview.js";
|
|
4
4
|
import { loadConfig } from "../core/config.js";
|
|
5
|
-
import { classifyReply, currentLogin, fetchConversation, fetchLastReviewRequest, fetchOwnReview, fetchPrInfo, fetchReviewRequests, lastMentionOfYou, lastWordOfYours, searchAwaitingMe, stillRequested, submitReview, } from "../core/gh.js";
|
|
5
|
+
import { classifyReply, currentLogin, fetchConversation, fetchLastReviewRequest, fetchOwnReview, fetchPrInfo, fetchReviewRequests, lastMentionOfYou, lastWordOfYours, searchAuthoredByMe, searchAwaitingMe, stillRequested, submitReview, } from "../core/gh.js";
|
|
6
6
|
import { withWriter } from "../core/history.js";
|
|
7
|
+
import { isOwnPr } from "../core/own.js";
|
|
7
8
|
import { pendingNews, notice, notify } from "../core/notify.js";
|
|
8
9
|
import { buildReviewPayload, computeCalibration } from "../core/send.js";
|
|
9
10
|
import { appendAutoSendLog, deleteArtifact, listArtifacts, loadArtifact, noteHistory, saveArtifact, updateArtifactByKey, } from "../core/state.js";
|
|
10
11
|
import { ReviewInProgressError } from "../runner/inflight.js";
|
|
11
12
|
import { SETTLED_BY_YOU, pool, reviewPr } from "../runner/review.js";
|
|
13
|
+
/**
|
|
14
|
+
* Whether a row could be one of your own PRs: it is, or cerber cannot tell
|
|
15
|
+
* because gh would not say who you are.
|
|
16
|
+
*/
|
|
17
|
+
export const mightBeYours = (a, me) => me === null || isOwnPr(a.pr, me);
|
|
18
|
+
/**
|
|
19
|
+
* The poll's searches as one list: first occurrence wins, so the order the
|
|
20
|
+
* searches are passed in is the order of precedence.
|
|
21
|
+
*/
|
|
22
|
+
export function dedupeDiscovered(refs) {
|
|
23
|
+
const seen = new Set();
|
|
24
|
+
return refs.filter((r) => {
|
|
25
|
+
const id = artifactId(r);
|
|
26
|
+
if (seen.has(id))
|
|
27
|
+
return false;
|
|
28
|
+
seen.add(id);
|
|
29
|
+
return true;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
12
32
|
/**
|
|
13
33
|
* A pure discovery stub: enough artifact for the queue to show an awaiting row.
|
|
14
34
|
* The AI run that follows (automatic or clicked) replaces it wholesale.
|
|
35
|
+
*
|
|
36
|
+
* `own` is a PR you opened yourself. It gets no `notified` ledger at all —
|
|
37
|
+
* absent, which is "nobody meant to announce this row" — because nobody is
|
|
38
|
+
* waiting on you for it: it is in the inbox so you can ask for a self-review
|
|
39
|
+
* when you want one, not to call you back to the cockpit. Both bells read the
|
|
40
|
+
* ledger, so this one omission keeps the machine's tap and the browser's quiet
|
|
41
|
+
* about it, now and after you ask for a draft (the run carries the ledger over).
|
|
15
42
|
*/
|
|
16
|
-
export function stubArtifact(ref) {
|
|
43
|
+
export function stubArtifact(ref, own = false) {
|
|
17
44
|
const now = new Date().toISOString();
|
|
18
|
-
|
|
45
|
+
const stub = {
|
|
19
46
|
schemaVersion: SCHEMA_VERSION,
|
|
20
47
|
id: artifactId(ref),
|
|
21
48
|
status: "awaiting",
|
|
@@ -60,6 +87,9 @@ export function stubArtifact(ref) {
|
|
|
60
87
|
preChat: null,
|
|
61
88
|
pendingChat: null,
|
|
62
89
|
};
|
|
90
|
+
if (own)
|
|
91
|
+
delete stub.notified;
|
|
92
|
+
return stub;
|
|
63
93
|
}
|
|
64
94
|
/**
|
|
65
95
|
* An artifact nothing has touched yet — safe to delete when its PR leaves the
|
|
@@ -242,18 +272,36 @@ export function startDaemon(opts) {
|
|
|
242
272
|
/** When GitHub was last asked whether a settled row has been re-requested, by
|
|
243
273
|
* artifact id. In-memory for the same reason: a restart just asks sooner. */
|
|
244
274
|
const requestCheckedAt = new Map();
|
|
245
|
-
|
|
275
|
+
/**
|
|
276
|
+
* What GitHub has for you: the PRs awaiting your review, then your own open
|
|
277
|
+
* ones, as one deduplicated list — and whether the second search ran at all
|
|
278
|
+
* (`ownSearched`).
|
|
279
|
+
*
|
|
280
|
+
* Your own PRs are asked for only when cerber knows who you are (`me`). The
|
|
281
|
+
* whole of their special handling — never drafted, never announced, never
|
|
282
|
+
* approved — turns on recognising them, so a poll that could not tell would
|
|
283
|
+
* be better off not bringing them in at all than bringing them in as if
|
|
284
|
+
* somebody had asked. And that search is the optional half: when it fails,
|
|
285
|
+
* the PRs people are waiting on you for still come through, and the poll
|
|
286
|
+
* says what it could not see rather than failing whole. Which search found a
|
|
287
|
+
* PR decides nothing — a team you are on can be requested on your own PR,
|
|
288
|
+
* and `isOwnPr` reads the author either way.
|
|
289
|
+
*/
|
|
290
|
+
async function discover(me) {
|
|
246
291
|
const filters = opts.repos.length > 0 ? opts.repos : [undefined];
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
292
|
+
const [awaiting, authored] = await Promise.all([
|
|
293
|
+
Promise.all(filters.map((repo) => searchAwaitingMe(repo))),
|
|
294
|
+
me === null
|
|
295
|
+
? Promise.resolve(null)
|
|
296
|
+
: Promise.all(filters.map((repo) => searchAuthoredByMe(repo))).catch((err) => {
|
|
297
|
+
log(`could not search for your own PRs: ${err instanceof Error ? err.message : String(err)}`);
|
|
298
|
+
return null;
|
|
299
|
+
}),
|
|
300
|
+
]);
|
|
301
|
+
return {
|
|
302
|
+
refs: dedupeDiscovered([...awaiting.flat(), ...(authored ?? []).flat()]),
|
|
303
|
+
ownSearched: authored !== null,
|
|
304
|
+
};
|
|
257
305
|
}
|
|
258
306
|
/**
|
|
259
307
|
* Make the local queue mirror what's actually awaiting: stub artifacts for
|
|
@@ -261,7 +309,7 @@ export function startDaemon(opts) {
|
|
|
261
309
|
* request went away. Freshness decisions always come from local artifacts —
|
|
262
310
|
* search results lag GitHub by minutes and never override them.
|
|
263
311
|
*/
|
|
264
|
-
async function syncQueue(refs) {
|
|
312
|
+
async function syncQueue(refs, ownSearched) {
|
|
265
313
|
const discovered = [];
|
|
266
314
|
/** Reopen checks spent this poll — the same cap the state refresh below obeys. */
|
|
267
315
|
let reopenChecks = 0;
|
|
@@ -297,6 +345,11 @@ export function startDaemon(opts) {
|
|
|
297
345
|
async function reopenIfAskedAgain(artifact) {
|
|
298
346
|
if (settledAtOf(artifact) === null)
|
|
299
347
|
return;
|
|
348
|
+
// Nobody can ask you to review your own PR, and a comment naming its
|
|
349
|
+
// author is the conversation of the PR rather than a request for a
|
|
350
|
+
// review — so a skip there stands until you undo it yourself.
|
|
351
|
+
if (isOwnPr(artifact.pr, await who()))
|
|
352
|
+
return;
|
|
300
353
|
const last = requestCheckedAt.get(artifact.id) ?? 0;
|
|
301
354
|
if (reopenChecks >= STATE_REFRESH_CAP || Date.now() - last < STATE_REFRESH_MIN_MS)
|
|
302
355
|
return;
|
|
@@ -346,6 +399,8 @@ export function startDaemon(opts) {
|
|
|
346
399
|
const me = await who();
|
|
347
400
|
if (me === null)
|
|
348
401
|
return;
|
|
402
|
+
if (isOwnPr(artifact.pr, me))
|
|
403
|
+
return;
|
|
349
404
|
let ask;
|
|
350
405
|
try {
|
|
351
406
|
ask = await askedInWords(artifact, me);
|
|
@@ -405,7 +460,7 @@ export function startDaemon(opts) {
|
|
|
405
460
|
}
|
|
406
461
|
continue;
|
|
407
462
|
}
|
|
408
|
-
await saveArtifact(stubArtifact(ref));
|
|
463
|
+
await saveArtifact(stubArtifact(ref, isOwnPr(ref, await who())));
|
|
409
464
|
discovered.push(ref);
|
|
410
465
|
}
|
|
411
466
|
/**
|
|
@@ -438,6 +493,13 @@ export function startDaemon(opts) {
|
|
|
438
493
|
const me = await who();
|
|
439
494
|
if (me === null)
|
|
440
495
|
return;
|
|
496
|
+
// Your own PR is never filed. Every reason below reads *you* acting on
|
|
497
|
+
// the PR as an answer to somebody's request, and on your own PR you act
|
|
498
|
+
// all the time — replying to its review threads posts a review of yours —
|
|
499
|
+
// with no request there to answer. It leaves the inbox when it merges or
|
|
500
|
+
// closes, or when you skip it.
|
|
501
|
+
if (isOwnPr(artifact.pr, me))
|
|
502
|
+
return;
|
|
441
503
|
/** Re-reads from disk: a run or a send may have started in the seconds
|
|
442
504
|
* these reads took, and neither wants filing out from under it. */
|
|
443
505
|
async function file(filed, note, stillFilable) {
|
|
@@ -502,10 +564,16 @@ export function startDaemon(opts) {
|
|
|
502
564
|
await updateArtifactByKey(artifactKey(artifact.id), (a) => ({ ...a, pr }));
|
|
503
565
|
log(`[${artifact.id}] ${pr.state.toLowerCase()} — archived`);
|
|
504
566
|
}
|
|
505
|
-
else {
|
|
567
|
+
else if (ownSearched || !mightBeYours(artifact, await who())) {
|
|
506
568
|
await deleteArtifact(artifact.id);
|
|
507
569
|
log(`[${artifact.id}] no longer awaiting your review — removed from the queue`);
|
|
508
570
|
}
|
|
571
|
+
// Otherwise this poll could not look for your own PRs, so "not in
|
|
572
|
+
// the results" says nothing about a stub that may be yours: it
|
|
573
|
+
// stays, rather than being dropped and logged as gone only to
|
|
574
|
+
// return next poll. Everybody else's is reaped as before — unless
|
|
575
|
+
// gh cannot say who you are, when any stub may be yours and every
|
|
576
|
+
// one waits for a poll that can tell.
|
|
509
577
|
}
|
|
510
578
|
catch {
|
|
511
579
|
// GitHub unreachable — leave the stub; next poll retries.
|
|
@@ -726,13 +794,13 @@ export function startDaemon(opts) {
|
|
|
726
794
|
* The status fields that follow the config, set from it. The poll calls this
|
|
727
795
|
* with what it just read, and `reconfigure` with what the cockpit just saved.
|
|
728
796
|
*/
|
|
729
|
-
function applyKnobs(config) {
|
|
797
|
+
function applyKnobs(config, me = null) {
|
|
730
798
|
const knobs = config.daemon;
|
|
731
|
-
const autoReview =
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
const drafts = (pr) => autoReviewFor(autoReview, pr.owner, pr.repo);
|
|
799
|
+
const autoReview = capAutoReview(knobs, opts.autoReview);
|
|
800
|
+
// Your own PRs are never drafted unasked, whatever auto-review says for
|
|
801
|
+
// their repo: they are in the inbox for a self-review on demand. The same
|
|
802
|
+
// predicate decides when a tap is due, which keeps them quiet there too.
|
|
803
|
+
const drafts = (pr) => !isOwnPr(pr, me) && autoReviewFor(autoReview, pr.owner, pr.repo);
|
|
736
804
|
status.pollEnabled = knobs.poll;
|
|
737
805
|
// What the cockpit's bell defers to: a loop that isn't polling announces
|
|
738
806
|
// nothing, whatever the notify toggle says.
|
|
@@ -763,7 +831,11 @@ export function startDaemon(opts) {
|
|
|
763
831
|
// or the knobs), so a broken file skips the tick loudly instead of
|
|
764
832
|
// proceeding on guessed defaults.
|
|
765
833
|
const config = await loadConfig();
|
|
766
|
-
|
|
834
|
+
// Who you are, asked once per poll (and cached for the process): it is
|
|
835
|
+
// what tells your own PRs apart from the ones awaiting you. Null is "gh
|
|
836
|
+
// could not say", and then no own PR is brought in at all — see `discover`.
|
|
837
|
+
const me = await currentLogin().catch(() => null);
|
|
838
|
+
const { knobs, drafts, drafting, notifyOn, announcing } = applyKnobs(config, me);
|
|
767
839
|
if (!knobs.poll) {
|
|
768
840
|
// Deliberately off is not an outage — don't leave a stale error up, or
|
|
769
841
|
// a list of PRs we are no longer checking are still awaiting you.
|
|
@@ -772,26 +844,34 @@ export function startDaemon(opts) {
|
|
|
772
844
|
status.lastSummary = "polling off (settings) — the queue only shows what you review by hand";
|
|
773
845
|
return;
|
|
774
846
|
}
|
|
775
|
-
const refs = await discover();
|
|
847
|
+
const { refs, ownSearched } = await discover(me);
|
|
848
|
+
// Your own PRs are synced into the queue with the rest, but nobody is
|
|
849
|
+
// asking you for them: they are not "awaiting" in anything the strip
|
|
850
|
+
// counts, and the cockpit's open-requests tab — "GitHub still lists you
|
|
851
|
+
// as a requested reviewer" — must never name one.
|
|
852
|
+
const asked = refs.filter((r) => !isOwnPr(r, me));
|
|
853
|
+
const yours = refs.length - asked.length;
|
|
854
|
+
const ownPart = yours > 0 ? `, ${yours} of your own` : "";
|
|
776
855
|
status.lastPollError = null;
|
|
777
856
|
// The same refs behind lastSummary's count, so the number the strip shows
|
|
778
857
|
// and the rows the cockpit can name always come from one answer.
|
|
779
858
|
// A failed poll leaves the last good list up; lastPollError says so.
|
|
780
|
-
status.awaiting = await classifyAll(
|
|
781
|
-
const { discovered } = await syncQueue(refs);
|
|
859
|
+
status.awaiting = await classifyAll(asked);
|
|
860
|
+
const { discovered } = await syncQueue(refs, ownSearched);
|
|
782
861
|
if (drafting) {
|
|
783
862
|
// A repo excepted from auto-review is discovered like any other — it
|
|
784
|
-
// is in the queue above — and only its run waits for the click.
|
|
785
|
-
|
|
786
|
-
const
|
|
863
|
+
// is in the queue above — and only its run waits for the click. So is
|
|
864
|
+
// your own PR, in every repo.
|
|
865
|
+
const toDraft = asked.filter(drafts);
|
|
866
|
+
const onClick = asked.length - toDraft.length;
|
|
787
867
|
const { reviewed, skipped, failed } = await reviewAll(toDraft);
|
|
788
868
|
status.lastSummary =
|
|
789
|
-
`${
|
|
869
|
+
`${asked.length} awaiting; ${reviewed} reviewed, ${skipped} up to date` +
|
|
790
870
|
`${failed > 0 ? `, ${failed} failed` : ""}` +
|
|
791
|
-
`${onClick > 0 ? `, ${onClick} waiting for a click` : ""}`;
|
|
871
|
+
`${onClick > 0 ? `, ${onClick} waiting for a click` : ""}${ownPart}`;
|
|
792
872
|
}
|
|
793
873
|
else {
|
|
794
|
-
status.lastSummary = `${
|
|
874
|
+
status.lastSummary = `${asked.length} awaiting${discovered.length > 0 ? `, ${discovered.length} new` : ""}${ownPart} (auto-review off)`;
|
|
795
875
|
}
|
|
796
876
|
// After the drafting, not before it. The arrival is not the news when
|
|
797
877
|
// cerber is about to write the review itself: a tap that lands on "no run
|
|
@@ -824,7 +904,7 @@ export function startDaemon(opts) {
|
|
|
824
904
|
}
|
|
825
905
|
}
|
|
826
906
|
async function handleAutoSend(artifact) {
|
|
827
|
-
const decision = evaluateAutoSend(artifact, opts.autoSendThreshold);
|
|
907
|
+
const decision = evaluateAutoSend(artifact, opts.autoSendThreshold, await currentLogin().catch(() => null));
|
|
828
908
|
if (decision.eligible)
|
|
829
909
|
status.autoSendCandidates++;
|
|
830
910
|
const entryBase = {
|