mirror of https://github.com/tomgi/git_stats.git
more integration tests and refactor
This commit is contained in:
parent
29681665cb
commit
e5206d112e
|
@ -8,11 +8,11 @@ module GitStats
|
|||
attr_reader :repo, :hash, :filename
|
||||
|
||||
def lines_count
|
||||
@lines_count ||= Command.new(repo, "git cat-file blob #{self.hash} | wc -l").run.to_i
|
||||
@lines_count ||= repo.run("git cat-file blob #{self.hash} | wc -l").to_i
|
||||
end
|
||||
|
||||
def content
|
||||
@content ||= Command.new(repo, "git cat-file blob #{self.hash}").run
|
||||
@content ||= repo.run("git cat-file blob #{self.hash}")
|
||||
end
|
||||
|
||||
def extension
|
||||
|
|
|
@ -17,6 +17,10 @@ module GitStats
|
|||
@files_by_extension ||= files.inject({}) { |acc, f| acc[f.extension] ||= []; acc[f.extension] << f; acc }
|
||||
end
|
||||
|
||||
def files_by_extension_count
|
||||
@files_by_extension ||= Hash[files_by_extension.map { |ext, files| [ext, files.count] }]
|
||||
end
|
||||
|
||||
def lines_by_extension
|
||||
@lines_by_extension ||= Hash[files_by_extension.map { |ext, files| [ext, files.map(&:lines_count).sum] }]
|
||||
end
|
||||
|
|
|
@ -5,7 +5,9 @@ module GitStats
|
|||
class Repo
|
||||
include HashInitializable
|
||||
|
||||
attr_reader :path, :git_command_observer
|
||||
attr_reader :path
|
||||
|
||||
delegate :files, :files_by_extension, :files_by_extension_count, :lines_by_extension, :files_count, :lines_count, to: :last_commit
|
||||
|
||||
def initialize(params)
|
||||
super(params)
|
||||
|
@ -28,12 +30,16 @@ module GitStats
|
|||
end.sort_by! { |e| e.date }
|
||||
end
|
||||
|
||||
def commit_range
|
||||
@first_commit ? "#{@first_commit}..#{last_commit}" : last_commit
|
||||
def last_commit
|
||||
commits.last
|
||||
end
|
||||
|
||||
def last_commit
|
||||
@last_commit ||= 'HEAD'
|
||||
def commit_range
|
||||
@first_commit_hash ? "#{@first_commit_hash}..#{last_commit_hash}" : last_commit_hash
|
||||
end
|
||||
|
||||
def last_commit_hash
|
||||
@last_commit_hash ||= 'HEAD'
|
||||
end
|
||||
|
||||
def short_stats
|
||||
|
@ -45,7 +51,7 @@ module GitStats
|
|||
end
|
||||
|
||||
def project_version
|
||||
@project_version ||= run('git rev-parse --short HEAD')
|
||||
@project_version ||= run('git rev-parse --short HEAD').strip
|
||||
end
|
||||
|
||||
def project_name
|
||||
|
|
|
@ -1,14 +1,44 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe GitStats::GitData::Repo do
|
||||
let(:repo) { build(:repo, path: 'spec/integration/test_repo', last_commit: '81e8be') }
|
||||
let(:repo) { build(:repo, path: 'spec/integration/test_repo', last_commit_hash: '45677ee') }
|
||||
let(:expected_authors) { [
|
||||
build(:author, repo: repo, name: "Tomasz Gieniusz", email: "tomasz.gieniusz@gmail.com"),
|
||||
build(:author, repo: repo, name: "John Doe", email: "john.doe@gmail.com"),
|
||||
] }
|
||||
|
||||
it 'should return all authors' do
|
||||
it 'should gather all authors' do
|
||||
repo.authors.should =~ expected_authors
|
||||
end
|
||||
|
||||
it 'should gather all commits sorted by date' do
|
||||
repo.should have(10).commits
|
||||
repo.commits.should be_all { |e| e.is_a? GitStats::GitData::Commit }
|
||||
repo.commits.map(&:hash).should =~ %w(b3b4f81 d60b5ec ab47ef8 2c11f5e c87ecf9 b621a5d fd66657 81e8bef 4e7d0e9 45677ee)
|
||||
end
|
||||
|
||||
it 'should return project name from dir' do
|
||||
repo.project_name.should == 'test_repo'
|
||||
end
|
||||
|
||||
it 'should return project version as last commit hash' do
|
||||
repo.project_version.should == '45677ee'
|
||||
end
|
||||
|
||||
it 'should count files in repo' do
|
||||
repo.files_count.should == 6
|
||||
end
|
||||
|
||||
it 'should count all lines in repo' do
|
||||
repo.lines_count.should == 1114
|
||||
end
|
||||
|
||||
it 'should count files by extension in repo' do
|
||||
repo.files_by_extension_count.should == {'.haml' => 1, '.txt' => 3, '.rb' => 2}
|
||||
end
|
||||
|
||||
it 'should count lines by extension in repo' do
|
||||
repo.lines_by_extension.should == {'.haml' => 100, '.txt' => 1008, '.rb' => 6}
|
||||
end
|
||||
|
||||
end
|
|
@ -1 +1 @@
|
|||
Subproject commit 81e8bef75eaa93d772f2ce11d2a266ada1292741
|
||||
Subproject commit 45677ee1ececcf2e8eab452f8af2c7a3e30e65d9
|
|
@ -13,17 +13,17 @@ describe GitStats::GitData::Repo do
|
|||
end
|
||||
|
||||
it 'should return last_commit if it was given' do
|
||||
repo = build(:repo, last_commit: 'abc')
|
||||
repo = build(:repo, last_commit_hash: 'abc')
|
||||
repo.commit_range.should == 'abc'
|
||||
end
|
||||
|
||||
it 'should return range from first_commit to HEAD if first_commit was given' do
|
||||
repo = build(:repo, first_commit: 'abc')
|
||||
repo = build(:repo, first_commit_hash: 'abc')
|
||||
repo.commit_range.should == 'abc..HEAD'
|
||||
end
|
||||
|
||||
it 'should return range from first to last commit if both were given' do
|
||||
repo = build(:repo, first_commit: 'abc', last_commit: 'def')
|
||||
repo = build(:repo, first_commit_hash: 'abc', last_commit_hash: 'def')
|
||||
repo.commit_range.should == 'abc..def'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue