mirror of
https://github.com/tomgi/git_stats.git
synced 2024-12-22 13:32:17 +01:00
files and lines by extension
This commit is contained in:
parent
5d2f838bae
commit
7ce8a2a7eb
9 changed files with 39 additions and 4 deletions
|
@ -15,6 +15,10 @@ module GitStats
|
||||||
@content ||= Command.new(repo, "git cat-file blob #{self.hash}").run
|
@content ||= Command.new(repo, "git cat-file blob #{self.hash}").run
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def extension
|
||||||
|
@ext ||= File.extname(filename)
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"#{self.class} #@hash #@filename"
|
"#{self.class} #@hash #@filename"
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,6 +15,14 @@ module GitStats
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def files_by_extension
|
||||||
|
@files_by_extension ||= files.inject({}) { |acc, f| acc[f.extension] ||= []; acc[f.extension] << f; acc }
|
||||||
|
end
|
||||||
|
|
||||||
|
def lines_by_extension
|
||||||
|
@lines_by_extension ||= Hash[files_by_extension.map { |ext, files| [ext, files.map(&:lines_count).sum] }]
|
||||||
|
end
|
||||||
|
|
||||||
def files_count
|
def files_count
|
||||||
@files_count ||= Command.new(repo, "git ls-tree -r --name-only #{self.hash} | wc -l").run.to_i
|
@files_count ||= Command.new(repo, "git ls-tree -r --name-only #{self.hash} | wc -l").run.to_i
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
module HashInitializable
|
module HashInitializable
|
||||||
def initialize(params = {})
|
def initialize(params = {})
|
||||||
|
raise "pass a Hash to initialize #{self.class}" unless params.is_a? Hash
|
||||||
params.each { |k, v| instance_variable_set("@#{k}", v) }
|
params.each { |k, v| instance_variable_set("@#{k}", v) }
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -42,6 +42,26 @@ module GitStats
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def files_by_extension
|
||||||
|
@files_by_extension ||= LazyHighCharts::HighChart.new('graph') do |f|
|
||||||
|
f.chart(type: "column")
|
||||||
|
f.title(text: "files by extension")
|
||||||
|
f.xAxis(categories: repo.commits.last.files_by_extension.keys)
|
||||||
|
f.yAxis(min: 0, title: {text: 'Commits'})
|
||||||
|
f.series(name: "commits", data: repo.commits.last.files_by_extension.values.map(&:count))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def lines_by_extension
|
||||||
|
@lines_by_extension ||= LazyHighCharts::HighChart.new('graph') do |f|
|
||||||
|
f.chart(type: "column")
|
||||||
|
f.title(text: "files by extension")
|
||||||
|
f.xAxis(categories: repo.commits.last.lines_by_extension.keys)
|
||||||
|
f.yAxis(min: 0, title: {text: 'Commits'})
|
||||||
|
f.series(name: "commits", data: repo.commits.last.lines_by_extension.values)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def files_by_date
|
def files_by_date
|
||||||
@files_by_date ||= LazyHighCharts::HighChart.new('graph') do |f|
|
@files_by_date ||= LazyHighCharts::HighChart.new('graph') do |f|
|
||||||
f.title(text: "Files")
|
f.title(text: "Files")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe GitStats::GitData::Author do
|
describe GitStats::GitData::Author do
|
||||||
let(:repo) { GitStats::GitData::Repo.new("repo_path") }
|
let(:repo) { GitStats::GitData::Repo.new(path: "repo_path") }
|
||||||
let(:author) { GitStats::GitData::Author.new(repo: repo, name: "author1", email: "author1@gmail.com") }
|
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(:other_author) { GitStats::GitData::Author.new(repo: repo, name: "author2", email: "author2@gmail.com") }
|
||||||
let(:my_commits) { 10.times.map { |i| double("my_commit #{i}", :author => author) } }
|
let(:my_commits) { 10.times.map { |i| double("my_commit #{i}", :author => author) } }
|
||||||
|
|
|
@ -19,7 +19,7 @@ describe GitStats::Generator do
|
||||||
|
|
||||||
it 'should render all templates with view data for this repo' do
|
it 'should render all templates with view data for this repo' do
|
||||||
repo = double('repo')
|
repo = double('repo')
|
||||||
GitStats::GitData::Repo.should_receive(:new).with(repo_path).and_return(repo)
|
GitStats::GitData::Repo.should_receive(:new).with(path: repo_path, git_command_observer: nil).and_return(repo)
|
||||||
|
|
||||||
view_data = double('view_data')
|
view_data = double('view_data')
|
||||||
GitStats::StatsView::ViewData.should_receive(:new).with(repo).and_return(view_data)
|
GitStats::StatsView::ViewData.should_receive(:new).with(repo).and_return(view_data)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe GitStats::GitData::Repo do
|
describe GitStats::GitData::Repo do
|
||||||
let(:repo) { GitStats::GitData::Repo.new("repo_path") }
|
let(:repo) { GitStats::GitData::Repo.new(path: "repo_path") }
|
||||||
|
|
||||||
describe 'git output parsing' do
|
describe 'git output parsing' do
|
||||||
before {
|
before {
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
= high_chart("files_by_date", files_by_date)
|
= high_chart("files_by_date", files_by_date)
|
||||||
|
= high_chart("files_by_extension", files_by_extension)
|
|
@ -1 +1,2 @@
|
||||||
= high_chart("lines_by_date", lines_by_date)
|
= high_chart("lines_by_date", lines_by_date)
|
||||||
|
= high_chart("lines_by_extension", lines_by_extension)
|
Loading…
Reference in a new issue