tinacms-gitprovider-github 0.0.0-20240902032558 → 0.0.0-20240903031924
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +74 -0
- package/package.json +4 -4
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { Octokit } from "@octokit/rest";
|
|
3
|
+
import { Base64 } from "js-base64";
|
|
4
|
+
var GitHubProvider = class {
|
|
5
|
+
constructor(args) {
|
|
6
|
+
this.owner = args.owner;
|
|
7
|
+
this.repo = args.repo;
|
|
8
|
+
this.branch = args.branch;
|
|
9
|
+
this.commitMessage = args.commitMessage;
|
|
10
|
+
this.rootPath = args.rootPath;
|
|
11
|
+
this.octokit = new Octokit({
|
|
12
|
+
auth: args.token,
|
|
13
|
+
...args.octokitOptions || {}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
async onPut(key, value) {
|
|
17
|
+
let sha;
|
|
18
|
+
const path = this.rootPath ? `${this.rootPath}/${key}` : key;
|
|
19
|
+
try {
|
|
20
|
+
const {
|
|
21
|
+
data: { sha: existingSha }
|
|
22
|
+
} = await this.octokit.repos.getContent({
|
|
23
|
+
owner: this.owner,
|
|
24
|
+
repo: this.repo,
|
|
25
|
+
path,
|
|
26
|
+
ref: this.branch
|
|
27
|
+
});
|
|
28
|
+
sha = existingSha;
|
|
29
|
+
} catch (e) {
|
|
30
|
+
}
|
|
31
|
+
await this.octokit.repos.createOrUpdateFileContents({
|
|
32
|
+
owner: this.owner,
|
|
33
|
+
repo: this.repo,
|
|
34
|
+
path,
|
|
35
|
+
message: this.commitMessage || "Edited with TinaCMS",
|
|
36
|
+
content: Base64.encode(value),
|
|
37
|
+
branch: this.branch,
|
|
38
|
+
sha
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async onDelete(key) {
|
|
42
|
+
let sha;
|
|
43
|
+
const path = this.rootPath ? `${this.rootPath}/${key}` : key;
|
|
44
|
+
try {
|
|
45
|
+
const {
|
|
46
|
+
data: { sha: existingSha }
|
|
47
|
+
} = await this.octokit.repos.getContent({
|
|
48
|
+
owner: this.owner,
|
|
49
|
+
repo: this.repo,
|
|
50
|
+
path,
|
|
51
|
+
ref: this.branch
|
|
52
|
+
});
|
|
53
|
+
sha = existingSha;
|
|
54
|
+
} catch (e) {
|
|
55
|
+
}
|
|
56
|
+
if (sha) {
|
|
57
|
+
await this.octokit.repos.deleteFile({
|
|
58
|
+
owner: this.owner,
|
|
59
|
+
repo: this.repo,
|
|
60
|
+
path,
|
|
61
|
+
message: this.commitMessage || "Edited with TinaCMS",
|
|
62
|
+
branch: this.branch,
|
|
63
|
+
sha
|
|
64
|
+
});
|
|
65
|
+
} else {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`Could not find file ${path} in repo ${this.owner}/${this.repo}`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
export {
|
|
73
|
+
GitHubProvider
|
|
74
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinacms-gitprovider-github",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-20240903031924",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"files": [
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^13.13.1",
|
|
26
|
-
"@tinacms/datalayer": "0.0.0-
|
|
27
|
-
"@tinacms/scripts": "0.0.0-
|
|
26
|
+
"@tinacms/datalayer": "0.0.0-20240903031924",
|
|
27
|
+
"@tinacms/scripts": "0.0.0-20240903031924"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@tinacms/datalayer": "0.0.0-
|
|
30
|
+
"@tinacms/datalayer": "0.0.0-20240903031924"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"registry": "https://registry.npmjs.org"
|