From cf27a2967b47bfb2b82ff9d8c62d01c69db49c81 Mon Sep 17 00:00:00 2001 From: Tomasz Gieniusz Date: Fri, 19 Oct 2012 22:01:01 +0200 Subject: [PATCH] commits_period method --- lib/git_stats/git_data/repo.rb | 4 ++++ spec/integration/repo_spec.rb | 4 ++++ templates/index.haml | 6 +++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/git_stats/git_data/repo.rb b/lib/git_stats/git_data/repo.rb index 044b612b5..5c9d70144 100644 --- a/lib/git_stats/git_data/repo.rb +++ b/lib/git_stats/git_data/repo.rb @@ -32,6 +32,10 @@ module GitStats end.sort_by! { |e| e.date }.extend(ByFieldFinder) end + def commits_period + commits.map(&:date).minmax + end + def last_commit commits.last end diff --git a/spec/integration/repo_spec.rb b/spec/integration/repo_spec.rb index 7d2bae606..0f6da7be8 100644 --- a/spec/integration/repo_spec.rb +++ b/spec/integration/repo_spec.rb @@ -10,6 +10,10 @@ describe GitStats::GitData::Repo do ] end + it 'should calculate correct commits period' do + repo.commits_period.should == [DateTime.parse('2012-10-19 10:44:34 +0200'), DateTime.parse('2012-10-26 17:05:25 +0200')] + end + it 'should gather all commits sorted by date' do repo.commits.map(&:hash).should =~ %w(b3b4f81 d60b5ec ab47ef8 2c11f5e c87ecf9 b621a5d fd66657 81e8bef 4e7d0e9 872955c) end diff --git a/templates/index.haml b/templates/index.haml index f53d70eee..c3354dea6 100644 --- a/templates/index.haml +++ b/templates/index.haml @@ -13,13 +13,13 @@ %td= "GitStats #{GitStats::VERSION}" %tr %td Report period - %td= repo.commits.map(&:date).minmax.map {|d| d.to_formatted_s(:long)}.join(" .. ") + %td= repo.commits_period.map {|d| d.to_formatted_s(:long)}.join(" .. ") %tr %td Total files - %td= repo.commits.last.files_count + %td= repo.files_count %tr %td Total lines - %td= "#{repo.commits.last.lines_count} lines (#{repo.short_stats.map(&:insertions).sum} insertions, #{repo.short_stats.map(&:deletions).sum} deletions)" + %td= "#{repo.lines_count} lines (#{repo.short_stats.map(&:insertions).sum} insertions, #{repo.short_stats.map(&:deletions).sum} deletions)" %tr %td Total commits %td= repo.commits.size