@chernabog/sdk 0.10.0 → 0.11.1
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 +510 -0
- package/src/block.ts +466 -0
- package/src/blocks.ts +1051 -0
- package/src/compose.ts +2666 -0
- package/src/epic-blocks.ts +1217 -0
- package/src/human-initiated-blocks.ts +274 -0
- package/src/hybrid.ts +2 -1
- package/src/implement.ts +103 -16
- package/src/index.ts +3 -0
- package/src/plan-blocks.ts +312 -0
- package/src/post-merge-blocks.ts +826 -0
- package/src/pull-request.ts +17 -0
- package/src/re-review-blocks.ts +234 -0
- package/src/resolve-conflicts-blocks.ts +567 -0
- package/src/review.ts +3 -1
- package/src/settings.ts +22 -2
- package/src/suits.ts +156 -0
|
@@ -0,0 +1,567 @@
|
|
|
1
|
+
// The resolve-conflicts blocks: merging the base into a pull request this
|
|
2
|
+
// persona wrote that conflicts with it, never by a rebase, after recording a
|
|
3
|
+
// squash- or rebase-merged layer below as already here; checking, pushing,
|
|
4
|
+
// saying so and waiting for CI on the merge; and asking an approving reviewer
|
|
5
|
+
// again. A run owns the pull request throughout, by its subject, so
|
|
6
|
+
// address-review doesn't push to the branch under it.
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
activity,
|
|
10
|
+
Agent,
|
|
11
|
+
GitHub,
|
|
12
|
+
type Json,
|
|
13
|
+
NeedsHuman,
|
|
14
|
+
NothingCommitted,
|
|
15
|
+
Repo,
|
|
16
|
+
reportAs,
|
|
17
|
+
Run,
|
|
18
|
+
StepFailed,
|
|
19
|
+
type WorkItem,
|
|
20
|
+
} from "@chernabog/core";
|
|
21
|
+
import * as Arr from "effect/Array";
|
|
22
|
+
import * as Effect from "effect/Effect";
|
|
23
|
+
import * as Option from "effect/Option";
|
|
24
|
+
import * as Schema from "effect/Schema";
|
|
25
|
+
|
|
26
|
+
import {
|
|
27
|
+
BaseBranch,
|
|
28
|
+
BranchName,
|
|
29
|
+
Committed,
|
|
30
|
+
defineBlock,
|
|
31
|
+
defineSource,
|
|
32
|
+
type FailureContext,
|
|
33
|
+
PullRequestNumber,
|
|
34
|
+
Pushed,
|
|
35
|
+
ToPerson,
|
|
36
|
+
type WorktreePath,
|
|
37
|
+
} from "./block.ts";
|
|
38
|
+
import * as Implement from "./implement.ts";
|
|
39
|
+
import { renderPrompt } from "./prompt.ts";
|
|
40
|
+
import * as PullRequest from "./pull-request.ts";
|
|
41
|
+
import * as Review from "./review.ts";
|
|
42
|
+
import * as Settings from "./settings.ts";
|
|
43
|
+
import * as Stack from "./stack.ts";
|
|
44
|
+
|
|
45
|
+
// GitHub computes mergeability in the background: `mergeable_state` is
|
|
46
|
+
// "dirty" for a conflict, and "unknown" until it has looked, which the next
|
|
47
|
+
// tick sees again.
|
|
48
|
+
const MergeState = Schema.Struct({ mergeable_state: Schema.String });
|
|
49
|
+
|
|
50
|
+
// What a work item says of a conflicting pull request.
|
|
51
|
+
const ConflictItem = Schema.Struct({
|
|
52
|
+
pullRequest: Schema.Finite,
|
|
53
|
+
headRef: Schema.String,
|
|
54
|
+
baseRef: Schema.String,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
type ConflictItem = typeof ConflictItem.Type;
|
|
58
|
+
|
|
59
|
+
const Resolution = Schema.Struct({
|
|
60
|
+
status: Schema.Literals(["resolved", "needs-human"]),
|
|
61
|
+
summary: Schema.String,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
type Resolution = typeof Resolution.Type;
|
|
65
|
+
|
|
66
|
+
const resolutionJsonSchema = {
|
|
67
|
+
type: "object",
|
|
68
|
+
properties: {
|
|
69
|
+
status: {
|
|
70
|
+
type: "string",
|
|
71
|
+
enum: ["resolved", "needs-human"],
|
|
72
|
+
description: "resolved once the merge is committed; needs-human when a person must decide",
|
|
73
|
+
},
|
|
74
|
+
summary: {
|
|
75
|
+
type: "string",
|
|
76
|
+
description:
|
|
77
|
+
"Which files conflicted and how you resolved each, or what a person must decide and why",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
required: ["status", "summary"],
|
|
81
|
+
additionalProperties: false,
|
|
82
|
+
} satisfies Json;
|
|
83
|
+
|
|
84
|
+
// What the agent is told of the merge: to make it, or that the flow left one
|
|
85
|
+
// in progress, with these conflicts, after recording the layer below.
|
|
86
|
+
type Merge = Option.Option<{ readonly lower: number; readonly conflicts: ReadonlyArray<string> }>;
|
|
87
|
+
|
|
88
|
+
const describeMerge = (base: string, merge: Merge) =>
|
|
89
|
+
Option.match(merge, {
|
|
90
|
+
onNone: () => `1. \`git fetch origin ${base}\`, then \`git merge --no-ff origin/${base}\`.`,
|
|
91
|
+
onSome: ({ conflicts, lower }) =>
|
|
92
|
+
[
|
|
93
|
+
`1. The merge is already started, and left in progress for you. #${lower}, the layer below this pull request, was squash- or rebase-merged into \`${base}\`, and Chernabog recorded its commits as already here, so a merge doesn't bring back what \`${base}\` has since moved or deleted of that layer. Resolve and commit the merge in progress; don't abort it, start another, or merge \`${base}\` yourself, which would undo that. Chernabog merges whatever of \`${base}\` is left. These files are in conflict:`,
|
|
94
|
+
"",
|
|
95
|
+
...conflicts.map((path) => ` - ${path}`),
|
|
96
|
+
].join("\n"),
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// The agent merges the base into the branch and commits the merge, in the
|
|
100
|
+
// run's own session: `step` is "resolve", or "resolve-2" for a second merge
|
|
101
|
+
// the flow left it.
|
|
102
|
+
const resolveStep = (
|
|
103
|
+
conflict: ConflictItem,
|
|
104
|
+
worktree: string,
|
|
105
|
+
sessionId: string,
|
|
106
|
+
merge: Merge,
|
|
107
|
+
step: string,
|
|
108
|
+
) =>
|
|
109
|
+
activity(
|
|
110
|
+
step,
|
|
111
|
+
Effect.gen(function* () {
|
|
112
|
+
const repo = yield* Repo;
|
|
113
|
+
const rules = yield* Settings.rules;
|
|
114
|
+
const localGate = yield* Settings.localGate;
|
|
115
|
+
|
|
116
|
+
const prompt = yield* renderPrompt("resolve-conflicts", {
|
|
117
|
+
repo: repo.slug,
|
|
118
|
+
pullRequest: conflict.pullRequest,
|
|
119
|
+
branch: conflict.headRef,
|
|
120
|
+
base: conflict.baseRef,
|
|
121
|
+
merge: describeMerge(conflict.baseRef, merge),
|
|
122
|
+
humanOnly: rules.humanOnly,
|
|
123
|
+
notes: rules.notes,
|
|
124
|
+
localGate: localGate.commands,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const result = yield* (yield* Agent).run({
|
|
128
|
+
cwd: worktree,
|
|
129
|
+
prompt,
|
|
130
|
+
sessionId,
|
|
131
|
+
resumePrompt: Option.none(),
|
|
132
|
+
outputSchema: Option.some(resolutionJsonSchema),
|
|
133
|
+
adapter: Option.none(),
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return yield* Schema.decodeUnknownEffect(Resolution)(result.output).pipe(
|
|
137
|
+
Effect.mapError(
|
|
138
|
+
(issue) => new StepFailed({ step, message: `agent answer: ${issue.message}` }),
|
|
139
|
+
),
|
|
140
|
+
);
|
|
141
|
+
}),
|
|
142
|
+
Resolution,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
// Resolves the conflict, after recording a squash- or rebase-merged layer
|
|
146
|
+
// below as already here when there is one. That record is a merge the flow
|
|
147
|
+
// makes (Stack.syncBase), and the agent resolves what it leaves in progress.
|
|
148
|
+
// A conflict in the base before the layer below's commits stops it short:
|
|
149
|
+
// once the agent commits that, the flow merges again to finish, and the agent
|
|
150
|
+
// resolves what that leaves. With nothing left in conflict, no agent runs.
|
|
151
|
+
const resolveWithBelow = (conflict: ConflictItem, worktree: string, sessionId: string) =>
|
|
152
|
+
Effect.gen(function* () {
|
|
153
|
+
const below = yield* activity(
|
|
154
|
+
"merged-below",
|
|
155
|
+
Stack.mergedBelow(worktree, conflict.baseRef),
|
|
156
|
+
Schema.Option(Schema.Finite),
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
if (Option.isNone(below)) {
|
|
160
|
+
return yield* resolveStep(conflict, worktree, sessionId, Option.none(), "resolve");
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const lower = below.value;
|
|
164
|
+
const recorded = `Recorded #${lower}, the layer below as \`${conflict.baseRef}\` merged it, as already here.`;
|
|
165
|
+
const summaries: Array<string> = [recorded];
|
|
166
|
+
|
|
167
|
+
const round = (id: string, step: string) =>
|
|
168
|
+
Effect.gen(function* () {
|
|
169
|
+
const synced = yield* Stack.syncBase(worktree, { base: conflict.baseRef, lower, id }).pipe(
|
|
170
|
+
Effect.catchTag("NotFound", (gone) =>
|
|
171
|
+
Effect.fail(new StepFailed({ step: "update-from-base", message: gone.message })),
|
|
172
|
+
),
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
if (synced.clean) {
|
|
176
|
+
return { synced, resolution: Option.none<Resolution>() };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const resolution = yield* resolveStep(
|
|
180
|
+
conflict,
|
|
181
|
+
worktree,
|
|
182
|
+
sessionId,
|
|
183
|
+
Option.some({ lower, conflicts: synced.conflicts }),
|
|
184
|
+
step,
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
return { synced, resolution: Option.some(resolution) };
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const rounds = [yield* round("resolve", "resolve")];
|
|
191
|
+
|
|
192
|
+
if (
|
|
193
|
+
!rounds[0].synced.reconciled &&
|
|
194
|
+
Option.exists(rounds[0].resolution, (said) => said.status === "resolved")
|
|
195
|
+
) {
|
|
196
|
+
rounds.push(yield* round("resolve-2", "resolve-2"));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
for (const done of rounds) {
|
|
200
|
+
if (Option.isSome(done.resolution)) {
|
|
201
|
+
if (done.resolution.value.status === "needs-human") {
|
|
202
|
+
return done.resolution.value;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
summaries.push(done.resolution.value.summary);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (summaries.length === 1) {
|
|
210
|
+
summaries.push("Nothing else conflicted.");
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return { status: "resolved", summary: summaries.join("\n\n") } satisfies Resolution;
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// What conflict.resolve gives: the agent's account, the session it resolved
|
|
217
|
+
// the conflict in, which the local gate and CI send failures back to, and
|
|
218
|
+
// proof the merge was committed.
|
|
219
|
+
export type Resolved = {
|
|
220
|
+
readonly resolution: Resolution;
|
|
221
|
+
readonly summary: string;
|
|
222
|
+
readonly session: Implement.AuthorSession;
|
|
223
|
+
readonly committed: Committed;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// The words the recipe hands a pull request to a person in when the agent
|
|
227
|
+
// committed no merge.
|
|
228
|
+
const committedNoMerge = <A, E, R>(effect: Effect.Effect<A, E | NothingCommitted, R>) =>
|
|
229
|
+
effect.pipe(
|
|
230
|
+
Effect.catchIf(
|
|
231
|
+
(error): error is NothingCommitted => error instanceof NothingCommitted,
|
|
232
|
+
(nothing) =>
|
|
233
|
+
Effect.fail(
|
|
234
|
+
new NeedsHuman({ reason: `the agent committed no merge on ${nothing.branch}` }),
|
|
235
|
+
),
|
|
236
|
+
),
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
export const resolveConflictsBlocks = {
|
|
240
|
+
"conflict.resolve": defineBlock({
|
|
241
|
+
name: "conflict.resolve",
|
|
242
|
+
about:
|
|
243
|
+
"Merges the pull request's base into its branch, never by a rebase, and has an agent resolve the conflicts and commit the merge, in a session of the run's own. On a layer of a stack whose layer below squash- or rebase-merged into the base, it first records that layer's commits as already here (merged-below, update-from-base#resolve), so the merge doesn't bring back what the base has since moved or deleted; the agent resolves what that leaves, and with nothing left no agent runs. A conflict in the base before that layer's commits stops the record short, and once the agent commits it the flow merges again (resolve-2). Its prompt is .chernabog/prompts/resolve-conflicts.md, which `chernabog recipes add resolve-conflicts` bakes.",
|
|
244
|
+
inputKinds: {
|
|
245
|
+
pr: "PullRequestNumber",
|
|
246
|
+
branch: "BranchName: the pull request's, trigger.branch",
|
|
247
|
+
base: "BaseBranch: the pull request's base, the layer below's branch on a layer of a stack, trigger.base",
|
|
248
|
+
worktree: "WorktreePath: from author.worktree",
|
|
249
|
+
},
|
|
250
|
+
outputKinds: {
|
|
251
|
+
resolution: "what the agent said: status and summary",
|
|
252
|
+
summary: "which files conflicted and how each was resolved, for conflict.report",
|
|
253
|
+
session:
|
|
254
|
+
"the session that resolved the conflict, for conflict.localGate and conflict.waitForCi",
|
|
255
|
+
committed: "Committed: proof for conflict.push",
|
|
256
|
+
},
|
|
257
|
+
outcomeKinds: {
|
|
258
|
+
"needs-human":
|
|
259
|
+
"an object: reason, why only a person can settle the conflict, for pr.handToPerson",
|
|
260
|
+
},
|
|
261
|
+
stepNames: ["merged-below", "update-from-base", "resolve"],
|
|
262
|
+
before: ["conflict.localGate", "conflict.push"],
|
|
263
|
+
inputs: { pr: "required", branch: "required", base: "required", worktree: "required" },
|
|
264
|
+
run: (input: {
|
|
265
|
+
readonly pr: PullRequestNumber;
|
|
266
|
+
readonly branch: BranchName;
|
|
267
|
+
readonly base: BaseBranch;
|
|
268
|
+
readonly worktree: WorktreePath;
|
|
269
|
+
}) =>
|
|
270
|
+
Effect.gen(function* () {
|
|
271
|
+
const run = yield* Run;
|
|
272
|
+
const sessionId = Implement.sessionIdFor(run.runId, "resolve-conflicts");
|
|
273
|
+
|
|
274
|
+
const resolution = yield* resolveWithBelow(
|
|
275
|
+
{ pullRequest: input.pr, headRef: input.branch, baseRef: input.base },
|
|
276
|
+
input.worktree,
|
|
277
|
+
sessionId,
|
|
278
|
+
);
|
|
279
|
+
|
|
280
|
+
return {
|
|
281
|
+
resolution,
|
|
282
|
+
summary: resolution.summary,
|
|
283
|
+
session: { sessionId: Option.some(sessionId), adapter: Option.none<string>() },
|
|
284
|
+
committed: new Committed({}),
|
|
285
|
+
};
|
|
286
|
+
}),
|
|
287
|
+
failures: { NeedsHuman: "person", Skip: "skip", StepFailed: "person" },
|
|
288
|
+
outcomes: {
|
|
289
|
+
"needs-human": (done: { readonly resolution: Resolution }) =>
|
|
290
|
+
Option.liftPredicate(
|
|
291
|
+
{ reason: `the merge conflict needs a person:\n\n${done.resolution.summary}` },
|
|
292
|
+
() => done.resolution.status === "needs-human",
|
|
293
|
+
),
|
|
294
|
+
},
|
|
295
|
+
mustRoute: ["needs-human"],
|
|
296
|
+
contributes: { settings: { ...Settings.Rules.fields, ...Settings.LocalGate.fields } },
|
|
297
|
+
}),
|
|
298
|
+
|
|
299
|
+
"conflict.localGate": defineBlock({
|
|
300
|
+
name: "conflict.localGate",
|
|
301
|
+
about:
|
|
302
|
+
"Runs the repo's local gate on the merge, resuming the session that resolved the conflict to fix a failure, up to localGateRounds. Its steps are local-gate-1#resolve and on.",
|
|
303
|
+
inputKinds: {
|
|
304
|
+
pr: "PullRequestNumber",
|
|
305
|
+
worktree: "WorktreePath: from author.worktree",
|
|
306
|
+
session: "the session that resolved the conflict, from conflict.resolve",
|
|
307
|
+
},
|
|
308
|
+
outputKinds: "nothing",
|
|
309
|
+
outcomeKinds: {},
|
|
310
|
+
before: ["conflict.push"],
|
|
311
|
+
inputs: { pr: "required", worktree: "required", session: "required" },
|
|
312
|
+
run: (input: {
|
|
313
|
+
readonly pr: PullRequestNumber;
|
|
314
|
+
readonly worktree: WorktreePath;
|
|
315
|
+
readonly session: Implement.AuthorSession;
|
|
316
|
+
}) =>
|
|
317
|
+
Implement.localGate(input.worktree, {
|
|
318
|
+
id: "resolve",
|
|
319
|
+
session: input.session,
|
|
320
|
+
pullRequest: input.pr,
|
|
321
|
+
}),
|
|
322
|
+
failures: { NeedsHuman: "person", Skip: "skip", StepFailed: "person" },
|
|
323
|
+
outcomes: {},
|
|
324
|
+
mustRoute: [],
|
|
325
|
+
contributes: { settings: Settings.LocalGate.fields },
|
|
326
|
+
}),
|
|
327
|
+
|
|
328
|
+
"conflict.push": defineBlock({
|
|
329
|
+
name: "conflict.push",
|
|
330
|
+
about:
|
|
331
|
+
"Pushes the merge to the pull request's branch as push-resolved: a plain push, since a merge only adds commits. It is checked against the pull request's base, the layer below's branch on a layer of a stack, so only the branch's own commits count; one that touches humanOnlyPaths goes to a person.",
|
|
332
|
+
inputKinds: {
|
|
333
|
+
worktree: "WorktreePath: from author.worktree",
|
|
334
|
+
branch: "BranchName: the pull request's, trigger.branch",
|
|
335
|
+
base: "BaseBranch: the pull request's, trigger.base",
|
|
336
|
+
committed: "Committed: from conflict.resolve",
|
|
337
|
+
},
|
|
338
|
+
outputKinds: { pushed: "Pushed: proof for conflict.report and conflict.askApproverAgain" },
|
|
339
|
+
outcomeKinds: {},
|
|
340
|
+
before: ["conflict.report", "conflict.waitForCi", "conflict.askApproverAgain"],
|
|
341
|
+
inputs: { worktree: "required", branch: "required", base: "required", committed: "required" },
|
|
342
|
+
run: (input: {
|
|
343
|
+
readonly worktree: WorktreePath;
|
|
344
|
+
readonly branch: BranchName;
|
|
345
|
+
readonly base: BaseBranch;
|
|
346
|
+
readonly committed: Committed;
|
|
347
|
+
}) =>
|
|
348
|
+
committedNoMerge(
|
|
349
|
+
Implement.push("push-resolved", input.worktree, input.branch, { base: input.base }),
|
|
350
|
+
).pipe(Effect.as({ pushed: new Pushed({}) })),
|
|
351
|
+
failures: { NeedsHuman: "person", PushRejected: "person", Skip: "skip", StepFailed: "person" },
|
|
352
|
+
outcomes: {},
|
|
353
|
+
mustRoute: [],
|
|
354
|
+
contributes: { settings: { ...Settings.Base.fields, ...Settings.Rules.fields } },
|
|
355
|
+
}),
|
|
356
|
+
|
|
357
|
+
"conflict.report": defineBlock({
|
|
358
|
+
name: "conflict.report",
|
|
359
|
+
about:
|
|
360
|
+
"Comments on the pull request that the base was merged in to resolve its conflicts, with which files conflicted and how each was resolved.",
|
|
361
|
+
inputKinds: {
|
|
362
|
+
pr: "PullRequestNumber",
|
|
363
|
+
base: "BaseBranch: the pull request's, trigger.base",
|
|
364
|
+
summary: "how the conflicts were resolved, from conflict.resolve",
|
|
365
|
+
pushed: "Pushed: from conflict.push",
|
|
366
|
+
},
|
|
367
|
+
outputKinds: "nothing",
|
|
368
|
+
outcomeKinds: {},
|
|
369
|
+
before: ["conflict.waitForCi"],
|
|
370
|
+
inputs: { pr: "required", base: "required", summary: "required", pushed: "required" },
|
|
371
|
+
run: (input: {
|
|
372
|
+
readonly pr: PullRequestNumber;
|
|
373
|
+
readonly base: BaseBranch;
|
|
374
|
+
readonly summary: string;
|
|
375
|
+
readonly pushed: Pushed;
|
|
376
|
+
}) =>
|
|
377
|
+
PullRequest.comment(
|
|
378
|
+
input.pr,
|
|
379
|
+
`Merged \`${input.base}\` into this branch to resolve its conflicts.\n\n${input.summary}`,
|
|
380
|
+
),
|
|
381
|
+
failures: { NeedsHuman: "person", Skip: "skip", StepFailed: "person" },
|
|
382
|
+
outcomes: {},
|
|
383
|
+
mustRoute: [],
|
|
384
|
+
contributes: {},
|
|
385
|
+
}),
|
|
386
|
+
|
|
387
|
+
"conflict.waitForCi": defineBlock({
|
|
388
|
+
name: "conflict.waitForCi",
|
|
389
|
+
about:
|
|
390
|
+
"Waits for CI on the pushed merge, resuming the session that resolved the conflict to fix red, up to ciRounds. Its steps carry #resolve.",
|
|
391
|
+
inputKinds: {
|
|
392
|
+
pr: "PullRequestNumber",
|
|
393
|
+
worktree: "WorktreePath: from author.worktree",
|
|
394
|
+
branch: "BranchName: the pull request's, trigger.branch",
|
|
395
|
+
base: "BaseBranch: the pull request's, trigger.base",
|
|
396
|
+
session: "the session that resolved the conflict, from conflict.resolve",
|
|
397
|
+
},
|
|
398
|
+
outputKinds: "nothing",
|
|
399
|
+
outcomeKinds: {},
|
|
400
|
+
before: ["conflict.askApproverAgain"],
|
|
401
|
+
inputs: {
|
|
402
|
+
pr: "required",
|
|
403
|
+
worktree: "required",
|
|
404
|
+
branch: "required",
|
|
405
|
+
base: "required",
|
|
406
|
+
session: "required",
|
|
407
|
+
},
|
|
408
|
+
run: (input: {
|
|
409
|
+
readonly pr: PullRequestNumber;
|
|
410
|
+
readonly worktree: WorktreePath;
|
|
411
|
+
readonly branch: BranchName;
|
|
412
|
+
readonly base: BaseBranch;
|
|
413
|
+
readonly session: Implement.AuthorSession;
|
|
414
|
+
}) =>
|
|
415
|
+
committedNoMerge(
|
|
416
|
+
Implement.waitForCi(
|
|
417
|
+
input.pr,
|
|
418
|
+
input.worktree,
|
|
419
|
+
{ ...input.session, branch: input.branch, base: input.base },
|
|
420
|
+
{ id: "resolve" },
|
|
421
|
+
),
|
|
422
|
+
),
|
|
423
|
+
failures: {
|
|
424
|
+
CiTimedOut: "person",
|
|
425
|
+
NeedsHuman: "person",
|
|
426
|
+
PushRejected: "person",
|
|
427
|
+
Skip: "skip",
|
|
428
|
+
StepFailed: "person",
|
|
429
|
+
},
|
|
430
|
+
outcomes: {},
|
|
431
|
+
mustRoute: [],
|
|
432
|
+
contributes: { settings: Settings.Ci.fields },
|
|
433
|
+
}),
|
|
434
|
+
|
|
435
|
+
"conflict.askApproverAgain": defineBlock({
|
|
436
|
+
name: "conflict.askApproverAgain",
|
|
437
|
+
about:
|
|
438
|
+
"When the pull request's latest approval or request for changes is an approval, asks that reviewer to review again, since they approved the code before the merge; their re-review merges an auto:ship pull request it approves. With no approval it asks no one. A pull request closed meanwhile skips the run. Its output is a summary, for end's summary.",
|
|
439
|
+
inputKinds: {
|
|
440
|
+
pr: "PullRequestNumber",
|
|
441
|
+
base: "BaseBranch: the pull request's, trigger.base",
|
|
442
|
+
pushed: "Pushed: from conflict.push",
|
|
443
|
+
},
|
|
444
|
+
outputKinds: "a summary, for `end`'s summary",
|
|
445
|
+
outcomeKinds: {},
|
|
446
|
+
stepNames: ["ask-approver-again"],
|
|
447
|
+
inputs: { pr: "required", base: "required", pushed: "required" },
|
|
448
|
+
run: (input: {
|
|
449
|
+
readonly pr: PullRequestNumber;
|
|
450
|
+
readonly base: BaseBranch;
|
|
451
|
+
readonly pushed: Pushed;
|
|
452
|
+
}) =>
|
|
453
|
+
activity(
|
|
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(
|
|
471
|
+
Effect.map((approver) =>
|
|
472
|
+
Option.match(approver, {
|
|
473
|
+
onNone: () => `#${input.pr}: merged ${input.base} and resolved its conflicts`,
|
|
474
|
+
onSome: (login) =>
|
|
475
|
+
`#${input.pr}: merged ${input.base}, resolved its conflicts and asked ${login} to review again`,
|
|
476
|
+
}),
|
|
477
|
+
),
|
|
478
|
+
),
|
|
479
|
+
failures: {
|
|
480
|
+
NeedsHuman: "person",
|
|
481
|
+
PullRequestClosed: "skip",
|
|
482
|
+
Skip: "skip",
|
|
483
|
+
StepFailed: "person",
|
|
484
|
+
},
|
|
485
|
+
outcomes: {},
|
|
486
|
+
mustRoute: [],
|
|
487
|
+
contributes: {},
|
|
488
|
+
}),
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
const decodeIn =
|
|
492
|
+
<A>(schema: Schema.Codec<A, Json>, step: string) =>
|
|
493
|
+
(json: Json) =>
|
|
494
|
+
Schema.decodeEffect(schema)(json).pipe(
|
|
495
|
+
Effect.mapError((issue) => new StepFailed({ step, message: issue.message })),
|
|
496
|
+
);
|
|
497
|
+
|
|
498
|
+
export const resolveConflictsSources = {
|
|
499
|
+
// Open pull requests this persona wrote that conflict with their base. A
|
|
500
|
+
// person has one labelled auto:needs-human, and a run of another flow one it
|
|
501
|
+
// owns; both are left alone. The key carries the head, so a conflict that
|
|
502
|
+
// comes back after a later push is new work.
|
|
503
|
+
"pr.conflicting": defineSource("pr.conflicting", "conflict", () => ({
|
|
504
|
+
trigger: Effect.gen(function* () {
|
|
505
|
+
const github = yield* GitHub;
|
|
506
|
+
const repo = yield* Repo;
|
|
507
|
+
const labelNames = yield* Settings.labels;
|
|
508
|
+
const items: Array<WorkItem> = [];
|
|
509
|
+
|
|
510
|
+
for (const pull of yield* Review.authoredByMe) {
|
|
511
|
+
if (pull.labels.includes(labelNames.needsHuman) || (yield* Review.ownedByARun(pull))) {
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const state = yield* github
|
|
516
|
+
.request("GET", `/repos/${repo.slug}/pulls/${pull.number}`, Option.none())
|
|
517
|
+
.pipe(Effect.flatMap(decodeIn(MergeState, "trigger")));
|
|
518
|
+
|
|
519
|
+
if (state.mergeable_state !== "dirty") {
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
items.push({
|
|
524
|
+
key: `pr-${pull.number}-${pull.headSha.slice(0, 7)}`,
|
|
525
|
+
title: pull.title,
|
|
526
|
+
url: pull.url,
|
|
527
|
+
data: { pullRequest: pull.number, headRef: pull.headRef, baseRef: pull.baseRef },
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
return items;
|
|
532
|
+
}).pipe(reportAs("trigger")),
|
|
533
|
+
contributes: { ownWork: true },
|
|
534
|
+
})),
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
// A pull request this persona wrote that conflicts with its base. A run owns
|
|
538
|
+
// the pull request throughout, so no other run pushes to its branch, and lets
|
|
539
|
+
// it go however it ends; one another run owns is skipped. A failure going to
|
|
540
|
+
// a person labels the pull request auto:needs-human and comments why.
|
|
541
|
+
export const conflictSubject = {
|
|
542
|
+
fields: ["pr", "branch", "base"],
|
|
543
|
+
kinds: { pr: "PullRequestNumber", branch: "BranchName", base: "BaseBranch" },
|
|
544
|
+
failureContext: [],
|
|
545
|
+
read: (item: WorkItem) =>
|
|
546
|
+
Schema.decodeUnknownEffect(ConflictItem)(item.data).pipe(
|
|
547
|
+
Effect.mapError((issue) => new StepFailed({ step: "item", message: issue.message })),
|
|
548
|
+
Effect.map((conflict) => ({
|
|
549
|
+
pr: PullRequestNumber(conflict.pullRequest),
|
|
550
|
+
branch: BranchName(conflict.headRef),
|
|
551
|
+
base: BaseBranch(conflict.baseRef),
|
|
552
|
+
})),
|
|
553
|
+
),
|
|
554
|
+
scope: <A, E, R>(
|
|
555
|
+
trigger: { readonly pr: PullRequestNumber },
|
|
556
|
+
_options: { readonly claims: boolean },
|
|
557
|
+
body: (context: FailureContext) => Effect.Effect<A, E | ToPerson, R>,
|
|
558
|
+
) =>
|
|
559
|
+
Effect.suspend(() => body({ pr: Option.some(trigger.pr) })).pipe(
|
|
560
|
+
Effect.catchIf(
|
|
561
|
+
(failure): failure is ToPerson => failure instanceof ToPerson,
|
|
562
|
+
(failure) => PullRequest.handToPerson(trigger.pr, failure.reason),
|
|
563
|
+
),
|
|
564
|
+
PullRequest.owning(trigger.pr),
|
|
565
|
+
),
|
|
566
|
+
stillValid: Option.some(Review.stillValid),
|
|
567
|
+
};
|
package/src/review.ts
CHANGED
|
@@ -776,7 +776,9 @@ const describeReviewLine = (note: ReviewNote) =>
|
|
|
776
776
|
|
|
777
777
|
// The review that asks for changes, as the author considers it: its round,
|
|
778
778
|
// from the reviewer's marker, and what the reviewer said.
|
|
779
|
-
export const changesAsked = (
|
|
779
|
+
export const changesAsked = (
|
|
780
|
+
address: Pick<AddressItem, "pullRequest" | "reviewer" | "reviewedSha">,
|
|
781
|
+
) =>
|
|
780
782
|
activity(
|
|
781
783
|
"read-review",
|
|
782
784
|
Effect.gen(function* () {
|
package/src/settings.ts
CHANGED
|
@@ -115,6 +115,8 @@ export const Labels = Schema.Struct({
|
|
|
115
115
|
stale: name,
|
|
116
116
|
ship: name,
|
|
117
117
|
hybrid: name,
|
|
118
|
+
// Only pr.readyForPerson's: not one of the label set every flow declares.
|
|
119
|
+
readyForPerson: name,
|
|
118
120
|
}).annotate({ description: "The label names the SDK's blocks use, by what each means." }),
|
|
119
121
|
),
|
|
120
122
|
});
|
|
@@ -122,11 +124,29 @@ export const Labels = Schema.Struct({
|
|
|
122
124
|
// The label names, each one the flow's settings give over the repo's.
|
|
123
125
|
export const labels = Effect.gen(function* () {
|
|
124
126
|
const repo = yield* Repo;
|
|
125
|
-
const own = yield* read(Labels);
|
|
127
|
+
const { readyForPerson: _, ...own } = (yield* read(Labels)).labels ?? {};
|
|
126
128
|
|
|
127
|
-
return { ...DEFAULT_LABEL_NAMES, ...repo.labels, ...own
|
|
129
|
+
return { ...DEFAULT_LABEL_NAMES, ...repo.labels, ...own } satisfies LabelNames;
|
|
128
130
|
});
|
|
129
131
|
|
|
132
|
+
// The label pr.readyForPerson gives a pull request a person takes on next,
|
|
133
|
+
// as what the run was for: auto:ready-for-person, unless the flow's settings
|
|
134
|
+
// name another (labels.readyForPerson). Unlike auto:needs-human, it stops no
|
|
135
|
+
// flow from picking the pull request up.
|
|
136
|
+
export const READY_FOR_PERSON = "auto:ready-for-person";
|
|
137
|
+
|
|
138
|
+
export const readyForPerson = Effect.map(
|
|
139
|
+
read(Labels),
|
|
140
|
+
(own) => own.labels?.readyForPerson ?? READY_FOR_PERSON,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
// For the flow's labels, so `chernabog labels` creates it, by its name.
|
|
144
|
+
export const readyForPersonLabel = Effect.map(readyForPerson, (label): FlowLabel => ({
|
|
145
|
+
name: label,
|
|
146
|
+
color: "0e8a16",
|
|
147
|
+
description: "Chernabog did its part; a person takes the next step, such as merging",
|
|
148
|
+
}));
|
|
149
|
+
|
|
130
150
|
const LOOK = {
|
|
131
151
|
eligible: { color: "0e8a16", description: "Queued for an unattended run; removed on claim" },
|
|
132
152
|
inProgress: { color: "fbca04", description: "An unattended run owns this issue" },
|