@chernabog/recipes 0.2.0 → 0.2.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/flows/epic.ts CHANGED
@@ -110,10 +110,68 @@ const queuedAs = (ships: boolean) =>
110
110
  const releaseTask = (issue: number, id: string) =>
111
111
  activity(`release-claim#${id}`, Claims.release(Claims.issue(issue)));
112
112
 
113
+ // Where a stacked task's pull request goes once its work is done, as the step
114
+ // `task-base#<id>`: its base, or, when the layer below merged while the task
115
+ // was implemented (and its branch was deleted with it), the branch that one
116
+ // merged into, and as far down as the layers below it merged too (#249). The
117
+ // work is brought up to date with the new base as a stack's layer is
118
+ // (Stack.updateFromBase): a squash or rebase of the layer below is recorded as
119
+ // already here, so its review shows only the task's change, and its edits of
120
+ // lines that layer added are no conflict. A merge that conflicts is undone and
121
+ // left to resolve-conflicts, as any conflict with its base is.
122
+ const TaskBase = Schema.Struct({ base: Schema.String });
123
+
124
+ const settleBase = (id: string, claimed: Option.Option<string>, worktree: string) =>
125
+ activity(
126
+ `task-base#${id}`,
127
+ Effect.gen(function* () {
128
+ const github = yield* GitHub;
129
+ const integration = yield* Settings.base;
130
+ const base = Option.getOrElse(claimed, () => integration);
131
+ let target = base;
132
+ // The merged pull request whose base is `target`.
133
+ let lower = Option.none<number>();
134
+
135
+ while (target !== integration) {
136
+ const below = Option.filter(
137
+ yield* github.pullRequestForBranch(target),
138
+ (pull) => pull.state === "merged",
139
+ );
140
+
141
+ if (Option.isNone(below)) {
142
+ break;
143
+ }
144
+
145
+ target = below.value.baseRef;
146
+ lower = Option.some(below.value.number);
147
+ }
148
+
149
+ if (Option.isNone(lower)) {
150
+ return { base };
151
+ }
152
+
153
+ const updated = yield* Stack.updateFromBase(worktree, { lower: lower.value });
154
+
155
+ if (!updated.clean) {
156
+ const git = yield* Git;
157
+ yield* git.run(["merge", "--abort"], worktree).pipe(Effect.ignore);
158
+ }
159
+
160
+ return { base: updated.base };
161
+ }),
162
+ TaskBase,
163
+ );
164
+
113
165
  // Implements one ready task as implement does, on its base, with its own
114
166
  // steps and session. A task that needs a person is handed to one, and lets
115
167
  // its claim go; the run carries on with the rest either way.
116
- const implementTask = (epic: number, task: Epic.Layer, attempt: number, ships: boolean) =>
168
+ const implementTask = (
169
+ epic: number,
170
+ task: Epic.Layer,
171
+ attempt: number,
172
+ ships: boolean,
173
+ withPerson: Set<number>,
174
+ ) =>
117
175
  Effect.gen(function* () {
118
176
  const issue = task.number;
119
177
  const id = attemptId(issue, attempt);
@@ -122,6 +180,7 @@ const implementTask = (epic: number, task: Epic.Layer, attempt: number, ships: b
122
180
  const toPerson = (reason: string) =>
123
181
  Implement.handToHuman(issue, reason, pullRequest, { id }).pipe(
124
182
  Effect.tap(() => releaseTask(issue, id)),
183
+ Effect.tap(() => Effect.sync(() => withPerson.add(issue))),
125
184
  );
126
185
 
127
186
  return yield* Effect.gen(function* () {
@@ -139,10 +198,11 @@ const implementTask = (epic: number, task: Epic.Layer, attempt: number, ships: b
139
198
 
140
199
  return yield* Effect.gen(function* () {
141
200
  yield* Implement.localGate(worktree, { id, session });
142
- yield* Implement.push(`push#${id}`, worktree, branch, { base });
201
+ const settled = yield* settleBase(id, Option.fromUndefinedOr(base), worktree);
202
+ yield* Implement.push(`push#${id}`, worktree, branch, { base: settled.base });
143
203
 
144
204
  const opened = yield* Implement.openPullRequest(issue, outcome, {
145
- base,
205
+ base: settled.base,
146
206
  id,
147
207
  partOf: epic,
148
208
  ...(yield* queuedAs(ships)),
@@ -150,7 +210,12 @@ const implementTask = (epic: number, task: Epic.Layer, attempt: number, ships: b
150
210
 
151
211
  pullRequest = Option.some(opened.number);
152
212
 
153
- yield* Implement.waitForCi(opened.number, worktree, { ...session, branch, base }, { id });
213
+ yield* Implement.waitForCi(
214
+ opened.number,
215
+ worktree,
216
+ { ...session, branch, base: settled.base },
217
+ { id },
218
+ );
154
219
 
155
220
  return yield* Implement.handOff(issue, opened, outcome, { needsReview: true, id });
156
221
  }).pipe(
@@ -637,12 +702,16 @@ const land = (round: number, progress: Epic.Progress, upkeep: Upkeep) =>
637
702
  // attempted starts again only once it has read as something other than ready
638
703
  // since, as one a person handed back with auto:eligible after its questions
639
704
  // or a hand-off has; one still ready after its attempt, as one another run
640
- // holds, waits. The counts are rebuilt from the rounds' saved results
641
- // whenever the run resumes.
705
+ // holds, waits. An attempt that ended with a person counts as read so: a
706
+ // round runs only once every task started with it ends, so a person may hand
707
+ // the task back before any round reads it with them (#249). The counts are
708
+ // rebuilt from the rounds' saved results whenever the run resumes.
642
709
  const workThrough = (epic: number, ships: boolean, concurrency: number) =>
643
710
  Effect.gen(function* () {
644
711
  const attempts = new Map<number, number>();
645
712
  const handedBack = new Set<number>();
713
+ // Tasks whose attempt ended with a person.
714
+ const withPerson = new Set<number>();
646
715
 
647
716
  const upkeep: Upkeep = {
648
717
  attempts: new Map(),
@@ -671,8 +740,12 @@ const workThrough = (epic: number, ships: boolean, concurrency: number) =>
671
740
  }
672
741
 
673
742
  for (const layer of progress.layers) {
674
- if (attempts.has(layer.number) && layer.state !== "ready") {
743
+ if (
744
+ attempts.has(layer.number) &&
745
+ (layer.state !== "ready" || withPerson.has(layer.number))
746
+ ) {
675
747
  handedBack.add(layer.number);
748
+ withPerson.delete(layer.number);
676
749
  }
677
750
  }
678
751
 
@@ -691,7 +764,7 @@ const workThrough = (epic: number, ships: boolean, concurrency: number) =>
691
764
 
692
765
  yield* Effect.forEach(
693
766
  starts,
694
- (start) => implementTask(epic, start.task, start.attempt, ships),
767
+ (start) => implementTask(epic, start.task, start.attempt, ships, withPerson),
695
768
  {
696
769
  concurrency,
697
770
  discard: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chernabog/recipes",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "license": "MIT",
5
5
  "description": "Chernabog's recipes: complete flows a repo copies in, or imports, written from @chernabog/sdk",
6
6
  "repository": {
@@ -57,12 +57,12 @@ When the issue already lays out the work as separate pull requests (usually a ch
57
57
 
58
58
  {{localGate}}
59
59
 
60
- Commit messages follow the repo's convention. When the repo has a `commitlint.config.*`, that means conventional commits, `type(scope): summary` with `Refs #{{issue}}` in the body; in a published library, pick the type for what the change does to the package's users, and never mark a commit breaking. Without commitlint, prefix commits `[#{{issue}}]`.
60
+ Commit messages follow the repo's convention. A repo uses conventional commits, `type(scope): summary` with `Refs #{{issue}}` in the body, when it has a `commitlint.config.*`, a CI check on pull request titles, or release-please, or when the recent commits on its base branch follow it; in a published library, pick the type for what the change does to the package's users, and never mark a commit breaking. Only in a repo with none of those, prefix commits `[#{{issue}}]`.
61
61
 
62
62
  ## Your final answer
63
63
 
64
64
  - `status`: `done` when the work is committed, or `needs-clarification`.
65
- - `title`: the pull request title. Under commitlint it is a conventional commit, because a squash merge uses it; otherwise `[#{{issue}}] <summary>`.
65
+ - `title`: the pull request title. In a repo that uses conventional commits it is one, with nothing before the type, because a squash merge makes it the commit; otherwise `[#{{issue}}] <summary>`.
66
66
  - `body`: the pull request body in Markdown: what changed and why, how it was tested (including anything you could not run locally), and **Decisions made without a person**. Chernabog adds the `Closes #{{issue}}` line.
67
67
  - `summary`: two or three sentences for the issue: what changed, how it was tested, and what a reviewer should look at first.
68
68
  - `questions`, for `needs-clarification` only: specific, numbered questions. Lead each with what you recommend and why, then what you would do under each answer. Add one line naming the document that would have let you decide this yourself.