Module: NotificationBranchSelection

Extended by:
ActiveSupport::Concern
Included in:
Integrations::BaseChatNotification, Integrations::EmailsOnPush, Integrations::PipelinesEmail
Defined in:
app/models/concerns/notification_branch_selection.rb

Overview

Concern handling functionality around deciding whether to send notification for activities on a specified branch or not. Will be included in Integrations::BaseChatNotification and PipelinesEmailService classes.

Instance Method Summary collapse

Instance Method Details

#notify_for_branch?(data) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/concerns/notification_branch_selection.rb', line 20

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 = ProtectedBranch.protected?(project, 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