2013-12-17 05:42:40 -05:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: services
|
|
|
|
#
|
2015-03-04 17:14:00 -05:00
|
|
|
# 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)
|
2015-05-03 12:05:38 -04:00
|
|
|
# note_events :boolean default(TRUE), not null
|
2016-01-05 21:30:59 -05:00
|
|
|
# build_events :boolean default(FALSE), not null
|
2013-12-17 05:42:40 -05:00
|
|
|
#
|
|
|
|
|
|
|
|
class EmailsOnPushService < Service
|
2015-02-25 08:05:45 -05:00
|
|
|
prop_accessor :send_from_committer_email
|
2015-02-25 08:29:49 -05:00
|
|
|
prop_accessor :disable_diffs
|
2014-09-07 20:54:18 -04:00
|
|
|
prop_accessor :recipients
|
2013-12-17 05:42:40 -05:00
|
|
|
validates :recipients, presence: true, if: :activated?
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def to_param
|
|
|
|
'emails_on_push'
|
|
|
|
end
|
|
|
|
|
2015-02-28 11:33:18 -05:00
|
|
|
def 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(
|
|
|
|
project_id,
|
|
|
|
recipients,
|
|
|
|
push_data,
|
|
|
|
send_from_committer_email: send_from_committer_email?,
|
|
|
|
disable_diffs: disable_diffs?
|
|
|
|
)
|
2015-03-08 19:49:11 -04:00
|
|
|
end
|
|
|
|
|
2015-02-25 08:05:45 -05:00
|
|
|
def send_from_committer_email?
|
|
|
|
self.send_from_committer_email == "1"
|
|
|
|
end
|
|
|
|
|
2015-02-25 08:29:49 -05:00
|
|
|
def disable_diffs?
|
|
|
|
self.disable_diffs == "1"
|
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." },
|
2013-12-17 05:58:44 -05:00
|
|
|
{ type: 'textarea', name: 'recipients', placeholder: 'Emails separated by whitespace' },
|
2013-12-17 05:42:40 -05:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|