Commit afb84289 authored by Sven Groot's avatar Sven Groot

Add check for ref to deployment notifications

Make sure that deployment notifications from chat integrations
such as Slack respect the "Branches to be notified" setting.
This makes it possible to only be notified about deployments triggerd
on default and/or protected branches.

Changelog: changed
Closes https://gitlab.com/gitlab-org/gitlab/-/issues/217020
parent 4407bcd2
......@@ -204,7 +204,7 @@ module Integrations
when "wiki_page"
Integrations::ChatMessage::WikiPageMessage.new(data)
when "deployment"
Integrations::ChatMessage::DeploymentMessage.new(data)
Integrations::ChatMessage::DeploymentMessage.new(data) if notify_for_ref?(data)
end
end
......@@ -241,7 +241,10 @@ module Integrations
def notify_for_ref?(data)
return true if data[:object_kind] == 'tag_push'
return true if data.dig(:object_attributes, :tag)
ref = data[:ref] || data.dig(:object_attributes, :ref)
return true if ref.blank? # No need to check protected branches when there is no ref
return true if Gitlab::Git.tag_ref?(ref) # Skip protected branch check because it doesn't support tags
notify_for_branch?(data)
end
......
......@@ -25,7 +25,8 @@ module Gitlab
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_title: deployment.commit.title,
ref: deployment.ref
}
end
end
......
......@@ -37,6 +37,7 @@ RSpec.describe Gitlab::DataBuilder::Deployment do
expect(data[:user_url]).to eq(expected_user_url)
expect(data[:commit_url]).to eq(expected_commit_url)
expect(data[:commit_title]).to eq(commit.title)
expect(data[:ref]).to eq(deployment.ref)
end
it 'does not include the deployable URL when there is no deployable' 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