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
|
2013-12-17 10:42:40 +00:00
|
|
|
validates :recipients, presence: true, if: :activated?
|
|
|
|
|
|
|
|
def title
|
|
|
|
'Emails on push'
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
2013-12-17 14:31:12 +00:00
|
|
|
'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
|
|
|
[
|
2015-03-08 23:49:11 +00:00
|
|
|
{ type: 'checkbox', name: 'send_from_committer_email', title: "Send from committer",
|
2015-02-25 14:56:42 +00: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 11:22:03 +00:00
|
|
|
{ type: 'textarea', name: 'recipients', placeholder: 'Emails separated by whitespace' }
|
2013-12-17 10:42:40 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|