@chernabog/recipes 0.1.0 → 0.2.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/README.md +2 -0
- package/flows/address-review.ts +26 -7
- package/flows/epic.ts +750 -0
- package/flows/human-initiated.ts +37 -7
- package/flows/implement.ts +113 -29
- package/flows/plan.ts +24 -7
- package/flows/re-review.ts +37 -14
- package/flows/resolve-conflicts.ts +24 -6
- package/flows/review.ts +41 -12
- package/package.json +10 -2
package/flows/human-initiated.ts
CHANGED
|
@@ -11,18 +11,29 @@
|
|
|
11
11
|
// version. The names of its steps ("claim", "work-with-person") are the keys a
|
|
12
12
|
// run in flight resumes by, so renaming one restarts that step.
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
Claims,
|
|
16
|
+
defineFlow,
|
|
17
|
+
Hybrid,
|
|
18
|
+
Implement,
|
|
19
|
+
Review,
|
|
20
|
+
Settings,
|
|
21
|
+
Skip,
|
|
22
|
+
type WorkItem,
|
|
23
|
+
} from "@chernabog/sdk";
|
|
15
24
|
import * as Effect from "effect/Effect";
|
|
16
25
|
import * as Option from "effect/Option";
|
|
26
|
+
import * as Schema from "effect/Schema";
|
|
17
27
|
|
|
18
28
|
const work = (issue: number) =>
|
|
19
29
|
Effect.gen(function* () {
|
|
20
|
-
|
|
21
|
-
const
|
|
30
|
+
// The base the claim settled, the flow's base setting here, which the later steps build on.
|
|
31
|
+
const { base, branch } = yield* Hybrid.claim(issue);
|
|
32
|
+
const worktree = yield* Implement.prepareWorktree(branch, { base });
|
|
22
33
|
// A session the person closes before open-pr fails the run, which lets
|
|
23
34
|
// the claim go and keeps the issue in progress, so chernabog start on the
|
|
24
35
|
// issue again picks the session back up.
|
|
25
|
-
const finished = yield* Hybrid.workWithPerson(issue, worktree);
|
|
36
|
+
const finished = yield* Hybrid.workWithPerson(issue, worktree, { base });
|
|
26
37
|
let pullRequest = Option.none<number>();
|
|
27
38
|
|
|
28
39
|
const toPerson = (reason: string) =>
|
|
@@ -35,10 +46,10 @@ const work = (issue: number) =>
|
|
|
35
46
|
const session = yield* Hybrid.personSession(issue);
|
|
36
47
|
yield* Implement.localGate(worktree, { session });
|
|
37
48
|
// The person watched the change written, so it may touch humanOnlyPaths; a person merges it.
|
|
38
|
-
yield* Implement.push("push", worktree, branch, { withPerson: true });
|
|
39
|
-
const opened = yield* Hybrid.openPullRequest(issue, finished);
|
|
49
|
+
yield* Implement.push("push", worktree, branch, { base, withPerson: true });
|
|
50
|
+
const opened = yield* Hybrid.openPullRequest(issue, finished, { base });
|
|
40
51
|
pullRequest = Option.some(opened.number);
|
|
41
|
-
yield* Implement.waitForCi(opened.number, worktree, { ...session, branch });
|
|
52
|
+
yield* Implement.waitForCi(opened.number, worktree, { ...session, branch, base });
|
|
42
53
|
|
|
43
54
|
return yield* Hybrid.handOff(issue, opened, finished);
|
|
44
55
|
}).pipe(
|
|
@@ -68,9 +79,28 @@ const workflow = (item: WorkItem) =>
|
|
|
68
79
|
Effect.catchTag("NotFound", (gone) => Effect.fail(new Skip({ reason: gone.message }))),
|
|
69
80
|
);
|
|
70
81
|
|
|
82
|
+
// What config.yaml may set for this flow, under settings: or flows.<name>.settings.
|
|
83
|
+
const settings = Schema.Struct({
|
|
84
|
+
...Settings.Labels.fields,
|
|
85
|
+
...Settings.Base.fields,
|
|
86
|
+
...Settings.Board.fields,
|
|
87
|
+
...Settings.LocalGate.fields,
|
|
88
|
+
...Settings.Rules.fields,
|
|
89
|
+
...Settings.Ci.fields,
|
|
90
|
+
...Settings.Reviewers.fields,
|
|
91
|
+
});
|
|
92
|
+
|
|
71
93
|
export default defineFlow({
|
|
94
|
+
labels: Settings.declaredLabels,
|
|
95
|
+
settings,
|
|
72
96
|
item: Hybrid.itemFor,
|
|
97
|
+
// The flow `chernabog start <issue>` runs.
|
|
98
|
+
start: true,
|
|
73
99
|
// No trigger finds work for several personas to share: each run is a person's.
|
|
74
100
|
ownWork: true,
|
|
101
|
+
// Doctor warns when no reviewer its pull requests may ask is a persona here.
|
|
102
|
+
doctor: [Review.poolCheck],
|
|
103
|
+
// An issue closed, or claimed by another run, ends the run as superseded.
|
|
104
|
+
stillValid: Implement.stillValid,
|
|
75
105
|
workflow,
|
|
76
106
|
});
|
package/flows/implement.ts
CHANGED
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
// reviewer from the team's pool. An auto:ship issue's pull request carries the
|
|
5
5
|
// label too, so its approving reviewer merges it.
|
|
6
6
|
//
|
|
7
|
+
// An issue an open pull request on another branch already closes is not
|
|
8
|
+
// implemented again: claim adopts that pull request (auto:adopted), and the
|
|
9
|
+
// run waits for CI, fixing red in a worktree on its branch, and hands it off.
|
|
10
|
+
// A draft waits for its author to mark it ready first. Several, or one on a
|
|
11
|
+
// fork, go to a person.
|
|
12
|
+
//
|
|
7
13
|
// Each block is a durable activity from @chernabog/sdk. Reorder them, leave
|
|
8
14
|
// one out, or put a step of your own from .chernabog/stages/ in between with
|
|
9
15
|
// `step("name", input, OutputSchema)`. Side effects belong inside activities or
|
|
@@ -14,36 +20,75 @@
|
|
|
14
20
|
// version. The names of its steps ("claim", "local-gate-1") are the keys a run
|
|
15
21
|
// in flight resumes by, so renaming one restarts that step.
|
|
16
22
|
|
|
17
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
type CiTimedOut,
|
|
25
|
+
Claims,
|
|
26
|
+
defineFlow,
|
|
27
|
+
GitHub,
|
|
28
|
+
Implement,
|
|
29
|
+
NeedsHuman,
|
|
30
|
+
type NothingCommitted,
|
|
31
|
+
type PullRequestClosed,
|
|
32
|
+
type PushRejected,
|
|
33
|
+
reportAs,
|
|
34
|
+
Review,
|
|
35
|
+
Routing,
|
|
36
|
+
Settings,
|
|
37
|
+
Skip,
|
|
38
|
+
} from "@chernabog/sdk";
|
|
18
39
|
import * as Effect from "effect/Effect";
|
|
19
40
|
import * as Option from "effect/Option";
|
|
41
|
+
import * as Schema from "effect/Schema";
|
|
20
42
|
|
|
21
43
|
// Issues labelled auto:eligible, then ones labelled auto:ship, the automated
|
|
22
44
|
// path, whose pull request chernabog merges once it's approved. Oldest first;
|
|
23
45
|
// with a board, only those whose Status is its readyStatus. An issue another
|
|
24
|
-
// open issue blocks waits for it, as the tasks of a plan's epic do
|
|
46
|
+
// open issue blocks waits for it, as the tasks of a plan's epic do, and a task
|
|
47
|
+
// of an epic that an epic run holds is that run's to start; both are held,
|
|
48
|
+
// and `chernabog status` says why. And the issues whose adopted draft its
|
|
49
|
+
// author marked ready, which wake their run.
|
|
25
50
|
const trigger = Effect.gen(function* () {
|
|
26
51
|
const github = yield* GitHub;
|
|
27
|
-
const
|
|
52
|
+
const labelNames = yield* Settings.labels;
|
|
28
53
|
|
|
29
|
-
const eligible = yield*
|
|
30
|
-
yield* github.queuedIssuesLabelled(repo.labels.eligible),
|
|
31
|
-
);
|
|
54
|
+
const eligible = yield* github.queuedIssuesLabelled(labelNames.eligible);
|
|
32
55
|
|
|
33
|
-
const shipping = (yield*
|
|
34
|
-
|
|
35
|
-
)
|
|
56
|
+
const shipping = (yield* github.queuedIssuesLabelled(labelNames.ship)).filter(
|
|
57
|
+
(issue) => !eligible.some((queued) => queued.number === issue.number),
|
|
58
|
+
);
|
|
36
59
|
|
|
37
60
|
return [
|
|
38
|
-
...
|
|
39
|
-
...
|
|
61
|
+
...(yield* Implement.queued(eligible)),
|
|
62
|
+
...(yield* Implement.queued(shipping, Option.some(labelNames.ship))),
|
|
63
|
+
...(yield* Implement.readied),
|
|
40
64
|
];
|
|
41
65
|
}).pipe(reportAs("trigger"));
|
|
42
66
|
|
|
67
|
+
// How long an adopted draft waits for its author to mark it ready.
|
|
68
|
+
const READY_WITHIN = "14 days";
|
|
69
|
+
|
|
70
|
+
// What config.yaml may set for this flow, under settings: or flows.<name>.settings.
|
|
71
|
+
const settings = Schema.Struct({
|
|
72
|
+
...Routing.Settings.fields,
|
|
73
|
+
...Settings.Labels.fields,
|
|
74
|
+
...Settings.Base.fields,
|
|
75
|
+
...Settings.Board.fields,
|
|
76
|
+
...Settings.LocalGate.fields,
|
|
77
|
+
...Settings.Rules.fields,
|
|
78
|
+
...Settings.Ci.fields,
|
|
79
|
+
...Settings.Reviewers.fields,
|
|
80
|
+
});
|
|
81
|
+
|
|
43
82
|
export default defineFlow({
|
|
44
83
|
trigger,
|
|
45
84
|
gate: Implement.gate,
|
|
46
85
|
concurrency: 1,
|
|
86
|
+
labels: Effect.map(Settings.declaredLabels, (set) => [...set, ...Implement.adoptionLabels]),
|
|
87
|
+
settings,
|
|
88
|
+
// Doctor warns when no reviewer its pull requests may ask is a persona here.
|
|
89
|
+
doctor: [Review.poolCheck],
|
|
90
|
+
// An issue closed, or claimed by another run, ends the run as superseded.
|
|
91
|
+
stillValid: Implement.stillValid,
|
|
47
92
|
workflow: (item) =>
|
|
48
93
|
Effect.gen(function* () {
|
|
49
94
|
const issue = yield* Implement.issueOf(item);
|
|
@@ -55,10 +100,60 @@ export default defineFlow({
|
|
|
55
100
|
Effect.flatMap(Implement.endForPerson),
|
|
56
101
|
);
|
|
57
102
|
|
|
103
|
+
// Nothing to push, a push the token may not make (its message says the
|
|
104
|
+
// fix), CI that never finishes, or a pull request closed under the run:
|
|
105
|
+
// each is a person's to look into.
|
|
106
|
+
const forPerson = {
|
|
107
|
+
NeedsHuman: (needsHuman: NeedsHuman) => toPerson(needsHuman.reason),
|
|
108
|
+
NothingCommitted: (nothing: NothingCommitted) =>
|
|
109
|
+
toPerson(`the agent finished without committing anything on ${nothing.branch}`),
|
|
110
|
+
PushRejected: (rejected: PushRejected) => toPerson(rejected.message),
|
|
111
|
+
CiTimedOut: (timedOut: CiTimedOut) => toPerson(timedOut.message),
|
|
112
|
+
PullRequestClosed: (closed: PullRequestClosed) => toPerson(closed.message),
|
|
113
|
+
};
|
|
114
|
+
|
|
58
115
|
return yield* Effect.gen(function* () {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
116
|
+
// The base the claim settled, the repo's base branch here, which the
|
|
117
|
+
// later steps build on; for an adopted pull request, its branch and base.
|
|
118
|
+
const claimed = yield* Implement.claim(issue, { ...queued, adopt: true });
|
|
119
|
+
const { base, branch } = claimed;
|
|
120
|
+
const adoption = Option.fromUndefinedOr(claimed.adopted);
|
|
121
|
+
|
|
122
|
+
if (Option.isSome(adoption)) {
|
|
123
|
+
const adopted = adoption.value;
|
|
124
|
+
pullRequest = Option.some(adopted.number);
|
|
125
|
+
|
|
126
|
+
return yield* Effect.gen(function* () {
|
|
127
|
+
// A draft is its author's until they mark it ready.
|
|
128
|
+
if (
|
|
129
|
+
adopted.draft &&
|
|
130
|
+
(yield* Implement.awaitReady(issue, adopted.number, READY_WITHIN)) === "timeout"
|
|
131
|
+
) {
|
|
132
|
+
return yield* new NeedsHuman({
|
|
133
|
+
reason: `#${adopted.number} is still a draft after ${READY_WITHIN}`,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// The worktree is made only for a fix.
|
|
138
|
+
yield* Implement.waitForCiMaking(
|
|
139
|
+
adopted.number,
|
|
140
|
+
Implement.prepareWorktree(branch, { base }),
|
|
141
|
+
{
|
|
142
|
+
...Implement.thisRunsSession,
|
|
143
|
+
branch,
|
|
144
|
+
base,
|
|
145
|
+
},
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
return yield* Implement.handOff(issue, adopted, Implement.adoptedOutcome(adopted), {
|
|
149
|
+
needsReview: true,
|
|
150
|
+
adoptedBranch: branch,
|
|
151
|
+
});
|
|
152
|
+
}).pipe(Effect.catchTags(forPerson));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const worktree = yield* Implement.prepareWorktree(branch, { base });
|
|
156
|
+
const outcome = yield* Implement.implementWithAgent(issue, worktree, { base });
|
|
62
157
|
|
|
63
158
|
if (outcome.status === "needs-clarification") {
|
|
64
159
|
return yield* Implement.askForClarification(issue, outcome, queued).pipe(
|
|
@@ -68,28 +163,17 @@ export default defineFlow({
|
|
|
68
163
|
|
|
69
164
|
return yield* Effect.gen(function* () {
|
|
70
165
|
yield* Implement.localGate(worktree);
|
|
71
|
-
yield* Implement.push("push", worktree, branch);
|
|
72
|
-
const opened = yield* Implement.openPullRequest(issue, outcome, queued);
|
|
166
|
+
yield* Implement.push("push", worktree, branch, { base });
|
|
167
|
+
const opened = yield* Implement.openPullRequest(issue, outcome, { ...queued, base });
|
|
73
168
|
pullRequest = Option.some(opened.number);
|
|
74
169
|
yield* Implement.waitForCi(opened.number, worktree, {
|
|
75
170
|
...Implement.thisRunsSession,
|
|
76
171
|
branch,
|
|
172
|
+
base,
|
|
77
173
|
});
|
|
78
174
|
|
|
79
175
|
return yield* Implement.handOff(issue, opened, outcome);
|
|
80
|
-
}).pipe(
|
|
81
|
-
Effect.catchTags({
|
|
82
|
-
NeedsHuman: (needsHuman) => toPerson(needsHuman.reason),
|
|
83
|
-
// Nothing to push, a push the token may not make (its message
|
|
84
|
-
// says the fix), CI that never finishes, or a pull request closed
|
|
85
|
-
// under the run: each is a person's to look into.
|
|
86
|
-
NothingCommitted: (nothing) =>
|
|
87
|
-
toPerson(`the agent finished without committing anything on ${nothing.branch}`),
|
|
88
|
-
PushRejected: (rejected) => toPerson(rejected.message),
|
|
89
|
-
CiTimedOut: (timedOut) => toPerson(timedOut.message),
|
|
90
|
-
PullRequestClosed: (closed) => toPerson(closed.message),
|
|
91
|
-
}),
|
|
92
|
-
);
|
|
176
|
+
}).pipe(Effect.catchTags(forPerson));
|
|
93
177
|
}).pipe(
|
|
94
178
|
// Any other failure once the issue is claimed hands it to a person, rather
|
|
95
179
|
// than leaving it claimed with nobody working on it.
|
package/flows/plan.ts
CHANGED
|
@@ -20,28 +20,32 @@ import {
|
|
|
20
20
|
NeedsHuman,
|
|
21
21
|
Plan,
|
|
22
22
|
reportAs,
|
|
23
|
+
Routing,
|
|
24
|
+
Settings,
|
|
23
25
|
Skip,
|
|
24
26
|
type WorkItem,
|
|
25
27
|
} from "@chernabog/sdk";
|
|
26
28
|
import * as Effect from "effect/Effect";
|
|
27
29
|
import * as Option from "effect/Option";
|
|
28
30
|
import * as Predicate from "effect/Predicate";
|
|
31
|
+
import * as Schema from "effect/Schema";
|
|
29
32
|
|
|
30
33
|
// How long a posted plan waits for a person before the run hands it back.
|
|
31
34
|
const ANSWER_WITHIN = "14 days";
|
|
32
35
|
|
|
33
36
|
// Specs labelled auto:plan, oldest first, as work to start; with a board,
|
|
34
|
-
// only those whose Status is its readyStatus
|
|
35
|
-
// person has answered, which wake the run waiting on it.
|
|
37
|
+
// only those whose Status is its readyStatus, routed by their assignees. Then
|
|
38
|
+
// specs whose posted plan a person has answered, which wake the run waiting on it.
|
|
36
39
|
const trigger = Effect.gen(function* () {
|
|
37
40
|
const github = yield* GitHub;
|
|
38
41
|
const queued = yield* github.queuedIssuesLabelled(Plan.LABELS.plan);
|
|
39
42
|
const answered = yield* Plan.answers;
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
const specs = yield* Effect.forEach(queued, (issue) =>
|
|
45
|
+
Implement.routed(issue, Implement.issueItem(issue, Option.some(Plan.LABELS.plan))),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return [...specs, ...answered];
|
|
45
49
|
}).pipe(reportAs("trigger"));
|
|
46
50
|
|
|
47
51
|
// Drafts, checks and proposes the plan, and waits for a person's answer,
|
|
@@ -120,10 +124,23 @@ const workflow = (item: WorkItem) =>
|
|
|
120
124
|
Effect.catchTag("NotFound", (gone) => Effect.fail(new Skip({ reason: gone.message }))),
|
|
121
125
|
);
|
|
122
126
|
|
|
127
|
+
// What config.yaml may set for this flow, under settings: or flows.<name>.settings.
|
|
128
|
+
const settings = Schema.Struct({
|
|
129
|
+
...Routing.Settings.fields,
|
|
130
|
+
...Settings.Labels.fields,
|
|
131
|
+
...Settings.Base.fields,
|
|
132
|
+
...Settings.Board.fields,
|
|
133
|
+
...Settings.Rules.fields,
|
|
134
|
+
...Settings.Plans.fields,
|
|
135
|
+
});
|
|
136
|
+
|
|
123
137
|
export default defineFlow({
|
|
124
138
|
trigger,
|
|
125
139
|
gate: Implement.gate,
|
|
126
140
|
concurrency: 1,
|
|
127
|
-
labels: Plan.flowLabels,
|
|
141
|
+
labels: Effect.map(Settings.declaredLabels, (set) => [...set, ...Plan.flowLabels]),
|
|
142
|
+
settings,
|
|
143
|
+
// A spec closed, or claimed by another run, ends the run as superseded.
|
|
144
|
+
stillValid: Plan.stillValid,
|
|
128
145
|
workflow,
|
|
129
146
|
});
|
package/flows/re-review.ts
CHANGED
|
@@ -18,6 +18,8 @@ import {
|
|
|
18
18
|
Repo,
|
|
19
19
|
reportAs,
|
|
20
20
|
Review,
|
|
21
|
+
Routing,
|
|
22
|
+
Settings,
|
|
21
23
|
Skip,
|
|
22
24
|
type WorkItem,
|
|
23
25
|
} from "@chernabog/sdk";
|
|
@@ -27,17 +29,16 @@ import * as Schema from "effect/Schema";
|
|
|
27
29
|
|
|
28
30
|
// Pull requests that ask this persona again after it reviewed them, one item
|
|
29
31
|
// per request, unless a person has them (auto:needs-human): asking again
|
|
30
|
-
// during a dispute doesn't restart the loop.
|
|
32
|
+
// during a dispute doesn't restart the loop. Each is routed by its assignees and reviewers.
|
|
31
33
|
const trigger = Effect.gen(function* () {
|
|
32
|
-
const
|
|
34
|
+
const labelNames = yield* Settings.labels;
|
|
33
35
|
|
|
34
|
-
return
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
Review.reviewItem(pull, `pr-${pull.number}-review-${reviewed + 1}`),
|
|
38
|
-
() => reviewed > 0 && !pull.labels.includes(repo.labels.needsHuman),
|
|
39
|
-
),
|
|
36
|
+
return yield* Effect.forEach(
|
|
37
|
+
(yield* Review.reviewRequests).filter(
|
|
38
|
+
({ pull, reviewed }) => reviewed > 0 && !pull.labels.includes(labelNames.needsHuman),
|
|
40
39
|
),
|
|
40
|
+
({ pull, reviewed }) =>
|
|
41
|
+
Review.routed(pull, Review.reviewItem(pull, `pr-${pull.number}-review-${reviewed + 1}`)),
|
|
41
42
|
);
|
|
42
43
|
}).pipe(reportAs("trigger"));
|
|
43
44
|
|
|
@@ -65,15 +66,22 @@ const conflicts = (pullRequest: number) =>
|
|
|
65
66
|
);
|
|
66
67
|
|
|
67
68
|
// Chernabog merges only pull requests on the automated path (auto:ship), and
|
|
68
|
-
// only when that's safe; a person merges any other.
|
|
69
|
-
//
|
|
70
|
-
//
|
|
69
|
+
// only when that's safe; a person merges any other. A layer of a stack waits,
|
|
70
|
+
// approved, for the layer below: the epic run merges it once it is on the
|
|
71
|
+
// base. One refused because it conflicts with its base is left to
|
|
72
|
+
// resolve-conflicts, which merges the base in and asks for this review again.
|
|
71
73
|
const mergeIfShipping = (pullRequest: number) =>
|
|
72
74
|
Effect.gen(function* () {
|
|
73
75
|
if (!(yield* PullRequest.shipping(pullRequest))) {
|
|
74
76
|
return `#${pullRequest} approved; a person merges`;
|
|
75
77
|
}
|
|
76
78
|
|
|
79
|
+
const waiting = yield* PullRequest.waitingOnLayer(pullRequest);
|
|
80
|
+
|
|
81
|
+
if (Option.isSome(waiting)) {
|
|
82
|
+
return `#${pullRequest} approved; ${waiting.value}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
77
85
|
return yield* PullRequest.merge(pullRequest, { method: "squash" }).pipe(
|
|
78
86
|
Effect.catchTag("MergeRefused", (refused) =>
|
|
79
87
|
Effect.gen(function* () {
|
|
@@ -117,7 +125,7 @@ const reReviews = (count: number) => {
|
|
|
117
125
|
|
|
118
126
|
const workflow = (item: WorkItem) =>
|
|
119
127
|
Effect.gen(function* () {
|
|
120
|
-
const
|
|
128
|
+
const { rounds } = yield* Settings.reviewers;
|
|
121
129
|
const { pullRequest } = yield* Review.pullRequestOf(item);
|
|
122
130
|
const earlier = yield* Review.latestOwnReview(pullRequest);
|
|
123
131
|
|
|
@@ -129,10 +137,10 @@ const workflow = (item: WorkItem) =>
|
|
|
129
137
|
const round = earlier.value.round ?? 1;
|
|
130
138
|
const done = round - 1;
|
|
131
139
|
|
|
132
|
-
if (done >=
|
|
140
|
+
if (done >= rounds) {
|
|
133
141
|
return yield* PullRequest.handToPerson(
|
|
134
142
|
pullRequest,
|
|
135
|
-
`asked to review again after ${reReviews(done)}, and
|
|
143
|
+
`asked to review again after ${reReviews(done)}, and reviewRounds is ${rounds}, so a person decides. Review ${round}'s findings are in its review above.`,
|
|
136
144
|
);
|
|
137
145
|
}
|
|
138
146
|
|
|
@@ -167,10 +175,25 @@ const workflow = (item: WorkItem) =>
|
|
|
167
175
|
}),
|
|
168
176
|
);
|
|
169
177
|
|
|
178
|
+
// What config.yaml may set for this flow, under settings: or flows.<name>.settings.
|
|
179
|
+
const settings = Schema.Struct({
|
|
180
|
+
...Routing.Settings.fields,
|
|
181
|
+
...Settings.Labels.fields,
|
|
182
|
+
...Settings.Base.fields,
|
|
183
|
+
...Settings.Rules.fields,
|
|
184
|
+
...Settings.Reviewers.fields,
|
|
185
|
+
});
|
|
186
|
+
|
|
170
187
|
export default defineFlow({
|
|
188
|
+
labels: Settings.declaredLabels,
|
|
189
|
+
settings,
|
|
171
190
|
trigger,
|
|
172
191
|
concurrency: 1,
|
|
173
192
|
// Its trigger finds only pull requests that ask this persona for a review.
|
|
174
193
|
ownWork: true,
|
|
194
|
+
// Doctor warns when a reviewer this machine acts as doesn't run it.
|
|
195
|
+
doctor: [Review.reviewerCheck],
|
|
196
|
+
// A pull request closed or merged ends the run as superseded.
|
|
197
|
+
stillValid: Review.stillValid,
|
|
175
198
|
workflow,
|
|
176
199
|
});
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
reportAs,
|
|
34
34
|
Review,
|
|
35
35
|
Run,
|
|
36
|
+
Settings,
|
|
36
37
|
Skip,
|
|
37
38
|
StepFailed,
|
|
38
39
|
type WorkItem,
|
|
@@ -68,10 +69,11 @@ const decodeIn =
|
|
|
68
69
|
const trigger = Effect.gen(function* () {
|
|
69
70
|
const github = yield* GitHub;
|
|
70
71
|
const repo = yield* Repo;
|
|
72
|
+
const labelNames = yield* Settings.labels;
|
|
71
73
|
const items: Array<WorkItem> = [];
|
|
72
74
|
|
|
73
75
|
for (const pull of yield* Review.authoredByMe) {
|
|
74
|
-
if (pull.labels.includes(
|
|
76
|
+
if (pull.labels.includes(labelNames.needsHuman) || (yield* Review.ownedByARun(pull))) {
|
|
75
77
|
continue;
|
|
76
78
|
}
|
|
77
79
|
|
|
@@ -123,15 +125,17 @@ const resolve = (conflict: ConflictItem, worktree: string, sessionId: string) =>
|
|
|
123
125
|
"resolve",
|
|
124
126
|
Effect.gen(function* () {
|
|
125
127
|
const repo = yield* Repo;
|
|
128
|
+
const rules = yield* Settings.rules;
|
|
129
|
+
const localGate = yield* Settings.localGate;
|
|
126
130
|
|
|
127
131
|
const prompt = yield* renderPrompt("resolve-conflicts", {
|
|
128
132
|
repo: repo.slug,
|
|
129
133
|
pullRequest: conflict.pullRequest,
|
|
130
134
|
branch: conflict.headRef,
|
|
131
135
|
base: conflict.baseRef,
|
|
132
|
-
humanOnly:
|
|
133
|
-
notes:
|
|
134
|
-
localGate:
|
|
136
|
+
humanOnly: rules.humanOnly,
|
|
137
|
+
notes: rules.notes,
|
|
138
|
+
localGate: localGate.commands,
|
|
135
139
|
});
|
|
136
140
|
|
|
137
141
|
const result = yield* (yield* Agent).run({
|
|
@@ -191,7 +195,8 @@ const unstick = (conflict: ConflictItem) =>
|
|
|
191
195
|
}
|
|
192
196
|
|
|
193
197
|
yield* Implement.localGate(worktree, { id: "resolve", session });
|
|
194
|
-
|
|
198
|
+
// Checked against the pull request's base, the layer below's branch for a layer of a stack.
|
|
199
|
+
yield* Implement.push("push-resolved", worktree, conflict.headRef, { base: conflict.baseRef });
|
|
195
200
|
yield* PullRequest.comment(
|
|
196
201
|
conflict.pullRequest,
|
|
197
202
|
`Merged \`${conflict.baseRef}\` into this branch to resolve its conflicts.\n\n${resolution.summary}`,
|
|
@@ -199,7 +204,7 @@ const unstick = (conflict: ConflictItem) =>
|
|
|
199
204
|
yield* Implement.waitForCi(
|
|
200
205
|
conflict.pullRequest,
|
|
201
206
|
worktree,
|
|
202
|
-
{ ...session, branch: conflict.headRef },
|
|
207
|
+
{ ...session, branch: conflict.headRef, base: conflict.baseRef },
|
|
203
208
|
{ id: "resolve" },
|
|
204
209
|
);
|
|
205
210
|
|
|
@@ -237,11 +242,24 @@ const workflow = (item: WorkItem) =>
|
|
|
237
242
|
);
|
|
238
243
|
});
|
|
239
244
|
|
|
245
|
+
// What config.yaml may set for this flow, under settings: or flows.<name>.settings.
|
|
246
|
+
const settings = Schema.Struct({
|
|
247
|
+
...Settings.Labels.fields,
|
|
248
|
+
...Settings.Base.fields,
|
|
249
|
+
...Settings.LocalGate.fields,
|
|
250
|
+
...Settings.Rules.fields,
|
|
251
|
+
...Settings.Ci.fields,
|
|
252
|
+
});
|
|
253
|
+
|
|
240
254
|
export default defineFlow({
|
|
255
|
+
labels: Settings.declaredLabels,
|
|
256
|
+
settings,
|
|
241
257
|
trigger,
|
|
242
258
|
gate: Implement.gate,
|
|
243
259
|
concurrency: 1,
|
|
244
260
|
// Its trigger finds only pull requests this persona wrote.
|
|
245
261
|
ownWork: true,
|
|
262
|
+
// A pull request closed or merged ends the run as superseded.
|
|
263
|
+
stillValid: Review.stillValid,
|
|
246
264
|
workflow,
|
|
247
265
|
});
|
package/flows/review.ts
CHANGED
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
Repo,
|
|
20
20
|
reportAs,
|
|
21
21
|
Review,
|
|
22
|
+
Routing,
|
|
23
|
+
Settings,
|
|
22
24
|
Skip,
|
|
23
25
|
type WorkItem,
|
|
24
26
|
} from "@chernabog/sdk";
|
|
@@ -27,15 +29,20 @@ import * as Option from "effect/Option";
|
|
|
27
29
|
import * as Schema from "effect/Schema";
|
|
28
30
|
|
|
29
31
|
// Pull requests that ask this persona for a review, which it hasn't reviewed
|
|
30
|
-
// yet
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
// yet, routed by their assignees and reviewers, and those waiting on a
|
|
33
|
+
// reviewer no persona on this machine acts as, which status lists. Reading
|
|
34
|
+
// review requests needs the persona's seat in the reviewer pool, which
|
|
35
|
+
// chernabog checks before the flow runs.
|
|
36
|
+
const trigger = Effect.gen(function* () {
|
|
37
|
+
const found = yield* Review.reviewRequests;
|
|
38
|
+
|
|
39
|
+
const mine = yield* Effect.forEach(
|
|
40
|
+
found.filter(({ reviewed }) => reviewed === 0),
|
|
41
|
+
({ pull }) => Review.routed(pull, Review.reviewItem(pull, `pr-${pull.number}`)),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return [...mine, ...(yield* Review.waitingElsewhere)];
|
|
45
|
+
}).pipe(reportAs("trigger"));
|
|
39
46
|
|
|
40
47
|
const MergeState = Schema.Struct({ mergeable_state: Schema.String });
|
|
41
48
|
|
|
@@ -61,15 +68,22 @@ const conflicts = (pullRequest: number) =>
|
|
|
61
68
|
);
|
|
62
69
|
|
|
63
70
|
// Chernabog merges only pull requests on the automated path (auto:ship), and
|
|
64
|
-
// only when that's safe; a person merges any other.
|
|
65
|
-
//
|
|
66
|
-
//
|
|
71
|
+
// only when that's safe; a person merges any other. A layer of a stack waits,
|
|
72
|
+
// approved, for the layer below: the epic run merges it once it is on the
|
|
73
|
+
// base. One refused because it conflicts with its base is left to
|
|
74
|
+
// resolve-conflicts, which merges the base in and asks for this review again.
|
|
67
75
|
const mergeIfShipping = (pullRequest: number) =>
|
|
68
76
|
Effect.gen(function* () {
|
|
69
77
|
if (!(yield* PullRequest.shipping(pullRequest))) {
|
|
70
78
|
return `#${pullRequest} approved; a person merges`;
|
|
71
79
|
}
|
|
72
80
|
|
|
81
|
+
const waiting = yield* PullRequest.waitingOnLayer(pullRequest);
|
|
82
|
+
|
|
83
|
+
if (Option.isSome(waiting)) {
|
|
84
|
+
return `#${pullRequest} approved; ${waiting.value}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
73
87
|
return yield* PullRequest.merge(pullRequest, { method: "squash" }).pipe(
|
|
74
88
|
Effect.catchTag("MergeRefused", (refused) =>
|
|
75
89
|
Effect.gen(function* () {
|
|
@@ -103,10 +117,25 @@ const workflow = (item: WorkItem) =>
|
|
|
103
117
|
}),
|
|
104
118
|
);
|
|
105
119
|
|
|
120
|
+
// What config.yaml may set for this flow, under settings: or flows.<name>.settings.
|
|
121
|
+
const settings = Schema.Struct({
|
|
122
|
+
...Routing.Settings.fields,
|
|
123
|
+
...Settings.Labels.fields,
|
|
124
|
+
...Settings.Base.fields,
|
|
125
|
+
...Settings.Rules.fields,
|
|
126
|
+
...Settings.Reviewers.fields,
|
|
127
|
+
});
|
|
128
|
+
|
|
106
129
|
export default defineFlow({
|
|
130
|
+
labels: Settings.declaredLabels,
|
|
131
|
+
settings,
|
|
107
132
|
trigger,
|
|
108
133
|
concurrency: 1,
|
|
109
134
|
// Its trigger finds only pull requests that ask this persona for a review.
|
|
110
135
|
ownWork: true,
|
|
136
|
+
// Doctor warns when a reviewer this machine acts as doesn't run it.
|
|
137
|
+
doctor: [Review.reviewerCheck],
|
|
138
|
+
// A pull request closed or merged ends the run as superseded.
|
|
139
|
+
stillValid: Review.stillValid,
|
|
111
140
|
workflow,
|
|
112
141
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chernabog/recipes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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,7 +15,7 @@
|
|
|
15
15
|
"README.md"
|
|
16
16
|
],
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"@chernabog/sdk": "
|
|
18
|
+
"@chernabog/sdk": "^0.8.0"
|
|
19
19
|
},
|
|
20
20
|
"chernabog": {
|
|
21
21
|
"recipes": {
|
|
@@ -64,6 +64,14 @@
|
|
|
64
64
|
],
|
|
65
65
|
"docs": "https://dataquail.github.io/chernabog/recipes/plan/"
|
|
66
66
|
},
|
|
67
|
+
"epic": {
|
|
68
|
+
"description": "Works through an auto:epic issue's tasks as pull requests, each stacked on the branch of the task it builds on, and parks between changes to its layers",
|
|
69
|
+
"flow": "flows/epic.ts",
|
|
70
|
+
"prompts": [
|
|
71
|
+
"prompts/implement.md"
|
|
72
|
+
],
|
|
73
|
+
"docs": "https://dataquail.github.io/chernabog/recipes/epic/"
|
|
74
|
+
},
|
|
67
75
|
"human-initiated": {
|
|
68
76
|
"description": "The hybrid path: chernabog start <issue> opens a session with a person, then opens the pull request and asks for a review",
|
|
69
77
|
"flow": "flows/human-initiated.ts",
|