Class: GitFindCommitter::Committer

Inherits:
Object
  • Object
show all
Defined in:
lib/git_find_committer/committer.rb

Instance Method Summary collapse

Constructor Details

#initialize(repo, branch, config) ⇒ Committer

Returns a new instance of Committer.



3
4
5
6
7
# File 'lib/git_find_committer/committer.rb', line 3

def initialize(repo, branch, config)
  @config = config
  @config.set_repo(repo)
  @config.branch = branch
end

Instance Method Details

#diff_filesObject



9
10
11
# File 'lib/git_find_committer/committer.rb', line 9

def diff_files
  `cd #{@config.tmp_repo_path} && git diff --name-only origin/#{@config.branch} origin/master`.split("\n").map { |val| val.chomp }
end

#find(file) ⇒ Object



28
29
30
31
32
# File 'lib/git_find_committer/committer.rb', line 28

def find(file)
  {"#{file}" => `cd #{@config.tmp_repo_path} && git log --follow --pretty=format:"%an" #{file} 2>/dev/null` }.each_with_object(Hash.new(0)) do |(file, committer), k|
    committer.split("\n").each {|r| k[r]+=1 }
  end.sort {|(k1, v1), (k2, v2)| v2 <=> v1 }.to_h
end

#searchObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/git_find_committer/committer.rb', line 13

def search
  Repository.new(@config).prepare_repo.pull_master

  result = diff_files.each_with_object(Hash.new(0)) do |file, k|
    find(file).each do |committer, commit_count|
      k[committer] += commit_count
    end
  end.sort { |(k1, v1), (k2, v2)| v2 <=> v1 }.to_h

  result = result.each_with_object([]) do |(key,val),arr|
    arr << {name: key, commit_count: val}
  end
  Response.new(Filter.new(@config).select_committer(result))
end