Slack Integration: Deploy Notifications only default_and_protected is not respected

Summary

Deployment statuses for non-default or protected branches are reported to Slack integration even if "Notify only default branch and protected branches" is selected.

Steps to reproduce

Create a project, add Slack Integration for default branch and protected branches deployment notifications with Branches to be notified set to Standard branch and protected branches, create a regex for protected branches and you will start receiving deployment notifications for events on any branches.

What is the current bug behavior?

Slack notifications are received for deployments events of any branches.

What is the expected correct behavior?

I should only receive Slack notifications when deploying the standard branch or protected branches.

Relevant logs and/or screenshots

Deploy notification:

Screenshot_from_2020-05-07_23-05-07

Protected branches configuration:

Screenshot_from_2020-05-07_23-07-57

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info
System information
System:         Ubuntu 18.04
Proxy:          no
Current User:   git
Using RVM:      no
Ruby Version:   2.6.5p114
Gem Version:    2.7.10
Bundler Version:1.17.3
Rake Version:   12.3.3
Redis Version:  5.0.7
Git Version:    2.26.2
Sidekiq Version:5.2.7
Go Version:     unknown

GitLab information
Version:        12.10.3-ee
Revision:       7c0ab260960
Directory:      /opt/gitlab/embedded/service/gitlab-rails
DB Adapter:     PostgreSQL
DB Version:     11.7
URL:            https://gitlab.example.com
HTTP Clone URL: https://gitlab.example.com/some-group/some-project.git
SSH Clone URL:  git@gitlab.example.com:some-group/some-project.git
Elasticsearch:  no
Geo:            no
Using LDAP:     no
Using Omniauth: yes
Omniauth Providers: saml, bitbucket

GitLab Shell
Version:        12.2.0
Repository storage paths:
- default:      /var/opt/gitlab/git-data/repositories
GitLab Shell path:              /opt/gitlab/embedded/service/gitlab-shell
Git:            /opt/gitlab/embedded/bin/git


Results of GitLab application Check

Expand for output related to the GitLab application check

Checking GitLab Shell ... Finished

Checking Gitaly ...

Gitaly: ... default ... OK

Checking Gitaly ... Finished

Checking Sidekiq ...

Sidekiq: ... Running? ... yes Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Checking Incoming Email ...

Incoming Email: ... Reply by email is disabled in config/gitlab.yml

Checking Incoming Email ... Finished

Checking LDAP ...

LDAP: ... LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab App ...

Git configured correctly? ... yes Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... yes Init script exists? ... skipped (omnibus-gitlab has no init script) Init script up-to-date? ... skipped (omnibus-gitlab has no init script) Projects have namespace: ... 10/7 ... yes 10/8 ... yes 10/9 ... yes 4/13 ... yes 4/14 ... yes 4/15 ... yes 4/17 ... yes 4/21 ... yes 4/22 ... yes 2/23 ... yes 4/29 ... yes 4/31 ... yes 4/47 ... yes 4/48 ... yes 4/50 ... yes 4/51 ... yes 4/52 ... yes 4/53 ... yes 4/54 ... yes 4/55 ... yes 4/56 ... yes 4/57 ... yes 4/58 ... yes 4/59 ... yes 4/60 ... yes 4/61 ... yes 4/62 ... yes 22/63 ... yes 22/64 ... yes 4/65 ... yes Redis version >= 4.0.0? ... yes Ruby version >= 2.5.3 ? ... yes (2.6.5) Git version >= 2.22.0 ? ... yes (2.26.2) Git user has default SSH configuration? ... yes Active users: ... 10 Is authorized keys file accessible? ... yes Elasticsearch version 5.6 - 6.x? ... skipped (elasticsearch is disabled)

Checking GitLab App ... Finished

Checking GitLab subtasks ... Finished

Possible fixes

https://gitlab.com/gitlab-org/gitlab-foss/-/blob/master/app/models/project_services/chat_notification_service.rb#L137

applying the same rule for pipeline notifications on deployments should work.