@codyswann/lisa 4.96.3 → 4.97.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/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
- package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
- package/dist/core/upstream-evidence-manifest.js +37 -5
- package/dist/core/upstream-evidence-manifest.js.map +1 -1
- package/package.json +4 -4
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/skills/lisa-github-build-intake/SKILL.md +1 -1
- package/plugins/lisa/.codex-plugin/skills/lisa-implement/SKILL.md +12 -1
- package/plugins/lisa/.codex-plugin/skills/lisa-track/SKILL.md +25 -2
- package/plugins/lisa/rules/reference/rejection-detection.md +2 -2
- package/plugins/lisa/skills/lisa-github-build-intake/SKILL.md +1 -1
- package/plugins/lisa/skills/lisa-implement/SKILL.md +12 -1
- package/plugins/lisa/skills/lisa-track/SKILL.md +25 -2
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-agy/skills/lisa-github-build-intake/SKILL.md +1 -1
- package/plugins/lisa-agy/skills/lisa-implement/SKILL.md +12 -1
- package/plugins/lisa-agy/skills/lisa-track/SKILL.md +25 -2
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/rules/reference/rejection-detection.md +2 -2
- package/plugins/lisa-copilot/skills/lisa-github-build-intake/SKILL.md +1 -1
- package/plugins/lisa-copilot/skills/lisa-implement/SKILL.md +12 -1
- package/plugins/lisa-copilot/skills/lisa-track/SKILL.md +25 -2
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/rules/rejection-detection-reference.mdc +2 -2
- package/plugins/lisa-cursor/skills/lisa-github-build-intake/SKILL.md +1 -1
- package/plugins/lisa-cursor/skills/lisa-implement/SKILL.md +12 -1
- package/plugins/lisa-cursor/skills/lisa-track/SKILL.md +25 -2
- package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/rules/reference/rejection-detection.md +2 -2
- package/plugins/lisa-devin/skills/lisa-github-build-intake/SKILL.md +1 -1
- package/plugins/lisa-devin/skills/lisa-implement/SKILL.md +12 -1
- package/plugins/lisa-devin/skills/lisa-track/SKILL.md +25 -2
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-agy/plugin.json +1 -1
- package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/src/base/rules/reference/rejection-detection.md +2 -2
- package/plugins/src/base/skills/lisa-github-build-intake/SKILL.md +1 -1
- package/plugins/src/base/skills/lisa-implement/SKILL.md +12 -1
- package/plugins/src/base/skills/lisa-track/SKILL.md +25 -2
- package/scripts/lisa-ci-failure-redispatch.mjs +30 -12
- package/scripts/lisa-ci-rework-route.mjs +380 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Decide whether a dispatched work item goes back to its existing PR.
|
|
4
|
+
*
|
|
5
|
+
* The gap (CodySwannGT/lisa#4677): when a required check fails on an agent's
|
|
6
|
+
* PR, `lisa-ci-failure-redispatch` posts a bot-authored
|
|
7
|
+
* `<!-- [lisa-ci-failed] pr=<n> sha=<head> -->` marker on the work item and
|
|
8
|
+
* moves it back to the ready lane. Build intake reads that marker and sends the
|
|
9
|
+
* agent back to the PR, but the session manager dispatches through
|
|
10
|
+
* `lisa-implement` → `lisa-track`, which never looked — so a bounced item was
|
|
11
|
+
* rebuilt from scratch and could open a second PR for the same work.
|
|
12
|
+
*
|
|
13
|
+
* This script is the one place the trust rules live, so both dispatch paths
|
|
14
|
+
* (`lisa-track` Phase 3 and `lisa-github-build-intake` 3b) reach the same
|
|
15
|
+
* answer. It reads the item's comments — which the caller must do BEFORE it
|
|
16
|
+
* posts its own claim comment, a newer Lisa marker that would hide the signal —
|
|
17
|
+
* and, when the newest counted marker is an uncleared failure marker, verifies
|
|
18
|
+
* the PR it names. The marker patterns, the trusted-author predicate, the
|
|
19
|
+
* newest-marker predicate and the comment reader are imported from the
|
|
20
|
+
* producer script so the two cannot drift.
|
|
21
|
+
*
|
|
22
|
+
* Read-only: it never writes to the tracker. Every failed read routes to the
|
|
23
|
+
* normal path, because building again is recoverable and a wrong route is not.
|
|
24
|
+
*
|
|
25
|
+
* Repo-only: like its producer, it lives in this repository's `scripts/` and
|
|
26
|
+
* is NOT shipped to host projects; `lisa-track` runs it only when it exists.
|
|
27
|
+
* @module scripts/lisa-ci-rework-route
|
|
28
|
+
*/
|
|
29
|
+
import { readFileSync } from "node:fs";
|
|
30
|
+
import process from "node:process";
|
|
31
|
+
|
|
32
|
+
import { invokedAsScript } from "../all/copy-overwrite/scripts/lib/invoked-as-script.mjs";
|
|
33
|
+
import {
|
|
34
|
+
soleWorkItem,
|
|
35
|
+
trackerContract,
|
|
36
|
+
workItemLines,
|
|
37
|
+
} from "../all/copy-overwrite/scripts/lisa-work-item.mjs";
|
|
38
|
+
import {
|
|
39
|
+
CLEARED_MARKER,
|
|
40
|
+
FAILURE_MARKER,
|
|
41
|
+
MARKER_AUTHORS,
|
|
42
|
+
LISA_MARKER,
|
|
43
|
+
isNewestLisaMarker,
|
|
44
|
+
liveGh,
|
|
45
|
+
readItemComments,
|
|
46
|
+
recordedGh,
|
|
47
|
+
trustedAuthor,
|
|
48
|
+
} from "./lisa-ci-failure-redispatch.mjs";
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Bot-authored failure markers for one PR at which dispatch stops retrying and
|
|
52
|
+
* blocks for a person. Mirrors build intake 3b's "3 or more" loop bound: every
|
|
53
|
+
* bounce gives the item a fresh ready-lane entry, so without a bound a PR that
|
|
54
|
+
* keeps failing would be re-dispatched forever.
|
|
55
|
+
*/
|
|
56
|
+
export const CI_LOOP_BOUND = 3;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The one decision the CLI prints. `ci-rework` carries the PR to drive;
|
|
60
|
+
* `blocked` is the loop bound; `implement` carries why the marker was ignored.
|
|
61
|
+
* @typedef {object} RouteDecision
|
|
62
|
+
* @property {"ci-rework"|"blocked"|"implement"} route - Where the work goes.
|
|
63
|
+
* @property {string} [reason] - Reason code for `implement` and `blocked`.
|
|
64
|
+
* @property {string} [detail] - Plain-language reason.
|
|
65
|
+
* @property {string} [item] - Canonical work item.
|
|
66
|
+
* @property {number} [pr] - The marker's pull request.
|
|
67
|
+
* @property {string} [sha] - The head the failure was observed on.
|
|
68
|
+
* @property {string} [headRefName] - The pull request's head branch.
|
|
69
|
+
* @property {string[]} [failingChecks] - Failing check names from the marker comment.
|
|
70
|
+
* @property {number} [markerCount] - Bot-authored failure markers for this PR.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
/** The first line the producer writes on a failure comment. */
|
|
74
|
+
const FAILURE_LINE =
|
|
75
|
+
/^A required check failed on pull request #\d+ at commit [0-9a-f]{40}: (.+)\.$/mu;
|
|
76
|
+
const ITEM_NUMBER = /^[1-9]\d*$/u;
|
|
77
|
+
const ITEM_REF = /^([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)#([1-9]\d*)$/u;
|
|
78
|
+
const REPO = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u;
|
|
79
|
+
/**
|
|
80
|
+
* Dispatch-bookkeeping markers: the lifecycle claim, build intake's legacy
|
|
81
|
+
* claim, and the session manager's own notes (stop, release, worker failed,
|
|
82
|
+
* answer delivered). None of them says anything about the PR's checks.
|
|
83
|
+
*/
|
|
84
|
+
const CLAIM_MARKERS =
|
|
85
|
+
/\[(?:lisa-tracker-claim|claude-build-intake|lisa-session-manager)\]/gu;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* A decision to resolve and implement the item the normal way.
|
|
89
|
+
* @param {string} reason - Short reason code.
|
|
90
|
+
* @param {string} detail - Plain-language reason.
|
|
91
|
+
* @returns {RouteDecision} Decision.
|
|
92
|
+
*/
|
|
93
|
+
function implement(reason, detail) {
|
|
94
|
+
return { route: "implement", reason, detail };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The failing check names on a failure comment's first line.
|
|
99
|
+
* @param {string} body - Comment body.
|
|
100
|
+
* @returns {string[]} Check names; empty when the line is not the producer's.
|
|
101
|
+
*/
|
|
102
|
+
export function failingChecksFrom(body) {
|
|
103
|
+
const match = FAILURE_LINE.exec(String(body ?? ""));
|
|
104
|
+
return match === null ? [] : match[1].split(", ");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* True when the comment carries a failure marker, whoever wrote it.
|
|
109
|
+
* @param {object} comment - Item comment.
|
|
110
|
+
* @returns {boolean} Whether it carries one.
|
|
111
|
+
*/
|
|
112
|
+
function carriesFailure(comment) {
|
|
113
|
+
return FAILURE_MARKER.test(comment.body ?? "");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* True when every Lisa marker the comment carries is a claim marker.
|
|
118
|
+
* @param {object} comment - Item comment.
|
|
119
|
+
* @returns {boolean} Whether it is a claim-only comment.
|
|
120
|
+
*/
|
|
121
|
+
function claimOnly(comment) {
|
|
122
|
+
const body = String(comment.body ?? "");
|
|
123
|
+
return (
|
|
124
|
+
LISA_MARKER.test(body) &&
|
|
125
|
+
!LISA_MARKER.test(body.replaceAll(CLAIM_MARKERS, ""))
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The producer's newest-marker test with claim comments left out. The
|
|
131
|
+
* session manager claims an item before its worker runs this helper, and a
|
|
132
|
+
* re-claim can post another claim comment, so a claim posted after the
|
|
133
|
+
* failure marker must not hide it: an uncleared marker on an open, bound PR
|
|
134
|
+
* still means the PR is red, whoever claimed the item since. Forged failure
|
|
135
|
+
* markers are already left out by the producer's predicate.
|
|
136
|
+
* @param {object[]} comments - Item comments, oldest first.
|
|
137
|
+
* @param {object} marker - The failure marker comment.
|
|
138
|
+
* @returns {boolean} Whether it is the newest counted marker.
|
|
139
|
+
*/
|
|
140
|
+
function isNewestCountedMarker(comments, marker) {
|
|
141
|
+
return isNewestLisaMarker(
|
|
142
|
+
comments.filter(c => c === marker || !claimOnly(c)),
|
|
143
|
+
marker
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Pick the failure marker that could count, or say why none does.
|
|
149
|
+
* @param {object[]} comments - Item comments, oldest first.
|
|
150
|
+
* @returns {{marker?: object, decision?: object}} The marker or a decision.
|
|
151
|
+
*/
|
|
152
|
+
function judgeMarker(comments) {
|
|
153
|
+
const marker = comments
|
|
154
|
+
.filter(c => carriesFailure(c) && trustedAuthor(c))
|
|
155
|
+
.at(-1);
|
|
156
|
+
if (marker === undefined) {
|
|
157
|
+
const forged = comments.findLast(carriesFailure);
|
|
158
|
+
if (forged === undefined)
|
|
159
|
+
return {
|
|
160
|
+
decision: implement(
|
|
161
|
+
"no-marker",
|
|
162
|
+
"the item carries no [lisa-ci-failed] marker"
|
|
163
|
+
),
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
decision: implement(
|
|
167
|
+
"untrusted-author",
|
|
168
|
+
`the [lisa-ci-failed] marker was posted by ${forged.user?.login ?? "an unknown author"}, not ${MARKER_AUTHORS.join(" or ")}; ignored`
|
|
169
|
+
),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if (!isNewestCountedMarker(comments, marker))
|
|
173
|
+
return {
|
|
174
|
+
decision: implement(
|
|
175
|
+
"not-newest",
|
|
176
|
+
"a newer Lisa marker (not a claim) was posted after the [lisa-ci-failed] marker, so it no longer describes the item"
|
|
177
|
+
),
|
|
178
|
+
};
|
|
179
|
+
if (CLEARED_MARKER.test(marker.body))
|
|
180
|
+
return {
|
|
181
|
+
decision: implement(
|
|
182
|
+
"cleared",
|
|
183
|
+
"the [lisa-ci-failed] marker is cleared: a later run passed every required check"
|
|
184
|
+
),
|
|
185
|
+
};
|
|
186
|
+
return { marker };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Check the named PR is open, same-repository and bound to this item.
|
|
191
|
+
* @param {object} view - `gh pr view` JSON.
|
|
192
|
+
* @param {string} item - Canonical `owner/repo#n`.
|
|
193
|
+
* @param {object} contract - Tracker contract scoped to the item's repository.
|
|
194
|
+
* @returns {RouteDecision|null} An implement decision, or null when the PR checks out.
|
|
195
|
+
*/
|
|
196
|
+
function judgePull(view, item, contract) {
|
|
197
|
+
if (view.state !== "OPEN")
|
|
198
|
+
return implement(
|
|
199
|
+
"pull-request-not-open",
|
|
200
|
+
`the marker's pull request is ${view.state}`
|
|
201
|
+
);
|
|
202
|
+
if (view.isCrossRepository)
|
|
203
|
+
return implement(
|
|
204
|
+
"fork-pull-request",
|
|
205
|
+
"the marker's pull request comes from a fork"
|
|
206
|
+
);
|
|
207
|
+
let bound;
|
|
208
|
+
try {
|
|
209
|
+
bound = soleWorkItem(view.body ?? "", contract, "pull-request body");
|
|
210
|
+
} catch (error) {
|
|
211
|
+
// Exactly one declared value that still fails names something else (an
|
|
212
|
+
// item in another repository); zero or several declarations bind nothing.
|
|
213
|
+
const declared = new Set(workItemLines(view.body ?? ""));
|
|
214
|
+
const reason =
|
|
215
|
+
declared.size === 1 ? "other-work-item" : "unbound-pull-request";
|
|
216
|
+
return implement(reason, String(error.message));
|
|
217
|
+
}
|
|
218
|
+
if (bound.toLowerCase() !== item.toLowerCase())
|
|
219
|
+
return implement(
|
|
220
|
+
"other-work-item",
|
|
221
|
+
`the marker's pull request is bound to ${bound}, not ${item}`
|
|
222
|
+
);
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Read one gh JSON answer, or throw naming the call.
|
|
228
|
+
* @param {Function} gh - Runner.
|
|
229
|
+
* @param {string[]} args - Arguments.
|
|
230
|
+
* @returns {any} Parsed stdout.
|
|
231
|
+
*/
|
|
232
|
+
function readJson(gh, args) {
|
|
233
|
+
const result = gh(args);
|
|
234
|
+
if (!result.ok)
|
|
235
|
+
throw new Error(`gh ${args.join(" ")} failed: ${result.stderr}`);
|
|
236
|
+
return JSON.parse(result.stdout);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Route a counted marker: verify its PR, then apply the loop bound.
|
|
241
|
+
* @param {{marker: object, comments: object[], item: string, repository: string, contract: object, gh: Function}} ctx - Context.
|
|
242
|
+
* @returns {RouteDecision} Decision.
|
|
243
|
+
*/
|
|
244
|
+
function routeMarker({ marker, comments, item, repository, contract, gh }) {
|
|
245
|
+
const [, prText, sha] = FAILURE_MARKER.exec(marker.body);
|
|
246
|
+
const pr = Number(prText);
|
|
247
|
+
const view = readJson(gh, [
|
|
248
|
+
"pr",
|
|
249
|
+
"view",
|
|
250
|
+
prText,
|
|
251
|
+
"--repo",
|
|
252
|
+
repository,
|
|
253
|
+
"--json",
|
|
254
|
+
"state,isCrossRepository,body,headRefName",
|
|
255
|
+
]);
|
|
256
|
+
const refused = judgePull(view, item, { ...contract, repository });
|
|
257
|
+
if (refused) return refused;
|
|
258
|
+
const markerCount = comments.filter(
|
|
259
|
+
c =>
|
|
260
|
+
trustedAuthor(c) && Number(FAILURE_MARKER.exec(c.body ?? "")?.[1]) === pr
|
|
261
|
+
).length;
|
|
262
|
+
const failingChecks = failingChecksFrom(marker.body);
|
|
263
|
+
if (markerCount >= CI_LOOP_BOUND)
|
|
264
|
+
return {
|
|
265
|
+
route: "blocked",
|
|
266
|
+
reason: "ci-loop-bound",
|
|
267
|
+
detail: `pull request #${pr} has failed its required checks ${markerCount} times; stop retrying and ask a person`,
|
|
268
|
+
item,
|
|
269
|
+
pr,
|
|
270
|
+
sha,
|
|
271
|
+
failingChecks,
|
|
272
|
+
markerCount,
|
|
273
|
+
};
|
|
274
|
+
return {
|
|
275
|
+
route: "ci-rework",
|
|
276
|
+
item,
|
|
277
|
+
pr,
|
|
278
|
+
sha,
|
|
279
|
+
headRefName: view.headRefName,
|
|
280
|
+
failingChecks,
|
|
281
|
+
markerCount,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Decide the dispatch route for one GitHub work item. Reads only.
|
|
287
|
+
* @param {{item: string, contract: object, gh: Function, repository?: string}} input - Item number, contract, runner.
|
|
288
|
+
* @returns {RouteDecision} `ci-rework`, `blocked`, or `implement` decision.
|
|
289
|
+
*/
|
|
290
|
+
export function decideRoute({ item, contract, gh, repository }) {
|
|
291
|
+
if (contract?.provider !== "github")
|
|
292
|
+
return implement(
|
|
293
|
+
"tracker-not-github",
|
|
294
|
+
"only the GitHub tracker carries [lisa-ci-failed] markers"
|
|
295
|
+
);
|
|
296
|
+
const repo = repository ?? contract.repository;
|
|
297
|
+
const ref = `${repo}#${item}`;
|
|
298
|
+
try {
|
|
299
|
+
const comments = readItemComments(String(item), repo, gh);
|
|
300
|
+
const { marker, decision } = judgeMarker(comments);
|
|
301
|
+
if (decision) return decision;
|
|
302
|
+
return routeMarker({
|
|
303
|
+
marker,
|
|
304
|
+
comments,
|
|
305
|
+
item: ref,
|
|
306
|
+
repository: repo,
|
|
307
|
+
contract,
|
|
308
|
+
gh,
|
|
309
|
+
});
|
|
310
|
+
} catch (error) {
|
|
311
|
+
return implement(
|
|
312
|
+
"read-failed",
|
|
313
|
+
`could not read the item or its pull request: ${error.message}`
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Decide the route from a recorded fixture: the gh answers it recorded.
|
|
320
|
+
* @param {{gh: object}} fixture - Recorded fixture.
|
|
321
|
+
* @param {string} item - Item number.
|
|
322
|
+
* @param {object} contract - Tracker contract.
|
|
323
|
+
* @returns {RouteDecision} Decision.
|
|
324
|
+
*/
|
|
325
|
+
export function routeFromFixture(fixture, item, contract) {
|
|
326
|
+
return decideRoute({ item, contract, gh: recordedGh(fixture.gh) });
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Parse CLI flags.
|
|
331
|
+
* @param {string[]} argv - Arguments.
|
|
332
|
+
* @returns {{item: string, repository?: string, payload?: string}} Options.
|
|
333
|
+
*/
|
|
334
|
+
function parseArgs(argv) {
|
|
335
|
+
const flags = {};
|
|
336
|
+
for (let i = 0; i < argv.length; i += 2) {
|
|
337
|
+
const [flag, value] = [argv[i], argv[i + 1]];
|
|
338
|
+
if (!["--item", "--repo", "--payload"].includes(flag))
|
|
339
|
+
throw new Error(`unknown argument: ${flag}`);
|
|
340
|
+
if (value === undefined) throw new Error(`${flag} needs a value`);
|
|
341
|
+
flags[flag.slice(2)] = value;
|
|
342
|
+
}
|
|
343
|
+
const ref = ITEM_REF.exec(flags.item ?? "");
|
|
344
|
+
if (ref === null && !ITEM_NUMBER.test(flags.item ?? ""))
|
|
345
|
+
throw new Error("pass --item <n> or --item <owner>/<repo>#<n>");
|
|
346
|
+
if (flags.repo !== undefined && !REPO.test(flags.repo))
|
|
347
|
+
throw new Error(`--repo must be <owner>/<repo>, got '${flags.repo}'`);
|
|
348
|
+
if (ref && flags.repo && ref[1].toLowerCase() !== flags.repo.toLowerCase())
|
|
349
|
+
throw new Error(`--item ${flags.item} is not in --repo ${flags.repo}`);
|
|
350
|
+
return {
|
|
351
|
+
item: ref ? ref[2] : flags.item,
|
|
352
|
+
repository: flags.repo ?? ref?.[1],
|
|
353
|
+
payload: flags.payload,
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* CLI entry: print one JSON decision line.
|
|
359
|
+
* @param {string[]} argv - Arguments.
|
|
360
|
+
* @param {{gh?: Function, write?: Function, contract?: object}} [deps] - Injectables.
|
|
361
|
+
* @returns {number} Exit code: 0 decided (any route), 2 bad usage or configuration.
|
|
362
|
+
*/
|
|
363
|
+
export function main(argv, deps = {}) {
|
|
364
|
+
const write = deps.write ?? (line => process.stdout.write(`${line}\n`));
|
|
365
|
+
try {
|
|
366
|
+
const options = parseArgs(argv);
|
|
367
|
+
const contract = deps.contract ?? trackerContract();
|
|
368
|
+
const gh = options.payload
|
|
369
|
+
? recordedGh(JSON.parse(readFileSync(options.payload, "utf8")).gh)
|
|
370
|
+
: (deps.gh ?? liveGh);
|
|
371
|
+
write(JSON.stringify(decideRoute({ ...options, contract, gh })));
|
|
372
|
+
return 0;
|
|
373
|
+
} catch (error) {
|
|
374
|
+
write(`lisa-ci-rework-route: ${error.message}`);
|
|
375
|
+
return 2;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (invokedAsScript(import.meta.url))
|
|
380
|
+
process.exitCode = main(process.argv.slice(2));
|