@pierre/storage 0.2.1 → 0.2.2

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/README.md CHANGED
@@ -129,6 +129,15 @@ const commitDiff = await repo.getCommitDiff({
129
129
  console.log(commitDiff.stats);
130
130
  console.log(commitDiff.files);
131
131
 
132
+ // Create a new branch from an existing one
133
+ const branch = await repo.createBranch({
134
+ baseBranch: 'main',
135
+ targetBranch: 'feature/demo',
136
+ // baseIsEphemeral: true,
137
+ // targetIsEphemeral: true,
138
+ });
139
+ console.log(branch.targetBranch, branch.commitSha);
140
+
132
141
  // Create a commit using the streaming helper
133
142
  const fs = await import('node:fs/promises');
134
143
  const result = await repo
package/dist/index.cjs CHANGED
@@ -110,6 +110,12 @@ var commitDiffResponseSchema = zod.z.object({
110
110
  files: zod.z.array(diffFileRawSchema),
111
111
  filtered_files: zod.z.array(filteredFileRawSchema)
112
112
  });
113
+ var createBranchResponseSchema = zod.z.object({
114
+ message: zod.z.string(),
115
+ target_branch: zod.z.string(),
116
+ target_is_ephemeral: zod.z.boolean(),
117
+ commit_sha: zod.z.string().nullable().optional()
118
+ });
113
119
  var refUpdateResultSchema = zod.z.object({
114
120
  branch: zod.z.string(),
115
121
  old_sha: zod.z.string(),
@@ -1491,6 +1497,14 @@ function transformCommitDiffResult(raw) {
1491
1497
  filteredFiles: raw.filtered_files.map(transformFilteredFile)
1492
1498
  };
1493
1499
  }
1500
+ function transformCreateBranchResult(raw) {
1501
+ return {
1502
+ message: raw.message,
1503
+ targetBranch: raw.target_branch,
1504
+ targetIsEphemeral: raw.target_is_ephemeral,
1505
+ commitSha: raw.commit_sha ?? void 0
1506
+ };
1507
+ }
1494
1508
  var RepoImpl = class {
1495
1509
  constructor(id, options, generateJWT) {
1496
1510
  this.id = id;
@@ -1626,7 +1640,7 @@ var RepoImpl = class {
1626
1640
  const raw = commitDiffResponseSchema.parse(await response.json());
1627
1641
  return transformCommitDiffResult(raw);
1628
1642
  }
1629
- async pullUpstream(options) {
1643
+ async pullUpstream(options = {}) {
1630
1644
  const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
1631
1645
  const jwt = await this.generateJWT(this.id, {
1632
1646
  permissions: ["git:write"],
@@ -1642,6 +1656,34 @@ var RepoImpl = class {
1642
1656
  }
1643
1657
  return;
1644
1658
  }
1659
+ async createBranch(options) {
1660
+ const baseBranch = options?.baseBranch?.trim();
1661
+ if (!baseBranch) {
1662
+ throw new Error("createBranch baseBranch is required");
1663
+ }
1664
+ const targetBranch = options?.targetBranch?.trim();
1665
+ if (!targetBranch) {
1666
+ throw new Error("createBranch targetBranch is required");
1667
+ }
1668
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
1669
+ const jwt = await this.generateJWT(this.id, {
1670
+ permissions: ["git:write"],
1671
+ ttl
1672
+ });
1673
+ const body = {
1674
+ base_branch: baseBranch,
1675
+ target_branch: targetBranch
1676
+ };
1677
+ if (options.baseIsEphemeral === true) {
1678
+ body.base_is_ephemeral = true;
1679
+ }
1680
+ if (options.targetIsEphemeral === true) {
1681
+ body.target_is_ephemeral = true;
1682
+ }
1683
+ const response = await this.api.post({ path: "repos/branches/create", body }, jwt);
1684
+ const raw = createBranchResponseSchema.parse(await response.json());
1685
+ return transformCreateBranchResult(raw);
1686
+ }
1645
1687
  async restoreCommit(options) {
1646
1688
  const targetBranch = options?.targetBranch?.trim();
1647
1689
  if (!targetBranch) {