diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-13 21:06:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-13 21:06:03 +0300 |
commit | 40d3d574132d2849646c20eb9d8742b159d9bfc8 (patch) | |
tree | 431dee6675639da4421dbb1d6f50b7734a3190c3 /app/models/concerns/notification_branch_selection.rb | |
parent | 5939b09fd3db37ec98dfce0345162617d9d1d313 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/concerns/notification_branch_selection.rb')
-rw-r--r-- | app/models/concerns/notification_branch_selection.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/app/models/concerns/notification_branch_selection.rb b/app/models/concerns/notification_branch_selection.rb new file mode 100644 index 00000000000..d8e18de7551 --- /dev/null +++ b/app/models/concerns/notification_branch_selection.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +# Concern handling functionality around deciding whether to send notification +# for activities on a specified branch or not. Will be included in +# ChatNotificationService and PipelinesEmailService classes. +module NotificationBranchSelection + extend ActiveSupport::Concern + + BRANCH_CHOICES = [ + [_('All branches'), 'all'], + [_('Default branch'), 'default'], + [_('Protected branches'), 'protected'], + [_('Default branch and protected branches'), 'default_and_protected'] + ].freeze + + def notify_for_branch?(data) + ref = if data[:ref] + Gitlab::Git.ref_name(data[:ref]) + else + data.dig(:object_attributes, :ref) + end + + is_default_branch = ref == project.default_branch + is_protected_branch = project.protected_branches.exists?(name: ref) + + case branches_to_be_notified + when "all" + true + when "default" + is_default_branch + when "protected" + is_protected_branch + when "default_and_protected" + is_default_branch || is_protected_branch + else + false + end + end +end |