@chernabog/recipes 0.6.0 → 0.7.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/flows/address-review.ts +17 -3
- package/flows/epic.ts +249 -78
- package/flows/human-initiated.ts +2 -1
- package/flows/implement.ts +41 -13
- package/flows/plan.ts +64 -12
- package/flows/post-merge.ts +299 -107
- package/flows/re-review.ts +25 -3
- package/flows/resolve-conflicts.ts +83 -26
- package/flows/review.ts +22 -3
- package/package.json +3 -3
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
// for checks that never start, and it can't merge. An agent merges the base
|
|
4
4
|
// into the branch in the author's worktree, resolves the conflicts and commits
|
|
5
5
|
// the merge; chernabog runs the local gate, pushes (a plain push: the merge
|
|
6
|
-
// only adds commits, so nothing is rewritten) and waits for CI
|
|
6
|
+
// only adds commits, so nothing is rewritten) and waits for CI, which parks
|
|
7
|
+
// while CI is pending over the pull request's review phase and records it
|
|
8
|
+
// again once the wait ends (Conflict.waitForCi). A run of
|
|
7
9
|
// another flow waiting on the pull request's CI, such as implement's, carries
|
|
8
10
|
// on from there.
|
|
9
11
|
//
|
|
@@ -32,12 +34,15 @@
|
|
|
32
34
|
import {
|
|
33
35
|
activity,
|
|
34
36
|
Agent,
|
|
37
|
+
Blocks,
|
|
38
|
+
Conflict,
|
|
35
39
|
defineFlow,
|
|
36
40
|
Events,
|
|
37
41
|
GitHub,
|
|
38
42
|
Implement,
|
|
39
43
|
type Json,
|
|
40
44
|
NeedsHuman,
|
|
45
|
+
Phases,
|
|
41
46
|
PullRequest,
|
|
42
47
|
renderPrompt,
|
|
43
48
|
Repo,
|
|
@@ -74,17 +79,23 @@ const decodeIn =
|
|
|
74
79
|
Effect.mapError((issue) => new StepFailed({ step, message: issue.message })),
|
|
75
80
|
);
|
|
76
81
|
|
|
77
|
-
// Open pull requests this persona wrote
|
|
78
|
-
//
|
|
79
|
-
//
|
|
82
|
+
// Open pull requests this persona wrote whose run parked on CI for the merge
|
|
83
|
+
// it pushed, to finish what's started: each is held until CI is green or
|
|
84
|
+
// red, or ciTimeout passes. Then open pull requests this persona wrote that
|
|
85
|
+
// conflict with their base. The key carries the head, so a conflict that
|
|
86
|
+
// comes back after a later push is new work.
|
|
80
87
|
const trigger = Effect.gen(function* () {
|
|
81
88
|
const github = yield* GitHub;
|
|
82
89
|
const repo = yield* Repo;
|
|
83
|
-
const
|
|
84
|
-
const
|
|
90
|
+
const items: Array<WorkItem> = [...(yield* Conflict.parkedOnCi)];
|
|
91
|
+
const all = yield* Phases.records;
|
|
85
92
|
|
|
86
93
|
for (const pull of yield* Review.authoredByMe) {
|
|
87
|
-
|
|
94
|
+
// A person has one whose record is with-person, whatever its label says.
|
|
95
|
+
if (
|
|
96
|
+
Phases.isWithPerson(Phases.recordOf(all, Phases.pullRequestItem(pull.number))) ||
|
|
97
|
+
(yield* Review.ownedByARun(pull))
|
|
98
|
+
) {
|
|
88
99
|
continue;
|
|
89
100
|
}
|
|
90
101
|
|
|
@@ -105,7 +116,11 @@ const trigger = Effect.gen(function* () {
|
|
|
105
116
|
}
|
|
106
117
|
|
|
107
118
|
return items;
|
|
108
|
-
}).pipe(
|
|
119
|
+
}).pipe(
|
|
120
|
+
// Every record it reads is checked first, as its document's are (ADR 21, decision 5).
|
|
121
|
+
Blocks.checked("pr.conflicting", "conflict.waitForCi"),
|
|
122
|
+
reportAs("trigger"),
|
|
123
|
+
);
|
|
109
124
|
|
|
110
125
|
const Resolution = Schema.Struct({
|
|
111
126
|
status: Schema.Literals(["resolved", "needs-human"]),
|
|
@@ -261,6 +276,35 @@ const resolveWithBelow = (conflict: ConflictItem, worktree: string, sessionId: s
|
|
|
261
276
|
return { status: "resolved", summary: summaries.join("\n\n") } satisfies typeof Resolution.Type;
|
|
262
277
|
});
|
|
263
278
|
|
|
279
|
+
// Waits for CI on the pushed merge, from `firstRound` for a run that takes a
|
|
280
|
+
// parked wait up, then asks an approving reviewer again.
|
|
281
|
+
const awaitMergeCi = (
|
|
282
|
+
conflict: ConflictItem,
|
|
283
|
+
worktree: string,
|
|
284
|
+
session: Implement.AuthorSession,
|
|
285
|
+
firstRound: Option.Option<number> = Option.none(),
|
|
286
|
+
) =>
|
|
287
|
+
Effect.gen(function* () {
|
|
288
|
+
yield* Conflict.waitForCi(
|
|
289
|
+
conflict.pullRequest,
|
|
290
|
+
worktree,
|
|
291
|
+
{ ...session, branch: conflict.headRef, base: conflict.baseRef },
|
|
292
|
+
Conflict.parkOnPullRequest(conflict.pullRequest),
|
|
293
|
+
firstRound,
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
// An approval was of the code before the merge: its reviewer looks again,
|
|
297
|
+
// and re-review merges an auto:ship pull request it approves.
|
|
298
|
+
const approver = yield* Review.askApproverAgain(conflict.pullRequest);
|
|
299
|
+
|
|
300
|
+
return Option.match(approver, {
|
|
301
|
+
onNone: () =>
|
|
302
|
+
`#${conflict.pullRequest}: merged ${conflict.baseRef} and resolved its conflicts`,
|
|
303
|
+
onSome: (login) =>
|
|
304
|
+
`#${conflict.pullRequest}: merged ${conflict.baseRef}, resolved its conflicts and asked ${login} to review again`,
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
|
|
264
308
|
const unstick = (conflict: ConflictItem) =>
|
|
265
309
|
Effect.gen(function* () {
|
|
266
310
|
const run = yield* Run;
|
|
@@ -288,23 +332,26 @@ const unstick = (conflict: ConflictItem) =>
|
|
|
288
332
|
conflict.pullRequest,
|
|
289
333
|
`Merged \`${conflict.baseRef}\` into this branch to resolve its conflicts.\n\n${resolution.summary}`,
|
|
290
334
|
);
|
|
291
|
-
yield* Implement.waitForCi(
|
|
292
|
-
conflict.pullRequest,
|
|
293
|
-
worktree,
|
|
294
|
-
{ ...session, branch: conflict.headRef, base: conflict.baseRef },
|
|
295
|
-
{ id: "resolve" },
|
|
296
|
-
);
|
|
297
335
|
|
|
298
|
-
//
|
|
299
|
-
// and
|
|
300
|
-
|
|
336
|
+
// Still-pending CI parks on the pull request's record, over its review
|
|
337
|
+
// phase, and ends the run; the item comes back through
|
|
338
|
+
// Conflict.parkedOnCi once CI finishes (resumeWait).
|
|
339
|
+
return yield* awaitMergeCi(conflict, worktree, session);
|
|
340
|
+
});
|
|
301
341
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
342
|
+
// A run that takes up a wait a run before it parked on: the merge is pushed,
|
|
343
|
+
// so it waits on in a worktree on the branch, for a fix of red CI, which
|
|
344
|
+
// starts a session of its own.
|
|
345
|
+
const resumeWait = (conflict: ConflictItem, round: number) =>
|
|
346
|
+
Effect.gen(function* () {
|
|
347
|
+
const worktree = yield* Review.prepareAuthorWorktree(conflict.headRef);
|
|
348
|
+
|
|
349
|
+
return yield* awaitMergeCi(
|
|
350
|
+
conflict,
|
|
351
|
+
worktree,
|
|
352
|
+
{ sessionId: Option.none(), adapter: Option.none() },
|
|
353
|
+
Option.some(round),
|
|
354
|
+
);
|
|
308
355
|
});
|
|
309
356
|
|
|
310
357
|
const workflow = (item: WorkItem) =>
|
|
@@ -313,12 +360,17 @@ const workflow = (item: WorkItem) =>
|
|
|
313
360
|
Effect.mapError((issue) => new StepFailed({ step: "item", message: issue.message })),
|
|
314
361
|
);
|
|
315
362
|
|
|
363
|
+
const resuming = Conflict.resumingCi(item);
|
|
364
|
+
|
|
316
365
|
const toPerson = (reason: string) => PullRequest.handToPerson(conflict.pullRequest, reason);
|
|
317
366
|
|
|
318
367
|
// Anything that stops it hands the pull request to a person, unless it
|
|
319
368
|
// closed meanwhile. It owns the pull request throughout, so no other run
|
|
320
369
|
// pushes to the branch under it; one another run owns is skipped.
|
|
321
|
-
return yield*
|
|
370
|
+
return yield* Option.match(resuming, {
|
|
371
|
+
onNone: () => unstick(conflict),
|
|
372
|
+
onSome: (round) => resumeWait(conflict, round),
|
|
373
|
+
}).pipe(
|
|
322
374
|
Effect.catchTags({
|
|
323
375
|
NeedsHuman: (needsHuman) => toPerson(needsHuman.reason),
|
|
324
376
|
StepFailed: (failed) => toPerson(`${failed.step}: ${failed.message}`),
|
|
@@ -356,5 +408,10 @@ const flow = defineFlow({
|
|
|
356
408
|
|
|
357
409
|
// The GitHub events that can change what its trigger finds, so it wakes in CI
|
|
358
410
|
// rather than only on the schedule: a pull request closing, which may move the
|
|
359
|
-
// base under every other one
|
|
360
|
-
|
|
411
|
+
// base under every other one, and a finished CI run, which frees a pull
|
|
412
|
+
// request whose run parked on its merge's CI. Its trigger reads pull
|
|
413
|
+
// requests' phases for those, so a phase event wakes it too.
|
|
414
|
+
export default Events.declare(flow, {
|
|
415
|
+
events: [Events.baseMoved, Events.ciCompleted],
|
|
416
|
+
readsPhases: true,
|
|
417
|
+
});
|
package/flows/review.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
import {
|
|
15
15
|
activity,
|
|
16
|
+
Blocks,
|
|
16
17
|
defineFlow,
|
|
17
18
|
Events,
|
|
18
19
|
GitHub,
|
|
@@ -33,16 +34,23 @@ import * as Schema from "effect/Schema";
|
|
|
33
34
|
// this persona, routed by their assignees and reviewers (one whose record
|
|
34
35
|
// GitHub disagrees with is held, for status to show why), those waiting on a reviewer
|
|
35
36
|
// no persona on this machine acts as, which status lists, and the runs
|
|
36
|
-
// holding a merge whose base branch is green again,
|
|
37
|
+
// holding a merge whose base branch is green again, or whose hold lasted past
|
|
38
|
+
// mergeHoldTimeout: they wake a run still parked on one, or a CI job's ended
|
|
39
|
+
// one is taken up by a new run, from the pull request's record. Reading
|
|
37
40
|
// review requests needs the persona's seat in the reviewer pool, which
|
|
38
41
|
// chernabog checks before the flow runs.
|
|
39
42
|
const trigger = Effect.gen(function* () {
|
|
40
43
|
return [
|
|
41
44
|
...(yield* Review.requestedFirst),
|
|
42
45
|
...(yield* Review.waitingElsewhere),
|
|
43
|
-
|
|
46
|
+
// A first review's work item is keyed pr-N; re-review's are pr-N-<more>.
|
|
47
|
+
...(yield* PullRequest.heldMerges((key, pullRequest) => key === `pr-${pullRequest}`)),
|
|
44
48
|
];
|
|
45
|
-
}).pipe(
|
|
49
|
+
}).pipe(
|
|
50
|
+
// Every record it reads is checked first, as its document's are (ADR 21, decision 5).
|
|
51
|
+
Blocks.checked("review.requested", "review.waitingElsewhere", "pr.land"),
|
|
52
|
+
reportAs("trigger"),
|
|
53
|
+
);
|
|
46
54
|
|
|
47
55
|
const MergeState = Schema.Struct({ mergeable_state: Schema.String });
|
|
48
56
|
|
|
@@ -100,7 +108,18 @@ const mergeIfShipping = (pullRequest: number) =>
|
|
|
100
108
|
|
|
101
109
|
const workflow = (item: WorkItem) =>
|
|
102
110
|
Effect.gen(function* () {
|
|
111
|
+
// A merge an earlier run held, which a CI job ended on: it was approved, so merge it.
|
|
112
|
+
const held = PullRequest.resumingMerge(item);
|
|
113
|
+
|
|
114
|
+
if (Option.isSome(held)) {
|
|
115
|
+
return yield* mergeIfShipping(held.value);
|
|
116
|
+
}
|
|
117
|
+
|
|
103
118
|
const { pullRequest } = yield* Review.pullRequestOf(item);
|
|
119
|
+
|
|
120
|
+
// One that changes a behavior spec no person approved goes to a person, unreviewed.
|
|
121
|
+
yield* PullRequest.specGuard(pullRequest);
|
|
122
|
+
|
|
104
123
|
const review = yield* Review.round(pullRequest, 1, { role: "reviewer" });
|
|
105
124
|
yield* Review.doneReviewing(pullRequest);
|
|
106
125
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chernabog/recipes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Chernabog's recipes: complete flows a repo copies in, or imports, written from @chernabog/sdk",
|
|
6
6
|
"repository": {
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"README.md"
|
|
16
16
|
],
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"@chernabog/core": "^
|
|
19
|
-
"@chernabog/sdk": ">=0.
|
|
18
|
+
"@chernabog/core": "^2.0.0",
|
|
19
|
+
"@chernabog/sdk": ">=0.14.0 <0.15.0"
|
|
20
20
|
},
|
|
21
21
|
"chernabog": {
|
|
22
22
|
"recipes": {
|