Commit fd70ebb5 authored by Nick Thomas's avatar Nick Thomas

Merge branch '33582-fix-protected-branch-wildcard' into 'master'

Fix protected branch detection in notification branch selection

Closes #33582

See merge request gitlab-org/gitlab!18221
parents cf648cc5 37e3b969
......@@ -21,7 +21,7 @@ module NotificationBranchSelection
end
is_default_branch = ref == project.default_branch
is_protected_branch = project.protected_branches.exists?(name: ref)
is_protected_branch = ProtectedBranch.protected?(project, ref)
case branches_to_be_notified
when "all"
......
---
title: Fix protected branch detection used by notification service
merge_request: 18221
author:
type: fixed
......@@ -369,6 +369,48 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
end
end
context 'on a protected branch with protected branches defined using wildcards' do
before do
create(:protected_branch, project: project, name: '*-stable')
end
let(:data) do
Gitlab::DataBuilder::Push.build(
project: project,
user: user,
ref: '1-stable'
)
end
context 'pushing tags' do
let(:data) do
Gitlab::DataBuilder::Push.build(
project: project,
user: user,
ref: "#{Gitlab::Git::TAG_REF_PREFIX}test"
)
end
it_behaves_like "triggered #{service_name} service", event_type: "push"
end
context 'notification enabled only for default branch' do
it_behaves_like "untriggered #{service_name} service", event_type: "push", branches_to_be_notified: "default"
end
context 'notification enabled only for protected branches' do
it_behaves_like "triggered #{service_name} service", event_type: "push", branches_to_be_notified: "protected"
end
context 'notification enabled only for default and protected branches' do
it_behaves_like "triggered #{service_name} service", event_type: "push", branches_to_be_notified: "default_and_protected"
end
context 'notification enabled for all branches' do
it_behaves_like "triggered #{service_name} service", event_type: "push", branches_to_be_notified: "all"
end
end
context 'on a neither protected nor default branch' do
let(:data) do
Gitlab::DataBuilder::Push.build(
......@@ -570,6 +612,36 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
end
end
context 'on a protected branch with protected branches defined usin wildcards' do
before do
create(:protected_branch, project: project, name: '*-stable')
end
let(:pipeline) do
create(:ci_pipeline,
project: project, status: :failed,
sha: project.commit.sha, ref: '1-stable')
end
let(:data) { Gitlab::DataBuilder::Pipeline.build(pipeline) }
context 'notification enabled only for default branch' do
it_behaves_like "untriggered #{service_name} service", event_type: "pipeline", branches_to_be_notified: "default"
end
context 'notification enabled only for protected branches' do
it_behaves_like "triggered #{service_name} service", event_type: "pipeline", branches_to_be_notified: "protected"
end
context 'notification enabled only for default and protected branches' do
it_behaves_like "triggered #{service_name} service", event_type: "pipeline", branches_to_be_notified: "default_and_protected"
end
context 'notification enabled for all branches' do
it_behaves_like "triggered #{service_name} service", event_type: "pipeline", branches_to_be_notified: "all"
end
end
context 'on a neither protected nor default branch' do
let(:pipeline) do
create(:ci_pipeline,
......
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