@chernabog/recipes 0.4.0 → 0.5.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 +11 -36
- package/flows/epic.ts +12 -1
- package/flows/implement.ts +10 -1
- package/flows/plan.ts +10 -1
- package/flows/post-merge.ts +6 -1
- package/flows/re-review.ts +16 -15
- package/flows/resolve-conflicts.ts +8 -25
- package/flows/review.ts +19 -11
- package/package.json +2 -2
package/flows/address-review.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
import {
|
|
15
15
|
defineFlow,
|
|
16
|
+
Events,
|
|
16
17
|
Implement,
|
|
17
18
|
NeedsHuman,
|
|
18
19
|
PullRequest,
|
|
@@ -23,47 +24,16 @@ import {
|
|
|
23
24
|
Skip,
|
|
24
25
|
type WorkItem,
|
|
25
26
|
} from "@chernabog/sdk";
|
|
26
|
-
import * as Arr from "effect/Array";
|
|
27
27
|
import * as Effect from "effect/Effect";
|
|
28
28
|
import * as Option from "effect/Option";
|
|
29
29
|
import * as Schema from "effect/Schema";
|
|
30
30
|
|
|
31
|
-
// Pull requests this persona wrote whose
|
|
32
|
-
//
|
|
31
|
+
// Pull requests this persona wrote whose record says changes asked, by a
|
|
32
|
+
// review on the current head, so nothing was pushed since. A review a person
|
|
33
|
+
// left moves the record there first.
|
|
33
34
|
// A person has one labelled auto:needs-human, and a run of another flow one it
|
|
34
35
|
// owns; both are left alone. Each is routed by its assignees and reviewers.
|
|
35
|
-
const trigger =
|
|
36
|
-
const labelNames = yield* Settings.labels;
|
|
37
|
-
const items: Array<WorkItem> = [];
|
|
38
|
-
|
|
39
|
-
for (const pull of yield* Review.authoredByMe) {
|
|
40
|
-
if (pull.labels.includes(labelNames.needsHuman)) {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const decisive = yield* Review.decisiveReviews(pull.number);
|
|
45
|
-
const latest = Arr.last(decisive);
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
!Option.exists(
|
|
49
|
-
latest,
|
|
50
|
-
(review) => review.state === "CHANGES_REQUESTED" && review.commitSha === pull.headSha,
|
|
51
|
-
)
|
|
52
|
-
) {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (yield* Review.ownedByARun(pull)) {
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
for (const review of Option.toArray(latest)) {
|
|
61
|
-
items.push(yield* Review.routed(pull, Review.addressItem(pull, review, decisive.length)));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return items;
|
|
66
|
-
}).pipe(reportAs("trigger"));
|
|
36
|
+
const trigger = Review.changesToAddress.pipe(reportAs("trigger"));
|
|
67
37
|
|
|
68
38
|
const answerReview = (address: Review.AddressItem) =>
|
|
69
39
|
Effect.gen(function* () {
|
|
@@ -160,7 +130,7 @@ const settings = Schema.Struct({
|
|
|
160
130
|
...Settings.Reviewers.fields,
|
|
161
131
|
});
|
|
162
132
|
|
|
163
|
-
|
|
133
|
+
const flow = defineFlow({
|
|
164
134
|
labels: Settings.declaredLabels,
|
|
165
135
|
settings,
|
|
166
136
|
trigger,
|
|
@@ -172,3 +142,8 @@ export default defineFlow({
|
|
|
172
142
|
stillValid: Review.stillValid,
|
|
173
143
|
workflow,
|
|
174
144
|
});
|
|
145
|
+
|
|
146
|
+
// The GitHub events that can change what its trigger finds, so it wakes in CI
|
|
147
|
+
// rather than only on the schedule: a review submitted. Its trigger reads each
|
|
148
|
+
// pull request's phase, so a phase event wakes it too.
|
|
149
|
+
export default Events.declare(flow, { events: [Events.reviewSubmitted], readsPhases: true });
|
package/flows/epic.ts
CHANGED
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
Claims,
|
|
33
33
|
defineFlow,
|
|
34
34
|
Epic,
|
|
35
|
+
Events,
|
|
35
36
|
Git,
|
|
36
37
|
GitHub,
|
|
37
38
|
Implement,
|
|
@@ -902,7 +903,7 @@ const settings = Schema.Struct({
|
|
|
902
903
|
...Own.fields,
|
|
903
904
|
});
|
|
904
905
|
|
|
905
|
-
|
|
906
|
+
const flow = defineFlow({
|
|
906
907
|
trigger: Epic.queued.pipe(reportAs("trigger")),
|
|
907
908
|
gate: Implement.gate,
|
|
908
909
|
concurrency: 1,
|
|
@@ -929,3 +930,13 @@ export default defineFlow({
|
|
|
929
930
|
return yield* workThrough(epic, ships, concurrency).pipe(Claims.releasing(Claims.epic(epic)));
|
|
930
931
|
}),
|
|
931
932
|
});
|
|
933
|
+
|
|
934
|
+
// The GitHub events that can change what its trigger finds, so it wakes in CI
|
|
935
|
+
// rather than only on the schedule: an issue labelled auto:epic, and what moves
|
|
936
|
+
// an epic's layers (a task closed or relabelled, a push to, review of or merge
|
|
937
|
+
// of a layer's pull request). Its trigger reads the epic's phase, so a phase
|
|
938
|
+
// event wakes it too.
|
|
939
|
+
export default Events.declare(flow, {
|
|
940
|
+
events: [Events.issueLabelled, ...Events.layerChanged],
|
|
941
|
+
readsPhases: true,
|
|
942
|
+
});
|
package/flows/implement.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
type CiTimedOut,
|
|
25
25
|
Claims,
|
|
26
26
|
defineFlow,
|
|
27
|
+
Events,
|
|
27
28
|
GitHub,
|
|
28
29
|
Implement,
|
|
29
30
|
NeedsHuman,
|
|
@@ -81,7 +82,7 @@ const settings = Schema.Struct({
|
|
|
81
82
|
...Settings.Reviewers.fields,
|
|
82
83
|
});
|
|
83
84
|
|
|
84
|
-
|
|
85
|
+
const flow = defineFlow({
|
|
85
86
|
trigger,
|
|
86
87
|
gate: Implement.gate,
|
|
87
88
|
concurrency: 1,
|
|
@@ -189,3 +190,11 @@ export default defineFlow({
|
|
|
189
190
|
Effect.catchTag("NotFound", (gone) => Effect.fail(new Skip({ reason: gone.message }))),
|
|
190
191
|
),
|
|
191
192
|
});
|
|
193
|
+
|
|
194
|
+
// The GitHub events that can change what its trigger finds, so it wakes in CI
|
|
195
|
+
// rather than only on the schedule: an issue labelled to queue it, and a draft
|
|
196
|
+
// its author marks ready, which wakes an adopted one's run.
|
|
197
|
+
export default Events.declare(flow, {
|
|
198
|
+
events: [Events.issueLabelled, Events.readyForReview],
|
|
199
|
+
readsPhases: false,
|
|
200
|
+
});
|
package/flows/plan.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import {
|
|
16
16
|
Claims,
|
|
17
17
|
defineFlow,
|
|
18
|
+
Events,
|
|
18
19
|
GitHub,
|
|
19
20
|
Implement,
|
|
20
21
|
NeedsHuman,
|
|
@@ -134,7 +135,7 @@ const settings = Schema.Struct({
|
|
|
134
135
|
...Settings.Plans.fields,
|
|
135
136
|
});
|
|
136
137
|
|
|
137
|
-
|
|
138
|
+
const flow = defineFlow({
|
|
138
139
|
trigger,
|
|
139
140
|
gate: Implement.gate,
|
|
140
141
|
concurrency: 1,
|
|
@@ -144,3 +145,11 @@ export default defineFlow({
|
|
|
144
145
|
stillValid: Plan.stillValid,
|
|
145
146
|
workflow,
|
|
146
147
|
});
|
|
148
|
+
|
|
149
|
+
// The GitHub events that can change what its trigger finds, so it wakes in CI
|
|
150
|
+
// rather than only on the schedule: a spec labelled auto:plan, and a person's
|
|
151
|
+
// answer on one, which wakes its run.
|
|
152
|
+
export default Events.declare(flow, {
|
|
153
|
+
events: [Events.issueLabelled, Events.commentCreated],
|
|
154
|
+
readsPhases: false,
|
|
155
|
+
});
|
package/flows/post-merge.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
activity,
|
|
24
24
|
type CiFailedRun,
|
|
25
25
|
defineFlow,
|
|
26
|
+
Events,
|
|
26
27
|
GitHub,
|
|
27
28
|
type Json,
|
|
28
29
|
NeedsHuman,
|
|
@@ -560,7 +561,7 @@ const settings = Schema.Struct({
|
|
|
560
561
|
...Own.fields,
|
|
561
562
|
});
|
|
562
563
|
|
|
563
|
-
|
|
564
|
+
const flow = defineFlow({
|
|
564
565
|
trigger,
|
|
565
566
|
// No agent runs, so no usage gate. Watching is only polling, so several merges are watched at once.
|
|
566
567
|
concurrency: 4,
|
|
@@ -570,3 +571,7 @@ export default defineFlow({
|
|
|
570
571
|
settings,
|
|
571
572
|
workflow,
|
|
572
573
|
});
|
|
574
|
+
|
|
575
|
+
// The GitHub events that can change what its trigger finds, so it wakes in CI
|
|
576
|
+
// rather than only on the schedule: a pull request closing, merged among them.
|
|
577
|
+
export default Events.declare(flow, { events: [Events.pullRequestClosed], readsPhases: false });
|
package/flows/re-review.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import {
|
|
14
14
|
activity,
|
|
15
15
|
defineFlow,
|
|
16
|
+
Events,
|
|
16
17
|
GitHub,
|
|
17
18
|
PullRequest,
|
|
18
19
|
Repo,
|
|
@@ -27,22 +28,13 @@ import * as Effect from "effect/Effect";
|
|
|
27
28
|
import * as Option from "effect/Option";
|
|
28
29
|
import * as Schema from "effect/Schema";
|
|
29
30
|
|
|
30
|
-
// Pull requests
|
|
31
|
-
// per request, unless a person has them (auto:needs-human): asking
|
|
32
|
-
// during a dispute doesn't restart the loop. Each is routed by its
|
|
31
|
+
// Pull requests whose record says a review is asked again of this persona,
|
|
32
|
+
// one item per request, unless a person has them (auto:needs-human): asking
|
|
33
|
+
// again during a dispute doesn't restart the loop. Each is routed by its
|
|
34
|
+
// assignees and reviewers.
|
|
33
35
|
// And the runs holding a merge whose base branch is green again, to wake them.
|
|
34
36
|
const trigger = Effect.gen(function* () {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const asked = yield* Effect.forEach(
|
|
38
|
-
(yield* Review.reviewRequests).filter(
|
|
39
|
-
({ pull, reviewed }) => reviewed > 0 && !pull.labels.includes(labelNames.needsHuman),
|
|
40
|
-
),
|
|
41
|
-
({ pull, reviewed }) =>
|
|
42
|
-
Review.routed(pull, Review.reviewItem(pull, `pr-${pull.number}-review-${reviewed + 1}`)),
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
return [...asked, ...(yield* PullRequest.baseTurnedGreen)];
|
|
37
|
+
return [...(yield* Review.requestedAgain), ...(yield* PullRequest.baseTurnedGreen)];
|
|
46
38
|
}).pipe(reportAs("trigger"));
|
|
47
39
|
|
|
48
40
|
const MergeState = Schema.Struct({ mergeable_state: Schema.String });
|
|
@@ -200,7 +192,7 @@ const settings = Schema.Struct({
|
|
|
200
192
|
...Settings.MergeHold.fields,
|
|
201
193
|
});
|
|
202
194
|
|
|
203
|
-
|
|
195
|
+
const flow = defineFlow({
|
|
204
196
|
labels: Settings.declaredLabels,
|
|
205
197
|
settings,
|
|
206
198
|
trigger,
|
|
@@ -213,3 +205,12 @@ export default defineFlow({
|
|
|
213
205
|
stillValid: Review.stillValid,
|
|
214
206
|
workflow,
|
|
215
207
|
});
|
|
208
|
+
|
|
209
|
+
// The GitHub events that can change what its trigger finds, so it wakes in CI
|
|
210
|
+
// rather than only on the schedule: a review asked again, and CI finishing on a
|
|
211
|
+
// base, which wakes a run holding a merge. Its trigger reads each pull
|
|
212
|
+
// request's phase, so a phase event wakes it too.
|
|
213
|
+
export default Events.declare(flow, {
|
|
214
|
+
events: [Events.reviewRequestedAgain, Events.ciCompleted],
|
|
215
|
+
readsPhases: true,
|
|
216
|
+
});
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
activity,
|
|
34
34
|
Agent,
|
|
35
35
|
defineFlow,
|
|
36
|
+
Events,
|
|
36
37
|
GitHub,
|
|
37
38
|
Implement,
|
|
38
39
|
type Json,
|
|
@@ -49,7 +50,6 @@ import {
|
|
|
49
50
|
StepFailed,
|
|
50
51
|
type WorkItem,
|
|
51
52
|
} from "@chernabog/sdk";
|
|
52
|
-
import * as Arr from "effect/Array";
|
|
53
53
|
import * as Effect from "effect/Effect";
|
|
54
54
|
import * as Option from "effect/Option";
|
|
55
55
|
import * as Schema from "effect/Schema";
|
|
@@ -190,28 +190,6 @@ const resolve = (
|
|
|
190
190
|
Resolution,
|
|
191
191
|
);
|
|
192
192
|
|
|
193
|
-
// When the pull request's latest approval or request for changes is an
|
|
194
|
-
// approval, asks its reviewer to review again.
|
|
195
|
-
const askApproverAgain = (pullRequest: number) =>
|
|
196
|
-
activity(
|
|
197
|
-
"ask-approver-again",
|
|
198
|
-
Effect.gen(function* () {
|
|
199
|
-
const approval = Option.filter(
|
|
200
|
-
Arr.last(yield* Review.decisiveReviews(pullRequest)),
|
|
201
|
-
(review) => review.state === "APPROVED",
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
if (Option.isNone(approval)) {
|
|
205
|
-
return Option.none<string>();
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
yield* (yield* GitHub).requestReviewers(pullRequest, [approval.value.author]);
|
|
209
|
-
|
|
210
|
-
return Option.some(approval.value.author);
|
|
211
|
-
}),
|
|
212
|
-
Schema.Option(Schema.String),
|
|
213
|
-
);
|
|
214
|
-
|
|
215
193
|
// Resolves the conflict, after recording a squash- or rebase-merged layer
|
|
216
194
|
// below as already here when there is one. That record is a merge the flow
|
|
217
195
|
// makes (Stack.syncBase), and the agent resolves what it leaves in progress.
|
|
@@ -319,7 +297,7 @@ const unstick = (conflict: ConflictItem) =>
|
|
|
319
297
|
|
|
320
298
|
// An approval was of the code before the merge: its reviewer looks again,
|
|
321
299
|
// and re-review merges an auto:ship pull request it approves.
|
|
322
|
-
const approver = yield* askApproverAgain(conflict.pullRequest);
|
|
300
|
+
const approver = yield* Review.askApproverAgain(conflict.pullRequest);
|
|
323
301
|
|
|
324
302
|
return Option.match(approver, {
|
|
325
303
|
onNone: () =>
|
|
@@ -363,7 +341,7 @@ const settings = Schema.Struct({
|
|
|
363
341
|
...Settings.Ci.fields,
|
|
364
342
|
});
|
|
365
343
|
|
|
366
|
-
|
|
344
|
+
const flow = defineFlow({
|
|
367
345
|
labels: Settings.declaredLabels,
|
|
368
346
|
settings,
|
|
369
347
|
trigger,
|
|
@@ -375,3 +353,8 @@ export default defineFlow({
|
|
|
375
353
|
stillValid: Review.stillValid,
|
|
376
354
|
workflow,
|
|
377
355
|
});
|
|
356
|
+
|
|
357
|
+
// The GitHub events that can change what its trigger finds, so it wakes in CI
|
|
358
|
+
// rather than only on the schedule: a pull request closing, which may move the
|
|
359
|
+
// base under every other one.
|
|
360
|
+
export default Events.declare(flow, { events: [Events.baseMoved], readsPhases: false });
|
package/flows/review.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import {
|
|
15
15
|
activity,
|
|
16
16
|
defineFlow,
|
|
17
|
+
Events,
|
|
17
18
|
GitHub,
|
|
18
19
|
PullRequest,
|
|
19
20
|
Repo,
|
|
@@ -28,21 +29,19 @@ import * as Effect from "effect/Effect";
|
|
|
28
29
|
import * as Option from "effect/Option";
|
|
29
30
|
import * as Schema from "effect/Schema";
|
|
30
31
|
|
|
31
|
-
// Pull requests
|
|
32
|
-
//
|
|
32
|
+
// Pull requests whose record says they wait for their first review, asked of
|
|
33
|
+
// this persona, routed by their assignees and reviewers (one whose record
|
|
34
|
+
// GitHub disagrees with is held, for status to show why), those waiting on a reviewer
|
|
33
35
|
// no persona on this machine acts as, which status lists, and the runs
|
|
34
36
|
// holding a merge whose base branch is green again, to wake them. Reading
|
|
35
37
|
// review requests needs the persona's seat in the reviewer pool, which
|
|
36
38
|
// chernabog checks before the flow runs.
|
|
37
39
|
const trigger = Effect.gen(function* () {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
return [...mine, ...(yield* Review.waitingElsewhere), ...(yield* PullRequest.baseTurnedGreen)];
|
|
40
|
+
return [
|
|
41
|
+
...(yield* Review.requestedFirst),
|
|
42
|
+
...(yield* Review.waitingElsewhere),
|
|
43
|
+
...(yield* PullRequest.baseTurnedGreen),
|
|
44
|
+
];
|
|
46
45
|
}).pipe(reportAs("trigger"));
|
|
47
46
|
|
|
48
47
|
const MergeState = Schema.Struct({ mergeable_state: Schema.String });
|
|
@@ -129,7 +128,7 @@ const settings = Schema.Struct({
|
|
|
129
128
|
...Settings.MergeHold.fields,
|
|
130
129
|
});
|
|
131
130
|
|
|
132
|
-
|
|
131
|
+
const flow = defineFlow({
|
|
133
132
|
labels: Settings.declaredLabels,
|
|
134
133
|
settings,
|
|
135
134
|
trigger,
|
|
@@ -142,3 +141,12 @@ export default defineFlow({
|
|
|
142
141
|
stillValid: Review.stillValid,
|
|
143
142
|
workflow,
|
|
144
143
|
});
|
|
144
|
+
|
|
145
|
+
// The GitHub events that can change what its trigger finds, so it wakes in CI
|
|
146
|
+
// rather than only on the schedule: a review asked of someone, and CI finishing
|
|
147
|
+
// on a base, which wakes a run holding a merge. Its trigger reads each pull
|
|
148
|
+
// request's phase, so a phase event wakes it too.
|
|
149
|
+
export default Events.declare(flow, {
|
|
150
|
+
events: [Events.reviewRequested, Events.ciCompleted],
|
|
151
|
+
readsPhases: true,
|
|
152
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chernabog/recipes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
],
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"@chernabog/core": "^1.1.0",
|
|
19
|
-
"@chernabog/sdk": "
|
|
19
|
+
"@chernabog/sdk": ">=0.12.0 <0.13.0"
|
|
20
20
|
},
|
|
21
21
|
"chernabog": {
|
|
22
22
|
"recipes": {
|