Sha256: 72c7b2e159ad951921328da87e4f2c66f5aeaf5b79ad1ec48c9d46aac7b2639f

Contents?: true

Size: 955 Bytes

Versions: 7

Compression:

Stored size: 955 Bytes

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?).sort.join(',')
      end.compact.reject(&:empty?)
    end

    def authors_with_commits(days)
      date = (Date.today - days).to_s
      authors = authors(date)
      author_groups = authors.group_by { |n| 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

7 entries across 7 versions & 1 rubygems

Version Path
pairing_matrix-1.1.1 lib/pairing_matrix/commit_reader.rb
pairing_matrix-1.1 lib/pairing_matrix/commit_reader.rb
pairing_matrix-1.0.1 lib/pairing_matrix/commit_reader.rb
pairing_matrix-1.0 lib/pairing_matrix/commit_reader.rb
pairing_matrix-0.1.2 lib/pairing_matrix/commit_reader.rb
pairing_matrix-0.1.1 lib/pairing_matrix/commit_reader.rb
pairing_matrix-0.1 lib/pairing_matrix/commit_reader.rb