diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-11-17 15:30:04 +0100 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-11-17 21:34:24 +0100 |
commit | 1607efa40081702488e22e560db2c1e30cd80093 (patch) | |
tree | e43388424e05c45eee6cf2ddef9f7e538327019b /lib | |
parent | 6737ada0c8d980ed1bd8f425e885fa1b89930616 (diff) | |
download | gitlab-ce-1607efa40081702488e22e560db2c1e30cd80093.tar.gz |
Add tests for increased converage
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/chat_commands/base_command.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/chat_commands/command.rb | 16 | ||||
-rw-r--r-- | lib/gitlab/chat_commands/issue_create.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/chat_commands/issue_show.rb | 2 | ||||
-rw-r--r-- | lib/mattermost/presenter.rb | 5 |
5 files changed, 20 insertions, 17 deletions
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+(?<title>[^\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 |