github-repository-provider 7.24.6 → 7.24.10
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 +1 -1
- package/package.json +4 -4
- package/src/github-branch.mjs +35 -46
- package/src/github-owner.mjs +2 -2
- package/src/github-provider.mjs +42 -12
- package/src/github-pull-request.mjs +3 -3
- package/src/github-repository.mjs +7 -14
package/README.md
CHANGED
|
@@ -97,7 +97,7 @@ Writes content into the branch
|
|
|
97
97
|
|
|
98
98
|
* `entry` **ConentEntry**
|
|
99
99
|
|
|
100
|
-
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<
|
|
100
|
+
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<ConentEntry>** written content with sha values set
|
|
101
101
|
|
|
102
102
|
### baseTreeSha
|
|
103
103
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "github-repository-provider",
|
|
3
|
-
"version": "7.24.
|
|
3
|
+
"version": "7.24.10",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"matching-iterator": "^2.0.0",
|
|
37
37
|
"node-fetch": "3.1.0",
|
|
38
38
|
"one-time-execution-method": "^2.0.9",
|
|
39
|
-
"repository-provider": "^26.0
|
|
39
|
+
"repository-provider": "^26.1.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"ava": "^3.15.0",
|
|
43
|
-
"c8": "^7.
|
|
43
|
+
"c8": "^7.11.0",
|
|
44
44
|
"documentation": "^13.2.5",
|
|
45
|
-
"repository-provider-test-support": "^1.
|
|
45
|
+
"repository-provider-test-support": "^1.9.0",
|
|
46
46
|
"semantic-release": "^18.0.1"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
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,27 +141,10 @@ export class GithubBranch extends Branch {
|
|
|
135
141
|
* @return {Object[]}
|
|
136
142
|
*/
|
|
137
143
|
async tree(treeSha) {
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
try {
|
|
143
|
-
res = await this.provider.fetch(url);
|
|
144
|
-
if (res.ok) {
|
|
145
|
-
const json = await res.json();
|
|
146
|
-
return json.tree;
|
|
147
|
-
}
|
|
148
|
-
} catch (e) {
|
|
149
|
-
// errno: 'ERR_STREAM_PREMATURE_CLOSE',
|
|
150
|
-
// code: 'ERR_STREAM_PREMATURE_CLOSE',
|
|
151
|
-
|
|
152
|
-
this.error(e);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
console.log(res.errno, res.code);
|
|
157
|
-
|
|
158
|
-
throw new Error(res.status);
|
|
144
|
+
const { json } = await this.provider.fetchJSON(
|
|
145
|
+
`repos/${this.slug}/git/trees/${treeSha}?recursive=1`
|
|
146
|
+
);
|
|
147
|
+
return json.tree;
|
|
159
148
|
}
|
|
160
149
|
|
|
161
150
|
async *entries(patterns) {
|
|
@@ -204,7 +193,7 @@ class LazyBufferContentEntry extends BufferContentEntryMixin(ContentEntry) {
|
|
|
204
193
|
}
|
|
205
194
|
|
|
206
195
|
const branch = this.branch;
|
|
207
|
-
const json = await branch.provider.fetchJSON(
|
|
196
|
+
const { json } = await branch.provider.fetchJSON(
|
|
208
197
|
`repos/${branch.slug}/contents/${this.name}?ref=${branch.ref}`
|
|
209
198
|
);
|
|
210
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
|
@@ -64,9 +64,22 @@ export class GithubProvider extends MultiGroupProvider {
|
|
|
64
64
|
set: value => value.replace(/\/$/, ""),
|
|
65
65
|
default: `https://api.${domain}`
|
|
66
66
|
},
|
|
67
|
+
/*
|
|
68
|
+
domain : {
|
|
69
|
+
type: "string",
|
|
70
|
+
env: ["GH_HOST"],
|
|
71
|
+
default: "github.com"
|
|
72
|
+
},
|
|
73
|
+
*/
|
|
67
74
|
"authentication.token": {
|
|
68
75
|
type: "string",
|
|
69
|
-
|
|
76
|
+
// @see https://cli.github.com/manual/gh_help_environment
|
|
77
|
+
env: [
|
|
78
|
+
"{{instanceIdentifier}}TOKEN",
|
|
79
|
+
"GH_TOKEN",
|
|
80
|
+
"GITHUB_ENTERPRISE_TOKEN",
|
|
81
|
+
"GH_ENTERPRISE_TOKEN"
|
|
82
|
+
],
|
|
70
83
|
additionalAttributes: { "authentication.type": "token" },
|
|
71
84
|
private: true,
|
|
72
85
|
mandatory: true
|
|
@@ -117,16 +130,27 @@ export class GithubProvider extends MultiGroupProvider {
|
|
|
117
130
|
}
|
|
118
131
|
|
|
119
132
|
async fetchJSON(url, options) {
|
|
120
|
-
for (let i =
|
|
133
|
+
for (let i = 1; ; i++) {
|
|
121
134
|
try {
|
|
122
135
|
const response = await this.fetch(url, options);
|
|
123
|
-
if (
|
|
124
|
-
|
|
136
|
+
if (response.ok) {
|
|
137
|
+
return { response, json: await response.json() };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (i >= 3 || response.status == 401) {
|
|
141
|
+
// none repeatable
|
|
142
|
+
throw new Error(
|
|
143
|
+
`Unable to fetch ${response.url} (${response.status})`
|
|
144
|
+
);
|
|
125
145
|
}
|
|
126
|
-
|
|
146
|
+
this.info(
|
|
147
|
+
`Unable to fetch ${response.url} (${response.status}) try #${i}`
|
|
148
|
+
);
|
|
127
149
|
} catch (e) {
|
|
150
|
+
if (i >= 3) {
|
|
151
|
+
throw e;
|
|
152
|
+
}
|
|
128
153
|
this.error(e);
|
|
129
|
-
throw e;
|
|
130
154
|
}
|
|
131
155
|
}
|
|
132
156
|
}
|
|
@@ -135,9 +159,9 @@ export class GithubProvider extends MultiGroupProvider {
|
|
|
135
159
|
* {@link https://developer.github.com/v3/repos/#list-repositories-for-the-authenticated-user}
|
|
136
160
|
*/
|
|
137
161
|
async initializeRepositories() {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const json = await this.fetchJSON(
|
|
162
|
+
try {
|
|
163
|
+
for (let page = 1; ; page++) {
|
|
164
|
+
const { json } = await this.fetchJSON(
|
|
141
165
|
`user/repos?page=${page}&per_page=100`,
|
|
142
166
|
{
|
|
143
167
|
headers: {
|
|
@@ -157,10 +181,8 @@ export class GithubProvider extends MultiGroupProvider {
|
|
|
157
181
|
r
|
|
158
182
|
);
|
|
159
183
|
});
|
|
160
|
-
} catch (e) {
|
|
161
|
-
return;
|
|
162
184
|
}
|
|
163
|
-
}
|
|
185
|
+
} catch {}
|
|
164
186
|
}
|
|
165
187
|
|
|
166
188
|
/**
|
|
@@ -202,3 +224,11 @@ replaceWithOneTimeExecutionMethod(
|
|
|
202
224
|
);
|
|
203
225
|
|
|
204
226
|
export default GithubProvider;
|
|
227
|
+
|
|
228
|
+
/*
|
|
229
|
+
{
|
|
230
|
+
"400" : { repeat: 3, timeout: 100 }
|
|
231
|
+
"401" : { repeat: 0 }
|
|
232
|
+
"500" : { repeat: 3, timeout: 100 }
|
|
233
|
+
}
|
|
234
|
+
*/
|
|
@@ -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), {
|