BigW Consortium Gitlab

emails_on_push_service.rb 1.47 KB
Newer Older
1
class EmailsOnPushService < Service
2
  prop_accessor :send_from_committer_email
3
  prop_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 15 16 17 18
  end

  def to_param
    'emails_on_push'
  end

19
  def 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 27 28 29 30 31 32
    EmailsOnPushWorker.perform_async(
      project_id, 
      recipients, 
      push_data, 
      send_from_committer_email:  send_from_committer_email?, 
      disable_diffs:              disable_diffs?
    )
33 34
  end

35 36 37 38
  def send_from_committer_email?
    self.send_from_committer_email == "1"
  end

39 40
  def disable_diffs?
    self.disable_diffs == "1"
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