Commit 48d06c74 authored by Igor Drozdov's avatar Igor Drozdov

Use modified paths inside AuthorityAnalyzer

parent da6b9e51
......@@ -3,6 +3,7 @@
module Gitlab
class AuthorityAnalyzer
COMMITS_TO_CONSIDER = 25
FILES_TO_CONSIDER = 100
def initialize(merge_request, skip_user)
@merge_request = merge_request
......@@ -30,20 +31,7 @@ module Gitlab
end
def list_of_involved_files
diffable = [@merge_request.compare, @merge_request.merge_request_diff].compact
return [] if diffable.empty?
compare_diffs = diffable.first.raw_diffs
return [] unless compare_diffs.present?
compare_diffs.map do |diff|
if diff.deleted_file || diff.renamed_file
diff.old_path
else
diff.new_path
end
end
@merge_request.modified_paths.first(FILES_TO_CONSIDER)
end
end
end
......@@ -9,7 +9,7 @@ describe Gitlab::AuthorityAnalyzer do
let(:user_a) { create(:user) }
let(:user_b) { create(:user) }
let(:merge_request) { create(:merge_request, target_project: project, source_project: project) }
let(:files) { [double(:file, deleted_file: true, old_path: 'foo')] }
let(:files) { %w(so many files) }
let(:commits) do
[
......@@ -23,12 +23,14 @@ describe Gitlab::AuthorityAnalyzer do
let(:approvers) { described_class.new(merge_request, author).calculate }
before do
merge_request.compare = double(:compare, raw_diffs: files)
allow(merge_request.target_project.repository).to receive(:commits).and_return(commits)
end
it 'returns contributors in order, without skip_user' do
stub_const('Gitlab::AuthorityAnalyzer::FILES_TO_CONSIDER', 1)
expect(merge_request).to receive(:modified_paths).and_return(files)
expect(merge_request.target_project.repository).to receive(:commits)
.with(merge_request.target_branch, path: ['so'], limit: Gitlab::AuthorityAnalyzer::COMMITS_TO_CONSIDER)
.and_return(commits)
expect(approvers).to contain_exactly(user_a, user_b)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment