-
Notifications
You must be signed in to change notification settings - Fork 2
/
whodid-file.js
48 lines (38 loc) · 1.06 KB
/
whodid-file.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
var whodid_config = require('./whodid-config.js')
const Table = require('cli-table');
const utils = require('./utils.js')
function store(storage, filename, amt){
if(filename in storage == false)
storage[filename] = 0
storage[filename] += amt
return storage
}
function run(commits){
let config = whodid_config.retrieve()
let storage = {}
commits.forEach(commit=>{
commit.modifications.forEach(mod=>{
store(storage, mod.filename, mod.edit_line_num)
})
})
var arr = []
for( filename in storage ){
arr.push({filename:filename, weight:storage[filename]})
}
arr = arr.sort((a,b)=>{
return b.weight-a.weight
})
if(config.num > 0)
arr.length = config.num
let data = [['weight', 'top modified file']]
arr.forEach(info=>{
data.push([info.weight, info.filename])
})
if(config.output_as=='json')
console.log(utils.serialize(data, 'json'))
else if(config.output_as=='csv')
console.log(utils.serialize(data, 'csv', {'csv_sep':config.csv_seperator}))
else
console.log(utils.serialize(data, 'table', {'colors':['yellow']}))
}
module.exports = {run}