summaryrefslogtreecommitdiff
path: root/lib/microsoft_teams
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-04-06 19:37:25 +0000
committerDouwe Maan <douwe@gitlab.com>2017-04-06 19:37:25 +0000
commit00e00cacf8cb4ce3bfb733bae47e7e594e91e294 (patch)
tree607671987a66dbb16d49738aef22616c13b6936b /lib/microsoft_teams
parent73cb71e41c0ade92b9673a5d74c7dd78679fae91 (diff)
parent1f404065ca602593dc18aa051515fd88132ddfdf (diff)
downloadgitlab-ce-00e00cacf8cb4ce3bfb733bae47e7e594e91e294.tar.gz
Merge branch 'microsoft-teams-integration' into 'master'
adds initial microsoft teams integration See merge request !10412
Diffstat (limited to 'lib/microsoft_teams')
-rw-r--r--lib/microsoft_teams/activity.rb19
-rw-r--r--lib/microsoft_teams/notifier.rb46
2 files changed, 65 insertions, 0 deletions
diff --git a/lib/microsoft_teams/activity.rb b/lib/microsoft_teams/activity.rb
new file mode 100644
index 00000000000..d2c420efdaf
--- /dev/null
+++ b/lib/microsoft_teams/activity.rb
@@ -0,0 +1,19 @@
+module MicrosoftTeams
+ class Activity
+ def initialize(title:, subtitle:, text:, image:)
+ @title = title
+ @subtitle = subtitle
+ @text = text
+ @image = image
+ end
+
+ def prepare
+ {
+ 'activityTitle' => @title,
+ 'activitySubtitle' => @subtitle,
+ 'activityText' => @text,
+ 'activityImage' => @image
+ }
+ end
+ end
+end
diff --git a/lib/microsoft_teams/notifier.rb b/lib/microsoft_teams/notifier.rb
new file mode 100644
index 00000000000..3bef68a1bcb
--- /dev/null
+++ b/lib/microsoft_teams/notifier.rb
@@ -0,0 +1,46 @@
+module MicrosoftTeams
+ class Notifier
+ def initialize(webhook)
+ @webhook = webhook
+ @header = { 'Content-type' => 'application/json' }
+ end
+
+ def ping(options = {})
+ result = false
+
+ begin
+ response = HTTParty.post(
+ @webhook.to_str,
+ headers: @header,
+ body: body(options)
+ )
+
+ result = true if response
+ rescue HTTParty::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[:pretext]
+ 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