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.
13
14
15
16
17
|
# File 'lib/git_stats/git_data/repo.rb', line 13
def initialize(params)
super(params)
@path = File.expand_path(@path)
@tree_path ||= '.'
end
|
Instance Attribute Details
#first_commit_sha ⇒ Object
Returns the value of attribute first_commit_sha.
23
24
25
|
# File 'lib/git_stats/git_data/repo.rb', line 23
def first_commit_sha
@first_commit_sha
end
|
Instance Method Details
#==(other) ⇒ Object
153
154
155
|
# File 'lib/git_stats/git_data/repo.rb', line 153
def ==(other)
path == other.path
end
|
#activity ⇒ Object
116
117
118
|
# File 'lib/git_stats/git_data/repo.rb', line 116
def activity
@activity ||= Activity.new(commits)
end
|
#add_command_observer(proc = nil, &block) ⇒ Object
148
149
150
151
|
# File 'lib/git_stats/git_data/repo.rb', line 148
def add_command_observer(proc = nil, &block)
command_observers << block if block
command_observers << proc if proc
end
|
#authors ⇒ Object
41
42
43
44
45
|
# File 'lib/git_stats/git_data/repo.rb', line 41
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
144
145
146
|
# File 'lib/git_stats/git_data/repo.rb', line 144
def command_parser
@command_parser ||= CommandParser.new
end
|
#command_runner ⇒ Object
140
141
142
|
# File 'lib/git_stats/git_data/repo.rb', line 140
def command_runner
@command_runner ||= CommandRunner.new
end
|
112
113
114
|
# File 'lib/git_stats/git_data/repo.rb', line 112
def
||= commits.map(&:comment_stat)
end
|
33
34
35
|
# File 'lib/git_stats/git_data/repo.rb', line 33
def
||= '//'
end
|
91
92
93
94
95
96
97
98
|
# File 'lib/git_stats/git_data/repo.rb', line 91
def
sum = 0
||= 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
104
105
106
|
# File 'lib/git_stats/git_data/repo.rb', line 104
def commit_range
first_commit_sha.blank? ? last_commit_sha : "#{first_commit_sha}..#{last_commit_sha}"
end
|
#commits ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/git_stats/git_data/repo.rb', line 47
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: DateTime.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
65
66
67
|
# File 'lib/git_stats/git_data/repo.rb', line 65
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
60
61
62
|
# File 'lib/git_stats/git_data/repo.rb', line 60
def commits_period
commits.map(&:date).minmax
end
|
#files_count_by_date ⇒ Object
76
77
78
79
80
|
# File 'lib/git_stats/git_data/repo.rb', line 76
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
100
101
102
|
# File 'lib/git_stats/git_data/repo.rb', line 100
def last_commit
commits.last
end
|
#last_commit_sha ⇒ Object
25
26
27
|
# File 'lib/git_stats/git_data/repo.rb', line 25
def last_commit_sha
@last_commit_sha ||= 'HEAD'
end
|
#lines_count_by_date ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'lib/git_stats/git_data/repo.rb', line 82
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
19
20
21
|
# File 'lib/git_stats/git_data/repo.rb', line 19
def path
@path ||= '.'
end
|
#project_name ⇒ Object
124
125
126
127
|
# File 'lib/git_stats/git_data/repo.rb', line 124
def project_name
@project_name ||= File.expand_path(File.join(path, tree_path)).sub(File.join(File.dirname(File.expand_path(path)), ''), '')
end
|
#project_version ⇒ Object
120
121
122
|
# File 'lib/git_stats/git_data/repo.rb', line 120
def project_version
@project_version ||= run("git rev-parse #{commit_range}").strip
end
|
#run(command) ⇒ Object
129
130
131
132
133
|
# File 'lib/git_stats/git_data/repo.rb', line 129
def run(command)
result = command_runner.run(path, command)
invoke_command_observers(command, result)
result
end
|
#run_and_parse(command) ⇒ Object
135
136
137
138
|
# File 'lib/git_stats/git_data/repo.rb', line 135
def run_and_parse(command)
result = run(command)
command_parser.parse(command, result)
end
|
#short_stats ⇒ Object
108
109
110
|
# File 'lib/git_stats/git_data/repo.rb', line 108
def short_stats
@short_stats ||= commits.map(&:short_stat)
end
|
#tree ⇒ Object
37
38
39
|
# File 'lib/git_stats/git_data/repo.rb', line 37
def tree
@tree ||= Tree.new(repo: self, relative_path: @tree_path)
end
|
#tree_path ⇒ Object
29
30
31
|
# File 'lib/git_stats/git_data/repo.rb', line 29
def tree_path
@tree_path ||= '.'
end
|