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.
Files changed (66) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/src/ai/fake.d.ts +10 -1
  3. package/dist/src/ai/fake.js +39 -4
  4. package/dist/src/cli/args.js +2 -0
  5. package/dist/src/cli/command_json.d.ts +6 -0
  6. package/dist/src/cli/command_json.js +1 -0
  7. package/dist/src/cli/commands/probe.js +25 -0
  8. package/dist/src/cli/commands/registry.js +11 -0
  9. package/dist/src/cli/commands/review.js +5 -1
  10. package/dist/src/cli/commands/serve.js +4 -0
  11. package/dist/src/cli/commands/set.js +4 -2
  12. package/dist/src/cli/review_args.d.ts +9 -0
  13. package/dist/src/cli/review_args.js +36 -1
  14. package/dist/src/github/app.d.ts +4 -0
  15. package/dist/src/github/app.js +10 -1
  16. package/dist/src/github/permissions.js +40 -0
  17. package/dist/src/github/write_access.d.ts +7 -0
  18. package/dist/src/github/write_access.js +12 -0
  19. package/dist/src/local/git_ops.js +3 -2
  20. package/dist/src/local/git_revision.d.ts +5 -2
  21. package/dist/src/local/git_revision.js +17 -10
  22. package/dist/src/pr/reviewer.d.ts +2 -0
  23. package/dist/src/pr/reviewer.js +1 -1
  24. package/dist/src/remote/push_client.d.ts +7 -0
  25. package/dist/src/remote/push_client.js +287 -0
  26. package/dist/src/remote/server/routes.d.ts +1 -0
  27. package/dist/src/remote/server/routes.js +61 -4
  28. package/dist/src/remote/server/sync.js +11 -3
  29. package/dist/src/remote/validate.js +17 -0
  30. package/dist/src/review/carry_over.d.ts +2 -0
  31. package/dist/src/review/carry_over.js +33 -26
  32. package/dist/src/server/api/repos.js +13 -2
  33. package/dist/src/server/pages/layout.js +1 -0
  34. package/dist/src/server/pages/repo.d.ts +3 -1
  35. package/dist/src/server/pages/repo.js +4 -1
  36. package/dist/src/server/pages/repo_pushes.d.ts +7 -0
  37. package/dist/src/server/pages/repo_pushes.js +144 -0
  38. package/dist/src/server/pages/repo_settings.js +45 -1
  39. package/dist/src/server/pages/router.js +22 -3
  40. package/dist/src/server/webhook/index.js +8 -1
  41. package/dist/src/services/dashboard.d.ts +46 -0
  42. package/dist/src/services/dashboard.js +24 -0
  43. package/dist/src/services/jobs.js +10 -0
  44. package/dist/src/services/push_review.d.ts +51 -0
  45. package/dist/src/services/push_review.js +878 -0
  46. package/dist/src/services/review.d.ts +20 -3
  47. package/dist/src/services/review.js +112 -39
  48. package/dist/src/services/setup.js +21 -0
  49. package/dist/src/services/watch_comments.d.ts +10 -0
  50. package/dist/src/services/watch_comments.js +166 -0
  51. package/dist/src/services/watch_issues.d.ts +70 -0
  52. package/dist/src/services/watch_issues.js +266 -0
  53. package/dist/src/services/watch_notes.d.ts +8 -0
  54. package/dist/src/services/watch_notes.js +80 -0
  55. package/dist/src/services/watch_status.d.ts +25 -0
  56. package/dist/src/services/watch_status.js +101 -0
  57. package/dist/src/services/webhook.js +108 -8
  58. package/dist/src/store/migrations.js +63 -0
  59. package/dist/src/store/repos.d.ts +1 -1
  60. package/dist/src/store/rows.d.ts +6 -0
  61. package/dist/src/store/watch.d.ts +108 -0
  62. package/dist/src/store/watch.js +186 -0
  63. package/dist/src/types.d.ts +2 -0
  64. package/dist/src/util/repo_name.d.ts +2 -0
  65. package/dist/src/util/repo_name.js +56 -0
  66. package/package.json +1 -1
@@ -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");
@@ -2,7 +2,7 @@ import { clearOauthStateCookieHeader, clearSessionCookieHeader, createSession, l
2
2
  import { githubAuthorizeUrl, githubLoginFromCode } from "../../github/oauth.js";
3
3
  import { readBoundedUtf8 } from "../../remote/server/body.js";
4
4
  import { handleClient, handleLogo, handleStyles } from "../assets.js";
5
- 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";
6
6
  import { escapeHtml, html, notFound } from "./layout.js";
7
7
  import { formatCostTotal } from "./cost.js";
8
8
  import { readConfig, writeUserConfig } from "../../config.js";
@@ -14,6 +14,9 @@ import { renderAddRepo } from "./add_repo.js";
14
14
  import { renderRepo } from "./repo.js";
15
15
  import { renderRepoPulls } from "./repo_prs.js";
16
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";
17
20
  import { renderPr } from "./pr.js";
18
21
  import { renderKnowledge } from "./knowledge.js";
19
22
  import { renderRepoSettings } from "./repo_settings.js";
@@ -28,7 +31,19 @@ import { getLogsSince } from "../../services/jobs.js";
28
31
  import { listInstallationsWithRepos, listOpenPulls } from "../../github/app.js";
29
32
  import { setupChecklist } from "../../services/setup_checklist.js";
30
33
  import { appReady, filterRepoList, repoState, } from "../../services/repo_list.js";
31
- const REPO = /^\/repos\/([^/]+)\/([^/]+)(?:\/(pulls|knowledge|settings|remote)(?:\/(\d+))?)?$/;
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+))?)?$/;
32
47
  /** Matches a repository page URL. Only `pulls` is keyed by a number, so a stray
33
48
  * suffix such as `/repos/o/r/remote/7` must fall through to a 404 rather than
34
49
  * render the listing and silently drop the number. */
@@ -184,7 +199,11 @@ export async function handlePageRequest(request, deps, ip) {
184
199
  const pr = match[4] ? Number(match[4]) : undefined;
185
200
  if (!sub) {
186
201
  const config = readConfig();
187
- return renderRepo(username, repoOverview(fullName), config.webhookUrl || deps.webhookUrl || "");
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));
188
207
  }
189
208
  if (sub === "pulls" && pr) {
190
209
  return renderPr(username, fullName, prDetail(fullName, pr));
@@ -4,6 +4,7 @@ import { hasDelivery, recordDelivery } from "../../store/deliveries.js";
4
4
  import { dispatchGithubEvent } from "../../services/webhook.js";
5
5
  import { readBoundedBytes } from "../../remote/server/body.js";
6
6
  import { verifySignature } from "./signature.js";
7
+ import { canonicalRepoName } from "../../util/repo_name.js";
7
8
  /** GitHub caps a webhook payload at 25 MB; nothing larger is genuine. */
8
9
  const WEBHOOK_MAX_BODY_BYTES = 25 * 1024 * 1024;
9
10
  function json(status, body) {
@@ -44,8 +45,14 @@ export async function handleWebhookRequest(request, secret) {
44
45
  Array.isArray(payload)) {
45
46
  return errorResponse(400, "bad_request", "body is not a JSON object");
46
47
  }
48
+ // GitHub sends the owner's own spelling, which may not be the one this
49
+ // server stored the repository under (issue #67).
50
+ const repository = payload.repository;
51
+ if (repository && typeof repository.full_name === "string") {
52
+ repository.full_name = canonicalRepoName(repository.full_name);
53
+ }
47
54
  const config = readConfig();
48
- const repoFullName = payload.repository?.full_name;
55
+ const repoFullName = repository?.full_name;
49
56
  const repoName = typeof repoFullName === "string" ? repoFullName : undefined;
50
57
  const repoConfig = repoName ? config.repos?.[repoName] : undefined;
51
58
  const maxDiffLines = repoConfig?.maxPullRequestChangeLines ??
@@ -105,6 +105,52 @@ export declare function repoRemoteReviews(fullName: string, limit?: number): {
105
105
  items: ReviewRow[];
106
106
  stats: import("../store/reviews.ts").ReviewStats;
107
107
  };
108
+ /** The Pushes tab: each commit watch review with its findings by severity,
109
+ * how the push arrived, and the issues it opened. */
110
+ export declare function repoPushes(fullName: string, limit?: number): {
111
+ items: {
112
+ via: import("../store/watch.ts").PushSource[];
113
+ p0: number;
114
+ p1: number;
115
+ p2: number;
116
+ p3: number;
117
+ issuesOpened: number;
118
+ id: string;
119
+ kind: string;
120
+ subject_id: string | null;
121
+ repo: string;
122
+ pr_number: number | null;
123
+ branch: string | null;
124
+ token_id: string | null;
125
+ token_name: string | null;
126
+ job_id: string;
127
+ head_sha: string | null;
128
+ base_sha: string | null;
129
+ scope: string;
130
+ model: string;
131
+ findings_count: number;
132
+ open_count: number;
133
+ closed_count: number;
134
+ tokens_in: number;
135
+ tokens_out: number;
136
+ cost: number | null;
137
+ cost_status: "known" | "unknown" | null;
138
+ cost_note: string | null;
139
+ billed_to: "server" | "byok" | null;
140
+ duration_ms: number | null;
141
+ posted_review_id: string | null;
142
+ status: string;
143
+ created_at: string;
144
+ round: number;
145
+ trigger: string | null;
146
+ check_run_id: string | null;
147
+ posted_fallback: number;
148
+ guide_built_at: string | null;
149
+ codegraph: string | null;
150
+ note_comment_id: string | null;
151
+ }[];
152
+ openIssues: number;
153
+ };
108
154
  export declare function repoPulls(fullName: string, page: number, per: number): {
109
155
  items: import("../store/reviews.ts").PullSummary[];
110
156
  page: number;
@@ -8,6 +8,8 @@ import { getRepo, listActiveRepos } from "../store/repos.js";
8
8
  import { listLatestReviewsForRepo, listPullSummaries, listRecentReviews, listReviewsForPr, reviewStats, reviewStatsByDay, reviewStatsByKind, reviewStatsByModel, reviewStatsByRemoteToken, listRemoteReviewsForRepo, reviewStatsByRepo, } from "../store/reviews.js";
9
9
  import { findingStatsBySeverity, listFindingsForReview, } from "../store/findings.js";
10
10
  import { daysAgoIso } from "../util/time.js";
11
+ import { listPushReviewsForRepo, listWatchIssues } from "../store/watch.js";
12
+ import { pushVia } from "./watch_status.js";
11
13
  import { isNotFound, readTextFile } from "../util/runtime.js";
12
14
  export function requireActiveRepo(fullName) {
13
15
  const row = getRepo(fullName);
@@ -116,6 +118,28 @@ export function repoRemoteReviews(fullName, limit = 30) {
116
118
  stats: reviewStats(since, fullName),
117
119
  };
118
120
  }
121
+ /** The Pushes tab: each commit watch review with its findings by severity,
122
+ * how the push arrived, and the issues it opened. */
123
+ export function repoPushes(fullName, limit = 50) {
124
+ requireActiveRepo(fullName);
125
+ const issues = listWatchIssues(fullName);
126
+ return {
127
+ items: listPushReviewsForRepo(fullName, limit).map((review) => {
128
+ const severities = listFindingsForReview(review.id).map((f) => f.severity);
129
+ const count = (severity) => severities.filter((s) => s === severity).length;
130
+ return {
131
+ ...review,
132
+ via: pushVia(fullName, review),
133
+ p0: count("P0"),
134
+ p1: count("P1"),
135
+ p2: count("P2"),
136
+ p3: count("P3"),
137
+ issuesOpened: issues.filter((issue) => issue.opened_review_id === review.id).length,
138
+ };
139
+ }),
140
+ openIssues: issues.filter((issue) => issue.state === "open").length,
141
+ };
142
+ }
119
143
  export function repoPulls(fullName, page, per) {
120
144
  requireActiveRepo(fullName);
121
145
  const safePage = Number.isFinite(page) && page > 0 ? Math.floor(page) : 1;
@@ -122,6 +122,11 @@ function claimNextEligible() {
122
122
  ? runningRemoteReviewsPerToken()
123
123
  : undefined;
124
124
  const oldestFirst = listJobs({ status: "queued" }).slice().reverse();
125
+ // Push reviews of one repository run one after another, oldest first, so a
126
+ // later push sees the issues an earlier one opened.
127
+ const pushRepos = new Set(listJobs({ status: "running" })
128
+ .filter((job) => job.type === "push_review")
129
+ .map((job) => job.repo));
125
130
  for (const candidate of oldestFirst) {
126
131
  if (!handlers.has(candidate.type))
127
132
  continue;
@@ -130,6 +135,11 @@ function claimNextEligible() {
130
135
  if (busy)
131
136
  continue;
132
137
  }
138
+ if (candidate.type === "push_review") {
139
+ if (pushRepos.has(candidate.repo))
140
+ continue;
141
+ pushRepos.add(candidate.repo);
142
+ }
133
143
  if (perTokenLimit && candidate.type === "remote_review") {
134
144
  const review = getReviewByJobId(candidate.id);
135
145
  const tokenId = review?.token_id;
@@ -0,0 +1,51 @@
1
+ import { type Revision } from "../review/revision.ts";
2
+ import { type PushSource } from "../store/watch.ts";
3
+ import type { JobRow } from "../store/rows.ts";
4
+ export declare const PUSH_JOB = "push_review";
5
+ export declare const PUSH_CHECK_JOB = "push_check";
6
+ export declare const CHECK_NAME = "co-maintainer commit watch";
7
+ export declare function isSha(value: unknown): value is string;
8
+ export declare function isZeroSha(value: string): boolean;
9
+ export type PushRequest = {
10
+ repo: string;
11
+ before: string;
12
+ after: string;
13
+ /** `refs/heads/<branch>`. */
14
+ ref: string;
15
+ source: PushSource;
16
+ /** The diff a CI step built. The App path builds its own from GitHub. */
17
+ revision?: Revision;
18
+ deliveryId?: string;
19
+ };
20
+ export type PushOutcome = {
21
+ kind: "enqueued" | "attached";
22
+ jobId: string;
23
+ reviewId: string;
24
+ } | {
25
+ kind: "no_changes";
26
+ } | {
27
+ kind: "skipped";
28
+ reason: string;
29
+ message: string;
30
+ checkRun: boolean;
31
+ }
32
+ /** cancel-and-merge folded this push into a waiting one, and only the
33
+ * client has the diff: it must send `before..after` instead. */
34
+ | {
35
+ kind: "extend";
36
+ before: string;
37
+ };
38
+ export declare const NOT_INITIALIZED = "This repository is not initialized.";
39
+ /** Records a push and decides what happens to it. Synchronous, so the
40
+ * webhook and the remote submit route can call it as they are. */
41
+ export declare function queuePush(req: PushRequest): PushOutcome;
42
+ export type IssueActivity = {
43
+ opened: number[];
44
+ stillFound: number[];
45
+ closed: number[];
46
+ closeDenied: number[];
47
+ closedStillFound: number[];
48
+ };
49
+ export declare function registerPushReviewHandlers(): void;
50
+ /** For the sync route: the stored result of a finished push review. */
51
+ export declare function pushJobStatus(jobId: string): JobRow | undefined;