-
Notifications
You must be signed in to change notification settings - Fork 2
/
whodid-history.js
64 lines (47 loc) · 1.67 KB
/
whodid-history.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
53
54
55
56
57
58
59
60
61
62
63
64
var whodid_config = require('./whodid-config.js')
var utils =require('./utils.js')
var moment = require('moment')
const Table = require('cli-table');
function store(storage, commit){
let d = moment(commit.date, 'YYYY-MM-DD HH:mm Z').format('YYYY-MM-DD')
if(d in storage == false)
storage[d] = {}
if(commit.author in storage[d] == false){
storage[d][commit.author] = {score:0, commits:[]}
}
storage[d][commit.author].score += commit.score
storage[d][commit.author].commits.push(commit)
return storage
}
function run(commits) {
let lpad = utils.lpad
let rpad = utils.rpad
let green = utils.green
let config = whodid_config.retrieve()
let storage = {}
commits.forEach( commit=>{ store(storage, commit) } )
let dates = Object.keys(storage)
dates = dates.sort()
var result = [['date', 'author', 'score', 'commit num', 'top 3']]
dates.forEach(date=>{
let score_dict = storage[date]
for( let author in score_dict ){
let score = storage[date][author].score.toFixed(0)
storage[date][author].commits.sort((a,b)=>{
return b.score - a.score
})
let related_commits = storage[date][author].commits.map(commit=>{return commit.hash.substr(0,7)})
related_commits.length = Math.min(3, related_commits.length)
let commit_num = storage[date][author].commits.length
result.push([date, author, score, commit_num, related_commits.join(", ")])
}
})
if(config.output_as=='json')
console.log(utils.serialize(result, 'json'))
else if(config.output_as=='csv')
console.log(utils.serialize(result, 'csv', {'csv_sep':config.csv_seperator}))
else
console.log(utils.serialize(result, 'table', {'colors':[null, null, 'yellow']}))
return
}
module.exports = {run}