@chernabog/recipes 0.5.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 +76 -6
- package/flows/epic.ts +249 -78
- package/flows/human-initiated.ts +2 -1
- package/flows/implement.ts +76 -16
- 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
package/flows/post-merge.ts
CHANGED
|
@@ -5,28 +5,39 @@
|
|
|
5
5
|
// labelled auto:eligible, with the failed runs and the tail of their logs, so
|
|
6
6
|
// implement takes the fix on.
|
|
7
7
|
//
|
|
8
|
-
// Each pull request is watched once: the run's first step
|
|
9
|
-
//
|
|
10
|
-
// marker with the merge commit's sha, so a run that resumes after filing
|
|
8
|
+
// Each pull request is watched once: the run's first step records its
|
|
9
|
+
// watched phase, which the trigger reads, and comments on it that it is
|
|
10
|
+
// watching. The follow-up carries a marker with the merge commit's sha, so a run that resumes after filing
|
|
11
11
|
// finds it rather than filing another. A red merge of a follow-up's own fix
|
|
12
12
|
// goes to a person (auto:needs-human), not to another follow-up. And when CI
|
|
13
13
|
// was already red on the commit before the merge, the merge didn't break it,
|
|
14
14
|
// and nothing is filed.
|
|
15
15
|
//
|
|
16
|
+
// Push CI can take minutes or hours, and a run ends at every park, so a
|
|
17
|
+
// first reading still pending parks: the run records awaiting-merge-ci on
|
|
18
|
+
// the pull request, with the merge commit and when the watch began, and
|
|
19
|
+
// ends. The trigger offers it again once CI settles, or none started within
|
|
20
|
+
// noCiGrace, or ciTimeout passed, both counted from when the watch began.
|
|
21
|
+
// The run that takes it up reads CI once, records watched again, and goes on.
|
|
22
|
+
//
|
|
16
23
|
// This file is chernabog's post-merge recipe, and this repo's to change:
|
|
17
24
|
// `chernabog recipes diff` shows how it differs from the recipe's current
|
|
18
|
-
// version. The names of its steps ("
|
|
19
|
-
// "
|
|
20
|
-
//
|
|
25
|
+
// version. The names of its steps ("mark-watched", "watch-limits",
|
|
26
|
+
// "watch-since", "ci-<n>", "awaiting-merge-ci", "watch-ended",
|
|
27
|
+
// "ci-before-merge", "closes-follow-up", "failure-details", "file-follow-up")
|
|
28
|
+
// are the keys a run in flight resumes by, so renaming one restarts that step.
|
|
21
29
|
|
|
22
30
|
import {
|
|
23
31
|
activity,
|
|
32
|
+
Blocks,
|
|
24
33
|
type CiFailedRun,
|
|
25
34
|
defineFlow,
|
|
26
35
|
Events,
|
|
27
36
|
GitHub,
|
|
28
37
|
type Json,
|
|
29
38
|
NeedsHuman,
|
|
39
|
+
type PhaseRecord,
|
|
40
|
+
Phases,
|
|
30
41
|
PullRequest,
|
|
31
42
|
Repo,
|
|
32
43
|
reportAs,
|
|
@@ -87,8 +98,33 @@ const marker = <A>(name: string, schema: Schema.Codec<A, Json>) => {
|
|
|
87
98
|
};
|
|
88
99
|
};
|
|
89
100
|
|
|
90
|
-
|
|
91
|
-
|
|
101
|
+
const WATCHED = Phases.PHASES.pullRequest.watched;
|
|
102
|
+
|
|
103
|
+
// Records that a run is watching the merge: the pull request's watched phase,
|
|
104
|
+
// carrying the merge commit, from whatever phase its review left.
|
|
105
|
+
const markWatched = (merged: MergedItem) =>
|
|
106
|
+
activity(
|
|
107
|
+
"mark-watched",
|
|
108
|
+
Phases.record(Phases.pullRequestItem(merged.pullRequest), WATCHED, { sha: merged.mergeSha }),
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const AWAITING = Phases.PHASES.pullRequest.awaitingMergeCi;
|
|
112
|
+
|
|
113
|
+
// What a parked watch's record carries: the merge commit, and when the watch
|
|
114
|
+
// began, which noCiGrace and ciTimeout count from across the runs that take
|
|
115
|
+
// it up. The record's `at` won't do for that: a record written afresh has a
|
|
116
|
+
// new one.
|
|
117
|
+
const ParkedWatch = Schema.Struct({ sha: Schema.String, since: Schema.String });
|
|
118
|
+
|
|
119
|
+
// When the watch of `sha` that `found` parked began; none for any other record.
|
|
120
|
+
const parkedSince = (found: PhaseRecord, sha: string) =>
|
|
121
|
+
Option.flatMap(
|
|
122
|
+
Option.filter(
|
|
123
|
+
Option.flatMap(found.data, Schema.decodeUnknownOption(ParkedWatch)),
|
|
124
|
+
(watch) => found.phase === AWAITING && watch.sha === sha,
|
|
125
|
+
),
|
|
126
|
+
(watch) => DateTime.make(watch.since),
|
|
127
|
+
);
|
|
92
128
|
|
|
93
129
|
// On a follow-up issue: the merge commit whose red CI it is for.
|
|
94
130
|
const followUpMarker = marker(
|
|
@@ -104,6 +140,8 @@ const MergedItem = Schema.Struct({
|
|
|
104
140
|
baseRef: Schema.String,
|
|
105
141
|
// The issue the pull request closes, when it names one.
|
|
106
142
|
issue: Schema.optionalKey(Schema.Finite),
|
|
143
|
+
// A watch a run parked, which this run takes up.
|
|
144
|
+
resumeWatch: Schema.optionalKey(Schema.Literal(true)),
|
|
107
145
|
});
|
|
108
146
|
|
|
109
147
|
type MergedItem = typeof MergedItem.Type;
|
|
@@ -150,63 +188,6 @@ const isRecent = (mergedAt: string, now: DateTime.Utc) =>
|
|
|
150
188
|
),
|
|
151
189
|
});
|
|
152
190
|
|
|
153
|
-
// Pull requests this persona wrote that merged into the base branch lately,
|
|
154
|
-
// and that no run has watched yet.
|
|
155
|
-
const trigger = Effect.gen(function* () {
|
|
156
|
-
const github = yield* GitHub;
|
|
157
|
-
const repo = yield* Repo;
|
|
158
|
-
const base = yield* Settings.base;
|
|
159
|
-
const me = yield* github.login;
|
|
160
|
-
const now = yield* DateTime.now;
|
|
161
|
-
const items: Array<WorkItem> = [];
|
|
162
|
-
|
|
163
|
-
const closed = yield* github
|
|
164
|
-
.request(
|
|
165
|
-
"GET",
|
|
166
|
-
`/repos/${repo.slug}/pulls?state=closed&sort=updated&direction=desc&per_page=30`,
|
|
167
|
-
Option.none(),
|
|
168
|
-
)
|
|
169
|
-
.pipe(Effect.flatMap(decodeIn(ClosedPulls, "trigger")));
|
|
170
|
-
|
|
171
|
-
for (const pull of closed) {
|
|
172
|
-
if (
|
|
173
|
-
!sameLogin(pull.user.login, me) ||
|
|
174
|
-
pull.base.ref !== base ||
|
|
175
|
-
Option.isNone(pull.merge_commit_sha) ||
|
|
176
|
-
!Option.exists(pull.merged_at, (at) => isRecent(at, now))
|
|
177
|
-
) {
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const comments = yield* github.trustedComments(pull.number);
|
|
182
|
-
|
|
183
|
-
if (comments.some((comment) => Option.isSome(watchedMarker.read(comment.body)))) {
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const issue = closedIssue(
|
|
188
|
-
Option.getOrElse(pull.body, () => ""),
|
|
189
|
-
pull.head.ref,
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
items.push({
|
|
193
|
-
key: `merged-${pull.number}`,
|
|
194
|
-
title: pull.title,
|
|
195
|
-
url: pull.html_url,
|
|
196
|
-
data: {
|
|
197
|
-
pullRequest: pull.number,
|
|
198
|
-
url: pull.html_url,
|
|
199
|
-
title: pull.title,
|
|
200
|
-
mergeSha: pull.merge_commit_sha.value,
|
|
201
|
-
baseRef: pull.base.ref,
|
|
202
|
-
...Option.match(issue, { onNone: () => ({}), onSome: (number) => ({ issue: number }) }),
|
|
203
|
-
},
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return items;
|
|
208
|
-
}).pipe(reportAs("trigger"));
|
|
209
|
-
|
|
210
191
|
const FailedRun = Schema.Struct({
|
|
211
192
|
name: Schema.String,
|
|
212
193
|
url: Schema.String,
|
|
@@ -256,32 +237,126 @@ const WatchLimits = Schema.Struct({ grace: Schema.Duration, timeout: Schema.Dura
|
|
|
256
237
|
|
|
257
238
|
type WatchLimits = typeof WatchLimits.Type;
|
|
258
239
|
|
|
240
|
+
// The no-CI grace and the CI timeout, from the flow's settings.
|
|
241
|
+
const limitsNow = Effect.gen(function* () {
|
|
242
|
+
const own = yield* Settings.read(Own);
|
|
243
|
+
const ci = yield* Settings.ci;
|
|
244
|
+
|
|
245
|
+
return {
|
|
246
|
+
grace: Option.getOrElse(
|
|
247
|
+
Option.flatMap(Option.fromUndefinedOr(own.noCiGrace), durationOf),
|
|
248
|
+
() => NO_CI_GRACE,
|
|
249
|
+
),
|
|
250
|
+
timeout: ci.timeout,
|
|
251
|
+
};
|
|
252
|
+
});
|
|
253
|
+
|
|
259
254
|
// The no-CI grace and the CI timeout, read once, so a replay decides the same.
|
|
260
|
-
const watchLimits = activity(
|
|
261
|
-
|
|
255
|
+
const watchLimits = activity("watch-limits", limitsNow, WatchLimits);
|
|
256
|
+
|
|
257
|
+
// When the watch began, as ISO text, and how long it had gone when this run
|
|
258
|
+
// first read CI: no time for a watch this run began, and since the record's
|
|
259
|
+
// `since` for one it takes up from a park. Read once, so a replay decides the
|
|
260
|
+
// same.
|
|
261
|
+
const WatchClock = Schema.Struct({ since: Schema.String, waited: Schema.Duration });
|
|
262
|
+
|
|
263
|
+
const watchClock = (merged: MergedItem) =>
|
|
264
|
+
activity(
|
|
265
|
+
"watch-since",
|
|
266
|
+
Effect.gen(function* () {
|
|
267
|
+
const now = yield* DateTime.now;
|
|
268
|
+
const found = yield* Phases.current(Phases.pullRequestItem(merged.pullRequest));
|
|
269
|
+
|
|
270
|
+
return Option.match(
|
|
271
|
+
Option.flatMap(found, (parked) => parkedSince(parked, merged.mergeSha)),
|
|
272
|
+
{
|
|
273
|
+
onNone: () => ({ since: DateTime.formatIso(now), waited: Duration.zero }),
|
|
274
|
+
onSome: (began) => ({
|
|
275
|
+
since: DateTime.formatIso(began),
|
|
276
|
+
waited: Duration.millis(
|
|
277
|
+
Math.max(0, DateTime.toEpochMillis(now) - DateTime.toEpochMillis(began)),
|
|
278
|
+
),
|
|
279
|
+
}),
|
|
280
|
+
},
|
|
281
|
+
);
|
|
282
|
+
}),
|
|
283
|
+
WatchClock,
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
// The watch is over: a pull request whose watch parked is recorded watched
|
|
287
|
+
// again, which the trigger takes for finished, by this run, not the one that
|
|
288
|
+
// parked. One whose watch never parked holds watched already.
|
|
289
|
+
const endWatch = (merged: MergedItem) =>
|
|
290
|
+
activity(
|
|
291
|
+
"watch-ended",
|
|
292
|
+
Effect.gen(function* () {
|
|
293
|
+
const item = Phases.pullRequestItem(merged.pullRequest);
|
|
294
|
+
const found = yield* Phases.current(item);
|
|
295
|
+
|
|
296
|
+
if (Option.isSome(Option.flatMap(found, (parked) => parkedSince(parked, merged.mergeSha)))) {
|
|
297
|
+
yield* Phases.record(item, WATCHED, { sha: merged.mergeSha });
|
|
298
|
+
}
|
|
299
|
+
}),
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
// Records that the watch waits on push CI, with the merge commit and when the
|
|
303
|
+
// watch began, and parks, which ends the run (Phases.park). A run that takes
|
|
304
|
+
// up a parked watch and parks again keeps the record it found, `since` and
|
|
305
|
+
// all. Nothing sends the signal: the run that takes the watch up is a new one.
|
|
306
|
+
const parkWatch = (merged: MergedItem, since: string) =>
|
|
307
|
+
Phases.park(
|
|
308
|
+
{
|
|
309
|
+
step: "awaiting-merge-ci",
|
|
310
|
+
item: Phases.pullRequestItem(merged.pullRequest),
|
|
311
|
+
phase: AWAITING,
|
|
312
|
+
data: { sha: merged.mergeSha, since },
|
|
313
|
+
},
|
|
314
|
+
["merge-ci-settled"],
|
|
315
|
+
"merge-ci",
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
// Why a parked watch of `sha` can't be taken up yet, for the trigger to hold
|
|
319
|
+
// it with: push CI still pending, with a run to wait on inside ciTimeout, or
|
|
320
|
+
// none yet inside noCiGrace, both counted from `since`. None once a run that
|
|
321
|
+
// takes it up goes on: CI green or red, no CI within the grace, or time up.
|
|
322
|
+
const watchHeld = (sha: string, since: DateTime.Utc, limits: WatchLimits) =>
|
|
262
323
|
Effect.gen(function* () {
|
|
263
|
-
const
|
|
264
|
-
const
|
|
324
|
+
const report = yield* (yield* GitHub).commitCiState(sha, { event: "push" });
|
|
325
|
+
const now = yield* DateTime.now;
|
|
265
326
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
};
|
|
273
|
-
}),
|
|
274
|
-
WatchLimits,
|
|
275
|
-
);
|
|
327
|
+
if (report.state !== "pending") {
|
|
328
|
+
return Option.none<string>();
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const waited = Duration.millis(DateTime.toEpochMillis(now) - DateTime.toEpochMillis(since));
|
|
332
|
+
const timedOut = Duration.isGreaterThanOrEqualTo(waited, limits.timeout);
|
|
276
333
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
334
|
+
const noCi =
|
|
335
|
+
report.waitingOn.length === 0 && Duration.isGreaterThanOrEqualTo(waited, limits.grace);
|
|
336
|
+
|
|
337
|
+
if (timedOut || noCi) {
|
|
338
|
+
return Option.none<string>();
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return Option.some(
|
|
342
|
+
Arr.match(report.waitingOn, {
|
|
343
|
+
onEmpty: () => `waits for push CI to start on ${sha.slice(0, 7)}`,
|
|
344
|
+
onNonEmpty: (names) => `waits on push CI on ${sha.slice(0, 7)}: ${names.join(", ")}`,
|
|
345
|
+
}),
|
|
346
|
+
);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// Watches the merge commit's push CI until it stops pending. No run within
|
|
350
|
+
// the noCiGrace setting is no CI for this push; still pending after the
|
|
351
|
+
// ciTimeout setting is a person's to look at; both count from when the watch
|
|
352
|
+
// began, across the runs that take it up. A first reading still pending
|
|
353
|
+
// parks (parkWatch), and the trigger offers the watch again once it settles.
|
|
280
354
|
const awaitMergeCi = (merged: MergedItem, limits: WatchLimits) =>
|
|
281
355
|
Effect.gen(function* () {
|
|
282
356
|
const grace = Duration.toMillis(limits.grace);
|
|
283
357
|
const timeout = Duration.toMillis(limits.timeout);
|
|
284
358
|
const every = Duration.toMillis(CI_POLL);
|
|
359
|
+
const clock = yield* watchClock(merged);
|
|
285
360
|
|
|
286
361
|
for (let poll = 1; ; poll++) {
|
|
287
362
|
if (poll > 1) {
|
|
@@ -291,23 +366,117 @@ const awaitMergeCi = (merged: MergedItem, limits: WatchLimits) =>
|
|
|
291
366
|
const reading = yield* readMergeCi(merged.mergeSha, poll);
|
|
292
367
|
|
|
293
368
|
if (reading.state !== "pending") {
|
|
369
|
+
yield* endWatch(merged);
|
|
370
|
+
|
|
294
371
|
return reading;
|
|
295
372
|
}
|
|
296
373
|
|
|
297
|
-
const waited = (poll - 1) * every;
|
|
374
|
+
const waited = Duration.toMillis(clock.waited) + (poll - 1) * every;
|
|
298
375
|
|
|
299
376
|
if (reading.waitingOn.length === 0 && waited >= grace) {
|
|
377
|
+
yield* endWatch(merged);
|
|
378
|
+
|
|
300
379
|
return { state: "none" as const };
|
|
301
380
|
}
|
|
302
381
|
|
|
303
382
|
if (waited >= timeout) {
|
|
383
|
+
yield* endWatch(merged);
|
|
384
|
+
|
|
304
385
|
return yield* new NeedsHuman({
|
|
305
386
|
reason: `CI on ${merged.baseRef} at ${merged.mergeSha} stayed pending for ${Duration.format(limits.timeout)} after #${merged.pullRequest} merged`,
|
|
306
387
|
});
|
|
307
388
|
}
|
|
389
|
+
|
|
390
|
+
if (poll === 1) {
|
|
391
|
+
yield* parkWatch(merged, clock.since);
|
|
392
|
+
}
|
|
308
393
|
}
|
|
309
394
|
});
|
|
310
395
|
|
|
396
|
+
// Pull requests this persona wrote that merged into the base branch lately,
|
|
397
|
+
// and that no run has watched yet: none recorded watched, nor, from before
|
|
398
|
+
// records, carries the marker. And those whose watch a run parked
|
|
399
|
+
// (awaiting-merge-ci), as work a run may start, which takes the watch up:
|
|
400
|
+
// held, with why, while push CI on the merge commit is still pending and
|
|
401
|
+
// the watch has time left.
|
|
402
|
+
const trigger = Effect.gen(function* () {
|
|
403
|
+
const github = yield* GitHub;
|
|
404
|
+
const repo = yield* Repo;
|
|
405
|
+
const base = yield* Settings.base;
|
|
406
|
+
const me = yield* github.login;
|
|
407
|
+
const now = yield* DateTime.now;
|
|
408
|
+
const all = yield* Phases.records;
|
|
409
|
+
const items: Array<WorkItem> = [];
|
|
410
|
+
|
|
411
|
+
const closed = yield* github
|
|
412
|
+
.request(
|
|
413
|
+
"GET",
|
|
414
|
+
`/repos/${repo.slug}/pulls?state=closed&sort=updated&direction=desc&per_page=30`,
|
|
415
|
+
Option.none(),
|
|
416
|
+
)
|
|
417
|
+
.pipe(Effect.flatMap(decodeIn(ClosedPulls, "trigger")));
|
|
418
|
+
|
|
419
|
+
for (const pull of closed) {
|
|
420
|
+
if (
|
|
421
|
+
!sameLogin(pull.user.login, me) ||
|
|
422
|
+
pull.base.ref !== base ||
|
|
423
|
+
Option.isNone(pull.merge_commit_sha) ||
|
|
424
|
+
!Option.exists(pull.merged_at, (at) => isRecent(at, now))
|
|
425
|
+
) {
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const sha = pull.merge_commit_sha.value;
|
|
430
|
+
const recorded = Phases.recordOf(all, Phases.pullRequestItem(pull.number));
|
|
431
|
+
|
|
432
|
+
if (Option.exists(recorded, (found) => found.phase === WATCHED)) {
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const parked = Option.flatMap(recorded, (found) => parkedSince(found, sha));
|
|
437
|
+
|
|
438
|
+
const issue = closedIssue(
|
|
439
|
+
Option.getOrElse(pull.body, () => ""),
|
|
440
|
+
pull.head.ref,
|
|
441
|
+
);
|
|
442
|
+
|
|
443
|
+
const item: WorkItem = {
|
|
444
|
+
key: `merged-${pull.number}`,
|
|
445
|
+
title: pull.title,
|
|
446
|
+
url: pull.html_url,
|
|
447
|
+
data: {
|
|
448
|
+
pullRequest: pull.number,
|
|
449
|
+
url: pull.html_url,
|
|
450
|
+
title: pull.title,
|
|
451
|
+
mergeSha: sha,
|
|
452
|
+
baseRef: pull.base.ref,
|
|
453
|
+
...Option.match(issue, { onNone: () => ({}), onSome: (number) => ({ issue: number }) }),
|
|
454
|
+
...Option.match(parked, { onNone: () => ({}), onSome: () => ({ resumeWatch: true }) }),
|
|
455
|
+
},
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
if (Option.isNone(parked)) {
|
|
459
|
+
items.push(item);
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const held = yield* watchHeld(sha, parked.value, yield* limitsNow);
|
|
464
|
+
|
|
465
|
+
items.push(
|
|
466
|
+
Option.match(held, {
|
|
467
|
+
onNone: () => item,
|
|
468
|
+
onSome: (why): WorkItem => ({ ...item, held: why }),
|
|
469
|
+
}),
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
return items;
|
|
474
|
+
}).pipe(
|
|
475
|
+
// Every record it reads is checked first, as its document's are (ADR 21, decision 5).
|
|
476
|
+
Blocks.checked("pr.mergedRecently", "merged.awaitCi"),
|
|
477
|
+
reportAs("trigger"),
|
|
478
|
+
);
|
|
479
|
+
|
|
311
480
|
const Parents = Schema.Struct({ parents: Schema.Array(Schema.Struct({ sha: Schema.String })) });
|
|
312
481
|
|
|
313
482
|
// Whether push CI was already red on the merge commit's first parent, the
|
|
@@ -472,26 +641,37 @@ const fileFollowUp = (merged: MergedItem, body: string, fixed: Option.Option<num
|
|
|
472
641
|
activity(
|
|
473
642
|
"file-follow-up",
|
|
474
643
|
Effect.gen(function* () {
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
644
|
+
const filed = yield* Option.match(yield* filedFor(merged.mergeSha), {
|
|
645
|
+
onSome: Effect.succeed,
|
|
646
|
+
onNone: () =>
|
|
647
|
+
Effect.gen(function* () {
|
|
648
|
+
const labelNames = yield* Settings.labels;
|
|
649
|
+
|
|
650
|
+
const issue = yield* (yield* GitHub).createIssue({
|
|
651
|
+
title: `CI is red on ${merged.baseRef} after #${merged.pullRequest} merged`,
|
|
652
|
+
body,
|
|
653
|
+
// Queued, unless it is a person's: then its with-person
|
|
654
|
+
// record, below, projects auto:needs-human.
|
|
655
|
+
labels: Option.match(fixed, {
|
|
656
|
+
onNone: () => [labelNames.eligible],
|
|
657
|
+
onSome: () => [],
|
|
658
|
+
}),
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
return issue.number;
|
|
490
662
|
}),
|
|
491
|
-
],
|
|
492
663
|
});
|
|
493
664
|
|
|
494
|
-
|
|
665
|
+
// A follow-up's own fix that broke CI again is a person's to fix: with
|
|
666
|
+
// a person from the start (ADR 21, decision 1).
|
|
667
|
+
for (const fixing of Option.toArray(fixed)) {
|
|
668
|
+
yield* Phases.recordWithPerson(
|
|
669
|
+
Phases.issueItem(filed),
|
|
670
|
+
`CI is red on ${merged.baseRef} again after #${merged.pullRequest}, the fix of #${fixing}, merged`,
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
return filed;
|
|
495
675
|
}),
|
|
496
676
|
Schema.Finite,
|
|
497
677
|
);
|
|
@@ -502,10 +682,15 @@ const watch = (merged: MergedItem) =>
|
|
|
502
682
|
const short = merged.mergeSha.slice(0, 7);
|
|
503
683
|
const pr = `#${merged.pullRequest}`;
|
|
504
684
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
685
|
+
// A run that takes up a parked watch has marked it and commented already.
|
|
686
|
+
if (merged.resumeWatch !== true) {
|
|
687
|
+
yield* markWatched(merged);
|
|
688
|
+
|
|
689
|
+
yield* PullRequest.comment(
|
|
690
|
+
merged.pullRequest,
|
|
691
|
+
`Watching CI on \`${merged.baseRef}\` at ${merged.mergeSha}, this pull request's merge commit.`,
|
|
692
|
+
);
|
|
693
|
+
}
|
|
509
694
|
|
|
510
695
|
const limits = yield* watchLimits;
|
|
511
696
|
const ci = yield* awaitMergeCi(merged, limits);
|
|
@@ -563,7 +748,7 @@ const settings = Schema.Struct({
|
|
|
563
748
|
|
|
564
749
|
const flow = defineFlow({
|
|
565
750
|
trigger,
|
|
566
|
-
// No agent runs, so no usage gate. Watching is only
|
|
751
|
+
// No agent runs, so no usage gate. Watching is only reading CI, so several merges are watched at once.
|
|
567
752
|
concurrency: 4,
|
|
568
753
|
// Its trigger finds only pull requests this persona wrote.
|
|
569
754
|
ownWork: true,
|
|
@@ -573,5 +758,12 @@ const flow = defineFlow({
|
|
|
573
758
|
});
|
|
574
759
|
|
|
575
760
|
// 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
|
-
|
|
761
|
+
// rather than only on the schedule: a pull request closing, merged among them,
|
|
762
|
+
// and push CI finishing on the default branch, which settles a parked watch:
|
|
763
|
+
// the plan looks only at the pull request whose record names that merge
|
|
764
|
+
// commit. Only its own runs record the phases its trigger reads, and a park
|
|
765
|
+
// settles nothing, so a phase event doesn't wake it.
|
|
766
|
+
export default Events.declare(flow, {
|
|
767
|
+
events: [Events.pullRequestClosed, Events.mergeCiCompleted],
|
|
768
|
+
readsPhases: false,
|
|
769
|
+
});
|
package/flows/re-review.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import {
|
|
14
14
|
activity,
|
|
15
|
+
Blocks,
|
|
15
16
|
defineFlow,
|
|
16
17
|
Events,
|
|
17
18
|
GitHub,
|
|
@@ -32,10 +33,20 @@ import * as Schema from "effect/Schema";
|
|
|
32
33
|
// one item per request, unless a person has them (auto:needs-human): asking
|
|
33
34
|
// again during a dispute doesn't restart the loop. Each is routed by its
|
|
34
35
|
// assignees and reviewers.
|
|
35
|
-
// And the
|
|
36
|
+
// And the merges its runs hold whose base branch is green again, or whose
|
|
37
|
+
// hold has lasted past mergeHoldTimeout: they wake a run still parked on one,
|
|
38
|
+
// or a CI job's ended one is taken up by a new run, from the pull request's
|
|
39
|
+
// record. A re-review's work item is keyed pr-N-<more>; review's is pr-N.
|
|
36
40
|
const trigger = Effect.gen(function* () {
|
|
37
|
-
return [
|
|
38
|
-
|
|
41
|
+
return [
|
|
42
|
+
...(yield* Review.requestedAgain),
|
|
43
|
+
...(yield* PullRequest.heldMerges((key, pullRequest) => key.startsWith(`pr-${pullRequest}-`))),
|
|
44
|
+
];
|
|
45
|
+
}).pipe(
|
|
46
|
+
// Every record it reads is checked first, as its document's are (ADR 21, decision 5).
|
|
47
|
+
Blocks.checked("review.requestedAgain", "pr.land"),
|
|
48
|
+
reportAs("trigger"),
|
|
49
|
+
);
|
|
39
50
|
|
|
40
51
|
const MergeState = Schema.Struct({ mergeable_state: Schema.String });
|
|
41
52
|
|
|
@@ -133,7 +144,18 @@ const reReviews = (count: number) => {
|
|
|
133
144
|
const workflow = (item: WorkItem) =>
|
|
134
145
|
Effect.gen(function* () {
|
|
135
146
|
const { rounds } = yield* Settings.reviewers;
|
|
147
|
+
// A merge an earlier run held, which a CI job ended on: it was approved, so merge it.
|
|
148
|
+
const held = PullRequest.resumingMerge(item);
|
|
149
|
+
|
|
150
|
+
if (Option.isSome(held)) {
|
|
151
|
+
return yield* mergeIfShipping(held.value);
|
|
152
|
+
}
|
|
153
|
+
|
|
136
154
|
const { pullRequest } = yield* Review.pullRequestOf(item);
|
|
155
|
+
|
|
156
|
+
// One that changes a behavior spec no person approved goes to a person, unreviewed.
|
|
157
|
+
yield* PullRequest.specGuard(pullRequest);
|
|
158
|
+
|
|
137
159
|
const earlier = yield* Review.latestOwnReview(pullRequest);
|
|
138
160
|
|
|
139
161
|
// No review of its own to resume, as one posted before markers named their reviewer: review afresh.
|