@chernabog/recipes 0.5.0 → 0.6.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.
@@ -33,7 +33,11 @@ import * as Schema from "effect/Schema";
33
33
  // left moves the record there first.
34
34
  // A person has one labelled auto:needs-human, and a run of another flow one it
35
35
  // owns; both are left alone. Each is routed by its assignees and reviewers.
36
- const trigger = Review.changesToAddress.pipe(reportAs("trigger"));
36
+ // Then pull requests whose fix a CI job pushed, ending the job while its CI
37
+ // ran: each is held until the checks are green or red.
38
+ const trigger = Effect.gen(function* () {
39
+ return [...(yield* Review.changesToAddress), ...(yield* Review.fixesAwaitingCi)];
40
+ }).pipe(reportAs("trigger"));
37
41
 
38
42
  const answerReview = (address: Review.AddressItem) =>
39
43
  Effect.gen(function* () {
@@ -83,17 +87,55 @@ const answerReview = (address: Review.AddressItem) =>
83
87
  base: address.baseRef,
84
88
  withPerson: session.withPerson,
85
89
  });
90
+ // In a CI job, still-pending CI ends the job here, and the pull request
91
+ // comes back through Review.fixesAwaitingCi once CI finishes.
86
92
  yield* Implement.waitForCi(
87
93
  address.pullRequest,
88
94
  worktree,
89
95
  { ...session, branch: address.headRef, base: address.baseRef },
90
- { id: `review-${round}` },
96
+ { id: `review-${round}`, ...Review.parkOnPullRequest(address.pullRequest) },
91
97
  );
92
98
  yield* Review.askAgain(address.pullRequest, round, address.reviewer, outcome.summary);
93
99
 
94
100
  return `#${address.pullRequest}: addressed review ${round}; asked ${address.reviewer} to review again`;
95
101
  });
96
102
 
103
+ // The fix is pushed, and a CI job ended while its CI ran, which has finished:
104
+ // wait on from the round the record names (a fix of red CI resumes the
105
+ // author's session), then ask the reviewer again.
106
+ const resumeCi = (address: Review.AddressItem, resumed: Review.ResumingCi) =>
107
+ Effect.gen(function* () {
108
+ const review = yield* Review.changesAsked(address);
109
+ const round = review.round ?? 1;
110
+ const author = yield* Review.authorSession(address.pullRequest);
111
+
112
+ const session = {
113
+ sessionId: Option.some(author.sessionId),
114
+ adapter: Option.some(author.adapter),
115
+ withPerson: author.withPerson === true,
116
+ };
117
+
118
+ const worktree = yield* Review.prepareAuthorWorktree(address.headRef);
119
+ yield* Implement.waitForCi(
120
+ address.pullRequest,
121
+ worktree,
122
+ { ...session, branch: address.headRef, base: address.baseRef },
123
+ {
124
+ id: `review-${round}`,
125
+ ...Review.parkOnPullRequest(address.pullRequest),
126
+ firstRound: resumed.round,
127
+ },
128
+ );
129
+ yield* Review.askAgain(
130
+ address.pullRequest,
131
+ round,
132
+ address.reviewer,
133
+ "the commits pushed since that review. Their CI finished after the job that pushed them ended.",
134
+ );
135
+
136
+ return `#${address.pullRequest}: addressed review ${round}; asked ${address.reviewer} to review again`;
137
+ });
138
+
97
139
  const workflow = (item: WorkItem) =>
98
140
  Effect.gen(function* () {
99
141
  const address = yield* Review.addressItemOf(item);
@@ -103,7 +145,17 @@ const workflow = (item: WorkItem) =>
103
145
  // Anything that stops it hands the pull request to a person, unless it
104
146
  // closed meanwhile. It owns the pull request throughout, so no other run
105
147
  // pushes to the branch under it; one another run owns is skipped.
106
- return yield* answerReview(address).pipe(
148
+ const answering = Effect.gen(function* () {
149
+ const resumed = Review.resumingCi(address);
150
+
151
+ if (Option.isSome(resumed)) {
152
+ return yield* resumeCi(address, resumed.value);
153
+ }
154
+
155
+ return yield* answerReview(address);
156
+ });
157
+
158
+ return yield* answering.pipe(
107
159
  Effect.catchTags({
108
160
  NeedsHuman: (needsHuman) => toPerson(needsHuman.reason),
109
161
  StepFailed: (failed) => toPerson(`${failed.step}: ${failed.message}`),
@@ -144,6 +196,10 @@ const flow = defineFlow({
144
196
  });
145
197
 
146
198
  // 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
199
+ // rather than only on the schedule: a review submitted, and a finished CI run,
200
+ // which frees a fix a CI job left waiting on its CI. Its trigger reads each
148
201
  // pull request's phase, so a phase event wakes it too.
149
- export default Events.declare(flow, { events: [Events.reviewSubmitted], readsPhases: true });
202
+ export default Events.declare(flow, {
203
+ events: [Events.reviewSubmitted, Events.ciCompleted],
204
+ readsPhases: true,
205
+ });
@@ -41,7 +41,9 @@ import * as Effect from "effect/Effect";
41
41
  import * as Option from "effect/Option";
42
42
  import * as Schema from "effect/Schema";
43
43
 
44
- // Issues labelled auto:eligible, then ones labelled auto:ship, the automated
44
+ // Issues whose run a CI job left waiting on its pull request's CI first, to
45
+ // finish what's started: each is held until the checks are green or red.
46
+ // Then issues labelled auto:eligible, then ones labelled auto:ship, the automated
45
47
  // path, whose pull request chernabog merges once it's approved. Oldest first,
46
48
  // but a post-merge follow-up, the fix for red CI on the base, before the rest;
47
49
  // with a board, only those whose Status is its readyStatus. An issue another
@@ -59,8 +61,9 @@ const trigger = Effect.gen(function* () {
59
61
  (issue) => !eligible.some((queued) => queued.number === issue.number),
60
62
  );
61
63
 
62
- // A follow-up fixing red CI on the base goes first, ahead of other work.
64
+ // A follow-up fixing red CI on the base goes first, ahead of other new work.
63
65
  return [
66
+ ...(yield* Implement.awaitingCi),
64
67
  ...(yield* Implement.queued(Implement.followUpsFirst(eligible))),
65
68
  ...(yield* Implement.queued(Implement.followUpsFirst(shipping), Option.some(labelNames.ship))),
66
69
  ...(yield* Implement.readied),
@@ -121,6 +124,30 @@ const flow = defineFlow({
121
124
  const claimed = yield* Implement.claim(issue, { ...queued, adopt: true });
122
125
  const { base, branch } = claimed;
123
126
  const adoption = Option.fromUndefinedOr(claimed.adopted);
127
+ const resuming = Implement.resumingCi(item);
128
+
129
+ // A CI job ended while this issue's pull request's CI ran, and it has
130
+ // finished: wait on from the round the record names (a fix of red CI
131
+ // starts a session of its own), then hand off.
132
+ if (Option.isSome(resuming)) {
133
+ const waited = resuming.value;
134
+ pullRequest = Option.some(waited.pullRequest);
135
+
136
+ return yield* Effect.gen(function* () {
137
+ yield* Implement.waitForCiMaking(
138
+ waited.pullRequest,
139
+ Implement.prepareWorktree(branch, { base }),
140
+ { ...Implement.thisRunsSession, branch, base },
141
+ { ...Implement.parkOnIssue(issue), firstRound: waited.round },
142
+ );
143
+
144
+ return yield* Implement.handOff(
145
+ issue,
146
+ { number: waited.pullRequest, url: waited.url },
147
+ Implement.resumedOutcome,
148
+ );
149
+ }).pipe(Effect.catchTags(forPerson));
150
+ }
124
151
 
125
152
  if (Option.isSome(adoption)) {
126
153
  const adopted = adoption.value;
@@ -169,11 +196,14 @@ const flow = defineFlow({
169
196
  yield* Implement.push("push", worktree, branch, { base });
170
197
  const opened = yield* Implement.openPullRequest(issue, outcome, { ...queued, base });
171
198
  pullRequest = Option.some(opened.number);
172
- yield* Implement.waitForCi(opened.number, worktree, {
173
- ...Implement.thisRunsSession,
174
- branch,
175
- base,
176
- });
199
+ // In a CI job, still-pending CI ends the job here, and the item
200
+ // comes back through Implement.awaitingCi once CI finishes.
201
+ yield* Implement.waitForCi(
202
+ opened.number,
203
+ worktree,
204
+ { ...Implement.thisRunsSession, branch, base },
205
+ Implement.parkOnIssue(issue),
206
+ );
177
207
 
178
208
  return yield* Implement.handOff(issue, opened, outcome);
179
209
  }).pipe(Effect.catchTags(forPerson));
@@ -192,9 +222,11 @@ const flow = defineFlow({
192
222
  });
193
223
 
194
224
  // 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.
225
+ // rather than only on the schedule: an issue labelled to queue it, a draft
226
+ // its author marks ready, which wakes an adopted one's run, and a finished CI
227
+ // run, which frees an issue a CI job left waiting on its pull request's CI.
228
+ // Its trigger reads issues' phases for those, so a phase event wakes it too.
197
229
  export default Events.declare(flow, {
198
- events: [Events.issueLabelled, Events.readyForReview],
199
- readsPhases: false,
230
+ events: [Events.issueLabelled, Events.readyForReview, Events.ciCompleted],
231
+ readsPhases: true,
200
232
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chernabog/recipes",
3
- "version": "0.5.0",
3
+ "version": "0.6.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": ">=0.12.0 <0.13.0"
19
+ "@chernabog/sdk": ">=0.13.0 <0.14.0"
20
20
  },
21
21
  "chernabog": {
22
22
  "recipes": {