@ravshansbox/pi-next-issue 1.0.2 → 1.0.3
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/README.md +1 -1
- package/package.json +1 -1
- package/src/github.ts +34 -11
- package/src/ports.ts +1 -1
- package/src/runner.ts +1 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ The run does not belong to a session: it goes on after `/new`, `/resume`, a fork
|
|
|
22
22
|
|
|
23
23
|
## What it does
|
|
24
24
|
|
|
25
|
-
Each loop fetches the open issues and takes the oldest one with saved state, else the oldest one with the `status:todo` label and none of `status:in-progress`, `status:done`, `status:needs-human` or `status:blocked`. The run ends when no such issue is left, or at the first error. For each issue:
|
|
25
|
+
Each loop fetches the 200 oldest open issues with the `status:todo` label and none of `status:in-progress`, `status:done`, `status:needs-human` or `status:blocked`, and the open issues with saved state that it can read. It takes the oldest one with saved state, else the oldest one with the `status:todo` label and none of `status:in-progress`, `status:done`, `status:needs-human` or `status:blocked`. The run ends when no such issue is left, or at the first error. For each issue:
|
|
26
26
|
|
|
27
27
|
1. Swap `status:todo` for `status:in-progress`.
|
|
28
28
|
2. Add a git worktree at `.worktrees/<n>` on the `<n>` branch, from the remote default branch.
|
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 type
|
|
3
|
+
import { LABELS, STOP_LABELS, type ChecksResult, type Issue } from './runner.ts';
|
|
4
4
|
|
|
5
5
|
export type Repo = { root: string; slug: string };
|
|
6
6
|
|
|
@@ -28,25 +28,48 @@ export async function defaultBranch(repo: Repo): Promise<string> {
|
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
type RawIssue = {
|
|
32
|
+
number: number;
|
|
33
|
+
title: string;
|
|
34
|
+
body: string | null;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
labels: Array<{ name: string }>;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const ISSUE_FIELDS = 'number,title,body,labels,createdAt';
|
|
40
|
+
|
|
41
|
+
export async function openIssues(repo: Repo, saved: number[]): Promise<Issue[]> {
|
|
32
42
|
const raw = await gh(repo, [
|
|
33
43
|
'issue',
|
|
34
44
|
'list',
|
|
35
45
|
'--state',
|
|
36
46
|
'open',
|
|
47
|
+
'--label',
|
|
48
|
+
LABELS.ready,
|
|
49
|
+
'--search',
|
|
50
|
+
['sort:created-asc', ...STOP_LABELS.map((label) => `-label:${label}`)].join(' '),
|
|
37
51
|
'--limit',
|
|
38
52
|
'200',
|
|
39
53
|
'--json',
|
|
40
|
-
|
|
54
|
+
ISSUE_FIELDS,
|
|
41
55
|
]);
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
56
|
+
const listed = JSON.parse(raw) as RawIssue[];
|
|
57
|
+
const known = new Set(listed.map((item) => item.number));
|
|
58
|
+
for (const number of saved.filter((item) => !known.has(item))) {
|
|
59
|
+
const view = await run(
|
|
60
|
+
'gh',
|
|
61
|
+
['issue', 'view', String(number), '--json', `${ISSUE_FIELDS},state`, '--repo', repo.slug],
|
|
62
|
+
{ cwd: repo.root },
|
|
63
|
+
);
|
|
64
|
+
if (view.code !== 0) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const item = JSON.parse(view.stdout) as RawIssue & { state: string };
|
|
68
|
+
if (item.state === 'OPEN') {
|
|
69
|
+
listed.push(item);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return listed
|
|
50
73
|
.sort((a, b) => a.createdAt.localeCompare(b.createdAt))
|
|
51
74
|
.map((item) => ({
|
|
52
75
|
number: item.number,
|
package/src/ports.ts
CHANGED
|
@@ -10,7 +10,7 @@ export async function createPorts(root: string, config: Config): Promise<Ports>
|
|
|
10
10
|
const base = await github.defaultBranch(repo);
|
|
11
11
|
const timeoutMs = config.checkTimeoutMinutes * 60_000;
|
|
12
12
|
return {
|
|
13
|
-
openIssues: () => github.openIssues(repo),
|
|
13
|
+
openIssues: async () => github.openIssues(repo, await state.savedIssues(root)),
|
|
14
14
|
comments: (issue) => github.comments(repo, issue),
|
|
15
15
|
setLabel: (issue, add, remove) => github.setLabel(repo, issue, add, remove),
|
|
16
16
|
commentOnIssue: (issue, body) => github.commentOnIssue(repo, issue, body),
|
package/src/runner.ts
CHANGED
|
@@ -86,7 +86,7 @@ export const LABELS = {
|
|
|
86
86
|
blocked: 'status:blocked',
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
const STOP_LABELS = [LABELS.inProgress, LABELS.done, LABELS.needsHuman, LABELS.blocked];
|
|
89
|
+
export const STOP_LABELS = [LABELS.inProgress, LABELS.done, LABELS.needsHuman, LABELS.blocked];
|
|
90
90
|
|
|
91
91
|
function ready(issue: Issue): boolean {
|
|
92
92
|
return (
|