-
Notifications
You must be signed in to change notification settings - Fork 1
/
Git Charts.tmCommand
141 lines (112 loc) · 4.08 KB
/
Git Charts.tmCommand
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>bundleUUID</key>
<string>EADD4718-EE11-4ABF-A7E6-13351FB3799D</string>
<key>command</key>
<string>#!/usr/bin/env ruby
require 'time'
require 'date'
require 'URI'
def chart_commits
lines = `git log --pretty=format:%ai`
times = lines.map { |l| Time.parse l }
dots = []
0.upto(7) { |wday|
0.upto(23) { |hour|
dots << [hour, wday, times.find_all { |t| t.hour == hour && t.wday == wday }.size]
}
}
max = dots.map { |h,w,c| c }.max
title = "Commit Activity by Day and Hour"
url = "http://chart.apis.google.com/chart?chtt=#{title}&chs=800x350&chds=-1,24,-1,7,0,#{max}&chf=bg,s,efefef&chd=t:#{dots.transpose.map { |c| c.join(",") }.join("|")}&chxt=x,y&chm=o,333333,1,1.0,25.0&chxl=0:||12am|1|2|3|4|5|6|7|8|9|10|11|12pm|1|2|3|4|5|6|7|8|9|10|11||1:||Sun|Mon|Tue|Wed|Thr|Fri|Sat|&cht=s&chma=20,20,20,20"
out = URI.escape(url)
return out
end
def chart_authors
author_limit = 10
authors = _get_authors
c = Hash.new(0)
authors.each { |n| c[n] += 1 }
c = c.sort_by { |x| x[1] }.reverse
if c.count < author_limit
limit = c.count
title = "Commits by Authors"
else
limit = author_limit
title = "Commits by Top " + limit.to_s + " Authors"
end
max = c.map { |n, x| x }.max
values = []
authors = []
c.each { |n, c| values << c && authors << n + ' (' + c.to_s + ')' }
values = values[0..limit-1].join(',')
authors = authors[0..limit-1].join('|')
url = "http://chart.apis.google.com/chart?chtt=#{title}&chs=800x350&cht=p&chds=0,#{max}&chd=t:#{values}&chl=#{authors}&chdlp=l&chp=360&chma=20,20,20,20"
out = URI.escape(url)
return out
end
def chart_timeline
lines = `git log --pretty=format:%ai`
times = lines.map { |l| Date.parse l }
days_limit = 90
date_range = ( DateTime.now - (times[-1]) ).to_i
dl = ( date_range < days_limit ? date_range : days_limit )
dates = Hash.new(0)
( (times[0]-dl+1) .. DateTime.now ).each { |d|
dates[d] = times.find_all{ |t| t.to_s == d.to_s }.size
}
dates = dates.sort
max = dates.map { |n, x| x }.max + 10
max = max - ( max % 10 )
marks = []
(0..dates.count-1).step(10) { |d| marks << [ d, dates[d][0] ] }
marks[-1][1] = dates[-1][0]
marks_str = '|' + marks.map { |k, v| "#{v}" }.join("|")
marks_step = '|' + marks.map { |k, v| "#{k}" }.join("|")
chart_data = dates.map! { |k, v| "#{v}" }.join(",")
gc = Hash[[
["cht", "lc"],
["chs", "800x350"],
["chtt", "Commit Activity over the last #{dl.to_s} Days"],
["chxl", "0:#{marks_str}"],
["chxp", marks_step],
["chxr", "0,0,#{dates.count}|1,0,#{max}"],
["chxtc", "0,10|1,5"],
["chxt", "x,y"],
["chma", "20,20,20,20"],
["chco", "3D7930,FF9900"],
["chds", "0,#{max}"],
["chd", "t:#{chart_data}"],
["chxl", "0:#{marks_str}"],
["chxr", "0,0,#{dates.count}|1,0,#{max}"],
["chxp", "#{marks_step}"],
["chg", "-1,-1,0,0"],
]]
return URI.escape( "http://chart.apis.google.com/chart?" + gc.sort.map! { |k, v| "#{k}=#{v}" }.join("&") )
end
def _get_authors
lines = `git log --pretty=format:%an`
authors = lines.map { |l| l.strip }
return authors
end
puts '<!DOCTYPE html><html lang="en"><head><title>Git Charts</title><style type="text/css" media="screen">body{margin: 20px;padding: 0px;}img{margin: 0 0 10px;}</style></head><body>'
puts '<img src="'+chart_commits+'" />'
puts '<img src="'+chart_timeline+'" />'
puts '<img src="'+chart_authors+'" />'
puts '</body></html>'</string>
<key>input</key>
<string>none</string>
<key>keyEquivalent</key>
<string>@G</string>
<key>name</key>
<string>Show Git Charts</string>
<key>output</key>
<string>showAsHTML</string>
<key>uuid</key>
<string>CFA55679-6FF9-46F7-BE1E-5B5A2FD334CA</string>
</dict>
</plist>