@sparted/shared-library 1.0.8-alpha.4 → 1.0.8-alpha.5
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/dist/github/commit/get-tree-by-commit-sha.d.ts +6 -6
- package/dist/github/commit/get-tree-by-commit-sha.js +3 -3
- package/dist/github/commit/get-tree-by-commit-sha.js.map +1 -1
- package/dist/github/commit/index.js +1 -1
- package/dist/github/commit/run-new-commit-process.d.ts +2 -2
- package/dist/github/commit/run-new-commit-process.js +2 -2
- package/dist/github/commit/run-new-commit-process.js.map +1 -1
- package/dist/github/github.d.ts +6 -4
- package/dist/github/github.js +9 -6
- package/dist/github/github.js.map +1 -1
- package/dist/github/merge/create-pull-request.d.ts +13 -0
- package/dist/github/merge/{create-merge-request.js → create-pull-request.js} +5 -5
- package/dist/github/merge/create-pull-request.js.map +1 -0
- package/dist/github/merge/index.d.ts +2 -1
- package/dist/github/merge/index.js +4 -2
- package/dist/github/merge/index.js.map +1 -1
- package/dist/github/merge/merge-pull-request.d.ts +13 -0
- package/dist/github/merge/merge-pull-request.js +28 -0
- package/dist/github/merge/merge-pull-request.js.map +1 -0
- package/dist/package.json +1 -1
- package/package.json +1 -1
- package/src/github/commit/get-tree-by-commit-sha.ts +10 -10
- package/src/github/commit/run-new-commit-process.ts +4 -4
- package/src/github/github.ts +14 -10
- package/src/github/merge/create-pull-request.ts +40 -0
- package/src/github/merge/index.ts +2 -1
- package/src/github/merge/merge-pull-request.ts +39 -0
- package/dist/github/merge/create-merge-request.d.ts +0 -13
- package/dist/github/merge/create-merge-request.js.map +0 -1
- package/src/github/merge/create-merge-request.ts +0 -40
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { AxiosInstance } from 'axios';
|
|
2
|
-
export declare type
|
|
2
|
+
export declare type GetTreeShaFromCommitArgs = {
|
|
3
3
|
sha: string;
|
|
4
4
|
};
|
|
5
|
-
export declare type
|
|
5
|
+
export declare type GetTreeShaFromCommitResponse = {
|
|
6
6
|
url: string;
|
|
7
7
|
sha: string;
|
|
8
8
|
};
|
|
9
|
-
export declare type
|
|
10
|
-
export declare type
|
|
9
|
+
export declare type GetTreeShaFromCommit = (args: GetTreeShaFromCommitArgs) => Promise<GetTreeShaFromCommitResponse>;
|
|
10
|
+
export declare type GetTreeShaFromCommitFactory = (instance: AxiosInstance) => GetTreeShaFromCommit;
|
|
11
11
|
/**
|
|
12
12
|
* Get the tree of a commit
|
|
13
13
|
*
|
|
@@ -15,9 +15,9 @@ export declare type GetTreeByCommitShaFactory = (instance: AxiosInstance) => Get
|
|
|
15
15
|
* @param repo the name of the repository
|
|
16
16
|
* @param sha the sha of the commit
|
|
17
17
|
* @param token the github token
|
|
18
|
-
* @returns
|
|
18
|
+
* @returns GetTreeShaFromCommitResponse
|
|
19
19
|
* @throws sha-not-found
|
|
20
20
|
* @throws validation-failed-or-the-endpoint-has-been-spammed
|
|
21
21
|
* @throws internal-server-error
|
|
22
22
|
*/
|
|
23
|
-
export declare const
|
|
23
|
+
export declare const getTreeShaFromCommitFactory: GetTreeShaFromCommitFactory;
|
|
@@ -17,12 +17,12 @@ const getTreeFromCommitShaSchema = zod.z.object({
|
|
|
17
17
|
* @param repo the name of the repository
|
|
18
18
|
* @param sha the sha of the commit
|
|
19
19
|
* @param token the github token
|
|
20
|
-
* @returns
|
|
20
|
+
* @returns GetTreeShaFromCommitResponse
|
|
21
21
|
* @throws sha-not-found
|
|
22
22
|
* @throws validation-failed-or-the-endpoint-has-been-spammed
|
|
23
23
|
* @throws internal-server-error
|
|
24
24
|
*/
|
|
25
|
-
const
|
|
25
|
+
const getTreeShaFromCommitFactory = (instance) => (args) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
26
26
|
const { sha } = args;
|
|
27
27
|
try {
|
|
28
28
|
const { data } = yield instance.get(`/git/commits/${sha}`);
|
|
@@ -33,5 +33,5 @@ const getTreeByCommitShaFactory = (instance) => (args) => _tslib.__awaiter(void
|
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
exports.
|
|
36
|
+
exports.getTreeShaFromCommitFactory = getTreeShaFromCommitFactory;
|
|
37
37
|
//# sourceMappingURL=get-tree-by-commit-sha.js.map
|
|
@@ -1 +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
|
|
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 GetTreeShaFromCommitArgs = {\n sha: string;\n};\n\nexport type GetTreeShaFromCommitResponse = {\n url: string;\n sha: string;\n};\n\nconst getTreeFromCommitShaSchema = z.object({\n url: z.string(),\n sha: z.string(),\n});\n\nexport type GetTreeShaFromCommit = (\n args: GetTreeShaFromCommitArgs\n) => Promise<GetTreeShaFromCommitResponse>;\n\nexport type GetTreeShaFromCommitFactory = (\n instance: AxiosInstance\n) => GetTreeShaFromCommit;\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 GetTreeShaFromCommitResponse\n * @throws sha-not-found\n * @throws validation-failed-or-the-endpoint-has-been-spammed\n * @throws internal-server-error\n */\nexport const getTreeShaFromCommitFactory: GetTreeShaFromCommitFactory = (instance) => async (args) => {\n const { sha } = args;\n\n try {\n const { data } = await instance.get<{\n tree: GetTreeShaFromCommitResponse;\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,2BAA2B,GAAgC,CAAC,QAAQ,KAAK,CAAO,IAAI,KAAIC,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;AACnG,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;;;;"}
|
|
@@ -15,6 +15,6 @@ exports.createGitBlobFactory = createGitBlob.createGitBlobFactory;
|
|
|
15
15
|
exports.createGitCommitFactory = createGitCommit.createGitCommitFactory;
|
|
16
16
|
exports.createGitTreeFactory = createGitTree.createGitTreeFactory;
|
|
17
17
|
exports.getShaLastCommitOfBranchFactory = getShaLastCommitOfBranch.getShaLastCommitOfBranchFactory;
|
|
18
|
-
exports.
|
|
18
|
+
exports.getTreeShaFromCommitFactory = getTreeByCommitSha.getTreeShaFromCommitFactory;
|
|
19
19
|
exports.runNewCommitProcessFactory = runNewCommitProcess.runNewCommitProcessFactory;
|
|
20
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -2,7 +2,7 @@ import type { CreateGitBlob } from './create-git-blob';
|
|
|
2
2
|
import type { CreateGitCommit } from './create-git-commit';
|
|
3
3
|
import type { CreateGitTree } from './create-git-tree';
|
|
4
4
|
import type { GetShaLastCommitOfBranch } from './get-sha-last-commit-of-branch';
|
|
5
|
-
import type {
|
|
5
|
+
import type { GetTreeShaFromCommit } from './get-tree-by-commit-sha';
|
|
6
6
|
export declare type VersionedFile = {
|
|
7
7
|
path: string;
|
|
8
8
|
content: string;
|
|
@@ -22,6 +22,6 @@ export declare type RunNewCommitProcessFactory = (args: {
|
|
|
22
22
|
createGitCommit: CreateGitCommit;
|
|
23
23
|
createGitTree: CreateGitTree;
|
|
24
24
|
getShaLastCommitOfBranch: GetShaLastCommitOfBranch;
|
|
25
|
-
|
|
25
|
+
getTreeShaFromCommit: GetTreeShaFromCommit;
|
|
26
26
|
}) => RunNewCommitProcess;
|
|
27
27
|
export declare const runNewCommitProcessFactory: RunNewCommitProcessFactory;
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var _tslib = require('../../_virtual/_tslib.js');
|
|
6
6
|
|
|
7
7
|
const runNewCommitProcessFactory = (args) => (runNewCommitProcessArgs, updateState = () => { }) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
-
const { createGitBlob, createGitCommit, createGitTree, getShaLastCommitOfBranch,
|
|
8
|
+
const { createGitBlob, createGitCommit, createGitTree, getShaLastCommitOfBranch, getTreeShaFromCommit } = args;
|
|
9
9
|
const { message, ref, files } = runNewCommitProcessArgs;
|
|
10
10
|
updateState('retrieving-sha-last-commit-of-branch');
|
|
11
11
|
const { sha: shaLastCommit } = yield getShaLastCommitOfBranch({
|
|
@@ -25,7 +25,7 @@ const runNewCommitProcessFactory = (args) => (runNewCommitProcessArgs, updateSta
|
|
|
25
25
|
})));
|
|
26
26
|
updateState('created-blobs-from-file');
|
|
27
27
|
updateState('retrieving-branch-current-tree');
|
|
28
|
-
const { sha: lastCommitTreeSha } = yield
|
|
28
|
+
const { sha: lastCommitTreeSha } = yield getTreeShaFromCommit({
|
|
29
29
|
sha: shaLastCommit,
|
|
30
30
|
});
|
|
31
31
|
updateState('retrieved-branch-current-tree');
|
|
@@ -1 +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 {
|
|
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 { GetTreeShaFromCommit } 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 getTreeShaFromCommit: GetTreeShaFromCommit;\n}) => RunNewCommitProcess;\n\nexport const runNewCommitProcessFactory: RunNewCommitProcessFactory = (args) => async (\n runNewCommitProcessArgs,\n updateState = () => {},\n) => {\n const { createGitBlob, createGitCommit, createGitTree, getShaLastCommitOfBranch, getTreeShaFromCommit } = 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 getTreeShaFromCommit({\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,oBAAoB,EAAE,GAAG,IAAI,CAAC;IAE/G,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,oBAAoB,CAAC;AAC5D,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;;;;"}
|
package/dist/github/github.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { CreateGitTree, CreateGitBlob, CreateGitCommit,
|
|
1
|
+
import type { CreateGitTree, CreateGitBlob, CreateGitCommit, GetTreeShaFromCommit, GetShaLastCommitOfBranch, RunNewCommitProcess } from './commit';
|
|
2
2
|
import { GetFileContent } from './content/get-file-content';
|
|
3
3
|
import { CreateBranch, UpdateBranch } from './branch';
|
|
4
|
-
import {
|
|
4
|
+
import { CreatePullRequest } from './merge';
|
|
5
|
+
import { MergePullRequest } from './merge/merge-pull-request';
|
|
5
6
|
export declare type GithubSdkArgs = {
|
|
6
7
|
owner: string;
|
|
7
8
|
repo: string;
|
|
@@ -12,12 +13,13 @@ export declare type GithubSdkInstance = {
|
|
|
12
13
|
createGitCommit: CreateGitCommit;
|
|
13
14
|
createGitTree: CreateGitTree;
|
|
14
15
|
getShaLastCommitOfBranch: GetShaLastCommitOfBranch;
|
|
15
|
-
|
|
16
|
+
getTreeShaFromCommit: GetTreeShaFromCommit;
|
|
16
17
|
runNewCommitProcess: RunNewCommitProcess;
|
|
17
18
|
getFileContent: GetFileContent;
|
|
18
19
|
createBranch: CreateBranch;
|
|
19
20
|
updateBranch: UpdateBranch;
|
|
20
|
-
|
|
21
|
+
createPullRequest: CreatePullRequest;
|
|
22
|
+
mergePullRequest: MergePullRequest;
|
|
21
23
|
};
|
|
22
24
|
export declare type GithubSdk = (args: GithubSdkArgs) => GithubSdkInstance;
|
|
23
25
|
export declare const githubSdk: GithubSdk;
|
package/dist/github/github.js
CHANGED
|
@@ -12,7 +12,8 @@ var runNewCommitProcess = require('./commit/run-new-commit-process.js');
|
|
|
12
12
|
var getFileContent = require('./content/get-file-content.js');
|
|
13
13
|
var createBranch = require('./branch/create-branch.js');
|
|
14
14
|
var updateBranch = require('./branch/update-branch.js');
|
|
15
|
-
var
|
|
15
|
+
var createPullRequest = require('./merge/create-pull-request.js');
|
|
16
|
+
var mergePullRequest = require('./merge/merge-pull-request.js');
|
|
16
17
|
|
|
17
18
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
18
19
|
|
|
@@ -32,29 +33,31 @@ const githubSdk = (args) => {
|
|
|
32
33
|
const createGitCommit$1 = createGitCommit.createGitCommitFactory(instance);
|
|
33
34
|
const createGitTree$1 = createGitTree.createGitTreeFactory(instance);
|
|
34
35
|
const getShaLastCommitOfBranch$1 = getShaLastCommitOfBranch.getShaLastCommitOfBranchFactory(instance);
|
|
35
|
-
const
|
|
36
|
+
const getTreeShaFromCommit = getTreeByCommitSha.getTreeShaFromCommitFactory(instance);
|
|
36
37
|
const getFileContent$1 = getFileContent.getFileContentFactory(instance);
|
|
37
38
|
const runNewCommitProcess$1 = runNewCommitProcess.runNewCommitProcessFactory({
|
|
38
39
|
createGitBlob: createGitBlob$1,
|
|
39
40
|
createGitCommit: createGitCommit$1,
|
|
40
41
|
createGitTree: createGitTree$1,
|
|
41
42
|
getShaLastCommitOfBranch: getShaLastCommitOfBranch$1,
|
|
42
|
-
|
|
43
|
+
getTreeShaFromCommit,
|
|
43
44
|
});
|
|
44
45
|
const createBranch$1 = createBranch.createBranchFactory(instance);
|
|
45
46
|
const updateBranch$1 = updateBranch.updateBranchFactory(instance);
|
|
46
|
-
const
|
|
47
|
+
const createPullRequest$1 = createPullRequest.createPullRequestFactory(instance);
|
|
48
|
+
const mergePullRequest$1 = mergePullRequest.mergePullRequestFactory(instance);
|
|
47
49
|
return {
|
|
48
50
|
createGitBlob: createGitBlob$1,
|
|
49
51
|
createGitCommit: createGitCommit$1,
|
|
50
52
|
createGitTree: createGitTree$1,
|
|
51
53
|
getShaLastCommitOfBranch: getShaLastCommitOfBranch$1,
|
|
52
|
-
|
|
54
|
+
getTreeShaFromCommit,
|
|
53
55
|
runNewCommitProcess: runNewCommitProcess$1,
|
|
54
56
|
getFileContent: getFileContent$1,
|
|
55
57
|
createBranch: createBranch$1,
|
|
56
58
|
updateBranch: updateBranch$1,
|
|
57
|
-
|
|
59
|
+
createPullRequest: createPullRequest$1,
|
|
60
|
+
mergePullRequest: mergePullRequest$1,
|
|
58
61
|
};
|
|
59
62
|
};
|
|
60
63
|
|
|
@@ -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
|
|
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 getTreeShaFromCommitFactory,\n runNewCommitProcessFactory,\n} from './commit';\nimport type {\n CreateGitTree,\n CreateGitBlob,\n CreateGitCommit,\n GetTreeShaFromCommit,\n GetShaLastCommitOfBranch,\n RunNewCommitProcess,\n} from './commit';\nimport { GetFileContent, getFileContentFactory } from './content/get-file-content';\nimport { CreateBranch, UpdateBranch, createBranchFactory, updateBranchFactory } from './branch';\nimport { CreatePullRequest, createPullRequestFactory } from './merge';\nimport { MergePullRequest, mergePullRequestFactory } from './merge/merge-pull-request';\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 getTreeShaFromCommit: GetTreeShaFromCommit;\n runNewCommitProcess: RunNewCommitProcess;\n getFileContent: GetFileContent;\n createBranch: CreateBranch;\n updateBranch: UpdateBranch;\n createPullRequest: CreatePullRequest;\n mergePullRequest: MergePullRequest;\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 getTreeShaFromCommit = getTreeShaFromCommitFactory(instance);\n\n const getFileContent = getFileContentFactory(instance);\n\n const runNewCommitProcess = runNewCommitProcessFactory({\n createGitBlob,\n createGitCommit,\n createGitTree,\n getShaLastCommitOfBranch,\n getTreeShaFromCommit,\n });\n\n const createBranch = createBranchFactory(instance);\n const updateBranch = updateBranchFactory(instance);\n\n const createPullRequest = createPullRequestFactory(instance);\n const mergePullRequest = mergePullRequestFactory(instance);\n\n return {\n createGitBlob,\n createGitCommit,\n createGitTree,\n getShaLastCommitOfBranch,\n getTreeShaFromCommit,\n runNewCommitProcess,\n getFileContent,\n createBranch,\n updateBranch,\n createPullRequest,\n mergePullRequest,\n };\n};\n"],"names":["axios","createGitBlob","createGitBlobFactory","createGitCommit","createGitCommitFactory","createGitTree","createGitTreeFactory","getShaLastCommitOfBranch","getShaLastCommitOfBranchFactory","getTreeShaFromCommitFactory","getFileContent","getFileContentFactory","runNewCommitProcess","runNewCommitProcessFactory","createBranch","createBranchFactory","updateBranch","updateBranchFactory","createPullRequest","createPullRequestFactory","mergePullRequest","mergePullRequestFactory"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA6Ca,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,MAAM,oBAAoB,GAAGC,8CAA2B,CAAC,QAAQ,CAAC,CAAC;AAEnE,IAAA,MAAMC,gBAAc,GAAGC,oCAAqB,CAAC,QAAQ,CAAC,CAAC;IAEvD,MAAMC,qBAAmB,GAAGC,8CAA0B,CAAC;uBACrDZ,eAAa;yBACbE,iBAAe;uBACfE,eAAa;kCACbE,0BAAwB;QACxB,oBAAoB;AACrB,KAAA,CAAC,CAAC;AAEH,IAAA,MAAMO,cAAY,GAAGC,gCAAmB,CAAC,QAAQ,CAAC,CAAC;AACnD,IAAA,MAAMC,cAAY,GAAGC,gCAAmB,CAAC,QAAQ,CAAC,CAAC;AAEnD,IAAA,MAAMC,mBAAiB,GAAGC,0CAAwB,CAAC,QAAQ,CAAC,CAAC;AAC7D,IAAA,MAAMC,kBAAgB,GAAGC,wCAAuB,CAAC,QAAQ,CAAC,CAAC;IAE3D,OAAO;uBACLpB,eAAa;yBACbE,iBAAe;uBACfE,eAAa;kCACbE,0BAAwB;QACxB,oBAAoB;6BACpBK,qBAAmB;wBACnBF,gBAAc;sBACdI,cAAY;sBACZE,cAAY;2BACZE,mBAAiB;0BACjBE,kBAAgB;KACjB,CAAC;AACJ;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AxiosInstance } from 'axios';
|
|
2
|
+
export declare type CreatePullRequestArgs = {
|
|
3
|
+
title: string;
|
|
4
|
+
body: string;
|
|
5
|
+
head: string;
|
|
6
|
+
base: string;
|
|
7
|
+
};
|
|
8
|
+
export declare type CreatePullRequestResponse = {
|
|
9
|
+
url: string;
|
|
10
|
+
};
|
|
11
|
+
export declare type CreatePullRequest = (args: CreatePullRequestArgs) => Promise<CreatePullRequestResponse>;
|
|
12
|
+
export declare type CreatePullRequestFactory = (instance: AxiosInstance) => CreatePullRequest;
|
|
13
|
+
export declare const createPullRequestFactory: CreatePullRequestFactory;
|
|
@@ -6,10 +6,10 @@ var _tslib = require('../../_virtual/_tslib.js');
|
|
|
6
6
|
var zod = require('zod');
|
|
7
7
|
var utils = require('../commit/utils.js');
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const createPullRequestResponseSchema = zod.z.object({
|
|
10
10
|
url: zod.z.string(),
|
|
11
11
|
});
|
|
12
|
-
const
|
|
12
|
+
const createPullRequestFactory = (instance) => (args) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
13
13
|
const { title, body, head, base } = args;
|
|
14
14
|
try {
|
|
15
15
|
const { data } = yield instance.post('/pulls', {
|
|
@@ -18,12 +18,12 @@ const createMergeRequestFactory = (instance) => (args) => _tslib.__awaiter(void
|
|
|
18
18
|
head,
|
|
19
19
|
base,
|
|
20
20
|
});
|
|
21
|
-
return
|
|
21
|
+
return createPullRequestResponseSchema.parse(data);
|
|
22
22
|
}
|
|
23
23
|
catch (error) {
|
|
24
24
|
throw utils.handleError(error);
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
exports.
|
|
29
|
-
//# sourceMappingURL=create-
|
|
28
|
+
exports.createPullRequestFactory = createPullRequestFactory;
|
|
29
|
+
//# sourceMappingURL=create-pull-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-pull-request.js","sources":["../../../src/github/merge/create-pull-request.ts"],"sourcesContent":["import type { AxiosInstance } from 'axios';\nimport { z } from 'zod';\n\nimport { handleError } from '../commit/utils';\n\nexport type CreatePullRequestArgs = {\n title: string;\n body: string;\n head: string;\n base: string;\n};\n\nexport type CreatePullRequestResponse = {\n url: string;\n};\n\nconst createPullRequestResponseSchema = z.object({\n url: z.string(),\n});\n\nexport type CreatePullRequest = (args: CreatePullRequestArgs) => Promise<CreatePullRequestResponse>;\n\nexport type CreatePullRequestFactory = (instance: AxiosInstance) => CreatePullRequest;\n\nexport const createPullRequestFactory: CreatePullRequestFactory = (instance) => async (args) => {\n const { title, body, head, base } = args;\n\n try {\n const { data } = await instance.post<CreatePullRequestResponse>('/pulls', {\n title,\n body,\n head,\n base,\n });\n\n return createPullRequestResponseSchema.parse(data);\n } catch (error) {\n throw handleError(error);\n }\n};\n"],"names":["z","__awaiter","handleError"],"mappings":";;;;;;;;AAgBA,MAAM,+BAA+B,GAAGA,KAAC,CAAC,MAAM,CAAC;AAC/C,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AAChB,CAAA,CAAC,CAAC;AAMI,MAAM,wBAAwB,GAA6B,CAAC,QAAQ,KAAK,CAAO,IAAI,KAAIC,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;IAC7F,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IAEzC,IAAI;QACF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,CAA4B,QAAQ,EAAE;YACxE,KAAK;YACL,IAAI;YACJ,IAAI;YACJ,IAAI;AACL,SAAA,CAAC,CAAC;AAEH,QAAA,OAAO,+BAA+B,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACpD,KAAA;AAAC,IAAA,OAAO,KAAK,EAAE;AACd,QAAA,MAAMC,iBAAW,CAAC,KAAK,CAAC,CAAC;AAC1B,KAAA;AACH,CAAC;;;;"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './create-
|
|
1
|
+
export * from './create-pull-request';
|
|
2
|
+
export * from './merge-pull-request';
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var createPullRequest = require('./create-pull-request.js');
|
|
6
|
+
var mergePullRequest = require('./merge-pull-request.js');
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
|
|
9
|
-
exports.
|
|
10
|
+
exports.createPullRequestFactory = createPullRequest.createPullRequestFactory;
|
|
11
|
+
exports.mergePullRequestFactory = mergePullRequest.mergePullRequestFactory;
|
|
10
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
export declare type MergePullRequestArgs = {
|
|
3
|
+
pullRequestNumber: number;
|
|
4
|
+
commitTitle: string;
|
|
5
|
+
commitMessage: string;
|
|
6
|
+
mergeMethod: 'merge' | 'squash' | 'rebase';
|
|
7
|
+
};
|
|
8
|
+
export declare type MergePullRequestResponse = {
|
|
9
|
+
sha: string;
|
|
10
|
+
};
|
|
11
|
+
export declare type MergePullRequest = (args: MergePullRequestArgs) => Promise<MergePullRequestResponse>;
|
|
12
|
+
export declare type MergePullRequestFactory = (instance: AxiosInstance) => MergePullRequest;
|
|
13
|
+
export declare const mergePullRequestFactory: MergePullRequestFactory;
|
|
@@ -0,0 +1,28 @@
|
|
|
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 mergePullRequestResponseSchema = zod.z.object({
|
|
10
|
+
sha: zod.z.string(),
|
|
11
|
+
});
|
|
12
|
+
const mergePullRequestFactory = (instance) => (args) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
+
const { pullRequestNumber, commitTitle, commitMessage, mergeMethod } = args;
|
|
14
|
+
try {
|
|
15
|
+
const { data } = yield instance.put(`/pulls/${pullRequestNumber}/merge`, {
|
|
16
|
+
commit_title: commitTitle,
|
|
17
|
+
commit_message: commitMessage,
|
|
18
|
+
merge_method: mergeMethod,
|
|
19
|
+
});
|
|
20
|
+
return mergePullRequestResponseSchema.parse(data);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
throw utils.handleError(error);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
exports.mergePullRequestFactory = mergePullRequestFactory;
|
|
28
|
+
//# sourceMappingURL=merge-pull-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-pull-request.js","sources":["../../../src/github/merge/merge-pull-request.ts"],"sourcesContent":["import { AxiosInstance } from 'axios';\nimport { z } from 'zod';\n\nimport { handleError } from '../commit/utils';\n\nexport type MergePullRequestArgs = {\n pullRequestNumber: number;\n commitTitle: string;\n commitMessage: string;\n mergeMethod: 'merge' | 'squash' | 'rebase';\n};\n\nexport type MergePullRequestResponse = {\n sha: string;\n};\n\nconst mergePullRequestResponseSchema = z.object({\n sha: z.string(),\n});\n\nexport type MergePullRequest = (args: MergePullRequestArgs) => Promise<MergePullRequestResponse>;\n\nexport type MergePullRequestFactory = (instance: AxiosInstance) => MergePullRequest;\n\nexport const mergePullRequestFactory: MergePullRequestFactory = (instance) => async (args) => {\n const { pullRequestNumber, commitTitle, commitMessage, mergeMethod } = args;\n\n try {\n const { data } = await instance.put<MergePullRequestResponse>(`/pulls/${pullRequestNumber}/merge`, {\n commit_title: commitTitle,\n commit_message: commitMessage,\n merge_method: mergeMethod,\n });\n\n return mergePullRequestResponseSchema.parse(data);\n } catch (error) {\n throw handleError(error);\n }\n};\n"],"names":["z","__awaiter","handleError"],"mappings":";;;;;;;;AAgBA,MAAM,8BAA8B,GAAGA,KAAC,CAAC,MAAM,CAAC;AAC9C,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AAChB,CAAA,CAAC,CAAC;AAMI,MAAM,uBAAuB,GAA4B,CAAC,QAAQ,KAAK,CAAO,IAAI,KAAIC,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;IAC3F,MAAM,EAAE,iBAAiB,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IAE5E,IAAI;AACF,QAAA,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,GAAG,CAA2B,CAAA,OAAA,EAAU,iBAAiB,CAAA,MAAA,CAAQ,EAAE;AACjG,YAAA,YAAY,EAAE,WAAW;AACzB,YAAA,cAAc,EAAE,aAAa;AAC7B,YAAA,YAAY,EAAE,WAAW;AAC1B,SAAA,CAAC,CAAC;AAEH,QAAA,OAAO,8BAA8B,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACnD,KAAA;AAAC,IAAA,OAAO,KAAK,EAAE;AACd,QAAA,MAAMC,iBAAW,CAAC,KAAK,CAAC,CAAC;AAC1B,KAAA;AACH,CAAC;;;;"}
|
package/dist/package.json
CHANGED
package/package.json
CHANGED
|
@@ -3,11 +3,11 @@ import { z } from 'zod';
|
|
|
3
3
|
|
|
4
4
|
import { handleError } from './utils';
|
|
5
5
|
|
|
6
|
-
export type
|
|
6
|
+
export type GetTreeShaFromCommitArgs = {
|
|
7
7
|
sha: string;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
export type
|
|
10
|
+
export type GetTreeShaFromCommitResponse = {
|
|
11
11
|
url: string;
|
|
12
12
|
sha: string;
|
|
13
13
|
};
|
|
@@ -17,13 +17,13 @@ const getTreeFromCommitShaSchema = z.object({
|
|
|
17
17
|
sha: z.string(),
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
export type
|
|
21
|
-
args:
|
|
22
|
-
) => Promise<
|
|
20
|
+
export type GetTreeShaFromCommit = (
|
|
21
|
+
args: GetTreeShaFromCommitArgs
|
|
22
|
+
) => Promise<GetTreeShaFromCommitResponse>;
|
|
23
23
|
|
|
24
|
-
export type
|
|
24
|
+
export type GetTreeShaFromCommitFactory = (
|
|
25
25
|
instance: AxiosInstance
|
|
26
|
-
) =>
|
|
26
|
+
) => GetTreeShaFromCommit;
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Get the tree of a commit
|
|
@@ -32,17 +32,17 @@ export type GetTreeByCommitShaFactory = (
|
|
|
32
32
|
* @param repo the name of the repository
|
|
33
33
|
* @param sha the sha of the commit
|
|
34
34
|
* @param token the github token
|
|
35
|
-
* @returns
|
|
35
|
+
* @returns GetTreeShaFromCommitResponse
|
|
36
36
|
* @throws sha-not-found
|
|
37
37
|
* @throws validation-failed-or-the-endpoint-has-been-spammed
|
|
38
38
|
* @throws internal-server-error
|
|
39
39
|
*/
|
|
40
|
-
export const
|
|
40
|
+
export const getTreeShaFromCommitFactory: GetTreeShaFromCommitFactory = (instance) => async (args) => {
|
|
41
41
|
const { sha } = args;
|
|
42
42
|
|
|
43
43
|
try {
|
|
44
44
|
const { data } = await instance.get<{
|
|
45
|
-
tree:
|
|
45
|
+
tree: GetTreeShaFromCommitResponse;
|
|
46
46
|
}>(`/git/commits/${sha}`);
|
|
47
47
|
|
|
48
48
|
return getTreeFromCommitShaSchema.parse(data.tree);
|
|
@@ -2,7 +2,7 @@ import type { CreateGitBlob } from './create-git-blob';
|
|
|
2
2
|
import type { CreateGitCommit } from './create-git-commit';
|
|
3
3
|
import type { CreateGitTree } from './create-git-tree';
|
|
4
4
|
import type { GetShaLastCommitOfBranch } from './get-sha-last-commit-of-branch';
|
|
5
|
-
import type {
|
|
5
|
+
import type { GetTreeShaFromCommit } from './get-tree-by-commit-sha';
|
|
6
6
|
|
|
7
7
|
export type VersionedFile = {
|
|
8
8
|
path: string;
|
|
@@ -30,14 +30,14 @@ export type RunNewCommitProcessFactory = (args: {
|
|
|
30
30
|
createGitCommit: CreateGitCommit;
|
|
31
31
|
createGitTree: CreateGitTree;
|
|
32
32
|
getShaLastCommitOfBranch: GetShaLastCommitOfBranch;
|
|
33
|
-
|
|
33
|
+
getTreeShaFromCommit: GetTreeShaFromCommit;
|
|
34
34
|
}) => RunNewCommitProcess;
|
|
35
35
|
|
|
36
36
|
export const runNewCommitProcessFactory: RunNewCommitProcessFactory = (args) => async (
|
|
37
37
|
runNewCommitProcessArgs,
|
|
38
38
|
updateState = () => {},
|
|
39
39
|
) => {
|
|
40
|
-
const { createGitBlob, createGitCommit, createGitTree, getShaLastCommitOfBranch,
|
|
40
|
+
const { createGitBlob, createGitCommit, createGitTree, getShaLastCommitOfBranch, getTreeShaFromCommit } = args;
|
|
41
41
|
|
|
42
42
|
const { message, ref, files } = runNewCommitProcessArgs;
|
|
43
43
|
|
|
@@ -64,7 +64,7 @@ export const runNewCommitProcessFactory: RunNewCommitProcessFactory = (args) =>
|
|
|
64
64
|
updateState('created-blobs-from-file');
|
|
65
65
|
|
|
66
66
|
updateState('retrieving-branch-current-tree');
|
|
67
|
-
const { sha: lastCommitTreeSha } = await
|
|
67
|
+
const { sha: lastCommitTreeSha } = await getTreeShaFromCommit({
|
|
68
68
|
sha: shaLastCommit,
|
|
69
69
|
});
|
|
70
70
|
updateState('retrieved-branch-current-tree');
|
package/src/github/github.ts
CHANGED
|
@@ -5,20 +5,21 @@ import {
|
|
|
5
5
|
createGitCommitFactory,
|
|
6
6
|
createGitTreeFactory,
|
|
7
7
|
getShaLastCommitOfBranchFactory,
|
|
8
|
-
|
|
8
|
+
getTreeShaFromCommitFactory,
|
|
9
9
|
runNewCommitProcessFactory,
|
|
10
10
|
} from './commit';
|
|
11
11
|
import type {
|
|
12
12
|
CreateGitTree,
|
|
13
13
|
CreateGitBlob,
|
|
14
14
|
CreateGitCommit,
|
|
15
|
-
|
|
15
|
+
GetTreeShaFromCommit,
|
|
16
16
|
GetShaLastCommitOfBranch,
|
|
17
17
|
RunNewCommitProcess,
|
|
18
18
|
} from './commit';
|
|
19
19
|
import { GetFileContent, getFileContentFactory } from './content/get-file-content';
|
|
20
20
|
import { CreateBranch, UpdateBranch, createBranchFactory, updateBranchFactory } from './branch';
|
|
21
|
-
import {
|
|
21
|
+
import { CreatePullRequest, createPullRequestFactory } from './merge';
|
|
22
|
+
import { MergePullRequest, mergePullRequestFactory } from './merge/merge-pull-request';
|
|
22
23
|
|
|
23
24
|
export type GithubSdkArgs = {
|
|
24
25
|
owner: string;
|
|
@@ -31,12 +32,13 @@ export type GithubSdkInstance = {
|
|
|
31
32
|
createGitCommit: CreateGitCommit;
|
|
32
33
|
createGitTree: CreateGitTree;
|
|
33
34
|
getShaLastCommitOfBranch: GetShaLastCommitOfBranch;
|
|
34
|
-
|
|
35
|
+
getTreeShaFromCommit: GetTreeShaFromCommit;
|
|
35
36
|
runNewCommitProcess: RunNewCommitProcess;
|
|
36
37
|
getFileContent: GetFileContent;
|
|
37
38
|
createBranch: CreateBranch;
|
|
38
39
|
updateBranch: UpdateBranch;
|
|
39
|
-
|
|
40
|
+
createPullRequest: CreatePullRequest;
|
|
41
|
+
mergePullRequest: MergePullRequest;
|
|
40
42
|
};
|
|
41
43
|
|
|
42
44
|
export type GithubSdk = (args: GithubSdkArgs) => GithubSdkInstance;
|
|
@@ -57,7 +59,7 @@ export const githubSdk: GithubSdk = (args) => {
|
|
|
57
59
|
const createGitCommit = createGitCommitFactory(instance);
|
|
58
60
|
const createGitTree = createGitTreeFactory(instance);
|
|
59
61
|
const getShaLastCommitOfBranch = getShaLastCommitOfBranchFactory(instance);
|
|
60
|
-
const
|
|
62
|
+
const getTreeShaFromCommit = getTreeShaFromCommitFactory(instance);
|
|
61
63
|
|
|
62
64
|
const getFileContent = getFileContentFactory(instance);
|
|
63
65
|
|
|
@@ -66,24 +68,26 @@ export const githubSdk: GithubSdk = (args) => {
|
|
|
66
68
|
createGitCommit,
|
|
67
69
|
createGitTree,
|
|
68
70
|
getShaLastCommitOfBranch,
|
|
69
|
-
|
|
71
|
+
getTreeShaFromCommit,
|
|
70
72
|
});
|
|
71
73
|
|
|
72
74
|
const createBranch = createBranchFactory(instance);
|
|
73
75
|
const updateBranch = updateBranchFactory(instance);
|
|
74
76
|
|
|
75
|
-
const
|
|
77
|
+
const createPullRequest = createPullRequestFactory(instance);
|
|
78
|
+
const mergePullRequest = mergePullRequestFactory(instance);
|
|
76
79
|
|
|
77
80
|
return {
|
|
78
81
|
createGitBlob,
|
|
79
82
|
createGitCommit,
|
|
80
83
|
createGitTree,
|
|
81
84
|
getShaLastCommitOfBranch,
|
|
82
|
-
|
|
85
|
+
getTreeShaFromCommit,
|
|
83
86
|
runNewCommitProcess,
|
|
84
87
|
getFileContent,
|
|
85
88
|
createBranch,
|
|
86
89
|
updateBranch,
|
|
87
|
-
|
|
90
|
+
createPullRequest,
|
|
91
|
+
mergePullRequest,
|
|
88
92
|
};
|
|
89
93
|
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { AxiosInstance } from 'axios';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { handleError } from '../commit/utils';
|
|
5
|
+
|
|
6
|
+
export type CreatePullRequestArgs = {
|
|
7
|
+
title: string;
|
|
8
|
+
body: string;
|
|
9
|
+
head: string;
|
|
10
|
+
base: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type CreatePullRequestResponse = {
|
|
14
|
+
url: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const createPullRequestResponseSchema = z.object({
|
|
18
|
+
url: z.string(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export type CreatePullRequest = (args: CreatePullRequestArgs) => Promise<CreatePullRequestResponse>;
|
|
22
|
+
|
|
23
|
+
export type CreatePullRequestFactory = (instance: AxiosInstance) => CreatePullRequest;
|
|
24
|
+
|
|
25
|
+
export const createPullRequestFactory: CreatePullRequestFactory = (instance) => async (args) => {
|
|
26
|
+
const { title, body, head, base } = args;
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const { data } = await instance.post<CreatePullRequestResponse>('/pulls', {
|
|
30
|
+
title,
|
|
31
|
+
body,
|
|
32
|
+
head,
|
|
33
|
+
base,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return createPullRequestResponseSchema.parse(data);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw handleError(error);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './create-
|
|
1
|
+
export * from './create-pull-request';
|
|
2
|
+
export * from './merge-pull-request';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { handleError } from '../commit/utils';
|
|
5
|
+
|
|
6
|
+
export type MergePullRequestArgs = {
|
|
7
|
+
pullRequestNumber: number;
|
|
8
|
+
commitTitle: string;
|
|
9
|
+
commitMessage: string;
|
|
10
|
+
mergeMethod: 'merge' | 'squash' | 'rebase';
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type MergePullRequestResponse = {
|
|
14
|
+
sha: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const mergePullRequestResponseSchema = z.object({
|
|
18
|
+
sha: z.string(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export type MergePullRequest = (args: MergePullRequestArgs) => Promise<MergePullRequestResponse>;
|
|
22
|
+
|
|
23
|
+
export type MergePullRequestFactory = (instance: AxiosInstance) => MergePullRequest;
|
|
24
|
+
|
|
25
|
+
export const mergePullRequestFactory: MergePullRequestFactory = (instance) => async (args) => {
|
|
26
|
+
const { pullRequestNumber, commitTitle, commitMessage, mergeMethod } = args;
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const { data } = await instance.put<MergePullRequestResponse>(`/pulls/${pullRequestNumber}/merge`, {
|
|
30
|
+
commit_title: commitTitle,
|
|
31
|
+
commit_message: commitMessage,
|
|
32
|
+
merge_method: mergeMethod,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return mergePullRequestResponseSchema.parse(data);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
throw handleError(error);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { AxiosInstance } from 'axios';
|
|
2
|
-
export declare type CreateMergeRequestArgs = {
|
|
3
|
-
title: string;
|
|
4
|
-
body: string;
|
|
5
|
-
head: string;
|
|
6
|
-
base: string;
|
|
7
|
-
};
|
|
8
|
-
export declare type CreateMergeRequestResponse = {
|
|
9
|
-
url: string;
|
|
10
|
-
};
|
|
11
|
-
export declare type CreateMergeRequest = (args: CreateMergeRequestArgs) => Promise<CreateMergeRequestResponse>;
|
|
12
|
-
export declare type CreateMergeRequestFactory = (instance: AxiosInstance) => CreateMergeRequest;
|
|
13
|
-
export declare const createMergeRequestFactory: CreateMergeRequestFactory;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-merge-request.js","sources":["../../../src/github/merge/create-merge-request.ts"],"sourcesContent":["import type { AxiosInstance } from 'axios';\nimport { z } from 'zod';\n\nimport { handleError } from '../commit/utils';\n\nexport type CreateMergeRequestArgs = {\n title: string;\n body: string;\n head: string;\n base: string;\n};\n\nexport type CreateMergeRequestResponse = {\n url: string;\n};\n\nconst createMergeRequestResponseSchema = z.object({\n url: z.string(),\n});\n\nexport type CreateMergeRequest = (args: CreateMergeRequestArgs) => Promise<CreateMergeRequestResponse>;\n\nexport type CreateMergeRequestFactory = (instance: AxiosInstance) => CreateMergeRequest;\n\nexport const createMergeRequestFactory: CreateMergeRequestFactory = (instance) => async (args) => {\n const { title, body, head, base } = args;\n\n try {\n const { data } = await instance.post<CreateMergeRequestResponse>('/pulls', {\n title,\n body,\n head,\n base,\n });\n\n return createMergeRequestResponseSchema.parse(data);\n } catch (error) {\n throw handleError(error);\n }\n};\n"],"names":["z","__awaiter","handleError"],"mappings":";;;;;;;;AAgBA,MAAM,gCAAgC,GAAGA,KAAC,CAAC,MAAM,CAAC;AAChD,IAAA,GAAG,EAAEA,KAAC,CAAC,MAAM,EAAE;AAChB,CAAA,CAAC,CAAC;AAMI,MAAM,yBAAyB,GAA8B,CAAC,QAAQ,KAAK,CAAO,IAAI,KAAIC,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;IAC/F,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IAEzC,IAAI;QACF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,CAA6B,QAAQ,EAAE;YACzE,KAAK;YACL,IAAI;YACJ,IAAI;YACJ,IAAI;AACL,SAAA,CAAC,CAAC;AAEH,QAAA,OAAO,gCAAgC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACrD,KAAA;AAAC,IAAA,OAAO,KAAK,EAAE;AACd,QAAA,MAAMC,iBAAW,CAAC,KAAK,CAAC,CAAC;AAC1B,KAAA;AACH,CAAC;;;;"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { AxiosInstance } from 'axios';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
import { handleError } from '../commit/utils';
|
|
5
|
-
|
|
6
|
-
export type CreateMergeRequestArgs = {
|
|
7
|
-
title: string;
|
|
8
|
-
body: string;
|
|
9
|
-
head: string;
|
|
10
|
-
base: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type CreateMergeRequestResponse = {
|
|
14
|
-
url: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const createMergeRequestResponseSchema = z.object({
|
|
18
|
-
url: z.string(),
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
export type CreateMergeRequest = (args: CreateMergeRequestArgs) => Promise<CreateMergeRequestResponse>;
|
|
22
|
-
|
|
23
|
-
export type CreateMergeRequestFactory = (instance: AxiosInstance) => CreateMergeRequest;
|
|
24
|
-
|
|
25
|
-
export const createMergeRequestFactory: CreateMergeRequestFactory = (instance) => async (args) => {
|
|
26
|
-
const { title, body, head, base } = args;
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
const { data } = await instance.post<CreateMergeRequestResponse>('/pulls', {
|
|
30
|
-
title,
|
|
31
|
-
body,
|
|
32
|
-
head,
|
|
33
|
-
base,
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
return createMergeRequestResponseSchema.parse(data);
|
|
37
|
-
} catch (error) {
|
|
38
|
-
throw handleError(error);
|
|
39
|
-
}
|
|
40
|
-
};
|