@pierre/storage 0.8.0 → 0.9.0
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 +42 -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 +42 -9
- package/dist/index.js.map +1 -1
- package/package.json +38 -39
- package/src/index.ts +41 -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.0"};
|
|
510
510
|
|
|
511
511
|
// src/version.ts
|
|
512
512
|
var PACKAGE_NAME = "code-storage-sdk";
|
|
@@ -2273,23 +2273,56 @@ 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
|
+
name: baseRepo.id,
|
|
2289
|
+
operation: "fork",
|
|
2290
|
+
auth: { token: baseRepoToken },
|
|
2291
|
+
...baseRepo.ref ? { ref: baseRepo.ref } : {},
|
|
2292
|
+
...baseRepo.sha ? { sha: baseRepo.sha } : {}
|
|
2293
|
+
};
|
|
2294
|
+
} else {
|
|
2295
|
+
baseRepoOptions = {
|
|
2296
|
+
provider: "github",
|
|
2297
|
+
...snakecaseKeys__default.default(baseRepo)
|
|
2298
|
+
};
|
|
2299
|
+
resolvedDefaultBranch = baseRepo.defaultBranch;
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
|
+
if (!resolvedDefaultBranch) {
|
|
2303
|
+
if (options?.defaultBranch) {
|
|
2304
|
+
resolvedDefaultBranch = options.defaultBranch;
|
|
2305
|
+
} else if (!isFork) {
|
|
2306
|
+
resolvedDefaultBranch = "main";
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
const createRepoPath = baseRepoOptions || resolvedDefaultBranch ? {
|
|
2282
2310
|
path: "repos",
|
|
2283
2311
|
body: {
|
|
2284
2312
|
...baseRepoOptions && { base_repo: baseRepoOptions },
|
|
2285
|
-
default_branch:
|
|
2313
|
+
...resolvedDefaultBranch && { default_branch: resolvedDefaultBranch }
|
|
2286
2314
|
}
|
|
2287
2315
|
} : "repos";
|
|
2288
2316
|
const resp = await this.api.post(createRepoPath, jwt, { allowedStatus: [409] });
|
|
2289
2317
|
if (resp.status === 409) {
|
|
2290
2318
|
throw new Error("Repository already exists");
|
|
2291
2319
|
}
|
|
2292
|
-
return new RepoImpl(
|
|
2320
|
+
return new RepoImpl(
|
|
2321
|
+
repoId,
|
|
2322
|
+
resolvedDefaultBranch ?? "main",
|
|
2323
|
+
this.options,
|
|
2324
|
+
this.generateJWT.bind(this)
|
|
2325
|
+
);
|
|
2293
2326
|
}
|
|
2294
2327
|
/**
|
|
2295
2328
|
* List repositories for the authenticated organization
|