@theholocron/cli 2.0.0-alpha.12 → 2.0.0-alpha.14

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.
Files changed (2) hide show
  1. package/dist/cli.mjs +32 -9
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -1361,8 +1361,10 @@ name: Sync GitHub Templates
1361
1361
  # template source files change on main or alpha.
1362
1362
  #
1363
1363
  # Secrets required:
1364
- # SYNC_TOKEN — fine-grained PAT or GitHub App token with Contents write
1365
- # access to the primary and secondary repos.
1364
+ # SYNC_TOKEN — fine-grained PAT (resource owner: org) with:
1365
+ # Contents: Read and write (git trees, blobs, refs)
1366
+ # Pull requests: Read and write (open sync PR)
1367
+ # Workflows: Read and write (write .github/workflows/*.yml)
1366
1368
 
1367
1369
  on: # yamllint disable-line rule:truthy
1368
1370
  workflow_call:
@@ -1839,7 +1841,8 @@ async function runSyncGithub(input) {
1839
1841
  };
1840
1842
  }
1841
1843
  let targetBranch = branch;
1842
- if (!targetBranch) {
1844
+ let defaultBranch;
1845
+ if (!targetBranch || createPr) {
1843
1846
  const repoRes = await fetchFn(`${API_BASE}/repos/${owner}/${repoName}`, { headers });
1844
1847
  if (!repoRes.ok) {
1845
1848
  const msg = "failed to fetch repo metadata";
@@ -1852,11 +1855,13 @@ async function runSyncGithub(input) {
1852
1855
  message: msg
1853
1856
  };
1854
1857
  }
1855
- targetBranch = (await repoRes.json()).default_branch;
1858
+ defaultBranch = (await repoRes.json()).default_branch;
1859
+ if (!targetBranch) targetBranch = defaultBranch;
1856
1860
  }
1857
- const refRes = await fetchFn(`${API_BASE}/repos/${owner}/${repoName}/git/ref/heads/${targetBranch}`, { headers });
1861
+ const baseBranch = createPr && defaultBranch ? defaultBranch : targetBranch;
1862
+ const refRes = await fetchFn(`${API_BASE}/repos/${owner}/${repoName}/git/ref/heads/${baseBranch}`, { headers });
1858
1863
  if (!refRes.ok) {
1859
- const msg = `Branch ${targetBranch} not found`;
1864
+ const msg = `Branch ${baseBranch} not found`;
1860
1865
  print(` ✗ ${msg}`);
1861
1866
  return {
1862
1867
  status: "fail",
@@ -1979,13 +1984,31 @@ async function runSyncGithub(input) {
1979
1984
  };
1980
1985
  }
1981
1986
  const { sha: newCommitSha } = await newCommitRes.json();
1982
- const updateRefRes = await fetchFn(`${API_BASE}/repos/${owner}/${repoName}/git/refs/heads/${targetBranch}`, {
1987
+ let refUpdateRes;
1988
+ if (createPr && branch) {
1989
+ refUpdateRes = await fetchFn(`${API_BASE}/repos/${owner}/${repoName}/git/refs`, {
1990
+ method: "POST",
1991
+ headers,
1992
+ body: JSON.stringify({
1993
+ ref: `refs/heads/${branch}`,
1994
+ sha: newCommitSha
1995
+ })
1996
+ });
1997
+ if (refUpdateRes.status === 422) refUpdateRes = await fetchFn(`${API_BASE}/repos/${owner}/${repoName}/git/refs/heads/${branch}`, {
1998
+ method: "PATCH",
1999
+ headers,
2000
+ body: JSON.stringify({
2001
+ sha: newCommitSha,
2002
+ force: true
2003
+ })
2004
+ });
2005
+ } else refUpdateRes = await fetchFn(`${API_BASE}/repos/${owner}/${repoName}/git/refs/heads/${targetBranch}`, {
1983
2006
  method: "PATCH",
1984
2007
  headers,
1985
2008
  body: JSON.stringify({ sha: newCommitSha })
1986
2009
  });
1987
- if (!updateRefRes.ok) {
1988
- const msg = `failed to update ref: ${(await updateRefRes.json()).message ?? updateRefRes.status}`;
2010
+ if (!refUpdateRes.ok) {
2011
+ const msg = `failed to update ref: ${(await refUpdateRes.json()).message ?? refUpdateRes.status}`;
1989
2012
  print(` ✗ ${msg}`);
1990
2013
  return {
1991
2014
  status: "fail",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/cli",
3
- "version": "2.0.0-alpha.12",
3
+ "version": "2.0.0-alpha.14",
4
4
  "description": "The Holocron CLI — a pluggable, capability-based orchestrator for spinning up and operating software projects.",
5
5
  "homepage": "https://github.com/theholocron/holocron/tree/main/packages/cli#readme",
6
6
  "bugs": "https://github.com/theholocron/holocron/issues",