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.
@@ -3,111 +3,117 @@ const allData = {
3
3
  document: {
4
4
  querySelectorAll: (query) => {
5
5
  if (query === '.profile__event') {
6
- return [{
7
- querySelector: (singleQuery) => {
8
- if (singleQuery === '.profile__event-time') {
9
- return {
10
- textContent: '2022-08-08',
11
- };
12
- }
6
+ return [
7
+ {
8
+ querySelector: (singleQuery) => {
9
+ if (singleQuery === '.profile__event-time') {
10
+ return {
11
+ textContent: '2022-08-08',
12
+ };
13
+ }
14
+
15
+ if (singleQuery === '.profile__event-title') {
16
+ return {
17
+ textContent: 'EventA',
18
+ };
19
+ }
13
20
 
14
- if (singleQuery === '.profile__event-title') {
15
21
  return {
16
- textContent: 'EventA',
22
+ textContent: 'we should not have reached here!',
17
23
  };
18
- }
19
-
20
- return {
21
- textContent: 'we should not have reached here!',
22
- };
23
- },
24
- getAttribute: (key) => {
25
- if (key === 'href') {
26
- return 'LinkA';
27
- }
28
-
29
- return '';
24
+ },
25
+ getAttribute: (key) => {
26
+ if (key === 'href') {
27
+ return 'LinkA';
28
+ }
29
+
30
+ return '';
31
+ },
30
32
  },
31
- }, {
32
- querySelector: (singleQuery) => {
33
- if (singleQuery === '.profile__event-time') {
34
- return {
35
- textContent: '2022-08-11',
36
- };
37
- }
33
+ {
34
+ querySelector: (singleQuery) => {
35
+ if (singleQuery === '.profile__event-time') {
36
+ return {
37
+ textContent: '2022-08-11',
38
+ };
39
+ }
40
+
41
+ if (singleQuery === '.profile__event-title') {
42
+ return {
43
+ textContent: 'EventB',
44
+ };
45
+ }
38
46
 
39
- if (singleQuery === '.profile__event-title') {
40
47
  return {
41
- textContent: 'EventB',
48
+ textContent: 'we should not have reached here!',
42
49
  };
43
- }
44
-
45
- return {
46
- textContent: 'we should not have reached here!',
47
- };
48
- },
49
- getAttribute: (key) => {
50
- if (key === 'href') {
51
- return 'LinkB';
52
- }
53
-
54
- return '';
50
+ },
51
+ getAttribute: (key) => {
52
+ if (key === 'href') {
53
+ return 'LinkB';
54
+ }
55
+
56
+ return '';
57
+ },
55
58
  },
56
- }];
59
+ ];
57
60
  }
58
61
 
59
62
  if (query === '.profile__campaign') {
60
- return [{
61
- querySelector: (singleQuery) => {
62
- if (singleQuery === '.profile__campaign-dates') {
63
- return {
64
- textContent: '2022-01-01',
65
- };
66
- }
63
+ return [
64
+ {
65
+ querySelector: (singleQuery) => {
66
+ if (singleQuery === '.profile__campaign-dates') {
67
+ return {
68
+ textContent: '2022-01-01',
69
+ };
70
+ }
71
+
72
+ if (singleQuery === '.profile__campaign-title') {
73
+ return {
74
+ textContent: 'CampaignA',
75
+ };
76
+ }
67
77
 
68
- if (singleQuery === '.profile__campaign-title') {
69
78
  return {
70
- textContent: 'CampaignA',
79
+ textContent: 'we should not have reached here!',
71
80
  };
72
- }
73
-
74
- return {
75
- textContent: 'we should not have reached here!',
76
- };
77
- },
78
- getAttribute: (key) => {
79
- if (key === 'href') {
80
- return 'LinkA';
81
- }
82
-
83
- return '';
81
+ },
82
+ getAttribute: (key) => {
83
+ if (key === 'href') {
84
+ return 'LinkA';
85
+ }
86
+
87
+ return '';
88
+ },
84
89
  },
85
- }, {
86
- querySelector: (singleQuery) => {
87
- if (singleQuery === '.profile__campaign-dates') {
88
- return {
89
- textContent: '2022-02-01',
90
- };
91
- }
90
+ {
91
+ querySelector: (singleQuery) => {
92
+ if (singleQuery === '.profile__campaign-dates') {
93
+ return {
94
+ textContent: '2022-02-01',
95
+ };
96
+ }
97
+
98
+ if (singleQuery === '.profile__campaign-title') {
99
+ return {
100
+ textContent: 'CampaignB',
101
+ };
102
+ }
92
103
 
93
- if (singleQuery === '.profile__campaign-title') {
94
104
  return {
95
- textContent: 'CampaignB',
105
+ textContent: 'we should not have reached here!',
96
106
  };
97
- }
98
-
99
- return {
100
- textContent: 'we should not have reached here!',
101
- };
102
- },
103
- getAttribute: (key) => {
104
- if (key === 'href') {
105
- return 'LinkB';
106
- }
107
-
108
- return '';
107
+ },
108
+ getAttribute: (key) => {
109
+ if (key === 'href') {
110
+ return 'LinkB';
111
+ }
112
+
113
+ return '';
114
+ },
109
115
  },
110
- }];
116
+ ];
111
117
  }
112
118
 
113
119
  return [];
@@ -139,111 +145,117 @@ const futureData = {
139
145
  document: {
140
146
  querySelectorAll: (query) => {
141
147
  if (query === '.profile__event') {
142
- return [{
143
- querySelector: (singleQuery) => {
144
- if (singleQuery === '.profile__event-time') {
145
- return {
146
- textContent: '2999-08-08',
147
- };
148
- }
148
+ return [
149
+ {
150
+ querySelector: (singleQuery) => {
151
+ if (singleQuery === '.profile__event-time') {
152
+ return {
153
+ textContent: '2999-08-08',
154
+ };
155
+ }
156
+
157
+ if (singleQuery === '.profile__event-title') {
158
+ return {
159
+ textContent: 'FutureEvent',
160
+ };
161
+ }
149
162
 
150
- if (singleQuery === '.profile__event-title') {
151
163
  return {
152
- textContent: 'FutureEvent',
164
+ textContent: 'we should not have reached here!',
153
165
  };
154
- }
155
-
156
- return {
157
- textContent: 'we should not have reached here!',
158
- };
159
- },
160
- getAttribute: (key) => {
161
- if (key === 'href') {
162
- return 'LinkA';
163
- }
164
-
165
- return '';
166
+ },
167
+ getAttribute: (key) => {
168
+ if (key === 'href') {
169
+ return 'LinkA';
170
+ }
171
+
172
+ return '';
173
+ },
166
174
  },
167
- }, {
168
- querySelector: (singleQuery) => {
169
- if (singleQuery === '.profile__event-time') {
170
- return {
171
- textContent: '2022-08-11',
172
- };
173
- }
175
+ {
176
+ querySelector: (singleQuery) => {
177
+ if (singleQuery === '.profile__event-time') {
178
+ return {
179
+ textContent: '2022-08-11',
180
+ };
181
+ }
182
+
183
+ if (singleQuery === '.profile__event-title') {
184
+ return {
185
+ textContent: 'PastEvent',
186
+ };
187
+ }
174
188
 
175
- if (singleQuery === '.profile__event-title') {
176
189
  return {
177
- textContent: 'PastEvent',
190
+ textContent: 'we should not have reached here!',
178
191
  };
179
- }
180
-
181
- return {
182
- textContent: 'we should not have reached here!',
183
- };
184
- },
185
- getAttribute: (key) => {
186
- if (key === 'href') {
187
- return 'LinkB';
188
- }
189
-
190
- return '';
192
+ },
193
+ getAttribute: (key) => {
194
+ if (key === 'href') {
195
+ return 'LinkB';
196
+ }
197
+
198
+ return '';
199
+ },
191
200
  },
192
- }];
201
+ ];
193
202
  }
194
203
 
195
204
  if (query === '.profile__campaign') {
196
- return [{
197
- querySelector: (singleQuery) => {
198
- if (singleQuery === '.profile__campaign-dates') {
199
- return {
200
- textContent: '2999-01-01',
201
- };
202
- }
205
+ return [
206
+ {
207
+ querySelector: (singleQuery) => {
208
+ if (singleQuery === '.profile__campaign-dates') {
209
+ return {
210
+ textContent: '2999-01-01',
211
+ };
212
+ }
213
+
214
+ if (singleQuery === '.profile__campaign-title') {
215
+ return {
216
+ textContent: 'FutureCampaign',
217
+ };
218
+ }
203
219
 
204
- if (singleQuery === '.profile__campaign-title') {
205
220
  return {
206
- textContent: 'FutureCampaign',
221
+ textContent: 'we should not have reached here!',
207
222
  };
208
- }
209
-
210
- return {
211
- textContent: 'we should not have reached here!',
212
- };
213
- },
214
- getAttribute: (key) => {
215
- if (key === 'href') {
216
- return 'LinkA';
217
- }
218
-
219
- return '';
223
+ },
224
+ getAttribute: (key) => {
225
+ if (key === 'href') {
226
+ return 'LinkA';
227
+ }
228
+
229
+ return '';
230
+ },
220
231
  },
221
- }, {
222
- querySelector: (singleQuery) => {
223
- if (singleQuery === '.profile__campaign-dates') {
224
- return {
225
- textContent: '2022-02-01',
226
- };
227
- }
232
+ {
233
+ querySelector: (singleQuery) => {
234
+ if (singleQuery === '.profile__campaign-dates') {
235
+ return {
236
+ textContent: '2022-02-01',
237
+ };
238
+ }
239
+
240
+ if (singleQuery === '.profile__campaign-title') {
241
+ return {
242
+ textContent: 'PastCampaign',
243
+ };
244
+ }
228
245
 
229
- if (singleQuery === '.profile__campaign-title') {
230
246
  return {
231
- textContent: 'PastCampaign',
247
+ textContent: 'we should not have reached here!',
232
248
  };
233
- }
234
-
235
- return {
236
- textContent: 'we should not have reached here!',
237
- };
238
- },
239
- getAttribute: (key) => {
240
- if (key === 'href') {
241
- return 'LinkB';
242
- }
243
-
244
- return '';
249
+ },
250
+ getAttribute: (key) => {
251
+ if (key === 'href') {
252
+ return 'LinkB';
253
+ }
254
+
255
+ return '';
256
+ },
245
257
  },
246
- }];
258
+ ];
247
259
  }
248
260
 
249
261
  return [];
package/lib/bugzilla.js CHANGED
@@ -44,17 +44,21 @@ async function gather({ bugzilla }, existingContributions = []) {
44
44
  }
45
45
 
46
46
  const latest = existingContributions.find((contribution) => {
47
- return contribution.source === BUGZILLA_COMMENTED_CATEGORY
48
- || contribution.source === BUGZILLA_CREATED_CATEGORY;
47
+ return (
48
+ contribution.source === BUGZILLA_COMMENTED_CATEGORY ||
49
+ contribution.source === BUGZILLA_CREATED_CATEGORY
50
+ );
49
51
  }) || { createdAt: bugzilla.stopDate };
50
52
 
51
53
  const commentedBugs = [];
52
54
  const bugsList = bugPageGenerator(bugzilla, latest.createdAt);
53
55
  for await (const bugList of bugsList) {
54
- commentedBugs.push(bugList.map((bug) => ({
55
- id: bug.id,
56
- summary: bug.summary,
57
- })));
56
+ commentedBugs.push(
57
+ bugList.map((bug) => ({
58
+ id: bug.id,
59
+ summary: bug.summary,
60
+ }))
61
+ );
58
62
  }
59
63
  const flatCommentedBugs = commentedBugs.flat();
60
64
 
@@ -80,7 +84,9 @@ async function* bugPageGenerator(bugzilla, stopDate) {
80
84
  let hasMoreToFetch = true;
81
85
  let offset = 0;
82
86
  const date = new Date(stopDate);
83
- const stop = `${date.getFullYear()}-${getPadded(date.getMonth() + 1)}-${getPadded(date.getDate())}`;
87
+ const stop = `${date.getFullYear()}-${getPadded(
88
+ date.getMonth() + 1
89
+ )}-${getPadded(date.getDate())}`;
84
90
  while (hasMoreToFetch) {
85
91
  const query = `quicksearch=ALL%20commenter:${bugzilla.username}&limit=${RESULTS_PER_PAGE}&offset=${offset}&last_change_time=${stop}`;
86
92
  const bugsUrl = `${bugzilla.baseUrl}/rest/bug?${query}`;
@@ -115,8 +121,9 @@ async function* getComments(bugzilla, bugs, titleMap) {
115
121
  timeout: FETCH_TIMEOUT,
116
122
  });
117
123
 
118
- const ownComments = data.bugs[bug.id].comments
119
- .filter((comment) => comment.creator === bugzilla.username);
124
+ const ownComments = data.bugs[bug.id].comments.filter(
125
+ (comment) => comment.creator === bugzilla.username
126
+ );
120
127
 
121
128
  yield processEntities(bugzilla, ownComments, titleMap);
122
129
  }
@@ -125,8 +132,7 @@ async function* getComments(bugzilla, bugs, titleMap) {
125
132
  }
126
133
 
127
134
  function processEntities({ types }, entities, titleMap) {
128
- return entities
129
- .map((entity) => format(types || {}, entity, titleMap));
135
+ return entities.map((entity) => format(types || {}, entity, titleMap));
130
136
  }
131
137
 
132
138
  function format(types, entity, titleMap) {
@@ -138,6 +144,9 @@ function format(types, entity, titleMap) {
138
144
  description: titleMap.get(entity.bug_id),
139
145
  link: `https://bugzilla.mozilla.org/show_bug.cgi?id=${entity.bug_id}#c${entity.count}`,
140
146
  type: entity.count === 0 ? created : commented,
141
- source: entity.count === 0 ? BUGZILLA_CREATED_CATEGORY : BUGZILLA_COMMENTED_CATEGORY,
147
+ source:
148
+ entity.count === 0
149
+ ? BUGZILLA_CREATED_CATEGORY
150
+ : BUGZILLA_COMMENTED_CATEGORY,
142
151
  };
143
152
  }
@@ -10,7 +10,7 @@ const config = {
10
10
  baseUrl: 'https://bugzilla.mozilla.org',
11
11
  username: 'user',
12
12
  stopDate: new Date('2021-11-01'),
13
- }
13
+ },
14
14
  };
15
15
 
16
16
  test.beforeEach((t) => {
@@ -27,43 +27,47 @@ test.beforeEach((t) => {
27
27
  };
28
28
 
29
29
  const secondBugsPage = {
30
- bugs: [{
31
- created_at: new Date('2022-04-13'),
32
- summary: 'SecondSummary',
33
- id: 1,
34
- }]
30
+ bugs: [
31
+ {
32
+ created_at: new Date('2022-04-13'),
33
+ summary: 'SecondSummary',
34
+ id: 1,
35
+ },
36
+ ],
35
37
  };
36
38
 
37
39
  const comments = {
38
40
  bugs: {
39
41
  // This would be the bug ID which would be different, but enough for testing purposes
40
42
  1: {
41
- comments: [{
42
- creation_time: new Date('2022-04-13'),
43
- creator: 'user',
44
- bug_id: 1,
45
- count: 0,
46
- }, {
47
- creation_time: new Date('2022-04-13'),
48
- creator: 'user',
49
- bug_id: 1,
50
- count: 1,
51
- }, {
52
- creation_time: new Date('2022-04-13'),
53
- creator: 'WILL_BE_FILTERED_OUT',
54
- bug_id: 1,
55
- count: 2,
56
- }],
43
+ comments: [
44
+ {
45
+ creation_time: new Date('2022-04-13'),
46
+ creator: 'user',
47
+ bug_id: 1,
48
+ count: 0,
49
+ },
50
+ {
51
+ creation_time: new Date('2022-04-13'),
52
+ creator: 'user',
53
+ bug_id: 1,
54
+ count: 1,
55
+ },
56
+ {
57
+ creation_time: new Date('2022-04-13'),
58
+ creator: 'WILL_BE_FILTERED_OUT',
59
+ bug_id: 1,
60
+ count: 2,
61
+ },
62
+ ],
57
63
  },
58
64
  },
59
65
  };
60
66
 
61
67
  t.context.sandbox.stub(axios, 'request');
62
68
  axios.request.resolves({ data: comments });
63
- axios.request.onCall(0)
64
- .resolves({ data: firstBugsPage });
65
- axios.request.onCall(1)
66
- .resolves({ data: secondBugsPage });
69
+ axios.request.onCall(0).resolves({ data: firstBugsPage });
70
+ axios.request.onCall(1).resolves({ data: secondBugsPage });
67
71
  });
68
72
 
69
73
  test.afterEach.always((t) => {
@@ -127,11 +131,14 @@ test.serial('should not fetch if disabled - by enable property', async (t) => {
127
131
  t.is(contributions.length, 0);
128
132
  });
129
133
 
130
- test.serial('should not fetch if disabled - by leaving off config value', async (t) => {
131
- const contributions = await bugzilla.gather({});
134
+ test.serial(
135
+ 'should not fetch if disabled - by leaving off config value',
136
+ async (t) => {
137
+ const contributions = await bugzilla.gather({});
132
138
 
133
- t.is(contributions.length, 0);
134
- });
139
+ t.is(contributions.length, 0);
140
+ }
141
+ );
135
142
 
136
143
  test.serial('should format', async (t) => {
137
144
  const contributions = await bugzilla.gather(config);
@@ -171,33 +178,37 @@ test.serial('should format with custom types', async (t) => {
171
178
 
172
179
  test.serial('should ignore comments older than stopDate', async (t) => {
173
180
  const bugsPage = {
174
- bugs: [{
175
- created_at: new Date('2022-04-13'),
176
- summary: 'Summary',
177
- id: 1,
178
- }]
181
+ bugs: [
182
+ {
183
+ created_at: new Date('2022-04-13'),
184
+ summary: 'Summary',
185
+ id: 1,
186
+ },
187
+ ],
179
188
  };
180
189
 
181
190
  const oldComments = {
182
191
  bugs: {
183
192
  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
- }],
193
+ comments: [
194
+ {
195
+ creation_time: new Date('1999-04-13'),
196
+ creator: 'user',
197
+ bug_id: 1,
198
+ count: 0,
199
+ },
200
+ {
201
+ creation_time: new Date('1999-04-13'),
202
+ creator: 'user',
203
+ bug_id: 1,
204
+ count: 1,
205
+ },
206
+ ],
195
207
  },
196
208
  },
197
209
  };
198
210
 
199
- axios.request.onCall(0)
200
- .resolves({ data: bugsPage });
211
+ axios.request.onCall(0).resolves({ data: bugsPage });
201
212
  axios.request.onCall(1).resolves({ data: oldComments });
202
213
 
203
214
  const contributions = await bugzilla.gather(config);