summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-12-23 14:31:48 +0000
committerRémy Coutable <remy@rymai.me>2016-12-23 14:31:48 +0000
commit518a0144b107e3fc802785d45ed873b4119c44a6 (patch)
tree8a0211147ad531aabbbf1c113fdbb88e9666980c
parent89b67d6d5ada3e2201f5041791c8fc8788c9de01 (diff)
parentb7894a7451b5e6802f24690162cdf1fbb3454136 (diff)
downloadgitlab-ce-518a0144b107e3fc802785d45ed873b4119c44a6.tar.gz
Merge branch 'zj-fix-issue-search-chat-command' into 'master'
Fix errorcode 500 on slash commands Closes #26013 See merge request !8285
-rw-r--r--lib/gitlab/chat_commands/deploy.rb5
-rw-r--r--lib/gitlab/chat_commands/presenter.rb12
-rw-r--r--spec/lib/gitlab/chat_commands/command_spec.rb24
-rw-r--r--spec/models/project_services/mattermost_slash_commands_service_spec.rb2
4 files changed, 34 insertions, 9 deletions
diff --git a/lib/gitlab/chat_commands/deploy.rb b/lib/gitlab/chat_commands/deploy.rb
index 6bb854dc080..0f70323810d 100644
--- a/lib/gitlab/chat_commands/deploy.rb
+++ b/lib/gitlab/chat_commands/deploy.rb
@@ -49,8 +49,9 @@ module Gitlab
end
def url(subject)
- polymorphic_url(
- [ subject.project.namespace.becomes(Namespace), subject.project, subject ])
+ project = subject.project
+
+ namespace_project_build_url(project.namespace.becomes(Namespace), project, subject)
end
end
end
diff --git a/lib/gitlab/chat_commands/presenter.rb b/lib/gitlab/chat_commands/presenter.rb
index caceaa25391..8930a21f406 100644
--- a/lib/gitlab/chat_commands/presenter.rb
+++ b/lib/gitlab/chat_commands/presenter.rb
@@ -30,12 +30,12 @@ module Gitlab
if subject.is_a?(Gitlab::ChatCommands::Result)
show_result(subject)
elsif subject.respond_to?(:count)
- if subject.many?
- multiple_resources(subject)
- elsif subject.none?
+ if subject.none?
not_found
+ elsif subject.one?
+ single_resource(subject.first)
else
- single_resource(subject)
+ multiple_resources(subject)
end
else
single_resource(subject)
@@ -71,9 +71,9 @@ module Gitlab
end
def multiple_resources(resources)
- resources.map! { |resource| title(resource) }
+ titles = resources.map { |resource| title(resource) }
- message = header_with_list("Multiple results were found:", resources)
+ message = header_with_list("Multiple results were found:", titles)
ephemeral_response(message)
end
diff --git a/spec/lib/gitlab/chat_commands/command_spec.rb b/spec/lib/gitlab/chat_commands/command_spec.rb
index a0ec8884635..a2d84977f58 100644
--- a/spec/lib/gitlab/chat_commands/command_spec.rb
+++ b/spec/lib/gitlab/chat_commands/command_spec.rb
@@ -54,6 +54,30 @@ describe Gitlab::ChatCommands::Command, service: true do
end
end
+ context 'searching for an issue' do
+ let(:params) { { text: 'issue search find me' } }
+ let!(:issue) { create(:issue, project: project, title: 'find me') }
+
+ before do
+ project.team << [user, :master]
+ end
+
+ context 'a single issue is found' do
+ it 'presents the issue' do
+ expect(subject[:text]).to match(issue.title)
+ end
+ end
+
+ context 'multiple issues found' do
+ let!(:issue2) { create(:issue, project: project, title: "someone find me") }
+
+ it 'shows a link to the new issue' do
+ expect(subject[:text]).to match(issue.title)
+ expect(subject[:text]).to match(issue2.title)
+ end
+ end
+ end
+
context 'when trying to do deployment' do
let(:params) { { text: 'deploy staging to production' } }
let!(:build) { create(:ci_build, project: project) }
diff --git a/spec/models/project_services/mattermost_slash_commands_service_spec.rb b/spec/models/project_services/mattermost_slash_commands_service_spec.rb
index 672ced68681..c879edddfdd 100644
--- a/spec/models/project_services/mattermost_slash_commands_service_spec.rb
+++ b/spec/models/project_services/mattermost_slash_commands_service_spec.rb
@@ -6,7 +6,7 @@ describe MattermostSlashCommandsService, :models do
context 'Mattermost API' do
let(:project) { create(:empty_project) }
let(:service) { project.build_mattermost_slash_commands_service }
- let(:user) { create(:user)}
+ let(:user) { create(:user) }
before do
Mattermost::Session.base_uri("http://mattermost.example.com")