github-repository-provider 7.30.17 → 7.30.20
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 +38 -25
- package/package.json +1 -1
- package/src/github-branch.mjs +9 -45
- package/src/github-repository.mjs +71 -21
package/README.md
CHANGED
|
@@ -38,19 +38,17 @@ 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)
|
|
42
|
+
* [Parameters](#parameters-2)
|
|
43
|
+
* [entry](#entry)
|
|
44
44
|
* [Parameters](#parameters-3)
|
|
45
|
-
* [tree](#tree)
|
|
46
|
-
* [Parameters](#parameters-4)
|
|
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
|
|
@@ -113,14 +115,6 @@ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/
|
|
|
113
115
|
* `entries` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<ContentEntry>**
|
|
114
116
|
* `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
|
115
117
|
|
|
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
118
|
### commitForSha
|
|
125
119
|
|
|
126
120
|
<https://developer.github.com/v3/git/commits/#get-a-commit>
|
|
@@ -131,15 +125,13 @@ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/
|
|
|
131
125
|
|
|
132
126
|
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** response
|
|
133
127
|
|
|
134
|
-
###
|
|
128
|
+
### entry
|
|
135
129
|
|
|
136
|
-
|
|
130
|
+
<https://developer.github.com/v3/repos/contents/#get-repository-content>
|
|
137
131
|
|
|
138
132
|
#### Parameters
|
|
139
133
|
|
|
140
|
-
* `
|
|
141
|
-
|
|
142
|
-
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)>**
|
|
134
|
+
* `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
|
143
135
|
|
|
144
136
|
### removeEntries
|
|
145
137
|
|
|
@@ -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,7 +11,6 @@ import {
|
|
|
11
11
|
*/
|
|
12
12
|
export class GithubBranch extends Branch {
|
|
13
13
|
#entries = new Map();
|
|
14
|
-
#trees = new Map();
|
|
15
14
|
#commits = new Map();
|
|
16
15
|
|
|
17
16
|
/**
|
|
@@ -59,30 +58,13 @@ export class GithubBranch extends Branch {
|
|
|
59
58
|
|
|
60
59
|
const shaLatestCommit = await this.refId();
|
|
61
60
|
const commit = await this.commitForSha(shaLatestCommit);
|
|
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);
|
|
61
|
+
const tree = await this.owner.addTree(updates, commit.tree.sha);
|
|
80
62
|
|
|
81
63
|
let r = await this.provider.fetchJSON(`${this.api}/git/commits`, {
|
|
82
64
|
method: "POST",
|
|
83
65
|
body: JSON.stringify({
|
|
84
66
|
message,
|
|
85
|
-
tree:
|
|
67
|
+
tree: tree.sha,
|
|
86
68
|
parents: [shaLatestCommit]
|
|
87
69
|
})
|
|
88
70
|
});
|
|
@@ -112,28 +94,6 @@ export class GithubBranch extends Branch {
|
|
|
112
94
|
return json;
|
|
113
95
|
}
|
|
114
96
|
|
|
115
|
-
/**
|
|
116
|
-
* @see https://developer.github.com/v3/git/trees/
|
|
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`
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
tree = json.tree;
|
|
131
|
-
|
|
132
|
-
this.#trees.set(sha, tree);
|
|
133
|
-
|
|
134
|
-
return tree;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
97
|
/**
|
|
138
98
|
* {@link https://developer.github.com/v3/repos/contents/#get-repository-content}
|
|
139
99
|
* @param {string} name
|
|
@@ -168,9 +128,13 @@ export class GithubBranch extends Branch {
|
|
|
168
128
|
async *entries(patterns) {
|
|
169
129
|
const commit = await this.commitForSha(await this.refId());
|
|
170
130
|
|
|
171
|
-
for (const entry of matcher(
|
|
172
|
-
|
|
173
|
-
|
|
131
|
+
for (const entry of matcher(
|
|
132
|
+
await this.owner.tree(commit.tree.sha),
|
|
133
|
+
patterns,
|
|
134
|
+
{
|
|
135
|
+
name: "path"
|
|
136
|
+
}
|
|
137
|
+
)) {
|
|
174
138
|
switch (entry.type) {
|
|
175
139
|
case "tree":
|
|
176
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,18 +215,26 @@ 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
|
}
|
|
178
224
|
|
|
179
|
-
|
|
225
|
+
/**
|
|
226
|
+
* {@link https://docs.github.com/en/github-ae@latest/rest/git/refs#update-a-reference}
|
|
227
|
+
* @param {string} ref
|
|
228
|
+
* @param {string} sha
|
|
229
|
+
* @param {Object} options
|
|
230
|
+
* @returns
|
|
231
|
+
*
|
|
232
|
+
* @TODO: belongs into Ref ?
|
|
233
|
+
*/
|
|
180
234
|
async setRefId(ref, sha, options) {
|
|
181
|
-
|
|
235
|
+
ref = ref.replace(/^refs\//, "");
|
|
182
236
|
|
|
183
|
-
const r = await this.provider.fetchJSON(`${this.api}/git/${ref}`, {
|
|
237
|
+
const r = await this.provider.fetchJSON(`${this.api}/git/refs/${ref}`, {
|
|
184
238
|
method: "PATCH",
|
|
185
239
|
body: JSON.stringify({
|
|
186
240
|
...options,
|
|
@@ -188,13 +242,10 @@ export class GithubRepository extends Repository {
|
|
|
188
242
|
})
|
|
189
243
|
});
|
|
190
244
|
|
|
191
|
-
if (r.response.ok
|
|
192
|
-
this.#
|
|
245
|
+
if (r.response.ok) {
|
|
246
|
+
this.#refs.set(ref, sha);
|
|
247
|
+
return r.json;
|
|
193
248
|
}
|
|
194
|
-
|
|
195
|
-
//console.log(r.response.ok, r.response.status, r.json);
|
|
196
|
-
|
|
197
|
-
return r.json;
|
|
198
249
|
}
|
|
199
250
|
|
|
200
251
|
async createBranch(name, from, options) {
|
|
@@ -225,7 +276,6 @@ export class GithubRepository extends Repository {
|
|
|
225
276
|
tree: sha
|
|
226
277
|
})
|
|
227
278
|
});
|
|
228
|
-
console.log(res);
|
|
229
279
|
*/
|
|
230
280
|
}
|
|
231
281
|
|