summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Botelho <tiagonbotelho@hotmail.com>2017-04-03 18:16:24 +0100
committerTiago Botelho <tiagonbotelho@hotmail.com>2017-04-05 13:57:11 +0100
commit9bfa0a5ffab279f25c52f2e1e9644616168bf994 (patch)
treedb0dbd9254858dc13c29b1e8bfdab167ac711b6a
parent7dd645e6c97dcc1dfeea4c0ad46ec1feabc87173 (diff)
downloadgitlab-ce-9bfa0a5ffab279f25c52f2e1e9644616168bf994.tar.gz
adds remaining messages
-rw-r--r--app/models/project_services/chat_message/base_message.rb4
-rw-r--r--app/models/project_services/chat_message/issue_message.rb24
-rw-r--r--app/models/project_services/chat_message/merge_message.rb13
-rw-r--r--app/models/project_services/chat_message/pipeline_message.rb30
-rw-r--r--app/models/project_services/chat_message/wiki_page_message.rb15
-rw-r--r--lib/microsoft_teams/notifier.rb5
6 files changed, 72 insertions, 19 deletions
diff --git a/app/models/project_services/chat_message/base_message.rb b/app/models/project_services/chat_message/base_message.rb
index a35c32ad43b..e17d0181691 100644
--- a/app/models/project_services/chat_message/base_message.rb
+++ b/app/models/project_services/chat_message/base_message.rb
@@ -17,6 +17,10 @@ module ChatMessage
raise NotImplementedError
end
+ def activity
+ raise NotImplementedError
+ end
+
private
def message
diff --git a/app/models/project_services/chat_message/issue_message.rb b/app/models/project_services/chat_message/issue_message.rb
index 791e5b0cec7..398ea1dee3d 100644
--- a/app/models/project_services/chat_message/issue_message.rb
+++ b/app/models/project_services/chat_message/issue_message.rb
@@ -1,6 +1,7 @@
module ChatMessage
class IssueMessage < BaseMessage
attr_reader :user_name
+ attr_reader :user_avatar
attr_reader :title
attr_reader :project_name
attr_reader :project_url
@@ -9,9 +10,11 @@ module ChatMessage
attr_reader :action
attr_reader :state
attr_reader :description
+ attr_reader :markdown_format
def initialize(params)
@user_name = params[:user][:username]
+ @user_avatar = params[:user][:avatar_url]
@project_name = params[:project_name]
@project_url = params[:project_url]
@@ -23,23 +26,28 @@ module ChatMessage
@action = obj_attr[:action]
@state = obj_attr[:state]
@description = obj_attr[:description] || ''
+ @markdown_format = params[:format]
end
def attachments
return [] unless opened_issue?
- description_message
+ markdown_format ? description : description_message
+ end
+
+ def activity
+ {
+ title: "Issue #{state} by #{user_name}",
+ subtitle: "to: #{project_link}",
+ text: issue_link,
+ image: user_avatar
+ }
end
private
def message
- case state
- when "opened"
- "[#{project_link}] Issue #{state} by #{user_name}"
- else
- "[#{project_link}] Issue #{issue_link} #{state} by #{user_name}"
- end
+ "[#{project_link}] Issue #{issue_link} #{state} by #{user_name}"
end
def opened_issue?
@@ -52,7 +60,7 @@ module ChatMessage
title_link: issue_url,
text: format(description),
color: "#C95823"
- }]
+ }]
end
def project_link
diff --git a/app/models/project_services/chat_message/merge_message.rb b/app/models/project_services/chat_message/merge_message.rb
index 5e5efca7bec..13a894df980 100644
--- a/app/models/project_services/chat_message/merge_message.rb
+++ b/app/models/project_services/chat_message/merge_message.rb
@@ -1,6 +1,7 @@
module ChatMessage
class MergeMessage < BaseMessage
attr_reader :user_name
+ attr_reader :user_avatar
attr_reader :project_name
attr_reader :project_url
attr_reader :merge_request_id
@@ -8,9 +9,11 @@ module ChatMessage
attr_reader :target_branch
attr_reader :state
attr_reader :title
+ attr_reader :markdown_format
def initialize(params)
@user_name = params[:user][:username]
+ @user_avatar = params[:user][:avatar_url]
@project_name = params[:project_name]
@project_url = params[:project_url]
@@ -21,10 +24,16 @@ module ChatMessage
@target_branch = obj_attr[:target_branch]
@state = obj_attr[:state]
@title = format_title(obj_attr[:title])
+ @markdown_format = params[:format]
end
- def pretext
- format(message)
+ def activity
+ {
+ title: "Merge Request #{state} by #{user_name}",
+ subtitle: "to: #{project_link}",
+ text: merge_request_link,
+ image: user_avatar
+ }
end
def attachments
diff --git a/app/models/project_services/chat_message/pipeline_message.rb b/app/models/project_services/chat_message/pipeline_message.rb
index 210027565a8..4c1cf120614 100644
--- a/app/models/project_services/chat_message/pipeline_message.rb
+++ b/app/models/project_services/chat_message/pipeline_message.rb
@@ -1,7 +1,15 @@
module ChatMessage
class PipelineMessage < BaseMessage
- attr_reader :ref_type, :ref, :status, :project_name, :project_url,
- :user_name, :duration, :pipeline_id
+ attr_reader :ref_type
+ attr_reader :ref
+ attr_reader :status
+ attr_reader :project_name
+ attr_reader :project_url
+ attr_reader :user_name
+ attr_reader :duration
+ attr_reader :pipeline_id
+ attr_reader :user_avatar
+ attr_reader :markdown_format
def initialize(data)
pipeline_attributes = data[:object_attributes]
@@ -14,6 +22,9 @@ module ChatMessage
@project_name = data[:project][:path_with_namespace]
@project_url = data[:project][:web_url]
@user_name = (data[:user] && data[:user][:name]) || 'API'
+ @user_avatar = data[:user][:avatar_url] || ''
+
+ @markdown_format = params[:format]
end
def pretext
@@ -24,8 +35,17 @@ module ChatMessage
format(message)
end
+ def activity
+ {
+ title: "Pipeline #{pipeline_link} of #{branch_link} #{ref_type} by #{user_name} #{humanized_status}",
+ subtitle: "to: #{project_link}",
+ text: "in #{duration} #{'second'.pluralize(duration)}",
+ image: user_avatar
+ }
+ end
+
def attachments
- [{ text: format(message), color: attachment_color }]
+ markdown_format ? message : [{ text: format(message), color: attachment_color }]
end
private
@@ -34,10 +54,6 @@ module ChatMessage
"#{project_link}: Pipeline #{pipeline_link} of #{branch_link} #{ref_type} by #{user_name} #{humanized_status} in #{duration} #{'second'.pluralize(duration)}"
end
- def format(string)
- Slack::Notifier::LinkFormatter.format(string)
- end
-
def humanized_status
case status
when 'success'
diff --git a/app/models/project_services/chat_message/wiki_page_message.rb b/app/models/project_services/chat_message/wiki_page_message.rb
index 134083e4504..4f5c2e719c9 100644
--- a/app/models/project_services/chat_message/wiki_page_message.rb
+++ b/app/models/project_services/chat_message/wiki_page_message.rb
@@ -7,9 +7,11 @@ module ChatMessage
attr_reader :wiki_page_url
attr_reader :action
attr_reader :description
+ attr_reader :markdown_format
def initialize(params)
@user_name = params[:user][:username]
+ @user_avatar = params[:user][:avatar_url]
@project_name = params[:project_name]
@project_url = params[:project_url]
@@ -26,10 +28,21 @@ module ChatMessage
when "update"
"edited"
end
+
+ @markdown_format = params[:format]
+ end
+
+ def activity
+ {
+ title: "#{user_name} #{action} #{wiki_page_link}",
+ subtitle: "in: #{project_link}",
+ text: title,
+ image: user_avatar
+ }
end
def attachments
- description_message
+ markdown_format ? @description : description_message
end
private
diff --git a/lib/microsoft_teams/notifier.rb b/lib/microsoft_teams/notifier.rb
index deff5fd26ee..8e422575636 100644
--- a/lib/microsoft_teams/notifier.rb
+++ b/lib/microsoft_teams/notifier.rb
@@ -25,7 +25,10 @@ module MicrosoftTeams
'activityText' => options[:activity][:text],
'activityImage' => options[:activity][:image]
}
- result['sections'] << { 'title' => 'Details', 'facts' => attachments(options[:attachments]) } if options[:attachments]
+
+ if options[:attachments].present? && !options[:attachments].empty?
+ result['sections'] << { 'title' => 'Details', 'facts' => attachments(options[:attachments]) }
+ end
result.to_json
end