@commitspark/git-adapter-github 0.4.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/.prettierrc +6 -0
- package/CHANGELOG.md +46 -0
- package/LICENSE +15 -0
- package/README.md +22 -0
- package/dist/addition.model.d.ts +5 -0
- package/dist/addition.model.js +12 -0
- package/dist/addition.model.js.map +1 -0
- package/dist/container.d.ts +2 -0
- package/dist/container.js +19 -0
- package/dist/container.js.map +1 -0
- package/dist/content-entries-to-actions-converter.service.d.ts +9 -0
- package/dist/content-entries-to-actions-converter.service.js +31 -0
- package/dist/content-entries-to-actions-converter.service.js.map +1 -0
- package/dist/deletion.model.d.ts +4 -0
- package/dist/deletion.model.js +10 -0
- package/dist/deletion.model.js.map +1 -0
- package/dist/git-hub-adapter.service.d.ts +20 -0
- package/dist/git-hub-adapter.service.js +139 -0
- package/dist/git-hub-adapter.service.js.map +1 -0
- package/dist/graphql-query-factory.service.d.ts +6 -0
- package/dist/graphql-query-factory.service.js +88 -0
- package/dist/graphql-query-factory.service.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +23 -0
- package/src/addition.model.ts +8 -0
- package/src/container.ts +20 -0
- package/src/content-entries-to-actions-converter.service.ts +37 -0
- package/src/deletion.model.ts +3 -0
- package/src/git-hub-adapter.service.ts +223 -0
- package/src/graphql-query-factory.service.ts +100 -0
- package/src/index.ts +16 -0
- package/tsconfig.json +22 -0
package/.prettierrc
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
All notable changes to this project will be documented in this file.
|
|
3
|
+
|
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [0.4.0] - 2023-05-12
|
|
8
|
+
### Changed
|
|
9
|
+
- Rename organization
|
|
10
|
+
|
|
11
|
+
## [0.3.2] - 2023-05-11
|
|
12
|
+
### Fixed
|
|
13
|
+
- [#3](https://github.com/commitspark/git-adapter-github/issues/3) Fix text content is not UTF-8 encoded when executing mutations
|
|
14
|
+
- Update `yaml` library to address [security advisory](https://github.com/advisories/GHSA-f9xv-q969-pqx4)
|
|
15
|
+
|
|
16
|
+
## [0.3.1] - 2023-05-06
|
|
17
|
+
### Fixed
|
|
18
|
+
- [#2](https://github.com/commitspark/git-adapter-github/issues/2) Fix error when querying repository without content entries
|
|
19
|
+
|
|
20
|
+
## [0.3.0] - 2023-04-28
|
|
21
|
+
### Changed
|
|
22
|
+
- Replace constructor use with object literals to prevent polluting DTOs with prototype function
|
|
23
|
+
- Update to Git Adapter interface 0.7.0
|
|
24
|
+
|
|
25
|
+
## [0.2.2] - 2023-03-15
|
|
26
|
+
### Changed
|
|
27
|
+
- Remove dependency injection package to support bundling with webpack & co.
|
|
28
|
+
- Upgrade dependencies
|
|
29
|
+
|
|
30
|
+
## [0.2.1] - 2023-03-12
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
- Throw exception when repository not found when retrieving commit hash
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
- Fix inadvertent use of HTTP cache for some requests
|
|
37
|
+
|
|
38
|
+
## [0.2.0] - 2022-12-13
|
|
39
|
+
|
|
40
|
+
### Added
|
|
41
|
+
- Expose schema file path and entries folder path as repository options
|
|
42
|
+
|
|
43
|
+
## [0.1.0] - 2022-11-04
|
|
44
|
+
|
|
45
|
+
### Added
|
|
46
|
+
- Initial release
|
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Markus Weiland
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Introduction
|
|
2
|
+
|
|
3
|
+
**[Commitspark](https://commitspark.com) is a workflow-first Content Management System based on Git and GraphQL.**
|
|
4
|
+
|
|
5
|
+
This repository holds code that implements access to Git repositories hosted on GitHub.
|
|
6
|
+
|
|
7
|
+
# Usage
|
|
8
|
+
|
|
9
|
+
Instantiate the adapter with `createAdapter()` and then call `setRepositoryOptions()` with `GitHubRepositoryOptions` on
|
|
10
|
+
the instance. These options are as follows:
|
|
11
|
+
|
|
12
|
+
| Option name | Required | Default value | Description |
|
|
13
|
+
|-----------------------|----------|-------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
14
|
+
| `repositoryOwner` | True | | GitHub repository owner, e.g. `commitspark` |
|
|
15
|
+
| `repositoryName` | True | | GitHub repository name, e.g. `git-adapter-github` |
|
|
16
|
+
| `personalAccessToken` | True | | GitHub [personal access token (classic)](https://docs.github.com/en/graphql/guides/forming-calls-with-graphql#authenticating-with-graphql) with at least `repo` scope |
|
|
17
|
+
| `pathSchemaFile` | False | `schema/schema.graphql` | Path to schema file in repository |
|
|
18
|
+
| `pathEntryFolder` | False | `entries/` | Path to folder for content entries |
|
|
19
|
+
|
|
20
|
+
# License
|
|
21
|
+
|
|
22
|
+
The code in this repository is licensed under the permissive ISC license (see [LICENSE](LICENSE)).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AdditionModel = void 0;
|
|
4
|
+
const buffer_1 = require("buffer");
|
|
5
|
+
class AdditionModel {
|
|
6
|
+
constructor(path, contents) {
|
|
7
|
+
this.path = path;
|
|
8
|
+
this.contents = buffer_1.Buffer.from(contents, 'utf8').toString('base64');
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.AdditionModel = AdditionModel;
|
|
12
|
+
//# sourceMappingURL=addition.model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addition.model.js","sourceRoot":"","sources":["../src/addition.model.ts"],"names":[],"mappings":";;;AAAA,mCAA+B;AAE/B,MAAa,aAAa;IAExB,YAAqB,IAAY,EAAE,QAAgB;QAA9B,SAAI,GAAJ,IAAI,CAAQ;QAC/B,IAAI,CAAC,QAAQ,GAAG,eAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAClE,CAAC;CACF;AALD,sCAKC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.gitHubAdapterService = void 0;
|
|
7
|
+
const content_entries_to_actions_converter_service_1 = require("./content-entries-to-actions-converter.service");
|
|
8
|
+
const git_hub_adapter_service_1 = require("./git-hub-adapter.service");
|
|
9
|
+
const graphql_query_factory_service_1 = require("./graphql-query-factory.service");
|
|
10
|
+
const axios_1 = __importDefault(require("axios"));
|
|
11
|
+
const axios_cache_interceptor_1 = require("axios-cache-interceptor");
|
|
12
|
+
const cachedHttpAdapter = (0, axios_cache_interceptor_1.setupCache)(axios_1.default.create(), {
|
|
13
|
+
ttl: git_hub_adapter_service_1.GitHubAdapterService.QUERY_CACHE_SECONDS * 1000,
|
|
14
|
+
methods: ['get', 'post'],
|
|
15
|
+
});
|
|
16
|
+
const graphqlQueryFactoryService = new graphql_query_factory_service_1.GraphqlQueryFactoryService();
|
|
17
|
+
const contentEntriesToActionsConverterService = new content_entries_to_actions_converter_service_1.ContentEntriesToActionsConverterService();
|
|
18
|
+
exports.gitHubAdapterService = new git_hub_adapter_service_1.GitHubAdapterService(cachedHttpAdapter, graphqlQueryFactoryService, contentEntriesToActionsConverterService);
|
|
19
|
+
//# sourceMappingURL=container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../src/container.ts"],"names":[],"mappings":";;;;;;AAAA,iHAAwG;AACxG,uEAAgE;AAChE,mFAA4E;AAC5E,kDAAyB;AACzB,qEAAoD;AAEpD,MAAM,iBAAiB,GAAG,IAAA,oCAAU,EAAC,eAAK,CAAC,MAAM,EAAE,EAAE;IACnD,GAAG,EAAE,8CAAoB,CAAC,mBAAmB,GAAG,IAAI;IACpD,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;CACzB,CAAC,CAAA;AAEF,MAAM,0BAA0B,GAAG,IAAI,0DAA0B,EAAE,CAAA;AACnE,MAAM,uCAAuC,GAC3C,IAAI,sFAAuC,EAAE,CAAA;AAElC,QAAA,oBAAoB,GAAG,IAAI,8CAAoB,CAC1D,iBAAiB,EACjB,0BAA0B,EAC1B,uCAAuC,CACxC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ContentEntryDraft } from '@commitspark/git-adapter';
|
|
2
|
+
import { AdditionModel } from './addition.model';
|
|
3
|
+
import { DeletionModel } from './deletion.model';
|
|
4
|
+
export declare class ContentEntriesToActionsConverterService {
|
|
5
|
+
convert(contentEntries: ContentEntryDraft[], pathEntryFolder: string): {
|
|
6
|
+
additions: AdditionModel[];
|
|
7
|
+
deletions: DeletionModel[];
|
|
8
|
+
};
|
|
9
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContentEntriesToActionsConverterService = void 0;
|
|
4
|
+
const git_adapter_1 = require("@commitspark/git-adapter");
|
|
5
|
+
const yaml_1 = require("yaml");
|
|
6
|
+
const addition_model_1 = require("./addition.model");
|
|
7
|
+
const deletion_model_1 = require("./deletion.model");
|
|
8
|
+
class ContentEntriesToActionsConverterService {
|
|
9
|
+
convert(contentEntries, pathEntryFolder) {
|
|
10
|
+
const additions = [];
|
|
11
|
+
const deletions = [];
|
|
12
|
+
contentEntries.forEach((contentEntry) => {
|
|
13
|
+
const entryPath = `${pathEntryFolder}/${contentEntry.id}${git_adapter_1.ENTRY_EXTENSION}`;
|
|
14
|
+
if (contentEntry.deletion) {
|
|
15
|
+
deletions.push(new deletion_model_1.DeletionModel(entryPath));
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
additions.push(new addition_model_1.AdditionModel(entryPath, (0, yaml_1.stringify)({
|
|
19
|
+
metadata: contentEntry.metadata,
|
|
20
|
+
data: contentEntry.data,
|
|
21
|
+
})));
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
additions,
|
|
26
|
+
deletions,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ContentEntriesToActionsConverterService = ContentEntriesToActionsConverterService;
|
|
31
|
+
//# sourceMappingURL=content-entries-to-actions-converter.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-entries-to-actions-converter.service.js","sourceRoot":"","sources":["../src/content-entries-to-actions-converter.service.ts"],"names":[],"mappings":";;;AAAA,0DAA6E;AAC7E,+BAAgC;AAChC,qDAAgD;AAChD,qDAAgD;AAEhD,MAAa,uCAAuC;IAClD,OAAO,CACL,cAAmC,EACnC,eAAuB;QAKvB,MAAM,SAAS,GAAoB,EAAE,CAAA;QACrC,MAAM,SAAS,GAAoB,EAAE,CAAA;QACrC,cAAc,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,EAAE;YACtC,MAAM,SAAS,GAAG,GAAG,eAAe,IAAI,YAAY,CAAC,EAAE,GAAG,6BAAe,EAAE,CAAA;YAC3E,IAAI,YAAY,CAAC,QAAQ,EAAE;gBACzB,SAAS,CAAC,IAAI,CAAC,IAAI,8BAAa,CAAC,SAAS,CAAC,CAAC,CAAA;aAC7C;iBAAM;gBACL,SAAS,CAAC,IAAI,CACZ,IAAI,8BAAa,CACf,SAAS,EACT,IAAA,gBAAS,EAAC;oBACR,QAAQ,EAAE,YAAY,CAAC,QAAQ;oBAC/B,IAAI,EAAE,YAAY,CAAC,IAAI;iBACxB,CAAC,CACH,CACF,CAAA;aACF;QACH,CAAC,CAAC,CAAA;QACF,OAAO;YACL,SAAS;YACT,SAAS;SACV,CAAA;IACH,CAAC;CACF;AA/BD,0FA+BC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeletionModel = void 0;
|
|
4
|
+
class DeletionModel {
|
|
5
|
+
constructor(path) {
|
|
6
|
+
this.path = path;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.DeletionModel = DeletionModel;
|
|
10
|
+
//# sourceMappingURL=deletion.model.js.map
|
|
@@ -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,20 @@
|
|
|
1
|
+
import { GraphqlQueryFactoryService } from './graphql-query-factory.service';
|
|
2
|
+
import { Commit, CommitDraft, ContentEntry, GitAdapter } from '@commitspark/git-adapter';
|
|
3
|
+
import { ContentEntriesToActionsConverterService } from './content-entries-to-actions-converter.service';
|
|
4
|
+
import { AxiosCacheInstance } from 'axios-cache-interceptor';
|
|
5
|
+
import { GitHubRepositoryOptions } from './index';
|
|
6
|
+
export declare class GitHubAdapterService implements GitAdapter {
|
|
7
|
+
private readonly cachedHttpAdapter;
|
|
8
|
+
private graphqlQueryFactory;
|
|
9
|
+
private contentEntriesToActionsConverter;
|
|
10
|
+
static readonly QUERY_CACHE_SECONDS: number;
|
|
11
|
+
static readonly API_URL = "https://api.github.com/graphql";
|
|
12
|
+
private gitRepositoryOptions;
|
|
13
|
+
constructor(cachedHttpAdapter: AxiosCacheInstance, graphqlQueryFactory: GraphqlQueryFactoryService, contentEntriesToActionsConverter: ContentEntriesToActionsConverterService);
|
|
14
|
+
setRepositoryOptions(repositoryOptions: GitHubRepositoryOptions): Promise<void>;
|
|
15
|
+
getContentEntries(commitHash: string): Promise<ContentEntry[]>;
|
|
16
|
+
getSchema(commitHash: string): Promise<string>;
|
|
17
|
+
getLatestCommitHash(ref: string): Promise<string>;
|
|
18
|
+
createCommit(commitDraft: CommitDraft): Promise<Commit>;
|
|
19
|
+
private getPathEntryFolder;
|
|
20
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GitHubAdapterService = void 0;
|
|
4
|
+
const git_adapter_1 = require("@commitspark/git-adapter");
|
|
5
|
+
const yaml_1 = require("yaml");
|
|
6
|
+
class GitHubAdapterService {
|
|
7
|
+
constructor(cachedHttpAdapter, graphqlQueryFactory, contentEntriesToActionsConverter) {
|
|
8
|
+
this.cachedHttpAdapter = cachedHttpAdapter;
|
|
9
|
+
this.graphqlQueryFactory = graphqlQueryFactory;
|
|
10
|
+
this.contentEntriesToActionsConverter = contentEntriesToActionsConverter;
|
|
11
|
+
}
|
|
12
|
+
async setRepositoryOptions(repositoryOptions) {
|
|
13
|
+
this.gitRepositoryOptions = repositoryOptions;
|
|
14
|
+
}
|
|
15
|
+
async getContentEntries(commitHash) {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
if (this.gitRepositoryOptions === undefined) {
|
|
18
|
+
throw new Error('Repository options must be set before reading');
|
|
19
|
+
}
|
|
20
|
+
const token = this.gitRepositoryOptions.personalAccessToken;
|
|
21
|
+
const pathEntryFolder = this.getPathEntryFolder(this.gitRepositoryOptions);
|
|
22
|
+
const queryFilesContent = this.graphqlQueryFactory.createBlobsContentQuery(this.gitRepositoryOptions.repositoryOwner, this.gitRepositoryOptions.repositoryName, commitHash, pathEntryFolder);
|
|
23
|
+
const filesContentResponse = await this.cachedHttpAdapter.post(GitHubAdapterService.API_URL, {
|
|
24
|
+
query: queryFilesContent,
|
|
25
|
+
}, {
|
|
26
|
+
headers: {
|
|
27
|
+
authorization: `Bearer ${token}`,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const extensionLength = git_adapter_1.ENTRY_EXTENSION.length;
|
|
31
|
+
if (!((_b = (_a = filesContentResponse.data.data.repository) === null || _a === void 0 ? void 0 : _a.object) === null || _b === void 0 ? void 0 : _b.entries)) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
return filesContentResponse.data.data.repository.object.entries
|
|
35
|
+
.filter((entry) => entry.name.endsWith(git_adapter_1.ENTRY_EXTENSION))
|
|
36
|
+
.map((entry) => {
|
|
37
|
+
const content = (0, yaml_1.parse)(entry.object.text);
|
|
38
|
+
const id = entry.name.substring(0, entry.name.length - extensionLength);
|
|
39
|
+
return {
|
|
40
|
+
id: id,
|
|
41
|
+
metadata: content.metadata,
|
|
42
|
+
data: content.data,
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async getSchema(commitHash) {
|
|
47
|
+
var _a, _b, _c, _d, _e;
|
|
48
|
+
if (this.gitRepositoryOptions === undefined) {
|
|
49
|
+
throw new Error('Repository options must be set before reading');
|
|
50
|
+
}
|
|
51
|
+
const repositoryOwner = this.gitRepositoryOptions.repositoryOwner;
|
|
52
|
+
const repositoryName = this.gitRepositoryOptions.repositoryName;
|
|
53
|
+
const token = this.gitRepositoryOptions.personalAccessToken;
|
|
54
|
+
const schemaFilePath = (_a = this.gitRepositoryOptions.pathSchemaFile) !== null && _a !== void 0 ? _a : git_adapter_1.PATH_SCHEMA_FILE;
|
|
55
|
+
const queryContent = this.graphqlQueryFactory.createBlobContentQuery(repositoryOwner, repositoryName, commitHash, schemaFilePath);
|
|
56
|
+
const response = await this.cachedHttpAdapter.post(GitHubAdapterService.API_URL, {
|
|
57
|
+
query: queryContent,
|
|
58
|
+
}, {
|
|
59
|
+
headers: {
|
|
60
|
+
authorization: `Bearer ${token}`,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
const schema = (_e = (_d = (_c = (_b = response.data) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.repository) === null || _d === void 0 ? void 0 : _d.object) === null || _e === void 0 ? void 0 : _e.text;
|
|
64
|
+
if (!schema) {
|
|
65
|
+
throw new Error(`"${schemaFilePath}" not found in Git repository "${repositoryOwner}/${repositoryName}" at commit "${commitHash}"`);
|
|
66
|
+
}
|
|
67
|
+
return schema;
|
|
68
|
+
}
|
|
69
|
+
async getLatestCommitHash(ref) {
|
|
70
|
+
var _a, _b, _c, _d, _e;
|
|
71
|
+
if (this.gitRepositoryOptions === undefined) {
|
|
72
|
+
throw new Error('Repository options must be set before reading');
|
|
73
|
+
}
|
|
74
|
+
const token = this.gitRepositoryOptions.personalAccessToken;
|
|
75
|
+
const queryLatestCommit = this.graphqlQueryFactory.createLatestCommitQuery(this.gitRepositoryOptions.repositoryOwner, this.gitRepositoryOptions.repositoryName, ref);
|
|
76
|
+
const response = await this.cachedHttpAdapter.post(GitHubAdapterService.API_URL, {
|
|
77
|
+
query: queryLatestCommit,
|
|
78
|
+
}, {
|
|
79
|
+
cache: false,
|
|
80
|
+
headers: {
|
|
81
|
+
authorization: `Bearer ${token}`,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
if (!response.data.data.repository) {
|
|
85
|
+
throw new Error(`No repository found "${this.gitRepositoryOptions.repositoryOwner}/${this.gitRepositoryOptions.repositoryName}"`);
|
|
86
|
+
}
|
|
87
|
+
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
|
+
if (!lastCommit) {
|
|
89
|
+
throw new Error(`No commit found for ref "${ref}"`);
|
|
90
|
+
}
|
|
91
|
+
return lastCommit;
|
|
92
|
+
}
|
|
93
|
+
async createCommit(commitDraft) {
|
|
94
|
+
var _a;
|
|
95
|
+
if (this.gitRepositoryOptions === undefined) {
|
|
96
|
+
throw new Error('Repository options must be set before committing');
|
|
97
|
+
}
|
|
98
|
+
const token = this.gitRepositoryOptions.personalAccessToken;
|
|
99
|
+
const pathEntryFolder = this.getPathEntryFolder(this.gitRepositoryOptions);
|
|
100
|
+
const { additions, deletions } = this.contentEntriesToActionsConverter.convert(commitDraft.contentEntries, pathEntryFolder);
|
|
101
|
+
const mutateCommit = this.graphqlQueryFactory.createCommitMutation();
|
|
102
|
+
const response = await this.cachedHttpAdapter.post(GitHubAdapterService.API_URL, {
|
|
103
|
+
query: mutateCommit,
|
|
104
|
+
variables: {
|
|
105
|
+
repositoryNameWithOwner: `${this.gitRepositoryOptions.repositoryOwner}/${this.gitRepositoryOptions.repositoryName}`,
|
|
106
|
+
branchName: commitDraft.ref,
|
|
107
|
+
commitMessage: (_a = commitDraft.message) !== null && _a !== void 0 ? _a : '-',
|
|
108
|
+
precedingCommitSha: commitDraft.parentSha,
|
|
109
|
+
additions: additions,
|
|
110
|
+
deletions: deletions,
|
|
111
|
+
},
|
|
112
|
+
}, {
|
|
113
|
+
cache: false,
|
|
114
|
+
headers: {
|
|
115
|
+
authorization: `Bearer ${token}`,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
if (response.data.errors) {
|
|
119
|
+
throw new Error(JSON.stringify(response.data.errors));
|
|
120
|
+
}
|
|
121
|
+
const mutationResult = response.data.data.commitCreate;
|
|
122
|
+
if (mutationResult.errors) {
|
|
123
|
+
throw new Error(JSON.stringify(mutationResult.errors));
|
|
124
|
+
}
|
|
125
|
+
return { ref: mutationResult.commit.oid };
|
|
126
|
+
}
|
|
127
|
+
getPathEntryFolder(gitRepositoryOptions) {
|
|
128
|
+
var _a;
|
|
129
|
+
const pathEntryFolder = (_a = gitRepositoryOptions.pathEntryFolder) !== null && _a !== void 0 ? _a : git_adapter_1.PATH_ENTRY_FOLDER;
|
|
130
|
+
if (pathEntryFolder.endsWith('/')) {
|
|
131
|
+
return pathEntryFolder.substring(0, pathEntryFolder.length - 1);
|
|
132
|
+
}
|
|
133
|
+
return pathEntryFolder;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.GitHubAdapterService = GitHubAdapterService;
|
|
137
|
+
GitHubAdapterService.QUERY_CACHE_SECONDS = 10 * 60;
|
|
138
|
+
GitHubAdapterService.API_URL = 'https://api.github.com/graphql';
|
|
139
|
+
//# sourceMappingURL=git-hub-adapter.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-hub-adapter.service.js","sourceRoot":"","sources":["../src/git-hub-adapter.service.ts"],"names":[],"mappings":";;;AACA,0DAQiC;AAEjC,+BAA4B;AAI5B,MAAa,oBAAoB;IAO/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Z,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,KAAK,EAAE;aACjC;SACF,CACF,CAAA;QAED,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE;YACxB,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;SACtD;QAED,MAAM,cAAc,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAA;QAEtD,IAAI,cAAc,CAAC,MAAM,EAAE;YACzB,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAA;SACvD;QAED,OAAO,EAAE,GAAG,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,EAAE,CAAA;IAC3C,CAAC;IAEO,kBAAkB,CACxB,oBAA6C;;QAE7C,MAAM,eAAe,GACnB,MAAA,oBAAoB,CAAC,eAAe,mCAAI,+BAAiB,CAAA;QAE3D,IAAI,eAAe,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACjC,OAAO,eAAe,CAAC,SAAS,CAAC,CAAC,EAAE,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;SAChE;QAED,OAAO,eAAe,CAAA;IACxB,CAAC;;AA9MH,oDA+MC;AA9MiB,wCAAmB,GAAG,EAAE,GAAG,EAAE,CAAA;AAE7B,4BAAO,GAAG,gCAAgC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare class GraphqlQueryFactoryService {
|
|
2
|
+
createBlobsContentQuery(repositoryOwner: string, repositoryName: string, ref: string, path: string): string;
|
|
3
|
+
createBlobContentQuery(repositoryOwner: string, repositoryName: string, ref: string, schemaFilePath: string): string;
|
|
4
|
+
createCommitMutation(): string;
|
|
5
|
+
createLatestCommitQuery(repositoryOwner: string, repositoryName: string, ref: string): string;
|
|
6
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphqlQueryFactoryService = void 0;
|
|
4
|
+
class GraphqlQueryFactoryService {
|
|
5
|
+
createBlobsContentQuery(repositoryOwner, repositoryName, ref, path) {
|
|
6
|
+
return `
|
|
7
|
+
query {
|
|
8
|
+
repository(owner:"${repositoryOwner}", name:"${repositoryName}") {
|
|
9
|
+
object(expression:"${ref}:${path}") {
|
|
10
|
+
... on Tree {
|
|
11
|
+
entries {
|
|
12
|
+
name
|
|
13
|
+
object {
|
|
14
|
+
... on Blob {
|
|
15
|
+
text
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
}
|
|
25
|
+
createBlobContentQuery(repositoryOwner, repositoryName, ref, schemaFilePath) {
|
|
26
|
+
return `
|
|
27
|
+
query {
|
|
28
|
+
repository(owner:"${repositoryOwner}", name:"${repositoryName}") {
|
|
29
|
+
object(expression:"${ref}:${schemaFilePath}") {
|
|
30
|
+
... on Blob {
|
|
31
|
+
text
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
}
|
|
38
|
+
createCommitMutation() {
|
|
39
|
+
return `
|
|
40
|
+
mutation (
|
|
41
|
+
$repositoryNameWithOwner:String!,
|
|
42
|
+
$branchName:String!,
|
|
43
|
+
$commitMessage:String!,
|
|
44
|
+
$precedingCommitSha:GitObjectID!,
|
|
45
|
+
$additions:[FileAddition!],
|
|
46
|
+
$deletions:[FileDeletion!]
|
|
47
|
+
) {
|
|
48
|
+
commitCreate: createCommitOnBranch(input:{
|
|
49
|
+
branch:{
|
|
50
|
+
repositoryNameWithOwner:$repositoryNameWithOwner
|
|
51
|
+
branchName:$branchName
|
|
52
|
+
}
|
|
53
|
+
message: {
|
|
54
|
+
headline:$commitMessage
|
|
55
|
+
body:""
|
|
56
|
+
}
|
|
57
|
+
expectedHeadOid:$precedingCommitSha
|
|
58
|
+
fileChanges:{
|
|
59
|
+
additions:$additions
|
|
60
|
+
deletions:$deletions
|
|
61
|
+
}
|
|
62
|
+
}) {
|
|
63
|
+
commit {
|
|
64
|
+
oid
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
`;
|
|
69
|
+
}
|
|
70
|
+
createLatestCommitQuery(repositoryOwner, repositoryName, ref) {
|
|
71
|
+
return `
|
|
72
|
+
query Content {
|
|
73
|
+
repository(owner:"${repositoryOwner}", name:"${repositoryName}") {
|
|
74
|
+
ref(qualifiedName:"${ref}") {
|
|
75
|
+
target {
|
|
76
|
+
oid
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
object(expression:"${ref}") {
|
|
80
|
+
oid
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.GraphqlQueryFactoryService = GraphqlQueryFactoryService;
|
|
88
|
+
//# sourceMappingURL=graphql-query-factory.service.js.map
|
|
@@ -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,CAC5B,eAAuB,EACvB,cAAsB,EACtB,GAAW,EACX,IAAY;QAEZ,OAAO;;4BAEiB,eAAe,YAAY,cAAc;+BACtC,GAAG,IAAI,IAAI;;;;;;;;;;;;;;KAcrC,CAAA;IACH,CAAC;IAEM,sBAAsB,CAC3B,eAAuB,EACvB,cAAsB,EACtB,GAAW,EACX,cAAsB;QAEtB,OAAO;;4BAEiB,eAAe,YAAY,cAAc;+BACtC,GAAG,IAAI,cAAc;;;;;;;KAO/C,CAAA;IACH,CAAC;IAEM,oBAAoB;QACzB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA6BN,CAAA;IACH,CAAC;IAEM,uBAAuB,CAC5B,eAAuB,EACvB,cAAsB,EACtB,GAAW;QAEX,OAAO;;4BAEiB,eAAe,YAAY,cAAc;+BACtC,GAAG;;;;;+BAKH,GAAG;;;;;KAK7B,CAAA;IACH,CAAC;CACF;AAnGD,gEAmGC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GitAdapter, GitRepositoryOptions } from '@commitspark/git-adapter';
|
|
2
|
+
export { GitHubAdapterService } from './git-hub-adapter.service';
|
|
3
|
+
export interface GitHubRepositoryOptions extends GitRepositoryOptions {
|
|
4
|
+
repositoryOwner: string;
|
|
5
|
+
repositoryName: string;
|
|
6
|
+
personalAccessToken: string;
|
|
7
|
+
pathSchemaFile?: string;
|
|
8
|
+
pathEntryFolder?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createAdapter(): GitAdapter;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAdapter = exports.GitHubAdapterService = void 0;
|
|
4
|
+
const container_1 = require("./container");
|
|
5
|
+
var git_hub_adapter_service_1 = require("./git-hub-adapter.service");
|
|
6
|
+
Object.defineProperty(exports, "GitHubAdapterService", { enumerable: true, get: function () { return git_hub_adapter_service_1.GitHubAdapterService; } });
|
|
7
|
+
function createAdapter() {
|
|
8
|
+
return container_1.gitHubAdapterService;
|
|
9
|
+
}
|
|
10
|
+
exports.createAdapter = createAdapter;
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,2CAAkD;AAElD,qEAAgE;AAAvD,+HAAA,oBAAoB,OAAA;AAU7B,SAAgB,aAAa;IAC3B,OAAO,gCAAoB,CAAA;AAC7B,CAAC;AAFD,sCAEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"program":{"fileNames":["../node_modules/typescript/lib/lib.es5.d.ts","../node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/typescript/lib/lib.dom.d.ts","../node_modules/typescript/lib/lib.dom.iterable.d.ts","../node_modules/typescript/lib/lib.webworker.importscripts.d.ts","../node_modules/typescript/lib/lib.scripthost.d.ts","../node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/typescript/lib/lib.es2017.full.d.ts","../node_modules/buffer/index.d.ts","../src/addition.model.ts","../node_modules/@commitspark/git-adapter/dist/model/content-entry-metadata.d.ts","../node_modules/@commitspark/git-adapter/dist/model/content-entry.d.ts","../node_modules/@commitspark/git-adapter/dist/model/content-entry-draft.d.ts","../node_modules/@commitspark/git-adapter/dist/model/commit-draft.d.ts","../node_modules/@commitspark/git-adapter/dist/model/commit.d.ts","../node_modules/@commitspark/git-adapter/dist/git-adapter.d.ts","../node_modules/@commitspark/git-adapter/dist/index.d.ts","../node_modules/yaml/dist/parse/line-counter.d.ts","../node_modules/yaml/dist/errors.d.ts","../node_modules/yaml/dist/doc/applyReviver.d.ts","../node_modules/yaml/dist/log.d.ts","../node_modules/yaml/dist/nodes/toJS.d.ts","../node_modules/yaml/dist/nodes/Scalar.d.ts","../node_modules/yaml/dist/nodes/Collection.d.ts","../node_modules/yaml/dist/nodes/YAMLMap.d.ts","../node_modules/yaml/dist/nodes/YAMLSeq.d.ts","../node_modules/yaml/dist/schema/types.d.ts","../node_modules/yaml/dist/schema/Schema.d.ts","../node_modules/yaml/dist/doc/createNode.d.ts","../node_modules/yaml/dist/nodes/addPairToJSMap.d.ts","../node_modules/yaml/dist/nodes/Pair.d.ts","../node_modules/yaml/dist/schema/tags.d.ts","../node_modules/yaml/dist/options.d.ts","../node_modules/yaml/dist/stringify/stringify.d.ts","../node_modules/yaml/dist/nodes/Node.d.ts","../node_modules/yaml/dist/parse/cst-scalar.d.ts","../node_modules/yaml/dist/parse/cst-stringify.d.ts","../node_modules/yaml/dist/parse/cst-visit.d.ts","../node_modules/yaml/dist/parse/cst.d.ts","../node_modules/yaml/dist/nodes/Alias.d.ts","../node_modules/yaml/dist/doc/Document.d.ts","../node_modules/yaml/dist/doc/directives.d.ts","../node_modules/yaml/dist/compose/composer.d.ts","../node_modules/yaml/dist/parse/lexer.d.ts","../node_modules/yaml/dist/parse/parser.d.ts","../node_modules/yaml/dist/public-api.d.ts","../node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts","../node_modules/yaml/dist/schema/yaml-1.1/set.d.ts","../node_modules/yaml/dist/visit.d.ts","../node_modules/yaml/dist/index.d.ts","../src/deletion.model.ts","../src/content-entries-to-actions-converter.service.ts","../src/graphql-query-factory.service.ts","../node_modules/axios/index.d.ts","../node_modules/fast-defer/dist/deferred.d.ts","../node_modules/fast-defer/dist/create-deferred.d.ts","../node_modules/fast-defer/dist/is-deferred.d.ts","../node_modules/fast-defer/dist/index.d.ts","../node_modules/axios-cache-interceptor/dist/header/types.d.ts","../node_modules/axios-cache-interceptor/dist/interceptors/build.d.ts","../node_modules/axios-cache-interceptor/dist/util/types.d.ts","../node_modules/axios-cache-interceptor/dist/storage/types.d.ts","../node_modules/axios-cache-interceptor/dist/cache/cache.d.ts","../node_modules/axios-cache-interceptor/dist/cache/axios.d.ts","../node_modules/axios-cache-interceptor/dist/cache/create.d.ts","../node_modules/axios-cache-interceptor/dist/header/headers.d.ts","../node_modules/axios-cache-interceptor/dist/header/interpreter.d.ts","../node_modules/axios-cache-interceptor/dist/interceptors/request.d.ts","../node_modules/axios-cache-interceptor/dist/interceptors/response.d.ts","../node_modules/axios-cache-interceptor/dist/interceptors/util.d.ts","../node_modules/axios-cache-interceptor/dist/storage/build.d.ts","../node_modules/axios-cache-interceptor/dist/storage/memory.d.ts","../node_modules/axios-cache-interceptor/dist/storage/web-api.d.ts","../node_modules/axios-cache-interceptor/dist/util/cache-predicate.d.ts","../node_modules/axios-cache-interceptor/dist/util/key-generator.d.ts","../node_modules/axios-cache-interceptor/dist/util/update-cache.d.ts","../node_modules/axios-cache-interceptor/dist/index.d.ts","../src/index.ts","../src/git-hub-adapter.service.ts","../src/container.ts"],"fileInfos":[{"version":"f20c05dbfe50a208301d2a1da37b9931bce0466eb5a1f4fe240971b4ecc82b67","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9",{"version":"9b087de7268e4efc5f215347a62656663933d63c0b1d7b624913240367b999ea","affectsGlobalScope":true},{"version":"3260e3386d9535b804205bdddb5618a9a27735bd22927f48ad54363abcd23d45","affectsGlobalScope":true},{"version":"7fac8cb5fc820bc2a59ae11ef1c5b38d3832c6d0dfaec5acdb5569137d09a481","affectsGlobalScope":true},{"version":"097a57355ded99c68e6df1b738990448e0bf170e606707df5a7c0481ff2427cd","affectsGlobalScope":true},{"version":"adb996790133eb33b33aadb9c09f15c2c575e71fb57a62de8bf74dbf59ec7dfb","affectsGlobalScope":true},{"version":"8cc8c5a3bac513368b0157f3d8b31cfdcfe78b56d3724f30f80ed9715e404af8","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"c5c05907c02476e4bde6b7e76a79ffcd948aedd14b6a8f56e4674221b0417398","affectsGlobalScope":true},{"version":"0d5f52b3174bee6edb81260ebcd792692c32c81fd55499d69531496f3f2b25e7","affectsGlobalScope":true},{"version":"55f400eec64d17e888e278f4def2f254b41b89515d3b88ad75d5e05f019daddd","affectsGlobalScope":true},{"version":"181f1784c6c10b751631b24ce60c7f78b20665db4550b335be179217bacc0d5f","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"81cac4cbc92c0c839c70f8ffb94eb61e2d32dc1c3cf6d95844ca099463cf37ea","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},"d2f31f19e1ba6ed59be9259d660a239d9a3fcbbc8e038c6b2009bde34b175fed","4967529644e391115ca5592184d4b63980569adf60ee685f968fd59ab1557188",{"version":"29a2385d4cdc2e78aeced2cd0f66b06eef95dbbeb0e4f09c61a017ba859efabe","signature":"89b04f42a9291feb49cfac8dc5b99e792bdde7462097d217b3f8318127ad8bd2"},"3525e7fa64365bf44ba82bf79b13a10ce1e78b3a92cb22fd98377e4663dcf7da","a0bdd2fd60487e6233d39964606158ac12a931bf8fde64ca1a3d816f306d8b86","2b3e9d284e89738cc7e256be71923592720ae463fb5488206482633acc27f18b","888e6eb5d13e636bdbe51357ce34fa7a14e41ebb3442944e0e7a31c02cf13d2c","fdf1c0f508657d404ee8a65540f71610ca29645e38c9175df70c05b6293affdb","d6f31277f878e17d6e02d24a27cfe3f57db08ef417e3542070154e11ac44c12f","ba3ce8962a91b70735056413855d6b08150b775bef48a9b0eed857e6162db6a0","3dfcd0a3bfa70b53135db3cf2e4ddcb7eccc3e4418ce833ae24eecd06928328f","b26f93d773cf3aa4dc421c45323adccaead92598594a56f4a84d77910ee4f510","bc41a8e33caf4d193b0c49ec70d1e8db5ce3312eafe5447c6c1d5a2084fece12","7c33f11a56ba4e79efc4ddae85f8a4a888e216d2bf66c863f344d403437ffc74","2bb86e343b4109c784b11070735fa881af5c870a409a3b87b13800ca2afef421","fc9d4e784c9e7569911d8a6a01e1de90617942639c7c260beffdef1548b1ce06","37c1aeea4ec8df37bbe5d96bda46831acab3f70b2001ec9f51cb3146a101de89","5ac83af1a323158abc8627462fe987f7c67f957f88cdcf2237ae4dddc26677a8","df486e591f21d229d75df323fb9cf34f4b5cdbccee6a9b42227be738a13755d6","69ebf923204206eecef4310dc8bf28ab07feddaa3542066cdafbe67adf45f811","ae8189514ed306971ac9aa7d917487ee51dc3590aa5735f23c1d71811c373ea6","6de9d8858034d3197c1525e1c29c942cf7912f807d4d7f14dea247b7c05b59b0","394b4927dcc6eda44eb759f395da17b6e07f4daf272216b5cfc92eb32239f561","1adcc285d2d477ec6c51d0282d891fdf9d04a5fa8dfa479eab153ae17376f1b4","0ad294cdc42fb1f99cc94db8f77364ddc516643d9c69d4e66942f2cfd783213b","3956f34170e48abf902bc81055fb35a7e8b87109dbf3ca272d096d6d42cf7b84","f3acf8cff186f71a3a9b2da63f1378de6fe68a8578cb47d097776143cc84cd7d","1db170e5dad144b639ddf3d32710491c583f48c6e522580c8d5a8c249a611338","960923ce078ecfef6e5c34468cdba5c552b064c0db7cb0fdd3eafd1bb9d3d7e9","42f034630b3a866d4a88b37cf0f8357b36af2f7298b319d536b7413ba99f979b","33d1d46d7789bebdf9b78cd54f39022aad5d7d1d03a58bdad4fe98658acfef06","b3956ba310c0bcd45b1c77455a9754a35b49642be91bfbb412e04d378fad83a1","052854468e3d8142f440fa9a0da1d743abef903dff09597025d07703c25b601e","284147c679272283a4bea7ccaecbbab198bb1854e19269b2e59d4b5cedd5894a","325994b6f6c7598c73bbd0294bf1e3f1e229772669b3c8a08fe3170442f600b8","581656e45b2555b764e2880a39859e25ac6c0c9a74cff83dd22d3859b2231982","843563f951d16e850a0be806010f630a4a71f0a55810bb9aced67c6d7774bf2f","9af1c478e5403b39b922df9132d779bc6e1ef88cafec17fcecf26356d90ecbd6","a95a6135f2d195c93d930ba01049c33579328e55612477c0ae5652429d3974ad","24ead5861f4400218aeaafa477082022f244e3df46d18831411f3a47fc3ff515","65ce9342063fcf793e7baea7526a5a9a2f6ce05dea0cf4ae726d02eae2b98fa3","b932682e049f41e294a3429aca3b0adb4d2eed8047b4c22f91565e9353d6940c","5a1755f317ac2c0d708fbf7c1dbf076ba3a31f624c534b44275c9c43033fdc2e",{"version":"2c96494b4ab2834248a1c71e0798e39a1754b57e3d5bdc87a2c15f8748f0fddd","signature":"c326042e25ba027385f0501a483ca939438bec254481190c4f3a26498b2da588"},{"version":"376dfde1b187f4e8494b87dfb2f5fab5ffea6fee37452751d3f98baed9d35e12","signature":"6f05188756ad21b77a4f6c0d3f5555fe236453336ccf8d1981d5a6c82151df3c"},{"version":"45ba73b236e68daa78ea25abc3d32a4a7012a77dd30dfb29737f01abb9a2ac7a","signature":"dbdf71f5d1394688e12a75a26640d2b9ccec310af4b4fa3167ceb9b4fb4d8a7c"},"17affcd8cc646e7f05e4b96d325b893d22542dd2c2c63ead572ca1bea346ebc9","20cfd3f265de121245f4e303186d4f9ac99694b5165059d43c92bf494e368fcb","32d782ffe891896f5507e5c0a459335a909085b0bd5d01f665217ac88e39061d","7843485677d4ecddf4c4a9af063bb174704c2524b89cc9baf31acba340cf5883","17035f33da424f147f9b71a485bcedc69259fa57da28d6b47d303270a56ae586","d1c5ae708ca53712e7f761aa5aef56613cea2a12649ba236d8e01a38158f20a1","0d874f837f0e757b7430cda012c2449f028d885857ab6bfb9260cb504f3dc526","08d5d34963c74cb25debac21053d4da99869447ac20d391348c8f614ed8c9125","8de0643adef9da014f2de936aa5bb26df21b5fa86fc5457c71fa8622369a7d82","0738e4b13b9c4f30e3b24866a6c450afe4b50ccd8285c865c0b1ba778160cf86","0d40edf4cd60571d4b61972768efc4832748a1d0370c96cec59fca22461f6f49","0dcc2de7ff7064735fa2619f142c6c3b182b8df27b3718f91dc0c12c2256252a","8698e5c166b98b0d75c0fb06553df6a27df69275b238fd3c4f3f534e03415523","b219d61f40f34e45a01f7c4cb3afac27e486b1672053ab7f9c8a5b2063ce95fb","e799e3e58dcefa1fbf7204883f0b5954055875287359289200da0b189420757f","e531dda5cfd2ca46af492cb98af92ecc0339f6f8c770d8d7afdf033b77d8fae6","86f0f8aa0aacb5f24a03922cfad0732c59dc703a52a38056229a6b373f47978f","9c963300aa9f0b8c0d61152d06d84a773a7f478b6c3e31c3678a3e81e974bb63","b856b895bdb28b396b5cf9b940c723de61afbf6dda0792afc9b716c5205d24ac","1be81084e824d6a9fc0fe5a9650998ff43548bce063d8bd265593ec3bc2ac3a0","e1c12ab2708279a56dc8cdb870647b384e6a60c1c056e7db87fd6071a92f438b","c0554fdfc7885397d22ad0a383575fd77e2cea5b1b59761bccd8b46c88bdd8dc","86f337397a07a8d851c6eda0de144eec0947501cd41b4ea4a301ab07b569b41f","c80d91e26836b6257433362adec238b0cf407b52944a5cf103d6149c997fa144",{"version":"97e4dc41c01c8112e10d5e5ecf7a4e8b0b618203218a4d7d33893d261012b717","signature":"6c23344ab224a6a6368c0c48f083a78d66cf871efa9138fd34a871c7af8b81e3"},{"version":"38f908a2c8d8dcad89352d7936dacce3dc4309bbcb8ad1a1093ecb6456955aed","signature":"9dbbd581ce4d65daca526671630c7cc414819fe78e19a6147a735dc0a5d20c5e"},{"version":"4e77900aa88e7f135bf37dd4cf757ad2c9f744466a3b06fb07892ff3bd025cea","signature":"a0743ad1a06bff9fbd877124d3f6ecd9241c1e083bb81bb81a3c02d79a3789ab"}],"options":{"allowSyntheticDefaultImports":true,"declaration":true,"emitDecoratorMetadata":true,"esModuleInterop":true,"experimentalDecorators":true,"module":1,"outDir":"./","removeComments":true,"skipLibCheck":true,"sourceMap":true,"strict":true,"target":4},"fileIdsList":[[28,30,31],[27,28,29,30,31,32],[29],[28],[27],[70,79],[70,74,75,76,77,78,80],[70,79,80],[75],[70],[75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92],[80],[76,80],[70,78,79,80],[77,78,80],[78],[70,77,80],[77,80],[78,80],[71],[71,72,73],[35,49,51,55,57,58],[35,39,41,42,44,47,49,51,56,58],[43,44,51,57],[57],[34],[34,35,39,41,42,43,44,47,48,49,51,55,56,57,59,60,61,62,63,64,65],[38,39,41,42,50,51,55,57],[44,51],[39,41,42,47,50,55,56,57],[38,39,41,42,44,45,46,50,51,55,56],[38,51,55],[38,39,40,44,47,50,51,55],[38,41,47],[50,51,57],[34,36,37,39,43,44,47,48,51,58],[35,39,51,55],[55],[52,53,54],[36,49,51,57,59],[43,47,49,51],[43,49],[39,41,42,44,45,49,50,51],[38,42,43,66],[38,39,41,43,44,47,50],[49,56,57],[39,41,42,47,51,56,57],[25],[68,69,70,93,95],[26,33,66,67],[33,66,68,69,93,94],[33,95,96],[95],[26,33,67],[33,68,69,93,94],[33,95]],"referencedMap":[[32,1],[33,2],[30,3],[29,4],[28,5],[80,6],[79,7],[81,8],[83,9],[75,10],[93,11],[76,12],[84,12],[85,13],[86,14],[87,15],[88,16],[78,17],[89,16],[90,18],[91,18],[77,19],[92,15],[72,20],[74,21],[73,20],[59,22],[57,23],[45,24],[58,25],[35,26],[66,27],[56,28],[40,29],[51,30],[47,31],[39,32],[41,33],[42,33],[46,34],[38,35],[49,36],[52,37],[53,38],[54,38],[55,39],[61,38],[62,40],[44,41],[48,42],[43,43],[63,44],[64,45],[50,46],[65,47],[26,48],[96,49],[68,50],[95,51],[94,52]],"exportedModulesMap":[[32,1],[33,2],[30,3],[29,4],[28,5],[80,6],[79,7],[81,8],[83,9],[75,10],[93,11],[76,12],[84,12],[85,13],[86,14],[87,15],[88,16],[78,17],[89,16],[90,18],[91,18],[77,19],[92,15],[72,20],[74,21],[73,20],[59,22],[57,23],[45,24],[58,25],[35,26],[66,27],[56,28],[40,29],[51,30],[47,31],[39,32],[41,33],[42,33],[46,34],[38,35],[49,36],[52,37],[53,38],[54,38],[55,39],[61,38],[62,40],[44,41],[48,42],[43,43],[63,44],[64,45],[50,46],[65,47],[96,53],[68,54],[95,55],[94,56]],"semanticDiagnosticsPerFile":[32,33,30,31,29,27,28,80,79,81,82,83,75,93,76,84,85,86,87,88,78,89,90,91,77,92,70,25,72,71,74,73,5,6,10,9,2,11,12,13,14,15,16,17,18,3,4,24,22,19,20,21,23,1,8,7,59,57,36,45,58,35,66,37,56,40,51,47,39,41,42,46,38,49,52,53,54,55,60,34,61,62,44,48,43,63,64,50,65,26,96,68,67,95,69,94]},"version":"4.8.4"}
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@commitspark/git-adapter-github",
|
|
3
|
+
"description": "Adapter that provides GitHub repository access to Commitspark",
|
|
4
|
+
"version": "0.4.0",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"private": false,
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@commitspark/git-adapter": "^0.8.0",
|
|
14
|
+
"axios": "^1.1.3",
|
|
15
|
+
"axios-cache-interceptor": "^0.10.7",
|
|
16
|
+
"buffer": "^6.0.3",
|
|
17
|
+
"yaml": "^2.1.1"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"prettier": "^2.7.1",
|
|
21
|
+
"typescript": "^4.8.4"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/container.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ContentEntriesToActionsConverterService } from './content-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
|
+
|
|
7
|
+
const cachedHttpAdapter = setupCache(axios.create(), {
|
|
8
|
+
ttl: GitHubAdapterService.QUERY_CACHE_SECONDS * 1000, // milliseconds
|
|
9
|
+
methods: ['get', 'post'],
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
const graphqlQueryFactoryService = new GraphqlQueryFactoryService()
|
|
13
|
+
const contentEntriesToActionsConverterService =
|
|
14
|
+
new ContentEntriesToActionsConverterService()
|
|
15
|
+
|
|
16
|
+
export const gitHubAdapterService = new GitHubAdapterService(
|
|
17
|
+
cachedHttpAdapter,
|
|
18
|
+
graphqlQueryFactoryService,
|
|
19
|
+
contentEntriesToActionsConverterService,
|
|
20
|
+
)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ContentEntryDraft, ENTRY_EXTENSION } from '@commitspark/git-adapter'
|
|
2
|
+
import { stringify } from 'yaml'
|
|
3
|
+
import { AdditionModel } from './addition.model'
|
|
4
|
+
import { DeletionModel } from './deletion.model'
|
|
5
|
+
|
|
6
|
+
export class ContentEntriesToActionsConverterService {
|
|
7
|
+
convert(
|
|
8
|
+
contentEntries: ContentEntryDraft[],
|
|
9
|
+
pathEntryFolder: string,
|
|
10
|
+
): {
|
|
11
|
+
additions: AdditionModel[]
|
|
12
|
+
deletions: DeletionModel[]
|
|
13
|
+
} {
|
|
14
|
+
const additions: AdditionModel[] = []
|
|
15
|
+
const deletions: DeletionModel[] = []
|
|
16
|
+
contentEntries.forEach((contentEntry) => {
|
|
17
|
+
const entryPath = `${pathEntryFolder}/${contentEntry.id}${ENTRY_EXTENSION}`
|
|
18
|
+
if (contentEntry.deletion) {
|
|
19
|
+
deletions.push(new DeletionModel(entryPath))
|
|
20
|
+
} else {
|
|
21
|
+
additions.push(
|
|
22
|
+
new AdditionModel(
|
|
23
|
+
entryPath,
|
|
24
|
+
stringify({
|
|
25
|
+
metadata: contentEntry.metadata,
|
|
26
|
+
data: contentEntry.data,
|
|
27
|
+
}),
|
|
28
|
+
),
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
return {
|
|
33
|
+
additions,
|
|
34
|
+
deletions,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { GraphqlQueryFactoryService } from './graphql-query-factory.service'
|
|
2
|
+
import {
|
|
3
|
+
Commit,
|
|
4
|
+
CommitDraft,
|
|
5
|
+
ContentEntry,
|
|
6
|
+
ENTRY_EXTENSION,
|
|
7
|
+
GitAdapter,
|
|
8
|
+
PATH_ENTRY_FOLDER,
|
|
9
|
+
PATH_SCHEMA_FILE,
|
|
10
|
+
} from '@commitspark/git-adapter'
|
|
11
|
+
import { ContentEntriesToActionsConverterService } from './content-entries-to-actions-converter.service'
|
|
12
|
+
import { parse } from 'yaml'
|
|
13
|
+
import { AxiosCacheInstance } from 'axios-cache-interceptor'
|
|
14
|
+
import { GitHubRepositoryOptions } from './index'
|
|
15
|
+
|
|
16
|
+
export class GitHubAdapterService implements GitAdapter {
|
|
17
|
+
static readonly QUERY_CACHE_SECONDS = 10 * 60
|
|
18
|
+
|
|
19
|
+
static readonly API_URL = 'https://api.github.com/graphql'
|
|
20
|
+
|
|
21
|
+
private gitRepositoryOptions: GitHubRepositoryOptions | undefined
|
|
22
|
+
|
|
23
|
+
constructor(
|
|
24
|
+
private readonly cachedHttpAdapter: AxiosCacheInstance,
|
|
25
|
+
private graphqlQueryFactory: GraphqlQueryFactoryService,
|
|
26
|
+
private contentEntriesToActionsConverter: ContentEntriesToActionsConverterService,
|
|
27
|
+
) {}
|
|
28
|
+
|
|
29
|
+
public async setRepositoryOptions(
|
|
30
|
+
repositoryOptions: GitHubRepositoryOptions,
|
|
31
|
+
): Promise<void> {
|
|
32
|
+
this.gitRepositoryOptions = repositoryOptions
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public async getContentEntries(commitHash: string): Promise<ContentEntry[]> {
|
|
36
|
+
if (this.gitRepositoryOptions === undefined) {
|
|
37
|
+
throw new Error('Repository options must be set before reading')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const token = this.gitRepositoryOptions.personalAccessToken
|
|
41
|
+
const pathEntryFolder = this.getPathEntryFolder(this.gitRepositoryOptions)
|
|
42
|
+
|
|
43
|
+
const queryFilesContent = this.graphqlQueryFactory.createBlobsContentQuery(
|
|
44
|
+
this.gitRepositoryOptions.repositoryOwner,
|
|
45
|
+
this.gitRepositoryOptions.repositoryName,
|
|
46
|
+
commitHash,
|
|
47
|
+
pathEntryFolder,
|
|
48
|
+
)
|
|
49
|
+
const filesContentResponse = await this.cachedHttpAdapter.post(
|
|
50
|
+
GitHubAdapterService.API_URL,
|
|
51
|
+
{
|
|
52
|
+
query: queryFilesContent,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
headers: {
|
|
56
|
+
authorization: `Bearer ${token}`,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
const extensionLength = ENTRY_EXTENSION.length
|
|
62
|
+
|
|
63
|
+
if (!filesContentResponse.data.data.repository?.object?.entries) {
|
|
64
|
+
return []
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return filesContentResponse.data.data.repository.object.entries
|
|
68
|
+
.filter((entry: any) => entry.name.endsWith(ENTRY_EXTENSION))
|
|
69
|
+
.map((entry: any) => {
|
|
70
|
+
const content = parse(entry.object.text)
|
|
71
|
+
const id = entry.name.substring(0, entry.name.length - extensionLength)
|
|
72
|
+
return {
|
|
73
|
+
id: id,
|
|
74
|
+
metadata: content.metadata,
|
|
75
|
+
data: content.data,
|
|
76
|
+
} as ContentEntry
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public async getSchema(commitHash: string): Promise<string> {
|
|
81
|
+
if (this.gitRepositoryOptions === undefined) {
|
|
82
|
+
throw new Error('Repository options must be set before reading')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const repositoryOwner = this.gitRepositoryOptions.repositoryOwner
|
|
86
|
+
const repositoryName = this.gitRepositoryOptions.repositoryName
|
|
87
|
+
const token = this.gitRepositoryOptions.personalAccessToken
|
|
88
|
+
const schemaFilePath =
|
|
89
|
+
this.gitRepositoryOptions.pathSchemaFile ?? PATH_SCHEMA_FILE
|
|
90
|
+
|
|
91
|
+
const queryContent = this.graphqlQueryFactory.createBlobContentQuery(
|
|
92
|
+
repositoryOwner,
|
|
93
|
+
repositoryName,
|
|
94
|
+
commitHash,
|
|
95
|
+
schemaFilePath,
|
|
96
|
+
)
|
|
97
|
+
const response = await this.cachedHttpAdapter.post(
|
|
98
|
+
GitHubAdapterService.API_URL,
|
|
99
|
+
{
|
|
100
|
+
query: queryContent,
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
headers: {
|
|
104
|
+
authorization: `Bearer ${token}`,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
)
|
|
108
|
+
const schema = response.data?.data?.repository?.object?.text
|
|
109
|
+
|
|
110
|
+
if (!schema) {
|
|
111
|
+
throw new Error(
|
|
112
|
+
`"${schemaFilePath}" not found in Git repository "${repositoryOwner}/${repositoryName}" at commit "${commitHash}"`,
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return schema
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public async getLatestCommitHash(ref: string): Promise<string> {
|
|
120
|
+
if (this.gitRepositoryOptions === undefined) {
|
|
121
|
+
throw new Error('Repository options must be set before reading')
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const token = this.gitRepositoryOptions.personalAccessToken
|
|
125
|
+
|
|
126
|
+
const queryLatestCommit = this.graphqlQueryFactory.createLatestCommitQuery(
|
|
127
|
+
this.gitRepositoryOptions.repositoryOwner,
|
|
128
|
+
this.gitRepositoryOptions.repositoryName,
|
|
129
|
+
ref,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
const response = await this.cachedHttpAdapter.post(
|
|
133
|
+
GitHubAdapterService.API_URL,
|
|
134
|
+
{
|
|
135
|
+
query: queryLatestCommit,
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
cache: false, // must not use cache, so we always get the branch's current head
|
|
139
|
+
headers: {
|
|
140
|
+
authorization: `Bearer ${token}`,
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
if (!response.data.data.repository) {
|
|
146
|
+
throw new Error(
|
|
147
|
+
`No repository found "${this.gitRepositoryOptions.repositoryOwner}/${this.gitRepositoryOptions.repositoryName}"`,
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const lastCommit =
|
|
152
|
+
response.data.data.repository.ref?.target?.oid ??
|
|
153
|
+
response.data.data.repository.object?.oid ??
|
|
154
|
+
undefined
|
|
155
|
+
if (!lastCommit) {
|
|
156
|
+
throw new Error(`No commit found for ref "${ref}"`)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return lastCommit
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
public async createCommit(commitDraft: CommitDraft): Promise<Commit> {
|
|
163
|
+
if (this.gitRepositoryOptions === undefined) {
|
|
164
|
+
throw new Error('Repository options must be set before committing')
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const token = this.gitRepositoryOptions.personalAccessToken
|
|
168
|
+
const pathEntryFolder = this.getPathEntryFolder(this.gitRepositoryOptions)
|
|
169
|
+
|
|
170
|
+
const { additions, deletions } =
|
|
171
|
+
this.contentEntriesToActionsConverter.convert(
|
|
172
|
+
commitDraft.contentEntries,
|
|
173
|
+
pathEntryFolder,
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
const mutateCommit = this.graphqlQueryFactory.createCommitMutation()
|
|
177
|
+
const response: any = await this.cachedHttpAdapter.post(
|
|
178
|
+
GitHubAdapterService.API_URL,
|
|
179
|
+
{
|
|
180
|
+
query: mutateCommit,
|
|
181
|
+
variables: {
|
|
182
|
+
repositoryNameWithOwner: `${this.gitRepositoryOptions.repositoryOwner}/${this.gitRepositoryOptions.repositoryName}`,
|
|
183
|
+
branchName: commitDraft.ref,
|
|
184
|
+
commitMessage: commitDraft.message ?? '-',
|
|
185
|
+
precedingCommitSha: commitDraft.parentSha,
|
|
186
|
+
additions: additions,
|
|
187
|
+
deletions: deletions,
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
cache: false,
|
|
192
|
+
headers: {
|
|
193
|
+
authorization: `Bearer ${token}`,
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
if (response.data.errors) {
|
|
199
|
+
throw new Error(JSON.stringify(response.data.errors))
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const mutationResult = response.data.data.commitCreate
|
|
203
|
+
|
|
204
|
+
if (mutationResult.errors) {
|
|
205
|
+
throw new Error(JSON.stringify(mutationResult.errors))
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return { ref: mutationResult.commit.oid }
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private getPathEntryFolder(
|
|
212
|
+
gitRepositoryOptions: GitHubRepositoryOptions,
|
|
213
|
+
): string {
|
|
214
|
+
const pathEntryFolder =
|
|
215
|
+
gitRepositoryOptions.pathEntryFolder ?? PATH_ENTRY_FOLDER
|
|
216
|
+
|
|
217
|
+
if (pathEntryFolder.endsWith('/')) {
|
|
218
|
+
return pathEntryFolder.substring(0, pathEntryFolder.length - 1)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return pathEntryFolder
|
|
222
|
+
}
|
|
223
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export class GraphqlQueryFactoryService {
|
|
2
|
+
public createBlobsContentQuery(
|
|
3
|
+
repositoryOwner: string,
|
|
4
|
+
repositoryName: string,
|
|
5
|
+
ref: string,
|
|
6
|
+
path: string,
|
|
7
|
+
): string {
|
|
8
|
+
return `
|
|
9
|
+
query {
|
|
10
|
+
repository(owner:"${repositoryOwner}", name:"${repositoryName}") {
|
|
11
|
+
object(expression:"${ref}:${path}") {
|
|
12
|
+
... on Tree {
|
|
13
|
+
entries {
|
|
14
|
+
name
|
|
15
|
+
object {
|
|
16
|
+
... on Blob {
|
|
17
|
+
text
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
`
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public createBlobContentQuery(
|
|
29
|
+
repositoryOwner: string,
|
|
30
|
+
repositoryName: string,
|
|
31
|
+
ref: string,
|
|
32
|
+
schemaFilePath: string,
|
|
33
|
+
): string {
|
|
34
|
+
return `
|
|
35
|
+
query {
|
|
36
|
+
repository(owner:"${repositoryOwner}", name:"${repositoryName}") {
|
|
37
|
+
object(expression:"${ref}:${schemaFilePath}") {
|
|
38
|
+
... on Blob {
|
|
39
|
+
text
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
`
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public createCommitMutation(): string {
|
|
48
|
+
return `
|
|
49
|
+
mutation (
|
|
50
|
+
$repositoryNameWithOwner:String!,
|
|
51
|
+
$branchName:String!,
|
|
52
|
+
$commitMessage:String!,
|
|
53
|
+
$precedingCommitSha:GitObjectID!,
|
|
54
|
+
$additions:[FileAddition!],
|
|
55
|
+
$deletions:[FileDeletion!]
|
|
56
|
+
) {
|
|
57
|
+
commitCreate: createCommitOnBranch(input:{
|
|
58
|
+
branch:{
|
|
59
|
+
repositoryNameWithOwner:$repositoryNameWithOwner
|
|
60
|
+
branchName:$branchName
|
|
61
|
+
}
|
|
62
|
+
message: {
|
|
63
|
+
headline:$commitMessage
|
|
64
|
+
body:""
|
|
65
|
+
}
|
|
66
|
+
expectedHeadOid:$precedingCommitSha
|
|
67
|
+
fileChanges:{
|
|
68
|
+
additions:$additions
|
|
69
|
+
deletions:$deletions
|
|
70
|
+
}
|
|
71
|
+
}) {
|
|
72
|
+
commit {
|
|
73
|
+
oid
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
`
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public createLatestCommitQuery(
|
|
81
|
+
repositoryOwner: string,
|
|
82
|
+
repositoryName: string,
|
|
83
|
+
ref: string,
|
|
84
|
+
): string {
|
|
85
|
+
return `
|
|
86
|
+
query Content {
|
|
87
|
+
repository(owner:"${repositoryOwner}", name:"${repositoryName}") {
|
|
88
|
+
ref(qualifiedName:"${ref}") {
|
|
89
|
+
target {
|
|
90
|
+
oid
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
object(expression:"${ref}") {
|
|
94
|
+
oid
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
`
|
|
99
|
+
}
|
|
100
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GitAdapter, GitRepositoryOptions } from '@commitspark/git-adapter'
|
|
2
|
+
import { gitHubAdapterService } from './container'
|
|
3
|
+
|
|
4
|
+
export { GitHubAdapterService } from './git-hub-adapter.service'
|
|
5
|
+
|
|
6
|
+
export interface GitHubRepositoryOptions extends GitRepositoryOptions {
|
|
7
|
+
repositoryOwner: string
|
|
8
|
+
repositoryName: string
|
|
9
|
+
personalAccessToken: string
|
|
10
|
+
pathSchemaFile?: string
|
|
11
|
+
pathEntryFolder?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function createAdapter(): GitAdapter {
|
|
15
|
+
return gitHubAdapterService
|
|
16
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"removeComments": true,
|
|
6
|
+
"emitDecoratorMetadata": true,
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"target": "es2017",
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"outDir": "./dist",
|
|
12
|
+
"baseUrl": "./",
|
|
13
|
+
"incremental": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"strict": true,
|
|
16
|
+
"esModuleInterop": true
|
|
17
|
+
},
|
|
18
|
+
"exclude": [
|
|
19
|
+
"node_modules",
|
|
20
|
+
"dist"
|
|
21
|
+
]
|
|
22
|
+
}
|