Class: GitPm::CommitsByDev
- Inherits:
-
Object
- Object
- GitPm::CommitsByDev
- Defined in:
- lib/git_pm/commits_by_dev.rb
Instance Method Summary collapse
- #generate_xls(by_date, stats) ⇒ Object
- #get_day(date) ⇒ Object
-
#initialize(args) ⇒ CommitsByDev
constructor
A new instance of CommitsByDev.
- #run! ⇒ Object
Constructor Details
#initialize(args) ⇒ CommitsByDev
Returns a new instance of CommitsByDev.
3 4 5 |
# File 'lib/git_pm/commits_by_dev.rb', line 3 def initialize(args) @branch = args.shift || "master" end |
Instance Method Details
#generate_xls(by_date, stats) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/git_pm/commits_by_dev.rb', line 56 def generate_xls(by_date, stats) report = Spreadsheet::Workbook.new stats.each do |name, commits_by_date| sheet = report.create_worksheet(:name => name) sheet.column(0).width = 80 row = 0 bold = Spreadsheet::Format.new :weight => :bold by_date.each do |date| commits = commits_by_date[date] || [] sheet.row(row+=1).push date commits.each do |commit| sheet.row(row+=1).push commit end sheet.row(row+=1).push "" sheet.row(row+=1).push "" end end report.write("commits_by_day.xls") end |
#get_day(date) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/git_pm/commits_by_dev.rb', line 39 def get_day(date) month = date.strftime("%B") day = date.day if date.hour < 6 day -= 1 end if day == 0 nd = (Time.parse(date.strftime("%F"))-1) day = nd.day month = nd.strftime("%B") end "#{day} #{month}" end |
#run! ⇒ Object
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 |
# File 'lib/git_pm/commits_by_dev.rb', line 7 def run! data = `git shortlog --date=short --pretty=format:"%at %s" --no-merges --since="3 months ago" #{@branch}` current = nil stats = {} fields = Set.new data.each do |line| if line =~ /^\s{6}(\d+)\s(.+)/ date = Time.at($1.to_i) msg = $2 stats[current] ||= {} (stats[current][get_day(date)] ||= []) << msg fields << Time.parse(date.strftime("%F")) elsif line =~ /^(\S.+)\s\(\d+\):/ current = $1 end end fields = fields.to_a.sort by_date = fields.map {|e| get_day(e) } graph = SVG::Graph::Line.new({:height => 500, :width => 1800*3, :fields => by_date}) stats.each do |name, all_commits| data = by_date.map {|f| (all_commits[f] || []).size } graph.add_data({:data => data, :title => name}) end graph.burn end |