github-repository-provider 7.24.8 → 7.25.1
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 +4 -4
- package/src/github-branch.mjs +32 -26
- package/src/github-owner.mjs +2 -2
- package/src/github-provider.mjs +43 -29
- package/src/github-pull-request.mjs +3 -3
- package/src/github-repository.mjs +7 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "github-repository-provider",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.25.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -32,17 +32,17 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"content-entry": "^3.0.2",
|
|
34
34
|
"fetch-link-util": "^1.0.4",
|
|
35
|
-
"fetch-rate-limit-util": "^
|
|
35
|
+
"fetch-rate-limit-util": "^2.0.2",
|
|
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.
|
|
39
|
+
"repository-provider": "^26.1.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"ava": "^3.15.0",
|
|
43
43
|
"c8": "^7.11.0",
|
|
44
44
|
"documentation": "^13.2.5",
|
|
45
|
-
"repository-provider-test-support": "^1.9.
|
|
45
|
+
"repository-provider-test-support": "^1.9.1",
|
|
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,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
|
@@ -9,7 +9,7 @@ import { GithubOwner } from "./github-owner.mjs";
|
|
|
9
9
|
import { GithubPullRequest } from "./github-pull-request.mjs";
|
|
10
10
|
export { GithubRepository, GithubBranch, GithubOwner, GithubPullRequest };
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const host = "github.com";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* <!-- skip-example -->
|
|
@@ -42,31 +42,40 @@ export class GithubProvider extends MultiGroupProvider {
|
|
|
42
42
|
* @return {string} default instance environment name prefix
|
|
43
43
|
*/
|
|
44
44
|
static get instanceIdentifier() {
|
|
45
|
-
return "GITHUB_";
|
|
45
|
+
return "GITHUB_"; // "GH_" "GH_ENTERPRISE_"
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
static get attributes() {
|
|
49
49
|
return {
|
|
50
50
|
...super.attributes,
|
|
51
|
+
host: {
|
|
52
|
+
type: "string",
|
|
53
|
+
env: ["{{instanceIdentifier}}HOST", "GH_HOST"],
|
|
54
|
+
default: "github.com"
|
|
55
|
+
},
|
|
51
56
|
ssh: {
|
|
52
57
|
type: "url",
|
|
53
|
-
default: `git@${
|
|
58
|
+
default: `git@${host}:`
|
|
54
59
|
},
|
|
55
60
|
url: {
|
|
56
61
|
type: "url",
|
|
57
62
|
env: ["{{instanceIdentifier}}SERVER_URL"],
|
|
58
63
|
set: value => (value.endsWith("/") ? value : value + "/"),
|
|
59
|
-
default: `https://${
|
|
64
|
+
default: `https://${host}/`
|
|
60
65
|
},
|
|
61
66
|
api: {
|
|
62
67
|
type: "url",
|
|
63
68
|
env: ["{{instanceIdentifier}}API_URL"],
|
|
64
69
|
set: value => value.replace(/\/$/, ""),
|
|
65
|
-
default: `https://api.${
|
|
70
|
+
default: `https://api.${host}`
|
|
66
71
|
},
|
|
67
72
|
"authentication.token": {
|
|
68
73
|
type: "string",
|
|
69
|
-
|
|
74
|
+
// @see https://cli.github.com/manual/gh_help_environment
|
|
75
|
+
env: [
|
|
76
|
+
"{{instanceIdentifier}}TOKEN",
|
|
77
|
+
"GH_TOKEN" // declare GH_ as identifier
|
|
78
|
+
],
|
|
70
79
|
additionalAttributes: { "authentication.type": "token" },
|
|
71
80
|
private: true,
|
|
72
81
|
mandatory: true
|
|
@@ -90,14 +99,15 @@ export class GithubProvider extends MultiGroupProvider {
|
|
|
90
99
|
|
|
91
100
|
fetch(url, options = {}) {
|
|
92
101
|
return rateLimitHandler(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
102
|
+
fetch,
|
|
103
|
+
new URL(url, this.api),
|
|
104
|
+
{
|
|
105
|
+
...options,
|
|
106
|
+
headers: {
|
|
107
|
+
authorization: `token ${this.authentication.token}`,
|
|
108
|
+
...options.headers
|
|
109
|
+
}
|
|
110
|
+
},
|
|
101
111
|
(millisecondsToWait, rateLimitRemaining, nthTry, response) => {
|
|
102
112
|
this.rateLimitRemaining = rateLimitRemaining;
|
|
103
113
|
|
|
@@ -117,18 +127,24 @@ export class GithubProvider extends MultiGroupProvider {
|
|
|
117
127
|
}
|
|
118
128
|
|
|
119
129
|
async fetchJSON(url, options) {
|
|
120
|
-
let i = 1;
|
|
121
|
-
while (true) {
|
|
130
|
+
for (let i = 1; ; i++) {
|
|
122
131
|
try {
|
|
123
132
|
const response = await this.fetch(url, options);
|
|
124
|
-
if (
|
|
133
|
+
if (response.ok) {
|
|
134
|
+
return { response, json: await response.json() };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (i >= 3 || response.status == 401) {
|
|
138
|
+
// none repeatable
|
|
125
139
|
throw new Error(
|
|
126
|
-
`Unable to fetch ${response.url} (${response.status})
|
|
140
|
+
`Unable to fetch ${response.url} (${response.status})`
|
|
127
141
|
);
|
|
128
142
|
}
|
|
129
|
-
|
|
143
|
+
this.info(
|
|
144
|
+
`Unable to fetch ${response.url} (${response.status}) try #${i}`
|
|
145
|
+
);
|
|
130
146
|
} catch (e) {
|
|
131
|
-
if (i
|
|
147
|
+
if (i >= 3) {
|
|
132
148
|
throw e;
|
|
133
149
|
}
|
|
134
150
|
this.error(e);
|
|
@@ -140,9 +156,9 @@ export class GithubProvider extends MultiGroupProvider {
|
|
|
140
156
|
* {@link https://developer.github.com/v3/repos/#list-repositories-for-the-authenticated-user}
|
|
141
157
|
*/
|
|
142
158
|
async initializeRepositories() {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const json = await this.fetchJSON(
|
|
159
|
+
try {
|
|
160
|
+
for (let page = 1; ; page++) {
|
|
161
|
+
const { json } = await this.fetchJSON(
|
|
146
162
|
`user/repos?page=${page}&per_page=100`,
|
|
147
163
|
{
|
|
148
164
|
headers: {
|
|
@@ -162,10 +178,8 @@ export class GithubProvider extends MultiGroupProvider {
|
|
|
162
178
|
r
|
|
163
179
|
);
|
|
164
180
|
});
|
|
165
|
-
} catch (e) {
|
|
166
|
-
return;
|
|
167
181
|
}
|
|
168
|
-
}
|
|
182
|
+
} catch {}
|
|
169
183
|
}
|
|
170
184
|
|
|
171
185
|
/**
|
|
@@ -182,9 +196,9 @@ export class GithubProvider extends MultiGroupProvider {
|
|
|
182
196
|
return super.repositoryBases.concat([
|
|
183
197
|
this.url,
|
|
184
198
|
"git+" + this.url,
|
|
185
|
-
`git+ssh://${
|
|
186
|
-
`git://${
|
|
187
|
-
`git@${
|
|
199
|
+
`git+ssh://${host}`,
|
|
200
|
+
`git://${host}/`,
|
|
201
|
+
`git@${host}:`
|
|
188
202
|
]);
|
|
189
203
|
}
|
|
190
204
|
|
|
@@ -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), {
|