@sparted/shared-library 1.0.8-alpha.0 → 1.0.8-alpha.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.
Files changed (61) hide show
  1. package/dist/github/branch/create-branch.d.ts +11 -0
  2. package/dist/github/branch/create-branch.js +27 -0
  3. package/dist/github/branch/create-branch.js.map +1 -0
  4. package/dist/github/branch/index.d.ts +2 -0
  5. package/dist/github/branch/index.js +12 -0
  6. package/dist/github/branch/index.js.map +1 -0
  7. package/dist/github/branch/update-branch.d.ts +11 -0
  8. package/dist/github/branch/update-branch.js +26 -0
  9. package/dist/github/branch/update-branch.js.map +1 -0
  10. package/dist/github/commit/create-git-blob.js.map +1 -0
  11. package/dist/github/commit/create-git-commit.js.map +1 -0
  12. package/dist/github/commit/create-git-tree.js.map +1 -0
  13. package/dist/github/commit/get-sha-last-commit-of-branch.js.map +1 -0
  14. package/dist/github/commit/get-tree-by-commit-sha.js.map +1 -0
  15. package/dist/github/commit/run-new-commit-process.js.map +1 -0
  16. package/dist/github/commit/utils.js.map +1 -0
  17. package/dist/github/content/get-file-content.d.ts +20 -0
  18. package/dist/github/content/get-file-content.js +38 -0
  19. package/dist/github/content/get-file-content.js.map +1 -0
  20. package/dist/github/github.d.ts +8 -9
  21. package/dist/github/github.js +15 -6
  22. package/dist/github/github.js.map +1 -1
  23. package/dist/package.json +3 -3
  24. package/package.json +3 -3
  25. package/src/github/branch/create-branch.ts +36 -0
  26. package/src/github/branch/index.ts +2 -0
  27. package/src/github/branch/update-branch.ts +35 -0
  28. package/src/github/content/get-file-content.ts +50 -0
  29. package/src/github/github.ts +18 -3
  30. package/dist/github/commits/create-git-blob.js.map +0 -1
  31. package/dist/github/commits/create-git-commit.js.map +0 -1
  32. package/dist/github/commits/create-git-tree.js.map +0 -1
  33. package/dist/github/commits/get-sha-last-commit-of-branch.js.map +0 -1
  34. package/dist/github/commits/get-tree-by-commit-sha.js.map +0 -1
  35. package/dist/github/commits/run-new-commit-process.js.map +0 -1
  36. package/dist/github/commits/utils.js.map +0 -1
  37. /package/dist/github/{commits → commit}/create-git-blob.d.ts +0 -0
  38. /package/dist/github/{commits → commit}/create-git-blob.js +0 -0
  39. /package/dist/github/{commits → commit}/create-git-commit.d.ts +0 -0
  40. /package/dist/github/{commits → commit}/create-git-commit.js +0 -0
  41. /package/dist/github/{commits → commit}/create-git-tree.d.ts +0 -0
  42. /package/dist/github/{commits → commit}/create-git-tree.js +0 -0
  43. /package/dist/github/{commits → commit}/get-sha-last-commit-of-branch.d.ts +0 -0
  44. /package/dist/github/{commits → commit}/get-sha-last-commit-of-branch.js +0 -0
  45. /package/dist/github/{commits → commit}/get-tree-by-commit-sha.d.ts +0 -0
  46. /package/dist/github/{commits → commit}/get-tree-by-commit-sha.js +0 -0
  47. /package/dist/github/{commits → commit}/index.d.ts +0 -0
  48. /package/dist/github/{commits → commit}/index.js +0 -0
  49. /package/dist/github/{commits → commit}/index.js.map +0 -0
  50. /package/dist/github/{commits → commit}/run-new-commit-process.d.ts +0 -0
  51. /package/dist/github/{commits → commit}/run-new-commit-process.js +0 -0
  52. /package/dist/github/{commits → commit}/utils.d.ts +0 -0
  53. /package/dist/github/{commits → commit}/utils.js +0 -0
  54. /package/src/github/{commits → commit}/create-git-blob.ts +0 -0
  55. /package/src/github/{commits → commit}/create-git-commit.ts +0 -0
  56. /package/src/github/{commits → commit}/create-git-tree.ts +0 -0
  57. /package/src/github/{commits → commit}/get-sha-last-commit-of-branch.ts +0 -0
  58. /package/src/github/{commits → commit}/get-tree-by-commit-sha.ts +0 -0
  59. /package/src/github/{commits → commit}/index.ts +0 -0
  60. /package/src/github/{commits → commit}/run-new-commit-process.ts +0 -0
  61. /package/src/github/{commits → commit}/utils.ts +0 -0
@@ -0,0 +1,11 @@
1
+ import { AxiosInstance } from 'axios';
2
+ export declare type CreateBranchArgs = {
3
+ branchName: string;
4
+ shaLastCommitOfBranch: string;
5
+ };
6
+ export declare type CreateBranchResponse = {
7
+ sha: string;
8
+ };
9
+ export declare type CreateBranch = (args: CreateBranchArgs) => Promise<CreateBranchResponse>;
10
+ export declare type CreateBranchFactory = (instance: AxiosInstance) => CreateBranch;
11
+ export declare const createBranchFactory: CreateBranchFactory;
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('../../_virtual/_tslib.js');
6
+ var zod = require('zod');
7
+ var utils = require('../commit/utils.js');
8
+
9
+ const createBranchResponseSchema = zod.z.object({
10
+ sha: zod.z.string(),
11
+ });
12
+ const createBranchFactory = (instance) => (args) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
13
+ const { branchName, shaLastCommitOfBranch } = args;
14
+ try {
15
+ const { data } = yield instance.post('/git/refs', {
16
+ ref: `refs/heads/${branchName}`,
17
+ sha: shaLastCommitOfBranch,
18
+ });
19
+ return createBranchResponseSchema.parse(data);
20
+ }
21
+ catch (error) {
22
+ throw utils.handleError(error);
23
+ }
24
+ });
25
+
26
+ exports.createBranchFactory = createBranchFactory;
27
+ //# sourceMappingURL=create-branch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-branch.js","sources":["../../../src/github/branch/create-branch.ts"],"sourcesContent":["import { AxiosInstance } from 'axios';\nimport { z } from 'zod';\n\nimport { handleError } from '../commit/utils';\n\nexport type CreateBranchArgs = {\n branchName: string;\n shaLastCommitOfBranch: string;\n};\n\nexport type CreateBranchResponse = {\n sha: string;\n};\n\nconst createBranchResponseSchema = z.object({\n sha: z.string(),\n});\n\nexport type CreateBranch = (args: CreateBranchArgs) => Promise<CreateBranchResponse>;\n\nexport type CreateBranchFactory = (instance: AxiosInstance) => CreateBranch;\n\nexport const createBranchFactory: CreateBranchFactory = (instance) => async (args) => {\n const { branchName, shaLastCommitOfBranch } = args;\n\n try {\n const { data } = await instance.post<CreateBranchResponse>('/git/refs', {\n ref: `refs/heads/${branchName}`,\n sha: shaLastCommitOfBranch,\n });\n\n return createBranchResponseSchema.parse(data);\n } catch (error) {\n throw handleError(error);\n }\n};\n"],"names":["z","__awaiter","handleError"],"mappings":";;;;;;;;AAcA,MAAM,0BAA0B,GAAGA,KAAC,CAAC,MAAM,CAAC;AAC1C,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AAChB,CAAA,CAAC,CAAC;AAMI,MAAM,mBAAmB,GAAwB,CAAC,QAAQ,KAAK,CAAO,IAAI,KAAIC,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;AACnF,IAAA,MAAM,EAAE,UAAU,EAAE,qBAAqB,EAAE,GAAG,IAAI,CAAC;IAEnD,IAAI;QACF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAuB,WAAW,EAAE;YACtE,GAAG,EAAE,CAAc,WAAA,EAAA,UAAU,CAAE,CAAA;AAC/B,YAAA,GAAG,EAAE,qBAAqB;AAC3B,SAAA,CAAC,CAAC;AAEH,QAAA,OAAO,0BAA0B,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC/C,KAAA;AAAC,IAAA,OAAO,KAAK,EAAE;AACd,QAAA,MAAMC,iBAAW,CAAC,KAAK,CAAC,CAAC;AAC1B,KAAA;AACH,CAAC;;;;"}
@@ -0,0 +1,2 @@
1
+ export * from './create-branch';
2
+ export * from './update-branch';
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var createBranch = require('./create-branch.js');
6
+ var updateBranch = require('./update-branch.js');
7
+
8
+
9
+
10
+ exports.createBranchFactory = createBranch.createBranchFactory;
11
+ exports.updateBranchFactory = updateBranch.updateBranchFactory;
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
@@ -0,0 +1,11 @@
1
+ import { AxiosInstance } from 'axios';
2
+ export declare type UpdateBranchArgs = {
3
+ branchName: string;
4
+ shaTree: string;
5
+ };
6
+ export declare type UpdateBranchResponse = {
7
+ sha: string;
8
+ };
9
+ export declare type UpdateBranch = (args: UpdateBranchArgs) => Promise<UpdateBranchResponse>;
10
+ export declare type UpdateBranchFactory = (instance: AxiosInstance) => UpdateBranch;
11
+ export declare const updateBranchFactory: UpdateBranchFactory;
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('../../_virtual/_tslib.js');
6
+ var zod = require('zod');
7
+ var utils = require('../commit/utils.js');
8
+
9
+ const updateBranchResponseSchema = zod.z.object({
10
+ sha: zod.z.string(),
11
+ });
12
+ const updateBranchFactory = (instance) => (args) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
13
+ const { branchName, shaTree } = args;
14
+ try {
15
+ const { data } = yield instance.patch(`/git/refs/heads/${branchName}`, {
16
+ sha: shaTree,
17
+ });
18
+ return updateBranchResponseSchema.parse(data);
19
+ }
20
+ catch (error) {
21
+ throw utils.handleError(error);
22
+ }
23
+ });
24
+
25
+ exports.updateBranchFactory = updateBranchFactory;
26
+ //# sourceMappingURL=update-branch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-branch.js","sources":["../../../src/github/branch/update-branch.ts"],"sourcesContent":["import { AxiosInstance } from 'axios';\nimport { z } from 'zod';\n\nimport { handleError } from '../commit/utils';\n\nexport type UpdateBranchArgs = {\n branchName: string;\n shaTree: string;\n};\n\nexport type UpdateBranchResponse = {\n sha: string;\n};\n\nconst updateBranchResponseSchema = z.object({\n sha: z.string(),\n});\n\nexport type UpdateBranch = (args: UpdateBranchArgs) => Promise<UpdateBranchResponse>;\n\nexport type UpdateBranchFactory = (instance: AxiosInstance) => UpdateBranch;\n\nexport const updateBranchFactory: UpdateBranchFactory = (instance) => async (args) => {\n const { branchName, shaTree } = args;\n\n try {\n const { data } = await instance.patch<UpdateBranchResponse>(`/git/refs/heads/${branchName}`, {\n sha: shaTree,\n });\n\n return updateBranchResponseSchema.parse(data);\n } catch (error) {\n throw handleError(error);\n }\n};\n"],"names":["z","__awaiter","handleError"],"mappings":";;;;;;;;AAcA,MAAM,0BAA0B,GAAGA,KAAC,CAAC,MAAM,CAAC;AAC1C,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AAChB,CAAA,CAAC,CAAC;AAMI,MAAM,mBAAmB,GAAwB,CAAC,QAAQ,KAAK,CAAO,IAAI,KAAIC,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;AACnF,IAAA,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAErC,IAAI;AACF,QAAA,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAuB,CAAA,gBAAA,EAAmB,UAAU,CAAA,CAAE,EAAE;AAC3F,YAAA,GAAG,EAAE,OAAO;AACb,SAAA,CAAC,CAAC;AAEH,QAAA,OAAO,0BAA0B,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC/C,KAAA;AAAC,IAAA,OAAO,KAAK,EAAE;AACd,QAAA,MAAMC,iBAAW,CAAC,KAAK,CAAC,CAAC;AAC1B,KAAA;AACH,CAAC;;;;"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-git-blob.js","sources":["../../../src/github/commit/create-git-blob.ts"],"sourcesContent":["import type { AxiosInstance } from 'axios';\nimport { z } from 'zod';\n\nimport { handleError } from './utils';\n\nexport type CreateGitBlobArgs = {\n content: string;\n encoding: 'utf-8' | 'base64';\n};\n\nexport type CreateGitBlobResponse = {\n sha: string;\n url: string;\n};\n\nconst createGitBlobResponseSchema = z.object({\n sha: z.string(),\n url: z.string(),\n});\n\nexport type CreateGitBlob = (\n args: CreateGitBlobArgs\n) => Promise<CreateGitBlobResponse>;\n\nexport type CreateGitBlobFactory = (instance: AxiosInstance) => CreateGitBlob;\n\n/**\n * Create a git blob\n *\n * @param owner the owner of the repository\n * @param repo the name of the repository\n * @param token the github token\n * @param content the content of the file\n * @param encoding the encoding of the content. Default: utf-8\n * @returns CreateGitBlobResponse\n * @throws forbidden\n * @throws resource-not-found\n * @throws conflict\n * @throws validation-failed-or-the-endpoint-has-been-spammed\n */\nexport const createGitBlobFactory: CreateGitBlobFactory = (instance) => async (args) => {\n const { content, encoding = 'utf-8' } = args;\n\n try {\n const { data } = await instance.post<CreateGitBlobResponse>(\n '/git/blobs',\n {\n content,\n encoding,\n },\n );\n\n return createGitBlobResponseSchema.parse(data);\n } catch (error) {\n throw handleError(error);\n }\n};\n"],"names":["z","__awaiter","handleError"],"mappings":";;;;;;;;AAeA,MAAM,2BAA2B,GAAGA,KAAC,CAAC,MAAM,CAAC;AAC3C,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AACf,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AAChB,CAAA,CAAC,CAAC;AAQH;;;;;;;;;;;;;AAaG;AACI,MAAM,oBAAoB,GAAyB,CAAC,QAAQ,KAAK,CAAO,IAAI,KAAIC,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;IACrF,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,OAAO,EAAE,GAAG,IAAI,CAAC;IAE7C,IAAI;QACF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,CAClC,YAAY,EACZ;YACE,OAAO;YACP,QAAQ;AACT,SAAA,CACF,CAAC;AAEF,QAAA,OAAO,2BAA2B,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAChD,KAAA;AAAC,IAAA,OAAO,KAAK,EAAE;AACd,QAAA,MAAMC,iBAAW,CAAC,KAAK,CAAC,CAAC;AAC1B,KAAA;AACH,CAAC;;;;"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-git-commit.js","sources":["../../../src/github/commit/create-git-commit.ts"],"sourcesContent":["import type { AxiosInstance } from 'axios';\nimport { z } from 'zod';\n\nimport { handleError } from './utils';\n\nexport type CreateGitCommitArgs = {\n message: string;\n treeSha: string;\n parents: string[];\n};\n\nexport type CreateGitCommitResponse = {\n sha: string;\n url: string;\n};\n\nconst createGitCommitSchema = z.object({\n sha: z.string(),\n url: z.string(),\n});\n\nexport type CreateGitCommit = (\n args: CreateGitCommitArgs\n) => Promise<CreateGitCommitResponse>;\n\nexport type CreateGitCommitFactory = (\n instance: AxiosInstance\n) => CreateGitCommit;\n\n/**\n * Create a git commit\n * @param owner the owner of the repository\n * @param repo the name of the repository\n * @param token the github token\n * @param message the commit message\n * @param treeSha the sha of the tree\n * @param parents the parents of the commit\n * @returns CreateGitCommitResponse\n */\nexport const createGitCommitFactory: CreateGitCommitFactory = (instance) => async (args) => {\n const { message, treeSha, parents } = args;\n\n try {\n const { data } = await instance.post<CreateGitCommitResponse>(\n '/git/commits',\n {\n message,\n tree: treeSha,\n parents,\n },\n );\n\n return createGitCommitSchema.parse(data);\n } catch (error) {\n throw handleError(error);\n }\n};\n"],"names":["z","__awaiter","handleError"],"mappings":";;;;;;;;AAgBA,MAAM,qBAAqB,GAAGA,KAAC,CAAC,MAAM,CAAC;AACrC,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AACf,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AAChB,CAAA,CAAC,CAAC;AAUH;;;;;;;;;AASG;AACI,MAAM,sBAAsB,GAA2B,CAAC,QAAQ,KAAK,CAAO,IAAI,KAAIC,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;IACzF,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAE3C,IAAI;QACF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,CAClC,cAAc,EACd;YACE,OAAO;AACP,YAAA,IAAI,EAAE,OAAO;YACb,OAAO;AACR,SAAA,CACF,CAAC;AAEF,QAAA,OAAO,qBAAqB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC1C,KAAA;AAAC,IAAA,OAAO,KAAK,EAAE;AACd,QAAA,MAAMC,iBAAW,CAAC,KAAK,CAAC,CAAC;AAC1B,KAAA;AACH,CAAC;;;;"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-git-tree.js","sources":["../../../src/github/commit/create-git-tree.ts"],"sourcesContent":["import type { AxiosInstance } from 'axios';\nimport { z } from 'zod';\n\nimport { handleError } from './utils';\n\nexport type Blob = {\n path: string;\n sha: string;\n};\n\nexport type CreateGitTreeArgs = {\n baseTreeSha: string;\n blobs: Blob[];\n};\n\nexport type CreateGitTreeResponse = {\n sha: string;\n url: string;\n};\n\nconst createGitTreeSchema = z.object({\n sha: z.string(),\n url: z.string(),\n});\n\nexport type CreateGitTree = (\n args: CreateGitTreeArgs\n) => Promise<CreateGitTreeResponse>;\n\nexport type CreateGitTreeFactory = (instance: AxiosInstance) => CreateGitTree;\n\n/**\n * Create a git tree\n *\n * @param owner the owner of the repository\n * @param repo the name of the repository\n * @param token the github token\n * @param baseTreeSha the sha of the base tree\n * @param blobs the blobs to add to the tree\n * @returns CreateGitTreeResponse\n * @throws forbidden\n * @throws resource-not-found\n * @throws validation-failed-or-the-endpoint-has-been-spammed\n */\nexport const createGitTreeFactory: CreateGitTreeFactory = (instance) => async (args) => {\n const { baseTreeSha, blobs } = args;\n\n const tree = blobs.map((blob) => ({\n path: blob.path,\n mode: '100644',\n type: 'blob',\n sha: blob.sha,\n }));\n\n try {\n const { data } = await instance.post<CreateGitTreeResponse>(\n '/git/trees',\n {\n base_tree: baseTreeSha,\n tree,\n },\n );\n\n return createGitTreeSchema.parse(data);\n } catch (error) {\n throw handleError(error);\n }\n};\n"],"names":["z","__awaiter","handleError"],"mappings":";;;;;;;;AAoBA,MAAM,mBAAmB,GAAGA,KAAC,CAAC,MAAM,CAAC;AACnC,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AACf,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AAChB,CAAA,CAAC,CAAC;AAQH;;;;;;;;;;;;AAYG;AACI,MAAM,oBAAoB,GAAyB,CAAC,QAAQ,KAAK,CAAO,IAAI,KAAIC,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;AACrF,IAAA,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAEpC,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,MAAM;QAChC,IAAI,EAAE,IAAI,CAAC,IAAI;AACf,QAAA,IAAI,EAAE,QAAQ;AACd,QAAA,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,IAAI,CAAC,GAAG;AACd,KAAA,CAAC,CAAC,CAAC;IAEJ,IAAI;QACF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,CAClC,YAAY,EACZ;AACE,YAAA,SAAS,EAAE,WAAW;YACtB,IAAI;AACL,SAAA,CACF,CAAC;AAEF,QAAA,OAAO,mBAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACxC,KAAA;AAAC,IAAA,OAAO,KAAK,EAAE;AACd,QAAA,MAAMC,iBAAW,CAAC,KAAK,CAAC,CAAC;AAC1B,KAAA;AACH,CAAC;;;;"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-sha-last-commit-of-branch.js","sources":["../../../src/github/commit/get-sha-last-commit-of-branch.ts"],"sourcesContent":["import type { AxiosInstance } from 'axios';\nimport { z } from 'zod';\n\nimport { handleError } from './utils';\n\nexport type GetShaLastCommitOfBranchArgs = {\n ref: `/heads/${string}`;\n};\n\nexport type GetShaLastCommitOfBranchResponse = {\n sha: string;\n url: string;\n};\n\nconst getShaLastCommitOfBranchSchema = z.object({\n sha: z.string(),\n url: z.string(),\n});\n\nexport type GetShaLastCommitOfBranch = (\n args: GetShaLastCommitOfBranchArgs\n) => Promise<GetShaLastCommitOfBranchResponse>;\n\nexport type GetShaLastCommitOfBranchFactory = (\n instance: AxiosInstance\n) => GetShaLastCommitOfBranch;\n\n/**\n * Get the sha of the last commit of a branch\n *\n * @param owner the owner of the repository\n * @param repo the name of the repository\n * @param ref the reference to a branch. Example: /heads/master\n * @param token the github token\n * @returns GetShaLastCommitOfBranchResponse\n * @throws ref-not-found\n */\nexport const getShaLastCommitOfBranchFactory: GetShaLastCommitOfBranchFactory = (instance) => async (args) => {\n const { ref } = args;\n\n try {\n const { data } = await instance.get<{\n object: GetShaLastCommitOfBranchResponse;\n }>(`/git/refs/${ref}`);\n\n return getShaLastCommitOfBranchSchema.parse(data.object);\n } catch (error) {\n throw handleError(error);\n }\n};\n"],"names":["z","__awaiter","handleError"],"mappings":";;;;;;;;AAcA,MAAM,8BAA8B,GAAGA,KAAC,CAAC,MAAM,CAAC;AAC9C,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AACf,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AAChB,CAAA,CAAC,CAAC;AAUH;;;;;;;;;AASG;AACI,MAAM,+BAA+B,GAAoC,CAAC,QAAQ,KAAK,CAAO,IAAI,KAAIC,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;AAC3G,IAAA,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAErB,IAAI;AACF,QAAA,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,GAAG,CAEhC,CAAA,UAAA,EAAa,GAAG,CAAA,CAAE,CAAC,CAAC;QAEvB,OAAO,8BAA8B,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC1D,KAAA;AAAC,IAAA,OAAO,KAAK,EAAE;AACd,QAAA,MAAMC,iBAAW,CAAC,KAAK,CAAC,CAAC;AAC1B,KAAA;AACH,CAAC;;;;"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-tree-by-commit-sha.js","sources":["../../../src/github/commit/get-tree-by-commit-sha.ts"],"sourcesContent":["import type { AxiosInstance } from 'axios';\nimport { z } from 'zod';\n\nimport { handleError } from './utils';\n\nexport type GetTreeFromCommitShaArgs = {\n sha: string;\n};\n\nexport type GetTreeFromCommitShaResponse = {\n url: string;\n sha: string;\n};\n\nconst getTreeFromCommitShaSchema = z.object({\n url: z.string(),\n sha: z.string(),\n});\n\nexport type GetTreeByCommitSha = (\n args: GetTreeFromCommitShaArgs\n) => Promise<GetTreeFromCommitShaResponse>;\n\nexport type GetTreeByCommitShaFactory = (\n instance: AxiosInstance\n) => GetTreeByCommitSha;\n\n/**\n * Get the tree of a commit\n *\n * @param owner the owner of the repository\n * @param repo the name of the repository\n * @param sha the sha of the commit\n * @param token the github token\n * @returns GetTreeFromCommitShaResponse\n * @throws sha-not-found\n * @throws validation-failed-or-the-endpoint-has-been-spammed\n * @throws internal-server-error\n */\nexport const getTreeByCommitShaFactory: GetTreeByCommitShaFactory = (instance) => async (args) => {\n const { sha } = args;\n\n try {\n const { data } = await instance.get<{\n tree: GetTreeFromCommitShaResponse;\n }>(`/git/commits/${sha}`);\n\n return getTreeFromCommitShaSchema.parse(data.tree);\n } catch (error) {\n throw handleError(error);\n }\n};\n"],"names":["z","__awaiter","handleError"],"mappings":";;;;;;;;AAcA,MAAM,0BAA0B,GAAGA,KAAC,CAAC,MAAM,CAAC;AAC1C,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AACf,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AAChB,CAAA,CAAC,CAAC;AAUH;;;;;;;;;;;AAWG;AACI,MAAM,yBAAyB,GAA8B,CAAC,QAAQ,KAAK,CAAO,IAAI,KAAIC,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;AAC/F,IAAA,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAErB,IAAI;AACF,QAAA,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,GAAG,CAEhC,CAAA,aAAA,EAAgB,GAAG,CAAA,CAAE,CAAC,CAAC;QAE1B,OAAO,0BAA0B,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACpD,KAAA;AAAC,IAAA,OAAO,KAAK,EAAE;AACd,QAAA,MAAMC,iBAAW,CAAC,KAAK,CAAC,CAAC;AAC1B,KAAA;AACH,CAAC;;;;"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-new-commit-process.js","sources":["../../../src/github/commit/run-new-commit-process.ts"],"sourcesContent":["import type { CreateGitBlob } from './create-git-blob';\nimport type { CreateGitCommit } from './create-git-commit';\nimport type { CreateGitTree } from './create-git-tree';\nimport type { GetShaLastCommitOfBranch } from './get-sha-last-commit-of-branch';\nimport type { GetTreeByCommitSha } from './get-tree-by-commit-sha';\n\nexport type VersionedFile = {\n path: string;\n content: string;\n};\n\nexport type RunNewCommitProcessArgs = {\n message: string;\n ref: `/heads/${string}`;\n files: VersionedFile[];\n};\n\nexport type RunNewCommitProcessResponse = {\n sha: string;\n url: string;\n};\n\nexport type RunNewCommitProcess = (\n args: RunNewCommitProcessArgs,\n updateState?: (state: string) => void\n) => Promise<RunNewCommitProcessResponse>;\n\nexport type RunNewCommitProcessFactory = (args: {\n createGitBlob: CreateGitBlob;\n createGitCommit: CreateGitCommit;\n createGitTree: CreateGitTree;\n getShaLastCommitOfBranch: GetShaLastCommitOfBranch;\n getTreeByCommitSha: GetTreeByCommitSha;\n}) => RunNewCommitProcess;\n\nexport const runNewCommitProcessFactory: RunNewCommitProcessFactory = (args) => async (\n runNewCommitProcessArgs,\n updateState = () => {},\n) => {\n const { createGitBlob, createGitCommit, createGitTree, getShaLastCommitOfBranch, getTreeByCommitSha } = args;\n\n const { message, ref, files } = runNewCommitProcessArgs;\n\n updateState('retrieving-sha-last-commit-of-branch');\n const { sha: shaLastCommit } = await getShaLastCommitOfBranch({\n ref,\n });\n updateState('retrieved-sha-last-commit-of-branch');\n\n updateState('creating-blobs-from-file');\n const blobs = await Promise.all(\n files.map(async (file) => {\n const blob = await createGitBlob({\n content: file.content,\n encoding: 'utf-8',\n });\n\n return {\n path: file.path,\n sha: blob.sha,\n };\n }),\n );\n updateState('created-blobs-from-file');\n\n updateState('retrieving-branch-current-tree');\n const { sha: lastCommitTreeSha } = await getTreeByCommitSha({\n sha: shaLastCommit,\n });\n updateState('retrieved-branch-current-tree');\n\n updateState('creating-new-tree-with-changes');\n const tree = await createGitTree({\n baseTreeSha: lastCommitTreeSha,\n blobs,\n });\n updateState('created-new-tree-with-changes');\n\n updateState('creating-new-commit');\n const commit = await createGitCommit({\n message,\n treeSha: tree.sha,\n parents: [shaLastCommit],\n });\n updateState('created-new-commit');\n\n return commit;\n};\n"],"names":["__awaiter"],"mappings":";;;;;;AAmCa,MAAA,0BAA0B,GAA+B,CAAC,IAAI,KAAK,CAC9E,uBAAuB,EACvB,WAAW,GAAG,MAAO,GAAC,KACpBA,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;AACF,IAAA,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAC;IAE7G,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,uBAAuB,CAAC;IAExD,WAAW,CAAC,sCAAsC,CAAC,CAAC;IACpD,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,MAAM,wBAAwB,CAAC;QAC5D,GAAG;AACJ,KAAA,CAAC,CAAC;IACH,WAAW,CAAC,qCAAqC,CAAC,CAAC;IAEnD,WAAW,CAAC,0BAA0B,CAAC,CAAC;AACxC,IAAA,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAC7B,KAAK,CAAC,GAAG,CAAC,CAAO,IAAI,KAAIA,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;AACvB,QAAA,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC;YAC/B,OAAO,EAAE,IAAI,CAAC,OAAO;AACrB,YAAA,QAAQ,EAAE,OAAO;AAClB,SAAA,CAAC,CAAC;QAEH,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,GAAG,EAAE,IAAI,CAAC,GAAG;SACd,CAAC;KACH,CAAA,CAAC,CACH,CAAC;IACF,WAAW,CAAC,yBAAyB,CAAC,CAAC;IAEvC,WAAW,CAAC,gCAAgC,CAAC,CAAC;IAC9C,MAAM,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,MAAM,kBAAkB,CAAC;AAC1D,QAAA,GAAG,EAAE,aAAa;AACnB,KAAA,CAAC,CAAC;IACH,WAAW,CAAC,+BAA+B,CAAC,CAAC;IAE7C,WAAW,CAAC,gCAAgC,CAAC,CAAC;AAC9C,IAAA,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC;AAC/B,QAAA,WAAW,EAAE,iBAAiB;QAC9B,KAAK;AACN,KAAA,CAAC,CAAC;IACH,WAAW,CAAC,+BAA+B,CAAC,CAAC;IAE7C,WAAW,CAAC,qBAAqB,CAAC,CAAC;AACnC,IAAA,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC;QACnC,OAAO;QACP,OAAO,EAAE,IAAI,CAAC,GAAG;QACjB,OAAO,EAAE,CAAC,aAAa,CAAC;AACzB,KAAA,CAAC,CAAC;IACH,WAAW,CAAC,oBAAoB,CAAC,CAAC;AAElC,IAAA,OAAO,MAAM,CAAC;AAChB,CAAC;;;;"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":["../../../src/github/commit/utils.ts"],"sourcesContent":["import type { AxiosResponse } from 'axios';\n\nexport const handleError = (error: unknown): Error => {\n const { response } = error as any;\n\n if (response) {\n const { status } = response as AxiosResponse;\n\n if (status === 403) {\n return new Error('forbidden');\n }\n\n if (status === 404) {\n return new Error('resource-not-found');\n }\n\n if (status === 409) {\n return new Error('conflict');\n }\n\n if (status === 422) {\n return new Error('validation-failed-or-the-endpoint-has-been-spammed');\n }\n\n if (status === 500) {\n return new Error('internal-server-error');\n }\n }\n\n return error as Error;\n};\n"],"names":[],"mappings":";;;;AAEa,MAAA,WAAW,GAAG,CAAC,KAAc,KAAW;AACnD,IAAA,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAY,CAAC;AAElC,IAAA,IAAI,QAAQ,EAAE;AACZ,QAAA,MAAM,EAAE,MAAM,EAAE,GAAG,QAAyB,CAAC;QAE7C,IAAI,MAAM,KAAK,GAAG,EAAE;AAClB,YAAA,OAAO,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC;AAC/B,SAAA;QAED,IAAI,MAAM,KAAK,GAAG,EAAE;AAClB,YAAA,OAAO,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;AACxC,SAAA;QAED,IAAI,MAAM,KAAK,GAAG,EAAE;AAClB,YAAA,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;AAC9B,SAAA;QAED,IAAI,MAAM,KAAK,GAAG,EAAE;AAClB,YAAA,OAAO,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;AACxE,SAAA;QAED,IAAI,MAAM,KAAK,GAAG,EAAE;AAClB,YAAA,OAAO,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;AAC3C,SAAA;AACF,KAAA;AAED,IAAA,OAAO,KAAc,CAAC;AACxB;;;;"}
@@ -0,0 +1,20 @@
1
+ import type { AxiosInstance } from 'axios';
2
+ export declare type GetFileContentArgs = {
3
+ path: string;
4
+ branch: string;
5
+ };
6
+ export declare type GetFileContentResponse = string;
7
+ export declare type GetFileContent = (args: GetFileContentArgs) => Promise<GetFileContentResponse>;
8
+ export declare type GetFileContentFactory = (instance: AxiosInstance) => GetFileContent;
9
+ /**
10
+ * Get the content of a file
11
+ *
12
+ * @param path the path of the file
13
+ * @param branch the branch of the file
14
+ * @returns GetFileContentResponse
15
+ * @throws validation-failed-or-the-endpoint-has-been-spammed
16
+ * @throws internal-server-error
17
+ * @throws forbidden
18
+ * @throws resource-not-found
19
+ */
20
+ export declare const getFileContentFactory: GetFileContentFactory;
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('../../_virtual/_tslib.js');
6
+ var utils = require('../commit/utils.js');
7
+
8
+ /**
9
+ * Get the content of a file
10
+ *
11
+ * @param path the path of the file
12
+ * @param branch the branch of the file
13
+ * @returns GetFileContentResponse
14
+ * @throws validation-failed-or-the-endpoint-has-been-spammed
15
+ * @throws internal-server-error
16
+ * @throws forbidden
17
+ * @throws resource-not-found
18
+ */
19
+ const getFileContentFactory = (instance) => (args) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
20
+ const { path, branch } = args;
21
+ try {
22
+ const { data } = yield instance.get(`/contents/${path}`, {
23
+ params: {
24
+ ref: branch,
25
+ },
26
+ });
27
+ if (data.encoding === 'base64') {
28
+ return Buffer.from(data.content, 'base64').toString('utf-8');
29
+ }
30
+ return data.content;
31
+ }
32
+ catch (error) {
33
+ throw utils.handleError(error);
34
+ }
35
+ });
36
+
37
+ exports.getFileContentFactory = getFileContentFactory;
38
+ //# sourceMappingURL=get-file-content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-file-content.js","sources":["../../../src/github/content/get-file-content.ts"],"sourcesContent":["import type { AxiosInstance } from 'axios';\n\nimport { handleError } from '../commit/utils';\n\nexport type GetFileContentArgs = {\n path: string;\n branch: string;\n};\n\ntype ApiResponse = {\n encoding: 'base64' | 'utf-8';\n content: string;\n};\n\nexport type GetFileContentResponse = string;\n\nexport type GetFileContent = (args: GetFileContentArgs) => Promise<GetFileContentResponse>;\n\nexport type GetFileContentFactory = (instance: AxiosInstance) => GetFileContent;\n\n/**\n * Get the content of a file\n *\n * @param path the path of the file\n * @param branch the branch of the file\n * @returns GetFileContentResponse\n * @throws validation-failed-or-the-endpoint-has-been-spammed\n * @throws internal-server-error\n * @throws forbidden\n * @throws resource-not-found\n */\nexport const getFileContentFactory: GetFileContentFactory = (instance) => async (args) => {\n const { path, branch } = args;\n\n try {\n const { data } = await instance.get<ApiResponse>(`/contents/${path}`, {\n params: {\n ref: branch,\n },\n });\n\n if (data.encoding === 'base64') {\n return Buffer.from(data.content, 'base64').toString('utf-8');\n }\n\n return data.content;\n } catch (error) {\n throw handleError(error);\n }\n};\n"],"names":["__awaiter","handleError"],"mappings":";;;;;;;AAoBA;;;;;;;;;;AAUG;AACI,MAAM,qBAAqB,GAA0B,CAAC,QAAQ,KAAK,CAAO,IAAI,KAAIA,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;AACvF,IAAA,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAE9B,IAAI;AACF,QAAA,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAc,CAAA,UAAA,EAAa,IAAI,CAAA,CAAE,EAAE;AACpE,YAAA,MAAM,EAAE;AACN,gBAAA,GAAG,EAAE,MAAM;AACZ,aAAA;AACF,SAAA,CAAC,CAAC;AAEH,QAAA,IAAI,IAAI,CAAC,QAAQ,KAAK,QAAQ,EAAE;AAC9B,YAAA,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAC9D,SAAA;QAED,OAAO,IAAI,CAAC,OAAO,CAAC;AACrB,KAAA;AAAC,IAAA,OAAO,KAAK,EAAE;AACd,QAAA,MAAMC,iBAAW,CAAC,KAAK,CAAC,CAAC;AAC1B,KAAA;AACH,CAAC;;;;"}
@@ -1,4 +1,6 @@
1
- import type { CreateGitTree, CreateGitBlob, CreateGitCommit, GetTreeByCommitSha, GetShaLastCommitOfBranch, RunNewCommitProcess } from './commits';
1
+ import type { CreateGitTree, CreateGitBlob, CreateGitCommit, GetTreeByCommitSha, GetShaLastCommitOfBranch, RunNewCommitProcess } from './commit';
2
+ import { GetFileContent } from './content/get-file-content';
3
+ import { CreateBranch, UpdateBranch } from './branch';
2
4
  export declare type GithubSdkArgs = {
3
5
  owner: string;
4
6
  repo: string;
@@ -11,12 +13,9 @@ export declare type GithubSdkInstance = {
11
13
  getShaLastCommitOfBranch: GetShaLastCommitOfBranch;
12
14
  getTreeByCommitSha: GetTreeByCommitSha;
13
15
  runNewCommitProcess: RunNewCommitProcess;
16
+ getFileContent: GetFileContent;
17
+ createBranch: CreateBranch;
18
+ updateBranch: UpdateBranch;
14
19
  };
15
- export declare const githubSdk: (args: GithubSdkArgs) => {
16
- createGitBlob: CreateGitBlob;
17
- createGitCommit: CreateGitCommit;
18
- createGitTree: CreateGitTree;
19
- getShaLastCommitOfBranch: GetShaLastCommitOfBranch;
20
- getTreeByCommitSha: GetTreeByCommitSha;
21
- runNewCommitProcess: RunNewCommitProcess;
22
- };
20
+ export declare type GithubSdk = (args: GithubSdkArgs) => GithubSdkInstance;
21
+ export declare const githubSdk: GithubSdk;
@@ -3,12 +3,15 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var axios = require('axios');
6
- var createGitBlob = require('./commits/create-git-blob.js');
7
- var createGitCommit = require('./commits/create-git-commit.js');
8
- var createGitTree = require('./commits/create-git-tree.js');
9
- var getShaLastCommitOfBranch = require('./commits/get-sha-last-commit-of-branch.js');
10
- var getTreeByCommitSha = require('./commits/get-tree-by-commit-sha.js');
11
- var runNewCommitProcess = require('./commits/run-new-commit-process.js');
6
+ var createGitBlob = require('./commit/create-git-blob.js');
7
+ var createGitCommit = require('./commit/create-git-commit.js');
8
+ var createGitTree = require('./commit/create-git-tree.js');
9
+ var getShaLastCommitOfBranch = require('./commit/get-sha-last-commit-of-branch.js');
10
+ var getTreeByCommitSha = require('./commit/get-tree-by-commit-sha.js');
11
+ var runNewCommitProcess = require('./commit/run-new-commit-process.js');
12
+ var getFileContent = require('./content/get-file-content.js');
13
+ var createBranch = require('./branch/create-branch.js');
14
+ var updateBranch = require('./branch/update-branch.js');
12
15
 
13
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
17
 
@@ -29,6 +32,7 @@ const githubSdk = (args) => {
29
32
  const createGitTree$1 = createGitTree.createGitTreeFactory(instance);
30
33
  const getShaLastCommitOfBranch$1 = getShaLastCommitOfBranch.getShaLastCommitOfBranchFactory(instance);
31
34
  const getTreeByCommitSha$1 = getTreeByCommitSha.getTreeByCommitShaFactory(instance);
35
+ const getFileContent$1 = getFileContent.getFileContentFactory(instance);
32
36
  const runNewCommitProcess$1 = runNewCommitProcess.runNewCommitProcessFactory({
33
37
  createGitBlob: createGitBlob$1,
34
38
  createGitCommit: createGitCommit$1,
@@ -36,6 +40,8 @@ const githubSdk = (args) => {
36
40
  getShaLastCommitOfBranch: getShaLastCommitOfBranch$1,
37
41
  getTreeByCommitSha: getTreeByCommitSha$1,
38
42
  });
43
+ const createBranch$1 = createBranch.createBranchFactory(instance);
44
+ const updateBranch$1 = updateBranch.updateBranchFactory(instance);
39
45
  return {
40
46
  createGitBlob: createGitBlob$1,
41
47
  createGitCommit: createGitCommit$1,
@@ -43,6 +49,9 @@ const githubSdk = (args) => {
43
49
  getShaLastCommitOfBranch: getShaLastCommitOfBranch$1,
44
50
  getTreeByCommitSha: getTreeByCommitSha$1,
45
51
  runNewCommitProcess: runNewCommitProcess$1,
52
+ getFileContent: getFileContent$1,
53
+ createBranch: createBranch$1,
54
+ updateBranch: updateBranch$1,
46
55
  };
47
56
  };
48
57
 
@@ -1 +1 @@
1
- {"version":3,"file":"github.js","sources":["../../src/github/github.ts"],"sourcesContent":["import axios from 'axios';\n\nimport {\n createGitBlobFactory,\n createGitCommitFactory,\n createGitTreeFactory,\n getShaLastCommitOfBranchFactory,\n getTreeByCommitShaFactory,\n runNewCommitProcessFactory,\n} from './commits';\nimport type {\n CreateGitTree,\n CreateGitBlob,\n CreateGitCommit,\n GetTreeByCommitSha,\n GetShaLastCommitOfBranch,\n RunNewCommitProcess,\n} from './commits';\n\nexport type GithubSdkArgs = {\n owner: string;\n repo: string;\n token: string;\n};\n\nexport type GithubSdkInstance = {\n createGitBlob: CreateGitBlob;\n createGitCommit: CreateGitCommit;\n createGitTree: CreateGitTree;\n getShaLastCommitOfBranch: GetShaLastCommitOfBranch;\n getTreeByCommitSha: GetTreeByCommitSha;\n runNewCommitProcess: RunNewCommitProcess;\n};\n\nexport const githubSdk = (args: GithubSdkArgs) => {\n const { owner, repo, token } = args;\n\n const instance = axios.create({\n baseURL: `https://api.github.com/repos/${owner}/${repo}`,\n headers: {\n Accept: 'application/vnd.github+json',\n Authorization: `Bearer ${token}`,\n 'X-GitHub-Api-Version': '2022-11-28',\n },\n });\n\n const createGitBlob = createGitBlobFactory(instance);\n const createGitCommit = createGitCommitFactory(instance);\n const createGitTree = createGitTreeFactory(instance);\n const getShaLastCommitOfBranch = getShaLastCommitOfBranchFactory(instance);\n const getTreeByCommitSha = getTreeByCommitShaFactory(instance);\n\n const runNewCommitProcess = runNewCommitProcessFactory({\n createGitBlob,\n createGitCommit,\n createGitTree,\n getShaLastCommitOfBranch,\n getTreeByCommitSha,\n });\n\n return {\n createGitBlob,\n createGitCommit,\n createGitTree,\n getShaLastCommitOfBranch,\n getTreeByCommitSha,\n runNewCommitProcess,\n };\n};\n"],"names":["axios","createGitBlob","createGitBlobFactory","createGitCommit","createGitCommitFactory","createGitTree","createGitTreeFactory","getShaLastCommitOfBranch","getShaLastCommitOfBranchFactory","getTreeByCommitSha","getTreeByCommitShaFactory","runNewCommitProcess","runNewCommitProcessFactory"],"mappings":";;;;;;;;;;;;;;;;AAkCa,MAAA,SAAS,GAAG,CAAC,IAAmB,KAAI;IAC/C,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;AAEpC,IAAA,MAAM,QAAQ,GAAGA,yBAAK,CAAC,MAAM,CAAC;AAC5B,QAAA,OAAO,EAAE,CAAA,6BAAA,EAAgC,KAAK,CAAA,CAAA,EAAI,IAAI,CAAE,CAAA;AACxD,QAAA,OAAO,EAAE;AACP,YAAA,MAAM,EAAE,6BAA6B;YACrC,aAAa,EAAE,CAAU,OAAA,EAAA,KAAK,CAAE,CAAA;AAChC,YAAA,sBAAsB,EAAE,YAAY;AACrC,SAAA;AACF,KAAA,CAAC,CAAC;AAEH,IAAA,MAAMC,eAAa,GAAGC,kCAAoB,CAAC,QAAQ,CAAC,CAAC;AACrD,IAAA,MAAMC,iBAAe,GAAGC,sCAAsB,CAAC,QAAQ,CAAC,CAAC;AACzD,IAAA,MAAMC,eAAa,GAAGC,kCAAoB,CAAC,QAAQ,CAAC,CAAC;AACrD,IAAA,MAAMC,0BAAwB,GAAGC,wDAA+B,CAAC,QAAQ,CAAC,CAAC;AAC3E,IAAA,MAAMC,oBAAkB,GAAGC,4CAAyB,CAAC,QAAQ,CAAC,CAAC;IAE/D,MAAMC,qBAAmB,GAAGC,8CAA0B,CAAC;uBACrDX,eAAa;yBACbE,iBAAe;uBACfE,eAAa;kCACbE,0BAAwB;4BACxBE,oBAAkB;AACnB,KAAA,CAAC,CAAC;IAEH,OAAO;uBACLR,eAAa;yBACbE,iBAAe;uBACfE,eAAa;kCACbE,0BAAwB;4BACxBE,oBAAkB;6BAClBE,qBAAmB;KACpB,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"github.js","sources":["../../src/github/github.ts"],"sourcesContent":["import axios from 'axios';\n\nimport {\n createGitBlobFactory,\n createGitCommitFactory,\n createGitTreeFactory,\n getShaLastCommitOfBranchFactory,\n getTreeByCommitShaFactory,\n runNewCommitProcessFactory,\n} from './commit';\nimport type {\n CreateGitTree,\n CreateGitBlob,\n CreateGitCommit,\n GetTreeByCommitSha,\n GetShaLastCommitOfBranch,\n RunNewCommitProcess,\n} from './commit';\nimport { GetFileContent, getFileContentFactory } from './content/get-file-content';\nimport { CreateBranch, UpdateBranch, createBranchFactory, updateBranchFactory } from './branch';\n\nexport type GithubSdkArgs = {\n owner: string;\n repo: string;\n token: string;\n};\n\nexport type GithubSdkInstance = {\n createGitBlob: CreateGitBlob;\n createGitCommit: CreateGitCommit;\n createGitTree: CreateGitTree;\n getShaLastCommitOfBranch: GetShaLastCommitOfBranch;\n getTreeByCommitSha: GetTreeByCommitSha;\n runNewCommitProcess: RunNewCommitProcess;\n getFileContent: GetFileContent;\n createBranch: CreateBranch;\n updateBranch: UpdateBranch;\n};\n\nexport type GithubSdk = (args: GithubSdkArgs) => GithubSdkInstance;\n\nexport const githubSdk: GithubSdk = (args) => {\n const { owner, repo, token } = args;\n\n const instance = axios.create({\n baseURL: `https://api.github.com/repos/${owner}/${repo}`,\n headers: {\n Accept: 'application/vnd.github+json',\n Authorization: `Bearer ${token}`,\n 'X-GitHub-Api-Version': '2022-11-28',\n },\n });\n\n const createGitBlob = createGitBlobFactory(instance);\n const createGitCommit = createGitCommitFactory(instance);\n const createGitTree = createGitTreeFactory(instance);\n const getShaLastCommitOfBranch = getShaLastCommitOfBranchFactory(instance);\n const getTreeByCommitSha = getTreeByCommitShaFactory(instance);\n\n const getFileContent = getFileContentFactory(instance);\n\n const runNewCommitProcess = runNewCommitProcessFactory({\n createGitBlob,\n createGitCommit,\n createGitTree,\n getShaLastCommitOfBranch,\n getTreeByCommitSha,\n });\n\n const createBranch = createBranchFactory(instance);\n const updateBranch = updateBranchFactory(instance);\n\n return {\n createGitBlob,\n createGitCommit,\n createGitTree,\n getShaLastCommitOfBranch,\n getTreeByCommitSha,\n runNewCommitProcess,\n getFileContent,\n createBranch,\n updateBranch,\n };\n};\n"],"names":["axios","createGitBlob","createGitBlobFactory","createGitCommit","createGitCommitFactory","createGitTree","createGitTreeFactory","getShaLastCommitOfBranch","getShaLastCommitOfBranchFactory","getTreeByCommitSha","getTreeByCommitShaFactory","getFileContent","getFileContentFactory","runNewCommitProcess","runNewCommitProcessFactory","createBranch","createBranchFactory","updateBranch","updateBranchFactory"],"mappings":";;;;;;;;;;;;;;;;;;;AAyCa,MAAA,SAAS,GAAc,CAAC,IAAI,KAAI;IAC3C,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;AAEpC,IAAA,MAAM,QAAQ,GAAGA,yBAAK,CAAC,MAAM,CAAC;AAC5B,QAAA,OAAO,EAAE,CAAA,6BAAA,EAAgC,KAAK,CAAA,CAAA,EAAI,IAAI,CAAE,CAAA;AACxD,QAAA,OAAO,EAAE;AACP,YAAA,MAAM,EAAE,6BAA6B;YACrC,aAAa,EAAE,CAAU,OAAA,EAAA,KAAK,CAAE,CAAA;AAChC,YAAA,sBAAsB,EAAE,YAAY;AACrC,SAAA;AACF,KAAA,CAAC,CAAC;AAEH,IAAA,MAAMC,eAAa,GAAGC,kCAAoB,CAAC,QAAQ,CAAC,CAAC;AACrD,IAAA,MAAMC,iBAAe,GAAGC,sCAAsB,CAAC,QAAQ,CAAC,CAAC;AACzD,IAAA,MAAMC,eAAa,GAAGC,kCAAoB,CAAC,QAAQ,CAAC,CAAC;AACrD,IAAA,MAAMC,0BAAwB,GAAGC,wDAA+B,CAAC,QAAQ,CAAC,CAAC;AAC3E,IAAA,MAAMC,oBAAkB,GAAGC,4CAAyB,CAAC,QAAQ,CAAC,CAAC;AAE/D,IAAA,MAAMC,gBAAc,GAAGC,oCAAqB,CAAC,QAAQ,CAAC,CAAC;IAEvD,MAAMC,qBAAmB,GAAGC,8CAA0B,CAAC;uBACrDb,eAAa;yBACbE,iBAAe;uBACfE,eAAa;kCACbE,0BAAwB;4BACxBE,oBAAkB;AACnB,KAAA,CAAC,CAAC;AAEH,IAAA,MAAMM,cAAY,GAAGC,gCAAmB,CAAC,QAAQ,CAAC,CAAC;AACnD,IAAA,MAAMC,cAAY,GAAGC,gCAAmB,CAAC,QAAQ,CAAC,CAAC;IAEnD,OAAO;uBACLjB,eAAa;yBACbE,iBAAe;uBACfE,eAAa;kCACbE,0BAAwB;4BACxBE,oBAAkB;6BAClBI,qBAAmB;wBACnBF,gBAAc;sBACdI,cAAY;sBACZE,cAAY;KACb,CAAC;AACJ;;;;"}
package/dist/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@sparted/shared-library",
3
- "version": "1.0.8-alpha.0",
3
+ "version": "1.0.8-alpha.2",
4
4
  "repository": "git@github.com:Sparted/shared-library.git",
5
5
  "author": "Thomas <duprethomasfr@gmail.com>",
6
6
  "license": "MIT",
7
7
  "sideEffets": false,
8
- "main": "index.js",
9
- "module": "index.js",
8
+ "main": "dist/index.js",
9
+ "module": "dist/index.js",
10
10
  "files": [
11
11
  "**/*",
12
12
  "**/**"
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@sparted/shared-library",
3
- "version": "1.0.8-alpha.0",
3
+ "version": "1.0.8-alpha.2",
4
4
  "repository": "git@github.com:Sparted/shared-library.git",
5
5
  "author": "Thomas <duprethomasfr@gmail.com>",
6
6
  "license": "MIT",
7
7
  "sideEffets": false,
8
- "main": "index.js",
9
- "module": "index.js",
8
+ "main": "dist/index.js",
9
+ "module": "dist/index.js",
10
10
  "files": [
11
11
  "**/*",
12
12
  "**/**"
@@ -0,0 +1,36 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { z } from 'zod';
3
+
4
+ import { handleError } from '../commit/utils';
5
+
6
+ export type CreateBranchArgs = {
7
+ branchName: string;
8
+ shaLastCommitOfBranch: string;
9
+ };
10
+
11
+ export type CreateBranchResponse = {
12
+ sha: string;
13
+ };
14
+
15
+ const createBranchResponseSchema = z.object({
16
+ sha: z.string(),
17
+ });
18
+
19
+ export type CreateBranch = (args: CreateBranchArgs) => Promise<CreateBranchResponse>;
20
+
21
+ export type CreateBranchFactory = (instance: AxiosInstance) => CreateBranch;
22
+
23
+ export const createBranchFactory: CreateBranchFactory = (instance) => async (args) => {
24
+ const { branchName, shaLastCommitOfBranch } = args;
25
+
26
+ try {
27
+ const { data } = await instance.post<CreateBranchResponse>('/git/refs', {
28
+ ref: `refs/heads/${branchName}`,
29
+ sha: shaLastCommitOfBranch,
30
+ });
31
+
32
+ return createBranchResponseSchema.parse(data);
33
+ } catch (error) {
34
+ throw handleError(error);
35
+ }
36
+ };
@@ -0,0 +1,2 @@
1
+ export * from './create-branch';
2
+ export * from './update-branch';
@@ -0,0 +1,35 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { z } from 'zod';
3
+
4
+ import { handleError } from '../commit/utils';
5
+
6
+ export type UpdateBranchArgs = {
7
+ branchName: string;
8
+ shaTree: string;
9
+ };
10
+
11
+ export type UpdateBranchResponse = {
12
+ sha: string;
13
+ };
14
+
15
+ const updateBranchResponseSchema = z.object({
16
+ sha: z.string(),
17
+ });
18
+
19
+ export type UpdateBranch = (args: UpdateBranchArgs) => Promise<UpdateBranchResponse>;
20
+
21
+ export type UpdateBranchFactory = (instance: AxiosInstance) => UpdateBranch;
22
+
23
+ export const updateBranchFactory: UpdateBranchFactory = (instance) => async (args) => {
24
+ const { branchName, shaTree } = args;
25
+
26
+ try {
27
+ const { data } = await instance.patch<UpdateBranchResponse>(`/git/refs/heads/${branchName}`, {
28
+ sha: shaTree,
29
+ });
30
+
31
+ return updateBranchResponseSchema.parse(data);
32
+ } catch (error) {
33
+ throw handleError(error);
34
+ }
35
+ };
@@ -0,0 +1,50 @@
1
+ import type { AxiosInstance } from 'axios';
2
+
3
+ import { handleError } from '../commit/utils';
4
+
5
+ export type GetFileContentArgs = {
6
+ path: string;
7
+ branch: string;
8
+ };
9
+
10
+ type ApiResponse = {
11
+ encoding: 'base64' | 'utf-8';
12
+ content: string;
13
+ };
14
+
15
+ export type GetFileContentResponse = string;
16
+
17
+ export type GetFileContent = (args: GetFileContentArgs) => Promise<GetFileContentResponse>;
18
+
19
+ export type GetFileContentFactory = (instance: AxiosInstance) => GetFileContent;
20
+
21
+ /**
22
+ * Get the content of a file
23
+ *
24
+ * @param path the path of the file
25
+ * @param branch the branch of the file
26
+ * @returns GetFileContentResponse
27
+ * @throws validation-failed-or-the-endpoint-has-been-spammed
28
+ * @throws internal-server-error
29
+ * @throws forbidden
30
+ * @throws resource-not-found
31
+ */
32
+ export const getFileContentFactory: GetFileContentFactory = (instance) => async (args) => {
33
+ const { path, branch } = args;
34
+
35
+ try {
36
+ const { data } = await instance.get<ApiResponse>(`/contents/${path}`, {
37
+ params: {
38
+ ref: branch,
39
+ },
40
+ });
41
+
42
+ if (data.encoding === 'base64') {
43
+ return Buffer.from(data.content, 'base64').toString('utf-8');
44
+ }
45
+
46
+ return data.content;
47
+ } catch (error) {
48
+ throw handleError(error);
49
+ }
50
+ };
@@ -7,7 +7,7 @@ import {
7
7
  getShaLastCommitOfBranchFactory,
8
8
  getTreeByCommitShaFactory,
9
9
  runNewCommitProcessFactory,
10
- } from './commits';
10
+ } from './commit';
11
11
  import type {
12
12
  CreateGitTree,
13
13
  CreateGitBlob,
@@ -15,7 +15,9 @@ import type {
15
15
  GetTreeByCommitSha,
16
16
  GetShaLastCommitOfBranch,
17
17
  RunNewCommitProcess,
18
- } from './commits';
18
+ } from './commit';
19
+ import { GetFileContent, getFileContentFactory } from './content/get-file-content';
20
+ import { CreateBranch, UpdateBranch, createBranchFactory, updateBranchFactory } from './branch';
19
21
 
20
22
  export type GithubSdkArgs = {
21
23
  owner: string;
@@ -30,9 +32,14 @@ export type GithubSdkInstance = {
30
32
  getShaLastCommitOfBranch: GetShaLastCommitOfBranch;
31
33
  getTreeByCommitSha: GetTreeByCommitSha;
32
34
  runNewCommitProcess: RunNewCommitProcess;
35
+ getFileContent: GetFileContent;
36
+ createBranch: CreateBranch;
37
+ updateBranch: UpdateBranch;
33
38
  };
34
39
 
35
- export const githubSdk = (args: GithubSdkArgs) => {
40
+ export type GithubSdk = (args: GithubSdkArgs) => GithubSdkInstance;
41
+
42
+ export const githubSdk: GithubSdk = (args) => {
36
43
  const { owner, repo, token } = args;
37
44
 
38
45
  const instance = axios.create({
@@ -50,6 +57,8 @@ export const githubSdk = (args: GithubSdkArgs) => {
50
57
  const getShaLastCommitOfBranch = getShaLastCommitOfBranchFactory(instance);
51
58
  const getTreeByCommitSha = getTreeByCommitShaFactory(instance);
52
59
 
60
+ const getFileContent = getFileContentFactory(instance);
61
+
53
62
  const runNewCommitProcess = runNewCommitProcessFactory({
54
63
  createGitBlob,
55
64
  createGitCommit,
@@ -58,6 +67,9 @@ export const githubSdk = (args: GithubSdkArgs) => {
58
67
  getTreeByCommitSha,
59
68
  });
60
69
 
70
+ const createBranch = createBranchFactory(instance);
71
+ const updateBranch = updateBranchFactory(instance);
72
+
61
73
  return {
62
74
  createGitBlob,
63
75
  createGitCommit,
@@ -65,5 +77,8 @@ export const githubSdk = (args: GithubSdkArgs) => {
65
77
  getShaLastCommitOfBranch,
66
78
  getTreeByCommitSha,
67
79
  runNewCommitProcess,
80
+ getFileContent,
81
+ createBranch,
82
+ updateBranch,
68
83
  };
69
84
  };
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-git-blob.js","sources":["../../../src/github/commits/create-git-blob.ts"],"sourcesContent":["import type { AxiosInstance } from 'axios';\nimport { z } from 'zod';\n\nimport { handleError } from './utils';\n\nexport type CreateGitBlobArgs = {\n content: string;\n encoding: 'utf-8' | 'base64';\n};\n\nexport type CreateGitBlobResponse = {\n sha: string;\n url: string;\n};\n\nconst createGitBlobResponseSchema = z.object({\n sha: z.string(),\n url: z.string(),\n});\n\nexport type CreateGitBlob = (\n args: CreateGitBlobArgs\n) => Promise<CreateGitBlobResponse>;\n\nexport type CreateGitBlobFactory = (instance: AxiosInstance) => CreateGitBlob;\n\n/**\n * Create a git blob\n *\n * @param owner the owner of the repository\n * @param repo the name of the repository\n * @param token the github token\n * @param content the content of the file\n * @param encoding the encoding of the content. Default: utf-8\n * @returns CreateGitBlobResponse\n * @throws forbidden\n * @throws resource-not-found\n * @throws conflict\n * @throws validation-failed-or-the-endpoint-has-been-spammed\n */\nexport const createGitBlobFactory: CreateGitBlobFactory = (instance) => async (args) => {\n const { content, encoding = 'utf-8' } = args;\n\n try {\n const { data } = await instance.post<CreateGitBlobResponse>(\n '/git/blobs',\n {\n content,\n encoding,\n },\n );\n\n return createGitBlobResponseSchema.parse(data);\n } catch (error) {\n throw handleError(error);\n }\n};\n"],"names":["z","__awaiter","handleError"],"mappings":";;;;;;;;AAeA,MAAM,2BAA2B,GAAGA,KAAC,CAAC,MAAM,CAAC;AAC3C,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AACf,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AAChB,CAAA,CAAC,CAAC;AAQH;;;;;;;;;;;;;AAaG;AACI,MAAM,oBAAoB,GAAyB,CAAC,QAAQ,KAAK,CAAO,IAAI,KAAIC,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;IACrF,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,OAAO,EAAE,GAAG,IAAI,CAAC;IAE7C,IAAI;QACF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,CAClC,YAAY,EACZ;YACE,OAAO;YACP,QAAQ;AACT,SAAA,CACF,CAAC;AAEF,QAAA,OAAO,2BAA2B,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAChD,KAAA;AAAC,IAAA,OAAO,KAAK,EAAE;AACd,QAAA,MAAMC,iBAAW,CAAC,KAAK,CAAC,CAAC;AAC1B,KAAA;AACH,CAAC;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-git-commit.js","sources":["../../../src/github/commits/create-git-commit.ts"],"sourcesContent":["import type { AxiosInstance } from 'axios';\nimport { z } from 'zod';\n\nimport { handleError } from './utils';\n\nexport type CreateGitCommitArgs = {\n message: string;\n treeSha: string;\n parents: string[];\n};\n\nexport type CreateGitCommitResponse = {\n sha: string;\n url: string;\n};\n\nconst createGitCommitSchema = z.object({\n sha: z.string(),\n url: z.string(),\n});\n\nexport type CreateGitCommit = (\n args: CreateGitCommitArgs\n) => Promise<CreateGitCommitResponse>;\n\nexport type CreateGitCommitFactory = (\n instance: AxiosInstance\n) => CreateGitCommit;\n\n/**\n * Create a git commit\n * @param owner the owner of the repository\n * @param repo the name of the repository\n * @param token the github token\n * @param message the commit message\n * @param treeSha the sha of the tree\n * @param parents the parents of the commit\n * @returns CreateGitCommitResponse\n */\nexport const createGitCommitFactory: CreateGitCommitFactory = (instance) => async (args) => {\n const { message, treeSha, parents } = args;\n\n try {\n const { data } = await instance.post<CreateGitCommitResponse>(\n '/git/commits',\n {\n message,\n tree: treeSha,\n parents,\n },\n );\n\n return createGitCommitSchema.parse(data);\n } catch (error) {\n throw handleError(error);\n }\n};\n"],"names":["z","__awaiter","handleError"],"mappings":";;;;;;;;AAgBA,MAAM,qBAAqB,GAAGA,KAAC,CAAC,MAAM,CAAC;AACrC,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AACf,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AAChB,CAAA,CAAC,CAAC;AAUH;;;;;;;;;AASG;AACI,MAAM,sBAAsB,GAA2B,CAAC,QAAQ,KAAK,CAAO,IAAI,KAAIC,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;IACzF,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAE3C,IAAI;QACF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,CAClC,cAAc,EACd;YACE,OAAO;AACP,YAAA,IAAI,EAAE,OAAO;YACb,OAAO;AACR,SAAA,CACF,CAAC;AAEF,QAAA,OAAO,qBAAqB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC1C,KAAA;AAAC,IAAA,OAAO,KAAK,EAAE;AACd,QAAA,MAAMC,iBAAW,CAAC,KAAK,CAAC,CAAC;AAC1B,KAAA;AACH,CAAC;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-git-tree.js","sources":["../../../src/github/commits/create-git-tree.ts"],"sourcesContent":["import type { AxiosInstance } from 'axios';\nimport { z } from 'zod';\n\nimport { handleError } from './utils';\n\nexport type Blob = {\n path: string;\n sha: string;\n};\n\nexport type CreateGitTreeArgs = {\n baseTreeSha: string;\n blobs: Blob[];\n};\n\nexport type CreateGitTreeResponse = {\n sha: string;\n url: string;\n};\n\nconst createGitTreeSchema = z.object({\n sha: z.string(),\n url: z.string(),\n});\n\nexport type CreateGitTree = (\n args: CreateGitTreeArgs\n) => Promise<CreateGitTreeResponse>;\n\nexport type CreateGitTreeFactory = (instance: AxiosInstance) => CreateGitTree;\n\n/**\n * Create a git tree\n *\n * @param owner the owner of the repository\n * @param repo the name of the repository\n * @param token the github token\n * @param baseTreeSha the sha of the base tree\n * @param blobs the blobs to add to the tree\n * @returns CreateGitTreeResponse\n * @throws forbidden\n * @throws resource-not-found\n * @throws validation-failed-or-the-endpoint-has-been-spammed\n */\nexport const createGitTreeFactory: CreateGitTreeFactory = (instance) => async (args) => {\n const { baseTreeSha, blobs } = args;\n\n const tree = blobs.map((blob) => ({\n path: blob.path,\n mode: '100644',\n type: 'blob',\n sha: blob.sha,\n }));\n\n try {\n const { data } = await instance.post<CreateGitTreeResponse>(\n '/git/trees',\n {\n base_tree: baseTreeSha,\n tree,\n },\n );\n\n return createGitTreeSchema.parse(data);\n } catch (error) {\n throw handleError(error);\n }\n};\n"],"names":["z","__awaiter","handleError"],"mappings":";;;;;;;;AAoBA,MAAM,mBAAmB,GAAGA,KAAC,CAAC,MAAM,CAAC;AACnC,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AACf,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AAChB,CAAA,CAAC,CAAC;AAQH;;;;;;;;;;;;AAYG;AACI,MAAM,oBAAoB,GAAyB,CAAC,QAAQ,KAAK,CAAO,IAAI,KAAIC,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;AACrF,IAAA,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAEpC,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,MAAM;QAChC,IAAI,EAAE,IAAI,CAAC,IAAI;AACf,QAAA,IAAI,EAAE,QAAQ;AACd,QAAA,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,IAAI,CAAC,GAAG;AACd,KAAA,CAAC,CAAC,CAAC;IAEJ,IAAI;QACF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,CAClC,YAAY,EACZ;AACE,YAAA,SAAS,EAAE,WAAW;YACtB,IAAI;AACL,SAAA,CACF,CAAC;AAEF,QAAA,OAAO,mBAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACxC,KAAA;AAAC,IAAA,OAAO,KAAK,EAAE;AACd,QAAA,MAAMC,iBAAW,CAAC,KAAK,CAAC,CAAC;AAC1B,KAAA;AACH,CAAC;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-sha-last-commit-of-branch.js","sources":["../../../src/github/commits/get-sha-last-commit-of-branch.ts"],"sourcesContent":["import type { AxiosInstance } from 'axios';\nimport { z } from 'zod';\n\nimport { handleError } from './utils';\n\nexport type GetShaLastCommitOfBranchArgs = {\n ref: `/heads/${string}`;\n};\n\nexport type GetShaLastCommitOfBranchResponse = {\n sha: string;\n url: string;\n};\n\nconst getShaLastCommitOfBranchSchema = z.object({\n sha: z.string(),\n url: z.string(),\n});\n\nexport type GetShaLastCommitOfBranch = (\n args: GetShaLastCommitOfBranchArgs\n) => Promise<GetShaLastCommitOfBranchResponse>;\n\nexport type GetShaLastCommitOfBranchFactory = (\n instance: AxiosInstance\n) => GetShaLastCommitOfBranch;\n\n/**\n * Get the sha of the last commit of a branch\n *\n * @param owner the owner of the repository\n * @param repo the name of the repository\n * @param ref the reference to a branch. Example: /heads/master\n * @param token the github token\n * @returns GetShaLastCommitOfBranchResponse\n * @throws ref-not-found\n */\nexport const getShaLastCommitOfBranchFactory: GetShaLastCommitOfBranchFactory = (instance) => async (args) => {\n const { ref } = args;\n\n try {\n const { data } = await instance.get<{\n object: GetShaLastCommitOfBranchResponse;\n }>(`/git/refs/${ref}`);\n\n return getShaLastCommitOfBranchSchema.parse(data.object);\n } catch (error) {\n throw handleError(error);\n }\n};\n"],"names":["z","__awaiter","handleError"],"mappings":";;;;;;;;AAcA,MAAM,8BAA8B,GAAGA,KAAC,CAAC,MAAM,CAAC;AAC9C,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AACf,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AAChB,CAAA,CAAC,CAAC;AAUH;;;;;;;;;AASG;AACI,MAAM,+BAA+B,GAAoC,CAAC,QAAQ,KAAK,CAAO,IAAI,KAAIC,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;AAC3G,IAAA,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAErB,IAAI;AACF,QAAA,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,GAAG,CAEhC,CAAA,UAAA,EAAa,GAAG,CAAA,CAAE,CAAC,CAAC;QAEvB,OAAO,8BAA8B,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC1D,KAAA;AAAC,IAAA,OAAO,KAAK,EAAE;AACd,QAAA,MAAMC,iBAAW,CAAC,KAAK,CAAC,CAAC;AAC1B,KAAA;AACH,CAAC;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-tree-by-commit-sha.js","sources":["../../../src/github/commits/get-tree-by-commit-sha.ts"],"sourcesContent":["import type { AxiosInstance } from 'axios';\nimport { z } from 'zod';\n\nimport { handleError } from './utils';\n\nexport type GetTreeFromCommitShaArgs = {\n sha: string;\n};\n\nexport type GetTreeFromCommitShaResponse = {\n url: string;\n sha: string;\n};\n\nconst getTreeFromCommitShaSchema = z.object({\n url: z.string(),\n sha: z.string(),\n});\n\nexport type GetTreeByCommitSha = (\n args: GetTreeFromCommitShaArgs\n) => Promise<GetTreeFromCommitShaResponse>;\n\nexport type GetTreeByCommitShaFactory = (\n instance: AxiosInstance\n) => GetTreeByCommitSha;\n\n/**\n * Get the tree of a commit\n *\n * @param owner the owner of the repository\n * @param repo the name of the repository\n * @param sha the sha of the commit\n * @param token the github token\n * @returns GetTreeFromCommitShaResponse\n * @throws sha-not-found\n * @throws validation-failed-or-the-endpoint-has-been-spammed\n * @throws internal-server-error\n */\nexport const getTreeByCommitShaFactory: GetTreeByCommitShaFactory = (instance) => async (args) => {\n const { sha } = args;\n\n try {\n const { data } = await instance.get<{\n tree: GetTreeFromCommitShaResponse;\n }>(`/git/commits/${sha}`);\n\n return getTreeFromCommitShaSchema.parse(data.tree);\n } catch (error) {\n throw handleError(error);\n }\n};\n"],"names":["z","__awaiter","handleError"],"mappings":";;;;;;;;AAcA,MAAM,0BAA0B,GAAGA,KAAC,CAAC,MAAM,CAAC;AAC1C,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AACf,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AAChB,CAAA,CAAC,CAAC;AAUH;;;;;;;;;;;AAWG;AACI,MAAM,yBAAyB,GAA8B,CAAC,QAAQ,KAAK,CAAO,IAAI,KAAIC,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;AAC/F,IAAA,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAErB,IAAI;AACF,QAAA,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,GAAG,CAEhC,CAAA,aAAA,EAAgB,GAAG,CAAA,CAAE,CAAC,CAAC;QAE1B,OAAO,0BAA0B,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACpD,KAAA;AAAC,IAAA,OAAO,KAAK,EAAE;AACd,QAAA,MAAMC,iBAAW,CAAC,KAAK,CAAC,CAAC;AAC1B,KAAA;AACH,CAAC;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"run-new-commit-process.js","sources":["../../../src/github/commits/run-new-commit-process.ts"],"sourcesContent":["import type { CreateGitBlob } from './create-git-blob';\nimport type { CreateGitCommit } from './create-git-commit';\nimport type { CreateGitTree } from './create-git-tree';\nimport type { GetShaLastCommitOfBranch } from './get-sha-last-commit-of-branch';\nimport type { GetTreeByCommitSha } from './get-tree-by-commit-sha';\n\nexport type VersionedFile = {\n path: string;\n content: string;\n};\n\nexport type RunNewCommitProcessArgs = {\n message: string;\n ref: `/heads/${string}`;\n files: VersionedFile[];\n};\n\nexport type RunNewCommitProcessResponse = {\n sha: string;\n url: string;\n};\n\nexport type RunNewCommitProcess = (\n args: RunNewCommitProcessArgs,\n updateState?: (state: string) => void\n) => Promise<RunNewCommitProcessResponse>;\n\nexport type RunNewCommitProcessFactory = (args: {\n createGitBlob: CreateGitBlob;\n createGitCommit: CreateGitCommit;\n createGitTree: CreateGitTree;\n getShaLastCommitOfBranch: GetShaLastCommitOfBranch;\n getTreeByCommitSha: GetTreeByCommitSha;\n}) => RunNewCommitProcess;\n\nexport const runNewCommitProcessFactory: RunNewCommitProcessFactory = (args) => async (\n runNewCommitProcessArgs,\n updateState = () => {},\n) => {\n const { createGitBlob, createGitCommit, createGitTree, getShaLastCommitOfBranch, getTreeByCommitSha } = args;\n\n const { message, ref, files } = runNewCommitProcessArgs;\n\n updateState('retrieving-sha-last-commit-of-branch');\n const { sha: shaLastCommit } = await getShaLastCommitOfBranch({\n ref,\n });\n updateState('retrieved-sha-last-commit-of-branch');\n\n updateState('creating-blobs-from-file');\n const blobs = await Promise.all(\n files.map(async (file) => {\n const blob = await createGitBlob({\n content: file.content,\n encoding: 'utf-8',\n });\n\n return {\n path: file.path,\n sha: blob.sha,\n };\n }),\n );\n updateState('created-blobs-from-file');\n\n updateState('retrieving-branch-current-tree');\n const { sha: lastCommitTreeSha } = await getTreeByCommitSha({\n sha: shaLastCommit,\n });\n updateState('retrieved-branch-current-tree');\n\n updateState('creating-new-tree-with-changes');\n const tree = await createGitTree({\n baseTreeSha: lastCommitTreeSha,\n blobs,\n });\n updateState('created-new-tree-with-changes');\n\n updateState('creating-new-commit');\n const commit = await createGitCommit({\n message,\n treeSha: tree.sha,\n parents: [shaLastCommit],\n });\n updateState('created-new-commit');\n\n return commit;\n};\n"],"names":["__awaiter"],"mappings":";;;;;;AAmCa,MAAA,0BAA0B,GAA+B,CAAC,IAAI,KAAK,CAC9E,uBAAuB,EACvB,WAAW,GAAG,MAAO,GAAC,KACpBA,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;AACF,IAAA,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAC;IAE7G,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,uBAAuB,CAAC;IAExD,WAAW,CAAC,sCAAsC,CAAC,CAAC;IACpD,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,MAAM,wBAAwB,CAAC;QAC5D,GAAG;AACJ,KAAA,CAAC,CAAC;IACH,WAAW,CAAC,qCAAqC,CAAC,CAAC;IAEnD,WAAW,CAAC,0BAA0B,CAAC,CAAC;AACxC,IAAA,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAC7B,KAAK,CAAC,GAAG,CAAC,CAAO,IAAI,KAAIA,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;AACvB,QAAA,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC;YAC/B,OAAO,EAAE,IAAI,CAAC,OAAO;AACrB,YAAA,QAAQ,EAAE,OAAO;AAClB,SAAA,CAAC,CAAC;QAEH,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,GAAG,EAAE,IAAI,CAAC,GAAG;SACd,CAAC;KACH,CAAA,CAAC,CACH,CAAC;IACF,WAAW,CAAC,yBAAyB,CAAC,CAAC;IAEvC,WAAW,CAAC,gCAAgC,CAAC,CAAC;IAC9C,MAAM,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,MAAM,kBAAkB,CAAC;AAC1D,QAAA,GAAG,EAAE,aAAa;AACnB,KAAA,CAAC,CAAC;IACH,WAAW,CAAC,+BAA+B,CAAC,CAAC;IAE7C,WAAW,CAAC,gCAAgC,CAAC,CAAC;AAC9C,IAAA,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC;AAC/B,QAAA,WAAW,EAAE,iBAAiB;QAC9B,KAAK;AACN,KAAA,CAAC,CAAC;IACH,WAAW,CAAC,+BAA+B,CAAC,CAAC;IAE7C,WAAW,CAAC,qBAAqB,CAAC,CAAC;AACnC,IAAA,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC;QACnC,OAAO;QACP,OAAO,EAAE,IAAI,CAAC,GAAG;QACjB,OAAO,EAAE,CAAC,aAAa,CAAC;AACzB,KAAA,CAAC,CAAC;IACH,WAAW,CAAC,oBAAoB,CAAC,CAAC;AAElC,IAAA,OAAO,MAAM,CAAC;AAChB,CAAC;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sources":["../../../src/github/commits/utils.ts"],"sourcesContent":["import type { AxiosResponse } from 'axios';\n\nexport const handleError = (error: unknown): Error => {\n const { response } = error as any;\n\n if (response) {\n const { status } = response as AxiosResponse;\n\n if (status === 403) {\n return new Error('forbidden');\n }\n\n if (status === 404) {\n return new Error('resource-not-found');\n }\n\n if (status === 409) {\n return new Error('conflict');\n }\n\n if (status === 422) {\n return new Error('validation-failed-or-the-endpoint-has-been-spammed');\n }\n\n if (status === 500) {\n return new Error('internal-server-error');\n }\n }\n\n return error as Error;\n};\n"],"names":[],"mappings":";;;;AAEa,MAAA,WAAW,GAAG,CAAC,KAAc,KAAW;AACnD,IAAA,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAY,CAAC;AAElC,IAAA,IAAI,QAAQ,EAAE;AACZ,QAAA,MAAM,EAAE,MAAM,EAAE,GAAG,QAAyB,CAAC;QAE7C,IAAI,MAAM,KAAK,GAAG,EAAE;AAClB,YAAA,OAAO,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC;AAC/B,SAAA;QAED,IAAI,MAAM,KAAK,GAAG,EAAE;AAClB,YAAA,OAAO,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;AACxC,SAAA;QAED,IAAI,MAAM,KAAK,GAAG,EAAE;AAClB,YAAA,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;AAC9B,SAAA;QAED,IAAI,MAAM,KAAK,GAAG,EAAE;AAClB,YAAA,OAAO,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;AACxE,SAAA;QAED,IAAI,MAAM,KAAK,GAAG,EAAE;AAClB,YAAA,OAAO,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;AAC3C,SAAA;AACF,KAAA;AAED,IAAA,OAAO,KAAc,CAAC;AACxB;;;;"}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes