@commitspark/git-adapter-github 0.6.0 → 0.8.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 +38 -2
- package/README.md +31 -15
- package/dist/{addition.model.js → cjs/addition.model.js} +1 -2
- package/dist/cjs/addition.model.js.map +1 -0
- package/dist/{container.js → cjs/container.js} +1 -1
- package/dist/cjs/container.js.map +1 -0
- package/dist/cjs/deletion.model.js.map +1 -0
- package/dist/cjs/entries-to-actions-converter.service.js.map +1 -0
- package/dist/cjs/entry-factory.service.js.map +1 -0
- package/dist/cjs/git-hub-adapter.service.js +154 -0
- package/dist/cjs/git-hub-adapter.service.js.map +1 -0
- package/dist/cjs/graphql-query-factory.service.js.map +1 -0
- package/dist/{index.js → cjs/index.js} +2 -2
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/path-factory.service.js.map +1 -0
- package/dist/esm/addition.model.js +9 -0
- package/dist/esm/addition.model.js.map +1 -0
- package/dist/esm/container.js +17 -0
- package/dist/esm/container.js.map +1 -0
- package/dist/esm/deletion.model.js +7 -0
- package/dist/esm/deletion.model.js.map +1 -0
- package/dist/esm/entries-to-actions-converter.service.js +27 -0
- package/dist/esm/entries-to-actions-converter.service.js.map +1 -0
- package/dist/esm/entry-factory.service.js +21 -0
- package/dist/esm/entry-factory.service.js.map +1 -0
- package/dist/{git-hub-adapter.service.js → esm/git-hub-adapter.service.js} +20 -20
- package/dist/esm/git-hub-adapter.service.js.map +1 -0
- package/dist/esm/graphql-query-factory.service.js +85 -0
- package/dist/esm/graphql-query-factory.service.js.map +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/path-factory.service.js +14 -0
- package/dist/esm/path-factory.service.js.map +1 -0
- package/dist/tsconfig.build.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.build.esm.tsbuildinfo +1 -0
- package/dist/tsconfig.build.types.tsbuildinfo +1 -0
- package/dist/{addition.model.d.ts → types/addition.model.d.ts} +1 -0
- package/dist/types/addition.model.d.ts.map +1 -0
- package/dist/{container.d.ts → types/container.d.ts} +1 -0
- package/dist/types/container.d.ts.map +1 -0
- package/dist/{deletion.model.d.ts → types/deletion.model.d.ts} +1 -0
- package/dist/types/deletion.model.d.ts.map +1 -0
- package/dist/{entries-to-actions-converter.service.d.ts → types/entries-to-actions-converter.service.d.ts} +1 -0
- package/dist/types/entries-to-actions-converter.service.d.ts.map +1 -0
- package/dist/{entry-factory.service.d.ts → types/entry-factory.service.d.ts} +1 -0
- package/dist/types/entry-factory.service.d.ts.map +1 -0
- package/dist/{git-hub-adapter.service.d.ts → types/git-hub-adapter.service.d.ts} +1 -0
- package/dist/types/git-hub-adapter.service.d.ts.map +1 -0
- package/dist/{graphql-query-factory.service.d.ts → types/graphql-query-factory.service.d.ts} +1 -0
- package/dist/types/graphql-query-factory.service.d.ts.map +1 -0
- package/dist/{index.d.ts → types/index.d.ts} +2 -1
- package/dist/types/index.d.ts.map +1 -0
- package/dist/{path-factory.service.d.ts → types/path-factory.service.d.ts} +1 -0
- package/dist/types/path-factory.service.d.ts.map +1 -0
- package/package.json +27 -14
- package/src/addition.model.ts +0 -2
- package/src/git-hub-adapter.service.ts +4 -4
- package/src/index.ts +1 -1
- package/dist/addition.model.js.map +0 -1
- package/dist/container.js.map +0 -1
- package/dist/deletion.model.js.map +0 -1
- package/dist/entries-to-actions-converter.service.js.map +0 -1
- package/dist/entry-factory.service.js.map +0 -1
- package/dist/git-hub-adapter.service.js.map +0 -1
- package/dist/graphql-query-factory.service.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/path-factory.service.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- /package/dist/{deletion.model.js → cjs/deletion.model.js} +0 -0
- /package/dist/{entries-to-actions-converter.service.js → cjs/entries-to-actions-converter.service.js} +0 -0
- /package/dist/{entry-factory.service.js → cjs/entry-factory.service.js} +0 -0
- /package/dist/{graphql-query-factory.service.js → cjs/graphql-query-factory.service.js} +0 -0
- /package/dist/{path-factory.service.js → cjs/path-factory.service.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,62 +1,98 @@
|
|
|
1
1
|
# Changelog
|
|
2
|
+
|
|
2
3
|
All notable changes to this project will be documented in this file.
|
|
3
4
|
|
|
4
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
7
|
|
|
8
|
+
## [0.8.0] - 2025-04-13
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Refactor library packaging to support ESM and CJS
|
|
13
|
+
- Clean up dependencies and relax version constraints
|
|
14
|
+
|
|
15
|
+
## [0.7.0] - 2024-08-23
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- Rename Git repository option `personalAccessToken` to `accessToken` to better reflect range of usable tokens
|
|
20
|
+
- Upgrade dependencies
|
|
21
|
+
|
|
7
22
|
## [0.6.0] - 2024-08-17
|
|
23
|
+
|
|
8
24
|
### Changed
|
|
25
|
+
|
|
9
26
|
- Upgrade to `@commitspark/git-adapter` 0.13.0
|
|
10
27
|
- Upgrade dependencies
|
|
11
28
|
|
|
12
29
|
## [0.5.0] - 2023-12-12
|
|
30
|
+
|
|
13
31
|
### Changed
|
|
32
|
+
|
|
14
33
|
- Add eslint
|
|
15
34
|
- Upgrade to `@commitspark/git-adapter` 0.10.0 with new default directories
|
|
16
35
|
- Reduce number of files included in NPM package
|
|
17
36
|
|
|
18
37
|
### Fixed
|
|
38
|
+
|
|
19
39
|
- Switch to GraphQL query variables to prevent string escaping issues
|
|
20
40
|
- Fix build process to include only relevant files
|
|
21
41
|
- Refactor content entry instantiation to ignore non-blob objects
|
|
22
42
|
|
|
23
43
|
## [0.4.0] - 2023-05-12
|
|
44
|
+
|
|
24
45
|
### Changed
|
|
46
|
+
|
|
25
47
|
- Rename organization
|
|
26
48
|
|
|
27
49
|
## [0.3.2] - 2023-05-11
|
|
50
|
+
|
|
28
51
|
### Fixed
|
|
29
|
-
|
|
52
|
+
|
|
53
|
+
- [#3](https://github.com/commitspark/git-adapter-github/issues/3) Fix text content is not UTF-8 encoded when executing
|
|
54
|
+
mutations
|
|
30
55
|
- Update `yaml` library to address [security advisory](https://github.com/advisories/GHSA-f9xv-q969-pqx4)
|
|
31
56
|
|
|
32
57
|
## [0.3.1] - 2023-05-06
|
|
58
|
+
|
|
33
59
|
### Fixed
|
|
34
|
-
|
|
60
|
+
|
|
61
|
+
- [#2](https://github.com/commitspark/git-adapter-github/issues/2) Fix error when querying repository without content
|
|
62
|
+
entries
|
|
35
63
|
|
|
36
64
|
## [0.3.0] - 2023-04-28
|
|
65
|
+
|
|
37
66
|
### Changed
|
|
67
|
+
|
|
38
68
|
- Replace constructor use with object literals to prevent polluting DTOs with prototype function
|
|
39
69
|
- Update to Git Adapter interface 0.7.0
|
|
40
70
|
|
|
41
71
|
## [0.2.2] - 2023-03-15
|
|
72
|
+
|
|
42
73
|
### Changed
|
|
74
|
+
|
|
43
75
|
- Remove dependency injection package to support bundling with webpack & co.
|
|
44
76
|
- Upgrade dependencies
|
|
45
77
|
|
|
46
78
|
## [0.2.1] - 2023-03-12
|
|
47
79
|
|
|
48
80
|
### Added
|
|
81
|
+
|
|
49
82
|
- Throw exception when repository not found when retrieving commit hash
|
|
50
83
|
|
|
51
84
|
### Fixed
|
|
85
|
+
|
|
52
86
|
- Fix inadvertent use of HTTP cache for some requests
|
|
53
87
|
|
|
54
88
|
## [0.2.0] - 2022-12-13
|
|
55
89
|
|
|
56
90
|
### Added
|
|
91
|
+
|
|
57
92
|
- Expose schema file path and entries folder path as repository options
|
|
58
93
|
|
|
59
94
|
## [0.1.0] - 2022-11-04
|
|
60
95
|
|
|
61
96
|
### Added
|
|
97
|
+
|
|
62
98
|
- Initial release
|
package/README.md
CHANGED
|
@@ -10,33 +10,49 @@ access to Git repositories hosted on GitHub.
|
|
|
10
10
|
Instantiate the adapter with `createAdapter()` and then call `setRepositoryOptions()` with `GitHubRepositoryOptions` on
|
|
11
11
|
the instance. These options are as follows:
|
|
12
12
|
|
|
13
|
-
| Option name
|
|
14
|
-
|
|
15
|
-
| `repositoryOwner`
|
|
16
|
-
| `repositoryName`
|
|
17
|
-
| `
|
|
18
|
-
| `pathSchemaFile`
|
|
19
|
-
| `pathEntryFolder`
|
|
13
|
+
| Option name | Required | Default value | Description |
|
|
14
|
+
|-------------------|----------|-------------------------------------|---------------------------------------------------|
|
|
15
|
+
| `repositoryOwner` | True | | GitHub repository owner, e.g. `commitspark` |
|
|
16
|
+
| `repositoryName` | True | | GitHub repository name, e.g. `git-adapter-github` |
|
|
17
|
+
| `accessToken` | True | | GitHub access token (see details below) |
|
|
18
|
+
| `pathSchemaFile` | False | `commitspark/schema/schema.graphql` | Path to schema file in repository |
|
|
19
|
+
| `pathEntryFolder` | False | `commitspark/entries/` | Path to folder for entries |
|
|
20
20
|
|
|
21
|
-
##
|
|
21
|
+
## Access Token
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
See
|
|
25
|
-
the [GitHub documentation](https://docs.github.com/en/graphql/guides/forming-calls-with-graphql#authenticating-with-graphql).
|
|
23
|
+
An `accessToken` may be any one of the following types of tokens:
|
|
26
24
|
|
|
27
|
-
### Tokens (classic)
|
|
25
|
+
### Personal Access Tokens (classic)
|
|
28
26
|
|
|
29
|
-
A
|
|
27
|
+
A [personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)
|
|
28
|
+
with `repo` scope is required.
|
|
30
29
|
|
|
31
|
-
### Fine-grained
|
|
30
|
+
### Fine-grained Personal Access Tokens
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
For read-only access,
|
|
33
|
+
a [fine-grained personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)
|
|
34
|
+
with the following repository permissions is sufficient:
|
|
34
35
|
|
|
35
36
|
| Permission | Access |
|
|
36
37
|
|------------|-----------|
|
|
37
38
|
| Contents | Read-only |
|
|
38
39
|
| Metadata | Read-only |
|
|
39
40
|
|
|
41
|
+
For write-access, permissions must be as follows:
|
|
42
|
+
|
|
43
|
+
| Permission | Access |
|
|
44
|
+
|------------|----------------|
|
|
45
|
+
| Contents | Read and write |
|
|
46
|
+
| Metadata | Read-only |
|
|
47
|
+
|
|
48
|
+
In both cases, ensure the fine-grained permissions you give actually apply to the repository you want to work with.
|
|
49
|
+
|
|
50
|
+
### OAuth Tokens
|
|
51
|
+
|
|
52
|
+
Access tokens for a user obtained
|
|
53
|
+
from an [OAuth app](https://docs.github.com/en/apps/oauth-apps/using-oauth-apps/authorizing-oauth-apps) can be used in
|
|
54
|
+
the same way (including permissions) as fine-grained personal access tokens.
|
|
55
|
+
|
|
40
56
|
# License
|
|
41
57
|
|
|
42
58
|
The code in this repository is licensed under the permissive ISC license (see [LICENSE](LICENSE)).
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AdditionModel = void 0;
|
|
4
|
-
const buffer_1 = require("buffer");
|
|
5
4
|
class AdditionModel {
|
|
6
5
|
constructor(path, contents) {
|
|
7
6
|
this.path = path;
|
|
8
|
-
this.contents =
|
|
7
|
+
this.contents = Buffer.from(contents, 'utf8').toString('base64');
|
|
9
8
|
}
|
|
10
9
|
}
|
|
11
10
|
exports.AdditionModel = AdditionModel;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addition.model.js","sourceRoot":"","sources":["../../src/addition.model.ts"],"names":[],"mappings":";;;AAAA,MAAa,aAAa;IAExB,YACW,IAAY,EACrB,QAAgB;QADP,SAAI,GAAJ,IAAI,CAAQ;QAGrB,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAClE,CAAC;CACF;AARD,sCAQC"}
|
|
@@ -12,7 +12,7 @@ const axios_cache_interceptor_1 = require("axios-cache-interceptor");
|
|
|
12
12
|
const path_factory_service_1 = require("./path-factory.service");
|
|
13
13
|
const entry_factory_service_1 = require("./entry-factory.service");
|
|
14
14
|
const cachedHttpAdapter = (0, axios_cache_interceptor_1.setupCache)(axios_1.default.create(), {
|
|
15
|
-
ttl: git_hub_adapter_service_1.GitHubAdapterService.QUERY_CACHE_SECONDS * 1000,
|
|
15
|
+
ttl: git_hub_adapter_service_1.GitHubAdapterService.QUERY_CACHE_SECONDS * 1000, // milliseconds
|
|
16
16
|
methods: ['get', 'post'],
|
|
17
17
|
});
|
|
18
18
|
const graphqlQueryFactoryService = new graphql_query_factory_service_1.GraphqlQueryFactoryService();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../src/container.ts"],"names":[],"mappings":";;;;;;AAAA,iGAAyF;AACzF,uEAAgE;AAChE,mFAA4E;AAC5E,kDAAyB;AACzB,qEAAoD;AACpD,iEAA2D;AAC3D,mEAA6D;AAE7D,MAAM,iBAAiB,GAAG,IAAA,oCAAU,EAAC,eAAK,CAAC,MAAM,EAAE,EAAE;IACnD,GAAG,EAAE,8CAAoB,CAAC,mBAAmB,GAAG,IAAI,EAAE,eAAe;IACrE,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;CACzB,CAAC,CAAA;AAEF,MAAM,0BAA0B,GAAG,IAAI,0DAA0B,EAAE,CAAA;AACnE,MAAM,gCAAgC,GAAG,IAAI,uEAAgC,EAAE,CAAA;AAC/E,MAAM,kBAAkB,GAAG,IAAI,yCAAkB,EAAE,CAAA;AACnD,MAAM,mBAAmB,GAAG,IAAI,2CAAmB,EAAE,CAAA;AAExC,QAAA,oBAAoB,GAAG,IAAI,8CAAoB,CAC1D,iBAAiB,EACjB,0BAA0B,EAC1B,gCAAgC,EAChC,kBAAkB,EAClB,mBAAmB,CACpB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deletion.model.js","sourceRoot":"","sources":["../../src/deletion.model.ts"],"names":[],"mappings":";;;AAAA,MAAa,aAAa;IACxB,YAAqB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,CAAC;CACtC;AAFD,sCAEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entries-to-actions-converter.service.js","sourceRoot":"","sources":["../../src/entries-to-actions-converter.service.ts"],"names":[],"mappings":";;;AAAA,0DAAsE;AACtE,+BAAgC;AAChC,qDAAgD;AAChD,qDAAgD;AAEhD,MAAa,gCAAgC;IAC3C,OAAO,CACL,WAAyB,EACzB,eAAuB;QAKvB,MAAM,SAAS,GAAoB,EAAE,CAAA;QACrC,MAAM,SAAS,GAAoB,EAAE,CAAA;QACrC,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;YACjC,MAAM,SAAS,GAAG,GAAG,eAAe,IAAI,UAAU,CAAC,EAAE,GAAG,6BAAe,EAAE,CAAA;YACzE,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;gBACxB,SAAS,CAAC,IAAI,CAAC,IAAI,8BAAa,CAAC,SAAS,CAAC,CAAC,CAAA;YAC9C,CAAC;iBAAM,CAAC;gBACN,SAAS,CAAC,IAAI,CACZ,IAAI,8BAAa,CACf,SAAS,EACT,IAAA,gBAAS,EAAC;oBACR,QAAQ,EAAE,UAAU,CAAC,QAAQ;oBAC7B,IAAI,EAAE,UAAU,CAAC,IAAI;iBACtB,CAAC,CACH,CACF,CAAA;YACH,CAAC;QACH,CAAC,CAAC,CAAA;QACF,OAAO;YACL,SAAS;YACT,SAAS;SACV,CAAA;IACH,CAAC;CACF;AA/BD,4EA+BC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-factory.service.js","sourceRoot":"","sources":["../../src/entry-factory.service.ts"],"names":[],"mappings":";;;AAAA,+BAA4B;AAC5B,0DAAiE;AAUjE,MAAa,mBAAmB;IACvB,gCAAgC,CAAC,OAAoB;QAC1D,CAAC;YACC,OAAO,OAAO;iBACX,MAAM,CACL,CAAC,KAAgB,EAAE,EAAE,CACnB,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,6BAAe,CAAC;gBACpC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,MAAM,CACxC;iBACA,GAAG,CAAC,CAAC,KAAgB,EAAE,EAAE;gBACxB,MAAM,WAAW,GAAG,IAAA,YAAK,EAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;gBAC5C,MAAM,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAC7B,CAAC,EACD,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,6BAAe,CAAC,MAAM,CAC3C,CAAA;gBACD,OAAO;oBACL,EAAE,EAAE,EAAE;oBACN,QAAQ,EAAE,WAAW,CAAC,QAAQ;oBAC9B,IAAI,EAAE,WAAW,CAAC,IAAI;iBACd,CAAA;YACZ,CAAC,CAAC,CAAA;QACN,CAAC;IACH,CAAC;CACF;AAvBD,kDAuBC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
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.GitHubAdapterService = void 0;
|
|
13
|
+
class GitHubAdapterService {
|
|
14
|
+
constructor(cachedHttpAdapter, graphqlQueryFactory, entriesToActionsConverter, pathFactory, entryFactory) {
|
|
15
|
+
this.cachedHttpAdapter = cachedHttpAdapter;
|
|
16
|
+
this.graphqlQueryFactory = graphqlQueryFactory;
|
|
17
|
+
this.entriesToActionsConverter = entriesToActionsConverter;
|
|
18
|
+
this.pathFactory = pathFactory;
|
|
19
|
+
this.entryFactory = entryFactory;
|
|
20
|
+
}
|
|
21
|
+
setRepositoryOptions(repositoryOptions) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
this.gitRepositoryOptions = repositoryOptions;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
getEntries(commitHash) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
if (this.gitRepositoryOptions === undefined) {
|
|
30
|
+
throw new Error('Repository options must be set before reading');
|
|
31
|
+
}
|
|
32
|
+
const token = this.gitRepositoryOptions.accessToken;
|
|
33
|
+
const pathEntryFolder = this.pathFactory.getPathEntryFolder(this.gitRepositoryOptions);
|
|
34
|
+
const queryFilesContent = this.graphqlQueryFactory.createBlobsContentQuery();
|
|
35
|
+
const filesContentResponse = yield this.cachedHttpAdapter.post(GitHubAdapterService.API_URL, {
|
|
36
|
+
query: queryFilesContent,
|
|
37
|
+
variables: {
|
|
38
|
+
repositoryOwner: this.gitRepositoryOptions.repositoryOwner,
|
|
39
|
+
repositoryName: this.gitRepositoryOptions.repositoryName,
|
|
40
|
+
expression: `${commitHash}:${pathEntryFolder}`,
|
|
41
|
+
},
|
|
42
|
+
}, {
|
|
43
|
+
headers: {
|
|
44
|
+
authorization: `Bearer ${token}`,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
if (!((_b = (_a = filesContentResponse.data.data.repository) === null || _a === void 0 ? void 0 : _a.object) === null || _b === void 0 ? void 0 : _b.entries)) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
return this.entryFactory.createFromBlobsQueryResponseData(filesContentResponse.data.data.repository.object.entries);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
getSchema(commitHash) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
var _a, _b, _c, _d;
|
|
56
|
+
if (this.gitRepositoryOptions === undefined) {
|
|
57
|
+
throw new Error('Repository options must be set before reading');
|
|
58
|
+
}
|
|
59
|
+
const repositoryOwner = this.gitRepositoryOptions.repositoryOwner;
|
|
60
|
+
const repositoryName = this.gitRepositoryOptions.repositoryName;
|
|
61
|
+
const token = this.gitRepositoryOptions.accessToken;
|
|
62
|
+
const schemaFilePath = this.pathFactory.getPathSchema(this.gitRepositoryOptions);
|
|
63
|
+
const queryContent = this.graphqlQueryFactory.createBlobContentQuery();
|
|
64
|
+
const response = yield this.cachedHttpAdapter.post(GitHubAdapterService.API_URL, {
|
|
65
|
+
query: queryContent,
|
|
66
|
+
variables: {
|
|
67
|
+
repositoryOwner: repositoryOwner,
|
|
68
|
+
repositoryName: repositoryName,
|
|
69
|
+
expression: `${commitHash}:${schemaFilePath}`,
|
|
70
|
+
},
|
|
71
|
+
}, {
|
|
72
|
+
headers: {
|
|
73
|
+
authorization: `Bearer ${token}`,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
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;
|
|
77
|
+
if (!schema) {
|
|
78
|
+
throw new Error(`"${schemaFilePath}" not found in Git repository "${repositoryOwner}/${repositoryName}" at commit "${commitHash}"`);
|
|
79
|
+
}
|
|
80
|
+
return schema;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
getLatestCommitHash(ref) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
var _a, _b, _c, _d, _e;
|
|
86
|
+
if (this.gitRepositoryOptions === undefined) {
|
|
87
|
+
throw new Error('Repository options must be set before reading');
|
|
88
|
+
}
|
|
89
|
+
const token = this.gitRepositoryOptions.accessToken;
|
|
90
|
+
const queryLatestCommit = this.graphqlQueryFactory.createLatestCommitQuery();
|
|
91
|
+
const response = yield this.cachedHttpAdapter.post(GitHubAdapterService.API_URL, {
|
|
92
|
+
query: queryLatestCommit,
|
|
93
|
+
variables: {
|
|
94
|
+
repositoryOwner: this.gitRepositoryOptions.repositoryOwner,
|
|
95
|
+
repositoryName: this.gitRepositoryOptions.repositoryName,
|
|
96
|
+
ref: ref,
|
|
97
|
+
},
|
|
98
|
+
}, {
|
|
99
|
+
cache: false, // must not use cache, so we always get the branch's current head
|
|
100
|
+
headers: {
|
|
101
|
+
authorization: `Bearer ${token}`,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
if (!response.data.data.repository) {
|
|
105
|
+
throw new Error(`No repository found "${this.gitRepositoryOptions.repositoryOwner}/${this.gitRepositoryOptions.repositoryName}"`);
|
|
106
|
+
}
|
|
107
|
+
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;
|
|
108
|
+
if (!lastCommit) {
|
|
109
|
+
throw new Error(`No commit found for ref "${ref}"`);
|
|
110
|
+
}
|
|
111
|
+
return lastCommit;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
createCommit(commitDraft) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
var _a;
|
|
117
|
+
if (this.gitRepositoryOptions === undefined) {
|
|
118
|
+
throw new Error('Repository options must be set before committing');
|
|
119
|
+
}
|
|
120
|
+
const token = this.gitRepositoryOptions.accessToken;
|
|
121
|
+
const pathEntryFolder = this.pathFactory.getPathEntryFolder(this.gitRepositoryOptions);
|
|
122
|
+
const { additions, deletions } = this.entriesToActionsConverter.convert(commitDraft.entries, pathEntryFolder);
|
|
123
|
+
const mutateCommit = this.graphqlQueryFactory.createCommitMutation();
|
|
124
|
+
const response = yield this.cachedHttpAdapter.post(GitHubAdapterService.API_URL, {
|
|
125
|
+
query: mutateCommit,
|
|
126
|
+
variables: {
|
|
127
|
+
repositoryNameWithOwner: `${this.gitRepositoryOptions.repositoryOwner}/${this.gitRepositoryOptions.repositoryName}`,
|
|
128
|
+
branchName: commitDraft.ref,
|
|
129
|
+
commitMessage: (_a = commitDraft.message) !== null && _a !== void 0 ? _a : '-',
|
|
130
|
+
precedingCommitSha: commitDraft.parentSha,
|
|
131
|
+
additions: additions,
|
|
132
|
+
deletions: deletions,
|
|
133
|
+
},
|
|
134
|
+
}, {
|
|
135
|
+
cache: false,
|
|
136
|
+
headers: {
|
|
137
|
+
authorization: `Bearer ${token}`,
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
if (response.data.errors) {
|
|
141
|
+
throw new Error(JSON.stringify(response.data.errors));
|
|
142
|
+
}
|
|
143
|
+
const mutationResult = response.data.data.commitCreate;
|
|
144
|
+
if (mutationResult.errors) {
|
|
145
|
+
throw new Error(JSON.stringify(mutationResult.errors));
|
|
146
|
+
}
|
|
147
|
+
return { ref: mutationResult.commit.oid };
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.GitHubAdapterService = GitHubAdapterService;
|
|
152
|
+
GitHubAdapterService.QUERY_CACHE_SECONDS = 10 * 60;
|
|
153
|
+
GitHubAdapterService.API_URL = 'https://api.github.com/graphql';
|
|
154
|
+
//# sourceMappingURL=git-hub-adapter.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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iBACrB;aACF,EACD;gBACE,KAAK,EAAE,KAAK;gBACZ,OAAO,EAAE;oBACP,aAAa,EAAE,UAAU,KAAK,EAAE;iBACjC;aACF,CACF,CAAA;YAED,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACzB,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;YACvD,CAAC;YAED,MAAM,cAAc,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAA;YAEtD,IAAI,cAAc,CAAC,MAAM,EAAE,CAAC;gBAC1B,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAA;YACxD,CAAC;YAED,OAAO,EAAE,GAAG,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,EAAE,CAAA;QAC3C,CAAC;KAAA;;AA9LH,oDA+LC;AA9LiB,wCAAmB,GAAG,EAAE,GAAG,EAAE,CAAA;AAE7B,4BAAO,GAAG,gCAAgC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-query-factory.service.js","sourceRoot":"","sources":["../../src/graphql-query-factory.service.ts"],"names":[],"mappings":";;;AAAA,MAAa,0BAA0B;IAC9B,uBAAuB;QAC5B,OAAO;;;;;;;;;;;;;;;;;;KAkBN,CAAA;IACH,CAAC;IAEM,sBAAsB;QAC3B,OAAO;;;;;;;;;;KAUN,CAAA;IACH,CAAC;IAEM,oBAAoB;QACzB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA6BN,CAAA;IACH,CAAC;IAEM,uBAAuB;QAC5B,OAAO;;;;;;;;;;;;;KAaN,CAAA;IACH,CAAC;CACF;AAtFD,gEAsFC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.GitHubAdapterService = void 0;
|
|
4
|
+
exports.createAdapter = createAdapter;
|
|
4
5
|
const container_1 = require("./container");
|
|
5
6
|
var git_hub_adapter_service_1 = require("./git-hub-adapter.service");
|
|
6
7
|
Object.defineProperty(exports, "GitHubAdapterService", { enumerable: true, get: function () { return git_hub_adapter_service_1.GitHubAdapterService; } });
|
|
7
8
|
function createAdapter() {
|
|
8
9
|
return container_1.gitHubAdapterService;
|
|
9
10
|
}
|
|
10
|
-
exports.createAdapter = createAdapter;
|
|
11
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAaA,sCAEC;AAdD,2CAAkD;AAElD,qEAAgE;AAAvD,+HAAA,oBAAoB,OAAA;AAU7B,SAAgB,aAAa;IAC3B,OAAO,gCAAoB,CAAA;AAC7B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "commonjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-factory.service.js","sourceRoot":"","sources":["../../src/path-factory.service.ts"],"names":[],"mappings":";;;AACA,0DAA8E;AAE9E,MAAa,kBAAkB;IACtB,aAAa,CAAC,oBAA6C;;QAChE,OAAO,MAAA,oBAAoB,CAAC,cAAc,mCAAI,8BAAgB,CAAA;IAChE,CAAC;IAEM,kBAAkB,CACvB,oBAA6C;;QAE7C,MAAM,eAAe,GACnB,MAAA,oBAAoB,CAAC,eAAe,mCAAI,+BAAiB,CAAA;QAE3D,IAAI,eAAe,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAClC,OAAO,eAAe,CAAC,SAAS,CAAC,CAAC,EAAE,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QACjE,CAAC;QAED,OAAO,eAAe,CAAA;IACxB,CAAC;CACF;AAjBD,gDAiBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addition.model.js","sourceRoot":"","sources":["../../src/addition.model.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,aAAa;IAGb;IAFF,QAAQ,CAAQ;IACzB,YACW,IAAY,EACrB,QAAgB;QADP,SAAI,GAAJ,IAAI,CAAQ;QAGrB,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAClE,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EntriesToActionsConverterService } from './entries-to-actions-converter.service';
|
|
2
|
+
import { GitHubAdapterService } from './git-hub-adapter.service';
|
|
3
|
+
import { GraphqlQueryFactoryService } from './graphql-query-factory.service';
|
|
4
|
+
import axios from 'axios';
|
|
5
|
+
import { setupCache } from 'axios-cache-interceptor';
|
|
6
|
+
import { PathFactoryService } from './path-factory.service';
|
|
7
|
+
import { EntryFactoryService } from './entry-factory.service';
|
|
8
|
+
const cachedHttpAdapter = setupCache(axios.create(), {
|
|
9
|
+
ttl: GitHubAdapterService.QUERY_CACHE_SECONDS * 1000, // milliseconds
|
|
10
|
+
methods: ['get', 'post'],
|
|
11
|
+
});
|
|
12
|
+
const graphqlQueryFactoryService = new GraphqlQueryFactoryService();
|
|
13
|
+
const entriesToActionsConverterService = new EntriesToActionsConverterService();
|
|
14
|
+
const pathFactoryService = new PathFactoryService();
|
|
15
|
+
const entryFactoryService = new EntryFactoryService();
|
|
16
|
+
export const gitHubAdapterService = new GitHubAdapterService(cachedHttpAdapter, graphqlQueryFactoryService, entriesToActionsConverterService, pathFactoryService, entryFactoryService);
|
|
17
|
+
//# sourceMappingURL=container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../src/container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,wCAAwC,CAAA;AACzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAA;AAC5E,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAE7D,MAAM,iBAAiB,GAAG,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE;IACnD,GAAG,EAAE,oBAAoB,CAAC,mBAAmB,GAAG,IAAI,EAAE,eAAe;IACrE,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;CACzB,CAAC,CAAA;AAEF,MAAM,0BAA0B,GAAG,IAAI,0BAA0B,EAAE,CAAA;AACnE,MAAM,gCAAgC,GAAG,IAAI,gCAAgC,EAAE,CAAA;AAC/E,MAAM,kBAAkB,GAAG,IAAI,kBAAkB,EAAE,CAAA;AACnD,MAAM,mBAAmB,GAAG,IAAI,mBAAmB,EAAE,CAAA;AAErD,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,CAC1D,iBAAiB,EACjB,0BAA0B,EAC1B,gCAAgC,EAChC,kBAAkB,EAClB,mBAAmB,CACpB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deletion.model.js","sourceRoot":"","sources":["../../src/deletion.model.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,aAAa;IACH;IAArB,YAAqB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,CAAC;CACtC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ENTRY_EXTENSION } from '@commitspark/git-adapter';
|
|
2
|
+
import { stringify } from 'yaml';
|
|
3
|
+
import { AdditionModel } from './addition.model';
|
|
4
|
+
import { DeletionModel } from './deletion.model';
|
|
5
|
+
export class EntriesToActionsConverterService {
|
|
6
|
+
convert(entryDrafts, pathEntryFolder) {
|
|
7
|
+
const additions = [];
|
|
8
|
+
const deletions = [];
|
|
9
|
+
entryDrafts.forEach((entryDraft) => {
|
|
10
|
+
const entryPath = `${pathEntryFolder}/${entryDraft.id}${ENTRY_EXTENSION}`;
|
|
11
|
+
if (entryDraft.deletion) {
|
|
12
|
+
deletions.push(new DeletionModel(entryPath));
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
additions.push(new AdditionModel(entryPath, stringify({
|
|
16
|
+
metadata: entryDraft.metadata,
|
|
17
|
+
data: entryDraft.data,
|
|
18
|
+
})));
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
additions,
|
|
23
|
+
deletions,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=entries-to-actions-converter.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entries-to-actions-converter.service.js","sourceRoot":"","sources":["../../src/entries-to-actions-converter.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,eAAe,EAAE,MAAM,0BAA0B,CAAA;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEhD,MAAM,OAAO,gCAAgC;IAC3C,OAAO,CACL,WAAyB,EACzB,eAAuB;QAKvB,MAAM,SAAS,GAAoB,EAAE,CAAA;QACrC,MAAM,SAAS,GAAoB,EAAE,CAAA;QACrC,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;YACjC,MAAM,SAAS,GAAG,GAAG,eAAe,IAAI,UAAU,CAAC,EAAE,GAAG,eAAe,EAAE,CAAA;YACzE,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;gBACxB,SAAS,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,SAAS,CAAC,CAAC,CAAA;YAC9C,CAAC;iBAAM,CAAC;gBACN,SAAS,CAAC,IAAI,CACZ,IAAI,aAAa,CACf,SAAS,EACT,SAAS,CAAC;oBACR,QAAQ,EAAE,UAAU,CAAC,QAAQ;oBAC7B,IAAI,EAAE,UAAU,CAAC,IAAI;iBACtB,CAAC,CACH,CACF,CAAA;YACH,CAAC;QACH,CAAC,CAAC,CAAA;QACF,OAAO;YACL,SAAS;YACT,SAAS;SACV,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { parse } from 'yaml';
|
|
2
|
+
import { ENTRY_EXTENSION } from '@commitspark/git-adapter';
|
|
3
|
+
export class EntryFactoryService {
|
|
4
|
+
createFromBlobsQueryResponseData(entries) {
|
|
5
|
+
{
|
|
6
|
+
return entries
|
|
7
|
+
.filter((entry) => entry.name.endsWith(ENTRY_EXTENSION) &&
|
|
8
|
+
entry.object['__typename'] === 'Blob')
|
|
9
|
+
.map((entry) => {
|
|
10
|
+
const fileContent = parse(entry.object.text);
|
|
11
|
+
const id = entry.name.substring(0, entry.name.length - ENTRY_EXTENSION.length);
|
|
12
|
+
return {
|
|
13
|
+
id: id,
|
|
14
|
+
metadata: fileContent.metadata,
|
|
15
|
+
data: fileContent.data,
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=entry-factory.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-factory.service.js","sourceRoot":"","sources":["../../src/entry-factory.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAS,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAUjE,MAAM,OAAO,mBAAmB;IACvB,gCAAgC,CAAC,OAAoB;QAC1D,CAAC;YACC,OAAO,OAAO;iBACX,MAAM,CACL,CAAC,KAAgB,EAAE,EAAE,CACnB,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC;gBACpC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,MAAM,CACxC;iBACA,GAAG,CAAC,CAAC,KAAgB,EAAE,EAAE;gBACxB,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;gBAC5C,MAAM,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAC7B,CAAC,EACD,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,eAAe,CAAC,MAAM,CAC3C,CAAA;gBACD,OAAO;oBACL,EAAE,EAAE,EAAE;oBACN,QAAQ,EAAE,WAAW,CAAC,QAAQ;oBAC9B,IAAI,EAAE,WAAW,CAAC,IAAI;iBACd,CAAA;YACZ,CAAC,CAAC,CAAA;QACN,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export class GitHubAdapterService {
|
|
2
|
+
cachedHttpAdapter;
|
|
3
|
+
graphqlQueryFactory;
|
|
4
|
+
entriesToActionsConverter;
|
|
5
|
+
pathFactory;
|
|
6
|
+
entryFactory;
|
|
7
|
+
static QUERY_CACHE_SECONDS = 10 * 60;
|
|
8
|
+
static API_URL = 'https://api.github.com/graphql';
|
|
9
|
+
gitRepositoryOptions;
|
|
5
10
|
constructor(cachedHttpAdapter, graphqlQueryFactory, entriesToActionsConverter, pathFactory, entryFactory) {
|
|
6
11
|
this.cachedHttpAdapter = cachedHttpAdapter;
|
|
7
12
|
this.graphqlQueryFactory = graphqlQueryFactory;
|
|
@@ -13,11 +18,10 @@ class GitHubAdapterService {
|
|
|
13
18
|
this.gitRepositoryOptions = repositoryOptions;
|
|
14
19
|
}
|
|
15
20
|
async getEntries(commitHash) {
|
|
16
|
-
var _a, _b;
|
|
17
21
|
if (this.gitRepositoryOptions === undefined) {
|
|
18
22
|
throw new Error('Repository options must be set before reading');
|
|
19
23
|
}
|
|
20
|
-
const token = this.gitRepositoryOptions.
|
|
24
|
+
const token = this.gitRepositoryOptions.accessToken;
|
|
21
25
|
const pathEntryFolder = this.pathFactory.getPathEntryFolder(this.gitRepositoryOptions);
|
|
22
26
|
const queryFilesContent = this.graphqlQueryFactory.createBlobsContentQuery();
|
|
23
27
|
const filesContentResponse = await this.cachedHttpAdapter.post(GitHubAdapterService.API_URL, {
|
|
@@ -32,19 +36,18 @@ class GitHubAdapterService {
|
|
|
32
36
|
authorization: `Bearer ${token}`,
|
|
33
37
|
},
|
|
34
38
|
});
|
|
35
|
-
if (!
|
|
39
|
+
if (!filesContentResponse.data.data.repository?.object?.entries) {
|
|
36
40
|
return [];
|
|
37
41
|
}
|
|
38
42
|
return this.entryFactory.createFromBlobsQueryResponseData(filesContentResponse.data.data.repository.object.entries);
|
|
39
43
|
}
|
|
40
44
|
async getSchema(commitHash) {
|
|
41
|
-
var _a, _b, _c, _d;
|
|
42
45
|
if (this.gitRepositoryOptions === undefined) {
|
|
43
46
|
throw new Error('Repository options must be set before reading');
|
|
44
47
|
}
|
|
45
48
|
const repositoryOwner = this.gitRepositoryOptions.repositoryOwner;
|
|
46
49
|
const repositoryName = this.gitRepositoryOptions.repositoryName;
|
|
47
|
-
const token = this.gitRepositoryOptions.
|
|
50
|
+
const token = this.gitRepositoryOptions.accessToken;
|
|
48
51
|
const schemaFilePath = this.pathFactory.getPathSchema(this.gitRepositoryOptions);
|
|
49
52
|
const queryContent = this.graphqlQueryFactory.createBlobContentQuery();
|
|
50
53
|
const response = await this.cachedHttpAdapter.post(GitHubAdapterService.API_URL, {
|
|
@@ -59,18 +62,17 @@ class GitHubAdapterService {
|
|
|
59
62
|
authorization: `Bearer ${token}`,
|
|
60
63
|
},
|
|
61
64
|
});
|
|
62
|
-
const schema =
|
|
65
|
+
const schema = response.data?.data?.repository?.object?.text;
|
|
63
66
|
if (!schema) {
|
|
64
67
|
throw new Error(`"${schemaFilePath}" not found in Git repository "${repositoryOwner}/${repositoryName}" at commit "${commitHash}"`);
|
|
65
68
|
}
|
|
66
69
|
return schema;
|
|
67
70
|
}
|
|
68
71
|
async getLatestCommitHash(ref) {
|
|
69
|
-
var _a, _b, _c, _d, _e;
|
|
70
72
|
if (this.gitRepositoryOptions === undefined) {
|
|
71
73
|
throw new Error('Repository options must be set before reading');
|
|
72
74
|
}
|
|
73
|
-
const token = this.gitRepositoryOptions.
|
|
75
|
+
const token = this.gitRepositoryOptions.accessToken;
|
|
74
76
|
const queryLatestCommit = this.graphqlQueryFactory.createLatestCommitQuery();
|
|
75
77
|
const response = await this.cachedHttpAdapter.post(GitHubAdapterService.API_URL, {
|
|
76
78
|
query: queryLatestCommit,
|
|
@@ -80,7 +82,7 @@ class GitHubAdapterService {
|
|
|
80
82
|
ref: ref,
|
|
81
83
|
},
|
|
82
84
|
}, {
|
|
83
|
-
cache: false,
|
|
85
|
+
cache: false, // must not use cache, so we always get the branch's current head
|
|
84
86
|
headers: {
|
|
85
87
|
authorization: `Bearer ${token}`,
|
|
86
88
|
},
|
|
@@ -88,18 +90,19 @@ class GitHubAdapterService {
|
|
|
88
90
|
if (!response.data.data.repository) {
|
|
89
91
|
throw new Error(`No repository found "${this.gitRepositoryOptions.repositoryOwner}/${this.gitRepositoryOptions.repositoryName}"`);
|
|
90
92
|
}
|
|
91
|
-
const lastCommit =
|
|
93
|
+
const lastCommit = response.data.data.repository.ref?.target?.oid ??
|
|
94
|
+
response.data.data.repository.object?.oid ??
|
|
95
|
+
undefined;
|
|
92
96
|
if (!lastCommit) {
|
|
93
97
|
throw new Error(`No commit found for ref "${ref}"`);
|
|
94
98
|
}
|
|
95
99
|
return lastCommit;
|
|
96
100
|
}
|
|
97
101
|
async createCommit(commitDraft) {
|
|
98
|
-
var _a;
|
|
99
102
|
if (this.gitRepositoryOptions === undefined) {
|
|
100
103
|
throw new Error('Repository options must be set before committing');
|
|
101
104
|
}
|
|
102
|
-
const token = this.gitRepositoryOptions.
|
|
105
|
+
const token = this.gitRepositoryOptions.accessToken;
|
|
103
106
|
const pathEntryFolder = this.pathFactory.getPathEntryFolder(this.gitRepositoryOptions);
|
|
104
107
|
const { additions, deletions } = this.entriesToActionsConverter.convert(commitDraft.entries, pathEntryFolder);
|
|
105
108
|
const mutateCommit = this.graphqlQueryFactory.createCommitMutation();
|
|
@@ -108,7 +111,7 @@ class GitHubAdapterService {
|
|
|
108
111
|
variables: {
|
|
109
112
|
repositoryNameWithOwner: `${this.gitRepositoryOptions.repositoryOwner}/${this.gitRepositoryOptions.repositoryName}`,
|
|
110
113
|
branchName: commitDraft.ref,
|
|
111
|
-
commitMessage:
|
|
114
|
+
commitMessage: commitDraft.message ?? '-',
|
|
112
115
|
precedingCommitSha: commitDraft.parentSha,
|
|
113
116
|
additions: additions,
|
|
114
117
|
deletions: deletions,
|
|
@@ -129,7 +132,4 @@ class GitHubAdapterService {
|
|
|
129
132
|
return { ref: mutationResult.commit.oid };
|
|
130
133
|
}
|
|
131
134
|
}
|
|
132
|
-
exports.GitHubAdapterService = GitHubAdapterService;
|
|
133
|
-
GitHubAdapterService.QUERY_CACHE_SECONDS = 10 * 60;
|
|
134
|
-
GitHubAdapterService.API_URL = 'https://api.github.com/graphql';
|
|
135
135
|
//# sourceMappingURL=git-hub-adapter.service.js.map
|