diff --git a/lib/git_stats.rb b/lib/git_stats.rb index 4fd7529f2..e4b12884d 100644 --- a/lib/git_stats.rb +++ b/lib/git_stats.rb @@ -1,4 +1,4 @@ +require 'git_stats/generator' + module GitStats end - -Dir['lib/**/*.rb'].each { |r| require File.expand_path(r) } \ No newline at end of file diff --git a/lib/git_stats/cli.rb b/lib/git_stats/cli.rb index 325e681e3..dabe22b07 100644 --- a/lib/git_stats/cli.rb +++ b/lib/git_stats/cli.rb @@ -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 diff --git a/lib/git_stats/generator.rb b/lib/git_stats/generator.rb index c07cad925..33e5b3101 100644 --- a/lib/git_stats/generator.rb +++ b/lib/git_stats/generator.rb @@ -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 diff --git a/lib/git_stats/git_author.rb b/lib/git_stats/git_author.rb new file mode 100644 index 000000000..bd80f6bf5 --- /dev/null +++ b/lib/git_stats/git_author.rb @@ -0,0 +1,7 @@ +require 'git_stats/hash_initializable' + +class GitStats::GitAuthor + include HashInitializable + + attr_accessor :name, :email +end \ No newline at end of file diff --git a/lib/git_stats/git_commit.rb b/lib/git_stats/git_commit.rb new file mode 100644 index 000000000..aafcdda68 --- /dev/null +++ b/lib/git_stats/git_commit.rb @@ -0,0 +1,7 @@ +require 'git_stats/hash_initializable' + +class GitStats::GitCommit + include HashInitializable + + attr_accessor :hash, :stamp, :date, :author +end \ No newline at end of file diff --git a/lib/git_stats/git_data.rb b/lib/git_stats/git_data.rb index f08b5566f..f9d8c3b57 100644 --- a/lib/git_stats/git_data.rb +++ b/lib/git_stats/git_data.rb @@ -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 diff --git a/lib/git_stats/hash_initializable.rb b/lib/git_stats/hash_initializable.rb new file mode 100644 index 000000000..676dc2a7d --- /dev/null +++ b/lib/git_stats/hash_initializable.rb @@ -0,0 +1,5 @@ +module HashInitializable + def initialize(params) + params.each { |k, v| instance_variable_set("@#{k}", v) } + end +end \ No newline at end of file diff --git a/templates/index.haml b/templates/index.haml index 3aaf5fc83..3cef5210e 100644 --- a/templates/index.haml +++ b/templates/index.haml @@ -1,7 +1,3 @@ -%table - %tr - %td= total_authors - %td bbb - %tr - %td cc - %td dd \ No newline at end of file +%p= total_authors +%p= project_version +%p= project_name diff --git a/templates/layout.haml b/templates/layout.haml index 121e64caf..38a694d7d 100644 --- a/templates/layout.haml +++ b/templates/layout.haml @@ -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"}