Skip to content

Commit b48bc87

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

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

lib/git_stats/git_data/repo.rb

Lines changed: 14 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,25 @@ 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+
emails = author_emails.map { |email| email.downcase }
55+
@commits ||= run_and_parse("git rev-list --pretty=format:'%H|%at|%ai|%aE' #{commit_range} #{tree_path} | grep -v commit")
56+
.select { |commit_line| emails.include?(commit_line[:author_email].downcase) }
57+
.map { |commit_line| Commit.new(
5158
repo: self,
5259
sha: commit_line[:sha],
5360
stamp: commit_line[:stamp],
5461
date: DateTime.parse(commit_line[:date]),
5562
author: authors.first! { |a| a.email == commit_line[:author_email] }
5663
)
57-
end.sort_by! { |e| e.date }
64+
}
65+
.sort_by! { |e| e.date }
5866
end
5967

6068
def commits_period

0 commit comments

Comments
 (0)