microsoft_teams_service.rb 1.46 KB
Newer Older
1 2
# frozen_string_literal: true

3 4
class MicrosoftTeamsService < ChatNotificationService
  def title
5
    'Microsoft Teams notifications'
6 7 8
  end

  def description
9
    'Send notifications about project events to Microsoft Teams.'
10 11 12 13 14 15 16
  end

  def self.to_param
    'microsoft_teams'
  end

  def help
17
    '<p>Use this service to send notifications about events in GitLab projects to your Microsoft Teams channels. <a href="https://docs.gitlab.com/ee/user/project/integrations/microsoft_teams.html">How do I configure this integration?</a></p>'
18 19 20 21 22 23 24 25 26
  end

  def webhook_placeholder
    'https://outlook.office.com/webhook/…'
  end

  def event_field(event)
  end

Tiago Botelho's avatar
Tiago Botelho committed
27 28 29
  def default_channel_placeholder
  end

30 31 32 33 34
  def self.supported_events
    %w[push issue confidential_issue merge_request note confidential_note tag_push
       pipeline wiki_page]
  end

35 36
  def default_fields
    [
37 38
      { type: 'text', name: 'webhook', placeholder: "#{webhook_placeholder}" },
      { type: 'checkbox', name: 'notify_only_broken_pipelines', help: 'If selected, successful pipelines do not trigger a notification event.' },
39
      { type: 'select', name: 'branches_to_be_notified', choices: branch_choices }
40 41 42
    ]
  end

Tiago Botelho's avatar
Tiago Botelho committed
43
  private
44

Tiago Botelho's avatar
Tiago Botelho committed
45 46
  def notify(message, opts)
    MicrosoftTeams::Notifier.new(webhook).ping(
47
      title: message.project_name,
48
      summary: message.summary,
49
      activity: message.activity,
50
      attachments: message.attachments
Tiago Botelho's avatar
Tiago Botelho committed
51 52 53 54
    )
  end

  def custom_data(data)
55
    super(data).merge(markdown: true)
56 57
  end
end