Commit 7dd645e6 authored by Tiago Botelho's avatar Tiago Botelho

add note message integration with microsoft teams

parent efe2d96a
......@@ -7,7 +7,7 @@ module ChatMessage
end
def pretext
format(message)
markdown_format ? message : format(message)
end
def fallback
......
module ChatMessage
class NoteMessage < BaseMessage
attr_reader :message
attr_reader :user_name
attr_reader :user_avatar
attr_reader :project_name
attr_reader :project_url
attr_reader :note
attr_reader :note_url
attr_reader :comment_attrs
attr_reader :markdown_format
def initialize(params)
params = HashWithIndifferentAccess.new(params)
@user_name = params[:user][:username]
@user_avatar = params[:user][:avatar]
@user_name = params[:user][:name]
@user_avatar = params[:user][:avatar_url]
@project_name = params[:project_name]
@project_url = params[:project_url]
......@@ -18,7 +20,30 @@ module ChatMessage
obj_attr = HashWithIndifferentAccess.new(obj_attr)
@note = obj_attr[:note]
@note_url = obj_attr[:url]
noteable_type = obj_attr[:noteable_type]
@comment_attrs = comment_params(obj_attr[:noteable_type], params)
@markdown_format = params[:format]
end
def activity
{
title: "#{user_name} #{link('commented on ' + comment_attrs[:target], note_url)}",
subtitle: "to: #{project_link}",
text: "*#{comment_attrs[:title]}*",
image: user_avatar
}
end
def attachments
markdown_format ? note : description_message
end
private
def message
commented_on_message(comment_attrs)
end
def comment_params(noteable_type, params)
case noteable_type
when "Commit"
create_commit_note(HashWithIndifferentAccess.new(params[:commit]))
......@@ -31,40 +56,27 @@ module ChatMessage
end
end
def attachments
description_message
end
private
def format_title(title)
title.lines.first.chomp
end
def create_issue_note(issue)
{ target: "issue ##{issue[:iid]}", title: format_title(issue[:title]) }
end
def create_commit_note(commit)
commit_sha = commit[:id]
commit_sha = Commit.truncate_sha(commit_sha)
commented_on_message(
"commit #{commit_sha}",
format_title(commit[:message]))
end
def create_issue_note(issue)
commented_on_message(
"issue ##{issue[:iid]}",
format_title(issue[:title]))
{ target: "commit #{commit_sha}", title: format_title(commit[:message]) }
end
def create_merge_note(merge_request)
commented_on_message(
"merge request !#{merge_request[:iid]}",
format_title(merge_request[:title]))
{ target: "merge request !#{merge_request[:iid]}", title: format_title(merge_request[:title]) }
end
def create_snippet_note(snippet)
commented_on_message(
"snippet ##{snippet[:id]}",
format_title(snippet[:title]))
{ target: "snippet ##{snippet[:id]}", title: format_title(snippet[:title]) }
end
def description_message
......@@ -75,8 +87,8 @@ module ChatMessage
link(project_name, project_url)
end
def commented_on_message(target, title)
@message = "#{user_name} #{link('commented on ' + target, note_url)} in #{project_link}: *#{title}*"
def commented_on_message(target:, title:)
"#{user_name} #{link('commented on ' + target, note_url)} in #{project_link}: *#{title}*"
end
end
end
......@@ -9,6 +9,7 @@ module ChatMessage
attr_reader :ref_type
attr_reader :user_name
attr_reader :user_avatar
attr_reader :markdown_format
def initialize(params)
@after = params[:after]
......@@ -20,7 +21,7 @@ module ChatMessage
@ref = Gitlab::Git.ref_name(params[:ref])
@user_name = params[:user_name]
@user_avatar = params[:user_avatar]
@format = params[:format]
@markdown_format = params[:format]
end
def activity
......@@ -28,18 +29,14 @@ module ChatMessage
title: activity_title,
subtitle: "to: #{project_link}",
text: compare_link,
image: params[:user_avatar]
image: user_avatar
}
end
def pretext
@format ? format(message) : message
end
def attachments
return [] if new_branch? || removed_branch?
@format ? commit_message_attachments : commit_messages
markdown_format ? commit_messages : commit_message_attachments
end
private
......
......@@ -52,7 +52,7 @@ class ChatNotificationService < Service
data = data.merge(
project_url: project_url,
project_name: project_name,
format: true
format: false
)
# WebHook events often have an 'update' event that follows a 'open' or
......
......@@ -50,7 +50,7 @@ class MicrosoftTeamsService < ChatNotificationService
data = data.merge(
project_url: project_url,
project_name: project_name,
format: false
format: true
)
message = get_message(object_kind, data)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment