@nanobpm/urban-pr-review-codefirst 1.2.1 → 1.3.0
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/CHANGELOG.md +7 -0
- package/actions/cancel.ts +20 -6
- package/actions/status.ts +22 -0
- package/app/service.ts +77 -14
- package/nano.app.json +5 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.3.0](https://github.com/jwulf/urban-pr-review-codefirst/compare/v1.2.1...v1.3.0) (2026-08-03)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* GET /app/status + cancel-by-prKey affordances ([#8](https://github.com/jwulf/urban-pr-review-codefirst/issues/8)) ([3df7fb3](https://github.com/jwulf/urban-pr-review-codefirst/commit/3df7fb3416625cf3e0170c5612f3671deb4d9563)), closes [#12](https://github.com/jwulf/urban-pr-review-codefirst/issues/12)
|
|
7
|
+
|
|
1
8
|
## [1.2.1](https://github.com/jwulf/urban-pr-review-codefirst/compare/v1.2.0...v1.2.1) (2026-08-03)
|
|
2
9
|
|
|
3
10
|
|
package/actions/cancel.ts
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
1
|
// POST /app/actions/cancel — override the generic row-cancel action. Terminating the engine
|
|
2
2
|
// instance emits no completion event, so reconcile the app row (status='abandoned', clear the
|
|
3
|
-
// open escalation) here.
|
|
3
|
+
// open escalation) here. Accepts either `processInstanceKey` or the `prKey` the status endpoint
|
|
4
|
+
// reports, so a caller can cancel a run it discovered via GET /app/status.
|
|
4
5
|
import type { ActionHandler } from "@nanobpm/urban";
|
|
5
6
|
import { cancelRun } from "../app/service.ts";
|
|
6
7
|
|
|
8
|
+
const str = (v: unknown): string | undefined => {
|
|
9
|
+
if (v == null) return undefined;
|
|
10
|
+
const s = String(v).trim();
|
|
11
|
+
return s === "" ? undefined : s;
|
|
12
|
+
};
|
|
13
|
+
|
|
7
14
|
const handler: ActionHandler = async ({ body }, app) => {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
15
|
+
const b = (body ?? {}) as { processInstanceKey?: unknown; prKey?: unknown };
|
|
16
|
+
const processInstanceKey = str(b.processInstanceKey);
|
|
17
|
+
const prKey = str(b.prKey);
|
|
18
|
+
if (!processInstanceKey && !prKey) {
|
|
19
|
+
return { status: 400, body: { error: "processInstanceKey or prKey is required" } };
|
|
11
20
|
}
|
|
12
|
-
|
|
13
|
-
|
|
21
|
+
if (processInstanceKey && prKey) {
|
|
22
|
+
return { status: 400, body: { error: "provide exactly one of processInstanceKey or prKey" } };
|
|
23
|
+
}
|
|
24
|
+
const r = await cancelRun(app.data, app.engine, { processInstanceKey, prKey });
|
|
25
|
+
if (r.ok) return { status: 200, body: r };
|
|
26
|
+
return { status: r.kind === "terminal" ? 409 : 404, body: r };
|
|
14
27
|
};
|
|
15
28
|
|
|
16
29
|
export default handler;
|
|
30
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// GET /app/status — list the PRs currently in flight (every tracked PR not converged/abandoned).
|
|
2
|
+
// A read-only projection over the app datasource so an operator or an external automation
|
|
3
|
+
// harness can see active work — and grab a prKey to cancel — without opening the DB or the UI.
|
|
4
|
+
//
|
|
5
|
+
// Optional shared-secret guard, mirroring /hooks/submit: when NANO_PR_WEBHOOK_SECRET is set,
|
|
6
|
+
// callers must present it via the x-hook-secret header. Unset → open (unchanged default). The
|
|
7
|
+
// pages UI does not call this endpoint (its grid reads the datasource directly), so the guard
|
|
8
|
+
// never affects the UI.
|
|
9
|
+
import type { ActionHandler } from "@nanobpm/urban";
|
|
10
|
+
import { activePrs } from "../app/service.ts";
|
|
11
|
+
|
|
12
|
+
const SECRET = process.env.NANO_PR_WEBHOOK_SECRET ?? "";
|
|
13
|
+
|
|
14
|
+
const handler: ActionHandler = async ({ req }, app) => {
|
|
15
|
+
if (SECRET && req.headers.get("x-hook-secret") !== SECRET) {
|
|
16
|
+
return { status: 401, body: { error: "unauthorized" } };
|
|
17
|
+
}
|
|
18
|
+
const prs = await activePrs(app.data);
|
|
19
|
+
return { status: 200, body: { count: prs.length, prs } };
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default handler;
|
package/app/service.ts
CHANGED
|
@@ -19,6 +19,10 @@ export interface ParsedPr {
|
|
|
19
19
|
|
|
20
20
|
const now = (): string => new Date().toISOString();
|
|
21
21
|
|
|
22
|
+
/** A PR is "done" in exactly these two states; everything else (converging, waiting_review,
|
|
23
|
+
* escalated) is in flight. The status endpoint and the cancel guard both key off this. */
|
|
24
|
+
export const TERMINAL_STATUSES: readonly string[] = ["converged", "abandoned"];
|
|
25
|
+
|
|
22
26
|
const prs = (data: DataLayer) => data.table<PullRequests>("pull_requests", "pr_key");
|
|
23
27
|
const rounds = (data: DataLayer) => data.table<Rounds>("rounds", "id");
|
|
24
28
|
const escalations = (data: DataLayer) => data.table<Escalations>("escalations", "id");
|
|
@@ -64,7 +68,7 @@ export async function submitPr(data: DataLayer, parsed: ParsedPr) {
|
|
|
64
68
|
const { repo, number, url, prKey } = parsed;
|
|
65
69
|
const table = prs(data);
|
|
66
70
|
const existing = await table.get(prKey);
|
|
67
|
-
if (existing && !
|
|
71
|
+
if (existing && !TERMINAL_STATUSES.includes(existing.status)) {
|
|
68
72
|
return { prKey, alreadyRunning: true };
|
|
69
73
|
}
|
|
70
74
|
const ts = now();
|
|
@@ -109,26 +113,85 @@ export async function answerEscalation(data: DataLayer, prKey: string, answer: s
|
|
|
109
113
|
return { ok: true, escalationId };
|
|
110
114
|
}
|
|
111
115
|
|
|
112
|
-
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
export
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
116
|
+
/** How a caller identifies the run to cancel: by its engine `processInstanceKey` or, more
|
|
117
|
+
* ergonomically, by the `prKey` the status endpoint reports. The cancel action rejects a
|
|
118
|
+
* request that supplies both, so exactly one selector reaches here. */
|
|
119
|
+
export interface CancelSelector {
|
|
120
|
+
processInstanceKey?: string;
|
|
121
|
+
prKey?: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Cancel a PR's running convergence instance and mark it abandoned. Terminating the engine
|
|
125
|
+
* instance emits no completion event (no worker runs), so the app-tier flips the PR's status
|
|
126
|
+
* here. Accepts either selector; a PR already in a terminal state is left untouched so a stale
|
|
127
|
+
* cancel can't overwrite a `converged` outcome with `abandoned`. */
|
|
128
|
+
export async function cancelRun(data: DataLayer, engine: EngineClient, selector: CancelSelector) {
|
|
129
|
+
const { processInstanceKey, prKey } = selector;
|
|
130
|
+
const table = prs(data);
|
|
131
|
+
const pr = prKey
|
|
132
|
+
? await table.get(prKey)
|
|
133
|
+
: processInstanceKey
|
|
134
|
+
? (await table.find({ process_key: processInstanceKey }))[0]
|
|
135
|
+
: undefined;
|
|
136
|
+
if (pr && TERMINAL_STATUSES.includes(pr.status)) {
|
|
137
|
+
return { ok: false, kind: "terminal", reason: `PR already ${pr.status}`, prKey: pr.pr_key };
|
|
138
|
+
}
|
|
139
|
+
const instanceKey = pr?.process_key ?? processInstanceKey ?? null;
|
|
140
|
+
if (instanceKey) {
|
|
141
|
+
try {
|
|
142
|
+
await engine.cancelInstance({ processInstanceKey: instanceKey });
|
|
143
|
+
} catch (err) {
|
|
144
|
+
// The instance may already be gone (converged/cancelled) — still reconcile the app row so
|
|
145
|
+
// a stale "converging" PR can't linger in the UI.
|
|
146
|
+
console.warn(`[cancel] engine cancel for ${instanceKey}: ${err}`);
|
|
147
|
+
}
|
|
123
148
|
}
|
|
124
149
|
if (pr) {
|
|
125
|
-
await
|
|
150
|
+
await table.update(String(pr.pr_key), {
|
|
126
151
|
status: "abandoned", updated_at: now(),
|
|
127
152
|
open_escalation_id: null, open_escalation_question: null,
|
|
128
153
|
});
|
|
129
154
|
return { ok: true, prKey: pr.pr_key };
|
|
130
155
|
}
|
|
131
|
-
return { ok: false, reason: "no PR for that
|
|
156
|
+
return { ok: false, kind: "not_found", reason: "no PR for that selector" };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** A PR currently in flight, as reported by the status endpoint. */
|
|
160
|
+
export interface ActivePr {
|
|
161
|
+
prKey: string;
|
|
162
|
+
repo: string;
|
|
163
|
+
number: number;
|
|
164
|
+
url: string;
|
|
165
|
+
title: string | null;
|
|
166
|
+
status: string;
|
|
167
|
+
round: number;
|
|
168
|
+
processKey: string | null;
|
|
169
|
+
waitingSince: string | null;
|
|
170
|
+
openEscalation: string | null;
|
|
171
|
+
updatedAt: string;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Every tracked PR not in a terminal state (converged/abandoned), newest-updated first. Backs
|
|
175
|
+
* the GET status endpoint so an operator or an external harness can see what is in flight
|
|
176
|
+
* without reading the datasource directly. */
|
|
177
|
+
export async function activePrs(data: DataLayer): Promise<ActivePr[]> {
|
|
178
|
+
const all = await prs(data).all();
|
|
179
|
+
return all
|
|
180
|
+
.filter((p) => !TERMINAL_STATUSES.includes(p.status))
|
|
181
|
+
.sort((a, b) => (a.updated_at < b.updated_at ? 1 : a.updated_at > b.updated_at ? -1 : 0))
|
|
182
|
+
.map((p) => ({
|
|
183
|
+
prKey: p.pr_key,
|
|
184
|
+
repo: p.repo,
|
|
185
|
+
number: p.number,
|
|
186
|
+
url: p.url,
|
|
187
|
+
title: p.title ?? null,
|
|
188
|
+
status: p.status,
|
|
189
|
+
round: p.current_round,
|
|
190
|
+
processKey: p.process_key ?? null,
|
|
191
|
+
waitingSince: p.waiting_since ?? null,
|
|
192
|
+
openEscalation: p.open_escalation_question ?? null,
|
|
193
|
+
updatedAt: p.updated_at,
|
|
194
|
+
}));
|
|
132
195
|
}
|
|
133
196
|
|
|
134
197
|
/** One poll pass: for each PR waiting on review, fetch fresh GitHub reviews (via the host
|
package/nano.app.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nanobpm/urban-pr-review-codefirst",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Code-first (defineFlow) expression of the Nano Urban PR-review convergence app: one durable multi-round loop per PR, BPMN model derived from TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|