diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-04-03 17:39:17 +0100 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-04-05 13:57:11 +0100 |
commit | 7dd645e6c97dcc1dfeea4c0ad46ec1feabc87173 (patch) | |
tree | f77c886035b926b5d44e36f95af0bbba5bc727ae | |
parent | efe2d96a90cb5e2cc0c368294a021423aeeaeabe (diff) | |
download | gitlab-ce-7dd645e6c97dcc1dfeea4c0ad46ec1feabc87173.tar.gz |
add note message integration with microsoft teams
5 files changed, 45 insertions, 36 deletions
diff --git a/app/models/project_services/chat_message/base_message.rb b/app/models/project_services/chat_message/base_message.rb index 86d271a3f69..a35c32ad43b 100644 --- a/app/models/project_services/chat_message/base_message.rb +++ b/app/models/project_services/chat_message/base_message.rb @@ -7,7 +7,7 @@ module ChatMessage end def pretext - format(message) + markdown_format ? message : format(message) end def fallback diff --git a/app/models/project_services/chat_message/note_message.rb b/app/models/project_services/chat_message/note_message.rb index e06c37df69e..da03e4d946e 100644 --- a/app/models/project_services/chat_message/note_message.rb +++ b/app/models/project_services/chat_message/note_message.rb @@ -1,16 +1,18 @@ 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 diff --git a/app/models/project_services/chat_message/push_message.rb b/app/models/project_services/chat_message/push_message.rb index 9fb77d806ed..8e11ddba594 100644 --- a/app/models/project_services/chat_message/push_message.rb +++ b/app/models/project_services/chat_message/push_message.rb @@ -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 diff --git a/app/models/project_services/chat_notification_service.rb b/app/models/project_services/chat_notification_service.rb index 2957237faac..9a23038b7f2 100644 --- a/app/models/project_services/chat_notification_service.rb +++ b/app/models/project_services/chat_notification_service.rb @@ -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 diff --git a/app/models/project_services/microsoft_teams_service.rb b/app/models/project_services/microsoft_teams_service.rb index c0a3d2c0025..08eaeb06228 100644 --- a/app/models/project_services/microsoft_teams_service.rb +++ b/app/models/project_services/microsoft_teams_service.rb @@ -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) |