Read about our upcoming Code of Conduct on this issue

This instance was upgraded to Heptapod 0.28.0 today

emails_on_push_service.rb 1.74 KB
Newer Older
1
2
# frozen_string_literal: true

3
class EmailsOnPushService < Service
Robert Schilling's avatar
Robert Schilling committed
4
5
  boolean_accessor :send_from_committer_email
  boolean_accessor :disable_diffs
Drew Blessing's avatar
Drew Blessing committed
6
  prop_accessor :recipients
James Lopez's avatar
James Lopez committed
7
  validates :recipients, presence: true, if: :valid_recipients?
8
9

  def title
10
    s_('EmailsOnPushService|Emails on push')
11
12
13
  end

  def description
14
    s_('EmailsOnPushService|Email the commits and diff of each push to a list of recipients.')
15
16
  end

17
  def self.to_param
18
19
20
    'emails_on_push'
  end

21
  def self.supported_events
22
    %w(push tag_push)
23
24
  end

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

28
    EmailsOnPushWorker.perform_async(
Robert Schilling's avatar
Robert Schilling committed
29
30
31
32
33
      project_id,
      recipients,
      push_data,
      send_from_committer_email: send_from_committer_email?,
      disable_diffs:             disable_diffs?
34
    )
35
36
  end

37
  def send_from_committer_email?
Robert Schilling's avatar
Robert Schilling committed
38
    Gitlab::Utils.to_boolean(self.send_from_committer_email)
39
40
  end

41
  def disable_diffs?
Robert Schilling's avatar
Robert Schilling committed
42
    Gitlab::Utils.to_boolean(self.disable_diffs)
43
44
45
  end

  def fields
46
    domains = Notify.allowed_email_domains.map { |domain| "user@#{domain}" }.join(", ")
47
    [
48
49
50
51
52
      { type: 'checkbox', name: 'send_from_committer_email', title: s_("EmailsOnPushService|Send from committer"),
        help: s_("EmailsOnPushService|Send notifications from the committer's email address if the domain is part of the domain GitLab is running on (e.g. %{domains}).") % { domains: domains } },
      { type: 'checkbox', name: 'disable_diffs', title: s_("EmailsOnPushService|Disable code diffs"),
        help: s_("EmailsOnPushService|Don't include possibly sensitive code diffs in notification body.") },
      { type: 'textarea', name: 'recipients', placeholder: s_('EmailsOnPushService|Emails separated by whitespace') }
53
54
55
    ]
  end
end