forked from kriskbx/gitlab-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv.js
More file actions
executable file
·104 lines (83 loc) · 3.15 KB
/
csv.js
File metadata and controls
executable file
·104 lines (83 loc) · 3.15 KB
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
96
97
98
99
100
101
102
103
104
const _ = require('underscore');
const fs = require('fs');
const path = require('path');
const Csv = require('csv-string');
const Base = require('./base');
/**
* csv output
*/
class csv extends Base {
makeStats() {
let stats = [[], []];
_.each(this.stats, (time, name) => {
stats[0].push(name);
stats[1].push(time);
});
if (this.projects.length > 1) {
_.each(this.projects, (time, name) => {
stats[0].push(name);
stats[1].push(time);
});
}
_.each(this.users, (time, name) => {
stats[0].push(name);
stats[1].push(time);
});
this.csvStats = Csv.stringify(stats);
}
makeIssues() {
let issues = [];
issues.push(this.config.get('issueColumns'));
this.report.issues.forEach(issue => issues.push(this.prepare(issue, this.config.get('issueColumns'))));
this.csvIssues = Csv.stringify(issues);
}
makeMergeRequests() {
let mergeRequests = [];
mergeRequests.push(this.config.get('mergeRequestColumns'));
this.report.mergeRequests.forEach(mergeRequest => mergeRequests.push(this.prepare(mergeRequest, this.config.get('mergeRequestColumns'))));
this.csvMergeRequests = Csv.stringify(mergeRequests);
}
makeRecords() {
let times = [];
times.push(this.config.get('recordColumns'));
this.times.forEach(time => times.push(this.prepare(time, this.config.get('recordColumns'))));
this.csvRecords = Csv.stringify(times);
}
toFile(file, resolve) {
let fileName = path.basename(file);
let extName = path.extname(file);
if (this.config.get('report').includes('stats')) {
fs.writeFileSync(file.replace(fileName, fileName.replace(extName, `.stats${extName}`)), this.csvStats);
}
if (this.config.get('report').includes('issues')) {
fs.writeFileSync(file.replace(fileName, fileName.replace(extName, `.issues${extName}`)), this.csvIssues);
}
if (this.config.get('report').includes('merge_requests')) {
fs.writeFileSync(file.replace(fileName, fileName.replace(extName, `.mergeRequests${extName}`)), this.csvMergeRequests);
}
if (this.config.get('report').includes('records')) {
fs.writeFileSync(file.replace(fileName, fileName.replace(extName, `.records${extName}`)), this.csvRecords);
}
resolve();
}
toStdOut() {
if (this.config.get('report').includes('state')) {
this.headline('STATS');
this.write(this.csvStats);
}
if (this.config.get('report').includes('issues')) {
this.headline('ISSUES');
this.write(this.csvIssues);
}
if (this.config.get('report').includes('merge_requests')) {
this.headline('MERGE REQUESTS');
this.write(this.csvMergeRequests);
}
if (this.config.get('report').includes('records')) {
this.headline('TIME RECORDS');
this.write(this.csvRecords);
}
super.toStdOut();
}
}
module.exports = csv;