hdoc-tools 0.17.3 → 0.17.4
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 +2 -2
- package/hdoc-module.js +55 -4
- package/package.json +1 -1
package/hdoc-build.js
CHANGED
@@ -47,7 +47,7 @@
|
|
47
47
|
prod_families = {},
|
48
48
|
prods_supported = [],
|
49
49
|
doc_id = '',
|
50
|
-
git_token = '
|
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
|
51
51
|
hdocbook_config = {},
|
52
52
|
hdocbook_project,
|
53
53
|
includes_found = 0,
|
@@ -429,7 +429,7 @@
|
|
429
429
|
if (hdocbook_config.publicSource && hdocbook_config.publicSource !== '' && hdocbook_config.publicSource.includes('github.com/Hornbill-Docs')) {
|
430
430
|
|
431
431
|
const github_paths = hdoc.get_github_api_path(hdocbook_config.publicSource, file_path.relativePath);
|
432
|
-
const contributors = await hdoc.get_github_contributors(github_paths.api_path, git_token);
|
432
|
+
const contributors = await hdoc.get_github_contributors(github_paths.api_path, git_token, hdocbook_config.publicSource);
|
433
433
|
|
434
434
|
if (!contributors.success) {
|
435
435
|
console.log(`Error retrieving contributors from Github: ${contributors.error}`);
|
package/hdoc-module.js
CHANGED
@@ -233,7 +233,14 @@
|
|
233
233
|
return '';
|
234
234
|
};
|
235
235
|
|
236
|
-
|
236
|
+
const get_github_contributors_path = function (repo) {
|
237
|
+
repo = repo.endsWith('/') ? repo.slice(0, -1) : repo;
|
238
|
+
let github_paths = {};
|
239
|
+
github_paths.api_path = repo.replace('https://github.com/', 'https://api.github.com/repos/');
|
240
|
+
github_paths.api_path += '/contributors';
|
241
|
+
return github_paths;
|
242
|
+
};
|
243
|
+
exports.get_github_contributors = async function (github_url, github_api_token, repo) {
|
237
244
|
let response = {
|
238
245
|
success: false,
|
239
246
|
error: '',
|
@@ -241,7 +248,6 @@
|
|
241
248
|
contributor_count: 0,
|
242
249
|
last_commit_date: ''
|
243
250
|
};
|
244
|
-
|
245
251
|
let contributors = {};
|
246
252
|
|
247
253
|
let request_options = {
|
@@ -259,8 +265,12 @@
|
|
259
265
|
try {
|
260
266
|
github_response = await axios.get(github_url, request_options);
|
261
267
|
} catch (err) {
|
262
|
-
response.
|
263
|
-
|
268
|
+
if (err.response.status !== 403) {
|
269
|
+
response.error = err;
|
270
|
+
return response;
|
271
|
+
} else {
|
272
|
+
github_response = err.response;
|
273
|
+
}
|
264
274
|
}
|
265
275
|
|
266
276
|
if (github_response.status === 200) {
|
@@ -291,6 +301,47 @@
|
|
291
301
|
response.contributors.push(contributors[key]);
|
292
302
|
}
|
293
303
|
}
|
304
|
+
} else if (github_response.status === 403) {
|
305
|
+
// Private repo, fine-grained permissions don't yet support getting commits without content, get list from meta permissions
|
306
|
+
const contrib_url = get_github_contributors_path(repo).api_path;
|
307
|
+
try {
|
308
|
+
github_response = await axios.get(contrib_url, request_options);
|
309
|
+
} catch (err) {
|
310
|
+
if (err.response.status !== 200) {
|
311
|
+
response.error = err;
|
312
|
+
return response;
|
313
|
+
}
|
314
|
+
}
|
315
|
+
if (github_response.status === 200) {
|
316
|
+
response.success = true;
|
317
|
+
let commits = github_response.data;
|
318
|
+
commits.forEach(function (commit) {
|
319
|
+
if (commit.committer && commit.committer.type && commit.committer.type.toLowerCase() === 'user' && commit.committer.login.toLowerCase() !== 'web-flow') {
|
320
|
+
if (!contributors[commit.committer.id]) {
|
321
|
+
response.contributor_count++;
|
322
|
+
contributors[commit.committer.id] = {
|
323
|
+
login: commit.committer.login,
|
324
|
+
avatar_url: commit.committer.avatar_url,
|
325
|
+
html_url: commit.committer.html_url,
|
326
|
+
name: commit.commit.committer.name
|
327
|
+
};
|
328
|
+
}
|
329
|
+
if (response.last_commit_date !== '') {
|
330
|
+
const new_commit_date = new Date(commit.commit.committer.date);
|
331
|
+
const exist_commit_date = new Date(response.last_commit_date);
|
332
|
+
if (new_commit_date > exist_commit_date) response.last_commit_date = commit.commit.committer.date;
|
333
|
+
} else {
|
334
|
+
response.last_commit_date = commit.commit.committer.date;
|
335
|
+
}
|
336
|
+
}
|
337
|
+
});
|
338
|
+
for (const key in contributors) {
|
339
|
+
if (contributors.hasOwnProperty(key)) {
|
340
|
+
response.contributors.push(contributors[key]);
|
341
|
+
}
|
342
|
+
}
|
343
|
+
}
|
344
|
+
|
294
345
|
} else {
|
295
346
|
response.error = `Unexpected Status: ${github_response.status}.`;
|
296
347
|
}
|