diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-11-17 21:27:12 +0100 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-11-17 21:44:26 +0100 |
commit | 166ee0965bacc20e2ad1187321654499a9b0f825 (patch) | |
tree | 57e97bcfd0c819adbe6b3673bb45b4fc0124781c /lib/mattermost | |
parent | 1607efa40081702488e22e560db2c1e30cd80093 (diff) | |
download | gitlab-ce-166ee0965bacc20e2ad1187321654499a9b0f825.tar.gz |
More refactoring, push present to base command
Diffstat (limited to 'lib/mattermost')
-rw-r--r-- | lib/mattermost/presenter.rb | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/lib/mattermost/presenter.rb b/lib/mattermost/presenter.rb index 84b7b8edd9e..7722022c658 100644 --- a/lib/mattermost/presenter.rb +++ b/lib/mattermost/presenter.rb @@ -4,24 +4,19 @@ module Mattermost include Rails.application.routes.url_helpers def authorize_chat_name(url) - message = "Hi there! We've yet to get acquainted! Please introduce yourself by [connection your GitLab profile](#{url})!" + message = ":wave: Hi there! Before I do anything for you, please [connect your GitLab account](#{url})." ephemeral_response(message) end - def help(messages, command) - return ephemeral_response("No commands configured") unless messages.count > 1 - message = ["Available commands:"] + def help(commands, trigger) + if commands.count == 0 + ephemeral_response("No commands configured") unless messages.count > 1 + else + message = header_with_list("Available commands", commands) - messages.each do |messsage| - message << "- #{command} #{message}" + ephemeral_response(message) end - - ephemeral_response(message.join("\n")) - end - - def not_found - ephemeral_response("404 not found! GitLab couldn't find what your were looking for! :boom:") end def present(resource) @@ -40,8 +35,16 @@ module Mattermost single_resource(resource) end + def access_denied + ephemeral_response("Whoops! That action is not allowed. This incident will be [reported](https://xkcd.com/838/).") + end + private + def not_found + ephemeral_response("404 not found! GitLab couldn't find what your were looking for! :boom:") + end + def single_resource(resource) return error(resource) if resource.errors.any? @@ -52,23 +55,33 @@ module Mattermost end def multiple_resources(resources) - message = "Multiple results were found:\n" - message << resources.map { |resource| "- #{title(resource)}" }.join("\n") + resources.map! { |resource| title(resource) } + + message = header_with_list("Multiple results were found:", resources) ephemeral_response(message) end def error(resource) - message = "The action was not succesfull because:\n" - message << resource.errors.messages.map { |message| "- #{message}" }.join("\n") + message = header_with_list("The action was not succesful, because:", resource.errors.messages) - ephemeral_response(resource.errors.messages.join("\n")) + ephemeral_response(message) end def title(resource) "[#{resource.to_reference} #{resource.title}](#{url(resource)})" end + def header_with_list(header, items) + message = [header] + + items.each do |item| + message << "- #{item}" + end + + message.join("\n") + end + def url(resource) url_for( [ @@ -82,14 +95,16 @@ module Mattermost def ephemeral_response(message) { response_type: :ephemeral, - text: message + text: message, + status: 200 } end def in_channel_response(message) { response_type: :in_channel, - text: message + text: message, + status: 200 } end end |