debian-mirror-gitlab/app/models/project_services/microsoft_teams_service.rb

58 lines
1.5 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
class MicrosoftTeamsService < ChatNotificationService
def title
2021-04-29 21:17:54 +05:30
'Microsoft Teams notifications'
2017-08-17 22:00:37 +05:30
end
def description
2021-06-08 01:23:25 +05:30
'Send notifications about project events to Microsoft Teams.'
2017-08-17 22:00:37 +05:30
end
def self.to_param
'microsoft_teams'
end
def help
2021-04-29 21:17:54 +05:30
'<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>'
2017-08-17 22:00:37 +05:30
end
def webhook_placeholder
'https://outlook.office.com/webhook/…'
end
def event_field(event)
end
def default_channel_placeholder
end
2019-07-31 22:56:46 +05:30
def self.supported_events
%w[push issue confidential_issue merge_request note confidential_note tag_push
pipeline wiki_page]
end
2017-08-17 22:00:37 +05:30
def default_fields
[
2021-04-29 21:17:54 +05:30
{ 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.' },
2020-04-22 19:07:51 +05:30
{ type: 'select', name: 'branches_to_be_notified', choices: branch_choices }
2017-08-17 22:00:37 +05:30
]
end
private
def notify(message, opts)
MicrosoftTeams::Notifier.new(webhook).ping(
title: message.project_name,
2018-11-08 19:23:39 +05:30
summary: message.summary,
2017-08-17 22:00:37 +05:30
activity: message.activity,
attachments: message.attachments
)
end
def custom_data(data)
2020-04-08 14:13:33 +05:30
super(data).merge(markdown: true)
2017-08-17 22:00:37 +05:30
end
end