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