volunteer-contributions-fetch 2.3.2 → 2.3.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/.eslintrc +1 -1
- package/.github/workflows/release.yml +2 -2
- package/.github/workflows/test.yml +13 -13
- package/.prettierignore +4 -0
- package/README.md +71 -71
- package/fixtures/community-portal.js +184 -172
- package/lib/bugzilla.js +21 -12
- package/lib/bugzilla.test.js +59 -48
- package/lib/community-portal.js +20 -14
- package/lib/community-portal.test.js +30 -18
- package/lib/discourse.js +7 -6
- package/lib/discourse.test.js +31 -28
- package/lib/fetch.js +25 -14
- package/lib/fetch.test.js +34 -17
- package/lib/github-fetcher.js +11 -1
- package/lib/github.js +75 -35
- package/lib/github.test.js +526 -403
- package/lib/wiki.js +27 -41
- package/lib/wiki.test.js +11 -10
- package/package.json +16 -8
package/lib/github.js
CHANGED
|
@@ -55,8 +55,10 @@ async function gather({ github }, existingContributions = []) {
|
|
|
55
55
|
return contribution.source === GITHUB_COMMIT_CATEGORY;
|
|
56
56
|
}) || { createdAt: github.stopDate };
|
|
57
57
|
const latestIssue = existingContributions.find((contribution) => {
|
|
58
|
-
return
|
|
59
|
-
|
|
58
|
+
return (
|
|
59
|
+
contribution.source === GITHUB_ISSUES_CREATED_CATEGORY ||
|
|
60
|
+
contribution.source === GITHUB_PR_CREATED_CATEGORY
|
|
61
|
+
);
|
|
60
62
|
}) || { createdAt: github.stopDate };
|
|
61
63
|
const latestReview = existingContributions.find((contribution) => {
|
|
62
64
|
return contribution.source === GITHUB_REVIEW_CATEGORY;
|
|
@@ -68,9 +70,11 @@ async function gather({ github }, existingContributions = []) {
|
|
|
68
70
|
try {
|
|
69
71
|
await fetcher.throwIfTokenHasPrivateRepoScope();
|
|
70
72
|
} catch (error) {
|
|
71
|
-
if (error.message ===
|
|
73
|
+
if (error.message === fetcher.PRIVATE_SCOPE_ERROR) {
|
|
72
74
|
if (!github.allowPrivate) {
|
|
73
|
-
throw new Error(
|
|
75
|
+
throw new Error(
|
|
76
|
+
'GITHUB_TOKEN might have private repo scope, but the config does not specify `allowPrivate` to fetch private repos. Are you sure you want to fetch private information? This might also be because you passed a fine-grained token. In that case we can not check the permissions it has and we assume it is private. You can double check the permissions and if you are sure it is correct, you may set `allowPrivate` to true.'
|
|
77
|
+
);
|
|
74
78
|
}
|
|
75
79
|
} else {
|
|
76
80
|
throw error;
|
|
@@ -81,19 +85,17 @@ async function gather({ github }, existingContributions = []) {
|
|
|
81
85
|
const issues = await processIssues(github, latestIssue.createdAt);
|
|
82
86
|
const reviews = await processReviews(github, latestReview.createdAt);
|
|
83
87
|
const comments = await processComments(github, latestComment.createdAt);
|
|
84
|
-
const contributions = [
|
|
85
|
-
...commits,
|
|
86
|
-
...issues,
|
|
87
|
-
...reviews,
|
|
88
|
-
...comments,
|
|
89
|
-
];
|
|
88
|
+
const contributions = [...commits, ...issues, ...reviews, ...comments];
|
|
90
89
|
|
|
91
90
|
debug('Finished gathering contributions');
|
|
92
91
|
return contributions;
|
|
93
92
|
}
|
|
94
93
|
|
|
95
94
|
async function processIssues(github, latestCreationDate) {
|
|
96
|
-
if (
|
|
95
|
+
if (
|
|
96
|
+
typeof github.issuesEnabled !== 'undefined' &&
|
|
97
|
+
github.issuesEnabled === false
|
|
98
|
+
) {
|
|
97
99
|
debug('Fetching issues is disabled, skipping!');
|
|
98
100
|
return [];
|
|
99
101
|
}
|
|
@@ -104,10 +106,8 @@ async function processIssues(github, latestCreationDate) {
|
|
|
104
106
|
const lowerBoundDate = new Date(latestCreationDate);
|
|
105
107
|
const generatedPeriod = periodGenerator(github.stopDate, lowerBoundDate);
|
|
106
108
|
for await (const periodChunk of generatedPeriod) {
|
|
107
|
-
const currentPage = pageGenerator(
|
|
108
|
-
github,
|
|
109
|
-
periodChunk,
|
|
110
|
-
(period, page) => getIssuePage(github, 'author', period, page)
|
|
109
|
+
const currentPage = pageGenerator(github, periodChunk, (period, page) =>
|
|
110
|
+
getIssuePage(github, 'author', period, page)
|
|
111
111
|
);
|
|
112
112
|
for await (const issues of currentPage) {
|
|
113
113
|
debug(`Got ${issues.length} issues`);
|
|
@@ -121,7 +121,10 @@ async function processIssues(github, latestCreationDate) {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
async function processCommits(github, latestCreationDate) {
|
|
124
|
-
if (
|
|
124
|
+
if (
|
|
125
|
+
typeof github.commitsEnabled !== 'undefined' &&
|
|
126
|
+
github.commitsEnabled === false
|
|
127
|
+
) {
|
|
125
128
|
debug('Fetching commits is disabled, skipping!');
|
|
126
129
|
return [];
|
|
127
130
|
}
|
|
@@ -132,10 +135,8 @@ async function processCommits(github, latestCreationDate) {
|
|
|
132
135
|
const lowerBoundDate = new Date(latestCreationDate);
|
|
133
136
|
const generatedPeriod = periodGenerator(github.stopDate, lowerBoundDate);
|
|
134
137
|
for await (const periodChunk of generatedPeriod) {
|
|
135
|
-
const currentPage = pageGenerator(
|
|
136
|
-
github,
|
|
137
|
-
periodChunk,
|
|
138
|
-
(period, page) => getCommitPage(github, period, page)
|
|
138
|
+
const currentPage = pageGenerator(github, periodChunk, (period, page) =>
|
|
139
|
+
getCommitPage(github, period, page)
|
|
139
140
|
);
|
|
140
141
|
for await (const commits of currentPage) {
|
|
141
142
|
debug(`Got ${commits.length} commits`);
|
|
@@ -149,7 +150,10 @@ async function processCommits(github, latestCreationDate) {
|
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
async function processReviews(github, latestCreationDate) {
|
|
152
|
-
if (
|
|
153
|
+
if (
|
|
154
|
+
typeof github.reviewsEnabled !== 'undefined' &&
|
|
155
|
+
github.reviewsEnabled === false
|
|
156
|
+
) {
|
|
153
157
|
debug('Fetching reviews is disabled, skipping!');
|
|
154
158
|
return [];
|
|
155
159
|
}
|
|
@@ -184,19 +188,30 @@ async function processReviews(github, latestCreationDate) {
|
|
|
184
188
|
// Now that we have all the PRs, we need to fetch the reviews
|
|
185
189
|
const allReviews = [];
|
|
186
190
|
|
|
187
|
-
const prReviewsList = getPRReviews(
|
|
191
|
+
const prReviewsList = getPRReviews(
|
|
192
|
+
allPRs.flat(),
|
|
193
|
+
github.username,
|
|
194
|
+
github.delayMsPerRequest
|
|
195
|
+
);
|
|
188
196
|
for await (const prReviews of prReviewsList) {
|
|
189
197
|
allReviews.push(prReviews);
|
|
190
198
|
}
|
|
191
199
|
|
|
192
|
-
const processedReviews = processEntities(
|
|
200
|
+
const processedReviews = processEntities(
|
|
201
|
+
github,
|
|
202
|
+
allReviews.flat(),
|
|
203
|
+
prTitleMap
|
|
204
|
+
);
|
|
193
205
|
return processedReviews.filter((review) => {
|
|
194
206
|
return new Date(review.createdAt) > new Date(latestCreationDate);
|
|
195
207
|
});
|
|
196
208
|
}
|
|
197
209
|
|
|
198
210
|
async function processComments(github, latestCreationDate) {
|
|
199
|
-
if (
|
|
211
|
+
if (
|
|
212
|
+
typeof github.commentsEnabled !== 'undefined' &&
|
|
213
|
+
github.commentsEnabled === false
|
|
214
|
+
) {
|
|
200
215
|
debug('Fetching comments is disabled, skipping!');
|
|
201
216
|
return [];
|
|
202
217
|
}
|
|
@@ -225,8 +240,11 @@ async function processComments(github, latestCreationDate) {
|
|
|
225
240
|
}
|
|
226
241
|
|
|
227
242
|
const commentTitleMap = new Map();
|
|
228
|
-
allCommentedIssues
|
|
229
|
-
.
|
|
243
|
+
allCommentedIssues
|
|
244
|
+
.flat()
|
|
245
|
+
.forEach((commentIssue) =>
|
|
246
|
+
commentTitleMap.set(commentIssue.url, commentIssue.title)
|
|
247
|
+
);
|
|
230
248
|
|
|
231
249
|
// Now that we have all the commented issues, we need to fetch the actual comments
|
|
232
250
|
const allComments = [];
|
|
@@ -240,7 +258,11 @@ async function processComments(github, latestCreationDate) {
|
|
|
240
258
|
allComments.push(comments);
|
|
241
259
|
}
|
|
242
260
|
|
|
243
|
-
const processedComments = processEntities(
|
|
261
|
+
const processedComments = processEntities(
|
|
262
|
+
github,
|
|
263
|
+
allComments.flat(),
|
|
264
|
+
commentTitleMap
|
|
265
|
+
);
|
|
244
266
|
return processedComments.filter((comment) => {
|
|
245
267
|
return new Date(comment.createdAt) > new Date(latestCreationDate);
|
|
246
268
|
});
|
|
@@ -274,10 +296,14 @@ function getNextPeriod(stopDate, period, lowerBoundDate) {
|
|
|
274
296
|
|
|
275
297
|
async function* periodGenerator(stopDate, lowerBoundDate) {
|
|
276
298
|
const date = new Date();
|
|
277
|
-
const firstOfThisMonth = `${date.getFullYear()}-${getPadded(
|
|
299
|
+
const firstOfThisMonth = `${date.getFullYear()}-${getPadded(
|
|
300
|
+
date.getMonth() + 1
|
|
301
|
+
)}-01`;
|
|
278
302
|
date.setMonth(date.getMonth() + 1);
|
|
279
303
|
date.setDate(0);
|
|
280
|
-
const lastOfThisMonth = `${date.getFullYear()}-${getPadded(
|
|
304
|
+
const lastOfThisMonth = `${date.getFullYear()}-${getPadded(
|
|
305
|
+
date.getMonth() + 1
|
|
306
|
+
)}-${date.getDate()}`;
|
|
281
307
|
let currentPeriod = [lastOfThisMonth, firstOfThisMonth];
|
|
282
308
|
while (true) {
|
|
283
309
|
yield currentPeriod;
|
|
@@ -310,7 +336,11 @@ async function* pageGenerator(github, period, cb, { skipProcessing } = {}) {
|
|
|
310
336
|
}
|
|
311
337
|
}
|
|
312
338
|
|
|
313
|
-
async function getCommitPage(
|
|
339
|
+
async function getCommitPage(
|
|
340
|
+
{ username, delayMsPerRequest },
|
|
341
|
+
commitsPeriod,
|
|
342
|
+
page
|
|
343
|
+
) {
|
|
314
344
|
const [before, after] = commitsPeriod;
|
|
315
345
|
|
|
316
346
|
debug(`Getting commits page ${page} between ${after} and ${before}`);
|
|
@@ -383,7 +413,9 @@ async function* getPRReviews(prList, reviewerUsername, delay) {
|
|
|
383
413
|
debug('Getting PR reviews');
|
|
384
414
|
for await (const pr of prList) {
|
|
385
415
|
try {
|
|
386
|
-
const [, owner, repo] = /github\.com\/repos\/(.+)\/(.*)/.exec(
|
|
416
|
+
const [, owner, repo] = /github\.com\/repos\/(.+)\/(.*)/.exec(
|
|
417
|
+
pr.repository_url
|
|
418
|
+
);
|
|
387
419
|
// We're waiting for a bit here, as we've previously hit a secondary GitHub rate limit...
|
|
388
420
|
await waitFor(delay ?? DELAY_FETCHING_MS);
|
|
389
421
|
debug(`Fetching reviews for ${owner}/${repo} PR ${pr.number}`);
|
|
@@ -393,7 +425,9 @@ async function* getPRReviews(prList, reviewerUsername, delay) {
|
|
|
393
425
|
pull_number: pr.number,
|
|
394
426
|
});
|
|
395
427
|
|
|
396
|
-
const onlyMyReviews = items.filter(
|
|
428
|
+
const onlyMyReviews = items.filter(
|
|
429
|
+
(review) => review.user.login === reviewerUsername
|
|
430
|
+
);
|
|
397
431
|
|
|
398
432
|
yield onlyMyReviews;
|
|
399
433
|
} catch (error) {
|
|
@@ -409,7 +443,9 @@ async function* getComments(issueList, commenterUsername, delay) {
|
|
|
409
443
|
debug('Getting comments');
|
|
410
444
|
for await (const issue of issueList) {
|
|
411
445
|
try {
|
|
412
|
-
const [, owner, repo] = /github\.com\/repos\/(.+)\/(.*)/.exec(
|
|
446
|
+
const [, owner, repo] = /github\.com\/repos\/(.+)\/(.*)/.exec(
|
|
447
|
+
issue.repository_url
|
|
448
|
+
);
|
|
413
449
|
// We're waiting for a bit here, as we've previously hit a secondary GitHub rate limit...
|
|
414
450
|
await waitFor(delay ?? DELAY_FETCHING_MS);
|
|
415
451
|
debug(`Fetching comments for ${owner}/${repo} issue ${issue.number}`);
|
|
@@ -419,7 +455,9 @@ async function* getComments(issueList, commenterUsername, delay) {
|
|
|
419
455
|
issue_number: issue.number,
|
|
420
456
|
});
|
|
421
457
|
|
|
422
|
-
const onlyMyComments = items.filter(
|
|
458
|
+
const onlyMyComments = items.filter(
|
|
459
|
+
(comment) => comment.user.login === commenterUsername
|
|
460
|
+
);
|
|
423
461
|
|
|
424
462
|
yield onlyMyComments;
|
|
425
463
|
} catch (error) {
|
|
@@ -495,7 +533,9 @@ function formatIssue(types, entity) {
|
|
|
495
533
|
type: entity.pull_request
|
|
496
534
|
? types?.createdPR || TYPE_CREATED_PR
|
|
497
535
|
: types?.createdIssue || TYPE_CREATED_ISSUE,
|
|
498
|
-
source: entity.pull_request
|
|
536
|
+
source: entity.pull_request
|
|
537
|
+
? GITHUB_PR_CREATED_CATEGORY
|
|
538
|
+
: GITHUB_ISSUES_CREATED_CATEGORY,
|
|
499
539
|
};
|
|
500
540
|
}
|
|
501
541
|
|