Class: BuildsEmailService

Inherits:
Service
  • Object
show all
Defined in:
app/models/project_services/builds_email_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, #issue_tracker?, prop_accessor, #reset_updated_properties, #template?, #test, #updated_properties

Instance Method Details

#all_recipients(data) ⇒ Object


92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/models/project_services/builds_email_service.rb', line 92

def all_recipients(data)
  all_recipients = []

  unless recipients.blank?
    all_recipients += recipients.split(',').compact.reject(&:blank?)
  end

  if add_pusher? && data[:user][:email]
    all_recipients << data[:user][:email]
  end

  all_recipients
end

#allow_failure?(data) ⇒ Boolean

Returns:

  • (Boolean)

88
89
90
# File 'app/models/project_services/builds_email_service.rb', line 88

def allow_failure?(data)
  data[:build_allow_failure] == true
end

#descriptionObject


42
43
44
# File 'app/models/project_services/builds_email_service.rb', line 42

def description
  'Email the builds status to a list of recipients.'
end

#execute(push_data) ⇒ Object


54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/models/project_services/builds_email_service.rb', line 54

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

  recipients = all_recipients(push_data)

  if recipients.any?
    BuildEmailWorker.perform_async(
      push_data[:build_id],
      recipients,
      push_data
    )
  end
end

#fieldsObject


69
70
71
72
73
74
75
# File 'app/models/project_services/builds_email_service.rb', line 69

def fields
  [
    { type: 'textarea', name: 'recipients', placeholder: 'Emails separated by comma' },
    { type: 'checkbox', name: 'add_pusher', label: 'Add pusher to recipients list' },
    { type: 'checkbox', name: 'notify_only_broken_builds' },
  ]
end

#initialize_propertiesObject


31
32
33
34
35
36
# File 'app/models/project_services/builds_email_service.rb', line 31

def initialize_properties
  if properties.nil?
    self.properties = {}
    self.notify_only_broken_builds = true
  end
end

#should_build_be_notified?(data) ⇒ Boolean

Returns:

  • (Boolean)

77
78
79
80
81
82
83
84
85
86
# File 'app/models/project_services/builds_email_service.rb', line 77

def should_build_be_notified?(data)
  case data[:build_status]
  when 'success'
    !notify_only_broken_builds?
  when 'failed'
    !allow_failure?(data)
  else
    false
  end
end

#supported_eventsObject


50
51
52
# File 'app/models/project_services/builds_email_service.rb', line 50

def supported_events
  %w(build)
end

#titleObject


38
39
40
# File 'app/models/project_services/builds_email_service.rb', line 38

def title
  'Builds emails'
end

#to_paramObject


46
47
48
# File 'app/models/project_services/builds_email_service.rb', line 46

def to_param
  'builds_email'
end