@commitspark/git-adapter-github 0.20.0 → 0.21.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 CHANGED
@@ -5,6 +5,12 @@ 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.21.0] - 2025-11-11
9
+
10
+ ### Added
11
+
12
+ - Add error handling and abstraction for GitHub API responses
13
+
8
14
  ## [0.20.0] - 2025-11-08
9
15
 
10
16
  ### 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,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,MAAM,CAAC,CAAA;QAC3C,MAAM,SAAS,GAAuB,MAAA,MAAM,CAAC,CAAC,CAAC,0CAAE,IAAI,CAAA;QAErD,2EAA2E;QAC3E,kDAAkD;QAClD,sEAAsE;QACtE,IAAI,SAAS,KAAK,WAAW,EAAE,CAAC;YAC9B,MAAM,IAAI,6BAAe,CAAC,uBAAS,CAAC,SAAS,EAAE,YAAY,CAAC,CAAA;QAC9D,CAAC;aAAM,IAAI,SAAS,KAAK,cAAc,EAAE,CAAC;YACxC,MAAM,IAAI,6BAAe,CAAC,uBAAS,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"}
@@ -10,28 +10,40 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.createCommit = exports.getLatestCommitHash = exports.getSchema = exports.getEntries = exports.API_URL = void 0;
13
+ const git_adapter_1 = require("@commitspark/git-adapter");
13
14
  const graphql_query_factory_1 = require("./util/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");
18
+ const errors_1 = require("./errors");
17
19
  exports.API_URL = 'https://api.github.com/graphql';
18
20
  const getEntries = (gitRepositoryOptions, axiosCacheInstance, commitHash) => __awaiter(void 0, void 0, void 0, function* () {
19
21
  var _a, _b;
20
22
  const token = gitRepositoryOptions.accessToken;
21
23
  const pathEntryFolder = (0, path_factory_1.getPathEntryFolder)(gitRepositoryOptions);
22
24
  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
- });
25
+ let filesContentResponse;
26
+ try {
27
+ filesContentResponse = yield axiosCacheInstance.post(exports.API_URL, {
28
+ query: queryFilesContent,
29
+ variables: {
30
+ repositoryOwner: gitRepositoryOptions.repositoryOwner,
31
+ repositoryName: gitRepositoryOptions.repositoryName,
32
+ expression: `${commitHash}:${pathEntryFolder}`,
33
+ },
34
+ }, {
35
+ headers: {
36
+ authorization: `Bearer ${token}`,
37
+ },
38
+ });
39
+ }
40
+ catch (error) {
41
+ (0, errors_1.handleHttpErrors)(error);
42
+ }
43
+ if (!filesContentResponse) {
44
+ throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.INTERNAL_ERROR, 'Failed to fetch entries');
45
+ }
46
+ (0, errors_1.handleGraphQLErrors)(filesContentResponse);
35
47
  if (!((_b = (_a = filesContentResponse.data.data.repository) === null || _a === void 0 ? void 0 : _a.object) === null || _b === void 0 ? void 0 : _b.entries)) {
36
48
  return [];
37
49
  }
@@ -45,21 +57,31 @@ const getSchema = (gitRepositoryOptions, axiosCacheInstance, commitHash) => __aw
45
57
  const token = gitRepositoryOptions.accessToken;
46
58
  const schemaFilePath = (0, path_factory_1.getPathSchema)(gitRepositoryOptions);
47
59
  const queryContent = (0, graphql_query_factory_1.createBlobContentQuery)();
48
- const response = yield axiosCacheInstance.post(exports.API_URL, {
49
- query: queryContent,
50
- variables: {
51
- repositoryOwner: repositoryOwner,
52
- repositoryName: repositoryName,
53
- expression: `${commitHash}:${schemaFilePath}`,
54
- },
55
- }, {
56
- headers: {
57
- authorization: `Bearer ${token}`,
58
- },
59
- });
60
+ let response;
61
+ try {
62
+ response = yield axiosCacheInstance.post(exports.API_URL, {
63
+ query: queryContent,
64
+ variables: {
65
+ repositoryOwner: repositoryOwner,
66
+ repositoryName: repositoryName,
67
+ expression: `${commitHash}:${schemaFilePath}`,
68
+ },
69
+ }, {
70
+ headers: {
71
+ authorization: `Bearer ${token}`,
72
+ },
73
+ });
74
+ }
75
+ catch (error) {
76
+ (0, errors_1.handleHttpErrors)(error);
77
+ }
78
+ if (!response) {
79
+ throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.INTERNAL_ERROR, `Failed to fetch schema`);
80
+ }
81
+ (0, errors_1.handleGraphQLErrors)(response);
60
82
  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
83
  if (!schema) {
62
- throw new Error(`"${schemaFilePath}" not found in Git repository "${repositoryOwner}/${repositoryName}" at commit "${commitHash}"`);
84
+ throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.NOT_FOUND, `"${schemaFilePath}" not found in Git repository "${repositoryOwner}/${repositoryName}" at commit "${commitHash}"`);
63
85
  }
64
86
  return schema;
65
87
  });
@@ -68,25 +90,35 @@ const getLatestCommitHash = (gitRepositoryOptions, axiosCacheInstance, ref) => _
68
90
  var _a, _b, _c, _d, _e;
69
91
  const token = gitRepositoryOptions.accessToken;
70
92
  const queryLatestCommit = (0, graphql_query_factory_1.createLatestCommitQuery)();
71
- const response = yield axiosCacheInstance.post(exports.API_URL, {
72
- query: queryLatestCommit,
73
- variables: {
74
- repositoryOwner: gitRepositoryOptions.repositoryOwner,
75
- repositoryName: gitRepositoryOptions.repositoryName,
76
- ref: ref,
77
- },
78
- }, {
79
- cache: false, // must not use cache, so we always get the branch's current head
80
- headers: {
81
- authorization: `Bearer ${token}`,
82
- },
83
- });
93
+ let response;
94
+ try {
95
+ response = yield axiosCacheInstance.post(exports.API_URL, {
96
+ query: queryLatestCommit,
97
+ variables: {
98
+ repositoryOwner: gitRepositoryOptions.repositoryOwner,
99
+ repositoryName: gitRepositoryOptions.repositoryName,
100
+ ref: ref,
101
+ },
102
+ }, {
103
+ cache: false, // must not use cache, so we always get the branch's current head
104
+ headers: {
105
+ authorization: `Bearer ${token}`,
106
+ },
107
+ });
108
+ }
109
+ catch (error) {
110
+ (0, errors_1.handleHttpErrors)(error);
111
+ }
112
+ if (!response) {
113
+ throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.INTERNAL_ERROR, 'Failed to fetch latest commit');
114
+ }
115
+ (0, errors_1.handleGraphQLErrors)(response);
84
116
  if (!response.data.data.repository) {
85
- throw new Error(`No repository found "${gitRepositoryOptions.repositoryOwner}/${gitRepositoryOptions.repositoryName}"`);
117
+ throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.NOT_FOUND, `No repository found "${gitRepositoryOptions.repositoryOwner}/${gitRepositoryOptions.repositoryName}"`);
86
118
  }
87
119
  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
120
  if (!lastCommit) {
89
- throw new Error(`No commit found for ref "${ref}"`);
121
+ throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.NOT_FOUND, `No commit found for ref "${ref}"`);
90
122
  }
91
123
  return lastCommit;
92
124
  });
@@ -97,28 +129,36 @@ const createCommit = (gitRepositoryOptions, axiosCacheInstance, commitDraft) =>
97
129
  const pathEntryFolder = (0, path_factory_1.getPathEntryFolder)(gitRepositoryOptions);
98
130
  const { additions, deletions } = (0, entries_to_actions_converter_1.convertEntriesToActions)(commitDraft.entries, pathEntryFolder);
99
131
  const mutateCommit = (0, graphql_query_factory_1.createCommitMutation)();
100
- const response = yield axiosCacheInstance.post(exports.API_URL, {
101
- query: mutateCommit,
102
- variables: {
103
- repositoryNameWithOwner: `${gitRepositoryOptions.repositoryOwner}/${gitRepositoryOptions.repositoryName}`,
104
- branchName: commitDraft.ref,
105
- commitMessage: (_a = commitDraft.message) !== null && _a !== void 0 ? _a : '-',
106
- precedingCommitSha: commitDraft.parentSha,
107
- additions: additions,
108
- deletions: deletions,
109
- },
110
- }, {
111
- cache: false,
112
- headers: {
113
- authorization: `Bearer ${token}`,
114
- },
115
- });
116
- if (response.data.errors) {
117
- throw new Error(JSON.stringify(response.data.errors));
132
+ let response;
133
+ try {
134
+ response = yield axiosCacheInstance.post(exports.API_URL, {
135
+ query: mutateCommit,
136
+ variables: {
137
+ repositoryNameWithOwner: `${gitRepositoryOptions.repositoryOwner}/${gitRepositoryOptions.repositoryName}`,
138
+ branchName: commitDraft.ref,
139
+ commitMessage: (_a = commitDraft.message) !== null && _a !== void 0 ? _a : '-',
140
+ precedingCommitSha: commitDraft.parentSha,
141
+ additions: additions,
142
+ deletions: deletions,
143
+ },
144
+ }, {
145
+ cache: false,
146
+ headers: {
147
+ authorization: `Bearer ${token}`,
148
+ },
149
+ });
150
+ }
151
+ catch (error) {
152
+ (0, errors_1.handleHttpErrors)(error);
153
+ }
154
+ if (!response) {
155
+ throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.INTERNAL_ERROR, `Failed to create commit`);
118
156
  }
157
+ (0, errors_1.handleGraphQLErrors)(response);
119
158
  const mutationResult = response.data.data.commitCreate;
120
159
  if (mutationResult.errors) {
121
- throw new Error(JSON.stringify(mutationResult.errors));
160
+ const errorMessage = JSON.stringify(mutationResult.errors);
161
+ throw new git_adapter_1.GitAdapterError(git_adapter_1.ErrorCode.BAD_REQUEST, `Failed to create commit: ${errorMessage}`);
122
162
  }
123
163
  return { ref: mutationResult.commit.oid };
124
164
  });
@@ -1 +1 @@
1
- {"version":3,"file":"github-adapter.js","sourceRoot":"","sources":["../../src/github-adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,wEAKqC;AACrC,sFAA6E;AAC7E,sDAAuE;AACvE,wDAA8E;AAEjE,QAAA,OAAO,GAAG,gCAAgC,CAAA;AAEhD,MAAM,UAAU,GAAG,CACxB,oBAA6C,EAC7C,kBAAsC,EACtC,UAAkB,EACA,EAAE;;IACpB,MAAM,KAAK,GAAG,oBAAoB,CAAC,WAAW,CAAA;IAC9C,MAAM,eAAe,GAAG,IAAA,iCAAkB,EAAC,oBAAoB,CAAC,CAAA;IAEhE,MAAM,iBAAiB,GAAG,IAAA,+CAAuB,GAAE,CAAA;IACnD,MAAM,oBAAoB,GAAG,MAAM,kBAAkB,CAAC,IAAI,CACxD,eAAO,EACP;QACE,KAAK,EAAE,iBAAiB;QACxB,SAAS,EAAE;YACT,eAAe,EAAE,oBAAoB,CAAC,eAAe;YACrD,cAAc,EAAE,oBAAoB,CAAC,cAAc;YACnD,UAAU,EAAE,GAAG,UAAU,IAAI,eAAe,EAAE;SAC/C;KACF,EACD;QACE,OAAO,EAAE;YACP,aAAa,EAAE,UAAU,KAAK,EAAE;SACjC;KACF,CACF,CAAA;IAED,IAAI,CAAC,CAAA,MAAA,MAAA,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,0CAAE,MAAM,0CAAE,OAAO,CAAA,EAAE,CAAC;QAChE,OAAO,EAAE,CAAA;IACX,CAAC;IAED,OAAO,IAAA,uDAAuC,EAC5C,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CACzD,CAAA;AACH,CAAC,CAAA,CAAA;AAjCY,QAAA,UAAU,cAiCtB;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;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,51 @@
1
+ import { ErrorCode, GitAdapterError } from '@commitspark/git-adapter';
2
+ import { AxiosError } from 'axios';
3
+ export const handleHttpErrors = (error) => {
4
+ if (error instanceof AxiosError) {
5
+ const status = error.response?.status;
6
+ const message = error.response?.data?.message || error.message;
7
+ switch (status) {
8
+ case 400:
9
+ throw new GitAdapterError(ErrorCode.BAD_REQUEST, message);
10
+ case 401:
11
+ throw new GitAdapterError(ErrorCode.UNAUTHORIZED, message);
12
+ case 403:
13
+ throw new GitAdapterError(ErrorCode.FORBIDDEN, message);
14
+ case 404:
15
+ throw new GitAdapterError(ErrorCode.NOT_FOUND, message);
16
+ case 409:
17
+ throw new GitAdapterError(ErrorCode.CONFLICT, message);
18
+ case 429:
19
+ throw new GitAdapterError(ErrorCode.TOO_MANY_REQUESTS, message);
20
+ default:
21
+ throw new GitAdapterError(ErrorCode.INTERNAL_ERROR, message);
22
+ }
23
+ }
24
+ throw new GitAdapterError(ErrorCode.INTERNAL_ERROR, error instanceof Error ? error.message : 'Unknown error');
25
+ };
26
+ export const handleGraphQLErrors = (response) => {
27
+ if (response.data.errors) {
28
+ const errors = response.data.errors;
29
+ const errorMessage = JSON.stringify(errors);
30
+ const errorType = errors[0]?.type;
31
+ // GitHub error types are not documented, and documentation is not planned,
32
+ // see https://github.com/github/docs/issues/22607
33
+ // Error type values below have been discovered through manual testing
34
+ if (errorType === 'NOT_FOUND') {
35
+ throw new GitAdapterError(ErrorCode.NOT_FOUND, errorMessage);
36
+ }
37
+ else if (errorType === 'RATE_LIMITED') {
38
+ throw new GitAdapterError(ErrorCode.TOO_MANY_REQUESTS, errorMessage);
39
+ }
40
+ else if (errorType === 'FORBIDDEN') {
41
+ throw new GitAdapterError(ErrorCode.FORBIDDEN, errorMessage);
42
+ }
43
+ else if (errorType === 'STALE_DATA') {
44
+ throw new GitAdapterError(ErrorCode.CONFLICT, errorMessage);
45
+ }
46
+ else {
47
+ throw new GitAdapterError(ErrorCode.INTERNAL_ERROR, errorMessage);
48
+ }
49
+ }
50
+ };
51
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AACrE,OAAO,EAAE,UAAU,EAAiB,MAAM,OAAO,CAAA;AAEjD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAS,EAAE;IACxD,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;QAChC,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAA;QACrC,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,IAAI,KAAK,CAAC,OAAO,CAAA;QAE9D,QAAQ,MAAM,EAAE,CAAC;YAC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CAAC,SAAS,CAAC,SAAS,EAAE,YAAY,CAAC,CAAA;QAC9D,CAAC;aAAM,IAAI,SAAS,KAAK,cAAc,EAAE,CAAC;YACxC,MAAM,IAAI,eAAe,CAAC,SAAS,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAA;QACtE,CAAC;aAAM,IAAI,SAAS,KAAK,WAAW,EAAE,CAAC;YACrC,MAAM,IAAI,eAAe,CAAC,SAAS,CAAC,SAAS,EAAE,YAAY,CAAC,CAAA;QAC9D,CAAC;aAAM,IAAI,SAAS,KAAK,YAAY,EAAE,CAAC;YACtC,MAAM,IAAI,eAAe,CAAC,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;QAC7D,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,eAAe,CAAC,SAAS,CAAC,cAAc,EAAE,YAAY,CAAC,CAAA;QACnE,CAAC;IACH,CAAC;AACH,CAAC,CAAA"}
@@ -1,24 +1,36 @@
1
+ import { ErrorCode, GitAdapterError, } from '@commitspark/git-adapter';
1
2
  import { createBlobContentQuery, createBlobsContentQuery, createCommitMutation, createLatestCommitQuery, } from './util/graphql-query-factory';
2
3
  import { convertEntriesToActions } from './util/entries-to-actions-converter';
3
4
  import { getPathEntryFolder, getPathSchema } from './util/path-factory';
4
5
  import { createEntriesFromBlobsQueryResponseData } from './util/entry-factory';
6
+ import { handleHttpErrors, handleGraphQLErrors } from './errors';
5
7
  export const API_URL = 'https://api.github.com/graphql';
6
8
  export const getEntries = async (gitRepositoryOptions, axiosCacheInstance, commitHash) => {
7
9
  const token = gitRepositoryOptions.accessToken;
8
10
  const pathEntryFolder = getPathEntryFolder(gitRepositoryOptions);
9
11
  const queryFilesContent = createBlobsContentQuery();
10
- const filesContentResponse = await axiosCacheInstance.post(API_URL, {
11
- query: queryFilesContent,
12
- variables: {
13
- repositoryOwner: gitRepositoryOptions.repositoryOwner,
14
- repositoryName: gitRepositoryOptions.repositoryName,
15
- expression: `${commitHash}:${pathEntryFolder}`,
16
- },
17
- }, {
18
- headers: {
19
- authorization: `Bearer ${token}`,
20
- },
21
- });
12
+ let filesContentResponse;
13
+ try {
14
+ filesContentResponse = await axiosCacheInstance.post(API_URL, {
15
+ query: queryFilesContent,
16
+ variables: {
17
+ repositoryOwner: gitRepositoryOptions.repositoryOwner,
18
+ repositoryName: gitRepositoryOptions.repositoryName,
19
+ expression: `${commitHash}:${pathEntryFolder}`,
20
+ },
21
+ }, {
22
+ headers: {
23
+ authorization: `Bearer ${token}`,
24
+ },
25
+ });
26
+ }
27
+ catch (error) {
28
+ handleHttpErrors(error);
29
+ }
30
+ if (!filesContentResponse) {
31
+ throw new GitAdapterError(ErrorCode.INTERNAL_ERROR, 'Failed to fetch entries');
32
+ }
33
+ handleGraphQLErrors(filesContentResponse);
22
34
  if (!filesContentResponse.data.data.repository?.object?.entries) {
23
35
  return [];
24
36
  }
@@ -30,48 +42,68 @@ export const getSchema = async (gitRepositoryOptions, axiosCacheInstance, commit
30
42
  const token = gitRepositoryOptions.accessToken;
31
43
  const schemaFilePath = getPathSchema(gitRepositoryOptions);
32
44
  const queryContent = createBlobContentQuery();
33
- const response = await axiosCacheInstance.post(API_URL, {
34
- query: queryContent,
35
- variables: {
36
- repositoryOwner: repositoryOwner,
37
- repositoryName: repositoryName,
38
- expression: `${commitHash}:${schemaFilePath}`,
39
- },
40
- }, {
41
- headers: {
42
- authorization: `Bearer ${token}`,
43
- },
44
- });
45
+ let response;
46
+ try {
47
+ response = await axiosCacheInstance.post(API_URL, {
48
+ query: queryContent,
49
+ variables: {
50
+ repositoryOwner: repositoryOwner,
51
+ repositoryName: repositoryName,
52
+ expression: `${commitHash}:${schemaFilePath}`,
53
+ },
54
+ }, {
55
+ headers: {
56
+ authorization: `Bearer ${token}`,
57
+ },
58
+ });
59
+ }
60
+ catch (error) {
61
+ handleHttpErrors(error);
62
+ }
63
+ if (!response) {
64
+ throw new GitAdapterError(ErrorCode.INTERNAL_ERROR, `Failed to fetch schema`);
65
+ }
66
+ handleGraphQLErrors(response);
45
67
  const schema = response.data?.data?.repository?.object?.text;
46
68
  if (!schema) {
47
- throw new Error(`"${schemaFilePath}" not found in Git repository "${repositoryOwner}/${repositoryName}" at commit "${commitHash}"`);
69
+ throw new GitAdapterError(ErrorCode.NOT_FOUND, `"${schemaFilePath}" not found in Git repository "${repositoryOwner}/${repositoryName}" at commit "${commitHash}"`);
48
70
  }
49
71
  return schema;
50
72
  };
51
73
  export const getLatestCommitHash = async (gitRepositoryOptions, axiosCacheInstance, ref) => {
52
74
  const token = gitRepositoryOptions.accessToken;
53
75
  const queryLatestCommit = createLatestCommitQuery();
54
- const response = await axiosCacheInstance.post(API_URL, {
55
- query: queryLatestCommit,
56
- variables: {
57
- repositoryOwner: gitRepositoryOptions.repositoryOwner,
58
- repositoryName: gitRepositoryOptions.repositoryName,
59
- ref: ref,
60
- },
61
- }, {
62
- cache: false, // must not use cache, so we always get the branch's current head
63
- headers: {
64
- authorization: `Bearer ${token}`,
65
- },
66
- });
76
+ let response;
77
+ try {
78
+ response = await axiosCacheInstance.post(API_URL, {
79
+ query: queryLatestCommit,
80
+ variables: {
81
+ repositoryOwner: gitRepositoryOptions.repositoryOwner,
82
+ repositoryName: gitRepositoryOptions.repositoryName,
83
+ ref: ref,
84
+ },
85
+ }, {
86
+ cache: false, // must not use cache, so we always get the branch's current head
87
+ headers: {
88
+ authorization: `Bearer ${token}`,
89
+ },
90
+ });
91
+ }
92
+ catch (error) {
93
+ handleHttpErrors(error);
94
+ }
95
+ if (!response) {
96
+ throw new GitAdapterError(ErrorCode.INTERNAL_ERROR, 'Failed to fetch latest commit');
97
+ }
98
+ handleGraphQLErrors(response);
67
99
  if (!response.data.data.repository) {
68
- throw new Error(`No repository found "${gitRepositoryOptions.repositoryOwner}/${gitRepositoryOptions.repositoryName}"`);
100
+ throw new GitAdapterError(ErrorCode.NOT_FOUND, `No repository found "${gitRepositoryOptions.repositoryOwner}/${gitRepositoryOptions.repositoryName}"`);
69
101
  }
70
102
  const lastCommit = response.data.data.repository.ref?.target?.oid ??
71
103
  response.data.data.repository.object?.oid ??
72
104
  undefined;
73
105
  if (!lastCommit) {
74
- throw new Error(`No commit found for ref "${ref}"`);
106
+ throw new GitAdapterError(ErrorCode.NOT_FOUND, `No commit found for ref "${ref}"`);
75
107
  }
76
108
  return lastCommit;
77
109
  };
@@ -80,28 +112,36 @@ export const createCommit = async (gitRepositoryOptions, axiosCacheInstance, com
80
112
  const pathEntryFolder = getPathEntryFolder(gitRepositoryOptions);
81
113
  const { additions, deletions } = convertEntriesToActions(commitDraft.entries, pathEntryFolder);
82
114
  const mutateCommit = createCommitMutation();
83
- const response = await axiosCacheInstance.post(API_URL, {
84
- query: mutateCommit,
85
- variables: {
86
- repositoryNameWithOwner: `${gitRepositoryOptions.repositoryOwner}/${gitRepositoryOptions.repositoryName}`,
87
- branchName: commitDraft.ref,
88
- commitMessage: commitDraft.message ?? '-',
89
- precedingCommitSha: commitDraft.parentSha,
90
- additions: additions,
91
- deletions: deletions,
92
- },
93
- }, {
94
- cache: false,
95
- headers: {
96
- authorization: `Bearer ${token}`,
97
- },
98
- });
99
- if (response.data.errors) {
100
- throw new Error(JSON.stringify(response.data.errors));
115
+ let response;
116
+ try {
117
+ response = await axiosCacheInstance.post(API_URL, {
118
+ query: mutateCommit,
119
+ variables: {
120
+ repositoryNameWithOwner: `${gitRepositoryOptions.repositoryOwner}/${gitRepositoryOptions.repositoryName}`,
121
+ branchName: commitDraft.ref,
122
+ commitMessage: commitDraft.message ?? '-',
123
+ precedingCommitSha: commitDraft.parentSha,
124
+ additions: additions,
125
+ deletions: deletions,
126
+ },
127
+ }, {
128
+ cache: false,
129
+ headers: {
130
+ authorization: `Bearer ${token}`,
131
+ },
132
+ });
133
+ }
134
+ catch (error) {
135
+ handleHttpErrors(error);
136
+ }
137
+ if (!response) {
138
+ throw new GitAdapterError(ErrorCode.INTERNAL_ERROR, `Failed to create commit`);
101
139
  }
140
+ handleGraphQLErrors(response);
102
141
  const mutationResult = response.data.data.commitCreate;
103
142
  if (mutationResult.errors) {
104
- throw new Error(JSON.stringify(mutationResult.errors));
143
+ const errorMessage = JSON.stringify(mutationResult.errors);
144
+ throw new GitAdapterError(ErrorCode.BAD_REQUEST, `Failed to create commit: ${errorMessage}`);
105
145
  }
106
146
  return { ref: mutationResult.commit.oid };
107
147
  };