-
Notifications
You must be signed in to change notification settings - Fork 1
/
cycleTimeCSVLogger.js
43 lines (37 loc) · 1.51 KB
/
cycleTimeCSVLogger.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
const fs = require('fs');
const cycleTimeFileUtils = require('./cycleTimeFileUtils');
const momentUtils = require('./momentUtils')();
function writeResults(prMetrics, team, onlyIncludeWorkingHours = false, filePrefix = '') {
const prRows = getPRMetricRows(prMetrics);
try {
fs.writeFileSync(
getPRResultFileName(team, onlyIncludeWorkingHours, filePrefix),
prRows
)
} catch (err) {
console.error(err)
}
}
module.exports.writeResults = writeResults;
function getPRMetricRows(prMetrics) {
const header = "PR number, Created at, Time to open (minutes), Time to first interaction (minutes), Time to merge (minutes), Cycle time (minutes), Number of commits, Number of files, Total additions, Total deletions, Number of reviews";
prMetrics.sort((a, b) => { return parseInt(b.number) - parseInt(a.number)});
const prMetricRows = prMetrics
.map(pr => [
`PR-${pr.number}`,
momentUtils.extractDateFromIso(pr.created_at),
pr.timeToOpen,
pr.timeToFirstInteraction,
pr.timeToMerge,
pr.cycleTime,
pr.numberOfCommits,
pr.numberOfFiles,
pr.totalAdditions,
pr.totalDeletions,
pr.numberOfReviews
].join(','));
return [header].concat(prMetricRows).join(`\n`);
}
function getPRResultFileName(team, onlyIncludeWorkingHours, filePrefix) {
return cycleTimeFileUtils.getResultFileName(filePrefix, `csv`, team, onlyIncludeWorkingHours);
}