Sha256: 170967263a4c48cd5f08c0e24262a2f62cb2037bd1d9371e824bf7108e38dcc7

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

require 'date'

module PairingMatrix
  class CommitReader
    def initialize(config)
      @config = config
    end

    def read(since)
      commits = []
      @config.repos.each do |repo|
        Dir.chdir repo do
          commits << read_commits(since)
        end
      end
      commits.flatten
    end

    def authors(since)
      commits = read(since)
      commits.map do |commit|
        commit.scan(/#{@config.authors_regex}/).flatten.compact.reject(&:empty?).map { |name| name.gsub(' ', '') }.sort.join(',')
      end.compact.reject(&:empty?)
    end

    def titleize(name)
      name.gsub(/\w+/) do |word|
        word.capitalize
      end
    end

    def authors_with_commits(days)
      date = (Date.today - days).to_s
      authors = authors(date)
      author_groups = authors.group_by { |n| titleize(n)}
      author_groups.map do |k, v|
        pair = k.split(',')
        pair.unshift('') if pair.size == 1
        [pair, v.size].flatten
      end
    end

    private
    def read_commits(since)
      `git log --oneline --after=\"#{since}\"`.split("\n")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pairing_matrix-2.3.1 lib/pairing_matrix/commit_reader.rb