Commit cc83aded authored by Kamil Trzcinski's avatar Kamil Trzcinski

Render format dependent links

parent dc995daf
...@@ -33,10 +33,11 @@ class ChatSlashCommandsService < Service ...@@ -33,10 +33,11 @@ class ChatSlashCommandsService < Service
user = find_chat_user(params) user = find_chat_user(params)
unless user unless user
url = authorize_chat_name_url(params) url = authorize_chat_name_url(params)
return Gitlab::ChatCommands::Presenter.authorize_chat_name(url) return presenter.authorize_chat_name(url)
end end
Gitlab::ChatCommands::Command.new(project, user, params).execute Gitlab::ChatCommands::Command.new(project, user,
params.merge(presenter_format: presenter_format)).execute
end end
private private
...@@ -48,4 +49,12 @@ class ChatSlashCommandsService < Service ...@@ -48,4 +49,12 @@ class ChatSlashCommandsService < Service
def authorize_chat_name_url(params) def authorize_chat_name_url(params)
ChatNames::AuthorizeUserService.new(self, params).execute ChatNames::AuthorizeUserService.new(self, params).execute
end end
def presenter
Gitlab::ChatCommands::Presenter.new(presenter_format)
end
def presenter_format
throw NotImplementedError
end
end end
...@@ -18,4 +18,8 @@ class MattermostSlashCommandsService < ChatService ...@@ -18,4 +18,8 @@ class MattermostSlashCommandsService < ChatService
def to_param def to_param
'mattermost_slash_commands' 'mattermost_slash_commands'
end end
def presenter_format
'mattermost'
end
end end
...@@ -12,4 +12,8 @@ class SlackSlashCommandsService < ChatSlashCommandsService ...@@ -12,4 +12,8 @@ class SlackSlashCommandsService < ChatSlashCommandsService
def to_param def to_param
'slack_slash_commands' 'slack_slash_commands'
end end
def presenter_format
'slack'
end
end end
...@@ -42,6 +42,10 @@ module Gitlab ...@@ -42,6 +42,10 @@ module Gitlab
def find_by_iid(iid) def find_by_iid(iid)
collection.find_by(iid: iid) collection.find_by(iid: iid)
end end
def presenter
Gitlab::ChatCommands::Presenter.new(params[:presenter_format])
end
end end
end end
end end
...@@ -48,15 +48,15 @@ module Gitlab ...@@ -48,15 +48,15 @@ module Gitlab
end end
def help(messages) def help(messages)
Mattermost::Presenter.help(messages, params[:command]) presenter.help(messages, params[:command])
end end
def access_denied def access_denied
Mattermost::Presenter.access_denied presenter.access_denied
end end
def present(resource) def present(resource)
Mattermost::Presenter.present(resource) presenter.present(resource)
end end
end end
end end
......
module Gitlab module Gitlab
class ChatCommands class ChatCommands
class Presenter class Presenter
class << self
include Gitlab::Routing.url_helpers include Gitlab::Routing.url_helpers
attr_reader :format
def initialize(format)
@format = format
end
def authorize_chat_name(url) def authorize_chat_name(url)
message = if url message = if url
":wave: Hi there! Before I do anything for you, please <#{url}|connect your GitLab account>." ":wave: Hi there! Before I do anything for you, please #{link(url, 'connect your GitLab account')}."
else else
":sweat_smile: Couldn't identify you, nor can I autorize you!" ":sweat_smile: Couldn't identify you, nor can I autorize you!"
end end
...@@ -44,7 +49,7 @@ module Gitlab ...@@ -44,7 +49,7 @@ module Gitlab
end end
def access_denied def access_denied
ephemeral_response("Whoops! That action is not allowed. This incident will be <https://xkcd.com/838/|reported>.") ephemeral_response("Whoops! That action is not allowed. This incident will be #{link('https://xkcd.com/838/', 'reported')}.")
end end
private private
...@@ -89,7 +94,7 @@ module Gitlab ...@@ -89,7 +94,7 @@ module Gitlab
reference = resource.try(:to_reference) || resource.try(:id) reference = resource.try(:to_reference) || resource.try(:id)
title = resource.try(:title) || resource.try(:name) title = resource.try(:title) || resource.try(:name)
"<#{url(resource)}|#{reference} #{title}>" link(url(resource), "#{reference} #{title}")
end end
def header_with_list(header, items) def header_with_list(header, items)
...@@ -127,6 +132,13 @@ module Gitlab ...@@ -127,6 +132,13 @@ module Gitlab
status: 200 status: 200
} }
end end
def link(url, title)
case format
when 'slack' then "<#{url}|#{title}>"
when 'mattermost' then "[#{title}](#{url})"
else then title
end
end end
end end
end end
......
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