@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/package.json +1 -1
- package/src/address-review-blocks.ts +33 -40
- package/src/block.ts +47 -3
- package/src/blocks.ts +117 -28
- package/src/compose.ts +394 -2
- package/src/epic-blocks.ts +18 -6
- package/src/events.ts +427 -0
- package/src/human-initiated-blocks.ts +5 -0
- package/src/hybrid.ts +2 -0
- package/src/implement.ts +192 -9
- package/src/index.ts +2 -0
- package/src/phases.ts +289 -0
- package/src/plan-blocks.ts +26 -13
- package/src/post-merge-blocks.ts +69 -55
- package/src/pull-request.ts +9 -0
- package/src/re-review-blocks.ts +41 -21
- package/src/resolve-conflicts-blocks.ts +36 -46
- package/src/review.ts +472 -13
package/src/post-merge-blocks.ts
CHANGED
|
@@ -38,6 +38,8 @@ import {
|
|
|
38
38
|
PullRequestNumber,
|
|
39
39
|
ToPerson,
|
|
40
40
|
} from "./block.ts";
|
|
41
|
+
import * as Events from "./events.ts";
|
|
42
|
+
import { PHASES } from "./phases.ts";
|
|
41
43
|
import * as PullRequest from "./pull-request.ts";
|
|
42
44
|
import * as Settings from "./settings.ts";
|
|
43
45
|
|
|
@@ -513,6 +515,7 @@ export const postMergeBlocks = {
|
|
|
513
515
|
failures: { NeedsHuman: "told", Skip: "skip", StepFailed: "fail" },
|
|
514
516
|
outcomes: {},
|
|
515
517
|
mustRoute: [],
|
|
518
|
+
records: [{ item: "pull-request", phase: PHASES.pullRequest.watched }],
|
|
516
519
|
contributes: {},
|
|
517
520
|
}),
|
|
518
521
|
|
|
@@ -724,63 +727,74 @@ export const postMergeBlocks = {
|
|
|
724
727
|
export const postMergeSources = {
|
|
725
728
|
// Pull requests this persona wrote that merged into the base branch in the
|
|
726
729
|
// last day, among the 30 closed most lately, and that no run has watched yet.
|
|
727
|
-
"pr.mergedRecently": defineSource(
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
pullRequest: pull.number,
|
|
771
|
-
url: pull.html_url,
|
|
730
|
+
"pr.mergedRecently": defineSource(
|
|
731
|
+
"pr.mergedRecently",
|
|
732
|
+
"merged",
|
|
733
|
+
() => ({
|
|
734
|
+
trigger: Effect.gen(function* () {
|
|
735
|
+
const github = yield* GitHub;
|
|
736
|
+
const repo = yield* Repo;
|
|
737
|
+
const base = yield* Settings.base;
|
|
738
|
+
const me = yield* github.login;
|
|
739
|
+
const now = yield* DateTime.now;
|
|
740
|
+
const items: Array<WorkItem> = [];
|
|
741
|
+
|
|
742
|
+
const closed = yield* github
|
|
743
|
+
.request(
|
|
744
|
+
"GET",
|
|
745
|
+
`/repos/${repo.slug}/pulls?state=closed&sort=updated&direction=desc&per_page=30`,
|
|
746
|
+
Option.none(),
|
|
747
|
+
)
|
|
748
|
+
.pipe(Effect.flatMap(decodeIn(ClosedPulls, "trigger")));
|
|
749
|
+
|
|
750
|
+
for (const pull of closed) {
|
|
751
|
+
if (
|
|
752
|
+
!sameLogin(pull.user.login, me) ||
|
|
753
|
+
pull.base.ref !== base ||
|
|
754
|
+
Option.isNone(pull.merge_commit_sha) ||
|
|
755
|
+
!Option.exists(pull.merged_at, (at) => isRecent(at, now))
|
|
756
|
+
) {
|
|
757
|
+
continue;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
const comments = yield* github.trustedComments(pull.number);
|
|
761
|
+
|
|
762
|
+
if (comments.some((comment) => Option.isSome(watchedMarker.read(comment.body)))) {
|
|
763
|
+
continue;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
const issue = closedIssue(
|
|
767
|
+
Option.getOrElse(pull.body, () => ""),
|
|
768
|
+
pull.head.ref,
|
|
769
|
+
);
|
|
770
|
+
|
|
771
|
+
items.push({
|
|
772
|
+
key: `merged-${pull.number}`,
|
|
772
773
|
title: pull.title,
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
774
|
+
url: pull.html_url,
|
|
775
|
+
data: {
|
|
776
|
+
pullRequest: pull.number,
|
|
777
|
+
url: pull.html_url,
|
|
778
|
+
title: pull.title,
|
|
779
|
+
mergeSha: pull.merge_commit_sha.value,
|
|
780
|
+
baseRef: pull.base.ref,
|
|
781
|
+
...Option.match(issue, {
|
|
782
|
+
onNone: () => ({}),
|
|
783
|
+
onSome: (number) => ({ issue: number }),
|
|
784
|
+
}),
|
|
785
|
+
},
|
|
786
|
+
});
|
|
787
|
+
}
|
|
779
788
|
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
789
|
+
return items;
|
|
790
|
+
}).pipe(reportAs("trigger")),
|
|
791
|
+
contributes: { settings: Settings.Base.fields, ownWork: true },
|
|
792
|
+
}),
|
|
793
|
+
{
|
|
794
|
+
reads: [{ item: "pull-request", phases: [PHASES.pullRequest.watched] }],
|
|
795
|
+
events: [Events.pullRequestClosed],
|
|
796
|
+
},
|
|
797
|
+
),
|
|
784
798
|
};
|
|
785
799
|
|
|
786
800
|
// A pull request this persona wrote, merged into the base branch. A run only
|
package/src/pull-request.ts
CHANGED
|
@@ -40,6 +40,7 @@ import * as DurableDeferred from "effect/workflow/DurableDeferred";
|
|
|
40
40
|
|
|
41
41
|
import * as Ci from "./ci.ts";
|
|
42
42
|
import { commentStep } from "./comment.ts";
|
|
43
|
+
import * as Phases from "./phases.ts";
|
|
43
44
|
import * as Settings from "./settings.ts";
|
|
44
45
|
|
|
45
46
|
// Marks the pull request as this run's: its claim ref, and a comment for people to read.
|
|
@@ -631,6 +632,10 @@ export const holdWhileBaseRed = (pullRequest: number, attempt = 1) =>
|
|
|
631
632
|
pullRequest,
|
|
632
633
|
`Holding the merge: CI is failing on \`${base}\`. It merges once CI there is green again. ${holdMarker.write({ runId: run.runId, key: run.item.key })}`,
|
|
633
634
|
);
|
|
635
|
+
yield* activity(
|
|
636
|
+
`merge-held-pr-${pullRequest}-${named}`,
|
|
637
|
+
Phases.record(Phases.pullRequestItem(pullRequest), Phases.PHASES.pullRequest.mergeHeld),
|
|
638
|
+
);
|
|
634
639
|
|
|
635
640
|
if ((yield* parkOnBase(pullRequest, named, base, left)) !== BASE_GREEN) {
|
|
636
641
|
return yield* stayedRed;
|
|
@@ -791,6 +796,10 @@ export const readyForPerson = (pullRequest: number, message: string) =>
|
|
|
791
796
|
const label = yield* Settings.readyForPerson;
|
|
792
797
|
yield* github.addLabel(pullRequest, label);
|
|
793
798
|
yield* github.comment(pullRequest, message);
|
|
799
|
+
yield* Phases.record(
|
|
800
|
+
Phases.pullRequestItem(pullRequest),
|
|
801
|
+
Phases.PHASES.pullRequest.readyForPerson,
|
|
802
|
+
);
|
|
794
803
|
|
|
795
804
|
return `#${pullRequest}: labelled ${label}; ${message}`;
|
|
796
805
|
}),
|
package/src/re-review-blocks.ts
CHANGED
|
@@ -7,6 +7,8 @@ import * as Effect from "effect/Effect";
|
|
|
7
7
|
import * as Option from "effect/Option";
|
|
8
8
|
|
|
9
9
|
import { Approved, defineBlock, defineSource, type PullRequestNumber } from "./block.ts";
|
|
10
|
+
import * as Events from "./events.ts";
|
|
11
|
+
import { NO_RECORD, PHASES } from "./phases.ts";
|
|
10
12
|
import * as PullRequest from "./pull-request.ts";
|
|
11
13
|
import * as Review from "./review.ts";
|
|
12
14
|
import * as Routing from "./routing.ts";
|
|
@@ -161,6 +163,10 @@ export const reReviewBlocks = {
|
|
|
161
163
|
},
|
|
162
164
|
mustRoute: ["approve", "changes"],
|
|
163
165
|
exhaustive: true,
|
|
166
|
+
records: [
|
|
167
|
+
{ item: "pull-request", phase: PHASES.pullRequest.changesAsked, on: "changes" },
|
|
168
|
+
{ item: "pull-request", phase: PHASES.pullRequest.approved, on: "approve" },
|
|
169
|
+
],
|
|
164
170
|
contributes: { settings: { ...Settings.Reviewers.fields, ...Settings.Rules.fields } },
|
|
165
171
|
}),
|
|
166
172
|
|
|
@@ -204,31 +210,45 @@ export const reReviewBlocks = {
|
|
|
204
210
|
failures: { NeedsHuman: "told", Skip: "skip", StepFailed: "fail" },
|
|
205
211
|
outcomes: {},
|
|
206
212
|
mustRoute: [],
|
|
213
|
+
records: [{ item: "pull-request", phase: PHASES.pullRequest.readyForPerson }],
|
|
207
214
|
contributes: { namedLabels: [Settings.readyForPersonLabel] },
|
|
208
215
|
}),
|
|
209
216
|
};
|
|
210
217
|
|
|
211
218
|
export const reReviewSources = {
|
|
212
|
-
// Pull requests
|
|
213
|
-
// per request, unless a person has them (auto:needs-human): asking
|
|
214
|
-
// during a dispute doesn't restart the loop. Each item's key carries
|
|
215
|
-
//
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
219
|
+
// Pull requests whose record says a review is asked again of this persona,
|
|
220
|
+
// one item per request, unless a person has them (auto:needs-human): asking
|
|
221
|
+
// again during a dispute doesn't restart the loop. Each item's key carries
|
|
222
|
+
// the record it reads, so each request is a run of its own. A request that
|
|
223
|
+
// finds the record at changes asked or approved, such as a person asking
|
|
224
|
+
// after a fix of their own, moves it on first (Review.requestedAgain).
|
|
225
|
+
"review.requestedAgain": defineSource(
|
|
226
|
+
"review.requestedAgain",
|
|
227
|
+
"pull-request",
|
|
228
|
+
() => ({
|
|
229
|
+
trigger: Review.requestedAgain.pipe(reportAs("trigger")),
|
|
230
|
+
contributes: {
|
|
231
|
+
settings: Routing.Settings.fields,
|
|
232
|
+
doctor: [Review.reviewerCheck],
|
|
233
|
+
ownWork: true,
|
|
234
|
+
},
|
|
235
|
+
}),
|
|
236
|
+
{
|
|
237
|
+
reads: [{ item: "pull-request", phases: [PHASES.pullRequest.reviewAskedAgain, NO_RECORD] }],
|
|
238
|
+
reconciles: [
|
|
239
|
+
{
|
|
240
|
+
item: "pull-request",
|
|
241
|
+
from: [
|
|
242
|
+
PHASES.pullRequest.reviewAsked,
|
|
243
|
+
PHASES.pullRequest.changesAsked,
|
|
244
|
+
PHASES.pullRequest.approved,
|
|
245
|
+
PHASES.pullRequest.draft,
|
|
246
|
+
PHASES.pullRequest.readyForPerson,
|
|
247
|
+
],
|
|
248
|
+
to: PHASES.pullRequest.reviewAskedAgain,
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
events: [Events.reviewRequestedAgain],
|
|
232
252
|
},
|
|
233
|
-
|
|
253
|
+
),
|
|
234
254
|
};
|
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
StepFailed,
|
|
19
19
|
type WorkItem,
|
|
20
20
|
} from "@chernabog/core";
|
|
21
|
-
import * as Arr from "effect/Array";
|
|
22
21
|
import * as Effect from "effect/Effect";
|
|
23
22
|
import * as Option from "effect/Option";
|
|
24
23
|
import * as Schema from "effect/Schema";
|
|
@@ -35,7 +34,9 @@ import {
|
|
|
35
34
|
ToPerson,
|
|
36
35
|
type WorktreePath,
|
|
37
36
|
} from "./block.ts";
|
|
37
|
+
import * as Events from "./events.ts";
|
|
38
38
|
import * as Implement from "./implement.ts";
|
|
39
|
+
import { PHASES } from "./phases.ts";
|
|
39
40
|
import { renderPrompt } from "./prompt.ts";
|
|
40
41
|
import * as PullRequest from "./pull-request.ts";
|
|
41
42
|
import * as Review from "./review.ts";
|
|
@@ -450,24 +451,7 @@ export const resolveConflictsBlocks = {
|
|
|
450
451
|
readonly base: BaseBranch;
|
|
451
452
|
readonly pushed: Pushed;
|
|
452
453
|
}) =>
|
|
453
|
-
|
|
454
|
-
"ask-approver-again",
|
|
455
|
-
Effect.gen(function* () {
|
|
456
|
-
const approval = Option.filter(
|
|
457
|
-
Arr.last(yield* Review.decisiveReviews(input.pr)),
|
|
458
|
-
(review) => review.state === "APPROVED",
|
|
459
|
-
);
|
|
460
|
-
|
|
461
|
-
if (Option.isNone(approval)) {
|
|
462
|
-
return Option.none<string>();
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
yield* (yield* GitHub).requestReviewers(input.pr, [approval.value.author]);
|
|
466
|
-
|
|
467
|
-
return Option.some(approval.value.author);
|
|
468
|
-
}),
|
|
469
|
-
Schema.Option(Schema.String),
|
|
470
|
-
).pipe(
|
|
454
|
+
Review.askApproverAgain(input.pr).pipe(
|
|
471
455
|
Effect.map((approver) =>
|
|
472
456
|
Option.match(approver, {
|
|
473
457
|
onNone: () => `#${input.pr}: merged ${input.base} and resolved its conflicts`,
|
|
@@ -484,6 +468,7 @@ export const resolveConflictsBlocks = {
|
|
|
484
468
|
},
|
|
485
469
|
outcomes: {},
|
|
486
470
|
mustRoute: [],
|
|
471
|
+
records: [{ item: "pull-request", phase: PHASES.pullRequest.reviewAskedAgain }],
|
|
487
472
|
contributes: {},
|
|
488
473
|
}),
|
|
489
474
|
};
|
|
@@ -500,38 +485,43 @@ export const resolveConflictsSources = {
|
|
|
500
485
|
// person has one labelled auto:needs-human, and a run of another flow one it
|
|
501
486
|
// owns; both are left alone. The key carries the head, so a conflict that
|
|
502
487
|
// comes back after a later push is new work.
|
|
503
|
-
"pr.conflicting": defineSource(
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
488
|
+
"pr.conflicting": defineSource(
|
|
489
|
+
"pr.conflicting",
|
|
490
|
+
"conflict",
|
|
491
|
+
() => ({
|
|
492
|
+
trigger: Effect.gen(function* () {
|
|
493
|
+
const github = yield* GitHub;
|
|
494
|
+
const repo = yield* Repo;
|
|
495
|
+
const labelNames = yield* Settings.labels;
|
|
496
|
+
const items: Array<WorkItem> = [];
|
|
497
|
+
|
|
498
|
+
for (const pull of yield* Review.authoredByMe) {
|
|
499
|
+
if (pull.labels.includes(labelNames.needsHuman) || (yield* Review.ownedByARun(pull))) {
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
509
502
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
}
|
|
503
|
+
const state = yield* github
|
|
504
|
+
.request("GET", `/repos/${repo.slug}/pulls/${pull.number}`, Option.none())
|
|
505
|
+
.pipe(Effect.flatMap(decodeIn(MergeState, "trigger")));
|
|
514
506
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
507
|
+
if (state.mergeable_state !== "dirty") {
|
|
508
|
+
continue;
|
|
509
|
+
}
|
|
518
510
|
|
|
519
|
-
|
|
520
|
-
|
|
511
|
+
items.push({
|
|
512
|
+
key: `pr-${pull.number}-${pull.headSha.slice(0, 7)}`,
|
|
513
|
+
title: pull.title,
|
|
514
|
+
url: pull.url,
|
|
515
|
+
data: { pullRequest: pull.number, headRef: pull.headRef, baseRef: pull.baseRef },
|
|
516
|
+
});
|
|
521
517
|
}
|
|
522
518
|
|
|
523
|
-
items
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
return items;
|
|
532
|
-
}).pipe(reportAs("trigger")),
|
|
533
|
-
contributes: { ownWork: true },
|
|
534
|
-
})),
|
|
519
|
+
return items;
|
|
520
|
+
}).pipe(reportAs("trigger")),
|
|
521
|
+
contributes: { ownWork: true },
|
|
522
|
+
}),
|
|
523
|
+
{ events: [Events.baseMoved] },
|
|
524
|
+
),
|
|
535
525
|
};
|
|
536
526
|
|
|
537
527
|
// A pull request this persona wrote that conflicts with its base. A run owns
|