mirror of
https://github.com/tomgi/git_stats.git
synced 2024-12-22 13:32:17 +01:00
repo.commits is now date sorted array, index page with simple stats
This commit is contained in:
parent
2d7a7db33c
commit
9ca2ece131
6 changed files with 51 additions and 23 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue