2012-10-09 22:34:02 +02:00
|
|
|
module GitStats
|
|
|
|
module GitData
|
|
|
|
class Repo
|
|
|
|
attr_reader :path
|
|
|
|
|
|
|
|
def initialize(path)
|
2012-10-13 15:32:06 +02:00
|
|
|
@path = File.expand_path(path)
|
2012-10-09 22:34:02 +02:00
|
|
|
end
|
|
|
|
|
2012-10-12 18:20:07 +02:00
|
|
|
def authors
|
2012-10-13 14:31:52 +02:00
|
|
|
@authors ||= Hash[Command.new(self, 'git shortlog -se HEAD').run.lines.map do |line|
|
2012-10-12 18:20:07 +02:00
|
|
|
name, email = line.split(/\t/)[1].strip.scan(/(.*)<(.*)>/).first.map(&:strip)
|
2012-10-13 14:31:52 +02:00
|
|
|
[email, Author.new(repo: self, name: name, email: email)]
|
|
|
|
end]
|
2012-10-09 22:34:02 +02:00
|
|
|
end
|
|
|
|
|
2012-10-12 18:20:07 +02:00
|
|
|
def commits
|
2012-10-13 14:31:52 +02:00
|
|
|
@commits ||= Command.new(self, 'git rev-list --pretty=format:"%h|%at|%ai|%aE" HEAD | grep -v commit').run.lines.map do |commit_line|
|
2012-10-09 22:34:02 +02:00
|
|
|
hash, stamp, date, author_email = commit_line.split('|').map(&:strip)
|
|
|
|
author = authors[author_email]
|
|
|
|
|
|
|
|
date = DateTime.parse(date)
|
2012-10-13 14:31:52 +02:00
|
|
|
Commit.new(repo: self, hash: hash, stamp: stamp, date: date, author: author)
|
|
|
|
end.sort_by! { |e| e.date }
|
|
|
|
end
|
|
|
|
|
|
|
|
def short_stats
|
|
|
|
@short_stats ||= commits.map(&:short_stat)
|
2012-10-09 22:34:02 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def activity
|
2012-10-12 18:24:28 +02:00
|
|
|
@activity ||= Activity.new(commits)
|
2012-10-09 22:34:02 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def project_version
|
|
|
|
@project_version ||= Command.new(self, 'git rev-parse --short HEAD').run
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_name
|
2012-10-13 15:32:06 +02:00
|
|
|
@project_name ||= File.basename(path)
|
2012-10-09 22:34:02 +02:00
|
|
|
end
|
2012-10-12 18:20:07 +02:00
|
|
|
|
2012-10-13 12:38:07 +02:00
|
|
|
def to_s
|
|
|
|
"#{self.class} #@path"
|
|
|
|
end
|
|
|
|
|
2012-10-13 13:27:15 +02:00
|
|
|
def ==(other)
|
|
|
|
self.path == other.path
|
|
|
|
end
|
|
|
|
|
2012-10-09 22:34:02 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|