- Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathcontributions.rake
68 lines (61 loc) · 1.86 KB
/
contributions.rake
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
namespace:contributionsdo
task:log=>:environmentdo
log={}
append_latest_to_loglog,:last_comment,Github.user_comment_log
append_latest_to_loglog,:last_issue,Github.user_issue_log
append_latest_to_loglog,:last_pr,Github.user_pr_log
append_latest_to_loglog,:last_accessed,Slack.user_access_log
append_latest_to_loglog,:last_messaged,Slack.user_message_log
file=convert_to_csv(log)
File.write('contributions.csv',file)
puts"Finished writing to contributions.csv"
end
defconvert_to_csv(log)
require'csv'
csv_date='%Y-%m-%d'
CSV.generatedo |csv|
csv << (columns=[
'username',
:last_comment,
:last_issue,
:last_pr,
:last_accessed,
:last_messaged,
:last_contribution
])
log.eachdo |username,row|
csv << [
username,
row[:last_comment].try(:strftime,csv_date),
row[:last_issue].try(:strftime,csv_date),
row[:last_pr].try(:strftime,csv_date),
row[:last_accessed].try(:strftime,csv_date),
row[:last_messaged].try(:strftime,csv_date),
row.values.compact.sort.last.strftime(csv_date)]
end
end
end
defappend_latest_to_log(log,column,results)
flatten_to_latest(results).eachdo |username,contribution_date|
iflog[username].blank?
log[username]={
last_comment: nil,
last_issue: nil,
last_pr: nil,
last_accessed: nil,
last_messaged: nil
}
end
log[username][column]=contribution_date
end
end
defflatten_to_latest(results)
results.inject({})do |users,row|
user_id=row[:username]
ifusers[user_id].blank? || users[user_id] < row[:created_at]
users[user_id]=row[:created_at]
end
users
end
end
end