diff --git a/lib/git_stats/git_data/author.rb b/lib/git_stats/git_data/author.rb index a964efb7e..cb89a6fd8 100644 --- a/lib/git_stats/git_data/author.rb +++ b/lib/git_stats/git_data/author.rb @@ -8,7 +8,7 @@ module GitStats attr_reader :repo, :name, :email def commits - @commits ||= repo.commits.select { |hash, commit| commit.author == self } + @commits ||= repo.commits.select { |commit| commit.author == self } end def activity diff --git a/lib/git_stats/git_data/repo.rb b/lib/git_stats/git_data/repo.rb index 208434ffc..960eabf37 100644 --- a/lib/git_stats/git_data/repo.rb +++ b/lib/git_stats/git_data/repo.rb @@ -8,22 +8,24 @@ module GitStats end def authors - @authors ||= Command.new(self, 'git shortlog -se HEAD').run.lines.inject({}) do |authors, line| + @authors ||= Hash[Command.new(self, 'git shortlog -se HEAD').run.lines.map do |line| name, email = line.split(/\t/)[1].strip.scan(/(.*)<(.*)>/).first.map(&:strip) - authors[email] = Author.new(repo: self, name: name, email: email) - authors - end + [email, Author.new(repo: self, name: name, email: email)] + end] end def commits - @commits ||= Command.new(self, 'git rev-list --pretty=format:"%h|%at|%ai|%aE" HEAD | grep -v commit').run.lines.inject({}) do |commits, commit_line| + @commits ||= Command.new(self, 'git rev-list --pretty=format:"%h|%at|%ai|%aE" HEAD | grep -v commit').run.lines.map do |commit_line| hash, stamp, date, author_email = commit_line.split('|').map(&:strip) author = authors[author_email] date = DateTime.parse(date) - commits[hash] = Commit.new(repo: self, hash: hash, stamp: stamp, date: date, author: author) - commits - end + Commit.new(repo: self, hash: hash, stamp: stamp, date: date, author: author) + end.sort_by! { |e| e.date } + end + + def short_stats + @short_stats ||= commits.map(&:short_stat) end def activity diff --git a/lib/git_stats/git_data/short_stat.rb b/lib/git_stats/git_data/short_stat.rb index 49fb40a67..5a21b3bf7 100644 --- a/lib/git_stats/git_data/short_stat.rb +++ b/lib/git_stats/git_data/short_stat.rb @@ -11,7 +11,7 @@ module GitStats def calculate_stat stat_line = Command.new(commit.repo, "git show --shortstat --oneline #{commit.hash}").run.lines.to_a[1] if stat_line.blank? - @files_changed, @insertions, @deletions = 0 + @files_changed = @insertions = @deletions = 0 else @files_changed = stat_line[/(\d+) files? changed/, 1].to_i @insertions = stat_line[/(\d+) insertions?/, 1].to_i diff --git a/spec/author_spec.rb b/spec/author_spec.rb index e73ba4611..d57234eee 100644 --- a/spec/author_spec.rb +++ b/spec/author_spec.rb @@ -4,10 +4,10 @@ describe GitStats::GitData::Author do let(:repo) { GitStats::GitData::Repo.new(path: "repo_path") } let(:author) { GitStats::GitData::Author.new(repo: repo, name: "author1", email: "author1@gmail.com") } let(:other_author) { GitStats::GitData::Author.new(repo: repo, name: "author2", email: "author2@gmail.com") } - let(:my_commits) { Hash[10.times.map { |i| ["my #{i}", double("my_commit #{i}", :author => author)] }] } - let(:other_commits) { Hash[10.times.map { |i| ["other #{i}", double("other_commit #{i}", :author => other_author)] }] } + let(:my_commits) { 10.times.map { |i| double("my_commit #{i}", :author => author) } } + let(:other_commits) { 10.times.map { |i| double("other_commit #{i}", :author => other_author) } } - before { repo.stub(:commits => my_commits.merge(other_commits)) } + before { repo.stub(:commits => my_commits + other_commits) } it 'commits should give repo commits filtered to this author' do author.commits.should == my_commits diff --git a/spec/repo_spec.rb b/spec/repo_spec.rb index 70a0c149b..43755daed 100644 --- a/spec/repo_spec.rb +++ b/spec/repo_spec.rb @@ -19,7 +19,7 @@ describe GitStats::GitData::Repo do } end - it 'should parse git revlist output to commits hash' do + it 'should parse git revlist output to date sorted commits array' do GitStats::GitData::Command.should_receive(:new).with( repo, 'git rev-list --pretty=format:"%h|%at|%ai|%aE" HEAD | grep -v commit').and_return( double(:run => "e4412c3|1348603824|2012-09-25 22:10:24 +0200|john.doe@gmail.com @@ -27,17 +27,17 @@ ce34874|1347482927|2012-09-12 22:48:47 +0200|joe.doe@gmail.com 5eab339|1345835073|2012-08-24 21:04:33 +0200|john.doe@gmail.com ")) - repo.commits.should == { - "e4412c3" => GitStats::GitData::Commit.new( - repo: repo, hash: "e4412c3", stamp: "1348603824", date: DateTime.parse("2012-09-25 22:10:24 +0200"), + repo.commits.should == [ + GitStats::GitData::Commit.new( + repo: repo, hash: "5eab339", stamp: "1345835073", date: DateTime.parse("2012-08-24 21:04:33 +0200"), author: repo.authors["john.doe@gmail.com"]), - "ce34874" => GitStats::GitData::Commit.new( + GitStats::GitData::Commit.new( repo: repo, hash: "ce34874", stamp: "1347482927", date: DateTime.parse("2012-09-12 22:48:47 +0200"), author: repo.authors["joe.doe@gmail.com"]), - "5eab339" => GitStats::GitData::Commit.new( - repo: repo, hash: "5eab339", stamp: "1345835073", date: DateTime.parse("2012-08-24 21:04:33 +0200"), + GitStats::GitData::Commit.new( + repo: repo, hash: "e4412c3", stamp: "1348603824", date: DateTime.parse("2012-09-25 22:10:24 +0200"), author: repo.authors["john.doe@gmail.com"]) - } + ] end end end \ No newline at end of file diff --git a/templates/index.haml b/templates/index.haml index bad59396f..8ad743d04 100644 --- a/templates/index.haml +++ b/templates/index.haml @@ -1,2 +1,28 @@ -%p= repo.project_name -%p= repo.project_version +%table{:class => "table table-hover table-bordered"} + %tr + %td Project name + %td= repo.project_name + %tr + %td Project version + %td= repo.project_version + %tr + %td Generated at + %td= DateTime.now.to_formatted_s(:long) + %tr + %td Generator + %td= "GitStats #{GitStats::VERSION}" + %tr + %td Report period + %td= repo.commits.map(&:date).minmax.map {|d| d.to_formatted_s(:long)}.join(" .. ") + %tr + %td Total files + %td= repo.commits.last.files_count + %tr + %td Total lines + %td= "#{repo.short_stats.map(&:insertions).sum} insertions, #{repo.short_stats.map(&:deletions).sum} deletions" + %tr + %td Total commits + %td= repo.commits.size + %tr + %td Authors + %td= repo.authors.size