Class: EmailsOnPushService

Inherits:
Service
  • Object
show all
Defined in:
app/models/project_services/emails_on_push_service.rb

Overview

Schema Information

Table name: services

id                    :integer          not null, primary key
type                  :string
title                 :string
project_id            :integer
created_at            :datetime         not null
updated_at            :datetime         not null
active                :boolean          not null
properties            :text
template              :boolean          default(FALSE)
push_events           :boolean          default(TRUE)
issues_events         :boolean          default(TRUE)
merge_requests_events :boolean          default(TRUE)
tag_push_events       :boolean          default(TRUE)
note_events           :boolean          default(TRUE), not null
build_events          :boolean          default(FALSE), not null
category              :string           default("common"), not null
default               :boolean          default(FALSE)
wiki_page_events      :boolean          default(TRUE)

Instance Method Summary collapse

Methods inherited from Service

#activated?, #async_execute, available_services_names, boolean_accessor, #can_test?, #category, create_from_template, #help, #initialize_properties, #issue_tracker?, prop_accessor, #reset_updated_properties, #template?, #test, #updated_properties

Instance Method Details

#descriptionObject


35
36
37
# File 'app/models/project_services/emails_on_push_service.rb', line 35

def description
  'Email the commits and diff of each push to a list of recipients.'
end

#disable_diffs?Boolean

Returns:

  • (Boolean)

63
64
65
# File 'app/models/project_services/emails_on_push_service.rb', line 63

def disable_diffs?
  self.disable_diffs == "1"
end

#execute(push_data) ⇒ Object


47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/project_services/emails_on_push_service.rb', line 47

def execute(push_data)
  return unless supported_events.include?(push_data[:object_kind])

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

#fieldsObject


67
68
69
70
71
72
73
74
75
76
# File 'app/models/project_services/emails_on_push_service.rb', line 67

def fields
  domains = Notify.allowed_email_domains.map { |domain| "[email protected]#{domain}" }.join(", ")
  [
    { type: 'checkbox', name: 'send_from_committer_email', title: "Send from committer",
      help: "Send notifications from the committer's email address if the domain is part of the domain GitLab is running on (e.g. #{domains})." },
    { type: 'checkbox', name: 'disable_diffs', title: "Disable code diffs",
      help: "Don't include possibly sensitive code diffs in notification body." },
    { type: 'textarea', name: 'recipients', placeholder: 'Emails separated by whitespace' },
  ]
end

#send_from_committer_email?Boolean

Returns:

  • (Boolean)

59
60
61
# File 'app/models/project_services/emails_on_push_service.rb', line 59

def send_from_committer_email?
  self.send_from_committer_email == "1"
end

#supported_eventsObject


43
44
45
# File 'app/models/project_services/emails_on_push_service.rb', line 43

def supported_events
  %w(push tag_push)
end

#titleObject


31
32
33
# File 'app/models/project_services/emails_on_push_service.rb', line 31

def title
  'Emails on push'
end

#to_paramObject


39
40
41
# File 'app/models/project_services/emails_on_push_service.rb', line 39

def to_param
  'emails_on_push'
end