Skip to content

Commit a6122a5

Browse files
committed
Allow specifying authors
1 parent 34a1d13 commit a6122a5

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

lib/git_stats/git_data/repo.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ def last_commit_sha
2727
@last_commit_sha ||= 'HEAD'
2828
end
2929

30+
def author_emails
31+
@author_emails ||= []
32+
end
33+
3034
def tree_path
3135
@tree_path ||= '.'
3236
end
@@ -40,21 +44,24 @@ def tree
4044
end
4145

4246
def authors
43-
@authors ||= run_and_parse("git shortlog -se #{commit_range} #{tree_path}").map do |author|
44-
Author.new(repo: self, name: author[:name], email: author[:email])
45-
end
47+
emails = author_emails.map { |email| email.downcase }
48+
@authors ||= run_and_parse("git shortlog -se #{commit_range} #{tree_path}")
49+
.select { |author| emails.count == 0 ? true : emails.include?(author[:email].downcase) }
50+
.map { |author| Author.new(repo: self, name: author[:name], email: author[:email]) }
4651
end
4752

4853
def commits
49-
@commits ||= run_and_parse("git rev-list --pretty=format:'%H|%at|%ai|%aE' #{commit_range} #{tree_path} | grep -v commit").map do |commit_line|
50-
Commit.new(
54+
@commits ||= run_and_parse("git rev-list --pretty=format:'%H|%at|%ai|%aE' #{commit_range} #{tree_path} | grep -v commit")
55+
.select { |commit_line| authors.select { |a| a.email == commit_line[:author_email] } .count > 0 }
56+
.map { |commit_line| Commit.new(
5157
repo: self,
5258
sha: commit_line[:sha],
5359
stamp: commit_line[:stamp],
5460
date: DateTime.parse(commit_line[:date]),
5561
author: authors.first! { |a| a.email == commit_line[:author_email] }
5662
)
57-
end.sort_by! { |e| e.date }
63+
}
64+
.sort_by! { |e| e.date }
5865
end
5966

6067
def commits_period

0 commit comments

Comments
 (0)