Commit 2d6a2b1e authored by Sean McGivern's avatar Sean McGivern

Merge branch 'id-fix-authority-analyzer' into 'master'

Use modified paths inside AuthorityAnalyzer

See merge request gitlab-org/gitlab!29138
parents 5b1879b1 48d06c74
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
module Gitlab module Gitlab
class AuthorityAnalyzer class AuthorityAnalyzer
COMMITS_TO_CONSIDER = 25 COMMITS_TO_CONSIDER = 25
FILES_TO_CONSIDER = 100
def initialize(merge_request, skip_user) def initialize(merge_request, skip_user)
@merge_request = merge_request @merge_request = merge_request
...@@ -30,20 +31,7 @@ module Gitlab ...@@ -30,20 +31,7 @@ module Gitlab
end end
def list_of_involved_files def list_of_involved_files
diffable = [@merge_request.compare, @merge_request.merge_request_diff].compact @merge_request.modified_paths.first(FILES_TO_CONSIDER)
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
end end
end end
end end
...@@ -9,7 +9,7 @@ describe Gitlab::AuthorityAnalyzer do ...@@ -9,7 +9,7 @@ describe Gitlab::AuthorityAnalyzer do
let(:user_a) { create(:user) } let(:user_a) { create(:user) }
let(:user_b) { create(:user) } let(:user_b) { create(:user) }
let(:merge_request) { create(:merge_request, target_project: project, source_project: project) } 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 let(:commits) do
[ [
...@@ -23,12 +23,14 @@ describe Gitlab::AuthorityAnalyzer do ...@@ -23,12 +23,14 @@ describe Gitlab::AuthorityAnalyzer do
let(:approvers) { described_class.new(merge_request, author).calculate } 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 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) expect(approvers).to contain_exactly(user_a, user_b)
end end
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