summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZ.J. van de Weg <git@zjvandeweg.nl>2016-12-12 11:20:17 +0100
committerZ.J. van de Weg <git@zjvandeweg.nl>2016-12-12 11:23:37 +0100
commitfa12c1b52c23151690ca005594086f9a00baee73 (patch)
tree1ec007cbb39a3083ed6e3c57fcf7c49b73035709
parent10167c0e1c3d1ca15faddeacc1c8ed907cd8dc93 (diff)
downloadgitlab-ce-zj-commands-have-presenter.tar.gz
PoC of multiple presenters for chat messageszj-commands-have-presenter
[ci skip]
-rw-r--r--app/models/project_services/mattermost_slash_commands_service.rb8
-rw-r--r--lib/gitlab/chat_commands/command.rb6
-rw-r--r--lib/gitlab/chat_commands/issue_create.rb4
-rw-r--r--lib/gitlab/chat_commands/presenters/mattermost/access.rb4
-rw-r--r--lib/gitlab/chat_commands/presenters/mattermost/new_issue.rb23
-rw-r--r--lib/gitlab/chat_commands/presenters/slack/new_issue.rb (renamed from lib/gitlab/chat_commands/presenters/new_issue.rb)0
6 files changed, 38 insertions, 7 deletions
diff --git a/app/models/project_services/mattermost_slash_commands_service.rb b/app/models/project_services/mattermost_slash_commands_service.rb
index ebb3b7f8203..c38f3e3d5e7 100644
--- a/app/models/project_services/mattermost_slash_commands_service.rb
+++ b/app/models/project_services/mattermost_slash_commands_service.rb
@@ -8,7 +8,7 @@ class MattermostSlashCommandsService < ChatService
end
def title
- 'Mattermost Command'
+ 'Mattermost Slash Commands'
end
def description
@@ -34,11 +34,15 @@ class MattermostSlashCommandsService < ChatService
return Gitlab::ChatCommands::Presenters::Access.new(url).authorize
end
- Gitlab::ChatCommands::Command.new(project, user, params).execute
+ Gitlab::ChatCommands::Command.new(project, user, params).execute(presenter_strategy)
end
private
+ def presenter_strategy
+ Gitlab::ChatCommands::Presenters::Mattermost
+ end
+
def find_chat_user(params)
ChatNames::FindUserService.new(self, params).execute
end
diff --git a/lib/gitlab/chat_commands/command.rb b/lib/gitlab/chat_commands/command.rb
index 880ddd8b9d0..4b730b0e7fc 100644
--- a/lib/gitlab/chat_commands/command.rb
+++ b/lib/gitlab/chat_commands/command.rb
@@ -8,14 +8,14 @@ module Gitlab
Gitlab::ChatCommands::Deploy,
].freeze
- def execute
+ def execute(presenter)
command, match = match_command
if command
if command.allowed?(project, current_user)
- command.new(project, current_user, params).execute(match)
+ command.new(project, current_user, params).execute(presenter_module, match)
else
- Gitlab::ChatCommands::Presenters::Access.new(match).access_denied
+ presenter::Access.new(match).access_denied
end
else
Gitlab::ChatCommands::Help.new(project, current_user, params).execute(available_commands)
diff --git a/lib/gitlab/chat_commands/issue_create.rb b/lib/gitlab/chat_commands/issue_create.rb
index 1f860f8a6e4..608cab52394 100644
--- a/lib/gitlab/chat_commands/issue_create.rb
+++ b/lib/gitlab/chat_commands/issue_create.rb
@@ -15,12 +15,12 @@ module Gitlab
can?(user, :create_issue, project)
end
- def execute(match)
+ def execute(presenter, match)
title = match[:title]
description = match[:description].to_s.rstrip
issue = create_issue(title: title, description: description)
- Gitlab::ChatCommands::Presenters::NewIssue.new(issue).present
+ persenter::NewIssue.new(issue).present
end
def create_issue(title:, description:)
diff --git a/lib/gitlab/chat_commands/presenters/mattermost/access.rb b/lib/gitlab/chat_commands/presenters/mattermost/access.rb
new file mode 100644
index 00000000000..1714258448e
--- /dev/null
+++ b/lib/gitlab/chat_commands/presenters/mattermost/access.rb
@@ -0,0 +1,4 @@
+module Gitlab::ChatCommands::Presenters::Mattermost::Access
+ class Access < Gitlab::ChatCommands::Presenters::Access
+ end
+end
diff --git a/lib/gitlab/chat_commands/presenters/mattermost/new_issue.rb b/lib/gitlab/chat_commands/presenters/mattermost/new_issue.rb
new file mode 100644
index 00000000000..bb828a684b7
--- /dev/null
+++ b/lib/gitlab/chat_commands/presenters/mattermost/new_issue.rb
@@ -0,0 +1,23 @@
+module Gitlab::ChatCommands::Presenters::Mattermost
+ class NewIssue < Gitlab::ChatCommands::Presenters::Issuable
+ def present
+ if @resource.errors.any?
+ display_errors
+ else
+ in_channel_response(new_issue)
+ end
+ end
+
+ def new_issue
+ message = [
+ "A new issue was opened by #{author.to_reference} on #{project.to_reference}",
+ "___",
+ "![#{author.name}](#{author.avatar_url}) #{author.name}",
+ "**#{@resource.title} ยท #{resource.to_reference}**",
+ "___"
+ ].join("\n")
+
+ ephemeral_response(text: message)
+ end
+ end
+end
diff --git a/lib/gitlab/chat_commands/presenters/new_issue.rb b/lib/gitlab/chat_commands/presenters/slack/new_issue.rb
index bfbae3bee9a..bfbae3bee9a 100644
--- a/lib/gitlab/chat_commands/presenters/new_issue.rb
+++ b/lib/gitlab/chat_commands/presenters/slack/new_issue.rb