hdoc-tools 0.17.4 → 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-build.js CHANGED
@@ -47,7 +47,7 @@
47
47
  prod_families = {},
48
48
  prods_supported = [],
49
49
  doc_id = '',
50
- git_token = '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', // Github fine-grained personal access token that has minimum read-only access to Hornbill Docs org repo content
50
+ git_token = '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', // Github fine-grained personal access token that has minimum read-only access to Hornbill Docs metadata
51
51
  hdocbook_config = {},
52
52
  hdocbook_project,
53
53
  includes_found = 0,
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=/' + relative_path.replace('\\\\', '/').replace('\\', '/');
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.status !== 403) {
269
- response.error = err;
270
- return response;
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
- github_response = err.response;
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 !== 200) {
311
- response.error = err;
312
- return response;
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.17.4",
3
+ "version": "0.17.6",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {