@pierre/storage 0.8.0 → 0.9.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/README.md +23 -0
- package/dist/index.cjs +43 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +43 -9
- package/dist/index.js.map +1 -1
- package/package.json +38 -39
- package/src/index.ts +42 -9
- package/src/types.ts +9 -1
package/README.md
CHANGED
|
@@ -40,6 +40,16 @@ console.log(repo.id); // e.g., '123e4567-e89b-12d3-a456-426614174000'
|
|
|
40
40
|
// Create a repository with custom ID
|
|
41
41
|
const customRepo = await store.createRepo({ id: 'my-custom-repo' });
|
|
42
42
|
console.log(customRepo.id); // 'my-custom-repo'
|
|
43
|
+
|
|
44
|
+
// Create a repository by forking an existing repo
|
|
45
|
+
const forkedRepo = await store.createRepo({
|
|
46
|
+
id: 'my-fork', // optional
|
|
47
|
+
baseRepo: {
|
|
48
|
+
id: 'my-template-id',
|
|
49
|
+
ref: 'main', // optional
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
// If defaultBranch is omitted, the SDK returns "main".
|
|
43
53
|
```
|
|
44
54
|
|
|
45
55
|
### Finding a Repository
|
|
@@ -337,6 +347,19 @@ interface GitStorageOptions {
|
|
|
337
347
|
|
|
338
348
|
interface CreateRepoOptions {
|
|
339
349
|
id?: string; // Optional custom repository ID
|
|
350
|
+
baseRepo?:
|
|
351
|
+
| {
|
|
352
|
+
id: string; // Fork source repo ID
|
|
353
|
+
ref?: string; // Optional ref to fork from
|
|
354
|
+
sha?: string; // Optional commit SHA to fork from
|
|
355
|
+
}
|
|
356
|
+
| {
|
|
357
|
+
owner: string; // GitHub owner
|
|
358
|
+
name: string; // GitHub repository name
|
|
359
|
+
defaultBranch?: string;
|
|
360
|
+
provider?: 'github';
|
|
361
|
+
};
|
|
362
|
+
defaultBranch?: string; // Optional default branch name (defaults to "main")
|
|
340
363
|
}
|
|
341
364
|
|
|
342
365
|
interface FindOneOptions {
|
package/dist/index.cjs
CHANGED
|
@@ -506,7 +506,7 @@ function concatChunks(a, b) {
|
|
|
506
506
|
|
|
507
507
|
// package.json
|
|
508
508
|
var package_default = {
|
|
509
|
-
version: "0.
|
|
509
|
+
version: "0.9.1"};
|
|
510
510
|
|
|
511
511
|
// src/version.ts
|
|
512
512
|
var PACKAGE_NAME = "code-storage-sdk";
|
|
@@ -2273,23 +2273,57 @@ var GitStorage = class _GitStorage {
|
|
|
2273
2273
|
permissions: ["repo:write"],
|
|
2274
2274
|
ttl
|
|
2275
2275
|
});
|
|
2276
|
-
const
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2276
|
+
const baseRepo = options?.baseRepo;
|
|
2277
|
+
const isFork = baseRepo ? "id" in baseRepo : false;
|
|
2278
|
+
let baseRepoOptions = null;
|
|
2279
|
+
let resolvedDefaultBranch;
|
|
2280
|
+
if (baseRepo) {
|
|
2281
|
+
if ("id" in baseRepo) {
|
|
2282
|
+
const baseRepoToken = await this.generateJWT(baseRepo.id, {
|
|
2283
|
+
permissions: ["git:read"],
|
|
2284
|
+
ttl
|
|
2285
|
+
});
|
|
2286
|
+
baseRepoOptions = {
|
|
2287
|
+
provider: "code",
|
|
2288
|
+
owner: this.options.name,
|
|
2289
|
+
name: baseRepo.id,
|
|
2290
|
+
operation: "fork",
|
|
2291
|
+
auth: { token: baseRepoToken },
|
|
2292
|
+
...baseRepo.ref ? { ref: baseRepo.ref } : {},
|
|
2293
|
+
...baseRepo.sha ? { sha: baseRepo.sha } : {}
|
|
2294
|
+
};
|
|
2295
|
+
} else {
|
|
2296
|
+
baseRepoOptions = {
|
|
2297
|
+
provider: "github",
|
|
2298
|
+
...snakecaseKeys__default.default(baseRepo)
|
|
2299
|
+
};
|
|
2300
|
+
resolvedDefaultBranch = baseRepo.defaultBranch;
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
if (!resolvedDefaultBranch) {
|
|
2304
|
+
if (options?.defaultBranch) {
|
|
2305
|
+
resolvedDefaultBranch = options.defaultBranch;
|
|
2306
|
+
} else if (!isFork) {
|
|
2307
|
+
resolvedDefaultBranch = "main";
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2310
|
+
const createRepoPath = baseRepoOptions || resolvedDefaultBranch ? {
|
|
2282
2311
|
path: "repos",
|
|
2283
2312
|
body: {
|
|
2284
2313
|
...baseRepoOptions && { base_repo: baseRepoOptions },
|
|
2285
|
-
default_branch:
|
|
2314
|
+
...resolvedDefaultBranch && { default_branch: resolvedDefaultBranch }
|
|
2286
2315
|
}
|
|
2287
2316
|
} : "repos";
|
|
2288
2317
|
const resp = await this.api.post(createRepoPath, jwt, { allowedStatus: [409] });
|
|
2289
2318
|
if (resp.status === 409) {
|
|
2290
2319
|
throw new Error("Repository already exists");
|
|
2291
2320
|
}
|
|
2292
|
-
return new RepoImpl(
|
|
2321
|
+
return new RepoImpl(
|
|
2322
|
+
repoId,
|
|
2323
|
+
resolvedDefaultBranch ?? "main",
|
|
2324
|
+
this.options,
|
|
2325
|
+
this.generateJWT.bind(this)
|
|
2326
|
+
);
|
|
2293
2327
|
}
|
|
2294
2328
|
/**
|
|
2295
2329
|
* List repositories for the authenticated organization
|