2015-12-07 07:23:23 -05:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: services
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# type :string(255)
|
|
|
|
# title :string(255)
|
|
|
|
# project_id :integer
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
# active :boolean default(FALSE), 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
|
2016-01-05 21:30:59 -05:00
|
|
|
# build_events :boolean default(FALSE), not null
|
2015-12-07 07:23:23 -05:00
|
|
|
#
|
|
|
|
|
|
|
|
class BuildsEmailService < Service
|
|
|
|
prop_accessor :recipients
|
|
|
|
boolean_accessor :add_pusher
|
|
|
|
boolean_accessor :notify_only_broken_builds
|
|
|
|
validates :recipients, presence: true, if: :activated?
|
|
|
|
|
2015-12-11 07:28:40 -05:00
|
|
|
def initialize_properties
|
|
|
|
if properties.nil?
|
|
|
|
self.properties = {}
|
|
|
|
self.notify_only_broken_builds = true
|
|
|
|
end
|
|
|
|
end
|
2015-12-10 08:08:09 -05:00
|
|
|
|
2015-12-07 07:23:23 -05:00
|
|
|
def title
|
|
|
|
'Builds emails'
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
|
|
|
'Email the builds status to a list of recipients.'
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_param
|
|
|
|
'builds_email'
|
|
|
|
end
|
|
|
|
|
|
|
|
def supported_events
|
|
|
|
%w(build)
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute(push_data)
|
|
|
|
return unless supported_events.include?(push_data[:object_kind])
|
|
|
|
|
|
|
|
if should_build_be_notified?(push_data)
|
|
|
|
BuildEmailWorker.perform_async(
|
|
|
|
push_data[:build_id],
|
|
|
|
all_recipients(push_data),
|
|
|
|
push_data,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def fields
|
|
|
|
[
|
2015-12-09 10:31:42 -05:00
|
|
|
{ type: 'textarea', name: 'recipients', placeholder: 'Emails separated by comma' },
|
2015-12-07 07:23:23 -05:00
|
|
|
{ type: 'checkbox', name: 'add_pusher', label: 'Add pusher to recipients list' },
|
|
|
|
{ type: 'checkbox', name: 'notify_only_broken_builds' },
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def should_build_be_notified?(data)
|
|
|
|
case data[:build_status]
|
|
|
|
when 'success'
|
|
|
|
!notify_only_broken_builds?
|
|
|
|
when 'failed'
|
2015-12-22 15:15:06 -05:00
|
|
|
!allow_failure?(data)
|
2015-12-07 07:23:23 -05:00
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-22 15:15:06 -05:00
|
|
|
def allow_failure?(data)
|
|
|
|
data[:build_allow_failure] == true
|
|
|
|
end
|
|
|
|
|
2015-12-07 07:23:23 -05:00
|
|
|
def all_recipients(data)
|
2015-12-11 12:01:57 -05:00
|
|
|
all_recipients = recipients.split(',')
|
2015-12-09 10:31:42 -05:00
|
|
|
|
2015-12-07 07:23:23 -05:00
|
|
|
if add_pusher? && data[:user][:email]
|
2015-12-09 10:31:42 -05:00
|
|
|
all_recipients << "#{data[:user][:email]}"
|
2015-12-07 07:23:23 -05:00
|
|
|
end
|
2015-12-09 10:31:42 -05:00
|
|
|
|
|
|
|
all_recipients
|
2015-12-07 07:23:23 -05:00
|
|
|
end
|
|
|
|
end
|