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