@commitspark/git-adapter-github 0.20.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +39 -0
- package/dist/cjs/errors.js +58 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/github-adapter.js +86 -71
- package/dist/cjs/github-adapter.js.map +1 -1
- package/dist/cjs/github-api/get-entry-content.js +53 -0
- package/dist/cjs/github-api/get-entry-content.js.map +1 -0
- package/dist/cjs/github-api/get-file-paths.js +48 -0
- package/dist/cjs/github-api/get-file-paths.js.map +1 -0
- package/dist/cjs/{util → github-api}/graphql-query-factory.js +32 -23
- package/dist/cjs/github-api/graphql-query-factory.js.map +1 -0
- package/dist/cjs/types.js +10 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/util/entries-to-actions-converter.js +1 -1
- package/dist/cjs/util/entries-to-actions-converter.js.map +1 -1
- package/dist/cjs/util/entry-factory.js +10 -9
- package/dist/cjs/util/entry-factory.js.map +1 -1
- package/dist/cjs/util/path-factory.js +3 -3
- package/dist/cjs/util/path-factory.js.map +1 -1
- package/dist/esm/errors.js +51 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/github-adapter.js +86 -70
- package/dist/esm/github-adapter.js.map +1 -1
- package/dist/esm/github-api/get-entry-content.js +40 -0
- package/dist/esm/github-api/get-entry-content.js.map +1 -0
- package/dist/esm/github-api/get-file-paths.js +35 -0
- package/dist/esm/github-api/get-file-paths.js.map +1 -0
- package/dist/esm/{util → github-api}/graphql-query-factory.js +30 -21
- package/dist/esm/github-api/graphql-query-factory.js.map +1 -0
- package/dist/esm/types.js +7 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/util/entries-to-actions-converter.js +1 -1
- package/dist/esm/util/entries-to-actions-converter.js.map +1 -1
- package/dist/esm/util/entry-factory.js +9 -8
- package/dist/esm/util/entry-factory.js.map +1 -1
- package/dist/esm/util/path-factory.js +3 -3
- package/dist/esm/util/path-factory.js.map +1 -1
- package/dist/tsconfig.build.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.build.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.build.types.tsbuildinfo +1 -1
- package/dist/types/errors.d.ts +4 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/github-adapter.d.ts +0 -1
- package/dist/types/github-adapter.d.ts.map +1 -1
- package/dist/types/github-api/get-entry-content.d.ts +4 -0
- package/dist/types/github-api/get-entry-content.d.ts.map +1 -0
- package/dist/types/github-api/get-file-paths.d.ts +4 -0
- package/dist/types/github-api/get-file-paths.d.ts.map +1 -0
- package/dist/types/github-api/graphql-query-factory.d.ts +8 -0
- package/dist/types/github-api/graphql-query-factory.d.ts.map +1 -0
- package/dist/types/types.d.ts +7 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/util/entry-factory.d.ts +2 -9
- package/dist/types/util/entry-factory.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/errors.ts +54 -0
- package/src/github-adapter.ts +128 -86
- package/src/github-api/get-entry-content.ts +76 -0
- package/src/github-api/get-file-paths.ts +66 -0
- package/src/{util → github-api}/graphql-query-factory.ts +42 -21
- package/src/types.ts +6 -0
- package/src/util/entries-to-actions-converter.ts +1 -1
- package/src/util/entry-factory.ts +13 -22
- package/src/util/path-factory.ts +3 -3
- package/dist/cjs/util/graphql-query-factory.js.map +0 -1
- package/dist/cjs/util/types.js +0 -7
- package/dist/cjs/util/types.js.map +0 -1
- package/dist/esm/util/graphql-query-factory.js.map +0 -1
- package/dist/esm/util/types.js +0 -4
- package/dist/esm/util/types.js.map +0 -1
- package/dist/types/util/graphql-query-factory.d.ts +0 -5
- package/dist/types/util/graphql-query-factory.d.ts.map +0 -1
- package/dist/types/util/types.d.ts +0 -4
- package/dist/types/util/types.d.ts.map +0 -1
- package/src/util/types.ts +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.30.0] - 2025-11-28
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Support loading thousands of entries
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- Increase request timeout to avoid artificially aborting requests
|
|
17
|
+
- Upgrade dependencies
|
|
18
|
+
|
|
19
|
+
## [0.21.0] - 2025-11-11
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- Add error handling and abstraction for GitHub API responses
|
|
24
|
+
|
|
8
25
|
## [0.20.0] - 2025-11-08
|
|
9
26
|
|
|
10
27
|
### Changed
|
package/README.md
CHANGED
|
@@ -58,6 +58,45 @@ Access tokens for a user obtained
|
|
|
58
58
|
from an [OAuth app](https://docs.github.com/en/apps/oauth-apps/using-oauth-apps/authorizing-oauth-apps) can be used in
|
|
59
59
|
the same way (including permissions) as fine-grained personal access tokens.
|
|
60
60
|
|
|
61
|
+
## Error Handling
|
|
62
|
+
|
|
63
|
+
This adapter sends requests to the GitHub GraphQL API. In case a request fails, HTTP and GraphQL errors are mapped to
|
|
64
|
+
`GitAdapterError` exceptions with `ErrorCode` values from the `@commitspark/git-adapter` package. This enables the
|
|
65
|
+
[Commitspark GraphQL API library](https://github.com/commitspark/graphql-api) to handle adapter errors in an
|
|
66
|
+
adapter-agnostic way.
|
|
67
|
+
|
|
68
|
+
### HTTP Status Code Mapping
|
|
69
|
+
|
|
70
|
+
HTTP error status codes are mapped as follows:
|
|
71
|
+
|
|
72
|
+
| HTTP Status | GitAdapter ErrorCode |
|
|
73
|
+
|-------------|----------------------|
|
|
74
|
+
| 400 | `BAD_REQUEST` |
|
|
75
|
+
| 401 | `UNAUTHORIZED` |
|
|
76
|
+
| 403 | `FORBIDDEN` |
|
|
77
|
+
| 404 | `NOT_FOUND` |
|
|
78
|
+
| 409 | `CONFLICT` |
|
|
79
|
+
| 429 | `TOO_MANY_REQUESTS` |
|
|
80
|
+
| Other | `INTERNAL_ERROR` |
|
|
81
|
+
|
|
82
|
+
### GitHub GraphQL API Error Type Mapping
|
|
83
|
+
|
|
84
|
+
GitHub GraphQL API error types are mapped as follows:
|
|
85
|
+
|
|
86
|
+
| GitHub Error Type | GitAdapter ErrorCode |
|
|
87
|
+
|-------------------|----------------------|
|
|
88
|
+
| `NOT_FOUND` | `NOT_FOUND` |
|
|
89
|
+
| `RATE_LIMITED` | `TOO_MANY_REQUESTS` |
|
|
90
|
+
| `FORBIDDEN` | `FORBIDDEN` |
|
|
91
|
+
| `STALE_DATA` | `CONFLICT` |
|
|
92
|
+
| Other | `INTERNAL_ERROR` |
|
|
93
|
+
|
|
94
|
+
All errors include the original error message from GitHub for debugging purposes.
|
|
95
|
+
|
|
96
|
+
As GitHub GraphQL error types (codes) are not documented (see
|
|
97
|
+
[GitHub documentation issue #22607](https://github.com/github/docs/issues/22607)), mapping of GraphQL error types is
|
|
98
|
+
done on a best-effort basis.
|
|
99
|
+
|
|
61
100
|
# Example
|
|
62
101
|
|
|
63
102
|
To use this adapter together with the Commitspark GraphQL API library, your code could be the following:
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleGraphQLErrors = exports.handleHttpErrors = void 0;
|
|
4
|
+
const git_adapter_1 = require("@commitspark/git-adapter");
|
|
5
|
+
const axios_1 = require("axios");
|
|
6
|
+
const handleHttpErrors = (error) => {
|
|
7
|
+
var _a, _b, _c;
|
|
8
|
+
if (error instanceof axios_1.AxiosError) {
|
|
9
|
+
const status = (_a = error.response) === null || _a === void 0 ? void 0 : _a.status;
|
|
10
|
+
const message = ((_c = (_b = error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || error.message;
|
|
11
|
+
switch (status) {
|
|
12
|
+
case 400:
|
|
13
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.BAD_REQUEST, message);
|
|
14
|
+
case 401:
|
|
15
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.UNAUTHORIZED, message);
|
|
16
|
+
case 403:
|
|
17
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.FORBIDDEN, message);
|
|
18
|
+
case 404:
|
|
19
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.NOT_FOUND, message);
|
|
20
|
+
case 409:
|
|
21
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.CONFLICT, message);
|
|
22
|
+
case 429:
|
|
23
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.TOO_MANY_REQUESTS, message);
|
|
24
|
+
default:
|
|
25
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.INTERNAL_ERROR, message);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.INTERNAL_ERROR, error instanceof Error ? error.message : 'Unknown error');
|
|
29
|
+
};
|
|
30
|
+
exports.handleHttpErrors = handleHttpErrors;
|
|
31
|
+
const handleGraphQLErrors = (response) => {
|
|
32
|
+
var _a;
|
|
33
|
+
if (response.data.errors) {
|
|
34
|
+
const errors = response.data.errors;
|
|
35
|
+
const errorMessage = JSON.stringify(errors);
|
|
36
|
+
const errorType = (_a = errors[0]) === null || _a === void 0 ? void 0 : _a.type;
|
|
37
|
+
// GitHub error types are not documented, and documentation is not planned,
|
|
38
|
+
// see https://github.com/github/docs/issues/22607
|
|
39
|
+
// Error type values below have been discovered through manual testing
|
|
40
|
+
if (errorType === 'NOT_FOUND') {
|
|
41
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.NOT_FOUND, errorMessage);
|
|
42
|
+
}
|
|
43
|
+
else if (errorType === 'RATE_LIMITED') {
|
|
44
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.TOO_MANY_REQUESTS, errorMessage);
|
|
45
|
+
}
|
|
46
|
+
else if (errorType === 'FORBIDDEN') {
|
|
47
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.FORBIDDEN, errorMessage);
|
|
48
|
+
}
|
|
49
|
+
else if (errorType === 'STALE_DATA') {
|
|
50
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.CONFLICT, errorMessage);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.INTERNAL_ERROR, errorMessage);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
exports.handleGraphQLErrors = handleGraphQLErrors;
|
|
58
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,0DAAqE;AACrE,iCAAiD;AAE1C,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAS,EAAE;;IACxD,IAAI,KAAK,YAAY,kBAAU,EAAE,CAAC;QAChC,MAAM,MAAM,GAAG,MAAA,KAAK,CAAC,QAAQ,0CAAE,MAAM,CAAA;QACrC,MAAM,OAAO,GAAG,CAAA,MAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,IAAI,0CAAE,OAAO,KAAI,KAAK,CAAC,OAAO,CAAA;QAE9D,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,GAAG;gBACN,MAAM,IAAI,6BAAe,CAAC,uBAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;YAC3D,KAAK,GAAG;gBACN,MAAM,IAAI,6BAAe,CAAC,uBAAS,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;YAC5D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AS,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAA;QACtE,CAAC;aAAM,IAAI,SAAS,KAAK,WAAW,EAAE,CAAC;YACrC,MAAM,IAAI,6BAAe,CAAC,uBAAS,CAAC,SAAS,EAAE,YAAY,CAAC,CAAA;QAC9D,CAAC;aAAM,IAAI,SAAS,KAAK,YAAY,EAAE,CAAC;YACtC,MAAM,IAAI,6BAAe,CAAC,uBAAS,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;QAC7D,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,6BAAe,CAAC,uBAAS,CAAC,cAAc,EAAE,YAAY,CAAC,CAAA;QACnE,CAAC;IACH,CAAC;AACH,CAAC,CAAA;AArBY,QAAA,mBAAmB,uBAqB/B"}
|
|
@@ -9,33 +9,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.createCommit = exports.getLatestCommitHash = exports.getSchema = exports.getEntries =
|
|
13
|
-
const
|
|
12
|
+
exports.createCommit = exports.getLatestCommitHash = exports.getSchema = exports.getEntries = void 0;
|
|
13
|
+
const git_adapter_1 = require("@commitspark/git-adapter");
|
|
14
|
+
const graphql_query_factory_1 = require("./github-api/graphql-query-factory");
|
|
14
15
|
const entries_to_actions_converter_1 = require("./util/entries-to-actions-converter");
|
|
15
16
|
const path_factory_1 = require("./util/path-factory");
|
|
16
17
|
const entry_factory_1 = require("./util/entry-factory");
|
|
17
|
-
|
|
18
|
+
const errors_1 = require("./errors");
|
|
19
|
+
const get_entry_content_1 = require("./github-api/get-entry-content");
|
|
20
|
+
const get_file_paths_1 = require("./github-api/get-file-paths");
|
|
21
|
+
const types_1 = require("./types");
|
|
18
22
|
const getEntries = (gitRepositoryOptions, axiosCacheInstance, commitHash) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const queryFilesContent = (0, graphql_query_factory_1.createBlobsContentQuery)();
|
|
23
|
-
const filesContentResponse = yield axiosCacheInstance.post(exports.API_URL, {
|
|
24
|
-
query: queryFilesContent,
|
|
25
|
-
variables: {
|
|
26
|
-
repositoryOwner: gitRepositoryOptions.repositoryOwner,
|
|
27
|
-
repositoryName: gitRepositoryOptions.repositoryName,
|
|
28
|
-
expression: `${commitHash}:${pathEntryFolder}`,
|
|
29
|
-
},
|
|
30
|
-
}, {
|
|
31
|
-
headers: {
|
|
32
|
-
authorization: `Bearer ${token}`,
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
if (!((_b = (_a = filesContentResponse.data.data.repository) === null || _a === void 0 ? void 0 : _a.object) === null || _b === void 0 ? void 0 : _b.entries)) {
|
|
36
|
-
return [];
|
|
37
|
-
}
|
|
38
|
-
return (0, entry_factory_1.createEntriesFromBlobsQueryResponseData)(filesContentResponse.data.data.repository.object.entries);
|
|
23
|
+
const filenames = yield (0, get_file_paths_1.getFilePaths)(gitRepositoryOptions, axiosCacheInstance, commitHash);
|
|
24
|
+
const filePathsContentMap = yield (0, get_entry_content_1.getEntryContent)(gitRepositoryOptions, axiosCacheInstance, commitHash, filenames);
|
|
25
|
+
return (0, entry_factory_1.createEntriesFromFileContent)(gitRepositoryOptions, filePathsContentMap);
|
|
39
26
|
});
|
|
40
27
|
exports.getEntries = getEntries;
|
|
41
28
|
const getSchema = (gitRepositoryOptions, axiosCacheInstance, commitHash) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -44,22 +31,32 @@ const getSchema = (gitRepositoryOptions, axiosCacheInstance, commitHash) => __aw
|
|
|
44
31
|
const repositoryName = gitRepositoryOptions.repositoryName;
|
|
45
32
|
const token = gitRepositoryOptions.accessToken;
|
|
46
33
|
const schemaFilePath = (0, path_factory_1.getPathSchema)(gitRepositoryOptions);
|
|
47
|
-
const queryContent = (0, graphql_query_factory_1.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
34
|
+
const queryContent = (0, graphql_query_factory_1.createSingleBlobContentQuery)();
|
|
35
|
+
let response;
|
|
36
|
+
try {
|
|
37
|
+
response = yield axiosCacheInstance.post(types_1.GITHUB_GRAPHQL_API_URL, {
|
|
38
|
+
query: queryContent,
|
|
39
|
+
variables: {
|
|
40
|
+
repositoryOwner: repositoryOwner,
|
|
41
|
+
repositoryName: repositoryName,
|
|
42
|
+
expression: `${commitHash}:${schemaFilePath}`,
|
|
43
|
+
},
|
|
44
|
+
}, {
|
|
45
|
+
headers: {
|
|
46
|
+
authorization: `Bearer ${token}`,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
(0, errors_1.handleHttpErrors)(error);
|
|
52
|
+
}
|
|
53
|
+
if (!response) {
|
|
54
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.INTERNAL_ERROR, `Failed to fetch schema`);
|
|
55
|
+
}
|
|
56
|
+
(0, errors_1.handleGraphQLErrors)(response);
|
|
60
57
|
const schema = (_d = (_c = (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.repository) === null || _c === void 0 ? void 0 : _c.object) === null || _d === void 0 ? void 0 : _d.text;
|
|
61
58
|
if (!schema) {
|
|
62
|
-
throw new
|
|
59
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.NOT_FOUND, `"${schemaFilePath}" not found in Git repository "${repositoryOwner}/${repositoryName}" at commit "${commitHash}"`);
|
|
63
60
|
}
|
|
64
61
|
return schema;
|
|
65
62
|
});
|
|
@@ -68,25 +65,35 @@ const getLatestCommitHash = (gitRepositoryOptions, axiosCacheInstance, ref) => _
|
|
|
68
65
|
var _a, _b, _c, _d, _e;
|
|
69
66
|
const token = gitRepositoryOptions.accessToken;
|
|
70
67
|
const queryLatestCommit = (0, graphql_query_factory_1.createLatestCommitQuery)();
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
68
|
+
let response;
|
|
69
|
+
try {
|
|
70
|
+
response = yield axiosCacheInstance.post(types_1.GITHUB_GRAPHQL_API_URL, {
|
|
71
|
+
query: queryLatestCommit,
|
|
72
|
+
variables: {
|
|
73
|
+
repositoryOwner: gitRepositoryOptions.repositoryOwner,
|
|
74
|
+
repositoryName: gitRepositoryOptions.repositoryName,
|
|
75
|
+
ref: ref,
|
|
76
|
+
},
|
|
77
|
+
}, {
|
|
78
|
+
cache: false, // must not use cache, so we always get the branch's current head
|
|
79
|
+
headers: {
|
|
80
|
+
authorization: `Bearer ${token}`,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
(0, errors_1.handleHttpErrors)(error);
|
|
86
|
+
}
|
|
87
|
+
if (!response) {
|
|
88
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.INTERNAL_ERROR, 'Failed to fetch latest commit');
|
|
89
|
+
}
|
|
90
|
+
(0, errors_1.handleGraphQLErrors)(response);
|
|
84
91
|
if (!response.data.data.repository) {
|
|
85
|
-
throw new
|
|
92
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.NOT_FOUND, `No repository found "${gitRepositoryOptions.repositoryOwner}/${gitRepositoryOptions.repositoryName}"`);
|
|
86
93
|
}
|
|
87
94
|
const lastCommit = (_e = (_c = (_b = (_a = response.data.data.repository.ref) === null || _a === void 0 ? void 0 : _a.target) === null || _b === void 0 ? void 0 : _b.oid) !== null && _c !== void 0 ? _c : (_d = response.data.data.repository.object) === null || _d === void 0 ? void 0 : _d.oid) !== null && _e !== void 0 ? _e : undefined;
|
|
88
95
|
if (!lastCommit) {
|
|
89
|
-
throw new
|
|
96
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.NOT_FOUND, `No commit found for ref "${ref}"`);
|
|
90
97
|
}
|
|
91
98
|
return lastCommit;
|
|
92
99
|
});
|
|
@@ -97,28 +104,36 @@ const createCommit = (gitRepositoryOptions, axiosCacheInstance, commitDraft) =>
|
|
|
97
104
|
const pathEntryFolder = (0, path_factory_1.getPathEntryFolder)(gitRepositoryOptions);
|
|
98
105
|
const { additions, deletions } = (0, entries_to_actions_converter_1.convertEntriesToActions)(commitDraft.entries, pathEntryFolder);
|
|
99
106
|
const mutateCommit = (0, graphql_query_factory_1.createCommitMutation)();
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
107
|
+
let response;
|
|
108
|
+
try {
|
|
109
|
+
response = yield axiosCacheInstance.post(types_1.GITHUB_GRAPHQL_API_URL, {
|
|
110
|
+
query: mutateCommit,
|
|
111
|
+
variables: {
|
|
112
|
+
repositoryNameWithOwner: `${gitRepositoryOptions.repositoryOwner}/${gitRepositoryOptions.repositoryName}`,
|
|
113
|
+
branchName: commitDraft.ref,
|
|
114
|
+
commitMessage: (_a = commitDraft.message) !== null && _a !== void 0 ? _a : '-',
|
|
115
|
+
precedingCommitSha: commitDraft.parentSha,
|
|
116
|
+
additions: additions,
|
|
117
|
+
deletions: deletions,
|
|
118
|
+
},
|
|
119
|
+
}, {
|
|
120
|
+
cache: false,
|
|
121
|
+
headers: {
|
|
122
|
+
authorization: `Bearer ${token}`,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
(0, errors_1.handleHttpErrors)(error);
|
|
128
|
+
}
|
|
129
|
+
if (!response) {
|
|
130
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.INTERNAL_ERROR, `Failed to create commit`);
|
|
118
131
|
}
|
|
132
|
+
(0, errors_1.handleGraphQLErrors)(response);
|
|
119
133
|
const mutationResult = response.data.data.commitCreate;
|
|
120
134
|
if (mutationResult.errors) {
|
|
121
|
-
|
|
135
|
+
const errorMessage = JSON.stringify(mutationResult.errors);
|
|
136
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.BAD_REQUEST, `Failed to create commit: ${errorMessage}`);
|
|
122
137
|
}
|
|
123
138
|
return { ref: mutationResult.commit.oid };
|
|
124
139
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github-adapter.js","sourceRoot":"","sources":["../../src/github-adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"github-adapter.js","sourceRoot":"","sources":["../../src/github-adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,0DAMiC;AAEjC,8EAI2C;AAC3C,sFAA6E;AAC7E,sDAAuE;AACvE,wDAAmE;AACnE,qCAAgE;AAChE,sEAAgE;AAChE,gEAA0D;AAC1D,mCAAgD;AAEzC,MAAM,UAAU,GAAG,CACxB,oBAA6C,EAC7C,kBAAsC,EACtC,UAAkB,EACA,EAAE;IACpB,MAAM,SAAS,GAAa,MAAM,IAAA,6BAAY,EAC5C,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,CACX,CAAA;IAED,MAAM,mBAAmB,GAAG,MAAM,IAAA,mCAAe,EAC/C,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,SAAS,CACV,CAAA;IAED,OAAO,IAAA,4CAA4B,EAAC,oBAAoB,EAAE,mBAAmB,CAAC,CAAA;AAChF,CAAC,CAAA,CAAA;AAnBY,QAAA,UAAU,cAmBtB;AAEM,M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CACF,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAA,yBAAgB,EAAC,KAAK,CAAC,CAAA;IACzB,CAAC;IAED,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,6BAAe,CACvB,uBAAS,CAAC,cAAc,EACxB,yBAAyB,CAC1B,CAAA;IACH,CAAC;IAED,IAAA,4BAAmB,EAAC,QAAQ,CAAC,CAAA;IAE7B,MAAM,cAAc,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAA;IAEtD,IAAI,cAAc,CAAC,MAAM,EAAE,CAAC;QAC1B,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;QAC1D,MAAM,IAAI,6BAAe,CACvB,uBAAS,CAAC,WAAW,EACrB,4BAA4B,YAAY,EAAE,CAC3C,CAAA;IACH,CAAC;IAED,OAAO,EAAE,GAAG,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,EAAE,CAAA;AAC3C,CAAC,CAAA,CAAA;AA7DY,QAAA,YAAY,gBA6DxB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getEntryContent = void 0;
|
|
13
|
+
const graphql_query_factory_1 = require("./graphql-query-factory");
|
|
14
|
+
const types_1 = require("../types");
|
|
15
|
+
const errors_1 = require("../errors");
|
|
16
|
+
const getEntryContent = (gitRepositoryOptions, axiosCacheInstance, commitHash, filePaths) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const filePathsContentMap = new Map();
|
|
18
|
+
const { queries, queryFilenameAliasMap } = (0, graphql_query_factory_1.createBlobsContentByFilePathsQuery)(filePaths, commitHash, types_1.QUERY_BATCH_SIZE);
|
|
19
|
+
const requestPromises = [];
|
|
20
|
+
for (const contentQuery of queries) {
|
|
21
|
+
try {
|
|
22
|
+
requestPromises.push(axiosCacheInstance
|
|
23
|
+
.post(types_1.GITHUB_GRAPHQL_API_URL, {
|
|
24
|
+
query: contentQuery,
|
|
25
|
+
variables: {
|
|
26
|
+
repositoryOwner: gitRepositoryOptions.repositoryOwner,
|
|
27
|
+
repositoryName: gitRepositoryOptions.repositoryName,
|
|
28
|
+
},
|
|
29
|
+
}, {
|
|
30
|
+
headers: {
|
|
31
|
+
authorization: `Bearer ${gitRepositoryOptions.accessToken}`,
|
|
32
|
+
},
|
|
33
|
+
timeout: 30000,
|
|
34
|
+
})
|
|
35
|
+
.then((contentResponse) => processContentResponse(filePathsContentMap, queryFilenameAliasMap, contentResponse)));
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
(0, errors_1.handleHttpErrors)(error);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
yield Promise.all(requestPromises);
|
|
42
|
+
return filePathsContentMap;
|
|
43
|
+
});
|
|
44
|
+
exports.getEntryContent = getEntryContent;
|
|
45
|
+
const processContentResponse = (filePathsContentMap, queryFilenameAliasMap, contentResponse) => {
|
|
46
|
+
(0, errors_1.handleGraphQLErrors)(contentResponse);
|
|
47
|
+
const filesResponseData = contentResponse.data.data.repository;
|
|
48
|
+
for (const [queryAlias, fileObject] of Object.entries(filesResponseData)) {
|
|
49
|
+
filePathsContentMap.set(queryFilenameAliasMap.get(queryAlias), // we assume we received only those files we know about
|
|
50
|
+
fileObject.text);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=get-entry-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-entry-content.js","sourceRoot":"","sources":["../../../src/github-api/get-entry-content.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,mEAA4E;AAC5E,oCAAmE;AACnE,sCAAiE;AAE1D,MAAM,eAAe,GAAG,CAC7B,oBAA6C,EAC7C,kBAAsC,EACtC,UAAkB,EAClB,SAAmB,EACW,EAAE;IAChC,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAkB,CAAA;IAErD,MAAM,EAAE,OAAO,EAAE,qBAAqB,EAAE,GAAG,IAAA,0DAAkC,EAC3E,SAAS,EACT,UAAU,EACV,wBAAgB,CACjB,CAAA;IAED,MAAM,eAAe,GAAG,EAAE,CAAA;IAC1B,KAAK,MAAM,YAAY,IAAI,OAAO,EAAE,CAAC;QACnC,IAAI,CAAC;YACH,eAAe,CAAC,IAAI,CAClB,kBAAkB;iBACf,IAAI,CACH,8BAAsB,EACtB;gBACE,KAAK,EAAE,YAAY;gBACnB,SAAS,EAAE;oBACT,eAAe,EAAE,oBAAoB,CAAC,eAAe;oBACrD,cAAc,EAAE,oBAAoB,CAAC,cAAc;iBACpD;aACF,EACD;gBACE,OAAO,EAAE;oBACP,aAAa,EAAE,UAAU,oBAAoB,CAAC,WAAW,EAAE;iBAC5D;gBACD,OAAO,EAAE,KAAK;aACf,CACF;iBACA,IAAI,CAAC,CAAC,eAAe,EAAE,EAAE,CACxB,sBAAsB,CACpB,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,CAChB,CACF,CACJ,CAAA;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAA,yBAAgB,EAAC,KAAK,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;IACD,MAAM,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;IAElC,OAAO,mBAAmB,CAAA;AAC5B,CAAC,CAAA,CAAA;AAlDY,QAAA,eAAe,mBAkD3B;AAED,MAAM,sBAAsB,GAAG,CAC7B,mBAAwC,EACxC,qBAA0C,EAC1C,eAAmC,EAC7B,EAAE;IACR,IAAA,4BAAmB,EAAC,eAAe,CAAC,CAAA;IACpC,MAAM,iBAAiB,GAAG,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,UAGnD,CAAA;IAED,KAAK,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;QACzE,mBAAmB,CAAC,GAAG,CACrB,qBAAqB,CAAC,GAAG,CAAC,UAAU,CAAW,EAAE,uDAAuD;QACxG,UAAU,CAAC,IAAI,CAChB,CAAA;IACH,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getFilePaths = void 0;
|
|
13
|
+
const git_adapter_1 = require("@commitspark/git-adapter");
|
|
14
|
+
const path_factory_1 = require("../util/path-factory");
|
|
15
|
+
const errors_1 = require("../errors");
|
|
16
|
+
const types_1 = require("../types");
|
|
17
|
+
const getFilePaths = (gitRepositoryOptions, axiosCacheInstance, treeSha) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const pathEntryFolder = (0, path_factory_1.getPathEntryFolder)(gitRepositoryOptions);
|
|
19
|
+
const { repositoryOwner, repositoryName, accessToken } = gitRepositoryOptions;
|
|
20
|
+
// hard limit of 100,000 entries and 7MB response size; see https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28#get-a-tree
|
|
21
|
+
const restApiUrl = types_1.GITHUB_REST_API_URL +
|
|
22
|
+
`/repos/${repositoryOwner}/${repositoryName}/git/trees/${treeSha}?recursive=1`;
|
|
23
|
+
let response;
|
|
24
|
+
try {
|
|
25
|
+
response = yield axiosCacheInstance.get(restApiUrl, {
|
|
26
|
+
headers: {
|
|
27
|
+
Authorization: `Bearer ${accessToken}`,
|
|
28
|
+
Accept: 'application/vnd.github+json',
|
|
29
|
+
},
|
|
30
|
+
timeout: 30000,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
(0, errors_1.handleHttpErrors)(error);
|
|
35
|
+
}
|
|
36
|
+
if (response === undefined) {
|
|
37
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.INTERNAL_ERROR, 'Failed to fetch repository file list.');
|
|
38
|
+
}
|
|
39
|
+
const data = response.data;
|
|
40
|
+
if (data.truncated) {
|
|
41
|
+
throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.INTERNAL_ERROR, `Too many files in repository.`);
|
|
42
|
+
}
|
|
43
|
+
return data.tree
|
|
44
|
+
.filter((entry) => entry.type === 'blob' && entry.path.startsWith(pathEntryFolder))
|
|
45
|
+
.map((entry) => entry.path);
|
|
46
|
+
});
|
|
47
|
+
exports.getFilePaths = getFilePaths;
|
|
48
|
+
//# sourceMappingURL=get-file-paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-file-paths.js","sourceRoot":"","sources":["../../../src/github-api/get-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G,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC,CAAA,CAAA;AAhDY,QAAA,YAAY,gBAgDxB"}
|
|
@@ -1,42 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.createSingleBlobContentQuery = createSingleBlobContentQuery;
|
|
4
|
+
exports.createBlobsContentByFilePathsQuery = createBlobsContentByFilePathsQuery;
|
|
5
5
|
exports.createCommitMutation = createCommitMutation;
|
|
6
6
|
exports.createLatestCommitQuery = createLatestCommitQuery;
|
|
7
|
-
function
|
|
7
|
+
function createSingleBlobContentQuery() {
|
|
8
8
|
return `
|
|
9
9
|
query ($repositoryOwner: String!, $repositoryName: String!, $expression: String!) {
|
|
10
10
|
repository(owner: $repositoryOwner, name: $repositoryName) {
|
|
11
11
|
object(expression: $expression) {
|
|
12
|
-
... on
|
|
13
|
-
|
|
14
|
-
name
|
|
15
|
-
object {
|
|
16
|
-
__typename
|
|
17
|
-
... on Blob {
|
|
18
|
-
text
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
12
|
+
... on Blob {
|
|
13
|
+
text
|
|
22
14
|
}
|
|
23
15
|
}
|
|
24
16
|
}
|
|
25
17
|
}
|
|
26
18
|
`;
|
|
27
19
|
}
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
function createBlobsContentByFilePathsQuery(filePaths, commitHash, batchSize) {
|
|
21
|
+
const queries = [];
|
|
22
|
+
const queryFilenameAliasMap = new Map();
|
|
23
|
+
for (let fileIndex = 0; fileIndex < filePaths.length; fileIndex += batchSize) {
|
|
24
|
+
// cut file content query into batches and use GraphQL aliases for maximum throughput in regard to GitHub API limits
|
|
25
|
+
const batchFilenames = filePaths.slice(fileIndex, fileIndex + batchSize);
|
|
26
|
+
let query = `
|
|
27
|
+
query ($repositoryOwner: String!, $repositoryName: String!) {
|
|
28
|
+
repository(owner: $repositoryOwner, name: $repositoryName) {`;
|
|
29
|
+
for (const [j, filename] of batchFilenames.entries()) {
|
|
30
|
+
const fileAliasIndex = fileIndex + j;
|
|
31
|
+
const fileAlias = `file${fileAliasIndex}`;
|
|
32
|
+
// using one query variable per file would significantly blow up query size, which would in turn require a lower
|
|
33
|
+
// batch size to avoid GitHub erroring out, and in consequence much lower throughput; we therefore use this poor
|
|
34
|
+
// man's manual escaping of filenames instead and write them directly into the query strings
|
|
35
|
+
const escapedExpression = JSON.stringify(`${commitHash}:${filename}`);
|
|
36
|
+
query += ` ${fileAlias}: object(expression: ${escapedExpression}) {
|
|
37
|
+
... on Blob {
|
|
38
|
+
text
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
|
-
|
|
41
|
+
`;
|
|
42
|
+
queryFilenameAliasMap.set(fileAlias, filename);
|
|
43
|
+
}
|
|
44
|
+
query += ` }
|
|
45
|
+
}`;
|
|
46
|
+
queries.push(query);
|
|
47
|
+
}
|
|
48
|
+
return { queries, queryFilenameAliasMap };
|
|
40
49
|
}
|
|
41
50
|
function createCommitMutation() {
|
|
42
51
|
return `
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-query-factory.js","sourceRoot":"","sources":["../../../src/github-api/graphql-query-factory.ts"],"names":[],"mappings":";;AAAA,oEAYC;AAED,gFAyCC;AAED,oDA+BC;AAED,0DAeC;AAzGD,SAAgB,4BAA4B;IAC1C,OAAO;;;;;;;;;;KAUJ,CAAA;AACL,CAAC;AAED,SAAgB,kCAAkC,CAChD,SAAmB,EACnB,UAAkB,EAClB,SAAiB;IAEjB,MAAM,OAAO,GAAG,EAAE,CAAA;IAClB,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAAkB,CAAA;IACvD,KACE,IAAI,SAAS,GAAG,CAAC,EACjB,SAAS,GAAG,SAAS,CAAC,MAAM,EAC5B,SAAS,IAAI,SAAS,EACtB,CAAC;QACD,oHAAoH;QAEpH,MAAM,cAAc,GAAG,SAAS,CAAC,KAAK,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,CAAC,CAAA;QAExE,IAAI,KAAK,GAAG;;qEAEqD,CAAA;QAEjE,KAAK,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,IAAI,cAAc,CAAC,OAAO,EAAE,EAAE,CAAC;YACrD,MAAM,cAAc,GAAG,SAAS,GAAG,CAAC,CAAA;YACpC,MAAM,SAAS,GAAG,OAAO,cAAc,EAAE,CAAA;YACzC,gHAAgH;YAChH,gHAAgH;YAChH,4FAA4F;YAC5F,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,UAAU,IAAI,QAAQ,EAAE,CAAC,CAAA;YACrE,KAAK,IAAI,OAAO,SAAS,wBAAwB,iBAAiB;;;;;CAKvE,CAAA;YACK,qBAAqB,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;QAChD,CAAC;QACD,KAAK,IAAI;EACX,CAAA;QACE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACrB,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,CAAA;AAC3C,CAAC;AAED,SAAgB,oBAAoB;IAClC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA6BJ,CAAA;AACL,CAAC;AAED,SAAgB,uBAAuB;IACrC,OAAO;;;;;;;;;;;;;KAaJ,CAAA;AACL,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GITHUB_REST_API_URL = exports.GITHUB_GRAPHQL_API_URL = exports.QUERY_BATCH_SIZE = exports.PATH_ENTRY_FOLDER = exports.PATH_SCHEMA_FILE = exports.ENTRY_EXTENSION = void 0;
|
|
4
|
+
exports.ENTRY_EXTENSION = '.yaml';
|
|
5
|
+
exports.PATH_SCHEMA_FILE = 'commitspark/schema/schema.graphql';
|
|
6
|
+
exports.PATH_ENTRY_FOLDER = 'commitspark/entries/';
|
|
7
|
+
exports.QUERY_BATCH_SIZE = 250;
|
|
8
|
+
exports.GITHUB_GRAPHQL_API_URL = 'https://api.github.com/graphql';
|
|
9
|
+
exports.GITHUB_REST_API_URL = 'https://api.github.com';
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG,OAAO,CAAA;AACzB,QAAA,gBAAgB,GAAG,mCAAmC,CAAA;AACtD,QAAA,iBAAiB,GAAG,sBAAsB,CAAA;AAC1C,QAAA,gBAAgB,GAAG,GAAG,CAAA;AACtB,QAAA,sBAAsB,GAAG,gCAAgC,CAAA;AACzD,QAAA,mBAAmB,GAAG,wBAAwB,CAAA"}
|
|
@@ -4,7 +4,7 @@ exports.convertEntriesToActions = convertEntriesToActions;
|
|
|
4
4
|
const yaml_1 = require("yaml");
|
|
5
5
|
const addition_model_1 = require("../model/addition.model");
|
|
6
6
|
const deletion_model_1 = require("../model/deletion.model");
|
|
7
|
-
const types_1 = require("
|
|
7
|
+
const types_1 = require("../types");
|
|
8
8
|
function convertEntriesToActions(entryDrafts, pathEntryFolder) {
|
|
9
9
|
const additions = [];
|
|
10
10
|
const deletions = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entries-to-actions-converter.js","sourceRoot":"","sources":["../../../src/util/entries-to-actions-converter.ts"],"names":[],"mappings":";;AAMA,0DA6BC;AAlCD,+BAAgC;AAChC,4DAAuD;AACvD,4DAAuD;AACvD,
|
|
1
|
+
{"version":3,"file":"entries-to-actions-converter.js","sourceRoot":"","sources":["../../../src/util/entries-to-actions-converter.ts"],"names":[],"mappings":";;AAMA,0DA6BC;AAlCD,+BAAgC;AAChC,4DAAuD;AACvD,4DAAuD;AACvD,oCAA0C;AAE1C,SAAgB,uBAAuB,CACrC,WAAyB,EACzB,eAAuB;IAKvB,MAAM,SAAS,GAAoB,EAAE,CAAA;IACrC,MAAM,SAAS,GAAoB,EAAE,CAAA;IACrC,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QACjC,MAAM,SAAS,GAAG,GAAG,eAAe,IAAI,UAAU,CAAC,EAAE,GAAG,uBAAe,EAAE,CAAA;QACzE,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;YACxB,SAAS,CAAC,IAAI,CAAC,IAAI,8BAAa,CAAC,SAAS,CAAC,CAAC,CAAA;QAC9C,CAAC;aAAM,CAAC;YACN,SAAS,CAAC,IAAI,CACZ,IAAI,8BAAa,CACf,SAAS,EACT,IAAA,gBAAS,EAAC;gBACR,QAAQ,EAAE,UAAU,CAAC,QAAQ;gBAC7B,IAAI,EAAE,UAAU,CAAC,IAAI;aACtB,CAAC,CACH,CACF,CAAA;QACH,CAAC;IACH,CAAC,CAAC,CAAA;IACF,OAAO;QACL,SAAS;QACT,SAAS;KACV,CAAA;AACH,CAAC"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createEntriesFromFileContent = createEntriesFromFileContent;
|
|
4
4
|
const yaml_1 = require("yaml");
|
|
5
|
-
const types_1 = require("
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
.map((
|
|
11
|
-
const fileContent = (0, yaml_1.parse)(
|
|
12
|
-
const id =
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const path_factory_1 = require("./path-factory");
|
|
7
|
+
function createEntriesFromFileContent(gitRepositoryOptions, filePathContentMap) {
|
|
8
|
+
return Array.from(filePathContentMap)
|
|
9
|
+
.filter(([filePath]) => filePath.endsWith(types_1.ENTRY_EXTENSION))
|
|
10
|
+
.map(([filePath, content]) => {
|
|
11
|
+
const fileContent = (0, yaml_1.parse)(content);
|
|
12
|
+
const id = filePath.substring((0, path_factory_1.getPathEntryFolder)(gitRepositoryOptions).length, // strip folder path back out
|
|
13
|
+
filePath.length - types_1.ENTRY_EXTENSION.length);
|
|
13
14
|
return {
|
|
14
15
|
id: id,
|
|
15
16
|
metadata: fileContent.metadata,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry-factory.js","sourceRoot":"","sources":["../../../src/util/entry-factory.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"entry-factory.js","sourceRoot":"","sources":["../../../src/util/entry-factory.ts"],"names":[],"mappings":";;AAMA,oEAkBC;AAxBD,+BAA4B;AAE5B,oCAA0C;AAC1C,iDAAmD;AAGnD,SAAgB,4BAA4B,CAC1C,oBAA6C,EAC7C,kBAAuC;IAEvC,OAAO,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC;SAClC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,uBAAe,CAAC,CAAC;SAC1D,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,EAAE;QAC3B,MAAM,WAAW,GAAG,IAAA,YAAK,EAAC,OAAO,CAAC,CAAA;QAClC,MAAM,EAAE,GAAG,QAAQ,CAAC,SAAS,CAC3B,IAAA,iCAAkB,EAAC,oBAAoB,CAAC,CAAC,MAAM,EAAE,6BAA6B;QAC9E,QAAQ,CAAC,MAAM,GAAG,uBAAe,CAAC,MAAM,CACzC,CAAA;QACD,OAAO;YACL,EAAE,EAAE,EAAE;YACN,QAAQ,EAAE,WAAW,CAAC,QAAQ;YAC9B,IAAI,EAAE,WAAW,CAAC,IAAI;SACd,CAAA;IACZ,CAAC,CAAC,CAAA;AACN,CAAC"}
|