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
78f22ed848
commit
e29d388b68
9 changed files with 65 additions and 57 deletions
|
@ -1,7 +1,11 @@
|
|||
module GitStats
|
||||
end
|
||||
|
||||
require 'active_support/all'
|
||||
require 'action_pack'
|
||||
require 'action_view'
|
||||
require 'git_stats/generator'
|
||||
|
||||
module GitStats
|
||||
end
|
||||
require 'pathname'
|
||||
require 'tilt'
|
||||
require 'lazy_high_charts'
|
||||
require 'launchy'
|
||||
Dir['lib/**/*.rb'].each { |r| require File.expand_path(r) }
|
|
@ -1,5 +1,4 @@
|
|||
require "git_stats"
|
||||
require "launchy"
|
||||
|
||||
class GitStats::CLI
|
||||
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
require 'git_stats/git_data/git_data'
|
||||
require 'git_stats/template/assets'
|
||||
require 'git_stats/template/template'
|
||||
|
||||
class GitStats::Generator
|
||||
def initialize(repo_path, out_path)
|
||||
@repo_path, @out_path = repo_path, out_path
|
||||
|
@ -9,9 +5,7 @@ class GitStats::Generator
|
|||
|
||||
def generate
|
||||
data = GitStats::GitData.new(@repo_path)
|
||||
data.gather_all_data
|
||||
GitStats::Assets.prepare(@out_path)
|
||||
output = GitStats::Template.new('index').render(data)
|
||||
File.open("#@out_path/index.html", 'w') { |f| f.write output }
|
||||
view_data = GitStats::ViewData.new(data)
|
||||
GitStats::View.render_all(view_data, @out_path)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,27 +1,19 @@
|
|||
require 'pathname'
|
||||
require 'git_stats/git_data/git_activity'
|
||||
require 'git_stats/git_data/git_author'
|
||||
require 'git_stats/git_data/git_commit'
|
||||
require 'lazy_high_charts'
|
||||
|
||||
class GitStats::GitData
|
||||
include ActionView::Helpers::TagHelper
|
||||
include LazyHighCharts::LayoutHelper
|
||||
|
||||
attr_reader :total_authors
|
||||
attr_reader :total_commits
|
||||
|
||||
def initialize(repo_path)
|
||||
@repo_path = repo_path
|
||||
gather_all
|
||||
end
|
||||
|
||||
def gather_all_data
|
||||
def gather_all
|
||||
@total_authors = run('git shortlog -s HEAD | wc -l')
|
||||
|
||||
gather_commit_data
|
||||
gather_commits
|
||||
end
|
||||
|
||||
def gather_commit_data
|
||||
def gather_commits
|
||||
run('git rev-list --pretty=format:"%h|%at|%ai|%aN|%aE" HEAD | grep -v commit').split(/\r?\n/).each do |commit|
|
||||
hash, stamp, date, author_name, author_email = commit.split('|')
|
||||
|
||||
|
@ -39,26 +31,6 @@ class GitStats::GitData
|
|||
author.activity.by_wday[date.wday] += 1
|
||||
author.activity.by_wday_hour[date.wday][date.hour] += 1
|
||||
end
|
||||
|
||||
@h = LazyHighCharts::HighChart.new('graph') do |f|
|
||||
f.chart(type: "column")
|
||||
f.title(text: "Commits")
|
||||
f.xAxis(categories: Date::ABBR_DAYNAMES)
|
||||
f.yAxis(min: 0, title: {text: 'Commits'})
|
||||
f.legend(
|
||||
layout: 'vertical',
|
||||
backgroundColor: '#FFFFFF',
|
||||
align: 'left',
|
||||
verticalAlign: 'top',
|
||||
x: 100,
|
||||
y: 70,
|
||||
floating: true,
|
||||
shadow: true
|
||||
)
|
||||
authors.each do |email, author|
|
||||
f.series(:name => email, :data => author.activity.by_wday.inject([]) { |acc, (k, v)| acc[k] = v; acc })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def authors
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
class GitStats::Assets
|
||||
def self.prepare(out_path)
|
||||
FileUtils.cp_r('templates/assets', out_path)
|
||||
end
|
||||
end
|
|
@ -1,9 +1,7 @@
|
|||
require 'tilt'
|
||||
|
||||
class GitStats::Template
|
||||
def initialize(name)
|
||||
def initialize(name, layout)
|
||||
@name = name
|
||||
@layout = Tilt.new("templates/layout.haml")
|
||||
@layout = layout
|
||||
@template = Tilt.new("templates/#@name.haml")
|
||||
end
|
||||
|
13
lib/git_stats/view/view.rb
Normal file
13
lib/git_stats/view/view.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
class GitStats::View
|
||||
def self.render_all(data, out_path)
|
||||
prepare_assets(out_path)
|
||||
|
||||
layout = Tilt.new("templates/layout.haml")
|
||||
output = GitStats::Template.new('index', layout).render(data)
|
||||
File.open("#{out_path}/index.html", 'w') { |f| f.write output }
|
||||
end
|
||||
|
||||
def self.prepare_assets(out_path)
|
||||
FileUtils.cp_r('templates/assets', out_path)
|
||||
end
|
||||
end
|
33
lib/git_stats/view/view_data.rb
Normal file
33
lib/git_stats/view/view_data.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
class GitStats::ViewData
|
||||
include ActionView::Helpers::TagHelper
|
||||
include LazyHighCharts::LayoutHelper
|
||||
|
||||
attr_accessor :git_data
|
||||
|
||||
def initialize(git_data)
|
||||
self.git_data = git_data
|
||||
generate_charts
|
||||
end
|
||||
|
||||
def generate_charts
|
||||
@h = LazyHighCharts::HighChart.new('graph') do |f|
|
||||
f.chart(type: "column")
|
||||
f.title(text: "Commits")
|
||||
f.xAxis(categories: Date::ABBR_DAYNAMES)
|
||||
f.yAxis(min: 0, title: {text: 'Commits'})
|
||||
f.legend(
|
||||
layout: 'vertical',
|
||||
backgroundColor: '#FFFFFF',
|
||||
align: 'left',
|
||||
verticalAlign: 'top',
|
||||
x: 100,
|
||||
y: 70,
|
||||
floating: true,
|
||||
shadow: true
|
||||
)
|
||||
git_data.authors.each do |email, author|
|
||||
f.series(:name => email, :data => author.activity.by_wday.inject([]) { |acc, (k, v)| acc[k] = v; acc })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
%p= total_authors
|
||||
%p= project_version
|
||||
%p= project_name
|
||||
%p= git_data.total_authors
|
||||
%p= git_data.project_version
|
||||
%p= git_data.project_name
|
||||
|
||||
= high_chart("my_id", @h)
|
Loading…
Reference in a new issue