Incorrect "Connection failed. Please check your settings." response in settings test of "Emails on push" integration
Summary
When using the "Protected branches" for the "Branches for which notifications are to be sent" setting in the "Emails on push" integration, the "Test settings" button incorrectly reports "Connection failed. Please check your settings." if the project's default branch is not protected.
The actual integration itself works correctly, emails are being sent as expected when the settings are saved despite the error. The error occurs both when no protected branches exist at all, but also when there are protected branches. Only if the default branch is added as a protected branch, the "Test settings" button will report "Connection successful."
Steps to reproduce
- Create new project
- Unprotect all branches
- Enable "Emails on push" integration
- Select "Protected branches" in "Branches for which notifications are to be sent" dropdown
- Enter valid email address
- Click "Test settings", observe "Connection failed. Please check your settings." message
- Create new branch in project and add it to protected branches
- Repeat step 6, still observing the same error message
- Add project default branch to protected branches
- Repeat step 6, now observe "Connection successful." message
Example Project
Other than a few settings and a branch there is nothing specific about the issue, but I'll provide the project I used to verify the issue occurs even on GitLab.com: https://gitlab.com/gitlab-gold/mg-gold/email-push-test
- Quick link to the integration settings: https://gitlab.com/gitlab-gold/mg-gold/email-push-test/-/integrations/emails_on_push/edit
- Quick link to the protected branches settings: https://gitlab.com/gitlab-gold/mg-gold/email-push-test/-/settings/repository#js-protected-branches-settings
What is the current bug behavior?
The settings test reports "Connection failed. Please check your settings."
What is the expected correct behavior?
The settings test should report "Connection successful." if there are any protected branches, and maybe a specific "No protected branches exist." error if that is the case.
Relevant logs and/or screenshots
Protected branch exists, default branch not protected, incorrect error message
No protected branch exists at all, incorrect error message
Protected branch exists, default branch is also protected, correct message
Only default branch is protected, correct message
Output of checks
This bug happens on GitLab.com
Possible fixes
I think it might be somewhere in notify_for_branch(), which is being called from notify_for_ref(), which is being called from execute(). It looks to me like execute() is what is being used for the test based on test() in app/models/integration.rb. But those are all just fairly wild guesses.



