Commit 3cda8c93 authored by Stan Hu's avatar Stan Hu

Fix merge request SHA

parent 7c88c4af
......@@ -28,25 +28,33 @@ module BitbucketServer
end
def committer_user
raw.dig('commit', 'committer', 'displayName')
commit.dig('committer', 'displayName')
end
def committer_email
raw.dig('commit', 'committer', 'emailAddress')
commit.dig('committer', 'emailAddress')
end
def merge_timestamp
timestamp = raw.dig('commit', 'committerTimestamp')
timestamp = commit['committerTimestamp']
self.class.convert_timestamp(timestamp)
end
def merge_commit
commit['id']
end
def created_at
self.class.convert_timestamp(created_date)
end
private
def commit
raw.fetch('commit', {})
end
def action
raw['action']
end
......
......@@ -197,7 +197,6 @@ module Gitlab
updated_at: pull_request.updated_at
}
attributes[:merge_commit_sha] = target_branch_sha if pull_request.merged?
merge_request = project.merge_requests.create!(attributes)
import_pull_request_comments(pull_request, merge_request) if merge_request.persisted?
end
......@@ -219,6 +218,7 @@ module Gitlab
user_id = gitlab_user_id(committer)
timestamp = merge_event.merge_timestamp
merge_request.update_attributes({ merge_commit_sha: merge_event.merge_commit })
metric = MergeRequest::Metrics.find_or_initialize_by(merge_request: merge_request)
metric.update(merged_by_id: user_id, merged_at: timestamp)
end
......
......@@ -33,5 +33,6 @@ describe BitbucketServer::Representation::Activity do
it { expect(subject.committer_email).to eq('test.user@example.com') }
it { expect(subject.merge_timestamp).to be_a(Time) }
it { expect(subject.created_at).to be_a(Time) }
it { expect(subject.merge_commit).to eq('839fa9a2d434eb697815b8fcafaecc51accfdbbc') }
end
end
......@@ -65,7 +65,9 @@ describe Gitlab::BitbucketServerImport::Importer do
comment?: false,
merge_event?: true,
committer_email: project.owner.email,
merge_timestamp: now)
merge_timestamp: now,
merge_commit: '12345678'
)
@pr_note = instance_double(
BitbucketServer::Representation::Comment,
......@@ -90,6 +92,7 @@ describe Gitlab::BitbucketServerImport::Importer do
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)
expect(merge_request.merge_commit_sha).to eq('12345678')
end
it 'imports comments' do
......
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