diff options
-rw-r--r-- | lib/gitlab/bitbucket_server_import/importer.rb | 8 | ||||
-rw-r--r-- | spec/lib/gitlab/bitbucket_server_import/importer_spec.rb | 64 |
2 files changed, 67 insertions, 5 deletions
diff --git a/lib/gitlab/bitbucket_server_import/importer.rb b/lib/gitlab/bitbucket_server_import/importer.rb index cc21e7aad9e..36069f0f168 100644 --- a/lib/gitlab/bitbucket_server_import/importer.rb +++ b/lib/gitlab/bitbucket_server_import/importer.rb @@ -163,6 +163,8 @@ module Gitlab target_branch_sha = pull_request.target_branch_sha source_branch_sha = project.repository.commit(source_branch_sha)&.sha || source_branch_sha target_branch_sha = project.repository.commit(target_branch_sha)&.sha || target_branch_sha + author = gitlab_user_id(project, pull_request.author_email) || User.ghost + project.merge_requests.find_by(iid: pull_request.iid)&.destroy attributes = { @@ -176,7 +178,7 @@ module Gitlab target_branch: Gitlab::Git.ref_name(pull_request.target_branch_name), target_branch_sha: target_branch_sha, state: pull_request.state, - author_id: gitlab_user_id(project, pull_request.author_email), + author_id: author.id, assignee_id: nil, created_at: pull_request.created_at, updated_at: pull_request.updated_at @@ -202,8 +204,8 @@ module Gitlab def import_merge_event(merge_request, merge_event) committer = merge_event.committer_email - user = User.ghost - user ||= find_user_id(committer) if committer + user = find_user_id(committer) if committer + user ||= User.ghost timestamp = merge_event.merge_timestamp metric = MergeRequest::Metrics.find_or_initialize_by(merge_request: merge_request) metric.update_attributes(merged_by: user, merged_at: timestamp) diff --git a/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb b/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb index 73875b92b71..a05fd53ecf9 100644 --- a/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Gitlab::BitbucketServerImport::Importer do include ImportSpecHelper - let(:project) { create(:project, import_url: 'http://my-bitbucket') } + set(:project) { create(:project, :repository, import_url: 'http://my-bitbucket') } subject { described_class.new(project) } @@ -32,11 +32,71 @@ describe Gitlab::BitbucketServerImport::Importer do end end + # XXX We don't handle pull requests across forks describe '#import_pull_requests' do + before do + allow(subject).to receive(:import_repository) + allow(subject).to receive(:delete_temp_branches) + allow(subject).to receive(:restore_branches) + + sample = RepoHelpers.sample_compare + pull_request = instance_double( + BitbucketServer::Representation::PullRequest, + iid: 10, + source_branch_sha: sample.commits.last, + source_branch_name: Gitlab::Git::BRANCH_REF_PREFIX + sample.source_branch, + target_branch_sha: sample.commits.first, + target_branch_name: Gitlab::Git::BRANCH_REF_PREFIX + sample.target_branch, + title: 'This is a title', + description: 'This is a test pull request', + state: 'merged', + author: 'Test Author', + author_email: project.owner.email, + created_at: Time.now, + updated_at: Time.now, + merged?: true) + + expect(subject.client).to receive(:pull_requests).and_return([pull_request]) + + @merge_event = instance_double( + BitbucketServer::Representation::Activity, + comment?: false, + merge_event?: true, + committer_email: project.owner.email, + merge_timestamp: Time.now) + @inline_comment = instance_double( + BitbucketServer::Representation::Activity, + comment?: true, + merge_event?: false) + @pr_comment = instance_double( + BitbucketServer::Representation::Activity, + comment?: true, + merge_event?: false) + end + + it 'handles merge event' do + expect(subject.client).to receive(:activities).and_return([@merge_event]) + + expect { subject.execute }.to change { MergeRequest.count }.by(1) + + merge_request = MergeRequest.first + expect(merge_request.metrics.merged_by).to eq(project.owner) + expect(merge_request.metrics.merged_at).to eq(@merge_event.merge_timestamp) + end + context 'handles comments' do + end + + context 'handles diff comments' do + end + + context 'falls back to comments if diff comments' do + end + + context 'restores branches of inaccessible SHAs' do + end end describe '#delete_temp_branches' do - end end |