BigW Consortium Gitlab

emails_on_push_service.rb 2.03 KB
Newer Older
1 2 3 4
# == Schema Information
#
# Table name: services
#
5 6 7 8 9 10 11 12 13 14 15 16 17
#  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)
18 19 20
#

class EmailsOnPushService < Service
21
  prop_accessor :send_from_committer_email
22
  prop_accessor :disable_diffs
23
  prop_accessor :recipients
24 25 26 27 28 29 30
  validates :recipients, presence: true, if: :activated?

  def title
    'Emails on push'
  end

  def description
31
    'Email the commits and diff of each push to a list of recipients.'
32 33 34 35 36 37
  end

  def to_param
    'emails_on_push'
  end

38 39 40 41
  def supported_events
    %w(push)
  end

42 43
  def execute(push_data)
    return unless supported_events.include?(push_data[:object_kind])
44

45 46 47
    EmailsOnPushWorker.perform_async(project_id, recipients, push_data, send_from_committer_email?, disable_diffs?)
  end

48 49 50 51
  def send_from_committer_email?
    self.send_from_committer_email == "1"
  end

52 53
  def disable_diffs?
    self.disable_diffs == "1"
54 55 56
  end

  def fields
57
    domains = Notify.allowed_email_domains.map { |domain| "user@#{domain}" }.join(", ")
58
    [
59
      { type: 'checkbox', name: 'send_from_committer_email', title: "Send from committer",
60 61 62
        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." },
63
      { type: 'textarea', name: 'recipients', placeholder: 'Emails separated by whitespace' },
64 65 66
    ]
  end
end