1
1
#!/usr/bin/env node
2
2
3
3
/**
4
- * This script gathers metadata for supporters of Mocha from OpenCollective's API by
5
- * aggregating order ("donation") information.
4
+ * This script gathers metadata for active supporters of Mocha from OpenCollective's
5
+ * API by aggregating order ("donation") information.
6
6
*
7
- * It's intended to be used with 11ty, but can be run directly. Running directly
7
+ * It's intended to be used with 11ty, but can be run directly. Running directly
8
8
* enables debug output.
9
9
*
10
10
* - gathers logo/avatar images (they are always pngs)
11
11
* - gathers links
12
- * - sorts by total contributions and tier
12
+ * - sorts by tier and total contributions
13
13
* - validates images
14
14
* - writes images to a temp dir
15
15
* @see https://docs.opencollective.com/help/contributing/development/api
@@ -28,7 +28,7 @@ const blocklist = new Set(require('./blocklist.json'));
28
28
* In addition to the blocklist, any account slug matching this regex will not
29
29
* be displayed on the website.
30
30
*/
31
- const BLOCKED_STRINGS = / (?: v p n | [ c k ] a [ s z ] i n o | s e o | s l o t s | g a m b l (?: e | i n g ) | c r y p t o ) / i;
31
+ const BLOCKED_STRINGS = / (?: [ c k ] a [ s z ] i n o | s e o | s l o t s | g a m b l (?: e | i n g ) | c r y p t o ) / i;
32
32
33
33
/**
34
34
* Add a few Categories exposed by Open Collective to help moderation
@@ -48,8 +48,8 @@ const BLOCKED_CATEGORIES = [
48
48
*/
49
49
const API_ENDPOINT = 'https://api.opencollective.com/graphql/v2' ;
50
50
51
- const SPONSOR_TIER = 'sponsor ' ;
52
- const BACKER_TIER = 'backer ' ;
51
+ const SPONSOR_TIER = 'sponsors ' ;
52
+ const BACKER_TIER = 'backers ' ;
53
53
54
54
// if this percent of fetches completes, the build will pass
55
55
const PRODUCTION_SUCCESS_THRESHOLD = 0.8 ;
@@ -58,7 +58,7 @@ const SUPPORTER_IMAGE_PATH = resolve(__dirname, '../images/supporters');
58
58
59
59
const SUPPORTER_QUERY = `query account($limit: Int, $offset: Int, $slug: String) {
60
60
account(slug: $slug) {
61
- orders(limit: $limit, offset: $offset) {
61
+ orders(limit: $limit, offset: $offset, status: ACTIVE, filter: INCOMING ) {
62
62
limit
63
63
offset
64
64
totalCount
@@ -73,9 +73,8 @@ const SUPPORTER_QUERY = `query account($limit: Int, $offset: Int, $slug: String)
73
73
type
74
74
categories
75
75
}
76
- totalDonations {
77
- value
78
- }
76
+ tier { slug }
77
+ totalDonations { value }
79
78
createdAt
80
79
}
81
80
}
@@ -93,10 +92,11 @@ const nodeToSupporter = node => ({
93
92
website : node . fromAccount . website ,
94
93
imgUrlMed : node . fromAccount . imgUrlMed ,
95
94
imgUrlSmall : node . fromAccount . imgUrlSmall ,
96
- firstDonation : node . createdAt ,
97
- totalDonations : node . totalDonations . value * 100 ,
98
95
type : node . fromAccount . type ,
99
- categories : node . fromAccount . categories
96
+ categories : node . fromAccount . categories ,
97
+ tier : ( node . tier && node . tier . slug ) || BACKER_TIER ,
98
+ totalDonations : node . totalDonations . value * 100 ,
99
+ firstDonation : node . createdAt
100
100
} ) ;
101
101
102
102
const fetchImage = process . env . MOCHA_DOCS_SKIP_IMAGE_DOWNLOAD
@@ -198,14 +198,13 @@ const getSupporters = async () => {
198
198
// determine which url to use depending on tier
199
199
. reduce (
200
200
( supporters , supporter ) => {
201
- if ( supporter . type === 'INDIVIDUAL' ) {
201
+ if ( supporter . tier === BACKER_TIER ) {
202
202
if ( supporter . name !== 'anonymous' ) {
203
203
supporters [ BACKER_TIER ] = [
204
204
...supporters [ BACKER_TIER ] ,
205
205
{
206
206
...supporter ,
207
- avatar : encodeURI ( supporter . imgUrlSmall ) ,
208
- tier : BACKER_TIER
207
+ avatar : encodeURI ( supporter . imgUrlSmall )
209
208
}
210
209
] ;
211
210
}
@@ -214,8 +213,7 @@ const getSupporters = async () => {
214
213
...supporters [ SPONSOR_TIER ] ,
215
214
{
216
215
...supporter ,
217
- avatar : encodeURI ( supporter . imgUrlMed ) ,
218
- tier : SPONSOR_TIER
216
+ avatar : encodeURI ( supporter . imgUrlMed )
219
217
}
220
218
] ;
221
219
}
0 commit comments