mirror of
https://github.com/tomgi/git_stats.git
synced 2024-12-22 13:32:17 +01:00
refactor
This commit is contained in:
parent
ca4783d5bf
commit
5cfd782716
8 changed files with 96 additions and 46 deletions
|
@ -27,20 +27,14 @@ module GitStats
|
|||
}
|
||||
end
|
||||
|
||||
def lines_added_by_date
|
||||
sum = 0
|
||||
commits.map { |commit|
|
||||
sum += commit.short_stat.insertions
|
||||
[commit.date, sum]
|
||||
}
|
||||
end
|
||||
|
||||
def lines_deleted_by_date
|
||||
sum = 0
|
||||
commits.map { |commit|
|
||||
sum += commit.short_stat.deletions
|
||||
[commit.date, sum]
|
||||
}
|
||||
[:insertions, :deletions].each do |method|
|
||||
define_method "#{method}_by_date" do
|
||||
sum = 0
|
||||
commits.map { |commit|
|
||||
sum += commit.short_stat.send(method)
|
||||
[commit.date, sum]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def short_stats
|
||||
|
|
|
@ -41,12 +41,10 @@ module GitStats
|
|||
Hash[authors.map { |author| [author, author.commits.size] }.sort_by { |author, commits| -commits }[0..limit]]
|
||||
end
|
||||
|
||||
def lines_added_by_author(limit = 4)
|
||||
Hash[authors.map { |author| [author, author.lines_added] }.sort_by { |author, lines| -lines }[0..limit]]
|
||||
end
|
||||
|
||||
def lines_deleted_by_author(limit = 4)
|
||||
Hash[authors.map { |author| [author, author.lines_deleted] }.sort_by { |author, lines| -lines }[0..limit]]
|
||||
[:lines_added, :lines_deleted].each do |method|
|
||||
define_method "#{method}_by_author" do |limit = 4|
|
||||
Hash[authors.map { |author| [author, author.send(method)] }.sort_by { |author, lines| -lines }[0..limit]]
|
||||
end
|
||||
end
|
||||
|
||||
def files_count_by_date
|
||||
|
|
|
@ -19,7 +19,7 @@ module GitStats
|
|||
def lines_added_by_author_by_date(limit = 4)
|
||||
Chart.new do |f|
|
||||
f.multi_date_chart(
|
||||
data: @authors.sort_by { |author| -author.lines_added }[0..limit].map { |author| {name: author.email, data: author.lines_added_by_date} },
|
||||
data: @authors.sort_by { |author| -author.lines_added }[0..limit].map { |author| {name: author.email, data: author.insertions_by_date} },
|
||||
title: :lines_by_date.t,
|
||||
y_text: :lines.t
|
||||
)
|
||||
|
@ -29,7 +29,7 @@ module GitStats
|
|||
def lines_deleted_by_author_by_date(limit = 4)
|
||||
Chart.new do |f|
|
||||
f.multi_date_chart(
|
||||
data: @authors.sort_by { |author| -author.lines_deleted }[0..limit].map { |author| {name: author.email, data: author.lines_deleted_by_date} },
|
||||
data: @authors.sort_by { |author| -author.lines_deleted }[0..limit].map { |author| {name: author.email, data: author.deletions_by_date} },
|
||||
title: :lines_by_date.t,
|
||||
y_text: :lines.t
|
||||
)
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
require 'spec_helper'
|
||||
require 'integration/shared'
|
||||
|
||||
describe GitStats::GitData::Activity do
|
||||
let(:repo) { build(:test_repo, last_commit_hash: '872955c') }
|
||||
include_context "shared"
|
||||
|
||||
let(:activity) { repo.activity }
|
||||
|
||||
it 'should count commits by hour' do
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
require 'integration/shared'
|
||||
|
||||
describe GitStats::GitData::Activity do
|
||||
let(:repo) { build(:test_repo, last_commit_hash: '872955c') }
|
||||
include_context "shared"
|
||||
|
||||
let(:tg) { repo.authors.by_email('tomasz.gieniusz@gmail.com') }
|
||||
let(:jd) { repo.authors.by_email('john.doe@gmail.com') }
|
||||
|
@ -41,5 +41,26 @@ describe GitStats::GitData::Activity do
|
|||
tg.activity.by_year_month.should == {2012 => {10 => 8}}
|
||||
jd.activity.by_year_month.should == {2012 => {10 => 2}}
|
||||
end
|
||||
|
||||
it 'should count commits_sum_by_date' do
|
||||
tg.commits_sum_by_date.map { |d, s| d }.should == tg_commit_dates
|
||||
tg.commits_sum_by_date.map { |d, s| s }.should == [1, 2, 3, 4, 5, 6, 7, 8]
|
||||
jd.commits_sum_by_date.map { |d, s| d }.should == jd_commit_dates
|
||||
jd.commits_sum_by_date.map { |d, s| s }.should == [1, 2]
|
||||
end
|
||||
|
||||
it 'should count lines_added_by_date' do
|
||||
tg.insertions_by_date.map { |d, s| d }.should == tg_commit_dates
|
||||
tg.insertions_by_date.map { |d, s| s }.should == [4, 9, 14, 15, 20, 1020, 1021, 1021]
|
||||
jd.insertions_by_date.map { |d, s| d }.should == jd_commit_dates
|
||||
jd.insertions_by_date.map { |d, s| s }.should == [3, 103]
|
||||
end
|
||||
|
||||
it 'should count lines_deleted_by_date' do
|
||||
tg.deletions_by_date.map { |d, s| d }.should == tg_commit_dates
|
||||
tg.deletions_by_date.map { |d, s| s }.should == [0, 0, 4, 4, 9, 9, 10, 10]
|
||||
jd.deletions_by_date.map { |d, s| d }.should == jd_commit_dates
|
||||
jd.deletions_by_date.map { |d, s| s }.should == [0, 0]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
require 'integration/shared'
|
||||
|
||||
describe GitStats::GitData::Repo do
|
||||
let(:repo) { build(:test_repo, last_commit_hash: '872955c') }
|
||||
include_context "shared"
|
||||
|
||||
it 'should gather all files in repo' do
|
||||
repo.files.map(&:filename).should =~ %w(long_second.haml long.txt second.txt test2.rb test.rb test.txt)
|
||||
|
|
|
@ -1,25 +1,10 @@
|
|||
require 'spec_helper'
|
||||
require 'integration/shared'
|
||||
|
||||
describe GitStats::GitData::Repo do
|
||||
let(:repo) { build(:test_repo, last_commit_sha: '872955c') }
|
||||
let(:commit_dates) { [
|
||||
DateTime.parse('2012-10-19 10:44:34 +0200'),
|
||||
DateTime.parse('2012-10-19 10:46:10 +0200'),
|
||||
DateTime.parse('2012-10-19 10:46:56 +0200'),
|
||||
DateTime.parse('2012-10-19 10:47:35 +0200'),
|
||||
DateTime.parse('2012-10-20 12:49:02 +0200'),
|
||||
DateTime.parse('2012-10-21 12:49:02 +0200'),
|
||||
DateTime.parse('2012-10-21 12:54:02 +0200'),
|
||||
DateTime.parse('2012-10-21 13:20:00 +0200'),
|
||||
DateTime.parse('2012-10-24 15:49:02 +0200'),
|
||||
DateTime.parse('2012-10-26 17:05:25 +0200'),
|
||||
] }
|
||||
include_context "shared"
|
||||
|
||||
it 'should gather all authors' do
|
||||
repo.authors.should =~ [
|
||||
build(:author, repo: repo, name: "Tomasz Gieniusz", email: "tomasz.gieniusz@gmail.com"),
|
||||
build(:author, repo: repo, name: "John Doe", email: "john.doe@gmail.com"),
|
||||
]
|
||||
repo.authors.should =~ expected_authors
|
||||
end
|
||||
|
||||
it 'should calculate correct commits period' do
|
||||
|
@ -64,4 +49,19 @@ describe GitStats::GitData::Repo do
|
|||
repo.lines_by_extension.should == {'.haml' => 100, '.txt' => 1008, '.rb' => 6}
|
||||
end
|
||||
|
||||
it 'should count commits_count_by_author' do
|
||||
repo.commits_count_by_author.keys.should == expected_authors
|
||||
repo.commits_count_by_author.values.should == [8, 2]
|
||||
end
|
||||
|
||||
it 'should count lines_added_by_author' do
|
||||
repo.lines_added_by_author.keys.should == expected_authors
|
||||
repo.lines_added_by_author.values.should == [1021, 103]
|
||||
end
|
||||
|
||||
it 'should count lines_deleted_by_author' do
|
||||
repo.lines_deleted_by_author.keys.should == expected_authors
|
||||
repo.lines_deleted_by_author.values.should == [10, 0]
|
||||
end
|
||||
|
||||
end
|
36
spec/integration/shared.rb
Normal file
36
spec/integration/shared.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
require 'spec_helper'
|
||||
|
||||
shared_context "shared" do
|
||||
let(:repo) { build(:test_repo, last_commit_sha: '872955c') }
|
||||
let(:commit_dates) { [
|
||||
DateTime.parse('2012-10-19 10:44:34 +0200'),
|
||||
DateTime.parse('2012-10-19 10:46:10 +0200'),
|
||||
DateTime.parse('2012-10-19 10:46:56 +0200'),
|
||||
DateTime.parse('2012-10-19 10:47:35 +0200'),
|
||||
DateTime.parse('2012-10-20 12:49:02 +0200'),
|
||||
DateTime.parse('2012-10-21 12:49:02 +0200'),
|
||||
DateTime.parse('2012-10-21 12:54:02 +0200'),
|
||||
DateTime.parse('2012-10-21 13:20:00 +0200'),
|
||||
DateTime.parse('2012-10-24 15:49:02 +0200'),
|
||||
DateTime.parse('2012-10-26 17:05:25 +0200'),
|
||||
] }
|
||||
let(:tg_commit_dates) { [
|
||||
DateTime.parse('2012-10-19 10:44:34 +0200'),
|
||||
DateTime.parse('2012-10-19 10:46:10 +0200'),
|
||||
DateTime.parse('2012-10-19 10:46:56 +0200'),
|
||||
DateTime.parse('2012-10-19 10:47:35 +0200'),
|
||||
DateTime.parse('2012-10-20 12:49:02 +0200'),
|
||||
DateTime.parse('2012-10-21 12:49:02 +0200'),
|
||||
DateTime.parse('2012-10-21 13:20:00 +0200'),
|
||||
DateTime.parse('2012-10-26 17:05:25 +0200'),
|
||||
] }
|
||||
let(:jd_commit_dates) { [
|
||||
DateTime.parse('2012-10-21 12:54:02 +0200'),
|
||||
DateTime.parse('2012-10-24 15:49:02 +0200'),
|
||||
] }
|
||||
|
||||
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"),
|
||||
] }
|
||||
end
|
Loading…
Reference in a new issue