@bakers-build/addon-forge 0.9.1-next.9 → 0.10.1-next.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.
@@ -42,9 +42,11 @@ export interface ForgeBackend {
42
42
  title: string;
43
43
  body: string;
44
44
  }): Promise<ForgePr>;
45
+ /** Also retargets the PR to `base`, which may have moved since it opened. */
45
46
  updatePr(pr: ForgePr, input: {
46
47
  title: string;
47
48
  body: string;
49
+ base: string;
48
50
  }): Promise<ForgePr>;
49
51
  openPrsWithBase(base: string): Promise<ForgePr[]>;
50
52
  /**
package/dist/src/tools.js CHANGED
@@ -17,6 +17,25 @@ function runOf(req) {
17
17
  ...(t.targetBranch ? { targetBranch: t.targetBranch } : {}),
18
18
  };
19
19
  }
20
+ /**
21
+ * Where `branch` merges: a variant into the ticket branch, the ticket branch into
22
+ * the ticket's current target as the server returns it now. A failed read refuses;
23
+ * the run copy may predate an environment added during the run.
24
+ */
25
+ async function currentBase(req, branch, run) {
26
+ if (branch !== run.branchName)
27
+ return derivedBase(branch, run);
28
+ const refuse = (why) => new Error(`forge: the ticket's current target_branch could not be read from the server (${why}); nothing was sent`);
29
+ if (!req.currentTicket)
30
+ throw refuse('no server read for this call');
31
+ const t = await req.currentTicket().catch((err) => {
32
+ throw refuse(err instanceof Error ? err.message : String(err));
33
+ });
34
+ const target = t.targetBranch ?? t.baseBranch;
35
+ if (!target)
36
+ throw refuse('no target_branch or base_branch returned');
37
+ return target;
38
+ }
20
39
  function ownedBranch(req, run) {
21
40
  const branch = req.args.branch ?? run.branchName;
22
41
  if (!isOwned(branch, run.branchName))
@@ -98,13 +117,14 @@ export function forgeTools(deps) {
98
117
  const run = runOf(req);
99
118
  const branch = ownedBranch(req, run);
100
119
  const body = req.args.body ?? '';
120
+ const base = await currentBase(req, branch, run);
101
121
  const b = await backend();
102
122
  const open = await b.findOpenPr(branch);
103
123
  const pr = open
104
- ? await b.updatePr(open, { title, body })
124
+ ? await b.updatePr(open, { title, body, base })
105
125
  : await b.createPr({
106
126
  head: branch,
107
- base: derivedBase(branch, run),
127
+ base,
108
128
  title,
109
129
  body,
110
130
  });
@@ -137,7 +157,7 @@ export function forgeTools(deps) {
137
157
  forge_merge: async (req) => {
138
158
  const run = runOf(req);
139
159
  const branch = ownedBranch(req, run);
140
- const base = derivedBase(branch, run);
160
+ const base = await currentBase(req, branch, run);
141
161
  const b = await backend();
142
162
  const pr = await b.findOpenPr(branch);
143
163
  if (!pr)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-forge",
3
- "version": "0.9.1-next.9",
3
+ "version": "0.10.1-next.1",
4
4
  "description": "bakers.build forge tools: a sandboxed run fetches, pushes its own branches, opens its PR/MR, reads checks and merges through the conductor, which holds the token. Backends implement the ForgeBackend contract (./backend).",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -22,11 +22,11 @@
22
22
  "directory": "bakers-cli/addons/forge"
23
23
  },
24
24
  "peerDependencies": {
25
- "@bakers-build/conductor": "^0.9.1-next.9",
26
- "@bakers-build/core": "^0.9.1-next.9"
25
+ "@bakers-build/conductor": "^0.10.1-next.1",
26
+ "@bakers-build/core": "^0.10.1-next.1"
27
27
  },
28
28
  "bakersBuild": {
29
- "commit": "fa0565441ae1aee6535c9205b3a37f87e9b52054",
29
+ "commit": "f9cee7721df536cac94906e7278d60a13e202502",
30
30
  "channel": "next"
31
31
  }
32
32
  }