Module: GitAnalyzer

Defined in:
lib/git_analyzer.rb,
lib/git_analyzer/version.rb,
lib/git_analyzer/formatter/csv.rb,
lib/git_analyzer/formatter/pretty.rb

Defined Under Namespace

Modules: Formatter

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.contributors(period: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/git_analyzer.rb', line 10

def contributors(period: nil)
  since = generate_since_day(period)

  result = `git shortlog -sne#{" --since='#{since}'" unless period.nil?}`

  # No commits
  return [] if result == ""

  result = result.scan(/(\d+)\t(.+)\<(.+)\>/)
  total_commits = result.inject(0) { |sum, el| sum + el[0].to_i }

  result.map do |array|
    {
      commits: array[0].to_i,
      # floor(n) is not available in Ruby < 2.3, multiply by 10000 and then divide by 100 to keep to decimals
      contribution_percentage: (array.shift.to_f / total_commits * 10_000).floor.to_f / 100,
      name: array.shift.strip,
      email: array.shift
    }
  end
end