c8755543f0
Enables frozen string for the following files: * lib/generators/**/*.rb * lib/gitaly/**/*.rb * lib/google_api/**/*.rb * lib/haml_lint/**/*.rb * lib/json_web_token/**/*.rb * lib/mattermost/**/*.rb * lib/microsoft_teams/**/*.rb * lib/object_storage/**/*.rb * lib/omni_auth/**/*.rb * lib/peek/**/*.rb * lib/rouge/**/*.rb * lib/rspec_flaky/**/*.rb * lib/system_check/**/*.rb Partially addresses #47424.
49 lines
1.1 KiB
Ruby
49 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module MicrosoftTeams
|
|
class Notifier
|
|
def initialize(webhook)
|
|
@webhook = webhook
|
|
@header = { 'Content-type' => 'application/json' }
|
|
end
|
|
|
|
def ping(options = {})
|
|
result = false
|
|
|
|
begin
|
|
response = Gitlab::HTTP.post(
|
|
@webhook.to_str,
|
|
headers: @header,
|
|
allow_local_requests: true,
|
|
body: body(options)
|
|
)
|
|
|
|
result = true if response
|
|
rescue Gitlab::HTTP::Error, StandardError => error
|
|
Rails.logger.info("#{self.class.name}: Error while connecting to #{@webhook}: #{error.message}")
|
|
end
|
|
|
|
result
|
|
end
|
|
|
|
private
|
|
|
|
def body(options = {})
|
|
result = { 'sections' => [] }
|
|
|
|
result['title'] = options[:title]
|
|
result['summary'] = options[:summary]
|
|
result['sections'] << MicrosoftTeams::Activity.new(options[:activity]).prepare
|
|
|
|
attachments = options[:attachments]
|
|
unless attachments.blank?
|
|
result['sections'] << {
|
|
'title' => 'Details',
|
|
'facts' => [{ 'name' => 'Attachments', 'value' => attachments }]
|
|
}
|
|
end
|
|
|
|
result.to_json
|
|
end
|
|
end
|
|
end
|