2018-08-10 06:45:01 +00:00
# frozen_string_literal: true
2013-12-17 10:42:40 +00:00
class EmailsOnPushService < Service
2016-12-05 14:40:53 +00:00
boolean_accessor :send_from_committer_email
boolean_accessor :disable_diffs
2014-09-08 00:54:18 +00:00
prop_accessor :recipients
2018-01-26 13:48:47 +00:00
validates :recipients , presence : true , if : :valid_recipients?
2013-12-17 10:42:40 +00:00
def title
2019-04-12 12:28:07 +00:00
s_ ( 'EmailsOnPushService|Emails on push' )
2013-12-17 10:42:40 +00:00
end
def description
2019-04-12 12:28:07 +00:00
s_ ( 'EmailsOnPushService|Email the commits and diff of each push to a list of recipients.' )
2013-12-17 10:42:40 +00:00
end
2016-12-27 12:44:24 +00:00
def self . to_param
2013-12-17 10:42:40 +00:00
'emails_on_push'
end
2016-12-27 12:44:24 +00:00
def self . supported_events
2015-03-17 12:55:39 +00:00
%w( push tag_push )
2015-02-28 16:33:18 +00:00
end
2015-03-08 23:49:11 +00:00
def execute ( push_data )
return unless supported_events . include? ( push_data [ :object_kind ] )
2015-02-19 05:02:57 +00:00
2015-03-23 14:00:12 +00:00
EmailsOnPushWorker . perform_async (
2016-12-05 14:40:53 +00:00
project_id ,
recipients ,
push_data ,
send_from_committer_email : send_from_committer_email? ,
disable_diffs : disable_diffs?
2015-03-23 14:00:12 +00:00
)
2015-03-08 23:49:11 +00:00
end
2015-02-25 13:05:45 +00:00
def send_from_committer_email?
2016-12-05 14:40:53 +00:00
Gitlab :: Utils . to_boolean ( self . send_from_committer_email )
2015-02-25 13:05:45 +00:00
end
2015-02-25 13:29:49 +00:00
def disable_diffs?
2016-12-05 14:40:53 +00:00
Gitlab :: Utils . to_boolean ( self . disable_diffs )
2013-12-17 10:42:40 +00:00
end
def fields
2015-02-25 14:56:42 +00:00
domains = Notify . allowed_email_domains . map { | domain | " user@ #{ domain } " } . join ( " , " )
2013-12-17 10:42:40 +00:00
[
2019-04-12 12:28:07 +00:00
{ 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 is part of the domain GitLab is running on (e.g. %{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 : 'textarea' , name : 'recipients' , placeholder : s_ ( 'EmailsOnPushService|Emails separated by whitespace' ) }
2013-12-17 10:42:40 +00:00
]
end
end