hdoc-tools 0.17.5 → 0.17.6
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/hdoc-module.js +44 -11
- package/hdoc.js +1 -1
- package/package.json +1 -1
package/hdoc-module.js
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
'use strict';
|
3
3
|
|
4
4
|
const axios = require('axios'),
|
5
|
+
axiosRetry = require('axios-retry'),
|
5
6
|
cheerio = require('cheerio'),
|
6
7
|
html2text = require('html-to-text'),
|
7
8
|
https = require('https'),
|
@@ -10,7 +11,18 @@
|
|
10
11
|
let includesCache = {},
|
11
12
|
agent = new https.Agent({
|
12
13
|
rejectUnauthorized: false
|
13
|
-
})
|
14
|
+
}),
|
15
|
+
retried = false;
|
16
|
+
|
17
|
+
axiosRetry(axios, {
|
18
|
+
retries: 5,
|
19
|
+
shouldResetTimeout: true,
|
20
|
+
retryCondition: (_error) => true,
|
21
|
+
onRetry: (retryCount, error, requestConfig) => {
|
22
|
+
retried = true;
|
23
|
+
console.log(`\n[WARNING] API call failed - ${error.message}\nEndpoint: ${requestConfig.url}\nRetrying: ${retryCount}`);
|
24
|
+
},
|
25
|
+
});
|
14
26
|
|
15
27
|
exports.content_type_for_ext = function (ext) {
|
16
28
|
switch (ext) {
|
@@ -132,6 +144,10 @@
|
|
132
144
|
let file_content;
|
133
145
|
try {
|
134
146
|
const file_response = await axios.get(link);
|
147
|
+
if (retried) {
|
148
|
+
retried = false;
|
149
|
+
console.log(`API call retry success!`);
|
150
|
+
}
|
135
151
|
if (file_response.status === 200) {
|
136
152
|
file_content = file_response.data;
|
137
153
|
} else {
|
@@ -226,7 +242,7 @@
|
|
226
242
|
repo = repo.endsWith('/') ? repo.slice(0, -1) : repo;
|
227
243
|
let github_paths = {};
|
228
244
|
github_paths.api_path = repo.replace('https://github.com/', 'https://api.github.com/repos/');
|
229
|
-
github_paths.api_path += '/commits?path
|
245
|
+
github_paths.api_path += '/commits?path=' + encodeURIComponent('/' + relative_path.replace('\\\\', '/').replace('\\', '/'));
|
230
246
|
github_paths.edit_path = repo + '/blob/main/' + relative_path.replace('\\\\', '/').replace('\\', '/');
|
231
247
|
return github_paths;
|
232
248
|
}
|
@@ -240,6 +256,7 @@
|
|
240
256
|
github_paths.api_path += '/contributors';
|
241
257
|
return github_paths;
|
242
258
|
};
|
259
|
+
|
243
260
|
exports.get_github_contributors = async function (github_url, github_api_token, repo) {
|
244
261
|
let response = {
|
245
262
|
success: false,
|
@@ -256,7 +273,8 @@
|
|
256
273
|
'Cache-Control': 'no-cache',
|
257
274
|
'Host': 'api.github.com',
|
258
275
|
'Accept': 'application/json'
|
259
|
-
}
|
276
|
+
},
|
277
|
+
timeout: 5000
|
260
278
|
};
|
261
279
|
if (github_api_token !== '') {
|
262
280
|
request_options.headers.authorization = `Bearer ${github_api_token}`;
|
@@ -264,15 +282,22 @@
|
|
264
282
|
let github_response;
|
265
283
|
try {
|
266
284
|
github_response = await axios.get(github_url, request_options);
|
285
|
+
if (retried) {
|
286
|
+
retried = false;
|
287
|
+
console.log(`API call retry success!`);
|
288
|
+
}
|
267
289
|
} catch (err) {
|
268
|
-
if (err.response
|
269
|
-
response.
|
270
|
-
|
290
|
+
if (err.response) {
|
291
|
+
if (err.response.status !== 403) {
|
292
|
+
response.error = err;
|
293
|
+
return response;
|
294
|
+
} else {
|
295
|
+
github_response = err.response;
|
296
|
+
}
|
271
297
|
} else {
|
272
|
-
|
298
|
+
response.error = `Unexpected response from GitHub for [${github_url}:\n${JSON.stringify(err)}]`
|
273
299
|
}
|
274
300
|
}
|
275
|
-
|
276
301
|
if (github_response.status === 200) {
|
277
302
|
response.success = true;
|
278
303
|
let commits = github_response.data;
|
@@ -306,10 +331,18 @@
|
|
306
331
|
const contrib_url = get_github_contributors_path(repo).api_path;
|
307
332
|
try {
|
308
333
|
github_response = await axios.get(contrib_url, request_options);
|
334
|
+
if (retried) {
|
335
|
+
retried = false;
|
336
|
+
console.log(`API call retry success!`);
|
337
|
+
}
|
309
338
|
} catch (err) {
|
310
|
-
if (err.response.status
|
311
|
-
response.
|
312
|
-
|
339
|
+
if (err.response && err.response.status) {
|
340
|
+
if (err.response.status !== 200) {
|
341
|
+
response.error = err;
|
342
|
+
return response;
|
343
|
+
}
|
344
|
+
} else {
|
345
|
+
response.error = `Unexpected response from GitHub for [${contrib_url}:\n${JSON.stringify(err)}]`
|
313
346
|
}
|
314
347
|
}
|
315
348
|
if (github_response.status === 200) {
|
package/hdoc.js
CHANGED