mirror of
https://github.com/tomgi/git_stats.git
synced 2024-11-16 16:48:34 +01:00
refactor
This commit is contained in:
parent
e29d388b68
commit
450828a2e9
3 changed files with 19 additions and 17 deletions
|
@ -10,4 +10,10 @@ class GitStats::GitActivity
|
||||||
def by_wday_hour
|
def by_wday_hour
|
||||||
@by_wday_hour ||= Hash.new { |h, k| h[k] = Hash.new(0) }
|
@by_wday_hour ||= Hash.new { |h, k| h[k] = Hash.new(0) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_commit(date)
|
||||||
|
self.by_hour[date.hour] += 1
|
||||||
|
self.by_wday[date.wday] += 1
|
||||||
|
self.by_wday_hour[date.wday][date.hour] += 1
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -1,6 +1,4 @@
|
||||||
class GitStats::GitData
|
class GitStats::GitData
|
||||||
attr_reader :total_authors
|
|
||||||
attr_reader :total_commits
|
|
||||||
|
|
||||||
def initialize(repo_path)
|
def initialize(repo_path)
|
||||||
@repo_path = repo_path
|
@repo_path = repo_path
|
||||||
|
@ -8,28 +6,27 @@ class GitStats::GitData
|
||||||
end
|
end
|
||||||
|
|
||||||
def gather_all
|
def gather_all
|
||||||
@total_authors = run('git shortlog -s HEAD | wc -l')
|
gather_authors
|
||||||
|
|
||||||
gather_commits
|
gather_commits
|
||||||
end
|
end
|
||||||
|
|
||||||
def gather_commits
|
def gather_authors
|
||||||
run('git rev-list --pretty=format:"%h|%at|%ai|%aN|%aE" HEAD | grep -v commit').split(/\r?\n/).each do |commit|
|
run('git shortlog -se HEAD').each_line do |author|
|
||||||
hash, stamp, date, author_name, author_email = commit.split('|')
|
name, email = author.split(/\t/)[1].strip.scan(/(.*)<(.*)>/).first.map(&:strip)
|
||||||
|
authors[email] = GitStats::GitAuthor.new(name: name, email: email)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
authors[author_email] = GitStats::GitAuthor.new(name: author_name, email: author_email) unless authors[author_email]
|
def gather_commits
|
||||||
|
run('git rev-list --pretty=format:"%h|%at|%ai|%aE" HEAD | grep -v commit').each_line do |commit|
|
||||||
|
hash, stamp, date, author_email = commit.split('|').map(&:strip)
|
||||||
author = authors[author_email]
|
author = authors[author_email]
|
||||||
|
|
||||||
date = DateTime.parse(date)
|
date = DateTime.parse(date)
|
||||||
commits[hash] = GitStats::GitCommit.new(hash: hash, stamp: stamp, date: date, author: author)
|
commits[hash] = GitStats::GitCommit.new(hash: hash, stamp: stamp, date: date, author: author)
|
||||||
|
|
||||||
activity.by_hour[date.hour] += 1
|
activity.add_commit(date)
|
||||||
activity.by_wday[date.wday] += 1
|
author.activity.add_commit(date)
|
||||||
activity.by_wday_hour[date.wday][date.hour] += 1
|
|
||||||
|
|
||||||
author.activity.by_hour[date.hour] += 1
|
|
||||||
author.activity.by_wday[date.wday] += 1
|
|
||||||
author.activity.by_wday_hour[date.wday][date.hour] += 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
%p= git_data.total_authors
|
|
||||||
%p= git_data.project_version
|
|
||||||
%p= git_data.project_name
|
%p= git_data.project_name
|
||||||
|
%p= git_data.project_version
|
||||||
|
|
||||||
= high_chart("my_id", @h)
|
= high_chart("my_id", @h)
|
Loading…
Reference in a new issue