diff options
author | Stan Hu <stanhu@gmail.com> | 2018-08-07 23:53:25 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-08-08 00:34:25 +0300 |
commit | 8c467b917537a87ae95c2fb5d3464ed4fe7e102f (patch) | |
tree | 73f0a01b196409839e94bcdaf3b95c4afa1a3bc7 /spec/lib/gitlab/bitbucket_import | |
parent | f3b36ac1171f6d170d008c52a0a324a438f3e886 (diff) |
Fix Bitbucket Cloud importer omitting replies
Inline diff comments did not have the proper position, so even though
they had line codes the merge request validation would fail. Now
we cache the line position for each parent comment and use that.
Closes #50052
Diffstat (limited to 'spec/lib/gitlab/bitbucket_import')
-rw-r--r-- | spec/lib/gitlab/bitbucket_import/importer_spec.rb | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/spec/lib/gitlab/bitbucket_import/importer_spec.rb b/spec/lib/gitlab/bitbucket_import/importer_spec.rb index 05c232d22cf..7a681bc6610 100644 --- a/spec/lib/gitlab/bitbucket_import/importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_import/importer_spec.rb @@ -69,6 +69,7 @@ describe Gitlab::BitbucketImport::Importer do let(:project) do create( :project, + :repository, import_source: project_identifier, import_url: "https://bitbucket.org/#{project_identifier}.git", import_data_attributes: { credentials: data } @@ -85,10 +86,84 @@ describe Gitlab::BitbucketImport::Importer do } end + let(:sample) { RepoHelpers.sample_compare } + before do allow(importer).to receive(:gitlab_shell) { gitlab_shell } end + subject { described_class.new(project) } + + describe '#import_pull_requests' do + before do + allow(subject).to receive(:import_wiki) + allow(subject).to receive(:import_issues) + + pull_request = instance_double( + Bitbucket::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: 'other', + created_at: Time.now, + updated_at: Time.now) + + # https://gitlab.com/gitlab-org/gitlab-test/compare/c1acaa58bbcbc3eafe538cb8274ba387047b69f8...5937ac0a7beb003549fc5fd26fc247ad + @inline_note = instance_double( + Bitbucket::Representation::PullRequestComment, + iid: 2, + file_path: '.gitmodules', + old_pos: nil, + new_pos: 4, + note: 'Hello world', + author: 'root', + created_at: Time.now, + updated_at: Time.now, + inline?: true, + has_parent?: false) + + @reply = instance_double( + Bitbucket::Representation::PullRequestComment, + iid: 3, + file_path: '.gitmodules', + note: 'Hello world', + author: 'root', + created_at: Time.now, + updated_at: Time.now, + inline?: true, + has_parent?: true, + parent_id: 2) + + comments = [@inline_note, @reply] + + allow(subject.client).to receive(:repo) + allow(subject.client).to receive(:pull_requests).and_return([pull_request]) + allow(subject.client).to receive(:pull_request_comments).with(anything, pull_request.iid).and_return(comments) + end + + it 'imports threaded discussions' do + expect { subject.execute }.to change { MergeRequest.count }.by(1) + + merge_request = MergeRequest.first + expect(merge_request.notes.count).to eq(2) + expect(merge_request.notes.map(&:discussion_id).uniq.count).to eq(1) + + notes = merge_request.notes.order(:id).to_a + start_note = notes.first + expect(start_note).to be_a(DiffNote) + expect(start_note.note).to eq(@inline_note.note) + + reply_note = notes.last + expect(reply_note).to be_a(DiffNote) + expect(reply_note.note).to eq(@reply.note) + end + end + context 'issues statuses' do before do # HACK: Bitbucket::Representation.const_get('Issue') seems to return ::Issue without this |