From 1607efa40081702488e22e560db2c1e30cd80093 Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Thu, 17 Nov 2016 15:30:04 +0100 Subject: Add tests for increased converage --- lib/gitlab/chat_commands/base_command.rb | 8 -------- lib/gitlab/chat_commands/command.rb | 16 +++++++++++++--- lib/gitlab/chat_commands/issue_create.rb | 6 +++--- lib/gitlab/chat_commands/issue_show.rb | 2 +- lib/mattermost/presenter.rb | 5 +++-- 5 files changed, 20 insertions(+), 17 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/chat_commands/base_command.rb b/lib/gitlab/chat_commands/base_command.rb index b5d58af3588..81b15bd1f7a 100644 --- a/lib/gitlab/chat_commands/base_command.rb +++ b/lib/gitlab/chat_commands/base_command.rb @@ -35,14 +35,6 @@ module Gitlab Ability.allowed?(object, action, subject) end - def present(resource) - Mattermost::Presenter.present(resource) - end - - def help(messages) - Mattermost::Presenter.help(messages) - end - def find_by_iid(iid) resource = collection.find_by(iid: iid) diff --git a/lib/gitlab/chat_commands/command.rb b/lib/gitlab/chat_commands/command.rb index 0ed51d9b8fc..43144975901 100644 --- a/lib/gitlab/chat_commands/command.rb +++ b/lib/gitlab/chat_commands/command.rb @@ -9,9 +9,11 @@ module Gitlab def execute klass, match = fetch_klass - return help(help_messages, params[:command]) unless klass.try(:available?, project) - - klass.new(project, current_user, params).execute(match) + if klass + present klass.new(project, current_user, params).execute(match) + else + help(help_messages) + end end private @@ -40,6 +42,14 @@ module Gitlab def command params[:text] end + + def present(resource) + Mattermost::Presenter.present(resource) + end + + def help(messages) + Mattermost::Presenter.help(messages, params[:command]) + end end end end diff --git a/lib/gitlab/chat_commands/issue_create.rb b/lib/gitlab/chat_commands/issue_create.rb index 0e2b4c0e9cd..1e311e09771 100644 --- a/lib/gitlab/chat_commands/issue_create.rb +++ b/lib/gitlab/chat_commands/issue_create.rb @@ -1,6 +1,6 @@ module Gitlab module ChatCommands - class IssueCreate < IssueCommand + class IssueCreate < IssueCommand def self.match(text) /\Aissue\s+create\s+(?[^\n]*)\n*(?<description>.*)\z/.match(text) end @@ -10,12 +10,12 @@ module Gitlab end def execute(match) - present nil unless can?(current_user, :create_issue, project) + return nil unless can?(current_user, :create_issue, project) title = match[:title] description = match[:description] - present Issues::CreateService.new(project, current_user, title: title, description: description).execute + Issues::CreateService.new(project, current_user, title: title, description: description).execute end end end diff --git a/lib/gitlab/chat_commands/issue_show.rb b/lib/gitlab/chat_commands/issue_show.rb index e5530df31cc..f5bceb038e5 100644 --- a/lib/gitlab/chat_commands/issue_show.rb +++ b/lib/gitlab/chat_commands/issue_show.rb @@ -10,7 +10,7 @@ module Gitlab end def execute(match) - present find_by_iid(match[:iid]) + find_by_iid(match[:iid]) end end end diff --git a/lib/mattermost/presenter.rb b/lib/mattermost/presenter.rb index b3d6c025109..84b7b8edd9e 100644 --- a/lib/mattermost/presenter.rb +++ b/lib/mattermost/presenter.rb @@ -4,19 +4,20 @@ 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](#{url})!" + message = "Hi there! We've yet to get acquainted! Please introduce yourself by [connection your GitLab profile](#{url})!" ephemeral_response(message) end def help(messages, command) + return ephemeral_response("No commands configured") unless messages.count > 1 message = ["Available commands:"] messages.each do |messsage| message << "- #{command} #{message}" end - ephemeral_response(messages.join("\n")) + ephemeral_response(message.join("\n")) end def not_found -- cgit v1.2.1