Class: GitFindCommitter::Committer
- Inherits:
-
Object
- Object
- GitFindCommitter::Committer
- Defined in:
- lib/git_find_committer/committer.rb
Instance Method Summary collapse
- #diff_files ⇒ Object
- #find(file) ⇒ Object
-
#initialize(repo, branch, config) ⇒ Committer
constructor
A new instance of Committer.
- #search ⇒ Object
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_files ⇒ Object
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 |
#search ⇒ Object
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 |