@chernabog/sdk 0.11.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chernabog/sdk",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "license": "MIT",
5
5
  "description": "The blocks Chernabog flows are written from (Implement, Review, Plan, Hybrid, PullRequest, prompts), over @chernabog/core, which it re-exports",
6
6
  "repository": {
package/src/hybrid.ts CHANGED
@@ -42,6 +42,7 @@ import {
42
42
  claimedBase,
43
43
  dropInProgress,
44
44
  issueItem,
45
+ landedBase,
45
46
  latestClaim,
46
47
  legacyClaim,
47
48
  markClaimed,
@@ -118,7 +119,7 @@ export const claim = (issue: number, options: BaseOptions = {}) =>
118
119
  const run = yield* Run;
119
120
  const branch = branchFor(issue);
120
121
  const item = Claims.issue(issue);
121
- const base = yield* baseOf(options);
122
+ const base = yield* landedBase(yield* baseOf(options));
122
123
  const baseSha = yield* baseHead(base);
123
124
  const claimed = yield* Claims.acquire(item, { withPerson: true });
124
125
 
package/src/implement.ts CHANGED
@@ -306,9 +306,40 @@ export const Claimed = Schema.Struct({
306
306
  // issue is taken on, rather than the issue implemented again (see claim).
307
307
  export type AdoptOptions = { readonly adopt?: boolean };
308
308
 
309
- // The head of the base to create the claim branch from. A base that is gone,
310
- // such as another task's branch merged and deleted, fails the claim: choosing
311
- // another is the flow's to do.
309
+ // Where work given `base` builds: `base`, or, when it is the branch of a pull
310
+ // request that merged, such as the task below an epic's task merged between
311
+ // the round that read it ready and its claim, the branch that one merged
312
+ // into, and on down as far as the layers below merged too. Stops at the
313
+ // flow's integration base, and at a branch with no merged pull request.
314
+ export const landedBase = (base: string) =>
315
+ Effect.gen(function* () {
316
+ const github = yield* GitHub;
317
+ const integration = yield* Settings.base;
318
+ const seen = new Set<string>();
319
+ let target = base;
320
+
321
+ while (target !== integration && !seen.has(target)) {
322
+ seen.add(target);
323
+
324
+ const below = Option.filter(
325
+ yield* github.pullRequestForBranch(target),
326
+ (pull) => pull.state === "merged",
327
+ );
328
+
329
+ if (Option.isNone(below)) {
330
+ break;
331
+ }
332
+
333
+ target = below.value.baseRef;
334
+ }
335
+
336
+ return target;
337
+ });
338
+
339
+ // The head of the base to create the claim branch from. A base that is gone
340
+ // with no merged pull request to follow (see landedBase), such as another
341
+ // task's branch deleted unmerged, fails the claim: choosing another is the
342
+ // flow's to do.
312
343
  export const baseHead = (base: string) =>
313
344
  Effect.gen(function* () {
314
345
  const sha = yield* (yield* GitHub).branchSha(base);
@@ -612,8 +643,9 @@ const adopt = (issue: number, label: string, takenOver: ReadonlyArray<string>) =
612
643
  // queued the issue. What it puts on the issue, the claim ref and a branch it
613
644
  // created are markers, which the engine releases however the run ends; the
614
645
  // branch only while it holds no work, and not when a person takes over. The
615
- // branch starts from `base`'s head, the repo's base branch unless given, and
616
- // the claim marker records the base, which a run that resumes keeps. With
646
+ // branch starts from the head of `base`, the repo's base branch unless given,
647
+ // or of what it merged into once its pull request merged (landedBase), and
648
+ // the claim marker records that base, which a run that resumes keeps. With
617
649
  // `adopt`, an open pull request that already closes the issue is adopted
618
650
  // instead (see adopt): no branch is made, and `adopted` names it.
619
651
  export const claim = (
@@ -628,7 +660,7 @@ export const claim = (
628
660
  const label = yield* queueLabel(options);
629
661
  const branch = branchFor(issue);
630
662
  const item = Claims.issue(issue);
631
- const base = yield* baseOf(options);
663
+ const base = yield* landedBase(yield* baseOf(options));
632
664
  const baseSha = yield* baseHead(base);
633
665
  const claimed = yield* Claims.acquire(item);
634
666