create-op-node 0.11.1 → 0.11.3

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/dist/cli.js CHANGED
@@ -259,12 +259,12 @@ async function fetchOutput(auth, workspaceId, outputName) {
259
259
  auth.token,
260
260
  `/workspaces/${encodeURIComponent(workspaceId)}/current-state-version-outputs`
261
261
  );
262
- if (res.status !== 200) return null;
262
+ if (res.status !== 200) return { kind: "error" };
263
263
  const body = res.body;
264
264
  const match = body.data?.find((o) => o.attributes?.name === outputName);
265
- if (!match) return null;
265
+ if (!match) return { kind: "absent" };
266
266
  const value = match.attributes?.value;
267
- return typeof value === "string" ? value : null;
267
+ return typeof value === "string" ? { kind: "value", value } : { kind: "absent" };
268
268
  }
269
269
  async function safeExeca(cmd, args, options) {
270
270
  try {
@@ -444,6 +444,16 @@ async function createRepoFromTemplate(input) {
444
444
  defaultBranch: res.data.default_branch ?? "main"
445
445
  };
446
446
  }
447
+ async function getRepoDefaultBranch(input) {
448
+ const parsed = parseRepoSlug(input.repo);
449
+ if (!parsed) return null;
450
+ try {
451
+ const res = await client(input.token).repos.get({ owner: parsed.owner, repo: parsed.repo });
452
+ return res.data.default_branch ?? null;
453
+ } catch {
454
+ return null;
455
+ }
456
+ }
447
457
  function parseRepoSlug(repo) {
448
458
  const slash = repo.indexOf("/");
449
459
  if (slash <= 0 || slash === repo.length - 1 || repo.indexOf("/", slash + 1) !== -1) return null;
@@ -699,21 +709,28 @@ async function waitForRunOutput(input, budgets, deps, runId) {
699
709
  );
700
710
  if (r?.finished) {
701
711
  if (!r.succeeded) return { kind: "run-failed", status: r.status };
702
- deps.onProgress?.("fetching");
703
- const value = await safePoll(
704
- () => deps.fetchOutput(
705
- { token: input.token, organization: input.organization },
706
- input.workspaceId,
707
- input.outputName
708
- ),
709
- () => deps.onProgress?.("retry")
710
- );
711
- return value !== null ? { kind: "success", value } : { kind: "output-missing" };
712
+ const out = await tryFetchOutput(input, deps);
713
+ if (out.kind === "value") return { kind: "success", value: out.value };
714
+ if (out.kind === "absent") return { kind: "output-missing" };
712
715
  }
713
716
  await deps.sleep(budgets.pollMs);
714
717
  }
715
718
  return { kind: "timeout" };
716
719
  }
720
+ async function tryFetchOutput(input, deps) {
721
+ deps.onProgress?.("fetching");
722
+ const out = await safePoll(
723
+ () => deps.fetchOutput(
724
+ { token: input.token, organization: input.organization },
725
+ input.workspaceId,
726
+ input.outputName
727
+ ),
728
+ () => deps.onProgress?.("retry")
729
+ );
730
+ if (out === null) return { kind: "error" };
731
+ if (out.kind === "error") deps.onProgress?.("retry");
732
+ return out;
733
+ }
717
734
 
718
735
  // src/commands/init.ts
719
736
  async function ghTokenFromCli() {
@@ -915,7 +932,16 @@ async function createRegionRepo(args) {
915
932
  );
916
933
  process.exit(0);
917
934
  }
918
- return { fullName: newRepoFull, defaultBranch: "main" };
935
+ const fetched = await getRepoDefaultBranch({ token: ghToken, repo: newRepoFull });
936
+ if (fetched === null) {
937
+ p3.note(
938
+ pc2.yellow(
939
+ `\u26A0 Couldn't read ${newRepoFull}'s default branch \u2014 assuming "main". If the branch/PR steps fail, check the repo's default branch on GitHub.`
940
+ ),
941
+ "Notice"
942
+ );
943
+ }
944
+ return { fullName: newRepoFull, defaultBranch: fetched ?? "main" };
919
945
  }
920
946
  }
921
947
  async function seedRepoSecrets(args) {
@@ -4978,7 +5004,7 @@ function withDefaultSubcommand(argv, known) {
4978
5004
  }
4979
5005
 
4980
5006
  // src/cli.ts
4981
- var VERSION = "0.11.1";
5007
+ var VERSION = "0.11.3";
4982
5008
  var program = new Command();
4983
5009
  program.name("create-op-node").description(
4984
5010
  "Interactive bootstrap for an Opus Populi federation node.\nCloudflare infrastructure \u2192 Mac Studio \u2192 live public API."