volunteer-contributions-fetch 2.3.0 → 2.3.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.
package/lib/bugzilla.js CHANGED
@@ -71,7 +71,9 @@ async function gather({ bugzilla }, existingContributions = []) {
71
71
  contributions = contributions.concat(comments);
72
72
  }
73
73
 
74
- return contributions;
74
+ return contributions.filter((contribution) => {
75
+ return contribution.createdAt > new Date(latest.createdAt);
76
+ });
75
77
  }
76
78
 
77
79
  async function* bugPageGenerator(bugzilla, stopDate) {
@@ -19,7 +19,7 @@ test.beforeEach((t) => {
19
19
 
20
20
  const firstBugsPage = {
21
21
  bugs: new Array(500).fill(0).map(() => ({
22
- created_at: new Date('2020-04-13'),
22
+ created_at: new Date('2022-04-13'),
23
23
  summary: 'Summary',
24
24
  // This would be the bug ID which would be different, but enough for testing purposes
25
25
  id: 1,
@@ -28,7 +28,7 @@ test.beforeEach((t) => {
28
28
 
29
29
  const secondBugsPage = {
30
30
  bugs: [{
31
- created_at: new Date('2020-04-13'),
31
+ created_at: new Date('2022-04-13'),
32
32
  summary: 'SecondSummary',
33
33
  id: 1,
34
34
  }]
@@ -39,17 +39,17 @@ test.beforeEach((t) => {
39
39
  // This would be the bug ID which would be different, but enough for testing purposes
40
40
  1: {
41
41
  comments: [{
42
- creation_time: new Date('2020-04-13'),
42
+ creation_time: new Date('2022-04-13'),
43
43
  creator: 'user',
44
44
  bug_id: 1,
45
45
  count: 0,
46
46
  }, {
47
- creation_time: new Date('2020-04-13'),
47
+ creation_time: new Date('2022-04-13'),
48
48
  creator: 'user',
49
49
  bug_id: 1,
50
50
  count: 1,
51
51
  }, {
52
- creation_time: new Date('2020-04-13'),
52
+ creation_time: new Date('2022-04-13'),
53
53
  creator: 'WILL_BE_FILTERED_OUT',
54
54
  bug_id: 1,
55
55
  count: 2,
@@ -137,14 +137,14 @@ test.serial('should format', async (t) => {
137
137
  const contributions = await bugzilla.gather(config);
138
138
 
139
139
  t.deepEqual(contributions[0], {
140
- createdAt: new Date('2020-04-13'),
140
+ createdAt: new Date('2022-04-13'),
141
141
  description: 'SecondSummary',
142
142
  link: 'https://bugzilla.mozilla.org/show_bug.cgi?id=1#c0',
143
143
  type: 'Created a Bug Report',
144
144
  source: 'bugzilla-created',
145
145
  });
146
146
  t.deepEqual(contributions[1], {
147
- createdAt: new Date('2020-04-13'),
147
+ createdAt: new Date('2022-04-13'),
148
148
  description: 'SecondSummary',
149
149
  link: 'https://bugzilla.mozilla.org/show_bug.cgi?id=1#c1',
150
150
  type: 'Commented on a Bug Report',
@@ -168,3 +168,38 @@ test.serial('should format with custom types', async (t) => {
168
168
  t.is(contributions[0].type, specificTypeConfig.bugzilla.types.createdType);
169
169
  t.is(contributions[1].type, specificTypeConfig.bugzilla.types.commentedType);
170
170
  });
171
+
172
+ test.serial('should ignore comments older than stopDate', async (t) => {
173
+ const bugsPage = {
174
+ bugs: [{
175
+ created_at: new Date('2022-04-13'),
176
+ summary: 'Summary',
177
+ id: 1,
178
+ }]
179
+ };
180
+
181
+ const oldComments = {
182
+ bugs: {
183
+ 1: {
184
+ comments: [{
185
+ creation_time: new Date('1999-04-13'),
186
+ creator: 'user',
187
+ bug_id: 1,
188
+ count: 0,
189
+ }, {
190
+ creation_time: new Date('1999-04-13'),
191
+ creator: 'user',
192
+ bug_id: 1,
193
+ count: 1,
194
+ }],
195
+ },
196
+ },
197
+ };
198
+
199
+ axios.request.onCall(0)
200
+ .resolves({ data: bugsPage });
201
+ axios.request.onCall(1).resolves({ data: oldComments });
202
+
203
+ const contributions = await bugzilla.gather(config);
204
+ t.is(contributions.length, 0);
205
+ });
package/lib/github.js CHANGED
@@ -184,7 +184,7 @@ async function processReviews(github, latestCreationDate) {
184
184
  // Now that we have all the PRs, we need to fetch the reviews
185
185
  const allReviews = [];
186
186
 
187
- const prReviewsList = getPRReviews(allPRs.flat(), github.delayMsPerRequest);
187
+ const prReviewsList = getPRReviews(allPRs.flat(), github.username, github.delayMsPerRequest);
188
188
  for await (const prReviews of prReviewsList) {
189
189
  allReviews.push(prReviews);
190
190
  }
@@ -379,7 +379,7 @@ async function getPRPage(github, reviewPeriod, page) {
379
379
  }
380
380
  }
381
381
 
382
- async function* getPRReviews(prList, delay) {
382
+ async function* getPRReviews(prList, reviewerUsername, delay) {
383
383
  debug('Getting PR reviews');
384
384
  for await (const pr of prList) {
385
385
  try {
@@ -393,7 +393,9 @@ async function* getPRReviews(prList, delay) {
393
393
  pull_number: pr.number,
394
394
  });
395
395
 
396
- yield items;
396
+ const onlyMyReviews = items.filter((review) => review.user.login === reviewerUsername);
397
+
398
+ yield onlyMyReviews;
397
399
  } catch (error) {
398
400
  debug('Error fetching reviews', error);
399
401
  return [];
@@ -70,11 +70,6 @@ test.serial('should validate config - missing stopDate', (t) => {
70
70
  t.throws(() => github.validate(failConfig));
71
71
  });
72
72
 
73
- // test.serial('should fetch', async (t) => {
74
- // const contributions = await github.gather(config);
75
- // t.is(contributions.length, 0);
76
- // });
77
-
78
73
  test.serial('should not fetch if disabled - by enable property', async (t) => {
79
74
  const specificTypeConfig = {
80
75
  github: {
@@ -594,7 +589,12 @@ test.serial('should fetch reviews until stop date', async (t) => {
594
589
  })));
595
590
 
596
591
  fetcher.listReviews.resolves([]);
597
- fetcher.listReviews.onCall(0).resolves([{ createdAt: new Date('2022-03-01') }]);
592
+ fetcher.listReviews.onCall(0).resolves([{
593
+ createdAt: new Date('2022-03-01'),
594
+ user: {
595
+ login: commitConfig.github.username,
596
+ },
597
+ }]);
598
598
 
599
599
  await github.gather(commitConfig);
600
600
  t.deepEqual(fetcher.searchIssues.getCall(0).args[0], {
@@ -668,16 +668,25 @@ test.serial('should format reviews', async (t) => {
668
668
  pull_request_url: 'https://github.com/contributions-test/foo/pulls/1',
669
669
  html_url: 'https://github.com/contribution-test/foo/pulls/1',
670
670
  state: 'CHANGES_REQUESTED',
671
+ user: {
672
+ login: commitConfig.github.username,
673
+ },
671
674
  }, {
672
675
  submitted_at: new Date('2022-03-02'),
673
676
  pull_request_url: 'https://github.com/contributions-test/foo/pulls/1',
674
677
  html_url: 'https://github.com/contribution-test/foo/pulls/1',
675
678
  state: 'COMMENTED',
679
+ user: {
680
+ login: commitConfig.github.username,
681
+ },
676
682
  }, {
677
683
  submitted_at: new Date('2022-03-02'),
678
684
  pull_request_url: 'https://github.com/contributions-test/foo/pulls/1',
679
685
  html_url: 'https://github.com/contribution-test/foo/pulls/1',
680
686
  state: 'APPROVED',
687
+ user: {
688
+ login: commitConfig.github.username,
689
+ },
681
690
  }]);
682
691
 
683
692
  const result = await github.gather(commitConfig);
@@ -737,16 +746,25 @@ test.serial('should custom format reviews', async (t) => {
737
746
  pull_request_url: 'https://github.com/contributions-test/foo/pulls/1',
738
747
  html_url: 'https://github.com/contribution-test/foo/pulls/1',
739
748
  state: 'CHANGES_REQUESTED',
749
+ user: {
750
+ login: commitConfig.github.username,
751
+ },
740
752
  }, {
741
753
  submitted_at: new Date('2022-03-02'),
742
754
  pull_request_url: 'https://github.com/contributions-test/foo/pulls/1',
743
755
  html_url: 'https://github.com/contribution-test/foo/pulls/1',
744
756
  state: 'COMMENTED',
757
+ user: {
758
+ login: commitConfig.github.username,
759
+ },
745
760
  }, {
746
761
  submitted_at: new Date('2022-03-02'),
747
762
  pull_request_url: 'https://github.com/contributions-test/foo/pulls/1',
748
763
  html_url: 'https://github.com/contribution-test/foo/pulls/1',
749
764
  state: 'APPROVED',
765
+ user: {
766
+ login: commitConfig.github.username,
767
+ },
750
768
  }]);
751
769
 
752
770
  const result = await github.gather(commitConfig);
@@ -812,7 +830,7 @@ test.serial('should ignore reviews not matching filter', async (t) => {
812
830
  }]);
813
831
 
814
832
  fetcher.listReviews.onCall(0).resolves([{
815
- submitted_at: new Date('1999-01-01'),
833
+ submitted_at: new Date('2022-03-01'),
816
834
  pull_request_url: 'https://github.com/not-matching-filter/foo/pulls/1',
817
835
  html_url: 'https://github.com/not-matching-filter/foo/pulls/1',
818
836
  state: 'CHANGES_REQUESTED',
@@ -822,6 +840,58 @@ test.serial('should ignore reviews not matching filter', async (t) => {
822
840
  t.is(result.length, 0);
823
841
  });
824
842
 
843
+ test.serial('should ignore reviews not by user', async (t) => {
844
+ const commitConfig = {
845
+ github: {
846
+ ...config.github,
847
+ issuesEnabled: false,
848
+ commitsEnabled: false,
849
+ filter: 'contribution-test',
850
+ stopDate: new Date('2022-01-01'),
851
+ },
852
+ };
853
+
854
+ fetcher.searchIssues.onCall(0).resolves([{
855
+ createdAt: new Date('2022-03-02'),
856
+ repository_url: 'https://api.github.com/repos/contribution-test/foo',
857
+ html_url: 'https://api.github.com/repos/contribution-test/foo',
858
+ title: 'Some PR',
859
+ number: 1111,
860
+ pull_request: {
861
+ url: 'https://github.com/contribution-test/foo/pulls/1',
862
+ },
863
+ }]);
864
+
865
+ fetcher.listReviews.onCall(0).resolves([{
866
+ submitted_at: new Date('2022-03-01'),
867
+ pull_request_url: 'https://github.com/contribution-test/foo/pulls/1',
868
+ html_url: 'https://github.com/contribution-test/foo/pulls/1',
869
+ state: 'CHANGES_REQUESTED',
870
+ user: {
871
+ login: 'not-the-right-user',
872
+ },
873
+ }, {
874
+ submitted_at: new Date('2022-03-01'),
875
+ pull_request_url: 'https://github.com/contribution-test/foo/pulls/1',
876
+ html_url: 'https://github.com/contribution-test/foo/pulls/1',
877
+ state: 'COMMENTED',
878
+ user: {
879
+ login: 'not-the-right-user',
880
+ },
881
+ }, {
882
+ submitted_at: new Date('2022-03-01'),
883
+ pull_request_url: 'https://github.com/contribution-test/foo/pulls/1',
884
+ html_url: 'https://github.com/contribution-test/foo/pulls/1',
885
+ state: 'CHANGES_REQUESTED',
886
+ user: {
887
+ login: commitConfig.github.username,
888
+ },
889
+ }]);
890
+
891
+ const result = await github.gather(commitConfig);
892
+ t.is(result.length, 1);
893
+ });
894
+
825
895
  test.serial('should fetch comments until stop date', async (t) => {
826
896
  const commitConfig = {
827
897
  github: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volunteer-contributions-fetch",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "description": "Library to fetch volunteer contributions from several sources such as GitHub",
5
5
  "author": "Michael Kohler",
6
6
  "license": "MIT",