GitAuthor and GitCommit

This commit is contained in:
Tomasz Gieniusz 2012-10-08 19:56:49 +02:00
parent bc44bfa01d
commit 1203e33f3d
9 changed files with 72 additions and 13 deletions

View file

@ -1,4 +1,4 @@
require 'git_stats/generator'
module GitStats
end
Dir['lib/**/*.rb'].each { |r| require File.expand_path(r) }

View file

@ -8,7 +8,7 @@ class GitStats::CLI
repo_path, out_path = args
validate(repo_path, out_path)
GitStats::Generator.new(repo_path, out_path).generate
Launchy.open("#{out_path}/index.html")
#Launchy.open("#{out_path}/index.html")
else
puts "Wrong number of arguments"
help

View file

@ -1,3 +1,7 @@
require 'git_stats/git_data'
require 'git_stats/assets'
require 'git_stats/template'
class GitStats::Generator
def initialize(repo_path, out_path)
@repo_path, @out_path = repo_path, out_path

View file

@ -0,0 +1,7 @@
require 'git_stats/hash_initializable'
class GitStats::GitAuthor
include HashInitializable
attr_accessor :name, :email
end

View file

@ -0,0 +1,7 @@
require 'git_stats/hash_initializable'
class GitStats::GitCommit
include HashInitializable
attr_accessor :hash, :stamp, :date, :author
end

View file

@ -1,3 +1,7 @@
require 'pathname'
require 'git_stats/git_author'
require 'git_stats/git_commit'
class GitStats::GitData
attr_reader :total_authors
attr_reader :total_commits
@ -7,8 +11,41 @@ class GitStats::GitData
end
def gather_all_data
Dir.chdir(@repo_path) {
@total_authors = %x[git shortlog -s HEAD | wc -l]
}
@total_authors = run('git shortlog -s HEAD | wc -l')
gather_commit_data
end
def gather_commit_data
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('|')
authors[author_email] = GitStats::GitAuthor.new(name: author_name, email: author_email) unless authors[author_email]
author = authors[author_email]
commits[hash] = GitStats::GitCommit.new(hash: hash, stamp: stamp, date: date, author: author)
end
end
def authors
@authors ||= {}
end
def commits
@commits ||= {}
end
def project_version
@project_version ||= run('git rev-parse --short HEAD')
end
def project_name
@project_name ||= Pathname(@repo_path).basename.to_s
end
def run(command)
in_repo { %x[#{command}] }
end
def in_repo
Dir.chdir(@repo_path) { yield }
end
end

View file

@ -0,0 +1,5 @@
module HashInitializable
def initialize(params)
params.each { |k, v| instance_variable_set("@#{k}", v) }
end
end

View file

@ -1,7 +1,3 @@
%table
%tr
%td= total_authors
%td bbb
%tr
%td cc
%td dd
%p= total_authors
%p= project_version
%p= project_name

View file

@ -4,6 +4,9 @@
%head
%title GitStats
%link{:rel => "stylesheet", :href => "assets/bootstrap/css/bootstrap.min.css", :type => "text/css"}
%style
:plain
body { padding-top: 60px; }
%link{:rel => "stylesheet", :href => "assets/bootstrap/css/bootstrap-responsive.min.css", :type => "text/css"}
%script{:src => "assets/jquery.min.js", :type => "text/javascript"}
%script{:src => "assets/bootstrap/js/bootstrap.min.js", :type => "text/javascript"}