Commit 11dd390c authored by Stan Hu's avatar Stan Hu

Add tests for pull request comments

parent 57c9a893
......@@ -55,7 +55,10 @@ module Gitlab
return users[email] if users.key?(email)
users[email] = User.find_by_any_email(email)
user = User.find_by_any_email(email)
users[email] = user&.id if user
user&.id
end
def repo
......@@ -163,7 +166,7 @@ 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
author_id = gitlab_user_id(project, pull_request.author_email) || User.ghost.id
project.merge_requests.find_by(iid: pull_request.iid)&.destroy
......@@ -178,7 +181,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: author.id,
author_id: author_id,
assignee_id: nil,
created_at: pull_request.created_at,
updated_at: pull_request.updated_at
......@@ -204,11 +207,11 @@ module Gitlab
def import_merge_event(merge_request, merge_event)
committer = merge_event.committer_email
user = find_user_id(committer) if committer
user ||= User.ghost
user_id = find_user_id(committer) if committer
user_id ||= User.ghost.id
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)
metric.update(merged_by_id: user_id, merged_at: timestamp)
end
def import_inline_comments(inline_comments, pull_request, merge_request)
......
......@@ -56,25 +56,36 @@ describe Gitlab::BitbucketServerImport::Importer do
updated_at: Time.now,
merged?: true)
expect(subject.client).to receive(:pull_requests).and_return([pull_request])
allow(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)
merge_timestamp: Time.now.utc.change(usec: 0))
@inline_comment = instance_double(
BitbucketServer::Representation::Activity,
comment?: true,
inline_comment?: true,
merge_event?: false)
@pr_note = instance_double(
BitbucketServer::Representation::Comment,
note: 'Hello world',
author_email: 'unknown@gmail.com',
comments: [],
created_at: Time.now.utc.change(usec: 0),
updated_at: Time.now.utc.change(usec: 0))
@pr_comment = instance_double(
BitbucketServer::Representation::Activity,
comment?: true,
merge_event?: false)
inline_comment?: false,
merge_event?: false,
comment: @pr_note)
end
it 'handles merge event' do
it 'imports merge event' do
expect(subject.client).to receive(:activities).and_return([@merge_event])
expect { subject.execute }.to change { MergeRequest.count }.by(1)
......@@ -84,19 +95,32 @@ describe Gitlab::BitbucketServerImport::Importer do
expect(merge_request.metrics.merged_at).to eq(@merge_event.merge_timestamp)
end
context 'handles comments' do
it 'imports comments' do
expect(subject.client).to receive(:activities).and_return([@pr_comment])
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.note).to eq(@pr_note.note)
expect(note.author).to eq(project.owner)
expect(note.created_at).to eq(@pr_note.created_at)
expect(note.updated_at).to eq(@pr_note.created_at)
end
context 'handles diff comments' do
it 'handles diff comments' do
end
context 'falls back to comments if diff comments' do
it 'falls back to comments if diff comments' do
end
context 'restores branches of inaccessible SHAs' do
it 'restores branches of inaccessible SHAs' do
end
end
describe '#delete_temp_branches' do
it 'deletes branches' do
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