Class: Integrations::EmailsOnPush

Inherits:
Integration show all
Includes:
NotificationBranchSelection
Defined in:
app/models/integrations/emails_on_push.rb

Constant Summary collapse

RECIPIENTS_LIMIT =
750

Constants inherited from Integration

Integration::BASE_CLASSES, Integration::DEV_INTEGRATION_NAMES, Integration::INTEGRATION_NAMES, Integration::PROJECT_SPECIFIC_INTEGRATION_NAMES, Integration::SECTION_TYPE_CONNECTION, Integration::UnknownType

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Instance Attribute Summary

Attributes included from Importable

#imported, #importing

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NotificationBranchSelection

#branch_choices, #notify_for_branch?

Methods inherited from Integration

#activate_disabled_reason, #activated?, #api_field_names, #async_execute, #attributes, available_integration_names, available_integration_types, boolean_accessor, build_from_integration, #category, #configurable_events, create_from_active_default_integrations, default_integration, #default_test_event, default_test_event, dev_integration_names, #dup, #editable?, #event_channel_names, event_description, #event_field, event_names, #event_names, field, fields, find_or_initialize_all_non_project_specific, find_or_initialize_non_project_specific_integration, #global_fields, #group_level?, #help, #inheritable?, inherited_descendants_from_self_or_ancestors_from, instance_exists_for?, #instance_level?, integration_name_to_model, integration_name_to_type, integration_names, #json_fields, #operating?, #parent, #project_level?, project_specific_integration_names, prop_accessor, #properties=, #reencrypt_properties, #reset_updated_properties, #secret_fields, #sections, #show_active_box?, #supported_events, #supports_data_fields?, #test, #testable?, #to_data_fields_hash, #to_integration_hash, #to_param, #updated_properties

Methods included from Gitlab::Utils::Override

#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!

Methods included from ResetSecretFields

#exposing_secrets_fields

Methods included from Loggable

#build_message, #log_error, #log_exception, #log_info, #logger

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.supported_eventsObject


31
32
33
# File 'app/models/integrations/emails_on_push.rb', line 31

def self.supported_events
  %w(push tag_push)
end

.to_paramObject


27
28
29
# File 'app/models/integrations/emails_on_push.rb', line 27

def self.to_param
  'emails_on_push'
end

.valid_recipients(recipients) ⇒ Object


15
16
17
# File 'app/models/integrations/emails_on_push.rb', line 15

def self.valid_recipients(recipients)
  recipients.split.grep(Devise.email_regexp).uniq(&:downcase)
end

Instance Method Details

#descriptionObject


23
24
25
# File 'app/models/integrations/emails_on_push.rb', line 23

def description
  s_('EmailsOnPushService|Email the commits and diff of each push to a list of recipients.')
end

#disable_diffs?Boolean

Returns:

  • (Boolean)

66
67
68
# File 'app/models/integrations/emails_on_push.rb', line 66

def disable_diffs?
  Gitlab::Utils.to_boolean(self.disable_diffs)
end

#execute(push_data) ⇒ Object


41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/integrations/emails_on_push.rb', line 41

def execute(push_data)
  return unless supported_events.include?(push_data[:object_kind])
  return if project.emails_disabled?
  return unless notify_for_ref?(push_data)

  EmailsOnPushWorker.perform_async(
    project_id,
    recipients,
    push_data,
    send_from_committer_email: send_from_committer_email?,
    disable_diffs:             disable_diffs?
  )
end

#fieldsObject


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/models/integrations/emails_on_push.rb', line 70

def fields
  domains = Notify.allowed_email_domains.map { |domain| "[email protected]#{domain}" }.join(", ")
  [
    { type: 'checkbox', name: 'send_from_committer_email', title: s_("EmailsOnPushService|Send from committer"),
      help: s_("EmailsOnPushService|Send notifications from the committer's email address if the domain matches the domain used by your GitLab instance (such as %{domains}).") % { domains: domains } },
    { type: 'checkbox', name: 'disable_diffs', title: s_("EmailsOnPushService|Disable code diffs"),
      help: s_("EmailsOnPushService|Don't include possibly sensitive code diffs in notification body.") },
    {
      type: 'select',
      name: 'branches_to_be_notified',
      title: s_('Integrations|Branches for which notifications are to be sent'),
      choices: branch_choices
    },
    {
      type: 'textarea',
      name: 'recipients',
      placeholder: s_('EmailsOnPushService|[email protected] [email protected]'),
      help: s_('EmailsOnPushService|Emails separated by whitespace.')
    }
  ]
end

#initialize_propertiesObject


35
36
37
38
39
# File 'app/models/integrations/emails_on_push.rb', line 35

def initialize_properties
  super

  self.branches_to_be_notified = 'all' if branches_to_be_notified.nil?
end

#notify_for_ref?(push_data) ⇒ Boolean

Returns:

  • (Boolean)

55
56
57
58
59
60
# File 'app/models/integrations/emails_on_push.rb', line 55

def notify_for_ref?(push_data)
  return true if push_data[:object_kind] == 'tag_push'
  return true if push_data.dig(:object_attributes, :tag)

  notify_for_branch?(push_data)
end

#send_from_committer_email?Boolean

Returns:

  • (Boolean)

62
63
64
# File 'app/models/integrations/emails_on_push.rb', line 62

def send_from_committer_email?
  Gitlab::Utils.to_boolean(self.send_from_committer_email)
end

#titleObject


19
20
21
# File 'app/models/integrations/emails_on_push.rb', line 19

def title
  s_('EmailsOnPushService|Emails on push')
end