mirror of
https://github.com/tomgi/git_stats.git
synced 2024-12-22 13:32:17 +01:00
it now works also under submodule directory
This commit is contained in:
parent
e80592f03c
commit
ae52078dc0
8 changed files with 53 additions and 90 deletions
|
@ -8,13 +8,12 @@ require 'git_stats/version'
|
||||||
require 'git_stats/i18n'
|
require 'git_stats/i18n'
|
||||||
require 'git_stats/cli'
|
require 'git_stats/cli'
|
||||||
require 'git_stats/generator'
|
require 'git_stats/generator'
|
||||||
require 'git_stats/validator'
|
require 'git_stats/command_runner'
|
||||||
|
require 'git_stats/command_parser'
|
||||||
|
|
||||||
require 'git_stats/git_data/activity'
|
require 'git_stats/git_data/activity'
|
||||||
require 'git_stats/git_data/author'
|
require 'git_stats/git_data/author'
|
||||||
require 'git_stats/git_data/blob'
|
require 'git_stats/git_data/blob'
|
||||||
require 'git_stats/git_data/command_parser'
|
|
||||||
require 'git_stats/git_data/command_runner'
|
|
||||||
require 'git_stats/git_data/commit'
|
require 'git_stats/git_data/commit'
|
||||||
require 'git_stats/git_data/repo'
|
require 'git_stats/git_data/repo'
|
||||||
require 'git_stats/git_data/short_stat'
|
require 'git_stats/git_data/short_stat'
|
||||||
|
|
31
lib/git_stats/command_parser.rb
Normal file
31
lib/git_stats/command_parser.rb
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# -*- encoding : utf-8 -*-
|
||||||
|
module GitStats
|
||||||
|
class CommandParser
|
||||||
|
def parse(command, result)
|
||||||
|
cmd, params = command.scan(/git (.*) (.*)/).first.map(&:split).flatten
|
||||||
|
send("parse_#{cmd.underscore}", result, params)
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_shortlog(result, params)
|
||||||
|
result.lines.map do |line|
|
||||||
|
commits, name, email = line.scan(/(.*)\t(.*)<(.*)>/).first.map(&:strip)
|
||||||
|
{commits: commits.to_i, name: name, email: email}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_ls_tree(result, params)
|
||||||
|
result.lines.map do |line|
|
||||||
|
mode, type, sha, filename = line.scan(/(.*) (.*) (.*)\t(.*)/).first.map(&:strip)
|
||||||
|
{mode: mode, type: type, sha: sha, filename: filename}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_rev_list(result, params)
|
||||||
|
result.lines.map do |line|
|
||||||
|
sha, stamp, date, author_email = line.split('|').map(&:strip)
|
||||||
|
{sha: sha, stamp: stamp, date: date, author_email: author_email}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
13
lib/git_stats/command_runner.rb
Normal file
13
lib/git_stats/command_runner.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# -*- encoding : utf-8 -*-
|
||||||
|
module GitStats
|
||||||
|
class CommandRunner
|
||||||
|
def run(path, command)
|
||||||
|
execute(command, path).encode!('UTF-8', 'UTF-8', :invalid => :replace)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def execute(command, path)
|
||||||
|
Dir.chdir(path) { %x[#{command}] }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -18,7 +18,12 @@ module GitStats
|
||||||
|
|
||||||
|
|
||||||
def validate_repo_path(repo_path)
|
def validate_repo_path(repo_path)
|
||||||
raise ArgumentError, "#{repo_path} is not a git repository" unless Validator.new.valid_repo_path?(repo_path)
|
raise ArgumentError, "#{repo_path} is not a git repository" unless valid_repo_path?(repo_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def valid_repo_path?(repo_path)
|
||||||
|
Dir.exists?("#{repo_path}/.git") || File.exists?("#{repo_path}/.git") || File.exists?("#{repo_path}/HEAD")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
# -*- encoding : utf-8 -*-
|
|
||||||
module GitStats
|
|
||||||
module GitData
|
|
||||||
class CommandParser
|
|
||||||
def parse(command, result)
|
|
||||||
cmd, params = command.scan(/git (.*) (.*)/).first.map(&:split).flatten
|
|
||||||
send("parse_#{cmd.underscore}", result, params)
|
|
||||||
end
|
|
||||||
|
|
||||||
def parse_shortlog(result, params)
|
|
||||||
result.lines.map do |line|
|
|
||||||
commits, name, email = line.scan(/(.*)\t(.*)<(.*)>/).first.map(&:strip)
|
|
||||||
{commits: commits.to_i, name: name, email: email}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def parse_ls_tree(result, params)
|
|
||||||
result.lines.map do |line|
|
|
||||||
mode, type, sha, filename = line.scan(/(.*) (.*) (.*)\t(.*)/).first.map(&:strip)
|
|
||||||
{mode: mode, type: type, sha: sha, filename: filename}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def parse_rev_list(result, params)
|
|
||||||
result.lines.map do |line|
|
|
||||||
sha, stamp, date, author_email = line.split('|').map(&:strip)
|
|
||||||
{sha: sha, stamp: stamp, date: date, author_email: author_email}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,15 +0,0 @@
|
||||||
# -*- encoding : utf-8 -*-
|
|
||||||
module GitStats
|
|
||||||
module GitData
|
|
||||||
class CommandRunner
|
|
||||||
def run(path, command)
|
|
||||||
execute(command, path).encode!('UTF-8', 'UTF-8', :invalid => :replace)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
def execute(command, path)
|
|
||||||
Dir.chdir(path) { %x[#{command}] }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,10 +0,0 @@
|
||||||
# -*- encoding : utf-8 -*-
|
|
||||||
module GitStats
|
|
||||||
class Validator
|
|
||||||
|
|
||||||
def valid_repo_path?(repo_path)
|
|
||||||
Dir.exists?("#{repo_path}/.git") || File.exists?("#{repo_path}/HEAD")
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -6,34 +6,7 @@ describe GitStats::Generator do
|
||||||
let(:out_path) { 'out_path' }
|
let(:out_path) { 'out_path' }
|
||||||
let(:generator) { GitStats::Generator.new(path: repo_path, out_path: out_path) }
|
let(:generator) { GitStats::Generator.new(path: repo_path, out_path: out_path) }
|
||||||
|
|
||||||
before { Dir.stub(:exists? => true) }
|
|
||||||
|
|
||||||
it 'should raise exception if given repo path is not a git repository' do
|
it 'should raise exception if given repo path is not a git repository' do
|
||||||
Dir.should_receive(:exists?).with("#{repo_path}/.git").and_return(false)
|
expect { generator }.to raise_error
|
||||||
expect { generator }.to raise_error(ArgumentError)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should pass command observer to repo' do
|
|
||||||
repo = double('repo')
|
|
||||||
GitStats::GitData::Repo.should_receive(:new).with(path: repo_path, out_path: out_path).and_return(repo)
|
|
||||||
|
|
||||||
observer = double('observer')
|
|
||||||
repo.should_receive(:add_command_observer).with(observer)
|
|
||||||
|
|
||||||
generator.add_command_observer observer
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should render all templates with view data for this repo' do
|
|
||||||
repo = double('repo')
|
|
||||||
GitStats::GitData::Repo.should_receive(:new).with(path: repo_path, out_path: out_path).and_return(repo)
|
|
||||||
|
|
||||||
view_data = double('view_data')
|
|
||||||
GitStats::StatsView::ViewData.should_receive(:new).with(repo).and_return(view_data)
|
|
||||||
|
|
||||||
view = double('view')
|
|
||||||
GitStats::StatsView::View.should_receive(:new).with(view_data, out_path).and_return(view)
|
|
||||||
view.should_receive(:render_all)
|
|
||||||
|
|
||||||
generator.render_all
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue