Class: GitStats::GitData::Repo
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Inspector
#inspect, #pretty_print, #to_s
Constructor Details
#initialize(params) ⇒ Repo
Returns a new instance of Repo.
15
16
17
18
19
|
# File 'lib/git_stats/git_data/repo.rb', line 15
def initialize(params)
super
@path = File.expand_path(@path)
@tree_path ||= '.'
end
|
Instance Attribute Details
#first_commit_sha ⇒ Object
Returns the value of attribute first_commit_sha.
25
26
27
|
# File 'lib/git_stats/git_data/repo.rb', line 25
def first_commit_sha
@first_commit_sha
end
|
Instance Method Details
#==(other) ⇒ Object
154
155
156
|
# File 'lib/git_stats/git_data/repo.rb', line 154
def ==(other)
path == other.path
end
|
#activity ⇒ Object
118
119
120
|
# File 'lib/git_stats/git_data/repo.rb', line 118
def activity
@activity ||= Activity.new(commits)
end
|
#add_command_observer(proc = nil, &block) ⇒ Object
149
150
151
152
|
# File 'lib/git_stats/git_data/repo.rb', line 149
def add_command_observer(proc = nil, &block)
command_observers << block if block
command_observers << proc if proc
end
|
#authors ⇒ Object
43
44
45
46
47
|
# File 'lib/git_stats/git_data/repo.rb', line 43
def authors
@authors ||= run_and_parse("git shortlog -se #{commit_range} #{tree_path}").map do |author|
Author.new(repo: self, name: author[:name], email: author[:email])
end
end
|
#command_parser ⇒ Object
145
146
147
|
# File 'lib/git_stats/git_data/repo.rb', line 145
def command_parser
@command_parser ||= CommandParser.new
end
|
#command_runner ⇒ Object
141
142
143
|
# File 'lib/git_stats/git_data/repo.rb', line 141
def command_runner
@command_runner ||= CommandRunner.new
end
|
114
115
116
|
# File 'lib/git_stats/git_data/repo.rb', line 114
def
@comment_stats ||= commits.map(&:comment_stat)
end
|
35
36
37
|
# File 'lib/git_stats/git_data/repo.rb', line 35
def
@comment_string ||= '//'
end
|
93
94
95
96
97
98
99
100
|
# File 'lib/git_stats/git_data/repo.rb', line 93
def
sum = 0
@comments_count_by_date ||= commits.map do |commit|
sum += commit..insertions
sum -= commit..deletions
[commit.date.to_date, sum]
end.to_h.fill_empty_days!(aggregated: true)
end
|
#commit_range ⇒ Object
106
107
108
|
# File 'lib/git_stats/git_data/repo.rb', line 106
def commit_range
first_commit_sha.blank? ? last_commit_sha : "#{first_commit_sha}..#{last_commit_sha}"
end
|
#commits ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/git_stats/git_data/repo.rb', line 49
def commits
command = "git rev-list --pretty=format:'%H|%at|%ai|%aE' #{commit_range} #{tree_path} | grep -v commit"
@commits ||= run_and_parse(command).map do |commit_line|
Commit.new(
repo: self,
sha: commit_line[:sha],
stamp: commit_line[:stamp],
date: Time.parse(commit_line[:date]),
author: authors.first! { |a| a.email == commit_line[:author_email] }
)
end.sort_by!(&:date)
end
|
#commits_count_by_author(limit = 4) ⇒ Object
TODO: This method is called from nowhere
67
68
69
|
# File 'lib/git_stats/git_data/repo.rb', line 67
def commits_count_by_author(limit = 4)
(authors.map { |author| [author, author.commits.size] }.sort_by { |_author, commits| -commits }[0..limit]).to_h
end
|
#commits_period ⇒ Object
62
63
64
|
# File 'lib/git_stats/git_data/repo.rb', line 62
def commits_period
commits.map(&:date).minmax
end
|
#files_count_by_date ⇒ Object
78
79
80
81
82
|
# File 'lib/git_stats/git_data/repo.rb', line 78
def files_count_by_date
@files_count_by_date ||= commits.map do |commit|
[commit.date.to_date, commit.files_count]
end.to_h
end
|
#last_commit ⇒ Object
102
103
104
|
# File 'lib/git_stats/git_data/repo.rb', line 102
def last_commit
commits.last
end
|
#last_commit_sha ⇒ Object
27
28
29
|
# File 'lib/git_stats/git_data/repo.rb', line 27
def last_commit_sha
@last_commit_sha ||= 'HEAD'
end
|
#lines_count_by_date ⇒ Object
84
85
86
87
88
89
90
91
|
# File 'lib/git_stats/git_data/repo.rb', line 84
def lines_count_by_date
sum = 0
@lines_count_by_date ||= commits.map do |commit|
sum += commit.short_stat.insertions
sum -= commit.short_stat.deletions
[commit.date.to_date, sum]
end.to_h
end
|
#path ⇒ Object
21
22
23
|
# File 'lib/git_stats/git_data/repo.rb', line 21
def path
@path ||= '.'
end
|
#project_name ⇒ Object
126
127
128
|
# File 'lib/git_stats/git_data/repo.rb', line 126
def project_name
@project_name ||= File.expand_path(File.join(path, tree_path)).sub(File.dirname(File.expand_path(path)) + File::SEPARATOR, '')
end
|
#project_version ⇒ Object
122
123
124
|
# File 'lib/git_stats/git_data/repo.rb', line 122
def project_version
@project_version ||= run("git rev-parse #{commit_range}").strip
end
|
#run(command) ⇒ Object
130
131
132
133
134
|
# File 'lib/git_stats/git_data/repo.rb', line 130
def run(command)
result = command_runner.run(path, command)
invoke_command_observers(command, result)
result
end
|
#run_and_parse(command) ⇒ Object
136
137
138
139
|
# File 'lib/git_stats/git_data/repo.rb', line 136
def run_and_parse(command)
result = run(command)
command_parser.parse(command, result)
end
|
#short_stats ⇒ Object
110
111
112
|
# File 'lib/git_stats/git_data/repo.rb', line 110
def short_stats
@short_stats ||= commits.map(&:short_stat)
end
|
#tree ⇒ Object
39
40
41
|
# File 'lib/git_stats/git_data/repo.rb', line 39
def tree
@tree ||= Tree.new(repo: self, relative_path: @tree_path)
end
|
#tree_path ⇒ Object
31
32
33
|
# File 'lib/git_stats/git_data/repo.rb', line 31
def tree_path
@tree_path ||= '.'
end
|