github-repository-provider 7.24.8 → 7.24.9
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/package.json +1 -1
- package/src/github-branch.mjs +32 -26
- package/src/github-owner.mjs +2 -2
- package/src/github-provider.mjs +16 -12
- package/src/github-pull-request.mjs +3 -3
- package/src/github-repository.mjs +7 -14
package/package.json
CHANGED
package/src/github-branch.mjs
CHANGED
|
@@ -18,13 +18,16 @@ export class GithubBranch extends Branch {
|
|
|
18
18
|
* @return {Promise<ConentEntry>} written content with sha values set
|
|
19
19
|
*/
|
|
20
20
|
async writeEntry(entry) {
|
|
21
|
-
const json = await this.provider.fetchJSON(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
const { json } = await this.provider.fetchJSON(
|
|
22
|
+
`repos/${this.slug}/git/blobs`,
|
|
23
|
+
{
|
|
24
|
+
method: "POST",
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
content: await entry.string,
|
|
27
|
+
encoding: "utf8"
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
);
|
|
28
31
|
|
|
29
32
|
entry.sha = json.sha;
|
|
30
33
|
|
|
@@ -36,7 +39,7 @@ export class GithubBranch extends Branch {
|
|
|
36
39
|
* @param {string} sha
|
|
37
40
|
*/
|
|
38
41
|
async baseTreeSha(sha) {
|
|
39
|
-
const json = await this.provider.fetchJSON(
|
|
42
|
+
const { json } = await this.provider.fetchJSON(
|
|
40
43
|
`repos/${this.slug}/git/commits/${sha}`
|
|
41
44
|
);
|
|
42
45
|
return json.tree.sha;
|
|
@@ -66,24 +69,27 @@ export class GithubBranch extends Branch {
|
|
|
66
69
|
const shaLatestCommit = await this.refId();
|
|
67
70
|
const shaBaseTree = await this.baseTreeSha(shaLatestCommit);
|
|
68
71
|
|
|
69
|
-
let json = await this.provider.fetchJSON(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
let { json } = await this.provider.fetchJSON(
|
|
73
|
+
`repos/${this.slug}/git/trees`,
|
|
74
|
+
{
|
|
75
|
+
method: "POST",
|
|
76
|
+
body: JSON.stringify({
|
|
77
|
+
base_tree: shaBaseTree,
|
|
78
|
+
tree: updates.map(u => {
|
|
79
|
+
return {
|
|
80
|
+
path: u.name,
|
|
81
|
+
sha: u.sha,
|
|
82
|
+
type: "blob",
|
|
83
|
+
mode: "100" + u.mode.toString(8)
|
|
84
|
+
};
|
|
85
|
+
})
|
|
80
86
|
})
|
|
81
|
-
}
|
|
82
|
-
|
|
87
|
+
}
|
|
88
|
+
);
|
|
83
89
|
|
|
84
90
|
const shaNewTree = json.sha;
|
|
85
91
|
|
|
86
|
-
|
|
92
|
+
const r = await this.provider.fetchJSON(`repos/${this.slug}/git/commits`, {
|
|
87
93
|
method: "POST",
|
|
88
94
|
body: JSON.stringify({
|
|
89
95
|
message,
|
|
@@ -92,7 +98,7 @@ export class GithubBranch extends Branch {
|
|
|
92
98
|
})
|
|
93
99
|
});
|
|
94
100
|
|
|
95
|
-
const sha = json.sha;
|
|
101
|
+
const sha = r.json.sha;
|
|
96
102
|
|
|
97
103
|
return await this.provider.fetchJSON(
|
|
98
104
|
`repos/${this.slug}/git/refs/heads/${this.name}`,
|
|
@@ -111,7 +117,7 @@ export class GithubBranch extends Branch {
|
|
|
111
117
|
* @param {string} name
|
|
112
118
|
*/
|
|
113
119
|
async entry(name) {
|
|
114
|
-
const json = await this.provider.fetchJSON(
|
|
120
|
+
const { json } = await this.provider.fetchJSON(
|
|
115
121
|
`repos/${this.slug}/contents/${name}?ref=${this.ref}`
|
|
116
122
|
);
|
|
117
123
|
|
|
@@ -135,7 +141,7 @@ export class GithubBranch extends Branch {
|
|
|
135
141
|
* @return {Object[]}
|
|
136
142
|
*/
|
|
137
143
|
async tree(treeSha) {
|
|
138
|
-
const json = await this.provider.fetchJSON(
|
|
144
|
+
const { json } = await this.provider.fetchJSON(
|
|
139
145
|
`repos/${this.slug}/git/trees/${treeSha}?recursive=1`
|
|
140
146
|
);
|
|
141
147
|
return json.tree;
|
|
@@ -187,7 +193,7 @@ class LazyBufferContentEntry extends BufferContentEntryMixin(ContentEntry) {
|
|
|
187
193
|
}
|
|
188
194
|
|
|
189
195
|
const branch = this.branch;
|
|
190
|
-
const json = await branch.provider.fetchJSON(
|
|
196
|
+
const { json } = await branch.provider.fetchJSON(
|
|
191
197
|
`repos/${branch.slug}/contents/${this.name}?ref=${branch.ref}`
|
|
192
198
|
);
|
|
193
199
|
|
package/src/github-owner.mjs
CHANGED
|
@@ -39,12 +39,12 @@ export class GithubOwner extends RepositoryGroup {
|
|
|
39
39
|
);
|
|
40
40
|
|
|
41
41
|
if (response.ok) {
|
|
42
|
-
this.
|
|
42
|
+
this.info(`Repository ${name} created`);
|
|
43
43
|
options.defaultBranchName = "main";
|
|
44
44
|
return this.addRepository(name, options);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
this.
|
|
47
|
+
this.error(`Repository ${name} creation error ${response.status}`);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
package/src/github-provider.mjs
CHANGED
|
@@ -117,18 +117,24 @@ export class GithubProvider extends MultiGroupProvider {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
async fetchJSON(url, options) {
|
|
120
|
-
let i = 1;
|
|
121
|
-
while (true) {
|
|
120
|
+
for (let i = 1; ; i++) {
|
|
122
121
|
try {
|
|
123
122
|
const response = await this.fetch(url, options);
|
|
124
|
-
if (
|
|
123
|
+
if (response.ok) {
|
|
124
|
+
return { response, json: await response.json() };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (i >= 3 || response.status == 401) {
|
|
128
|
+
// none repeatable
|
|
125
129
|
throw new Error(
|
|
126
|
-
`Unable to fetch ${response.url} (${response.status})
|
|
130
|
+
`Unable to fetch ${response.url} (${response.status})`
|
|
127
131
|
);
|
|
128
132
|
}
|
|
129
|
-
|
|
133
|
+
this.info(
|
|
134
|
+
`Unable to fetch ${response.url} (${response.status}) try #${i}`
|
|
135
|
+
);
|
|
130
136
|
} catch (e) {
|
|
131
|
-
if (i
|
|
137
|
+
if (i >= 3) {
|
|
132
138
|
throw e;
|
|
133
139
|
}
|
|
134
140
|
this.error(e);
|
|
@@ -140,9 +146,9 @@ export class GithubProvider extends MultiGroupProvider {
|
|
|
140
146
|
* {@link https://developer.github.com/v3/repos/#list-repositories-for-the-authenticated-user}
|
|
141
147
|
*/
|
|
142
148
|
async initializeRepositories() {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const json = await this.fetchJSON(
|
|
149
|
+
try {
|
|
150
|
+
for (let page = 1; ; page++) {
|
|
151
|
+
const { json } = await this.fetchJSON(
|
|
146
152
|
`user/repos?page=${page}&per_page=100`,
|
|
147
153
|
{
|
|
148
154
|
headers: {
|
|
@@ -162,10 +168,8 @@ export class GithubProvider extends MultiGroupProvider {
|
|
|
162
168
|
r
|
|
163
169
|
);
|
|
164
170
|
});
|
|
165
|
-
} catch (e) {
|
|
166
|
-
return;
|
|
167
171
|
}
|
|
168
|
-
}
|
|
172
|
+
} catch {}
|
|
169
173
|
}
|
|
170
174
|
|
|
171
175
|
/**
|
|
@@ -43,8 +43,8 @@ export class GithubPullRequest extends PullRequest {
|
|
|
43
43
|
|
|
44
44
|
do {
|
|
45
45
|
const provider = repository.provider;
|
|
46
|
-
const response = await provider.
|
|
47
|
-
for (const node of
|
|
46
|
+
const { response, json } = await provider.fetchJSON(next);
|
|
47
|
+
for (const node of json) {
|
|
48
48
|
const [source, dest] = await Promise.all(
|
|
49
49
|
[node.head, node.base].map(r =>
|
|
50
50
|
provider.branch([r.repo.full_name, r.ref].join("#"))
|
|
@@ -72,7 +72,7 @@ export class GithubPullRequest extends PullRequest {
|
|
|
72
72
|
return p;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
const json = await destination.provider.fetchJSON(
|
|
75
|
+
const { json } = await destination.provider.fetchJSON(
|
|
76
76
|
`repos/${destination.repository.slug}/pulls`,
|
|
77
77
|
{
|
|
78
78
|
method: "POST",
|
|
@@ -37,16 +37,7 @@ export class GithubRepository extends Repository {
|
|
|
37
37
|
let next = `repos/${this.slug}/${typeName}`;
|
|
38
38
|
|
|
39
39
|
do {
|
|
40
|
-
const response = await this.provider.
|
|
41
|
-
|
|
42
|
-
if (!response.ok) {
|
|
43
|
-
this.error(
|
|
44
|
-
`Unable to fetch ${typeName} ${response.status} ${response.url}`
|
|
45
|
-
);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const json = await response.json();
|
|
40
|
+
const { response, json } = await this.provider.fetchJSON(next);
|
|
50
41
|
json.forEach(b => this[addMethodName](b.name, b));
|
|
51
42
|
next = getHeaderLink(response.headers);
|
|
52
43
|
} while (next);
|
|
@@ -112,7 +103,9 @@ export class GithubRepository extends Repository {
|
|
|
112
103
|
async refId(ref) {
|
|
113
104
|
ref = ref.replace(/^refs\//, "");
|
|
114
105
|
|
|
115
|
-
const json = await this.provider.fetchJSON(
|
|
106
|
+
const { json } = await this.provider.fetchJSON(
|
|
107
|
+
`repos/${this.slug}/git/ref/${ref}`
|
|
108
|
+
);
|
|
116
109
|
|
|
117
110
|
// TODO why does this happen ?
|
|
118
111
|
if (!json.object.sha) {
|
|
@@ -147,7 +140,7 @@ export class GithubRepository extends Repository {
|
|
|
147
140
|
console.log(res);
|
|
148
141
|
*/
|
|
149
142
|
} else {
|
|
150
|
-
const json = await this.provider.fetchJSON(
|
|
143
|
+
const { json } = await this.provider.fetchJSON(
|
|
151
144
|
`repos/${this.slug}/git/ref/heads/${
|
|
152
145
|
from === undefined ? this.defaultBranchName : from.name
|
|
153
146
|
}`
|
|
@@ -204,9 +197,9 @@ export class GithubRepository extends Repository {
|
|
|
204
197
|
let next = `repos/${this.slug}/hooks`;
|
|
205
198
|
|
|
206
199
|
do {
|
|
207
|
-
const response = await this.provider.
|
|
200
|
+
const { response, json } = await this.provider.fetchJSON(next);
|
|
208
201
|
|
|
209
|
-
for (const h of
|
|
202
|
+
for (const h of json) {
|
|
210
203
|
const id = h.id;
|
|
211
204
|
delete h.id;
|
|
212
205
|
new this.hookClass(this, id, new Set(h.events), {
|