Skip to content

Commit

Permalink
Allow specifying authors
Browse files Browse the repository at this point in the history
  • Loading branch information
evandcoleman committed Feb 24, 2019
1 parent 34a1d13 commit e1390a8
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/git_stats/git_data/repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def last_commit_sha
@last_commit_sha ||= 'HEAD'
end

def author_emails
@author_emails ||= []
end

def tree_path
@tree_path ||= '.'
end
Expand All @@ -40,21 +44,25 @@ def tree
end

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
emails = author_emails.map { |email| email.downcase }
@authors ||= run_and_parse("git shortlog -se #{commit_range} #{tree_path}")
.select { |author| emails.count == 0 ? true : emails.include?(author[:email].downcase) }
.map { |author| Author.new(repo: self, name: author[:name], email: author[:email]) }
end

def commits
@commits ||= run_and_parse("git rev-list --pretty=format:'%H|%at|%ai|%aE' #{commit_range} #{tree_path} | grep -v commit").map do |commit_line|
Commit.new(
emails = author_emails.map { |email| email.downcase }
@commits ||= run_and_parse("git rev-list --pretty=format:'%H|%at|%ai|%aE' #{commit_range} #{tree_path} | grep -v commit")
.select { |commit_line| authors.select { |a| a.email == commit_line[:author_email] } .count > 0 }
.map { |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! { |e| e.date }
}
.sort_by! { |e| e.date }
end

def commits_period
Expand Down

0 comments on commit e1390a8

Please sign in to comment.