Commit 4f7fc64e authored by Shinya Maeda's avatar Shinya Maeda

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

Guard against Deployment#deployed_by being nil

See merge request gitlab-org/gitlab!85032
parents 8dfa92b7 49c776f8
......@@ -17,6 +17,11 @@ module Gitlab
Gitlab::UrlBuilder.build(commit)
end
user_url =
if deployment.deployed_by
Gitlab::UrlBuilder.build(deployment.deployed_by)
end
{
object_kind: 'deployment',
status: deployment.status,
......@@ -27,8 +32,8 @@ module Gitlab
environment: deployment.environment.name,
project: deployment.project.hook_attrs,
short_sha: deployment.short_sha,
user: deployment.deployed_by.hook_attrs,
user_url: Gitlab::UrlBuilder.build(deployment.deployed_by),
user: deployment.deployed_by&.hook_attrs,
user_url: user_url,
commit_url: commit_url,
commit_title: deployment.commit_title,
ref: deployment.ref
......
......@@ -57,13 +57,31 @@ RSpec.describe Gitlab::DataBuilder::Deployment do
project.repository.remove
end
it 'does not include commit_url' do
it 'returns nil for commit_url' do
expect(data[:commit_url]).to be_nil
end
it 'does not include commit_title' do
it 'returns nil for commit_title' do
expect(data[:commit_title]).to be_nil
end
end
context 'when deployed_by is nil' do
let_it_be(:deployment) { create(:deployment, user: nil, deployable: nil) }
subject(:data) { described_class.build(deployment, Time.current) }
before(:all) do
deployment.user = nil
end
it 'returns nil for user' do
expect(data[:user]).to be_nil
end
it 'returns nil for user_url' do
expect(data[:user_url]).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