mirror of
https://github.com/tomgi/git_stats.git
synced 2025-01-03 11:12:11 +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 'active_support/all'
|
||||||
require 'action_pack'
|
require 'action_pack'
|
||||||
require 'action_view'
|
require 'action_view'
|
||||||
require 'git_stats/generator'
|
require 'pathname'
|
||||||
|
require 'tilt'
|
||||||
module GitStats
|
require 'lazy_high_charts'
|
||||||
end
|
require 'launchy'
|
||||||
|
Dir['lib/**/*.rb'].each { |r| require File.expand_path(r) }
|
|
@ -1,5 +1,4 @@
|
||||||
require "git_stats"
|
require "git_stats"
|
||||||
require "launchy"
|
|
||||||
|
|
||||||
class GitStats::CLI
|
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
|
class GitStats::Generator
|
||||||
def initialize(repo_path, out_path)
|
def initialize(repo_path, out_path)
|
||||||
@repo_path, @out_path = repo_path, out_path
|
@repo_path, @out_path = repo_path, out_path
|
||||||
|
@ -9,9 +5,7 @@ class GitStats::Generator
|
||||||
|
|
||||||
def generate
|
def generate
|
||||||
data = GitStats::GitData.new(@repo_path)
|
data = GitStats::GitData.new(@repo_path)
|
||||||
data.gather_all_data
|
view_data = GitStats::ViewData.new(data)
|
||||||
GitStats::Assets.prepare(@out_path)
|
GitStats::View.render_all(view_data, @out_path)
|
||||||
output = GitStats::Template.new('index').render(data)
|
|
||||||
File.open("#@out_path/index.html", 'w') { |f| f.write output }
|
|
||||||
end
|
end
|
||||||
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
|
class GitStats::GitData
|
||||||
include ActionView::Helpers::TagHelper
|
|
||||||
include LazyHighCharts::LayoutHelper
|
|
||||||
|
|
||||||
attr_reader :total_authors
|
attr_reader :total_authors
|
||||||
attr_reader :total_commits
|
attr_reader :total_commits
|
||||||
|
|
||||||
def initialize(repo_path)
|
def initialize(repo_path)
|
||||||
@repo_path = repo_path
|
@repo_path = repo_path
|
||||||
|
gather_all
|
||||||
end
|
end
|
||||||
|
|
||||||
def gather_all_data
|
def gather_all
|
||||||
@total_authors = run('git shortlog -s HEAD | wc -l')
|
@total_authors = run('git shortlog -s HEAD | wc -l')
|
||||||
|
|
||||||
gather_commit_data
|
gather_commits
|
||||||
end
|
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|
|
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('|')
|
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[date.wday] += 1
|
||||||
author.activity.by_wday_hour[date.wday][date.hour] += 1
|
author.activity.by_wday_hour[date.wday][date.hour] += 1
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def authors
|
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
|
class GitStats::Template
|
||||||
def initialize(name)
|
def initialize(name, layout)
|
||||||
@name = name
|
@name = name
|
||||||
@layout = Tilt.new("templates/layout.haml")
|
@layout = layout
|
||||||
@template = Tilt.new("templates/#@name.haml")
|
@template = Tilt.new("templates/#@name.haml")
|
||||||
end
|
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= git_data.total_authors
|
||||||
%p= project_version
|
%p= git_data.project_version
|
||||||
%p= project_name
|
%p= git_data.project_name
|
||||||
|
|
||||||
= high_chart("my_id", @h)
|
= high_chart("my_id", @h)
|
Loading…
Reference in a new issue