gitlab-org--gitlab-foss/lib/microsoft_teams/notifier.rb

34 lines
756 B
Ruby
Raw Normal View History

module MicrosoftTeams
class Notifier
def initialize(webhook)
@webhook = webhook
end
def ping(options = {})
HTTParty.post(
@webhook.to_str,
headers: { 'Content-type' => 'application/json' },
body: body(options)
)
end
private
def body(options = {})
attachments = options[:attachments]
result = { 'sections' => [] }
result['title'] = options[:title]
result['summary'] = options[:pretext]
result['sections'] << options[:activity]
2017-04-03 17:16:24 +00:00
result['sections'] << {
'title' => 'Details',
'facts' => [{ 'name' => 'Attachments', 'value' => attachments }]
} if attachments.present? && attachments.empty?
result.to_json
end
end
end