@ravshansbox/pi-next-issue 1.0.4 → 1.0.6
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/package.json +1 -1
- package/src/github.ts +16 -6
- package/src/runner.ts +6 -3
package/package.json
CHANGED
package/src/github.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { setTimeout as sleep } from 'node:timers/promises';
|
|
2
2
|
import { must, run } from './exec.ts';
|
|
3
|
-
import { LABELS, STOP_LABELS, type ChecksResult, type Issue } from './runner.ts';
|
|
3
|
+
import { LABELS, STOP_LABELS, type ChecksResult, type Issue, type MergeResult } from './runner.ts';
|
|
4
4
|
|
|
5
5
|
export type Repo = { root: string; slug: string };
|
|
6
6
|
|
|
@@ -247,21 +247,31 @@ export async function merge(
|
|
|
247
247
|
pr: number,
|
|
248
248
|
timeoutMs: number,
|
|
249
249
|
signal: AbortSignal,
|
|
250
|
-
): Promise<
|
|
250
|
+
): Promise<MergeResult> {
|
|
251
|
+
const before = await gh(repo, ['pr', 'view', String(pr), '--json', 'state', '--jq', '.state']);
|
|
252
|
+
if (before === 'MERGED') {
|
|
253
|
+
return { merged: true };
|
|
254
|
+
}
|
|
251
255
|
const result = await run('gh', ['pr', 'merge', String(pr), '--squash', '--repo', repo.slug], {
|
|
252
256
|
cwd: repo.root,
|
|
253
257
|
});
|
|
254
258
|
if (result.code !== 0) {
|
|
255
|
-
return
|
|
259
|
+
return {
|
|
260
|
+
merged: false,
|
|
261
|
+
reason: result.stderr.trim().slice(-2000) || `gh pr merge failed with code ${result.code}`,
|
|
262
|
+
};
|
|
256
263
|
}
|
|
257
264
|
const deadline = Date.now() + timeoutMs;
|
|
258
265
|
for (;;) {
|
|
259
266
|
const state = await gh(repo, ['pr', 'view', String(pr), '--json', 'state', '--jq', '.state']);
|
|
260
267
|
if (state === 'MERGED') {
|
|
261
|
-
return true;
|
|
268
|
+
return { merged: true };
|
|
269
|
+
}
|
|
270
|
+
if (state === 'CLOSED') {
|
|
271
|
+
return { merged: false, reason: 'the pull request was closed' };
|
|
262
272
|
}
|
|
263
|
-
if (
|
|
264
|
-
return false;
|
|
273
|
+
if (Date.now() >= deadline) {
|
|
274
|
+
return { merged: false, reason: 'the merge did not finish in time' };
|
|
265
275
|
}
|
|
266
276
|
await sleep(Math.min(POLL_MS, deadline - Date.now()), undefined, { signal });
|
|
267
277
|
}
|
package/src/runner.ts
CHANGED
|
@@ -52,7 +52,7 @@ export type Ports = {
|
|
|
52
52
|
checks(pr: number, cwd: string, signal: AbortSignal): Promise<ChecksResult>;
|
|
53
53
|
failedLogs(pr: number): Promise<string>;
|
|
54
54
|
commentOnPr(pr: number, body: string): Promise<void>;
|
|
55
|
-
merge(pr: number, signal: AbortSignal): Promise<
|
|
55
|
+
merge(pr: number, signal: AbortSignal): Promise<MergeResult>;
|
|
56
56
|
cleanup(issue: number, branch: string, cwd: string): Promise<void>;
|
|
57
57
|
work(task: AgentTask): Promise<string>;
|
|
58
58
|
review(task: AgentTask): Promise<Verdict | undefined>;
|
|
@@ -64,6 +64,8 @@ export type Ports = {
|
|
|
64
64
|
unlock(): Promise<void>;
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
+
export type MergeResult = { merged: true } | { merged: false; reason: string };
|
|
68
|
+
|
|
67
69
|
export type Outcome = 'merged' | 'needs-human';
|
|
68
70
|
|
|
69
71
|
export type Status = 'idle' | 'running' | 'stopping' | 'finished' | 'stopped' | 'failed';
|
|
@@ -330,8 +332,9 @@ export class Runner {
|
|
|
330
332
|
}
|
|
331
333
|
case 'merge': {
|
|
332
334
|
this.stage('merge');
|
|
333
|
-
|
|
334
|
-
|
|
335
|
+
const result = await ports.merge(pr(), this.controller.signal);
|
|
336
|
+
if (!result.merged) {
|
|
337
|
+
return needsHuman(`pull request #${pr()} could not be merged: ${result.reason}`);
|
|
335
338
|
}
|
|
336
339
|
await ports.setLabel(number, LABELS.done, [LABELS.inProgress]);
|
|
337
340
|
await ports.cleanup(number, state.branch, cwd);
|