co-maintainer 0.6.9 → 0.6.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +1 -1
- package/dist/src/ai/fake.d.ts +10 -1
- package/dist/src/ai/fake.js +39 -4
- package/dist/src/cli/args.js +2 -0
- package/dist/src/cli/command_json.d.ts +6 -0
- package/dist/src/cli/command_json.js +1 -0
- package/dist/src/cli/commands/probe.js +25 -0
- package/dist/src/cli/commands/registry.js +11 -0
- package/dist/src/cli/commands/review.js +5 -1
- package/dist/src/cli/commands/serve.js +4 -0
- package/dist/src/cli/commands/set.js +4 -2
- package/dist/src/cli/review_args.d.ts +9 -0
- package/dist/src/cli/review_args.js +36 -1
- package/dist/src/github/app.d.ts +4 -0
- package/dist/src/github/app.js +10 -1
- package/dist/src/github/permissions.js +40 -0
- package/dist/src/github/write_access.d.ts +7 -0
- package/dist/src/github/write_access.js +12 -0
- package/dist/src/local/git_ops.js +3 -2
- package/dist/src/local/git_revision.d.ts +5 -2
- package/dist/src/local/git_revision.js +17 -10
- package/dist/src/pr/reviewer.d.ts +2 -0
- package/dist/src/pr/reviewer.js +1 -1
- package/dist/src/remote/push_client.d.ts +7 -0
- package/dist/src/remote/push_client.js +287 -0
- package/dist/src/remote/server/routes.d.ts +1 -0
- package/dist/src/remote/server/routes.js +61 -4
- package/dist/src/remote/server/sync.js +11 -3
- package/dist/src/remote/validate.js +17 -0
- package/dist/src/review/carry_over.d.ts +2 -0
- package/dist/src/review/carry_over.js +33 -26
- package/dist/src/server/api/repos.js +13 -2
- package/dist/src/server/pages/layout.js +1 -0
- package/dist/src/server/pages/repo.d.ts +3 -1
- package/dist/src/server/pages/repo.js +4 -1
- package/dist/src/server/pages/repo_pushes.d.ts +7 -0
- package/dist/src/server/pages/repo_pushes.js +144 -0
- package/dist/src/server/pages/repo_settings.js +45 -1
- package/dist/src/server/pages/router.js +22 -3
- package/dist/src/server/webhook/index.js +8 -1
- package/dist/src/services/dashboard.d.ts +46 -0
- package/dist/src/services/dashboard.js +24 -0
- package/dist/src/services/jobs.js +10 -0
- package/dist/src/services/push_review.d.ts +51 -0
- package/dist/src/services/push_review.js +878 -0
- package/dist/src/services/review.d.ts +20 -3
- package/dist/src/services/review.js +112 -39
- package/dist/src/services/setup.js +21 -0
- package/dist/src/services/watch_comments.d.ts +10 -0
- package/dist/src/services/watch_comments.js +166 -0
- package/dist/src/services/watch_issues.d.ts +70 -0
- package/dist/src/services/watch_issues.js +266 -0
- package/dist/src/services/watch_notes.d.ts +8 -0
- package/dist/src/services/watch_notes.js +80 -0
- package/dist/src/services/watch_status.d.ts +25 -0
- package/dist/src/services/watch_status.js +101 -0
- package/dist/src/services/webhook.js +108 -8
- package/dist/src/store/migrations.js +63 -0
- package/dist/src/store/repos.d.ts +1 -1
- package/dist/src/store/rows.d.ts +6 -0
- package/dist/src/store/watch.d.ts +108 -0
- package/dist/src/store/watch.js +186 -0
- package/dist/src/types.d.ts +2 -0
- package/dist/src/util/repo_name.d.ts +2 -0
- package/dist/src/util/repo_name.js +56 -0
- package/package.json +1 -1
|
@@ -289,4 +289,67 @@ export const migrations = [
|
|
|
289
289
|
// (registered by init itself, or found on disk by serve after an upgrade),
|
|
290
290
|
// NULL for one added from the dashboard.
|
|
291
291
|
[`ALTER TABLE repos ADD COLUMN added_from TEXT`],
|
|
292
|
+
// 15 — commit watch: pushes to the default branch, the issues opened for
|
|
293
|
+
// their P0/P1 findings, and the maintainer notes left on those issues.
|
|
294
|
+
[
|
|
295
|
+
`ALTER TABLE repos ADD COLUMN watch_open_issues INTEGER NOT NULL DEFAULT 1`,
|
|
296
|
+
`ALTER TABLE repos ADD COLUMN watch_push_mode TEXT NOT NULL DEFAULT 'queue'`,
|
|
297
|
+
`CREATE TABLE push_events (
|
|
298
|
+
repo TEXT NOT NULL,
|
|
299
|
+
after_sha TEXT NOT NULL,
|
|
300
|
+
before_sha TEXT NOT NULL,
|
|
301
|
+
ref TEXT NOT NULL,
|
|
302
|
+
sources TEXT NOT NULL DEFAULT '[]',
|
|
303
|
+
review_id TEXT,
|
|
304
|
+
job_id TEXT,
|
|
305
|
+
created_at TEXT NOT NULL,
|
|
306
|
+
PRIMARY KEY (repo, after_sha)
|
|
307
|
+
)`,
|
|
308
|
+
`CREATE INDEX idx_push_events_review ON push_events(review_id)`,
|
|
309
|
+
`CREATE TABLE push_inputs (
|
|
310
|
+
job_id TEXT PRIMARY KEY,
|
|
311
|
+
revision_json TEXT NOT NULL,
|
|
312
|
+
created_at TEXT NOT NULL
|
|
313
|
+
)`,
|
|
314
|
+
`CREATE TABLE push_results (
|
|
315
|
+
review_id TEXT PRIMARY KEY,
|
|
316
|
+
result_json TEXT NOT NULL,
|
|
317
|
+
created_at TEXT NOT NULL
|
|
318
|
+
)`,
|
|
319
|
+
`CREATE TABLE watch_issues (
|
|
320
|
+
id TEXT PRIMARY KEY,
|
|
321
|
+
repo TEXT NOT NULL,
|
|
322
|
+
issue_number INTEGER NOT NULL,
|
|
323
|
+
severity TEXT NOT NULL,
|
|
324
|
+
title TEXT NOT NULL,
|
|
325
|
+
body_md TEXT NOT NULL,
|
|
326
|
+
path TEXT,
|
|
327
|
+
line_from INTEGER,
|
|
328
|
+
line_to INTEGER,
|
|
329
|
+
anchor_text TEXT,
|
|
330
|
+
state TEXT NOT NULL,
|
|
331
|
+
closed_check TEXT,
|
|
332
|
+
opened_review_id TEXT NOT NULL,
|
|
333
|
+
last_review_id TEXT,
|
|
334
|
+
last_check TEXT,
|
|
335
|
+
last_check_at TEXT,
|
|
336
|
+
created_at TEXT NOT NULL,
|
|
337
|
+
updated_at TEXT NOT NULL
|
|
338
|
+
)`,
|
|
339
|
+
`CREATE UNIQUE INDEX idx_watch_issues_number
|
|
340
|
+
ON watch_issues(repo, issue_number)`,
|
|
341
|
+
`CREATE TABLE watch_notes (
|
|
342
|
+
id TEXT PRIMARY KEY,
|
|
343
|
+
repo TEXT NOT NULL,
|
|
344
|
+
issue_number INTEGER NOT NULL,
|
|
345
|
+
comment_id TEXT NOT NULL,
|
|
346
|
+
author TEXT,
|
|
347
|
+
kind TEXT NOT NULL,
|
|
348
|
+
body TEXT NOT NULL,
|
|
349
|
+
note TEXT,
|
|
350
|
+
created_at TEXT NOT NULL,
|
|
351
|
+
applied_at TEXT,
|
|
352
|
+
UNIQUE(repo, comment_id)
|
|
353
|
+
)`,
|
|
354
|
+
],
|
|
292
355
|
];
|
|
@@ -7,7 +7,7 @@ export declare function activateRepo(fullName: string, installationId: number |
|
|
|
7
7
|
export declare function registerCliRepo(fullName: string, knowledgeBuiltAt?: string): boolean;
|
|
8
8
|
export declare function deactivateRepo(fullName: string): void;
|
|
9
9
|
export declare function deactivateReposForInstallation(installationId: number): void;
|
|
10
|
-
export declare function updateRepoSettings(fullName: string, patch: Partial<Pick<RepoRow, "auto_review" | "review_scope" | "skip_drafts" | "skip_bots" | "use_codegraph" | "review_policy_json">>): void;
|
|
10
|
+
export declare function updateRepoSettings(fullName: string, patch: Partial<Pick<RepoRow, "auto_review" | "review_scope" | "skip_drafts" | "skip_bots" | "use_codegraph" | "review_policy_json" | "watch_open_issues" | "watch_push_mode">>): void;
|
|
11
11
|
export declare function markKnowledgeBuilt(fullName: string, baseSha: string): void;
|
|
12
12
|
/** Forgets the built knowledge: the stamp every review and the dashboard read
|
|
13
13
|
* as "built", and the drift baseline that only meant anything against it. */
|
package/dist/src/store/rows.d.ts
CHANGED
|
@@ -30,6 +30,12 @@ export type RepoRow = {
|
|
|
30
30
|
/** `'cli'` when a CLI init built it, NULL when added from the dashboard.
|
|
31
31
|
* Optional so a row built by hand (a test fixture) need not name it. */
|
|
32
32
|
added_from?: string | null;
|
|
33
|
+
/** Commit watch: 1 opens an issue for each P0/P1 finding. Optional so a
|
|
34
|
+
* hand-built fixture need not name it; missing means on. */
|
|
35
|
+
watch_open_issues?: number;
|
|
36
|
+
/** Commit watch: `queue` reviews pushes in a row one by one,
|
|
37
|
+
* `cancel-and-merge` folds a waiting or running review into the next. */
|
|
38
|
+
watch_push_mode?: string;
|
|
33
39
|
};
|
|
34
40
|
export type JobRow = {
|
|
35
41
|
id: string;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { ReviewRow, SubjectRow } from "./rows.ts";
|
|
2
|
+
export type PushSource = "app" | "ci";
|
|
3
|
+
export type PushEventRow = {
|
|
4
|
+
repo: string;
|
|
5
|
+
after_sha: string;
|
|
6
|
+
before_sha: string;
|
|
7
|
+
ref: string;
|
|
8
|
+
/** JSON array of `PushSource`. */
|
|
9
|
+
sources: string;
|
|
10
|
+
review_id: string | null;
|
|
11
|
+
job_id: string | null;
|
|
12
|
+
created_at: string;
|
|
13
|
+
};
|
|
14
|
+
export type WatchIssueState = "open" | "closed_by_us" | "closed_by_user" | "ignored";
|
|
15
|
+
/** For an issue a maintainer closed: `pending` until the first push review
|
|
16
|
+
* after the closing checks it, then `still_found` or `fixed`. */
|
|
17
|
+
export type ClosedCheck = "pending" | "still_found" | "fixed";
|
|
18
|
+
export type WatchIssueRow = {
|
|
19
|
+
id: string;
|
|
20
|
+
repo: string;
|
|
21
|
+
issue_number: number;
|
|
22
|
+
severity: string;
|
|
23
|
+
title: string;
|
|
24
|
+
body_md: string;
|
|
25
|
+
path: string | null;
|
|
26
|
+
line_from: number | null;
|
|
27
|
+
line_to: number | null;
|
|
28
|
+
anchor_text: string | null;
|
|
29
|
+
state: WatchIssueState;
|
|
30
|
+
closed_check: ClosedCheck | null;
|
|
31
|
+
opened_review_id: string;
|
|
32
|
+
last_review_id: string | null;
|
|
33
|
+
last_check: string | null;
|
|
34
|
+
last_check_at: string | null;
|
|
35
|
+
created_at: string;
|
|
36
|
+
updated_at: string;
|
|
37
|
+
};
|
|
38
|
+
export type WatchNoteRow = {
|
|
39
|
+
id: string;
|
|
40
|
+
repo: string;
|
|
41
|
+
issue_number: number;
|
|
42
|
+
comment_id: string;
|
|
43
|
+
author: string | null;
|
|
44
|
+
kind: "ignore" | "info";
|
|
45
|
+
body: string;
|
|
46
|
+
note: string | null;
|
|
47
|
+
created_at: string;
|
|
48
|
+
applied_at: string | null;
|
|
49
|
+
};
|
|
50
|
+
export declare function pushSources(row: PushEventRow): PushSource[];
|
|
51
|
+
export declare function getPushEvent(repo: string, afterSha: string): PushEventRow | undefined;
|
|
52
|
+
export declare function insertPushEvent(row: {
|
|
53
|
+
repo: string;
|
|
54
|
+
afterSha: string;
|
|
55
|
+
beforeSha: string;
|
|
56
|
+
ref: string;
|
|
57
|
+
source: PushSource;
|
|
58
|
+
}): void;
|
|
59
|
+
export declare function addPushSource(repo: string, afterSha: string, source: PushSource): void;
|
|
60
|
+
export declare function setPushEventReview(repo: string, afterSha: string, reviewId: string, jobId: string): void;
|
|
61
|
+
/** Every push whose review moves to a merged one, so a CI step still waiting
|
|
62
|
+
* on an older push finds the review that now covers it. */
|
|
63
|
+
export declare function movePushEvents(fromReviewId: string, toReviewId: string, toJobId: string): void;
|
|
64
|
+
export declare function listPushEventsForReview(reviewId: string): PushEventRow[];
|
|
65
|
+
export declare function getOrCreatePushSubject(repo: string, branch: string): SubjectRow;
|
|
66
|
+
export declare function insertPushReview(row: {
|
|
67
|
+
id: string;
|
|
68
|
+
subjectId: string;
|
|
69
|
+
repo: string;
|
|
70
|
+
branch: string;
|
|
71
|
+
jobId: string;
|
|
72
|
+
beforeSha: string;
|
|
73
|
+
afterSha: string;
|
|
74
|
+
model: string;
|
|
75
|
+
}): void;
|
|
76
|
+
export declare function setPushReviewRange(reviewId: string, beforeSha: string): void;
|
|
77
|
+
export declare function listPushReviewsForRepo(repo: string, limit?: number): ReviewRow[];
|
|
78
|
+
export declare function latestPushReview(repo: string): ReviewRow | undefined;
|
|
79
|
+
export declare function savePushInput(jobId: string, revisionJson: string): void;
|
|
80
|
+
export declare function getPushInput(jobId: string): string | undefined;
|
|
81
|
+
export declare function deletePushInput(jobId: string): void;
|
|
82
|
+
export declare function savePushResult(reviewId: string, result: unknown): void;
|
|
83
|
+
export declare function getPushResult(reviewId: string): Record<string, unknown> | undefined;
|
|
84
|
+
export declare function insertWatchIssue(row: {
|
|
85
|
+
repo: string;
|
|
86
|
+
issueNumber: number;
|
|
87
|
+
severity: string;
|
|
88
|
+
title: string;
|
|
89
|
+
bodyMd: string;
|
|
90
|
+
path: string | null;
|
|
91
|
+
lineFrom: number | null;
|
|
92
|
+
lineTo: number | null;
|
|
93
|
+
anchorText: string | null;
|
|
94
|
+
reviewId: string;
|
|
95
|
+
}): WatchIssueRow;
|
|
96
|
+
export declare function getWatchIssue(repo: string, issueNumber: number): WatchIssueRow | undefined;
|
|
97
|
+
export declare function listWatchIssues(repo: string): WatchIssueRow[];
|
|
98
|
+
export declare function updateWatchIssue(id: string, patch: Partial<Pick<WatchIssueRow, "state" | "closed_check" | "path" | "line_from" | "line_to" | "anchor_text" | "last_review_id" | "last_check" | "last_check_at">>): void;
|
|
99
|
+
export declare function insertWatchNote(row: {
|
|
100
|
+
repo: string;
|
|
101
|
+
issueNumber: number;
|
|
102
|
+
commentId: string;
|
|
103
|
+
author: string | null;
|
|
104
|
+
kind: "ignore" | "info";
|
|
105
|
+
body: string;
|
|
106
|
+
}): boolean;
|
|
107
|
+
export declare function listWatchNotes(repo: string): WatchNoteRow[];
|
|
108
|
+
export declare function markWatchNoteApplied(id: string, note: string): void;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/** Commit watch tables: the pushes to a default branch, the issues opened
|
|
2
|
+
* for their P0/P1 findings, and the notes maintainers left on those issues. */
|
|
3
|
+
import { getAppDb } from "./app_db.js";
|
|
4
|
+
import { nowIso } from "../util/time.js";
|
|
5
|
+
export function pushSources(row) {
|
|
6
|
+
try {
|
|
7
|
+
const parsed = JSON.parse(row.sources);
|
|
8
|
+
return Array.isArray(parsed)
|
|
9
|
+
? parsed.filter((s) => s === "app" || s === "ci")
|
|
10
|
+
: [];
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function getPushEvent(repo, afterSha) {
|
|
17
|
+
return getAppDb()
|
|
18
|
+
.prepare(`SELECT * FROM push_events WHERE repo = ? AND after_sha = ?`)
|
|
19
|
+
.get(repo, afterSha);
|
|
20
|
+
}
|
|
21
|
+
export function insertPushEvent(row) {
|
|
22
|
+
getAppDb()
|
|
23
|
+
.prepare(`INSERT INTO push_events
|
|
24
|
+
(repo, after_sha, before_sha, ref, sources, review_id, job_id, created_at)
|
|
25
|
+
VALUES (?, ?, ?, ?, ?, NULL, NULL, ?)`)
|
|
26
|
+
.run(row.repo, row.afterSha, row.beforeSha, row.ref, JSON.stringify([row.source]), nowIso());
|
|
27
|
+
}
|
|
28
|
+
export function addPushSource(repo, afterSha, source) {
|
|
29
|
+
const row = getPushEvent(repo, afterSha);
|
|
30
|
+
if (!row)
|
|
31
|
+
return;
|
|
32
|
+
const sources = new Set(pushSources(row));
|
|
33
|
+
sources.add(source);
|
|
34
|
+
getAppDb()
|
|
35
|
+
.prepare(`UPDATE push_events SET sources = ? WHERE repo = ? AND after_sha = ?`)
|
|
36
|
+
.run(JSON.stringify([...sources]), repo, afterSha);
|
|
37
|
+
}
|
|
38
|
+
export function setPushEventReview(repo, afterSha, reviewId, jobId) {
|
|
39
|
+
getAppDb()
|
|
40
|
+
.prepare(`UPDATE push_events SET review_id = ?, job_id = ?
|
|
41
|
+
WHERE repo = ? AND after_sha = ?`)
|
|
42
|
+
.run(reviewId, jobId, repo, afterSha);
|
|
43
|
+
}
|
|
44
|
+
/** Every push whose review moves to a merged one, so a CI step still waiting
|
|
45
|
+
* on an older push finds the review that now covers it. */
|
|
46
|
+
export function movePushEvents(fromReviewId, toReviewId, toJobId) {
|
|
47
|
+
getAppDb()
|
|
48
|
+
.prepare(`UPDATE push_events SET review_id = ?, job_id = ? WHERE review_id = ?`)
|
|
49
|
+
.run(toReviewId, toJobId, fromReviewId);
|
|
50
|
+
}
|
|
51
|
+
export function listPushEventsForReview(reviewId) {
|
|
52
|
+
return getAppDb()
|
|
53
|
+
.prepare(`SELECT * FROM push_events WHERE review_id = ? ORDER BY created_at`)
|
|
54
|
+
.all(reviewId);
|
|
55
|
+
}
|
|
56
|
+
export function getOrCreatePushSubject(repo, branch) {
|
|
57
|
+
const db = getAppDb();
|
|
58
|
+
const existing = db
|
|
59
|
+
.prepare(`SELECT * FROM subjects WHERE kind = 'push' AND repo = ? AND branch = ?`)
|
|
60
|
+
.get(repo, branch);
|
|
61
|
+
if (existing)
|
|
62
|
+
return existing;
|
|
63
|
+
const row = {
|
|
64
|
+
id: crypto.randomUUID(),
|
|
65
|
+
kind: "push",
|
|
66
|
+
repo,
|
|
67
|
+
pr_number: null,
|
|
68
|
+
branch,
|
|
69
|
+
token_id: null,
|
|
70
|
+
created_at: nowIso(),
|
|
71
|
+
updated_at: nowIso(),
|
|
72
|
+
};
|
|
73
|
+
db.prepare(`INSERT INTO subjects (id, kind, repo, pr_number, branch, token_id, created_at, updated_at)
|
|
74
|
+
VALUES (?, 'push', ?, NULL, ?, NULL, ?, ?)`).run(row.id, repo, branch, row.created_at, row.updated_at);
|
|
75
|
+
return row;
|
|
76
|
+
}
|
|
77
|
+
export function insertPushReview(row) {
|
|
78
|
+
getAppDb()
|
|
79
|
+
.prepare(`INSERT INTO reviews
|
|
80
|
+
(id, kind, subject_id, repo, pr_number, branch, token_id, token_name,
|
|
81
|
+
job_id, head_sha, base_sha, scope, model, status, created_at, round,
|
|
82
|
+
"trigger", cost_status, cost_note, billed_to)
|
|
83
|
+
VALUES (?, 'push', ?, ?, NULL, ?, NULL, NULL, ?, ?, ?, 'push', ?, 'queued', ?, 1,
|
|
84
|
+
'push', 'unknown', 'not_recorded', 'server')`)
|
|
85
|
+
.run(row.id, row.subjectId, row.repo, row.branch, row.jobId, row.afterSha, row.beforeSha, row.model, nowIso());
|
|
86
|
+
}
|
|
87
|
+
export function setPushReviewRange(reviewId, beforeSha) {
|
|
88
|
+
getAppDb()
|
|
89
|
+
.prepare(`UPDATE reviews SET base_sha = ? WHERE id = ?`)
|
|
90
|
+
.run(beforeSha, reviewId);
|
|
91
|
+
}
|
|
92
|
+
export function listPushReviewsForRepo(repo, limit = 50) {
|
|
93
|
+
return getAppDb()
|
|
94
|
+
.prepare(`SELECT * FROM reviews WHERE repo = ? AND kind = 'push'
|
|
95
|
+
ORDER BY created_at DESC LIMIT ?`)
|
|
96
|
+
.all(repo, limit);
|
|
97
|
+
}
|
|
98
|
+
export function latestPushReview(repo) {
|
|
99
|
+
return getAppDb()
|
|
100
|
+
.prepare(`SELECT * FROM reviews WHERE repo = ? AND kind = 'push'
|
|
101
|
+
ORDER BY created_at DESC LIMIT 1`)
|
|
102
|
+
.get(repo);
|
|
103
|
+
}
|
|
104
|
+
export function savePushInput(jobId, revisionJson) {
|
|
105
|
+
getAppDb()
|
|
106
|
+
.prepare(`INSERT OR REPLACE INTO push_inputs (job_id, revision_json, created_at)
|
|
107
|
+
VALUES (?, ?, ?)`)
|
|
108
|
+
.run(jobId, revisionJson, nowIso());
|
|
109
|
+
}
|
|
110
|
+
export function getPushInput(jobId) {
|
|
111
|
+
return getAppDb()
|
|
112
|
+
.prepare(`SELECT revision_json FROM push_inputs WHERE job_id = ?`)
|
|
113
|
+
.get(jobId)?.revision_json;
|
|
114
|
+
}
|
|
115
|
+
export function deletePushInput(jobId) {
|
|
116
|
+
getAppDb().prepare(`DELETE FROM push_inputs WHERE job_id = ?`).run(jobId);
|
|
117
|
+
}
|
|
118
|
+
export function savePushResult(reviewId, result) {
|
|
119
|
+
getAppDb()
|
|
120
|
+
.prepare(`INSERT OR REPLACE INTO push_results (review_id, result_json, created_at)
|
|
121
|
+
VALUES (?, ?, ?)`)
|
|
122
|
+
.run(reviewId, JSON.stringify(result), nowIso());
|
|
123
|
+
}
|
|
124
|
+
export function getPushResult(reviewId) {
|
|
125
|
+
const raw = getAppDb()
|
|
126
|
+
.prepare(`SELECT result_json FROM push_results WHERE review_id = ?`)
|
|
127
|
+
.get(reviewId)?.result_json;
|
|
128
|
+
if (!raw)
|
|
129
|
+
return undefined;
|
|
130
|
+
try {
|
|
131
|
+
return JSON.parse(raw);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
export function insertWatchIssue(row) {
|
|
138
|
+
const id = crypto.randomUUID();
|
|
139
|
+
const now = nowIso();
|
|
140
|
+
getAppDb()
|
|
141
|
+
.prepare(`INSERT INTO watch_issues
|
|
142
|
+
(id, repo, issue_number, severity, title, body_md, path, line_from,
|
|
143
|
+
line_to, anchor_text, state, closed_check, opened_review_id,
|
|
144
|
+
last_review_id, last_check, last_check_at, created_at, updated_at)
|
|
145
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'open', NULL, ?, ?, NULL, NULL, ?, ?)`)
|
|
146
|
+
.run(id, row.repo, row.issueNumber, row.severity, row.title, row.bodyMd, row.path, row.lineFrom, row.lineTo, row.anchorText, row.reviewId, row.reviewId, now, now);
|
|
147
|
+
return getWatchIssue(row.repo, row.issueNumber);
|
|
148
|
+
}
|
|
149
|
+
export function getWatchIssue(repo, issueNumber) {
|
|
150
|
+
return getAppDb()
|
|
151
|
+
.prepare(`SELECT * FROM watch_issues WHERE repo = ? AND issue_number = ?`)
|
|
152
|
+
.get(repo, issueNumber);
|
|
153
|
+
}
|
|
154
|
+
export function listWatchIssues(repo) {
|
|
155
|
+
return getAppDb()
|
|
156
|
+
.prepare(`SELECT * FROM watch_issues WHERE repo = ? ORDER BY issue_number`)
|
|
157
|
+
.all(repo);
|
|
158
|
+
}
|
|
159
|
+
export function updateWatchIssue(id, patch) {
|
|
160
|
+
const fields = Object.keys(patch);
|
|
161
|
+
if (fields.length === 0)
|
|
162
|
+
return;
|
|
163
|
+
const set = [...fields.map((field) => `${field} = ?`), "updated_at = ?"].join(", ");
|
|
164
|
+
getAppDb()
|
|
165
|
+
.prepare(`UPDATE watch_issues SET ${set} WHERE id = ?`)
|
|
166
|
+
.run(...fields.map((field) => (patch[field] ?? null)), nowIso(), id);
|
|
167
|
+
}
|
|
168
|
+
export function insertWatchNote(row) {
|
|
169
|
+
const result = getAppDb()
|
|
170
|
+
.prepare(`INSERT OR IGNORE INTO watch_notes
|
|
171
|
+
(id, repo, issue_number, comment_id, author, kind, body, note,
|
|
172
|
+
created_at, applied_at)
|
|
173
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, NULL, ?, NULL)`)
|
|
174
|
+
.run(crypto.randomUUID(), row.repo, row.issueNumber, row.commentId, row.author, row.kind, row.body, nowIso());
|
|
175
|
+
return Number(result.changes ?? 0) > 0;
|
|
176
|
+
}
|
|
177
|
+
export function listWatchNotes(repo) {
|
|
178
|
+
return getAppDb()
|
|
179
|
+
.prepare(`SELECT * FROM watch_notes WHERE repo = ? ORDER BY created_at`)
|
|
180
|
+
.all(repo);
|
|
181
|
+
}
|
|
182
|
+
export function markWatchNoteApplied(id, note) {
|
|
183
|
+
getAppDb()
|
|
184
|
+
.prepare(`UPDATE watch_notes SET note = ?, applied_at = ? WHERE id = ?`)
|
|
185
|
+
.run(note, nowIso(), id);
|
|
186
|
+
}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -78,6 +78,8 @@ export type GitHubClient = {
|
|
|
78
78
|
/** POST JSON. Optional so collect-test fakes stay GET-only. Review
|
|
79
79
|
* posting requires it. */
|
|
80
80
|
write?<T>(endpoint: string, body: unknown): Promise<T>;
|
|
81
|
+
/** PATCH JSON, for closing an issue. Only the App client has it. */
|
|
82
|
+
patch?<T>(endpoint: string, body: unknown): Promise<T>;
|
|
81
83
|
/** GitHub Checks API operations. Optional so read-only test clients and
|
|
82
84
|
* older integrations can continue to review without check runs. */
|
|
83
85
|
createCheckRun?<T>(endpoint: string, body: unknown): Promise<T>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** One spelling per repository (issue #67).
|
|
2
|
+
*
|
|
3
|
+
* GitHub treats `owner/repo` without regard to case, but co-maintainer keys a
|
|
4
|
+
* repository by its name: the `repos` entry in config.json, the guide folder
|
|
5
|
+
* and the app.db row. Typed two ways, it became two repositories.
|
|
6
|
+
*
|
|
7
|
+
* A name is matched against what is already stored, ignoring case, and the
|
|
8
|
+
* stored spelling wins, so nothing written before changes. A repository seen
|
|
9
|
+
* for the first time is stored in lower case. */
|
|
10
|
+
import { readdirSync } from "node:fs";
|
|
11
|
+
import { readConfig, reposDir } from "../config.js";
|
|
12
|
+
import { getAppDb, isAppDbOpen } from "../store/app_db.js";
|
|
13
|
+
function storedInDb(lower) {
|
|
14
|
+
if (!isAppDbOpen())
|
|
15
|
+
return undefined;
|
|
16
|
+
try {
|
|
17
|
+
return getAppDb()
|
|
18
|
+
.prepare(`SELECT full_name FROM repos WHERE lower(full_name) = ?
|
|
19
|
+
ORDER BY active DESC, created_at LIMIT 1`)
|
|
20
|
+
.get(lower)?.full_name;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function storedInConfig(lower) {
|
|
27
|
+
try {
|
|
28
|
+
return Object.keys(readConfig().repos ?? {}).find((name) => name.toLowerCase() === lower);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function caseInsensitiveEntry(dir, name) {
|
|
35
|
+
try {
|
|
36
|
+
return readdirSync(dir).find((entry) => entry.toLowerCase() === name.toLowerCase());
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function storedOnDisk(lower) {
|
|
43
|
+
const [owner, repo] = lower.split("/");
|
|
44
|
+
const ownerDir = caseInsensitiveEntry(reposDir(), owner);
|
|
45
|
+
if (!ownerDir)
|
|
46
|
+
return undefined;
|
|
47
|
+
const repoDir = caseInsensitiveEntry(`${reposDir()}/${ownerDir}`, repo);
|
|
48
|
+
return repoDir ? `${ownerDir}/${repoDir}` : undefined;
|
|
49
|
+
}
|
|
50
|
+
/** The spelling to use for `name` (`owner/repo`). */
|
|
51
|
+
export function canonicalRepoName(name) {
|
|
52
|
+
const lower = name.toLowerCase();
|
|
53
|
+
if (!/^[^/]+\/[^/]+$/.test(lower))
|
|
54
|
+
return name;
|
|
55
|
+
return (storedInDb(lower) ?? storedInConfig(lower) ?? storedOnDisk(lower) ?? lower);
|
|
56
|
+
}
|