mirror of
https://github.com/tomgi/git_stats.git
synced 2025-03-11 19:18:54 +01:00
Merge branch 'maplesteve-comments_stats'
This commit is contained in:
commit
72a0cbfe82
15 changed files with 96 additions and 10 deletions
|
@ -46,6 +46,8 @@ It browses the repository and outputs html page with statistics.
|
||||||
s, [--silent], [--no-silent] # Silent mode. Don't output anything.
|
s, [--silent], [--no-silent] # Silent mode. Don't output anything.
|
||||||
d, [--tree=TREE] # Tree where statistics should be generated.
|
d, [--tree=TREE] # Tree where statistics should be generated.
|
||||||
# Default: .
|
# Default: .
|
||||||
|
c, [--comment=COMMENT] # The string which is used for comments.
|
||||||
|
# Default: ///
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,10 @@ de:
|
||||||
commits_by_hour: Commits in der Stunde
|
commits_by_hour: Commits in der Stunde
|
||||||
files: Dateien
|
files: Dateien
|
||||||
lines: Zeilen
|
lines: Zeilen
|
||||||
|
comments: Kommentare
|
||||||
files_by_date: Dateien nach Datum
|
files_by_date: Dateien nach Datum
|
||||||
lines_by_date: Zeilen nach Datum
|
lines_by_date: Zeilen nach Datum
|
||||||
|
comments_by_date: Kommentare nach Datum
|
||||||
files_by_extension: Dateien nach Erweiterungen
|
files_by_extension: Dateien nach Erweiterungen
|
||||||
lines_by_extension: Zeilen nach Erweiterungen
|
lines_by_extension: Zeilen nach Erweiterungen
|
||||||
hour_of_day: Tagesstunden
|
hour_of_day: Tagesstunden
|
||||||
|
|
|
@ -13,8 +13,10 @@ en:
|
||||||
commits_by_hour: Commits by hour
|
commits_by_hour: Commits by hour
|
||||||
files: Files
|
files: Files
|
||||||
lines: Lines
|
lines: Lines
|
||||||
|
comments: Comments
|
||||||
files_by_date: Files by date
|
files_by_date: Files by date
|
||||||
lines_by_date: Lines by date
|
lines_by_date: Lines by date
|
||||||
|
comments_by_date: Comments by date
|
||||||
files_by_extension: Files by extension
|
files_by_extension: Files by extension
|
||||||
lines_by_extension: Lines by extension
|
lines_by_extension: Lines by extension
|
||||||
hour_of_day: Hour of day
|
hour_of_day: Hour of day
|
||||||
|
|
|
@ -18,6 +18,7 @@ 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'
|
||||||
|
require 'git_stats/git_data/comment_stat'
|
||||||
require 'git_stats/git_data/tree'
|
require 'git_stats/git_data/tree'
|
||||||
|
|
||||||
require 'git_stats/stats_view/template'
|
require 'git_stats/stats_view/template'
|
||||||
|
|
|
@ -10,11 +10,12 @@ class GitStats::CLI < Thor
|
||||||
option :to, :aliases => :t, :default => 'HEAD', :desc => 'Commit where statistics should stop.'
|
option :to, :aliases => :t, :default => 'HEAD', :desc => 'Commit where statistics should stop.'
|
||||||
option :silent, :aliases => :s, :type => :boolean, :desc => 'Silent mode. Don\'t output anything.'
|
option :silent, :aliases => :s, :type => :boolean, :desc => 'Silent mode. Don\'t output anything.'
|
||||||
option :tree, :aliases => :d, :default => '.', :desc => 'Tree where statistics should be generated.'
|
option :tree, :aliases => :d, :default => '.', :desc => 'Tree where statistics should be generated.'
|
||||||
|
option :comment, :aliases => :c, :default => '///', :desc => 'The string which is used for comments.'
|
||||||
|
|
||||||
desc 'generate', 'Generates the statistics of a repository'
|
desc 'generate', 'Generates the statistics of a repository'
|
||||||
def generate
|
def generate
|
||||||
I18n.locale = options[:language]
|
I18n.locale = options[:language]
|
||||||
GitStats::Generator.new(options[:path], options[:output], options[:from], options[:to], options[:tree]) { |g|
|
GitStats::Generator.new(options[:path], options[:output], options[:from], options[:to], options[:tree], options[:comment]) { |g|
|
||||||
g.add_command_observer { |command, result| puts "#{command}" } unless options[:silent]
|
g.add_command_observer { |command, result| puts "#{command}" } unless options[:silent]
|
||||||
}.render_all
|
}.render_all
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,10 +4,10 @@ module GitStats
|
||||||
delegate :add_command_observer, to: :@repo
|
delegate :add_command_observer, to: :@repo
|
||||||
delegate :render_all, to: :@view
|
delegate :render_all, to: :@view
|
||||||
|
|
||||||
def initialize(repo_path, out_path, first_commit_sha = nil, last_commit_sha = "HEAD", tree_path = ".")
|
def initialize(repo_path, out_path, first_commit_sha = nil, last_commit_sha = "HEAD", tree_path = ".", comment_string = "///")
|
||||||
validate_repo_path(repo_path)
|
validate_repo_path(repo_path)
|
||||||
|
|
||||||
@repo = GitData::Repo.new(path: repo_path, first_commit_sha: first_commit_sha, last_commit_sha: last_commit_sha, tree_path: tree_path)
|
@repo = GitData::Repo.new(path: repo_path, first_commit_sha: first_commit_sha, last_commit_sha: last_commit_sha, tree_path: tree_path, comment_string: comment_string)
|
||||||
view_data = StatsView::ViewData.new(@repo)
|
view_data = StatsView::ViewData.new(@repo)
|
||||||
@view = StatsView::View.new(view_data, out_path)
|
@view = StatsView::View.new(view_data, out_path)
|
||||||
|
|
||||||
|
|
38
lib/git_stats/git_data/comment_stat.rb
Normal file
38
lib/git_stats/git_data/comment_stat.rb
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
# -*- encoding : utf-8 -*-
|
||||||
|
module GitStats
|
||||||
|
module GitData
|
||||||
|
class CommentStat
|
||||||
|
attr_reader :commit, :insertions, :deletions
|
||||||
|
|
||||||
|
def initialize(commit)
|
||||||
|
@commit = commit
|
||||||
|
calculate_stat
|
||||||
|
end
|
||||||
|
|
||||||
|
def changed_lines
|
||||||
|
insertions + deletions
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
"#{self.class} #@commit"
|
||||||
|
end
|
||||||
|
|
||||||
|
def escape_characters_in_string(string)
|
||||||
|
pattern = /(\'|\"|\.|\*|\/|\-|\\)/
|
||||||
|
string.gsub(pattern){|match|"\\" + match}
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def calculate_stat
|
||||||
|
escaped_string = escape_characters_in_string(commit.repo.comment_string)
|
||||||
|
stat_line = commit.repo.run("git show #{commit.sha} | awk 'BEGIN {adds=0; dels=0} {if ($0 ~ /^\\+#{escaped_string}/) adds++; if ($0 ~ /^\-#{escaped_string}/) dels++} END {print adds \" insertions \" dels \" deletes\"}'").lines.to_a[0]
|
||||||
|
if stat_line.blank?
|
||||||
|
@insertions = @deletions = 0
|
||||||
|
else
|
||||||
|
@insertions = stat_line[/(\d+) insertions?/, 1].to_i
|
||||||
|
@deletions = stat_line[/(\d+) deletes?/, 1].to_i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -50,6 +50,10 @@ module GitStats
|
||||||
@short_stat ||= ShortStat.new(self)
|
@short_stat ||= ShortStat.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def comment_stat
|
||||||
|
@comment_stat ||= CommentStat.new(self)
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"#{self.class} #@sha"
|
"#{self.class} #@sha"
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,10 +6,10 @@ module GitStats
|
||||||
class Repo
|
class Repo
|
||||||
include HashInitializable
|
include HashInitializable
|
||||||
|
|
||||||
attr_reader :path, :first_commit_sha, :last_commit_sha, :tree_path
|
attr_reader :path, :first_commit_sha, :last_commit_sha, :tree_path, :comment_string
|
||||||
|
|
||||||
delegate :files, :files_by_extension, :files_by_extension_count, :lines_by_extension,
|
delegate :files, :files_by_extension, :files_by_extension_count, :lines_by_extension,
|
||||||
:files_count, :binary_files, :text_files, :lines_count, to: :last_commit
|
:files_count, :binary_files, :text_files, :lines_count, :comments_count, to: :last_commit
|
||||||
|
|
||||||
def initialize(params)
|
def initialize(params)
|
||||||
super(params)
|
super(params)
|
||||||
|
@ -64,6 +64,15 @@ module GitStats
|
||||||
}]
|
}]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def comments_count_by_date
|
||||||
|
sum = 0
|
||||||
|
@comment_count_each_day ||= Hash[commits.map { |commit|
|
||||||
|
sum += commit.comment_stat.insertions
|
||||||
|
sum -= commit.comment_stat.deletions
|
||||||
|
[commit.date.to_date, sum]
|
||||||
|
}].fill_empty_days!(aggregated: true)
|
||||||
|
end
|
||||||
|
|
||||||
def last_commit
|
def last_commit
|
||||||
commits.last
|
commits.last
|
||||||
end
|
end
|
||||||
|
@ -80,6 +89,10 @@ module GitStats
|
||||||
@short_stats ||= commits.map(&:short_stat)
|
@short_stats ||= commits.map(&:short_stat)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def comment_stats
|
||||||
|
@comment_stats ||= commits.map(&:comment_stat)
|
||||||
|
end
|
||||||
|
|
||||||
def activity
|
def activity
|
||||||
@activity ||= Activity.new(commits)
|
@activity ||= Activity.new(commits)
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ module GitStats
|
||||||
module StatsView
|
module StatsView
|
||||||
module Charts
|
module Charts
|
||||||
class All
|
class All
|
||||||
delegate :files_by_extension, :lines_by_extension, :files_by_date, :lines_by_date, to: :repo_charts
|
delegate :files_by_extension, :lines_by_extension, :files_by_date, :lines_by_date, :comments_by_date, to: :repo_charts
|
||||||
|
|
||||||
delegate :commits_sum_by_author_by_date, :changed_lines_by_author_by_date,
|
delegate :commits_sum_by_author_by_date, :changed_lines_by_author_by_date,
|
||||||
:insertions_by_author_by_date, :deletions_by_author_by_date, to: :authors_charts
|
:insertions_by_author_by_date, :deletions_by_author_by_date, to: :authors_charts
|
||||||
|
|
|
@ -47,6 +47,16 @@ module GitStats
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def comments_by_date
|
||||||
|
Chart.new do |f|
|
||||||
|
f.date_chart(
|
||||||
|
data: @repo.comments_count_by_date,
|
||||||
|
title: :comments_by_date.t,
|
||||||
|
y_text: :comments.t
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -55,7 +55,8 @@ module GitStats
|
||||||
activity: 'activity/by_date.html',
|
activity: 'activity/by_date.html',
|
||||||
authors: 'authors/best_authors.html',
|
authors: 'authors/best_authors.html',
|
||||||
files: 'files/by_date.html',
|
files: 'files/by_date.html',
|
||||||
lines: 'lines/by_date.html'
|
lines: 'lines/by_date.html',
|
||||||
|
comments: 'comments/by_date.html'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ describe GitStats::Generator do
|
||||||
|
|
||||||
it 'should pass command observer to repo' do
|
it 'should pass command observer to repo' do
|
||||||
repo = double('repo')
|
repo = double('repo')
|
||||||
GitStats::GitData::Repo.should_receive(:new).with(path: repo_path, first_commit_sha: nil, last_commit_sha: "HEAD", tree_path: ".").and_return(repo)
|
GitStats::GitData::Repo.should_receive(:new).with(path: repo_path, first_commit_sha: nil, last_commit_sha: "HEAD", tree_path: ".", :comment_string=>"///").and_return(repo)
|
||||||
|
|
||||||
generator = GitStats::Generator.new(repo_path, out_path)
|
generator = GitStats::Generator.new(repo_path, out_path)
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ describe GitStats::Generator do
|
||||||
|
|
||||||
it 'should render all templates with view data for this repo' do
|
it 'should render all templates with view data for this repo' do
|
||||||
repo = double('repo')
|
repo = double('repo')
|
||||||
GitStats::GitData::Repo.should_receive(:new).with(path: repo_path, first_commit_sha: nil, last_commit_sha: "HEAD", tree_path: ".").and_return(repo)
|
GitStats::GitData::Repo.should_receive(:new).with(path: repo_path, first_commit_sha: nil, last_commit_sha: "HEAD", tree_path: ".", :comment_string=>"///").and_return(repo)
|
||||||
|
|
||||||
view_data = double('view_data')
|
view_data = double('view_data')
|
||||||
GitStats::StatsView::ViewData.should_receive(:new).with(repo).and_return(view_data)
|
GitStats::StatsView::ViewData.should_receive(:new).with(repo).and_return(view_data)
|
||||||
|
|
11
templates/comments/_comments.haml
Normal file
11
templates/comments/_comments.haml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
.tabbable.tabs-left
|
||||||
|
%ul.nav.nav-tabs
|
||||||
|
%li{class: page == :comments_by_date ? "active" : ""}
|
||||||
|
%a{:href => 'by_date.html'}= :comments_by_date.t
|
||||||
|
|
||||||
|
.tab-content
|
||||||
|
.tab-pane.active
|
||||||
|
.page-header
|
||||||
|
%h1.pagination-centered= page.t
|
||||||
|
- if page == :comments_by_date
|
||||||
|
= high_stock("comments_by_date", charts.comments_by_date)
|
1
templates/comments/by_date.haml
Normal file
1
templates/comments/by_date.haml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
= render_partial('comments/_comments', page: :comments_by_date)
|
Loading…
Reference in a new issue