Commit 1f5b91d6 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'id-nil-short-commit-sha' into 'master'

Serialize short sha as nil if head commit is blank

See merge request gitlab-org/gitlab!19014
parents 0c713622 09fefc32
...@@ -21,6 +21,8 @@ class MergeRequestDiffEntity < Grape::Entity ...@@ -21,6 +21,8 @@ class MergeRequestDiffEntity < Grape::Entity
expose :latest?, as: :latest expose :latest?, as: :latest
expose :short_commit_sha do |merge_request_diff| expose :short_commit_sha do |merge_request_diff|
next unless merge_request_diff.head_commit_sha
short_sha(merge_request_diff.head_commit_sha) short_sha(merge_request_diff.head_commit_sha)
end end
......
---
title: Serialize short sha as nil if head commit is blank
merge_request: 19014
author:
type: fixed
...@@ -7,14 +7,15 @@ describe MergeRequestDiffEntity do ...@@ -7,14 +7,15 @@ describe MergeRequestDiffEntity do
let(:request) { EntityRequest.new(project: project) } let(:request) { EntityRequest.new(project: project) }
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
let(:merge_request_diffs) { merge_request.merge_request_diffs } let(:merge_request_diffs) { merge_request.merge_request_diffs }
let(:merge_request_diff) { merge_request_diffs.first }
let(:entity) do let(:entity) do
described_class.new(merge_request_diffs.first, request: request, merge_request: merge_request, merge_request_diffs: merge_request_diffs) described_class.new(merge_request_diff, request: request, merge_request: merge_request, merge_request_diffs: merge_request_diffs)
end end
context 'as json' do subject { entity.as_json }
subject { entity.as_json }
context 'as json' do
it 'exposes needed attributes' do it 'exposes needed attributes' do
expect(subject).to include( expect(subject).to include(
:version_index, :created_at, :commits_count, :version_index, :created_at, :commits_count,
...@@ -23,4 +24,16 @@ describe MergeRequestDiffEntity do ...@@ -23,4 +24,16 @@ describe MergeRequestDiffEntity do
) )
end end
end end
describe '#short_commit_sha' do
it 'returns short sha' do
expect(subject[:short_commit_sha]).to eq('b83d6e39')
end
it 'returns nil if head_commit_sha does not exist' do
allow(merge_request_diff).to receive(:head_commit_sha).and_return(nil)
expect(subject[:short_commit_sha]).to eq(nil)
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