BigW Consortium Gitlab

emails_on_push_service.rb 1.51 KB
Newer Older
1
class EmailsOnPushService < Service
2 3
  boolean_accessor :send_from_committer_email
  boolean_accessor :disable_diffs
4
  prop_accessor :recipients
5 6 7 8 9 10 11
  validates :recipients, presence: true, if: :activated?

  def title
    'Emails on push'
  end

  def description
12
    'Email the commits and diff of each push to a list of recipients.'
13 14
  end

15
  def self.to_param
16 17 18
    'emails_on_push'
  end

19
  def self.supported_events
20
    %w(push tag_push)
21 22
  end

23 24
  def execute(push_data)
    return unless supported_events.include?(push_data[:object_kind])
25

26
    EmailsOnPushWorker.perform_async(
27 28 29 30 31
      project_id,
      recipients,
      push_data,
      send_from_committer_email: send_from_committer_email?,
      disable_diffs:             disable_diffs?
32
    )
33 34
  end

35
  def send_from_committer_email?
36
    Gitlab::Utils.to_boolean(self.send_from_committer_email)
37 38
  end

39
  def disable_diffs?
40
    Gitlab::Utils.to_boolean(self.disable_diffs)
41 42 43
  end

  def fields
44
    domains = Notify.allowed_email_domains.map { |domain| "user@#{domain}" }.join(", ")
45
    [
46
      { type: 'checkbox', name: 'send_from_committer_email', title: "Send from committer",
47 48 49
        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." },
50
      { type: 'textarea', name: 'recipients', placeholder: 'Emails separated by whitespace' }
51 52 53
    ]
  end
end