volunteer-contributions-fetch 2.0.0 → 2.1.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/.eslintrc +3 -0
- package/README.md +35 -30
- package/commitlint.config.js +6 -1
- package/fixtures/community-portal.js +259 -0
- package/fixtures/wiki.js +57 -0
- package/lib/community-portal.js +5 -10
- package/lib/community-portal.test.js +149 -0
- package/lib/discourse.js +5 -10
- package/lib/discourse.test.js +73 -7
- package/lib/fetch.js +1 -1
- package/lib/fetch.test.js +72 -0
- package/lib/github-fetcher.js +14 -4
- package/lib/github-fetcher.test.js +1 -1
- package/lib/github.js +118 -113
- package/lib/github.test.js +822 -0
- package/lib/validator.test.js +59 -0
- package/lib/wiki.js +10 -7
- package/lib/wiki.test.js +131 -0
- package/package.json +5 -5
package/.eslintrc
CHANGED
package/README.md
CHANGED
|
@@ -87,51 +87,56 @@ This section documents all the possible configuration values. For examples see t
|
|
|
87
87
|
|
|
88
88
|
#### Community Portal
|
|
89
89
|
|
|
90
|
-
| Field | Data Type | Required | Default
|
|
91
|
-
|
|
92
|
-
| `enabled` | boolean | Yes | -
|
|
93
|
-
| `baseUrl` | string | Yes | -
|
|
94
|
-
| `username` | string | Yes | -
|
|
95
|
-
| `participationType` | string |
|
|
96
|
-
| `campaignType` | string |
|
|
90
|
+
| Field | Data Type | Required | Default | Description |
|
|
91
|
+
|---------------------|-----------|----------|----------------------------|----------------------------------------------------------------------------------------------------------------------------|
|
|
92
|
+
| `enabled` | boolean | Yes | - | Indicates whether this data source is enabled. Alternatively you can also leave off the `communityPortal` object entirely. |
|
|
93
|
+
| `baseUrl` | string | Yes | - | Community Portal base url without trailing slash |
|
|
94
|
+
| `username` | string | Yes | - | Username on the Community Portal |
|
|
95
|
+
| `participationType` | string | No | Participated in an event | Label for entries related to having participated in an event. |
|
|
96
|
+
| `campaignType` | string | No | Participated in a campaign | Label for entries related to having participated in a campaign |
|
|
97
97
|
|
|
98
98
|
#### Discourse
|
|
99
99
|
|
|
100
|
-
| Field | Data Type | Required | Default
|
|
101
|
-
|
|
102
|
-
| `enabled` | boolean | Yes | -
|
|
103
|
-
| `baseUrl` | string | Yes | -
|
|
104
|
-
| `username` | string | Yes | -
|
|
105
|
-
| `topicType` | string |
|
|
106
|
-
| `postType` | string |
|
|
100
|
+
| Field | Data Type | Required | Default | Description |
|
|
101
|
+
|---------------------|-----------|----------|---------------------------|----------------------------------------------------------------------------------------------------------------------------|
|
|
102
|
+
| `enabled` | boolean | Yes | - | Indicates whether this data source is enabled. Alternatively you can also leave off the `discourse` object entirely. |
|
|
103
|
+
| `baseUrl` | string | Yes | - | API base url without trailing slash |
|
|
104
|
+
| `username` | string | Yes | - | Username on Discourse |
|
|
105
|
+
| `topicType` | string | No | Created Discourse Topic | Label for entries related to having created a new topic. |
|
|
106
|
+
| `postType` | string | No | Posted on Discourse Topic | Label for entries related to having posted on an existing topic. |
|
|
107
107
|
|
|
108
108
|
#### GitHub
|
|
109
109
|
|
|
110
110
|
| Field | Data Type | Required | Default | Description |
|
|
111
111
|
|----------------------------|-----------|----------|---------|----------------------------------------------------------------------------------------------------------------------------|
|
|
112
112
|
| `enabled` | boolean | Yes | - | Indicates whether this data source is enabled. Alternatively you can also leave off the `github` object entirely. |
|
|
113
|
+
| `allowPrivate` | boolean | No | false | Indicates whether fetching from private repositories is allowed. If not set, the script will throw if you pass a `GITHUB_TOKEN` with private repo scope. In most cases you will not want to have a token with private scope as you do not want to leak any private information in your contribution overview. Please think twice before enabling this config. |
|
|
114
|
+
| `commitsEnabled` | boolean | No | true | Indicates whether fetching commits is enabled. |
|
|
115
|
+
| `issuesEnabled` | boolean | No | true | Indicates whether fetching issues is enabled. |
|
|
116
|
+
| `reviewsEnabled` | boolean | No | true | Indicates whether fetching reviews is enabled. |
|
|
113
117
|
| `username` | string | Yes | - | Username on GitHub |
|
|
114
118
|
| `stopDate` | string | Yes | - | `new Date()` parseable string containing a date of possibly earliest contribution to track |
|
|
115
119
|
| `filter` | string | Yes | - | Regex to apply to each entry to filter for organization/repo names. For example: `"mozilla|firefox"` to only include orgs and repos with either "mozilla" or "firefox" it their name.|
|
|
116
|
-
| `types` | Object |
|
|
117
|
-
| `types.commit` | string |
|
|
118
|
-
| `types.privateCommit` | string |
|
|
119
|
-
| `types.createdPR` | string |
|
|
120
|
-
| `types.createdIssue` | string |
|
|
121
|
-
| `types.commentedPR` | string |
|
|
122
|
-
| `types.approvedPR` | string |
|
|
123
|
-
| `types.changesRequestedPR` | string |
|
|
124
|
-
| `types.reviewedPR` | string |
|
|
120
|
+
| `types` | Object | No | - | Object containing the different labels below |
|
|
121
|
+
| `types.commit` | string | No | GitHub Commit | Label for entries related to GitHub commits |
|
|
122
|
+
| `types.privateCommit` | string | No | Commit in private repository | Label for entries related to private GitHub commits |
|
|
123
|
+
| `types.createdPR` | string | No | Created PR | Label for entries related to opening GitHub PRs |
|
|
124
|
+
| `types.createdIssue` | string | No | Created Issue Report | Label for entries related to creating GitHub issues |
|
|
125
|
+
| `types.commentedPR` | string | No | Commented on a Pull Request | Label for entries related to commenting on a GitHub PR (review) |
|
|
126
|
+
| `types.approvedPR` | string | No | Approved a Pull Request | Label for entries related to approving a GitHub PR |
|
|
127
|
+
| `types.changesRequestedPR` | string | No | Requested changes on a Pull Request | Label for entries related to requesting changes on a GitHub PR |
|
|
128
|
+
| `types.reviewedPR` | string | No | Reviewed a Pull Request | Label for entries related to reviewing a GitHub PR (fallback) |
|
|
129
|
+
| `delayMsPerRequest` | number | No | 2000 | Delay between each request to GitHub. You might hit rate limiting if you set this lower than default. |
|
|
125
130
|
|
|
126
131
|
#### MediaWiki
|
|
127
132
|
|
|
128
|
-
| Field | Data Type | Required | Default
|
|
129
|
-
|
|
130
|
-
| `enabled` | boolean | Yes | -
|
|
131
|
-
| `baseUrl` | string | Yes | -
|
|
132
|
-
| `username` | string | Yes | -
|
|
133
|
-
| `editType` | string |
|
|
134
|
-
| `stopDate` | string | Yes | -
|
|
133
|
+
| Field | Data Type | Required | Default | Description |
|
|
134
|
+
|---------------------|-----------|----------|-----------|----------------------------------------------------------------------------------------------------------------------------|
|
|
135
|
+
| `enabled` | boolean | Yes | - | Indicates whether this data source is enabled. Alternatively you can also leave off the `mediaWiki` object entirely. |
|
|
136
|
+
| `baseUrl` | string | Yes | - | API base url without trailing slash |
|
|
137
|
+
| `username` | string | Yes | - | Username on MediaWiki |
|
|
138
|
+
| `editType` | string | No | Wiki Edit | Label for entries related to having edited an article. |
|
|
139
|
+
| `stopDate` | string | Yes | - | `new Date()` parseable string containing a date of possibly earliest contribution to track |
|
|
135
140
|
|
|
136
141
|
### Sample configuration
|
|
137
142
|
|
package/commitlint.config.js
CHANGED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
const allData = {
|
|
2
|
+
window: {
|
|
3
|
+
document: {
|
|
4
|
+
querySelectorAll: (query) => {
|
|
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
|
+
}
|
|
13
|
+
|
|
14
|
+
if (singleQuery === '.profile__event-title') {
|
|
15
|
+
return {
|
|
16
|
+
textContent: 'EventA',
|
|
17
|
+
};
|
|
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 '';
|
|
30
|
+
},
|
|
31
|
+
}, {
|
|
32
|
+
querySelector: (singleQuery) => {
|
|
33
|
+
if (singleQuery === '.profile__event-time') {
|
|
34
|
+
return {
|
|
35
|
+
textContent: '2022-08-11',
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (singleQuery === '.profile__event-title') {
|
|
40
|
+
return {
|
|
41
|
+
textContent: 'EventB',
|
|
42
|
+
};
|
|
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 '';
|
|
55
|
+
},
|
|
56
|
+
}];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (query === '.profile__campaign') {
|
|
60
|
+
return [{
|
|
61
|
+
querySelector: (singleQuery) => {
|
|
62
|
+
if (singleQuery === '.profile__campaign-dates') {
|
|
63
|
+
return {
|
|
64
|
+
textContent: '2022-01-01',
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (singleQuery === '.profile__campaign-title') {
|
|
69
|
+
return {
|
|
70
|
+
textContent: 'CampaignA',
|
|
71
|
+
};
|
|
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 '';
|
|
84
|
+
},
|
|
85
|
+
}, {
|
|
86
|
+
querySelector: (singleQuery) => {
|
|
87
|
+
if (singleQuery === '.profile__campaign-dates') {
|
|
88
|
+
return {
|
|
89
|
+
textContent: '2022-02-01',
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (singleQuery === '.profile__campaign-title') {
|
|
94
|
+
return {
|
|
95
|
+
textContent: 'CampaignB',
|
|
96
|
+
};
|
|
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 '';
|
|
109
|
+
},
|
|
110
|
+
}];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return [];
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const noData = {
|
|
120
|
+
window: {
|
|
121
|
+
document: {
|
|
122
|
+
querySelectorAll: (query) => {
|
|
123
|
+
if (query === '.profile__event') {
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (query === '.profile__campaign') {
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return [];
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const futureData = {
|
|
138
|
+
window: {
|
|
139
|
+
document: {
|
|
140
|
+
querySelectorAll: (query) => {
|
|
141
|
+
if (query === '.profile__event') {
|
|
142
|
+
return [{
|
|
143
|
+
querySelector: (singleQuery) => {
|
|
144
|
+
if (singleQuery === '.profile__event-time') {
|
|
145
|
+
return {
|
|
146
|
+
textContent: '2999-08-08',
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (singleQuery === '.profile__event-title') {
|
|
151
|
+
return {
|
|
152
|
+
textContent: 'FutureEvent',
|
|
153
|
+
};
|
|
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
|
+
}, {
|
|
168
|
+
querySelector: (singleQuery) => {
|
|
169
|
+
if (singleQuery === '.profile__event-time') {
|
|
170
|
+
return {
|
|
171
|
+
textContent: '2022-08-11',
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (singleQuery === '.profile__event-title') {
|
|
176
|
+
return {
|
|
177
|
+
textContent: 'PastEvent',
|
|
178
|
+
};
|
|
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 '';
|
|
191
|
+
},
|
|
192
|
+
}];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (query === '.profile__campaign') {
|
|
196
|
+
return [{
|
|
197
|
+
querySelector: (singleQuery) => {
|
|
198
|
+
if (singleQuery === '.profile__campaign-dates') {
|
|
199
|
+
return {
|
|
200
|
+
textContent: '2999-01-01',
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (singleQuery === '.profile__campaign-title') {
|
|
205
|
+
return {
|
|
206
|
+
textContent: 'FutureCampaign',
|
|
207
|
+
};
|
|
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 '';
|
|
220
|
+
},
|
|
221
|
+
}, {
|
|
222
|
+
querySelector: (singleQuery) => {
|
|
223
|
+
if (singleQuery === '.profile__campaign-dates') {
|
|
224
|
+
return {
|
|
225
|
+
textContent: '2022-02-01',
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (singleQuery === '.profile__campaign-title') {
|
|
230
|
+
return {
|
|
231
|
+
textContent: 'PastCampaign',
|
|
232
|
+
};
|
|
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 '';
|
|
245
|
+
},
|
|
246
|
+
}];
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return [];
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
module.exports = {
|
|
256
|
+
allData,
|
|
257
|
+
noData,
|
|
258
|
+
futureData,
|
|
259
|
+
};
|
package/fixtures/wiki.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const firstMonth = `
|
|
2
|
+
<rss version="2.0">
|
|
3
|
+
<channel>
|
|
4
|
+
<title>MozillaWiki - User contributions [en]</title>
|
|
5
|
+
<link>https://wiki.mozilla.org/Special:Contributions/User</link>
|
|
6
|
+
<description>User contributions</description>
|
|
7
|
+
<language>en</language>
|
|
8
|
+
<generator>MediaWiki 1.27.4</generator>
|
|
9
|
+
<lastBuildDate>Fri, 26 Aug 2022 20:13:05 GMT</lastBuildDate>
|
|
10
|
+
<item>
|
|
11
|
+
<title>PageA</title>
|
|
12
|
+
<link>LinkA</link>
|
|
13
|
+
<guid isPermaLink="false">GUID</guid>
|
|
14
|
+
<description>Blabla</description>
|
|
15
|
+
<pubDate>Sat, 01 Jan 2022 00:00:00 GMT</pubDate>
|
|
16
|
+
<dc:creator>User</dc:creator>
|
|
17
|
+
<comments>https://wiki.mozilla.org/Talk:PageA</comments>
|
|
18
|
+
</item>
|
|
19
|
+
<item>
|
|
20
|
+
<title>PageB</title>
|
|
21
|
+
<link>LinkB</link>
|
|
22
|
+
<guid isPermaLink="false">GUID</guid>
|
|
23
|
+
<description>Blabla</description>
|
|
24
|
+
<pubDate>Sun, 02 Jan 2022 00:00:00 GMT</pubDate>
|
|
25
|
+
<dc:creator>User</dc:creator>
|
|
26
|
+
<comments>https://wiki.mozilla.org/Talk:PageA</comments>
|
|
27
|
+
</item>
|
|
28
|
+
</channel>
|
|
29
|
+
</rss>
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
const secondMonth = `
|
|
33
|
+
<rss version="2.0">
|
|
34
|
+
<channel>
|
|
35
|
+
<title>MozillaWiki - User contributions [en]</title>
|
|
36
|
+
<link>https://wiki.mozilla.org/Special:Contributions/User</link>
|
|
37
|
+
<description>User contributions</description>
|
|
38
|
+
<language>en</language>
|
|
39
|
+
<generator>MediaWiki 1.27.4</generator>
|
|
40
|
+
<lastBuildDate>Fri, 26 Aug 2022 20:13:05 GMT</lastBuildDate>
|
|
41
|
+
<item>
|
|
42
|
+
<title>PageC</title>
|
|
43
|
+
<link>LinkC</link>
|
|
44
|
+
<guid isPermaLink="false">GUID</guid>
|
|
45
|
+
<description>Blabla</description>
|
|
46
|
+
<pubDate>Wed, 01 Dec 2021 00:00:00 GMT</pubDate>
|
|
47
|
+
<dc:creator>User</dc:creator>
|
|
48
|
+
<comments>https://wiki.mozilla.org/Talk:PageC</comments>
|
|
49
|
+
</item>
|
|
50
|
+
</channel>
|
|
51
|
+
</rss>
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
module.exports = {
|
|
55
|
+
firstMonth,
|
|
56
|
+
secondMonth,
|
|
57
|
+
};
|
package/lib/community-portal.js
CHANGED
|
@@ -4,6 +4,9 @@ const { JSDOM } = require('jsdom');
|
|
|
4
4
|
const EVENTS_CATEGORY = 'community-portal-events';
|
|
5
5
|
const CAMPAIGNS_CATEGORY = 'community-portal-campaigns';
|
|
6
6
|
|
|
7
|
+
const TYPE_PARTICIPATION = 'Participated in an event';
|
|
8
|
+
const TYPE_CAMPAIGN = 'Participated in a campaign';
|
|
9
|
+
|
|
7
10
|
module.exports = {
|
|
8
11
|
EVENTS_CATEGORY,
|
|
9
12
|
CAMPAIGNS_CATEGORY,
|
|
@@ -25,14 +28,6 @@ function validate(config) {
|
|
|
25
28
|
if (config && config.enabled && !config.username) {
|
|
26
29
|
throw new Error('Community Portal: username is required');
|
|
27
30
|
}
|
|
28
|
-
|
|
29
|
-
if (config && config.enabled && !config.participationType) {
|
|
30
|
-
throw new Error('Community Portal: participationType is required');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (config && config.enabled && !config.campaignType) {
|
|
34
|
-
throw new Error('Community Portal: campaignType is required');
|
|
35
|
-
}
|
|
36
31
|
}
|
|
37
32
|
|
|
38
33
|
async function gather({ communityPortal }) {
|
|
@@ -90,7 +85,7 @@ function formatEvent(type, entity) {
|
|
|
90
85
|
createdAt: new Date(entity.querySelector('.profile__event-time').textContent.replace(/[\n\t∙]/g, '')),
|
|
91
86
|
description: entity.querySelector('.profile__event-title').textContent.replace(/[\n\t]/g, ''),
|
|
92
87
|
link: entity.getAttribute('href'),
|
|
93
|
-
type,
|
|
88
|
+
type: type || TYPE_PARTICIPATION,
|
|
94
89
|
source: EVENTS_CATEGORY,
|
|
95
90
|
};
|
|
96
91
|
}
|
|
@@ -101,7 +96,7 @@ function formatCampaign(type, entity) {
|
|
|
101
96
|
createdAt: new Date(dateValue),
|
|
102
97
|
description: entity.querySelector('.profile__campaign-title').textContent.replace(/[\n\t]/g, ''),
|
|
103
98
|
link: entity.getAttribute('href'),
|
|
104
|
-
type,
|
|
99
|
+
type: type || TYPE_CAMPAIGN,
|
|
105
100
|
source: CAMPAIGNS_CATEGORY,
|
|
106
101
|
};
|
|
107
102
|
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
const test = require('ava');
|
|
2
|
+
const { JSDOM } = require('jsdom');
|
|
3
|
+
const sinon = require('sinon');
|
|
4
|
+
|
|
5
|
+
const fixtures = require('../fixtures/community-portal');
|
|
6
|
+
const communityPortal = require('./community-portal');
|
|
7
|
+
|
|
8
|
+
const config = {
|
|
9
|
+
communityPortal: {
|
|
10
|
+
enabled: true,
|
|
11
|
+
baseUrl: 'https://community.mozilla.org',
|
|
12
|
+
username: 'user',
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
test.beforeEach((t) => {
|
|
17
|
+
// eslint-disable-next-line no-param-reassign
|
|
18
|
+
t.context.sandbox = sinon.createSandbox();
|
|
19
|
+
|
|
20
|
+
t.context.sandbox.stub(JSDOM, 'fromURL');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test.afterEach.always((t) => {
|
|
24
|
+
t.context.sandbox.restore();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test.serial('should validate config - missing completely', (t) => {
|
|
28
|
+
const emptyConfig = {};
|
|
29
|
+
t.notThrows(() => communityPortal.validate(emptyConfig));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test.serial('should validate config - missing baseUrl', (t) => {
|
|
33
|
+
const failConfig = {
|
|
34
|
+
enabled: true,
|
|
35
|
+
username: 'A',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
t.throws(() => communityPortal.validate(failConfig));
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test.serial('should validate config - missing username', (t) => {
|
|
42
|
+
const failConfig = {
|
|
43
|
+
enabled: true,
|
|
44
|
+
baseUrl: 'A',
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
t.throws(() => communityPortal.validate(failConfig));
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test.serial('should fetch', async (t) => {
|
|
51
|
+
JSDOM.fromURL.resolves(fixtures.allData);
|
|
52
|
+
|
|
53
|
+
const contributions = await communityPortal.gather(config);
|
|
54
|
+
t.is(contributions.length, 4);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test.serial('should fetch even though sections are empty', async (t) => {
|
|
58
|
+
JSDOM.fromURL.resolves(fixtures.noData);
|
|
59
|
+
|
|
60
|
+
const contributions = await communityPortal.gather(config);
|
|
61
|
+
t.is(contributions.length, 0);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test.serial('should only fetch events and campaigns that are not in the future', async (t) => {
|
|
65
|
+
JSDOM.fromURL.resolves(fixtures.futureData);
|
|
66
|
+
|
|
67
|
+
const contributions = await communityPortal.gather(config);
|
|
68
|
+
t.is(contributions.length, 2);
|
|
69
|
+
t.deepEqual(contributions[0].createdAt, new Date('2022-08-11'));
|
|
70
|
+
t.is(contributions[0].description, 'PastEvent');
|
|
71
|
+
t.deepEqual(contributions[1].createdAt, new Date('2022-02-01'));
|
|
72
|
+
t.is(contributions[1].description, 'PastCampaign');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test.serial('should not fetch if disabled - by enable property', async (t) => {
|
|
76
|
+
const specificTypeConfig = {
|
|
77
|
+
communityPortal: {
|
|
78
|
+
...config.communityPortal,
|
|
79
|
+
enabled: false,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const contributions = await communityPortal.gather(specificTypeConfig);
|
|
84
|
+
|
|
85
|
+
t.is(contributions.length, 0);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test.serial('should not fetch if disabled - by leaving off config value', async (t) => {
|
|
89
|
+
const contributions = await communityPortal.gather({});
|
|
90
|
+
|
|
91
|
+
t.is(contributions.length, 0);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test.serial('should format', async (t) => {
|
|
95
|
+
JSDOM.fromURL.resolves(fixtures.allData);
|
|
96
|
+
|
|
97
|
+
const contributions = await communityPortal.gather(config);
|
|
98
|
+
|
|
99
|
+
// Event
|
|
100
|
+
t.deepEqual(contributions[0], {
|
|
101
|
+
createdAt: new Date('2022-08-11'),
|
|
102
|
+
description: 'EventB',
|
|
103
|
+
link: 'LinkB',
|
|
104
|
+
type: 'Participated in an event',
|
|
105
|
+
source: 'community-portal-events',
|
|
106
|
+
});
|
|
107
|
+
t.deepEqual(contributions[1], {
|
|
108
|
+
createdAt: new Date('2022-08-08'),
|
|
109
|
+
description: 'EventA',
|
|
110
|
+
link: 'LinkA',
|
|
111
|
+
type: 'Participated in an event',
|
|
112
|
+
source: 'community-portal-events',
|
|
113
|
+
});
|
|
114
|
+
// Campaign
|
|
115
|
+
t.deepEqual(contributions[2], {
|
|
116
|
+
createdAt: new Date('2022-02-01'),
|
|
117
|
+
description: 'CampaignB',
|
|
118
|
+
link: 'LinkB',
|
|
119
|
+
type: 'Participated in a campaign',
|
|
120
|
+
source: 'community-portal-campaigns',
|
|
121
|
+
});
|
|
122
|
+
t.deepEqual(contributions[3], {
|
|
123
|
+
createdAt: new Date('2022-01-01'),
|
|
124
|
+
description: 'CampaignA',
|
|
125
|
+
link: 'LinkA',
|
|
126
|
+
type: 'Participated in a campaign',
|
|
127
|
+
source: 'community-portal-campaigns',
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test.serial('should format with custom types', async (t) => {
|
|
132
|
+
JSDOM.fromURL.resolves(fixtures.allData);
|
|
133
|
+
|
|
134
|
+
const specificTypeConfig = {
|
|
135
|
+
communityPortal: {
|
|
136
|
+
...config.communityPortal,
|
|
137
|
+
participationType: 'Event!',
|
|
138
|
+
campaignType: 'Campaign!',
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const contributions = await communityPortal.gather(specificTypeConfig);
|
|
143
|
+
|
|
144
|
+
// Event
|
|
145
|
+
t.is(contributions[0].type, specificTypeConfig.communityPortal.participationType);
|
|
146
|
+
t.is(contributions[1].type, specificTypeConfig.communityPortal.participationType);
|
|
147
|
+
t.is(contributions[2].type, specificTypeConfig.communityPortal.campaignType);
|
|
148
|
+
t.is(contributions[3].type, specificTypeConfig.communityPortal.campaignType);
|
|
149
|
+
});
|
package/lib/discourse.js
CHANGED
|
@@ -5,6 +5,9 @@ const RESULTS_PER_PAGE = 30;
|
|
|
5
5
|
const TOPICS_CATEGORY = 'discourse-topics';
|
|
6
6
|
const POSTS_CATEGORY = 'discourse-posts';
|
|
7
7
|
|
|
8
|
+
const TYPE_TOPIC = 'Created Discourse Topic';
|
|
9
|
+
const TYPE_POST = 'Posted on Discourse Topic';
|
|
10
|
+
|
|
8
11
|
module.exports = {
|
|
9
12
|
TOPICS_CATEGORY,
|
|
10
13
|
POSTS_CATEGORY,
|
|
@@ -26,14 +29,6 @@ function validate(config) {
|
|
|
26
29
|
if (config && config.enabled && !config.username) {
|
|
27
30
|
throw new Error('Discourse: username is required');
|
|
28
31
|
}
|
|
29
|
-
|
|
30
|
-
if (config && config.enabled && !config.topicType) {
|
|
31
|
-
throw new Error('Discourse: topicType is required');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (config && config.enabled && !config.postType) {
|
|
35
|
-
throw new Error('Discourse: postType is required');
|
|
36
|
-
}
|
|
37
32
|
}
|
|
38
33
|
|
|
39
34
|
async function gather({ discourse }) {
|
|
@@ -128,7 +123,7 @@ function formatTopic(type, baseUrl, entity) {
|
|
|
128
123
|
createdAt: new Date(entity.created_at),
|
|
129
124
|
description: entity.title,
|
|
130
125
|
link: `${baseUrl}/t/${entity.slug}/${entity.id}`,
|
|
131
|
-
type,
|
|
126
|
+
type: type || TYPE_TOPIC,
|
|
132
127
|
source: TOPICS_CATEGORY,
|
|
133
128
|
};
|
|
134
129
|
}
|
|
@@ -138,7 +133,7 @@ function formatPost(type, baseUrl, entity) {
|
|
|
138
133
|
createdAt: new Date(entity.created_at),
|
|
139
134
|
description: entity.title,
|
|
140
135
|
link: `${baseUrl}/t/${entity.slug}/${entity.topic_id}/${entity.post_number}`,
|
|
141
|
-
type,
|
|
136
|
+
type: type || TYPE_POST,
|
|
142
137
|
source: POSTS_CATEGORY,
|
|
143
138
|
};
|
|
144
139
|
}
|