mirror of
https://github.com/tomgi/git_stats.git
synced 2024-12-22 13:32:17 +01:00
GitAuthor and GitCommit
This commit is contained in:
parent
bc44bfa01d
commit
1203e33f3d
9 changed files with 72 additions and 13 deletions
|
@ -1,4 +1,4 @@
|
|||
require 'git_stats/generator'
|
||||
|
||||
module GitStats
|
||||
end
|
||||
|
||||
Dir['lib/**/*.rb'].each { |r| require File.expand_path(r) }
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
7
lib/git_stats/git_author.rb
Normal file
7
lib/git_stats/git_author.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require 'git_stats/hash_initializable'
|
||||
|
||||
class GitStats::GitAuthor
|
||||
include HashInitializable
|
||||
|
||||
attr_accessor :name, :email
|
||||
end
|
7
lib/git_stats/git_commit.rb
Normal file
7
lib/git_stats/git_commit.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require 'git_stats/hash_initializable'
|
||||
|
||||
class GitStats::GitCommit
|
||||
include HashInitializable
|
||||
|
||||
attr_accessor :hash, :stamp, :date, :author
|
||||
end
|
|
@ -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
|
||||
|
|
5
lib/git_stats/hash_initializable.rb
Normal file
5
lib/git_stats/hash_initializable.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
module HashInitializable
|
||||
def initialize(params)
|
||||
params.each { |k, v| instance_variable_set("@#{k}", v) }
|
||||
end
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -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"}
|
||||
|
|
Loading…
Reference in a new issue