Commit 470ece08 authored by Glen P Miller's avatar Glen P Miller Committed by Alex Pooley

Update BitBucket Server importer username mapping

parent 0407fa98
...@@ -78,10 +78,7 @@ the author's: ...@@ -78,10 +78,7 @@ the author's:
- `slug` - `slug`
- `displayName` - `displayName`
If the user is not found by any of these properties, the search falls back to the author's If the user is not found by any of these properties, the project creator is set as the author.
`email` address.
Alternatively, if there is also no email address, the project creator is set as the author.
##### Enable or disable User assignment by username ##### Enable or disable User assignment by username
......
...@@ -461,11 +461,15 @@ module Gitlab ...@@ -461,11 +461,15 @@ module Gitlab
end end
def uid(rep_object) def uid(rep_object)
find_user_id(by: :email, value: rep_object.author_email) unless Feature.enabled?(:bitbucket_server_user_mapping_by_username) # We want this explicit to only be username on the FF
# Otherwise, match email.
find_user_id(by: :username, value: rep_object.author_username) || # There should be no default fall-through on username. Fall-through to import user
if Feature.enabled?(:bitbucket_server_user_mapping_by_username)
find_user_id(by: :username, value: rep_object.author_username)
else
find_user_id(by: :email, value: rep_object.author_email) find_user_id(by: :email, value: rep_object.author_email)
end end
end end
end end
end
end end
...@@ -142,7 +142,7 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer do ...@@ -142,7 +142,7 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer do
expect { subject.execute }.to change { MergeRequest.count }.by(1) expect { subject.execute }.to change { MergeRequest.count }.by(1)
merge_request = MergeRequest.first merge_request = MergeRequest.first
expect(merge_request.author).to eq(pull_request_author) expect(merge_request.author).to eq(expected_author)
end end
end end
...@@ -151,27 +151,50 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer do ...@@ -151,27 +151,50 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer do
stub_feature_flags(bitbucket_server_user_mapping_by_username: false) stub_feature_flags(bitbucket_server_user_mapping_by_username: false)
end end
context 'when email is not present' do
before do
allow(pull_request).to receive(:author_email).and_return(nil)
end
let(:expected_author) { project_creator }
include_examples 'imports pull requests'
end
context 'when email is present' do
before do
allow(pull_request).to receive(:author_email).and_return(pull_request_author.email)
end
let(:expected_author) { pull_request_author }
include_examples 'imports pull requests' include_examples 'imports pull requests'
end end
end
context 'when bitbucket_server_user_mapping_by_username feature flag is enabled' do context 'when bitbucket_server_user_mapping_by_username feature flag is enabled' do
before do before do
stub_feature_flags(bitbucket_server_user_mapping_by_username: true) stub_feature_flags(bitbucket_server_user_mapping_by_username: true)
end end
include_examples 'imports pull requests' do
context 'when username is not present' do context 'when username is not present' do
before do before do
allow(pull_request).to receive(:author_username).and_return(nil) allow(pull_request).to receive(:author_username).and_return(nil)
end end
it 'maps by email' do let(:expected_author) { project_creator }
expect { subject.execute }.to change { MergeRequest.count }.by(1)
merge_request = MergeRequest.first include_examples 'imports pull requests'
expect(merge_request.author).to eq(pull_request_author)
end end
context 'when username is present' do
before do
allow(pull_request).to receive(:author_username).and_return(pull_request_author.username)
end end
let(:expected_author) { pull_request_author }
include_examples 'imports pull requests'
end end
end end
...@@ -228,7 +251,23 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer do ...@@ -228,7 +251,23 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer do
allow(subject.client).to receive(:activities).and_return([pr_comment]) allow(subject.client).to receive(:activities).and_return([pr_comment])
end end
it 'maps by email' do it 'defaults to import user' do
expect { subject.execute }.to change { MergeRequest.count }.by(1)
merge_request = MergeRequest.first
expect(merge_request.notes.count).to eq(1)
note = merge_request.notes.first
expect(note.author).to eq(project_creator)
end
end
context 'when username is present' do
before do
allow(pr_note).to receive(:author_username).and_return(note_author.username)
allow(subject.client).to receive(:activities).and_return([pr_comment])
end
it 'maps by username' do
expect { subject.execute }.to change { MergeRequest.count }.by(1) expect { subject.execute }.to change { MergeRequest.count }.by(1)
merge_request = MergeRequest.first merge_request = MergeRequest.first
...@@ -384,13 +423,13 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer do ...@@ -384,13 +423,13 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer do
allow(inline_note).to receive(:author_username).and_return(nil) allow(inline_note).to receive(:author_username).and_return(nil)
end end
it 'maps by email' do it 'defaults to import user' do
expect { subject.execute }.to change { MergeRequest.count }.by(1) expect { subject.execute }.to change { MergeRequest.count }.by(1)
notes = MergeRequest.first.notes.order(:id).to_a notes = MergeRequest.first.notes.order(:id).to_a
expect(notes.first.author).to eq(inline_note_author) expect(notes.first.author).to eq(project_creator)
expect(notes.last.author).to eq(reply_author) expect(notes.last.author).to eq(project_creator)
end end
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