Commit 57204bf6 authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'ali/fix-notimplementederror-in-deployments-hooksworker' into 'master'

Handle commit being nil in Deployments::HooksWorker

See merge request gitlab-org/gitlab!84321
parents 601762d8 ff3c1a70
......@@ -12,6 +12,11 @@ module Gitlab
Gitlab::UrlBuilder.build(deployment.deployable)
end
commit_url =
if (commit = deployment.commit)
Gitlab::UrlBuilder.build(commit)
end
{
object_kind: 'deployment',
status: deployment.status,
......@@ -24,8 +29,8 @@ module Gitlab
short_sha: deployment.short_sha,
user: deployment.deployed_by.hook_attrs,
user_url: Gitlab::UrlBuilder.build(deployment.deployed_by),
commit_url: Gitlab::UrlBuilder.build(deployment.commit),
commit_title: deployment.commit.title,
commit_url: commit_url,
commit_title: deployment.commit&.title,
ref: deployment.ref
}
end
......
......@@ -46,5 +46,24 @@ RSpec.describe Gitlab::DataBuilder::Deployment do
expect(data[:deployable_url]).to be_nil
end
context 'when commit does not exist in the repository' do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:deployment) { create(:deployment, project: project) }
subject(:data) { described_class.build(deployment, Time.current) }
before(:all) do
project.repository.remove
end
it 'does not include commit_url' do
expect(data[:commit_url]).to be_nil
end
it 'does not include commit_title' do
expect(data[:commit_title]).to be_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