volunteer-contributions-fetch 4.0.0 → 4.0.2

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.
@@ -1,12 +1,18 @@
1
1
  // Existing contributions are read from JSON and therefore have a string as
2
2
  // createdAt, while freshly fetched ones have a Date. Normalize before comparing.
3
+ // All fields a contribution carries are part of the key: some sources only
4
+ // provide day precision (e.g. community portal events at midnight), so
5
+ // distinct entries can share source, type, link and createdAt and only differ
6
+ // by description. JSON.stringify avoids ambiguity when a field contains the
7
+ // separator.
3
8
  function getContributionKey(contribution) {
4
- return [
9
+ return JSON.stringify([
5
10
  contribution.source,
6
11
  contribution.type,
7
12
  contribution.link,
8
13
  new Date(contribution.createdAt).getTime(),
9
- ].join('|');
14
+ contribution.description,
15
+ ]);
10
16
  }
11
17
 
12
18
  // Invalid dates would make the comparator return NaN, which leaves the sort
package/lib/github.js CHANGED
@@ -288,13 +288,17 @@ async function processComments(github, latestCreationDate) {
288
288
  // There is a possibility that an issue was created before `latestCreationDate`
289
289
  // but has later been commented on. Therefore we fetch the commented issues for one year
290
290
  // and then later on filter out already stored comments.
291
- const allCommentedIssues = await searchAllPeriods(
292
- github,
293
- new Date(latestCreationDate) - ONE_YEAR_IN_MS,
294
- (period, page) => getCommentedPage(github, period, page),
295
- 'commented issues',
296
- { skipProcessing: true }
297
- );
291
+ const allCommentedIssues = [];
292
+ for (const type of ['issue', 'pull-request']) {
293
+ const commented = await searchAllPeriods(
294
+ github,
295
+ new Date(latestCreationDate) - ONE_YEAR_IN_MS,
296
+ (period, page) => getCommentedPage(github, type, period, page),
297
+ `commented ${type}s`,
298
+ { skipProcessing: true }
299
+ );
300
+ allCommentedIssues.push(...commented);
301
+ }
298
302
 
299
303
  const commentTitleMap = new Map();
300
304
  allCommentedIssues.forEach((commentIssue) =>
@@ -513,19 +517,21 @@ async function getIssuePage(github, relationship, issuesPeriod, page) {
513
517
  });
514
518
  }
515
519
 
516
- async function getCommentedPage(github, commentedPeriod, page) {
520
+ async function getCommentedPage(github, type, commentedPeriod, page) {
517
521
  const [before, after] = commentedPeriod;
518
522
 
519
- debug(`Getting commented page ${page} between ${after} and ${before}`);
523
+ debug(
524
+ `Getting commented ${type} page ${page} between ${after} and ${before}`
525
+ );
520
526
  if (github.delayMsPerRequest !== 0) {
521
527
  await sleep(github.delayMsPerRequest);
522
528
  }
523
529
  // Errors are not caught here, see getCommitPage. Items are filtered in
524
530
  // pageGenerator, see getIssuePage.
525
- // No `is:` qualifier, as the issue comments endpoint also returns the
526
- // conversation comments of PRs.
531
+ // PRs are searched as well, as the issue comments endpoint also returns
532
+ // the conversation comments of PRs.
527
533
  return searchIssues({
528
- q: `commenter:${github.username}+created:${after}..${before}`,
534
+ q: `commenter:${github.username}+created:${after}..${before}+is:${type}`,
529
535
  sort: 'created',
530
536
  page,
531
537
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volunteer-contributions-fetch",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "Library to fetch volunteer contributions from several sources such as GitHub",
5
5
  "author": "Michael Kohler",
6
6
  "license": "MIT",