github-repository-provider 7.23.46 → 7.24.3
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 +3 -3
- package/src/github-branch.mjs +5 -11
- package/src/github-provider.mjs +37 -20
- package/src/github-repository.mjs +2 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "github-repository-provider",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.24.3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"lint:docs": "documentation lint ./src/**/*.mjs"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"content-entry": "^3.0.
|
|
33
|
+
"content-entry": "^3.0.2",
|
|
34
34
|
"fetch-link-util": "^1.0.4",
|
|
35
35
|
"fetch-rate-limit-util": "^1.1.6",
|
|
36
36
|
"matching-iterator": "^2.0.0",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"ava": "^3.15.0",
|
|
43
43
|
"c8": "^7.10.0",
|
|
44
44
|
"documentation": "^13.2.5",
|
|
45
|
-
"repository-provider-test-support": "^1.8.
|
|
45
|
+
"repository-provider-test-support": "^1.8.13",
|
|
46
46
|
"semantic-release": "^18.0.1"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
package/src/github-branch.mjs
CHANGED
|
@@ -72,7 +72,7 @@ export class GithubBranch extends Branch {
|
|
|
72
72
|
const shaLatestCommit = await this.refId();
|
|
73
73
|
const shaBaseTree = await this.baseTreeSha(shaLatestCommit);
|
|
74
74
|
|
|
75
|
-
let
|
|
75
|
+
let json = await this.provider.fetchJSON(`repos/${this.slug}/git/trees`, {
|
|
76
76
|
method: "POST",
|
|
77
77
|
body: JSON.stringify({
|
|
78
78
|
base_tree: shaBaseTree,
|
|
@@ -87,11 +87,9 @@ export class GithubBranch extends Branch {
|
|
|
87
87
|
})
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
let json = await result.json();
|
|
91
|
-
|
|
92
90
|
const shaNewTree = json.sha;
|
|
93
91
|
|
|
94
|
-
|
|
92
|
+
json = await this.provider.fetchJSON(`repos/${this.slug}/git/commits`, {
|
|
95
93
|
method: "POST",
|
|
96
94
|
body: JSON.stringify({
|
|
97
95
|
message,
|
|
@@ -99,11 +97,10 @@ export class GithubBranch extends Branch {
|
|
|
99
97
|
parents: [shaLatestCommit]
|
|
100
98
|
})
|
|
101
99
|
});
|
|
102
|
-
json = await result.json();
|
|
103
100
|
|
|
104
101
|
const sha = json.sha;
|
|
105
102
|
|
|
106
|
-
|
|
103
|
+
return await this.provider.fetchJSON(
|
|
107
104
|
`repos/${this.slug}/git/refs/heads/${this.name}`,
|
|
108
105
|
{
|
|
109
106
|
method: "PATCH",
|
|
@@ -113,8 +110,6 @@ export class GithubBranch extends Branch {
|
|
|
113
110
|
})
|
|
114
111
|
}
|
|
115
112
|
);
|
|
116
|
-
|
|
117
|
-
return result.json();
|
|
118
113
|
}
|
|
119
114
|
|
|
120
115
|
/**
|
|
@@ -163,9 +158,8 @@ export class GithubBranch extends Branch {
|
|
|
163
158
|
}
|
|
164
159
|
} catch (e) {
|
|
165
160
|
// errno: 'ERR_STREAM_PREMATURE_CLOSE',
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
console.error(e);
|
|
161
|
+
// code: 'ERR_STREAM_PREMATURE_CLOSE',
|
|
162
|
+
|
|
169
163
|
this.error(e);
|
|
170
164
|
}
|
|
171
165
|
}
|
package/src/github-provider.mjs
CHANGED
|
@@ -42,7 +42,7 @@ 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_";
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
static get attributes() {
|
|
@@ -116,34 +116,51 @@ export class GithubProvider extends MultiGroupProvider {
|
|
|
116
116
|
);
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
async fetchJSON(url, options) {
|
|
120
|
+
for (let i = 0; i < 3; i++) {
|
|
121
|
+
try {
|
|
122
|
+
const response = await this.fetch(url, options);
|
|
123
|
+
if (!response.ok) {
|
|
124
|
+
this.error(`Unable to fetch ${response.status} ${response.url}`);
|
|
125
|
+
throw new Error(`Unable to fetch ${response.status} ${response.url}`);
|
|
126
|
+
}
|
|
127
|
+
return await response.json();
|
|
128
|
+
} catch (e) {
|
|
129
|
+
this.error(e);
|
|
130
|
+
throw e;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
119
135
|
/**
|
|
120
136
|
* {@link https://developer.github.com/v3/repos/#list-repositories-for-the-authenticated-user}
|
|
121
137
|
*/
|
|
122
138
|
async initializeRepositories() {
|
|
123
139
|
for (let page = 1; ; page++) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
140
|
+
try {
|
|
141
|
+
const json = await this.fetchJSON(
|
|
142
|
+
`user/repos?page=${page}&per_page=100`,
|
|
143
|
+
{
|
|
144
|
+
headers: {
|
|
145
|
+
accept: "application/vnd.github.baptiste-preview+json"
|
|
146
|
+
// accept: "application/vnd.github.v3+json"
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
if (json.length === 0 || !Array.isArray(json)) {
|
|
151
|
+
break;
|
|
127
152
|
}
|
|
128
|
-
});
|
|
129
153
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
154
|
+
json.forEach(r => {
|
|
155
|
+
const [groupName, repoName] = r.full_name.split(/\//);
|
|
156
|
+
this.addRepositoryGroup(groupName, r.owner).addRepository(
|
|
157
|
+
repoName,
|
|
158
|
+
r
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
} catch (e) {
|
|
134
162
|
return;
|
|
135
163
|
}
|
|
136
|
-
|
|
137
|
-
const json = await response.json();
|
|
138
|
-
|
|
139
|
-
if (json.length === 0 || !Array.isArray(json)) {
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
json.forEach(r => {
|
|
144
|
-
const [groupName, repoName] = r.full_name.split(/\//);
|
|
145
|
-
this.addRepositoryGroup(groupName, r.owner).addRepository(repoName, r);
|
|
146
|
-
});
|
|
147
164
|
}
|
|
148
165
|
}
|
|
149
166
|
|
|
@@ -112,13 +112,7 @@ export class GithubRepository extends Repository {
|
|
|
112
112
|
async refId(ref) {
|
|
113
113
|
ref = ref.replace(/^refs\//, "");
|
|
114
114
|
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
if (!res.ok) {
|
|
118
|
-
throw new Error(`Unable to fetch ${res.url}: ${res.code}`);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const json = await res.json();
|
|
115
|
+
const json = await this.provider.fetchJSON(`repos/${this.slug}/git/ref/${ref}`);
|
|
122
116
|
|
|
123
117
|
// TODO why does this happen ?
|
|
124
118
|
if (!json.object.sha) {
|
|
@@ -153,12 +147,11 @@ export class GithubRepository extends Repository {
|
|
|
153
147
|
console.log(res);
|
|
154
148
|
*/
|
|
155
149
|
} else {
|
|
156
|
-
const
|
|
150
|
+
const json = await this.provider.fetchJSON(
|
|
157
151
|
`repos/${this.slug}/git/ref/heads/${
|
|
158
152
|
from === undefined ? this.defaultBranchName : from.name
|
|
159
153
|
}`
|
|
160
154
|
);
|
|
161
|
-
let json = await res.json();
|
|
162
155
|
sha = json.object.sha;
|
|
163
156
|
}
|
|
164
157
|
|