-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainlineMergeFrequency.js
48 lines (40 loc) · 1.41 KB
/
mainlineMergeFrequency.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
const gClient = require('./gitClient');
const csvResultLogger = require('./mainlineMergeFrequencyCSVLogger');
const minimist = require('minimist');
const momentUtils = require('./momentUtils')();
const gitClient = gClient();
const args = minimist(process.argv.slice(2));
const NUMBER_OF_WEEKS = args.p || "1";
const FILE_PREFIX = args.f || undefined;
const TEAM = args.t || undefined;
const MAIN_BRANCH_NAME = args.b || "main";
main();
async function main() {
if (+NUMBER_OF_WEEKS <= 0) {
console.log("Number of weeks must be > 0");
return;
}
try {
const mergedPRs = await gitClient.getMergedPullRequests(NUMBER_OF_WEEKS, TEAM);
const mergedMainlinePRs = mergedPRs.filter(pr => pr.base.ref === MAIN_BRANCH_NAME)
const mergedPRsByDay = getNumberOfMergedPRsPerDay(mergedMainlinePRs);
csvResultLogger.writeResults(mergedPRsByDay, TEAM, FILE_PREFIX);
} catch (error) {
console.log(error);
}
}
function getNumberOfMergedPRsPerDay(prs) {
return getPerDay(prs, pr => pr.merged_at);
}
function getPerDay(thingsWithDates, getDate) {
return thingsWithDates.reduce((thingPerDay, thing) => {
const thingsDate = momentUtils.extractDateFromIso(getDate(thing));
if (thingsDate in thingPerDay) {
thingPerDay[thingsDate]++
}
else {
thingPerDay[thingsDate] = 1
}
return thingPerDay
}, {});
}