-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfill.mjs
95 lines (73 loc) · 2.19 KB
/
fill.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import fs from 'fs';
const SPONSOR_AMOUNT_REGULAR = '1';
const SPONSOR_AMOUNT_FOUNDATIONAL = '2';
function toKey(row) {
const key = row.split(',')[0].trim();
return key;
}
function isTrueish(row) {
if (!row) {
return false;
}
return /,\d$/.test(row) && parseInt(row.split(',').at(-1), 10) > 0;
}
function toMap(rows) {
const m = new Map();
for (let i = 1; i < rows.length; i++) {
if (!rows[i].trim()) {
continue;
}
m.set(toKey(rows[i]), rows[i].trim());
}
return m;
}
const codeContributions = fs.readFileSync('code-contributions.csv', 'utf8').trim().toString().split('\n');
const foundationalWork = fs.readFileSync('foundational-work.csv', 'utf8').trim().toString().split('\n');
let exported = fs.readFileSync('export.csv', 'utf8').toString().trim().split('\n');
const additional = fs.readFileSync('additional.csv', 'utf8').toString().trim().split('\n');
const codeContributionsMap = toMap(codeContributions);
const foundationalWorkMap = toMap(foundationalWork);
for (let i = 1; i < exported.length; i++) {
const z = exported[i];
if (!z) {
continue;
}
const weDoCodeContributions = isTrueish(codeContributionsMap.get(toKey(z)));
const isFoundationalToOurWork = isTrueish(foundationalWorkMap.get(toKey(z)));
if (weDoCodeContributions) {
// We contribute time/code
exported[i] = z;
continue;
}
if (isFoundationalToOurWork) {
// This is foundational to our work and needs more support
exported[i] = z.trim() + SPONSOR_AMOUNT_FOUNDATIONAL;
continue;
}
exported[i] = z.trim() + SPONSOR_AMOUNT_REGULAR;
}
exported.push(...additional.slice(1))
exported = [
exported[0],
...exported.slice(1).sort((a, b) => {
return a.localeCompare(b);
}).filter(isTrueish),
]
// Bulk sponsoring has a limit of 100 rows
// They might increase this limit in the future
// fs.writeFileSync('sponsor-log.csv', exported.join('\n') + '\n', 'utf8');
{
const chunks = [];
let chunk = [exported[0]];
for (let i = 1; i < exported.length; i++) {
if (i % 99 === 0) {
chunks.push(chunk);
chunk = [exported[0]];
}
chunk.push(exported[i]);
}
chunks.push(chunk);
for (let i = 0; i < chunks.length; i++) {
fs.writeFileSync(`sponsor-log-${i}.csv`, chunks[i].join('\n') + '\n', 'utf8');
}
}