github-repository-provider 7.30.16 → 7.30.19
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/README.md +11 -11
- package/package.json +1 -1
- package/src/github-branch.mjs +37 -88
- package/src/github-repository.mjs +62 -17
package/README.md
CHANGED
|
@@ -38,11 +38,11 @@ console.log(entry.name);
|
|
|
38
38
|
* [Parameters](#parameters)
|
|
39
39
|
* [commit](#commit)
|
|
40
40
|
* [Parameters](#parameters-1)
|
|
41
|
-
* [entry](#entry)
|
|
42
|
-
* [Parameters](#parameters-2)
|
|
43
41
|
* [commitForSha](#commitforsha)
|
|
44
|
-
* [Parameters](#parameters-
|
|
42
|
+
* [Parameters](#parameters-2)
|
|
45
43
|
* [tree](#tree)
|
|
44
|
+
* [Parameters](#parameters-3)
|
|
45
|
+
* [entry](#entry)
|
|
46
46
|
* [Parameters](#parameters-4)
|
|
47
47
|
* [removeEntries](#removeentries)
|
|
48
48
|
* [Parameters](#parameters-5)
|
|
@@ -113,14 +113,6 @@ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/
|
|
|
113
113
|
* `entries` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<ContentEntry>**
|
|
114
114
|
* `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
|
115
115
|
|
|
116
|
-
### entry
|
|
117
|
-
|
|
118
|
-
<https://developer.github.com/v3/repos/contents/#get-repository-content>
|
|
119
|
-
|
|
120
|
-
#### Parameters
|
|
121
|
-
|
|
122
|
-
* `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
|
123
|
-
|
|
124
116
|
### commitForSha
|
|
125
117
|
|
|
126
118
|
<https://developer.github.com/v3/git/commits/#get-a-commit>
|
|
@@ -141,6 +133,14 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
|
|
|
141
133
|
|
|
142
134
|
Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>**
|
|
143
135
|
|
|
136
|
+
### entry
|
|
137
|
+
|
|
138
|
+
<https://developer.github.com/v3/repos/contents/#get-repository-content>
|
|
139
|
+
|
|
140
|
+
#### Parameters
|
|
141
|
+
|
|
142
|
+
* `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
|
143
|
+
|
|
144
144
|
### removeEntries
|
|
145
145
|
|
|
146
146
|
<https://developer.github.com/v3/repos/contents/>
|
package/package.json
CHANGED
package/src/github-branch.mjs
CHANGED
|
@@ -10,9 +10,8 @@ import {
|
|
|
10
10
|
* Branch on GitHub.
|
|
11
11
|
*/
|
|
12
12
|
export class GithubBranch extends Branch {
|
|
13
|
-
#entries;
|
|
14
|
-
#
|
|
15
|
-
#commitForSha;
|
|
13
|
+
#entries = new Map();
|
|
14
|
+
#commits = new Map();
|
|
16
15
|
|
|
17
16
|
/**
|
|
18
17
|
* Writes content into the branch
|
|
@@ -29,9 +28,7 @@ export class GithubBranch extends Branch {
|
|
|
29
28
|
})
|
|
30
29
|
});
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
this.#entries.set(entry.name, entry);
|
|
34
|
-
}
|
|
31
|
+
this.#entries.set(entry.name, entry);
|
|
35
32
|
|
|
36
33
|
entry.sha = json.sha;
|
|
37
34
|
|
|
@@ -61,48 +58,50 @@ export class GithubBranch extends Branch {
|
|
|
61
58
|
|
|
62
59
|
const shaLatestCommit = await this.refId();
|
|
63
60
|
const commit = await this.commitForSha(shaLatestCommit);
|
|
64
|
-
|
|
65
|
-
let { json } = await this.provider.fetchJSON(`${this.api}/git/trees`, {
|
|
66
|
-
method: "POST",
|
|
67
|
-
body: JSON.stringify({
|
|
68
|
-
base_tree: commit.tree.sha,
|
|
69
|
-
tree: updates.map(u => {
|
|
70
|
-
return {
|
|
71
|
-
path: u.name,
|
|
72
|
-
sha: u.sha,
|
|
73
|
-
type: "blob",
|
|
74
|
-
mode: "100" + u.mode.toString(8)
|
|
75
|
-
};
|
|
76
|
-
})
|
|
77
|
-
})
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
//console.log("TREE", json.sha, shaLatestCommit);
|
|
61
|
+
const tree = await this.owner.addTree(updates, commit.tree.sha);
|
|
81
62
|
|
|
82
63
|
let r = await this.provider.fetchJSON(`${this.api}/git/commits`, {
|
|
83
64
|
method: "POST",
|
|
84
65
|
body: JSON.stringify({
|
|
85
66
|
message,
|
|
86
|
-
tree:
|
|
67
|
+
tree: tree.sha,
|
|
87
68
|
parents: [shaLatestCommit]
|
|
88
69
|
})
|
|
89
70
|
});
|
|
90
71
|
|
|
72
|
+
this.#commits.set(r.json.sha, r.json);
|
|
73
|
+
|
|
91
74
|
return this.owner.setRefId(this.ref, r.json.sha, options);
|
|
92
75
|
}
|
|
93
76
|
|
|
77
|
+
/**
|
|
78
|
+
* {@link https://developer.github.com/v3/git/commits/#get-a-commit}
|
|
79
|
+
* @param {string} sha
|
|
80
|
+
* @return {Object} response
|
|
81
|
+
*/
|
|
82
|
+
async commitForSha(sha) {
|
|
83
|
+
const commit = this.#commits.get(sha);
|
|
84
|
+
if (commit) {
|
|
85
|
+
return commit;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const { json } = await this.provider.fetchJSON(
|
|
89
|
+
`${this.api}/git/commits/${sha}`
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
this.#commits.set(sha, json);
|
|
93
|
+
|
|
94
|
+
return json;
|
|
95
|
+
}
|
|
96
|
+
|
|
94
97
|
/**
|
|
95
98
|
* {@link https://developer.github.com/v3/repos/contents/#get-repository-content}
|
|
96
99
|
* @param {string} name
|
|
97
100
|
*/
|
|
98
101
|
async entry(name) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return entry;
|
|
103
|
-
}
|
|
104
|
-
} else {
|
|
105
|
-
this.#entries = new Map();
|
|
102
|
+
const entry = this.#entries.get(name);
|
|
103
|
+
if (entry) {
|
|
104
|
+
return entry;
|
|
106
105
|
}
|
|
107
106
|
|
|
108
107
|
const f = async () => {
|
|
@@ -126,66 +125,16 @@ export class GithubBranch extends Branch {
|
|
|
126
125
|
return p;
|
|
127
126
|
}
|
|
128
127
|
|
|
129
|
-
/**
|
|
130
|
-
* {@link https://developer.github.com/v3/git/commits/#get-a-commit}
|
|
131
|
-
* @param {string} sha
|
|
132
|
-
* @return {Object} response
|
|
133
|
-
*/
|
|
134
|
-
async commitForSha(sha) {
|
|
135
|
-
if (this.#commitForSha) {
|
|
136
|
-
const json = this.#commitForSha.get(sha);
|
|
137
|
-
if (json) {
|
|
138
|
-
return json;
|
|
139
|
-
}
|
|
140
|
-
} else {
|
|
141
|
-
this.#commitForSha = new Map();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const { json } = await this.provider.fetchJSON(
|
|
145
|
-
`${this.api}/git/commits/${sha}`
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
this.#commitForSha.set(sha, json);
|
|
149
|
-
|
|
150
|
-
return json;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* @see https://developer.github.com/v3/git/trees/
|
|
155
|
-
* @param {string} sha
|
|
156
|
-
* @return {Object[]}
|
|
157
|
-
*/
|
|
158
|
-
async tree(sha) {
|
|
159
|
-
if (this.#tree) {
|
|
160
|
-
const tree = this.#tree.get(sha);
|
|
161
|
-
if (tree) {
|
|
162
|
-
return tree;
|
|
163
|
-
}
|
|
164
|
-
} else {
|
|
165
|
-
this.#tree = new Map();
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const { json } = await this.provider.fetchJSON(
|
|
169
|
-
`${this.api}/git/trees/${sha}?recursive=1`
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
const tree = json.tree;
|
|
173
|
-
|
|
174
|
-
this.#tree.set(sha, tree);
|
|
175
|
-
|
|
176
|
-
return tree;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
128
|
async *entries(patterns) {
|
|
180
129
|
const commit = await this.commitForSha(await this.refId());
|
|
181
130
|
|
|
182
|
-
|
|
183
|
-
this
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
131
|
+
for (const entry of matcher(
|
|
132
|
+
await this.owner.tree(commit.tree.sha),
|
|
133
|
+
patterns,
|
|
134
|
+
{
|
|
135
|
+
name: "path"
|
|
136
|
+
}
|
|
137
|
+
)) {
|
|
189
138
|
switch (entry.type) {
|
|
190
139
|
case "tree":
|
|
191
140
|
yield new BaseCollectionEntry(entry.path);
|
|
@@ -12,6 +12,9 @@ const conflictErrorActions = {
|
|
|
12
12
|
* Repository on GitHub.
|
|
13
13
|
*/
|
|
14
14
|
export class GithubRepository extends Repository {
|
|
15
|
+
#refs = new Map();
|
|
16
|
+
#trees = new Map();
|
|
17
|
+
|
|
15
18
|
static get attributeMapping() {
|
|
16
19
|
return {
|
|
17
20
|
...super.attributeMapping,
|
|
@@ -70,6 +73,55 @@ export class GithubRepository extends Repository {
|
|
|
70
73
|
} while (next);
|
|
71
74
|
}
|
|
72
75
|
|
|
76
|
+
/**
|
|
77
|
+
* @see https://developer.github.com/v3/git/trees/
|
|
78
|
+
* @param {string} sha
|
|
79
|
+
* @return {Object[]}
|
|
80
|
+
*/
|
|
81
|
+
async tree(sha) {
|
|
82
|
+
let tree = this.#trees.get(sha);
|
|
83
|
+
if (tree) {
|
|
84
|
+
return tree;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const { json } = await this.provider.fetchJSON(
|
|
88
|
+
`${this.api}/git/trees/${sha}?recursive=1`
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
tree = json.tree;
|
|
92
|
+
|
|
93
|
+
this.#trees.set(sha, tree);
|
|
94
|
+
|
|
95
|
+
return tree;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @see https://developer.github.com/v3/git/trees/
|
|
100
|
+
* @param {Object[]} updates
|
|
101
|
+
* @param {string} base base tree sha
|
|
102
|
+
* @returns {Object} newly created tree
|
|
103
|
+
*/
|
|
104
|
+
async addTree(updates, base) {
|
|
105
|
+
let { json } = await this.provider.fetchJSON(`${this.api}/git/trees`, {
|
|
106
|
+
method: "POST",
|
|
107
|
+
body: JSON.stringify({
|
|
108
|
+
base_tree: base,
|
|
109
|
+
tree: updates.map(u => {
|
|
110
|
+
return {
|
|
111
|
+
path: u.name,
|
|
112
|
+
sha: u.sha,
|
|
113
|
+
type: "blob",
|
|
114
|
+
mode: "100" + u.mode.toString(8)
|
|
115
|
+
};
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
this.#trees.set(json.sha, json);
|
|
121
|
+
|
|
122
|
+
return json;
|
|
123
|
+
}
|
|
124
|
+
|
|
73
125
|
async #initializeSlot(typeName, addMethodName) {
|
|
74
126
|
let next = `${this.api}/${typeName}`;
|
|
75
127
|
|
|
@@ -140,8 +192,6 @@ export class GithubRepository extends Repository {
|
|
|
140
192
|
});
|
|
141
193
|
}
|
|
142
194
|
|
|
143
|
-
#ref;
|
|
144
|
-
|
|
145
195
|
/**
|
|
146
196
|
* Get sha of a ref.
|
|
147
197
|
* {@link https://developer.github.com/v3/git/refs/}
|
|
@@ -151,13 +201,9 @@ export class GithubRepository extends Repository {
|
|
|
151
201
|
async refId(ref) {
|
|
152
202
|
ref = ref.replace(/^refs\//, "");
|
|
153
203
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return sha;
|
|
158
|
-
}
|
|
159
|
-
} else {
|
|
160
|
-
this.#ref = new Map();
|
|
204
|
+
let sha = this.#refs.get(ref);
|
|
205
|
+
if (sha) {
|
|
206
|
+
return sha;
|
|
161
207
|
}
|
|
162
208
|
|
|
163
209
|
const { response, json } = await this.provider.fetchJSON(
|
|
@@ -169,9 +215,9 @@ export class GithubRepository extends Repository {
|
|
|
169
215
|
throw new Error(`No refId for '${this.fullName}' '${ref}'`);
|
|
170
216
|
}
|
|
171
217
|
|
|
172
|
-
|
|
218
|
+
sha = json.object.sha;
|
|
173
219
|
|
|
174
|
-
this.#
|
|
220
|
+
this.#refs.set(ref, sha);
|
|
175
221
|
|
|
176
222
|
return sha;
|
|
177
223
|
}
|
|
@@ -188,13 +234,12 @@ export class GithubRepository extends Repository {
|
|
|
188
234
|
})
|
|
189
235
|
});
|
|
190
236
|
|
|
191
|
-
|
|
192
|
-
this.#ref.set(ref, sha);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
//console.log(r.response.ok, r.response.status, r.json);
|
|
237
|
+
console.log(ref, sha, r.response.ok, r.response.status, r.json);
|
|
196
238
|
|
|
197
|
-
|
|
239
|
+
if (r.response.ok) {
|
|
240
|
+
this.#refs.set(ref, sha);
|
|
241
|
+
return r.json;
|
|
242
|
+
}
|
|
198
243
|
}
|
|
199
244
|
|
|
200
245
|
async createBranch(name, from, options) {
|