This repository has been archived by the owner on Aug 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
globals.js
52 lines (44 loc) · 2 KB
/
globals.js
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
const { createLuxonDateTimeFromIso, createTimeZone } = require('./dateTimes');
function getOrThrowIfMissingOrEmpty(configField) {
const value = process.env[configField];
if (!value) {
throw new Error(
`${configField} is required. Please create a .env file, based off of the .env.template file, and ensure that all variables have values (no empty quotes)`
);
}
return value;
}
function getDateTimesFromArgv(timeZone) {
console.info(`Using time zone: ${createTimeZone(timeZone).name}`);
const startDate = process.argv[2];
const endDate = process.argv[3];
const startMoment = createLuxonDateTimeFromIso(startDate, timeZone).startOf('day');
const endMoment = createLuxonDateTimeFromIso(endDate, timeZone).endOf('day');
return [startMoment, endMoment];
}
const githubToken = Buffer.from(getOrThrowIfMissingOrEmpty('GITHUB_TOKEN')).toString('base64');
const githubIdColumnNumber = getOrThrowIfMissingOrEmpty('CSV_COLUMN_NUMBER_FOR_GITHUB_ID');
const alternateIdColumnNumber = getOrThrowIfMissingOrEmpty('CSV_COLUMN_NUMBER_FOR_ALTERNATE_ID');
const minimumNumberOfContributions = process.env.MINIMUM_NUMBER_OF_CONTRIBUTIONS || 1;
const githubImportantEvents = getOrThrowIfMissingOrEmpty('GITHUB_IMPORTANT_EVENTS').split(',');
const timeZone = process.env.TIMEZONE;
const dateTimes = getDateTimesFromArgv(timeZone);
const csvFilename = process.argv[4];
const ignoreSelfOwnedEvents = (process.env.IGNORE_SELFOWNED_EVENTS || 'false').toLowerCase();
console.info(`Configuration set to ignore self-owned events? ${ignoreSelfOwnedEvents}`);
if (ignoreSelfOwnedEvents !== 'true' && ignoreSelfOwnedEvents !== 'false') {
console.error('IGNORE_SELFOWNED_EVENTS must be "true" or "false"');
process.exit(1);
}
module.exports = {
alternateIdColumnNumber,
csvFilename,
dateTimes,
getDateTimesFromArgv,
getOrThrowIfMissingOrEmpty,
githubIdColumnNumber,
githubImportantEvents,
githubToken,
ignoreSelfOwnedEvents,
minimumNumberOfContributions,
};