next-issue 6.6.87 → 6.6.89
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 +4 -1
- package/dist/exec.mjs +16 -4
- package/dist/github.mjs +8 -3
- package/dist/hand-over-comments.mjs +42 -9
- package/dist/handover.mjs +8 -2
- package/dist/open-job.mjs +2 -2
- package/dist/pipeline.mjs +17 -7
- package/dist/skip.mjs +3 -3
- package/dist/state.mjs +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -590,7 +590,10 @@ the mark and keeps the branch and the step that the last run reached, so the
|
|
|
590
590
|
work carries on where it stopped. After a revert, the branch holds the change
|
|
591
591
|
again on top of the revert, so the change goes back to the review. An issue
|
|
592
592
|
that still has the label is not claimed, unless it has an answer to the
|
|
593
|
-
hand-over: then the run claims it and takes the label off.
|
|
593
|
+
hand-over: then the run claims it and takes the label off. When the label of a
|
|
594
|
+
hand-over reaches GitHub but its comment does not, an answer to an earlier
|
|
595
|
+
hand-over does not count: the issue waits, and the worker lists it, until a
|
|
596
|
+
person takes the label off or a writer comments after that hand-over.
|
|
594
597
|
|
|
595
598
|
To give guidance, answer the hand-over with a comment on the issue. When the run
|
|
596
599
|
resumes the issue, it reads the comments posted after its last
|
package/dist/exec.mjs
CHANGED
|
@@ -7,6 +7,11 @@ let observer;
|
|
|
7
7
|
const DEFAULT_TIMEOUT_MS = minutesToMs(10);
|
|
8
8
|
const defaultTimeout = new AsyncLocalStorage();
|
|
9
9
|
const STDERR_TAIL = 200_000;
|
|
10
|
+
// After the child exits, wait this long for `close`, which comes once both pipes have
|
|
11
|
+
// finished. A background process that inherited the pipes can keep them open, so `close`
|
|
12
|
+
// may never come. The fallback then waits one more poll phase before it closes the pipes,
|
|
13
|
+
// so output still in the pipes is read even when the event loop was busy past the wait.
|
|
14
|
+
const DRAIN_MS = 200;
|
|
10
15
|
let shownCommands = 0;
|
|
11
16
|
export function showingCommands() {
|
|
12
17
|
return shownCommands > 0;
|
|
@@ -70,12 +75,14 @@ export function run(command, args, options = {}) {
|
|
|
70
75
|
const output = collect(child, options);
|
|
71
76
|
const timer = deadline(limit, () => killTree(child));
|
|
72
77
|
let done = false;
|
|
78
|
+
let drain;
|
|
73
79
|
let shown = options.show === true;
|
|
74
80
|
if (shown) {
|
|
75
81
|
shownCommands += 1;
|
|
76
82
|
}
|
|
77
83
|
const release = () => {
|
|
78
84
|
timer.clear();
|
|
85
|
+
clearTimeout(drain);
|
|
79
86
|
unwatch();
|
|
80
87
|
if (shown) {
|
|
81
88
|
shown = false;
|
|
@@ -98,12 +105,17 @@ export function run(command, args, options = {}) {
|
|
|
98
105
|
reject(error);
|
|
99
106
|
});
|
|
100
107
|
child.on('exit', (code) => {
|
|
101
|
-
|
|
108
|
+
const finish = () => {
|
|
109
|
+
child.stdout?.destroy();
|
|
110
|
+
child.stderr?.destroy();
|
|
111
|
+
settle(code);
|
|
112
|
+
};
|
|
113
|
+
if (timer.timedOut()) {
|
|
114
|
+
finish();
|
|
102
115
|
return;
|
|
103
116
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
settle(code);
|
|
117
|
+
timer.clear();
|
|
118
|
+
drain = setTimeout(() => setImmediate(finish), DRAIN_MS);
|
|
107
119
|
});
|
|
108
120
|
child.on('close', settle);
|
|
109
121
|
sendInput(child, options.input);
|
package/dist/github.mjs
CHANGED
|
@@ -42,12 +42,17 @@ export async function issueComments(repo, issue) {
|
|
|
42
42
|
return parsed.comments.map((comment) => ({ author: comment.author.login, body: comment.body }));
|
|
43
43
|
}
|
|
44
44
|
export async function threadComments(repo, number) {
|
|
45
|
-
const raw = await ghApi(repo, `issues/${number}/comments`, '.[] | [.user.login, .body, .html_url] | @json', { paginate: true });
|
|
45
|
+
const raw = await ghApi(repo, `issues/${number}/comments`, '.[] | [.user.login, .body, .html_url, .created_at] | @json', { paginate: true });
|
|
46
46
|
return lines(raw).map((line) => parseComment(line, number));
|
|
47
47
|
}
|
|
48
48
|
function parseComment(line, number) {
|
|
49
|
-
const [author, body, url] = parseJson(line, () => `gh gave a comment of #${number} that is not valid JSON: ${line}`);
|
|
50
|
-
return
|
|
49
|
+
const [author, body, url, createdAt] = parseJson(line, () => `gh gave a comment of #${number} that is not valid JSON: ${line}`);
|
|
50
|
+
return {
|
|
51
|
+
author,
|
|
52
|
+
body: body ?? '',
|
|
53
|
+
...(url === undefined ? {} : { url }),
|
|
54
|
+
...(createdAt === undefined ? {} : { createdAt }),
|
|
55
|
+
};
|
|
51
56
|
}
|
|
52
57
|
export async function canWrite(repo, login) {
|
|
53
58
|
try {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { repoArg } from './gh.mjs';
|
|
2
|
+
import { readState } from './state.mjs';
|
|
2
3
|
export const HAND_OVER = 'next-issue needs help:';
|
|
3
4
|
const HARNESS_HEADINGS = [HAND_OVER, '### Review:', '### Fixer:'];
|
|
4
5
|
function fromHarness(comment) {
|
|
@@ -53,22 +54,41 @@ export async function waitingQuestions(repo, config, ports) {
|
|
|
53
54
|
}
|
|
54
55
|
return questions;
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
function postedAfter(comment, since) {
|
|
58
|
+
return since !== undefined && comment.createdAt !== undefined && comment.createdAt > since;
|
|
59
|
+
}
|
|
60
|
+
/** With a pending hand-over, only comments after it answer; without its time, none do. */
|
|
61
|
+
function answerCandidates(comments, last, pending) {
|
|
62
|
+
if (pending !== undefined) {
|
|
63
|
+
return comments.filter((comment) => postedAfter(comment, pending.since));
|
|
64
|
+
}
|
|
65
|
+
return last === -1 ? [] : comments.slice(last + 1);
|
|
66
|
+
}
|
|
67
|
+
async function replyAfter(comments, last, writer, pending) {
|
|
68
|
+
return writerQuotes(answerCandidates(comments, last, pending).filter((comment) => !fromHarness(comment)), writer);
|
|
69
|
+
}
|
|
70
|
+
async function pendingHandOver(repo, issue) {
|
|
71
|
+
try {
|
|
72
|
+
return (await readState(repo, issue))?.pendingHandOver;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return undefined;
|
|
59
76
|
}
|
|
60
|
-
return writerQuotes(comments.slice(last + 1).filter((comment) => !fromHarness(comment)), writer);
|
|
61
77
|
}
|
|
62
78
|
async function waitingQuestion(repo, config, ports, writer, issue) {
|
|
63
79
|
const { comments, last } = await handOverThread(repo, ports, writer, issue.number);
|
|
64
|
-
|
|
80
|
+
const pending = await pendingHandOver(repo, issue.number);
|
|
81
|
+
if ((await replyAfter(comments, last, writer, pending)).length > 0) {
|
|
65
82
|
return undefined;
|
|
66
83
|
}
|
|
67
|
-
const
|
|
84
|
+
const latest = comments[last];
|
|
85
|
+
const comment = pending === undefined || (latest !== undefined && postedAfter(latest, pending.since))
|
|
86
|
+
? latest
|
|
87
|
+
: undefined;
|
|
68
88
|
return {
|
|
69
89
|
issue: issue.number,
|
|
70
90
|
title: issue.title,
|
|
71
|
-
reason: comment?.body.slice(HAND_OVER.length).trim() ?? '',
|
|
91
|
+
reason: comment?.body.slice(HAND_OVER.length).trim() ?? pending?.reason ?? '',
|
|
72
92
|
url: comment?.url ?? '',
|
|
73
93
|
repo: repoArg(repo),
|
|
74
94
|
labels: { needsHuman: config.labels.needsHuman, skip: config.labels.skip },
|
|
@@ -79,9 +99,22 @@ export async function writerComments(context, log, issue) {
|
|
|
79
99
|
const comments = (await ports.issueComments(repo, issue)).filter((comment) => !fromHarness(comment));
|
|
80
100
|
return writerQuotes(comments, writers(repo, ports), (comment) => log.event('comment.skip', { author: comment.author }, 'quiet'));
|
|
81
101
|
}
|
|
82
|
-
export async function handOverReply(context, issue) {
|
|
102
|
+
export async function handOverReply(context, issue, pending) {
|
|
83
103
|
const { repo, ports } = context;
|
|
84
104
|
const writer = writers(repo, ports);
|
|
85
105
|
const { comments, last } = await handOverThread(repo, ports, writer, issue);
|
|
86
|
-
return replyAfter(comments, last, writer);
|
|
106
|
+
return replyAfter(comments, last, writer, pending);
|
|
107
|
+
}
|
|
108
|
+
/** The time of the newest thread comment, `''` for an empty thread, `undefined` when the thread cannot be read. */
|
|
109
|
+
export async function threadEnd(context, issue) {
|
|
110
|
+
try {
|
|
111
|
+
const comments = await context.ports.threadComments(context.repo, issue);
|
|
112
|
+
return comments.reduce((end, comment) => {
|
|
113
|
+
const at = comment.createdAt ?? '';
|
|
114
|
+
return at > end ? at : end;
|
|
115
|
+
}, '');
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
87
120
|
}
|
package/dist/handover.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { runStopped } from './children.mjs';
|
|
2
2
|
import { elapsedMs } from './durations.mjs';
|
|
3
3
|
import { message } from './errors.mjs';
|
|
4
|
-
import { HAND_OVER } from './hand-over-comments.mjs';
|
|
4
|
+
import { HAND_OVER, threadEnd } from './hand-over-comments.mjs';
|
|
5
5
|
import { setStatus, } from './job.mjs';
|
|
6
6
|
import { oneAtATime } from './lock.mjs';
|
|
7
7
|
import { revertFailedFix } from './revert.mjs';
|
|
@@ -142,14 +142,20 @@ async function cleanUp(context, log, branch) {
|
|
|
142
142
|
async function handOver(context, log, issue, state, reason) {
|
|
143
143
|
const { repo, ports, config } = context;
|
|
144
144
|
log.event('hand-over', { reason }, 'quiet');
|
|
145
|
+
const { pendingHandOver: _pending, ...rest } = state;
|
|
145
146
|
try {
|
|
147
|
+
const since = await threadEnd(context, issue);
|
|
148
|
+
await writeState(repo, {
|
|
149
|
+
...rest,
|
|
150
|
+
pendingHandOver: { reason, ...(since === undefined ? {} : { since }) },
|
|
151
|
+
});
|
|
146
152
|
await setStatus(context, issue, config.labels.needsHuman);
|
|
147
153
|
await ports.commentOnIssue(repo, issue, handOverComment(reason));
|
|
148
154
|
}
|
|
149
155
|
catch (error) {
|
|
150
156
|
throw new HandOverFailed(reason, error);
|
|
151
157
|
}
|
|
152
|
-
await writeState(repo, { ...
|
|
158
|
+
await writeState(repo, { ...rest, handedOver: true });
|
|
153
159
|
}
|
|
154
160
|
class HandOverFailed extends Error {
|
|
155
161
|
reason;
|
package/dist/open-job.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { handOverReply, writerComments } from './hand-over-comments.mjs';
|
|
|
2
2
|
import { setStatus } from './job.mjs';
|
|
3
3
|
import { oneAtATime } from './lock.mjs';
|
|
4
4
|
import { writeState } from './state.mjs';
|
|
5
|
-
export async function openJob(context, issue, log, state, start, handedOver) {
|
|
5
|
+
export async function openJob(context, issue, log, state, start, handedOver, pending) {
|
|
6
6
|
const started = Date.now();
|
|
7
7
|
const { repo, config } = context;
|
|
8
8
|
const branch = state.branch;
|
|
@@ -12,7 +12,7 @@ export async function openJob(context, issue, log, state, start, handedOver) {
|
|
|
12
12
|
});
|
|
13
13
|
const comments = await log.step('comments', {}, () => writerComments(context, log, issue.number));
|
|
14
14
|
const reply = handedOver
|
|
15
|
-
? await log.step('reply', {}, () => handOverReply(context, issue.number))
|
|
15
|
+
? await log.step('reply', {}, () => handOverReply(context, issue.number, pending))
|
|
16
16
|
: [];
|
|
17
17
|
const worktree = await openWorktree(context, issue, log, branch, start);
|
|
18
18
|
return {
|
package/dist/pipeline.mjs
CHANGED
|
@@ -6,7 +6,8 @@ import { implement } from './implement.mjs';
|
|
|
6
6
|
import { openJob } from './open-job.mjs';
|
|
7
7
|
import { reviewRound } from './review.mjs';
|
|
8
8
|
import { skipReport, unclaimedError } from './skip.mjs';
|
|
9
|
-
import {
|
|
9
|
+
import { hasLabel } from './labels.mjs';
|
|
10
|
+
import { newState, readState, resetState, } from './state.mjs';
|
|
10
11
|
import { setUp } from './worktree-setup.mjs';
|
|
11
12
|
export async function processIssue(context, issue, claimed = () => undefined) {
|
|
12
13
|
const { repo } = context;
|
|
@@ -29,12 +30,13 @@ export async function processIssue(context, issue, claimed = () => undefined) {
|
|
|
29
30
|
}
|
|
30
31
|
claimed();
|
|
31
32
|
log.event('issue.start', { title: issue.title, createdAt: issue.createdAt }, 'quiet');
|
|
32
|
-
const
|
|
33
|
+
const handedOver = wasHandedOver(context, issue, saved);
|
|
34
|
+
const state = startState(context, issue, saved, handedOver);
|
|
33
35
|
let report;
|
|
34
36
|
try {
|
|
35
37
|
report = closing
|
|
36
38
|
? await finishClosing(context, issue, log, state, started)
|
|
37
|
-
: await work(context, issue, log, state, saved === undefined, saved?.
|
|
39
|
+
: await work(context, issue, log, state, saved === undefined, handedOver, saved?.pendingHandOver);
|
|
38
40
|
}
|
|
39
41
|
catch (error) {
|
|
40
42
|
if (!runStopped()) {
|
|
@@ -45,14 +47,22 @@ export async function processIssue(context, issue, claimed = () => undefined) {
|
|
|
45
47
|
log.event('issue.end', { outcome: report.outcome, reason: report.reason, ms: report.ms }, 'quiet');
|
|
46
48
|
return report;
|
|
47
49
|
}
|
|
48
|
-
|
|
50
|
+
/** A hand-over whose comment failed counts once the issue is claimed with its label still on, that is with an answer. */
|
|
51
|
+
function wasHandedOver(context, issue, saved) {
|
|
52
|
+
if (saved?.handedOver === true) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return (saved?.pendingHandOver !== undefined && hasLabel(issue.labels, context.config.labels.needsHuman));
|
|
56
|
+
}
|
|
57
|
+
function startState(context, issue, saved, handedOver) {
|
|
49
58
|
if (saved === undefined) {
|
|
50
59
|
return newState(issue.number, branchName(issue.number));
|
|
51
60
|
}
|
|
52
|
-
|
|
61
|
+
const { pendingHandOver: _pending, ...rest } = saved;
|
|
62
|
+
return context.reset || handedOver ? resetState(saved) : rest;
|
|
53
63
|
}
|
|
54
|
-
async function work(context, issue, log, state, start, handedOver) {
|
|
55
|
-
const job = await openJob(context, issue, log, state, start, handedOver);
|
|
64
|
+
async function work(context, issue, log, state, start, handedOver, pending) {
|
|
65
|
+
const job = await openJob(context, issue, log, state, start, handedOver, pending);
|
|
56
66
|
const setup = await setUp(job);
|
|
57
67
|
if (setup.done) {
|
|
58
68
|
return setup.report;
|
package/dist/skip.mjs
CHANGED
|
@@ -25,7 +25,7 @@ export function skipReason(issue, config, resuming, answered = false) {
|
|
|
25
25
|
export async function skipReport(context, log, issue, saved, started) {
|
|
26
26
|
let answered;
|
|
27
27
|
try {
|
|
28
|
-
answered = await hasAnswer(context, issue);
|
|
28
|
+
answered = await hasAnswer(context, issue, saved);
|
|
29
29
|
}
|
|
30
30
|
catch (error) {
|
|
31
31
|
return readError(log, issue, saved, error, started);
|
|
@@ -51,11 +51,11 @@ export async function skipReport(context, log, issue, saved, started) {
|
|
|
51
51
|
}
|
|
52
52
|
return undefined;
|
|
53
53
|
}
|
|
54
|
-
async function hasAnswer(context, issue) {
|
|
54
|
+
async function hasAnswer(context, issue, saved) {
|
|
55
55
|
if (!hasLabel(issue.labels, context.config.labels.needsHuman)) {
|
|
56
56
|
return false;
|
|
57
57
|
}
|
|
58
|
-
return (await handOverReply(context, issue.number)).length > 0;
|
|
58
|
+
return (await handOverReply(context, issue.number, saved?.pendingHandOver)).length > 0;
|
|
59
59
|
}
|
|
60
60
|
function readError(log, issue, saved, error, started) {
|
|
61
61
|
if (!runStopped()) {
|
package/dist/state.mjs
CHANGED
|
@@ -45,6 +45,9 @@ function isReviewRound(value) {
|
|
|
45
45
|
isOptional(value.dispute, 'string') &&
|
|
46
46
|
isOptional(value.settled, 'string'));
|
|
47
47
|
}
|
|
48
|
+
function isPending(value) {
|
|
49
|
+
return isRecord(value) && typeof value.reason === 'string' && isOptional(value.since, 'string');
|
|
50
|
+
}
|
|
48
51
|
function isState(value) {
|
|
49
52
|
return (isRecord(value) &&
|
|
50
53
|
typeof value.issue === 'number' &&
|
|
@@ -66,6 +69,7 @@ function isState(value) {
|
|
|
66
69
|
Array.isArray(value.reviewLog) &&
|
|
67
70
|
value.reviewLog.every(isReviewRound) &&
|
|
68
71
|
isOptional(value.handedOver, 'boolean') &&
|
|
72
|
+
(value.pendingHandOver === undefined || isPending(value.pendingHandOver)) &&
|
|
69
73
|
isOptional(value.closing, 'boolean'));
|
|
70
74
|
}
|
|
71
75
|
export async function savedIssues(repo) {
|
|
@@ -79,7 +83,7 @@ export function newState(issue, branch) {
|
|
|
79
83
|
return { issue, phase: 'claimed', branch, ciFixes: 0, reviewRounds: 0, reviewLog: [] };
|
|
80
84
|
}
|
|
81
85
|
export function resetState(state) {
|
|
82
|
-
const { handedOver: _handedOver, ...rest } = state;
|
|
86
|
+
const { handedOver: _handedOver, pendingHandOver: _pending, ...rest } = state;
|
|
83
87
|
const phase = rest.phase === 'approved' ? 'review' : rest.phase;
|
|
84
88
|
return { ...rest, phase, ciFixes: 0, commitFixes: 0, reviewRounds: 0, reviewLog: [] };
|
|
85
89
|
}
|