opencode-magi 0.0.0-dev-20261027230846 → 0.0.0-dev-20261028021002
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/tools/review/check.js +69 -36
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import picomatch from "picomatch";
|
|
2
2
|
import { MagiError } from "@/magi";
|
|
3
3
|
import { Prompt } from "@/prompts";
|
|
4
|
-
import { command, filterEmpty, isBoolean, isNumber, omitNullish, quote, retry, Worker, } from "@/utils";
|
|
4
|
+
import { command, filterEmpty, isBoolean, isNumber, omitNullish, quote, retry, wait, Worker, } from "@/utils";
|
|
5
5
|
const ci = {
|
|
6
6
|
isExcluded(exclude, { name }) {
|
|
7
7
|
return exclude.some((pattern) => {
|
|
@@ -220,15 +220,12 @@ export async function rerunChecks() {
|
|
|
220
220
|
this.context.signal.throwIfAborted();
|
|
221
221
|
if (!this.state.pr?.checks)
|
|
222
222
|
throw new MagiError("blocked", "PR checks not found.");
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
passed: this.state.pr.checks.passed,
|
|
226
|
-
};
|
|
223
|
+
const previousChecks = this.state.pr.checks;
|
|
224
|
+
let checks = { ...previousChecks };
|
|
227
225
|
const failedChecks = checks.failed.filter(({ scope }) => !scope);
|
|
228
226
|
if (!failedChecks.length)
|
|
229
227
|
return;
|
|
230
228
|
await this.updateEvent(`Rerunning CI checks.`);
|
|
231
|
-
let label = failedChecks.map(({ name }) => name).join(", ");
|
|
232
229
|
if (this.state.dryRun) {
|
|
233
230
|
checks.passed = [
|
|
234
231
|
...checks.passed,
|
|
@@ -237,31 +234,39 @@ export async function rerunChecks() {
|
|
|
237
234
|
checks.failed = checks.failed.filter(({ scope }) => scope);
|
|
238
235
|
}
|
|
239
236
|
else {
|
|
240
|
-
|
|
237
|
+
for (let count = 1; count <= this.config.review.checks.retryFailedJobs; count++) {
|
|
238
|
+
const targets = checks.failed.filter(({ scope }) => !scope);
|
|
239
|
+
const label = targets.map(({ name }) => name).join(", ");
|
|
241
240
|
await this.updateEvent(`Rerunning checks ${label}.`);
|
|
242
|
-
|
|
243
|
-
.
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
241
|
+
for (const target of targets) {
|
|
242
|
+
const check = checks.failed.find(({ name, workflow }) => name === target.name && workflow === target.workflow);
|
|
243
|
+
if (!check)
|
|
244
|
+
continue;
|
|
245
|
+
await rerunCheck.call(this, check.id);
|
|
246
|
+
for (;;) {
|
|
247
|
+
await watchChecks.call(this);
|
|
248
|
+
const next = await getChecks.call(this, false);
|
|
249
|
+
const result = [...next.failed, ...next.passed].find(({ name, workflow }) => name === check.name && workflow === check.workflow);
|
|
250
|
+
if (!next.pending.length && result && result.id !== check.id) {
|
|
251
|
+
await Promise.all(next.failed.map(async (check) => {
|
|
252
|
+
check.log = await getCheckLog.call(this, check.id);
|
|
253
|
+
}));
|
|
254
|
+
for (const key of ["failed", "passed"])
|
|
255
|
+
next[key] = next[key].map((check) => {
|
|
256
|
+
const { classifieds, scope } = previousChecks.failed.find(({ name, workflow }) => check.name === name && check.workflow === workflow) ?? {};
|
|
257
|
+
return omitNullish({ ...check, classifieds, scope });
|
|
258
|
+
});
|
|
259
|
+
checks = next;
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
await wait(1_000, this.context.signal);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const remaining = checks.failed.filter(({ scope }) => !scope);
|
|
266
|
+
if (!remaining.length)
|
|
267
|
+
break;
|
|
268
|
+
await this.updateEvent(`Attempt ${count} failed to rerun checks ${remaining.map(({ name }) => name).join(", ")}.${count < this.config.review.checks.retryFailedJobs ? " Retrying..." : ""}`);
|
|
269
|
+
}
|
|
265
270
|
}
|
|
266
271
|
const passedChecksAfterRerun = checks.passed.filter((check) => "scope" in check && !check.scope);
|
|
267
272
|
const failedChecksAfterRerun = checks.failed.filter(({ scope }) => !scope);
|
|
@@ -296,7 +301,7 @@ export async function getMetadata() {
|
|
|
296
301
|
metadata: data,
|
|
297
302
|
};
|
|
298
303
|
}
|
|
299
|
-
async function getChecks() {
|
|
304
|
+
async function getChecks(includeLogs = true) {
|
|
300
305
|
const fields = "name,state,bucket,link,workflow";
|
|
301
306
|
const checks = {
|
|
302
307
|
excluded: [],
|
|
@@ -313,8 +318,10 @@ async function getChecks() {
|
|
|
313
318
|
checks.excluded.push(check);
|
|
314
319
|
}
|
|
315
320
|
else if (ci.isFailed(check)) {
|
|
316
|
-
const log =
|
|
317
|
-
|
|
321
|
+
const log = includeLogs
|
|
322
|
+
? await getCheckLog.call(this, check.id)
|
|
323
|
+
: undefined;
|
|
324
|
+
checks.failed.push(omitNullish({ ...check, log }));
|
|
318
325
|
}
|
|
319
326
|
else if (ci.isPassed(check)) {
|
|
320
327
|
checks.passed.push(check);
|
|
@@ -332,12 +339,38 @@ async function getChecks() {
|
|
|
332
339
|
}
|
|
333
340
|
async function getCheckLog(id) {
|
|
334
341
|
const log = await this.exec(command("gh", "run", "view", "--repo", this.state.repo, "--job", quote(id), "--log-failed"), { signal: this.context.signal });
|
|
335
|
-
|
|
342
|
+
const lines = log
|
|
336
343
|
// oxlint-disable-next-line no-control-regex
|
|
337
344
|
.replaceAll(/\u001B\[[0-9;]*m/g, "")
|
|
338
345
|
.split("\n")
|
|
339
|
-
.filter((line) => line.trim())
|
|
340
|
-
|
|
346
|
+
.filter((line) => line.trim());
|
|
347
|
+
const unknownStep = /^[^\t]*\tUNKNOWN STEP\t\s*(\S+)/;
|
|
348
|
+
if (!lines.some((line) => unknownStep.test(line)))
|
|
349
|
+
return lines.join("\n");
|
|
350
|
+
const raw = await this.exec(command("gh", "api", quote(`repos/${this.config.github.owner}/${this.config.github.repo}/actions/jobs/${id}`)), { signal: this.context.signal });
|
|
351
|
+
const { steps = [] } = JSON.parse(raw);
|
|
352
|
+
const ranges = steps.flatMap(({ completed_at, conclusion, started_at }) => {
|
|
353
|
+
if (conclusion !== "failure" || !started_at || !completed_at)
|
|
354
|
+
return [];
|
|
355
|
+
return [
|
|
356
|
+
{
|
|
357
|
+
// GitHub step timestamps have second precision, so include the final second.
|
|
358
|
+
end: Date.parse(completed_at) + 1_000,
|
|
359
|
+
start: Date.parse(started_at),
|
|
360
|
+
},
|
|
361
|
+
];
|
|
362
|
+
});
|
|
363
|
+
if (!ranges.length)
|
|
364
|
+
return lines.join("\n");
|
|
365
|
+
const filtered = lines.filter((line) => {
|
|
366
|
+
const match = line.match(unknownStep);
|
|
367
|
+
if (!match)
|
|
368
|
+
return true;
|
|
369
|
+
const time = Date.parse(match[1]);
|
|
370
|
+
return (Number.isNaN(time) ||
|
|
371
|
+
ranges.some(({ end, start }) => start <= time && time < end));
|
|
372
|
+
});
|
|
373
|
+
return (filtered.length ? filtered : lines).join("\n");
|
|
341
374
|
}
|
|
342
375
|
async function rerunCheck(id) {
|
|
343
376
|
await this.exec(command("gh", "run", "rerun", "--repo", this.state.repo, "--job", quote(id)), { signal: this.context.signal });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-magi",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20261028021002",
|
|
4
4
|
"description": "Multi-agent PR review and merge orchestration plugin for OpenCode.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Hirotomo Yamada <hirotomo.yamada@avap.co.jp>",
|