Class: PairingMatrix::CommitReader

Inherits:
Object
  • Object
show all
Defined in:
lib/pairing_matrix/commit_reader.rb

Direct Known Subclasses

GithubCommitReader

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ CommitReader

Returns a new instance of CommitReader.



5
6
7
# File 'lib/pairing_matrix/commit_reader.rb', line 5

def initialize(config)
  @config = config
end

Instance Method Details

#authors(since) ⇒ Object



19
20
21
22
23
24
# File 'lib/pairing_matrix/commit_reader.rb', line 19

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

#authors_with_commits(days) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/pairing_matrix/commit_reader.rb', line 26

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

#read(since) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/pairing_matrix/commit_reader.rb', line 9

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