github-repository-provider 7.30.18 → 7.30.21
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 +34 -21
- package/package.json +1 -1
- package/src/github-branch.mjs +18 -81
- package/src/github-repository.mjs +104 -13
package/README.md
CHANGED
|
@@ -40,17 +40,15 @@ console.log(entry.name);
|
|
|
40
40
|
* [Parameters](#parameters-1)
|
|
41
41
|
* [commitForSha](#commitforsha)
|
|
42
42
|
* [Parameters](#parameters-2)
|
|
43
|
-
* [tree](#tree)
|
|
44
|
-
* [Parameters](#parameters-3)
|
|
45
43
|
* [entry](#entry)
|
|
46
|
-
* [Parameters](#parameters-
|
|
44
|
+
* [Parameters](#parameters-3)
|
|
47
45
|
* [removeEntries](#removeentries)
|
|
48
|
-
* [Parameters](#parameters-
|
|
46
|
+
* [Parameters](#parameters-4)
|
|
49
47
|
* [GithubOwner](#githubowner)
|
|
50
48
|
* [createRepository](#createrepository)
|
|
51
|
-
* [Parameters](#parameters-
|
|
49
|
+
* [Parameters](#parameters-5)
|
|
52
50
|
* [deleteRepository](#deleterepository)
|
|
53
|
-
* [Parameters](#parameters-
|
|
51
|
+
* [Parameters](#parameters-6)
|
|
54
52
|
* [attributeMapping](#attributemapping)
|
|
55
53
|
* [GithubProvider](#githubprovider)
|
|
56
54
|
* [Examples](#examples)
|
|
@@ -60,17 +58,21 @@ console.log(entry.name);
|
|
|
60
58
|
* [instanceIdentifier](#instanceidentifier)
|
|
61
59
|
* [GithubPullRequest](#githubpullrequest)
|
|
62
60
|
* [\_merge](#\_merge)
|
|
63
|
-
* [Parameters](#parameters-
|
|
61
|
+
* [Parameters](#parameters-7)
|
|
64
62
|
* [update](#update)
|
|
65
63
|
* [validMergeMethods](#validmergemethods)
|
|
66
64
|
* [list](#list)
|
|
67
|
-
* [Parameters](#parameters-
|
|
65
|
+
* [Parameters](#parameters-8)
|
|
68
66
|
* [open](#open)
|
|
69
|
-
* [Parameters](#parameters-
|
|
67
|
+
* [Parameters](#parameters-9)
|
|
70
68
|
* [GithubRepository](#githubrepository)
|
|
71
69
|
* [defaultBranchName](#defaultbranchname)
|
|
72
70
|
* [commits](#commits)
|
|
71
|
+
* [Parameters](#parameters-10)
|
|
72
|
+
* [tree](#tree)
|
|
73
73
|
* [Parameters](#parameters-11)
|
|
74
|
+
* [addTree](#addtree)
|
|
75
|
+
* [Parameters](#parameters-12)
|
|
74
76
|
* [initializeBranches](#initializebranches)
|
|
75
77
|
* [initializeTags](#initializetags)
|
|
76
78
|
* [url](#url)
|
|
@@ -79,9 +81,9 @@ console.log(entry.name);
|
|
|
79
81
|
* [api](#api)
|
|
80
82
|
* [update](#update-1)
|
|
81
83
|
* [refId](#refid)
|
|
82
|
-
* [Parameters](#parameters-12)
|
|
83
|
-
* [deletePullRequest](#deletepullrequest)
|
|
84
84
|
* [Parameters](#parameters-13)
|
|
85
|
+
* [deletePullRequest](#deletepullrequest)
|
|
86
|
+
* [Parameters](#parameters-14)
|
|
85
87
|
* [initializeHooks](#initializehooks)
|
|
86
88
|
|
|
87
89
|
## GithubBranch
|
|
@@ -123,16 +125,6 @@ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/
|
|
|
123
125
|
|
|
124
126
|
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** response
|
|
125
127
|
|
|
126
|
-
### tree
|
|
127
|
-
|
|
128
|
-
* **See**: <https://developer.github.com/v3/git/trees/>
|
|
129
|
-
|
|
130
|
-
#### Parameters
|
|
131
|
-
|
|
132
|
-
* `sha` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
|
133
|
-
|
|
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)>**
|
|
135
|
-
|
|
136
128
|
### entry
|
|
137
129
|
|
|
138
130
|
<https://developer.github.com/v3/repos/contents/#get-repository-content>
|
|
@@ -296,6 +288,27 @@ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
|
|
|
296
288
|
|
|
297
289
|
Returns **AsyncIterator\<Commit>**
|
|
298
290
|
|
|
291
|
+
### tree
|
|
292
|
+
|
|
293
|
+
* **See**: <https://developer.github.com/v3/git/trees/>
|
|
294
|
+
|
|
295
|
+
#### Parameters
|
|
296
|
+
|
|
297
|
+
* `sha` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
|
298
|
+
|
|
299
|
+
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)>**
|
|
300
|
+
|
|
301
|
+
### addTree
|
|
302
|
+
|
|
303
|
+
* **See**: <https://developer.github.com/v3/git/trees/>
|
|
304
|
+
|
|
305
|
+
#### Parameters
|
|
306
|
+
|
|
307
|
+
* `updates` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>**
|
|
308
|
+
* `base` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** base tree sha
|
|
309
|
+
|
|
310
|
+
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** newly created tree
|
|
311
|
+
|
|
299
312
|
### initializeBranches
|
|
300
313
|
|
|
301
314
|
<https://developer.github.com/v3/repos/branches/#list-branches>
|
package/package.json
CHANGED
package/src/github-branch.mjs
CHANGED
|
@@ -11,8 +11,6 @@ import {
|
|
|
11
11
|
*/
|
|
12
12
|
export class GithubBranch extends Branch {
|
|
13
13
|
#entries = new Map();
|
|
14
|
-
#trees = new Map();
|
|
15
|
-
#commits = new Map();
|
|
16
14
|
|
|
17
15
|
/**
|
|
18
16
|
* Writes content into the branch
|
|
@@ -45,10 +43,6 @@ export class GithubBranch extends Branch {
|
|
|
45
43
|
* @param {Object} options
|
|
46
44
|
*/
|
|
47
45
|
async commit(message, entries, options) {
|
|
48
|
-
const updates = await Promise.all(
|
|
49
|
-
entries.map(entry => this.writeEntry(entry))
|
|
50
|
-
);
|
|
51
|
-
|
|
52
46
|
/*
|
|
53
47
|
* 1st. commit on empty tree
|
|
54
48
|
* https://stackoverflow.com/questions/9765453/is-gits-semi-secret-empty-tree-object-reliable-and-why-is-there-not-a-symbolic/9766506#9766506
|
|
@@ -57,81 +51,20 @@ export class GithubBranch extends Branch {
|
|
|
57
51
|
* sha256:6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321
|
|
58
52
|
*/
|
|
59
53
|
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
let { json } = await this.provider.fetchJSON(`${this.api}/git/trees`, {
|
|
64
|
-
method: "POST",
|
|
65
|
-
body: JSON.stringify({
|
|
66
|
-
base_tree: commit.tree.sha,
|
|
67
|
-
tree: updates.map(u => {
|
|
68
|
-
return {
|
|
69
|
-
path: u.name,
|
|
70
|
-
sha: u.sha,
|
|
71
|
-
type: "blob",
|
|
72
|
-
mode: "100" + u.mode.toString(8)
|
|
73
|
-
};
|
|
74
|
-
})
|
|
75
|
-
})
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const treeSHA = json.sha;
|
|
79
|
-
this.#trees.set(treeSHA, json);
|
|
80
|
-
|
|
81
|
-
let r = await this.provider.fetchJSON(`${this.api}/git/commits`, {
|
|
82
|
-
method: "POST",
|
|
83
|
-
body: JSON.stringify({
|
|
84
|
-
message,
|
|
85
|
-
tree: treeSHA,
|
|
86
|
-
parents: [shaLatestCommit]
|
|
87
|
-
})
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
this.#commits.set(r.json.sha, r.json);
|
|
91
|
-
|
|
92
|
-
return this.owner.setRefId(this.ref, r.json.sha, options);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* {@link https://developer.github.com/v3/git/commits/#get-a-commit}
|
|
97
|
-
* @param {string} sha
|
|
98
|
-
* @return {Object} response
|
|
99
|
-
*/
|
|
100
|
-
async commitForSha(sha) {
|
|
101
|
-
const commit = this.#commits.get(sha);
|
|
102
|
-
if (commit) {
|
|
103
|
-
return commit;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const { json } = await this.provider.fetchJSON(
|
|
107
|
-
`${this.api}/git/commits/${sha}`
|
|
54
|
+
const updates = await Promise.all(
|
|
55
|
+
entries.map(entry => this.writeEntry(entry))
|
|
108
56
|
);
|
|
109
57
|
|
|
110
|
-
this
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
* @param {string} sha
|
|
118
|
-
* @return {Object[]}
|
|
119
|
-
*/
|
|
120
|
-
async tree(sha) {
|
|
121
|
-
let tree = this.#trees.get(sha);
|
|
122
|
-
if (tree) {
|
|
123
|
-
return tree;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const { json } = await this.provider.fetchJSON(
|
|
127
|
-
`${this.api}/git/trees/${sha}?recursive=1`
|
|
58
|
+
const shaLatestCommit = await this.refId();
|
|
59
|
+
const latestCommit = await this.owner.commitForSha(shaLatestCommit);
|
|
60
|
+
const tree = await this.owner.addTree(updates, latestCommit.tree.sha);
|
|
61
|
+
const commit = await this.owner.addCommit(
|
|
62
|
+
tree.sha,
|
|
63
|
+
[shaLatestCommit],
|
|
64
|
+
message
|
|
128
65
|
);
|
|
129
66
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
this.#trees.set(sha, tree);
|
|
133
|
-
|
|
134
|
-
return tree;
|
|
67
|
+
return this.owner.setRefId(this.ref, commit.sha, options);
|
|
135
68
|
}
|
|
136
69
|
|
|
137
70
|
/**
|
|
@@ -166,11 +99,15 @@ export class GithubBranch extends Branch {
|
|
|
166
99
|
}
|
|
167
100
|
|
|
168
101
|
async *entries(patterns) {
|
|
169
|
-
const commit = await this.commitForSha(await this.refId());
|
|
102
|
+
const commit = await this.owner.commitForSha(await this.refId());
|
|
170
103
|
|
|
171
|
-
for (const entry of matcher(
|
|
172
|
-
|
|
173
|
-
|
|
104
|
+
for (const entry of matcher(
|
|
105
|
+
await this.owner.tree(commit.tree.sha),
|
|
106
|
+
patterns,
|
|
107
|
+
{
|
|
108
|
+
name: "path"
|
|
109
|
+
}
|
|
110
|
+
)) {
|
|
174
111
|
switch (entry.type) {
|
|
175
112
|
case "tree":
|
|
176
113
|
yield new BaseCollectionEntry(entry.path);
|
|
@@ -12,7 +12,9 @@ const conflictErrorActions = {
|
|
|
12
12
|
* Repository on GitHub.
|
|
13
13
|
*/
|
|
14
14
|
export class GithubRepository extends Repository {
|
|
15
|
-
#
|
|
15
|
+
#refs = new Map();
|
|
16
|
+
#trees = new Map();
|
|
17
|
+
#commits = new Map();
|
|
16
18
|
|
|
17
19
|
static get attributeMapping() {
|
|
18
20
|
return {
|
|
@@ -61,6 +63,8 @@ export class GithubRepository extends Repository {
|
|
|
61
63
|
const { response, json } = await this.provider.fetchJSON(next);
|
|
62
64
|
|
|
63
65
|
for (const c of json) {
|
|
66
|
+
this.#commits.set(c.sha, json);
|
|
67
|
+
|
|
64
68
|
yield {
|
|
65
69
|
sha: c.sha,
|
|
66
70
|
message: c.message,
|
|
@@ -72,6 +76,89 @@ export class GithubRepository extends Repository {
|
|
|
72
76
|
} while (next);
|
|
73
77
|
}
|
|
74
78
|
|
|
79
|
+
async addCommit(tree, parents, message) {
|
|
80
|
+
let r = await this.provider.fetchJSON(`${this.api}/git/commits`, {
|
|
81
|
+
method: "POST",
|
|
82
|
+
body: JSON.stringify({
|
|
83
|
+
tree,
|
|
84
|
+
parents,
|
|
85
|
+
message
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
this.#commits.set(r.json.sha, r.json);
|
|
90
|
+
return r.json;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* {@link https://developer.github.com/v3/git/commits/#get-a-commit}
|
|
95
|
+
* @param {string} sha
|
|
96
|
+
* @return {Object} response
|
|
97
|
+
*/
|
|
98
|
+
async commitForSha(sha) {
|
|
99
|
+
const commit = this.#commits.get(sha);
|
|
100
|
+
if (commit) {
|
|
101
|
+
return commit;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const { json } = await this.provider.fetchJSON(
|
|
105
|
+
`${this.api}/git/commits/${sha}`
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
this.#commits.set(sha, json);
|
|
109
|
+
|
|
110
|
+
return json;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @see https://developer.github.com/v3/git/trees/
|
|
115
|
+
* @param {string} sha
|
|
116
|
+
* @return {Object[]}
|
|
117
|
+
*/
|
|
118
|
+
async tree(sha) {
|
|
119
|
+
let tree = this.#trees.get(sha);
|
|
120
|
+
if (tree) {
|
|
121
|
+
return tree;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const { json } = await this.provider.fetchJSON(
|
|
125
|
+
`${this.api}/git/trees/${sha}?recursive=1`
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
tree = json.tree;
|
|
129
|
+
|
|
130
|
+
this.#trees.set(sha, tree);
|
|
131
|
+
|
|
132
|
+
return tree;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @see https://developer.github.com/v3/git/trees/
|
|
137
|
+
* @param {Object[]} updates
|
|
138
|
+
* @param {string} base base tree sha
|
|
139
|
+
* @returns {Object} newly created tree
|
|
140
|
+
*/
|
|
141
|
+
async addTree(updates, base) {
|
|
142
|
+
let { json } = await this.provider.fetchJSON(`${this.api}/git/trees`, {
|
|
143
|
+
method: "POST",
|
|
144
|
+
body: JSON.stringify({
|
|
145
|
+
base_tree: base,
|
|
146
|
+
tree: updates.map(u => {
|
|
147
|
+
return {
|
|
148
|
+
path: u.name,
|
|
149
|
+
sha: u.sha,
|
|
150
|
+
type: "blob",
|
|
151
|
+
mode: "100" + u.mode.toString(8)
|
|
152
|
+
};
|
|
153
|
+
})
|
|
154
|
+
})
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
this.#trees.set(json.sha, json);
|
|
158
|
+
|
|
159
|
+
return json;
|
|
160
|
+
}
|
|
161
|
+
|
|
75
162
|
async #initializeSlot(typeName, addMethodName) {
|
|
76
163
|
let next = `${this.api}/${typeName}`;
|
|
77
164
|
|
|
@@ -151,7 +238,7 @@ export class GithubRepository extends Repository {
|
|
|
151
238
|
async refId(ref) {
|
|
152
239
|
ref = ref.replace(/^refs\//, "");
|
|
153
240
|
|
|
154
|
-
let sha = this.#
|
|
241
|
+
let sha = this.#refs.get(ref);
|
|
155
242
|
if (sha) {
|
|
156
243
|
return sha;
|
|
157
244
|
}
|
|
@@ -167,16 +254,24 @@ export class GithubRepository extends Repository {
|
|
|
167
254
|
|
|
168
255
|
sha = json.object.sha;
|
|
169
256
|
|
|
170
|
-
this.#
|
|
257
|
+
this.#refs.set(ref, sha);
|
|
171
258
|
|
|
172
259
|
return sha;
|
|
173
260
|
}
|
|
174
261
|
|
|
175
|
-
|
|
262
|
+
/**
|
|
263
|
+
* {@link https://docs.github.com/en/github-ae@latest/rest/git/refs#update-a-reference}
|
|
264
|
+
* @param {string} ref
|
|
265
|
+
* @param {string} sha
|
|
266
|
+
* @param {Object} options
|
|
267
|
+
* @returns
|
|
268
|
+
*
|
|
269
|
+
* @TODO: belongs into Ref ?
|
|
270
|
+
*/
|
|
176
271
|
async setRefId(ref, sha, options) {
|
|
177
|
-
|
|
272
|
+
ref = ref.replace(/^refs\//, "");
|
|
178
273
|
|
|
179
|
-
const r = await this.provider.fetchJSON(`${this.api}/git/${ref}`, {
|
|
274
|
+
const r = await this.provider.fetchJSON(`${this.api}/git/refs/${ref}`, {
|
|
180
275
|
method: "PATCH",
|
|
181
276
|
body: JSON.stringify({
|
|
182
277
|
...options,
|
|
@@ -184,13 +279,10 @@ export class GithubRepository extends Repository {
|
|
|
184
279
|
})
|
|
185
280
|
});
|
|
186
281
|
|
|
187
|
-
if (r.response.ok
|
|
188
|
-
this.#
|
|
282
|
+
if (r.response.ok) {
|
|
283
|
+
this.#refs.set(ref, sha);
|
|
284
|
+
return r.json;
|
|
189
285
|
}
|
|
190
|
-
|
|
191
|
-
//console.log(ref, sha, r.response.ok, r.response.status, r.json);
|
|
192
|
-
|
|
193
|
-
return r.json;
|
|
194
286
|
}
|
|
195
287
|
|
|
196
288
|
async createBranch(name, from, options) {
|
|
@@ -221,7 +313,6 @@ export class GithubRepository extends Repository {
|
|
|
221
313
|
tree: sha
|
|
222
314
|
})
|
|
223
315
|
});
|
|
224
|
-
console.log(res);
|
|
225
316
|
*/
|
|
226
317
|
}
|
|
227
318
|
|