@chernabog/sdk 0.11.1 → 0.13.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/src/review.ts CHANGED
@@ -18,6 +18,7 @@ import {
18
18
  latestMarker,
19
19
  Machine,
20
20
  NeedsHuman,
21
+ type PhaseRecord,
21
22
  type PullRequest,
22
23
  Repo,
23
24
  ReviewerSeat,
@@ -34,12 +35,14 @@ import {
34
35
  type WorkItem,
35
36
  Worktree,
36
37
  } from "@chernabog/core";
38
+ import * as Arr from "effect/Array";
37
39
  import * as Effect from "effect/Effect";
38
40
  import * as Option from "effect/Option";
39
41
  import * as Schema from "effect/Schema";
40
42
 
41
43
  import { RECHECK } from "./default-prompts.ts";
42
- import { ADOPTED_LABEL, sessionIdFor } from "./implement.ts";
44
+ import { ADOPTED_LABEL, type CiWait, sessionIdFor, waitingOnCi } from "./implement.ts";
45
+ import * as Phases from "./phases.ts";
43
46
  import { renderPrompt, renderPromptOr } from "./prompt.ts";
44
47
  import * as PullRequestSteps from "./pull-request.ts";
45
48
  import * as Routing from "./routing.ts";
@@ -115,13 +118,23 @@ const sameLogin = (left: string, right: string) => left.toLowerCase() === right.
115
118
  // flow that uses it, or any block that reviews, requires ReviewerSeat.
116
119
  export const reviewerLogin = ReviewerSeat.use((seat) => seat.login);
117
120
 
121
+ // An open pull request that asks this persona for a review: how many reviews
122
+ // it has submitted on it so far, and the pull request's record, none for one
123
+ // with no phase recorded yet.
124
+ export type ReviewRequest = {
125
+ readonly pull: PullRequest;
126
+ readonly reviewed: number;
127
+ readonly record: Option.Option<PhaseRecord>;
128
+ };
129
+
118
130
  // Open pull requests that ask this persona for a review, each with how many
119
- // reviews it has submitted on it so far. One a run of another flow owns is
120
- // left out. It requires the persona's seat in the reviewer pool.
131
+ // reviews it has submitted on it so far and its record. One a run of another
132
+ // flow owns is left out. It requires the persona's seat in the reviewer pool.
121
133
  export const reviewRequests = Effect.gen(function* () {
122
134
  const github = yield* GitHub;
123
135
  const me = yield* reviewerLogin;
124
- const found: Array<{ readonly pull: PullRequest; readonly reviewed: number }> = [];
136
+ const all = yield* Phases.records;
137
+ const found: Array<ReviewRequest> = [];
125
138
 
126
139
  for (const pull of yield* github.openPullRequests) {
127
140
  if (!pull.requestedReviewers.some((login) => sameLogin(login, me))) {
@@ -137,12 +150,159 @@ export const reviewRequests = Effect.gen(function* () {
137
150
  reviewed: (yield* github.reviews(pull.number)).filter((review) =>
138
151
  sameLogin(review.author, me),
139
152
  ).length,
153
+ record: Phases.recordOf(all, Phases.pullRequestItem(pull.number)),
140
154
  });
141
155
  }
142
156
 
143
157
  return found;
144
158
  });
145
159
 
160
+ // What a review request asks of this persona, by the pull request's phase:
161
+ // its first review (review's), a review again (re-review's), one whose
162
+ // record moves on to review-asked-again first, or a record GitHub disagrees
163
+ // with, which status shows rather than starting either.
164
+ type Asked =
165
+ | { readonly kind: "first" }
166
+ | { readonly kind: "again"; readonly record: Option.Option<PhaseRecord> }
167
+ | { readonly kind: "reconcile"; readonly record: PhaseRecord }
168
+ | { readonly kind: "disagrees"; readonly reason: string };
169
+
170
+ const P = Phases.PHASES.pullRequest;
171
+
172
+ // Today's inference, for a pull request with no record: see askedOf.
173
+ const legacyAsked = (request: ReviewRequest): Asked => {
174
+ if (request.reviewed === 0) {
175
+ return { kind: "first" };
176
+ }
177
+
178
+ return { kind: "again", record: Option.none() };
179
+ };
180
+
181
+ // A pull request with a record is read by its phase, not by how many times
182
+ // this persona reviewed it. Migration: one with no record, such as one
183
+ // handed off before phases were recorded, or one a person opened, falls back
184
+ // to the review count (legacyAsked). Drop the count a release after phases
185
+ // became the record, keeping "first" for an item with none.
186
+ const askedOf = (request: ReviewRequest, me: string): Asked =>
187
+ Option.match(request.record, {
188
+ onNone: () => legacyAsked(request),
189
+ onSome: (found): Asked => {
190
+ if (found.phase === P.reviewAskedAgain) {
191
+ return { kind: "again", record: Option.some(found) };
192
+ }
193
+
194
+ // Waiting on a first review, or a person's turn, then a review asked of
195
+ // this persona: its first, or, when it has reviewed already, again. An
196
+ // adopted pull request it reviewed before the hand-off is one.
197
+ if (
198
+ Phases.holds(found, [P.reviewAsked, P.draft, P.readyForPerson]) &&
199
+ request.reviewed === 0
200
+ ) {
201
+ return { kind: "first" };
202
+ }
203
+
204
+ if (
205
+ Phases.holds(found, [P.reviewAsked, P.changesAsked, P.approved, P.draft, P.readyForPerson])
206
+ ) {
207
+ return { kind: "reconcile", record: found };
208
+ }
209
+
210
+ return {
211
+ kind: "disagrees",
212
+ reason: `its record says ${found.phase}, but GitHub asks ${me} for a review`,
213
+ };
214
+ },
215
+ });
216
+
217
+ // review.requested's items: open pull requests that ask this persona for its
218
+ // first review, routed by their assignees and reviewers, as `pr-7`. One whose
219
+ // record GitHub disagrees with is held, with why, for status to show.
220
+ export const requestedFirst = Effect.gen(function* () {
221
+ const me = yield* reviewerLogin;
222
+ const items: Array<WorkItem> = [];
223
+
224
+ for (const request of yield* reviewRequests) {
225
+ const asked = askedOf(request, me);
226
+ const item = reviewItem(request.pull, `pr-${request.pull.number}`);
227
+
228
+ if (asked.kind === "first") {
229
+ items.push(yield* routed(request.pull, item));
230
+ }
231
+
232
+ if (asked.kind === "disagrees") {
233
+ items.push({ ...item, held: `#${request.pull.number}: ${asked.reason}` });
234
+ }
235
+ }
236
+
237
+ return items;
238
+ });
239
+
240
+ // Who moves a record from what a source reads on GitHub, outside any run.
241
+ const observer = (source: string) => `observer:${source}`;
242
+
243
+ // The key a request to review again runs under: the record it reads, or the
244
+ // one reconciling moves it to; the review count for a pull request with no
245
+ // record (askedOf). None for a request that isn't to review again, or whose
246
+ // record another writer moved elsewhere first.
247
+ const againKey = (request: ReviewRequest, asked: Asked) => {
248
+ const item = Phases.pullRequestItem(request.pull.number);
249
+
250
+ if (asked.kind === "again") {
251
+ return Effect.succeedSome(
252
+ Option.match(asked.record, {
253
+ onNone: () => `pr-${request.pull.number}-review-${request.reviewed + 1}`,
254
+ onSome: (found) => Phases.keyFor(item, found),
255
+ }),
256
+ );
257
+ }
258
+
259
+ if (asked.kind !== "reconcile") {
260
+ return Effect.succeedNone;
261
+ }
262
+
263
+ return Phases.reconcile(
264
+ item,
265
+ Option.some(asked.record),
266
+ P.reviewAskedAgain,
267
+ observer("review.requestedAgain"),
268
+ ).pipe(
269
+ Effect.map((found) =>
270
+ Option.map(
271
+ Option.filter(found, (record) => record.phase === P.reviewAskedAgain),
272
+ (record) => Phases.keyFor(item, record),
273
+ ),
274
+ ),
275
+ );
276
+ };
277
+
278
+ // review.requestedAgain's items: open pull requests that ask this persona to
279
+ // review again, unless a person has them (auto:needs-human), routed by their
280
+ // assignees and reviewers. Each item's key carries the record it reads,
281
+ // `pr-7-review-asked-again-1a2b3c4`, so each request is a run of its own. A
282
+ // review asked again of a pull request whose record says changes asked or
283
+ // approved, such as a person asking after a fix of their own, moves the record
284
+ // to review-asked-again first. One with no record keys by the review count,
285
+ // `pr-7-review-2`, as before phases.
286
+ export const requestedAgain = Effect.gen(function* () {
287
+ const labelNames = yield* Settings.labels;
288
+ const me = yield* reviewerLogin;
289
+ const items: Array<WorkItem> = [];
290
+
291
+ for (const request of yield* reviewRequests) {
292
+ if (request.pull.labels.includes(labelNames.needsHuman)) {
293
+ continue;
294
+ }
295
+
296
+ const key = yield* againKey(request, askedOf(request, me));
297
+
298
+ for (const found of Option.toArray(key)) {
299
+ items.push(yield* routed(request.pull, reviewItem(request.pull, found)));
300
+ }
301
+ }
302
+
303
+ return items;
304
+ });
305
+
146
306
  // Whether this machine acts as the login, among the logins it acts as.
147
307
  const actsAs = (here: ReadonlyArray<string>, login: string) =>
148
308
  here.some((own) => sameLogin(own, login));
@@ -425,6 +585,15 @@ const headingFor = (verdict: Verdict["verdict"], reviewer: string) => {
425
585
  return `Changes requested by ${reviewer}`;
426
586
  };
427
587
 
588
+ // The phase a review leaves its pull request in.
589
+ const phaseAfter = (verdict: Verdict["verdict"]): Phases.Phase => {
590
+ if (verdict === "approve") {
591
+ return Phases.PHASES.pullRequest.approved;
592
+ }
593
+
594
+ return Phases.PHASES.pullRequest.changesAsked;
595
+ };
596
+
428
597
  const eventOf = (verdict: Verdict["verdict"]): ReviewEvent => {
429
598
  if (verdict === "approve") {
430
599
  return "APPROVE";
@@ -448,6 +617,7 @@ const postReview = (pull: PullRequest, review: ReviewMarker, verdict: Verdict, h
448
617
  event,
449
618
  });
450
619
  yield* github.comment(pull.number, `${heading} at \`${pull.headSha.slice(0, 7)}\`. ${marker}`);
620
+ yield* Phases.record(Phases.pullRequestItem(pull.number), phaseAfter(verdict.verdict));
451
621
  });
452
622
 
453
623
  const reviewAndPost = (pullRequest: number, round: number, role: Option.Option<string>) =>
@@ -695,6 +865,16 @@ export const decisiveReviews = (pullRequest: number) =>
695
865
  ),
696
866
  );
697
867
 
868
+ // What address-review needs of the pull request and the review it answers.
869
+ const addressData = (pull: PullRequest, review: SubmittedReview) => ({
870
+ pullRequest: pull.number,
871
+ headRef: pull.headRef,
872
+ baseRef: pull.baseRef,
873
+ agentWritten: isAgentBranch(pull.headRef),
874
+ reviewer: review.author,
875
+ reviewedSha: review.commitSha,
876
+ });
877
+
698
878
  // address-review's work item for a review that asks for changes, the
699
879
  // `count`th decisive review of the pull request.
700
880
  export const addressItem = (
@@ -705,30 +885,280 @@ export const addressItem = (
705
885
  key: `pr-${pull.number}-changes-${count}`,
706
886
  title: pull.title,
707
887
  url: pull.url,
708
- data: {
709
- pullRequest: pull.number,
710
- headRef: pull.headRef,
711
- baseRef: pull.baseRef,
712
- agentWritten: isAgentBranch(pull.headRef),
713
- reviewer: review.author,
714
- reviewedSha: review.commitSha,
715
- },
888
+ data: addressData(pull, review),
716
889
  });
717
890
 
891
+ // The round of CI a CI job's address-review run parked on (awaitingCi),
892
+ // which the job that resumes the work waits on.
893
+ export const ResumingCi = Schema.Struct({ round: Schema.Finite });
894
+
895
+ export type ResumingCi = typeof ResumingCi.Type;
896
+
718
897
  // baseRef: the pull request's base, which a layer of a stack has as the
719
898
  // layer below's branch. An item saved without it pushes against the repo's
720
- // base branch.
899
+ // base branch. resumeCi: the fix is pushed, and a CI job ended while its CI
900
+ // ran (fixesAwaitingCi).
721
901
  export const AddressItem = Schema.Struct({
722
902
  ...ReviewItem.fields,
723
903
  baseRef: Schema.optionalKey(Schema.String),
724
904
  reviewer: Schema.String,
725
905
  reviewedSha: Schema.String,
906
+ resumeCi: Schema.optionalKey(ResumingCi),
726
907
  });
727
908
 
728
909
  export type AddressItem = typeof AddressItem.Type;
729
910
 
730
911
  export const addressItemOf = itemData(AddressItem);
731
912
 
913
+ // The latest approval or request for changes, when it asks for changes on
914
+ // the pull request's head: nothing was pushed since.
915
+ const changesOnHead = (pull: PullRequest, decisive: ReadonlyArray<SubmittedReview>) =>
916
+ Option.filter(
917
+ Arr.last(decisive),
918
+ (review) => review.state === "CHANGES_REQUESTED" && review.commitSha === pull.headSha,
919
+ );
920
+
921
+ // Today's inference, for a pull request with no record: the latest decisive
922
+ // review asks for changes on the head, keyed by the count of decisive
923
+ // reviews. Migration: drop it a release after phases became the record.
924
+ const legacyChanges = (pull: PullRequest) =>
925
+ Effect.gen(function* () {
926
+ const decisive = yield* decisiveReviews(pull.number);
927
+ const latest = changesOnHead(pull, decisive);
928
+
929
+ if (Option.isNone(latest) || (yield* ownedByARun(pull))) {
930
+ return Option.none<WorkItem>();
931
+ }
932
+
933
+ return Option.some(addressItem(pull, latest.value, decisive.length));
934
+ });
935
+
936
+ // The phases a review that asks for changes on the head moves a pull request
937
+ // on from: a person's review, which no run was there to record.
938
+ const CHANGES_FROM = [P.reviewAsked, P.reviewAskedAgain, P.approved, P.draft, P.readyForPerson];
939
+
940
+ const shortSha = (sha: string) => sha.slice(0, 7);
941
+
942
+ // Why a pull request whose record says changes asked isn't one to address,
943
+ // by its latest approval or request for changes.
944
+ const changesDisagree = (pull: PullRequest, latest: Option.Option<SubmittedReview>) =>
945
+ Option.match(
946
+ Option.filter(latest, (review) => review.state === "CHANGES_REQUESTED"),
947
+ {
948
+ onNone: () =>
949
+ `#${pull.number}: its record says changes asked, but its latest review asks for none`,
950
+ onSome: (review) =>
951
+ `#${pull.number}: changes were asked at ${shortSha(review.commitSha)}, but its head has moved to ${shortSha(pull.headSha)} since; ask ${review.author} to review again`,
952
+ },
953
+ );
954
+
955
+ // The record a pull request with changes asked on its head holds: its own
956
+ // when it says so, or else the one reconciling it moves it to.
957
+ const changesAskedRecord = (item: string, found: PhaseRecord) => {
958
+ if (found.phase === P.changesAsked) {
959
+ return Effect.succeedSome(found);
960
+ }
961
+
962
+ return Phases.reconcile(
963
+ item,
964
+ Option.some(found),
965
+ P.changesAsked,
966
+ observer("review.changesRequested"),
967
+ );
968
+ };
969
+
970
+ // One pull request with a record, for changesToAddress: an item to address
971
+ // when its record says changes asked and the review it names is on the head;
972
+ // held, with why, when GitHub disagrees; moved to changes-asked first when a
973
+ // review asks for changes on the head of one in a phase before it.
974
+ const changesByRecord = (pull: PullRequest, found: PhaseRecord) =>
975
+ Effect.gen(function* () {
976
+ const item = Phases.pullRequestItem(pull.number);
977
+ const asks = found.phase === P.changesAsked;
978
+ // A fix whose CI a CI job left pending (awaitingCi): a review asking for
979
+ // changes on its head is new work, as it is after a hand-off.
980
+ const fixPending = Option.isSome(Phases.ciRoundOf(found.phase));
981
+
982
+ if (!asks && !fixPending && !Phases.holds(found, [...CHANGES_FROM, P.mergeHeld])) {
983
+ return Option.none<WorkItem>();
984
+ }
985
+
986
+ const decisive = yield* decisiveReviews(pull.number);
987
+ const latest = changesOnHead(pull, decisive);
988
+
989
+ if ((!asks && Option.isNone(latest)) || (yield* ownedByARun(pull))) {
990
+ return Option.none<WorkItem>();
991
+ }
992
+
993
+ if (Option.isNone(latest)) {
994
+ return Option.some<WorkItem>({
995
+ ...reviewItem(pull, Phases.keyFor(item, found)),
996
+ held: changesDisagree(pull, Arr.last(decisive)),
997
+ });
998
+ }
999
+
1000
+ if (found.phase === P.mergeHeld) {
1001
+ return Option.some<WorkItem>({
1002
+ ...reviewItem(pull, Phases.keyFor(item, found)),
1003
+ held: `#${pull.number}: its merge is held for a green base, but ${latest.value.author} has asked for changes since`,
1004
+ });
1005
+ }
1006
+
1007
+ const now = Option.filter(
1008
+ yield* changesAskedRecord(item, found),
1009
+ (record) => record.phase === P.changesAsked,
1010
+ );
1011
+
1012
+ return Option.map(now, (record) => ({
1013
+ ...addressItem(pull, latest.value, decisive.length),
1014
+ key: Phases.keyFor(item, record),
1015
+ }));
1016
+ });
1017
+
1018
+ // A held item stays here, for status to show why; any other is routed.
1019
+ const routedUnlessHeld = (pull: PullRequest, item: WorkItem) => {
1020
+ if (Option.isSome(Option.fromUndefinedOr(item.held))) {
1021
+ return Effect.succeed(item);
1022
+ }
1023
+
1024
+ return routed(pull, item);
1025
+ };
1026
+
1027
+ // review.changesRequested's items: pull requests this persona wrote whose
1028
+ // record says changes asked, by the review that asks them, on the current
1029
+ // head, so nothing was pushed since. Each item's key carries the record,
1030
+ // `pr-7-changes-asked-1a2b3c4`. A person's review that asks for changes on
1031
+ // the head of one whose record is before it moves the record on first. One a
1032
+ // person has (auto:needs-human), or a run of another flow owns, is left
1033
+ // alone; one whose record GitHub disagrees with is held, with why, for status
1034
+ // to show. One with no record is read from its reviews (legacyChanges). Each
1035
+ // is routed by its assignees and reviewers.
1036
+ export const changesToAddress = Effect.gen(function* () {
1037
+ const labelNames = yield* Settings.labels;
1038
+ const all = yield* Phases.records;
1039
+ const items: Array<WorkItem> = [];
1040
+
1041
+ for (const pull of yield* authoredByMe) {
1042
+ if (pull.labels.includes(labelNames.needsHuman)) {
1043
+ continue;
1044
+ }
1045
+
1046
+ const found = yield* Option.match(Phases.recordOf(all, Phases.pullRequestItem(pull.number)), {
1047
+ onNone: () => legacyChanges(pull),
1048
+ onSome: (record) => changesByRecord(pull, record),
1049
+ });
1050
+
1051
+ for (const item of Option.toArray(found)) {
1052
+ items.push(yield* routedUnlessHeld(pull, item));
1053
+ }
1054
+ }
1055
+
1056
+ return items;
1057
+ });
1058
+
1059
+ // Where address-review parks in a CI job while the CI of its pushed fix
1060
+ // runs: on the pull request's record, which fixesAwaitingCi reads to resume.
1061
+ export const parkOnPullRequest = (pullRequest: number): CiWait => ({
1062
+ park: Phases.pullRequestItem(pullRequest),
1063
+ });
1064
+
1065
+ // What a pull request a CI job parked on its fix's CI is waiting for, by its
1066
+ // latest decisive review: the review the fix was pushed over still stands,
1067
+ // so the wait resumes; or the reviewer has moved on since, on the fix's own
1068
+ // head. Changes asked there are new work, which changesByRecord takes up; an
1069
+ // approval there moves the record to approved, as no run was there to
1070
+ // record it. Nothing else is this source's.
1071
+ type FixWaits =
1072
+ | { readonly kind: "resume"; readonly review: SubmittedReview }
1073
+ | { readonly kind: "approved" }
1074
+ | { readonly kind: "other" };
1075
+
1076
+ const fixWaits = (pull: PullRequest, latest: Option.Option<SubmittedReview>): FixWaits =>
1077
+ Option.match(latest, {
1078
+ onNone: (): FixWaits => ({ kind: "other" }),
1079
+ onSome: (review): FixWaits => {
1080
+ const onHead = review.commitSha === pull.headSha;
1081
+
1082
+ if (review.state === "CHANGES_REQUESTED" && !onHead) {
1083
+ return { kind: "resume", review };
1084
+ }
1085
+
1086
+ if (review.state === "APPROVED" && onHead) {
1087
+ return { kind: "approved" };
1088
+ }
1089
+
1090
+ return { kind: "other" };
1091
+ },
1092
+ });
1093
+
1094
+ // One pull request whose record says a CI job parked on its fix's CI, as a
1095
+ // work item that resumes the wait, when the review it answers is still the
1096
+ // latest decisive one (fixWaits). Held while the checks are pending.
1097
+ const fixAwaitingCi = (pull: PullRequest, found: PhaseRecord, round: number) =>
1098
+ Effect.gen(function* () {
1099
+ if (yield* ownedByARun(pull)) {
1100
+ return Option.none<WorkItem>();
1101
+ }
1102
+
1103
+ const item = Phases.pullRequestItem(pull.number);
1104
+ const waits = fixWaits(pull, Arr.last(yield* decisiveReviews(pull.number)));
1105
+
1106
+ if (waits.kind === "approved") {
1107
+ yield* Phases.reconcile(item, Option.some(found), P.approved, observer("review.approved"));
1108
+ }
1109
+
1110
+ if (waits.kind !== "resume") {
1111
+ return Option.none<WorkItem>();
1112
+ }
1113
+
1114
+ const resumed: WorkItem = {
1115
+ ...reviewItem(pull, Phases.keyFor(item, found)),
1116
+ data: { ...addressData(pull, waits.review), resumeCi: { round } },
1117
+ };
1118
+
1119
+ return Option.some(
1120
+ Option.match(yield* waitingOnCi(pull.number), {
1121
+ onNone: () => resumed,
1122
+ onSome: (held) => ({ ...resumed, held }),
1123
+ }),
1124
+ );
1125
+ });
1126
+
1127
+ // Pull requests this persona wrote whose fix for a review a CI job pushed,
1128
+ // and ended the job while its CI ran (their record is awaitingCi), as work
1129
+ // items that resume that wait: held while the checks are pending, and free to
1130
+ // start once they're green or red. One a person has (auto:needs-human), or a
1131
+ // run of another flow owns, is left alone. Each is routed by its assignees
1132
+ // and reviewers.
1133
+ export const fixesAwaitingCi = Effect.gen(function* () {
1134
+ const labelNames = yield* Settings.labels;
1135
+ const all = yield* Phases.records;
1136
+ const items: Array<WorkItem> = [];
1137
+
1138
+ for (const pull of yield* authoredByMe) {
1139
+ if (pull.labels.includes(labelNames.needsHuman)) {
1140
+ continue;
1141
+ }
1142
+
1143
+ const parked = Option.flatMap(
1144
+ Phases.recordOf(all, Phases.pullRequestItem(pull.number)),
1145
+ (found) => Option.map(Phases.ciRoundOf(found.phase), (round) => ({ found, round })),
1146
+ );
1147
+
1148
+ for (const { found, round } of Option.toArray(parked)) {
1149
+ for (const resumed of Option.toArray(yield* fixAwaitingCi(pull, found, round))) {
1150
+ items.push(yield* routedUnlessHeld(pull, resumed));
1151
+ }
1152
+ }
1153
+ }
1154
+
1155
+ return items;
1156
+ });
1157
+
1158
+ // The wait an address-review item from fixesAwaitingCi resumes; none for any other.
1159
+ export const resumingCi = (address: AddressItem): Option.Option<ResumingCi> =>
1160
+ Option.fromUndefinedOr(address.resumeCi);
1161
+
732
1162
  // The author's session, from the marker the implement run left; a fresh one
733
1163
  // for `purpose` if there is none. Outside an activity, for a block that reads
734
1164
  // it under a name of its own.
@@ -850,6 +1280,10 @@ export const requestAgain = (pullRequest: number, reviewer: string, said: string
850
1280
  const github = yield* GitHub;
851
1281
  yield* github.comment(pullRequest, said);
852
1282
  yield* github.requestReviewers(pullRequest, [reviewer]);
1283
+ yield* Phases.record(
1284
+ Phases.pullRequestItem(pullRequest),
1285
+ Phases.PHASES.pullRequest.reviewAskedAgain,
1286
+ );
853
1287
  });
854
1288
 
855
1289
  // Asks the reviewer who requested the changes to review again, which starts
@@ -859,3 +1293,28 @@ export const askAgain = (pullRequest: number, round: number, reviewer: string, s
859
1293
  `ask-again-${round}`,
860
1294
  requestAgain(pullRequest, reviewer, `Addressed review ${round}: ${summary}`),
861
1295
  );
1296
+
1297
+ // After resolve-conflicts merged the base in: when the pull request's latest
1298
+ // approval or request for changes is an approval, asks its reviewer to review
1299
+ // again, since they approved the code before the merge, and records
1300
+ // review-asked-again. The approver, or none, with no approval to ask again.
1301
+ export const askApproverAgain = (pullRequest: number) =>
1302
+ activity(
1303
+ "ask-approver-again",
1304
+ Effect.gen(function* () {
1305
+ const approval = Option.filter(
1306
+ Arr.last(yield* decisiveReviews(pullRequest)),
1307
+ (review) => review.state === "APPROVED",
1308
+ );
1309
+
1310
+ if (Option.isNone(approval)) {
1311
+ return Option.none<string>();
1312
+ }
1313
+
1314
+ yield* (yield* GitHub).requestReviewers(pullRequest, [approval.value.author]);
1315
+ yield* Phases.record(Phases.pullRequestItem(pullRequest), P.reviewAskedAgain);
1316
+
1317
+ return Option.some(approval.value.author);
1318
+ }),
1319
+ Schema.Option(Schema.String),
1320
+ );