Commit 6a08de73 authored by Z.J. van de Weg's avatar Z.J. van de Weg

Add issue search slash command

One of many requested in: gitlab-org/gitlab-ce#24768
parent 2914fa39
---
title: Add issue search slash command
merge_request:
author:
...@@ -40,9 +40,7 @@ module Gitlab ...@@ -40,9 +40,7 @@ module Gitlab
private private
def find_by_iid(iid) def find_by_iid(iid)
resource = collection.find_by(iid: iid) collection.find_by(iid: iid)
readable?(resource) ? resource : nil
end end
end end
end end
......
...@@ -4,6 +4,7 @@ module Gitlab ...@@ -4,6 +4,7 @@ module Gitlab
COMMANDS = [ COMMANDS = [
Gitlab::ChatCommands::IssueShow, Gitlab::ChatCommands::IssueShow,
Gitlab::ChatCommands::IssueCreate, Gitlab::ChatCommands::IssueCreate,
Gitlab::ChatCommands::IssueSearch,
Gitlab::ChatCommands::Deploy, Gitlab::ChatCommands::Deploy,
].freeze ].freeze
......
...@@ -6,11 +6,7 @@ module Gitlab ...@@ -6,11 +6,7 @@ module Gitlab
end end
def collection def collection
project.issues IssuesFinder.new(current_user, project_id: project.id).execute
end
def readable?(issue)
self.class.can?(current_user, :read_issue, issue)
end end
end end
end end
......
module Gitlab
module ChatCommands
class IssueSearch < IssueCommand
def self.match(text)
/\Aissue\s+search\s+(?<query>.*)/.match(text)
end
def self.help_message
"issue search <your query>"
end
def execute(match)
collection.search(match[:query]).limit(QUERY_LIMIT)
end
end
end
end
require 'spec_helper'
describe Gitlab::ChatCommands::IssueSearch, service: true do
describe '#execute' do
let!(:issue) { create(:issue, title: 'find me') }
let!(:confidential) { create(:issue, :confidential, project: project, title: 'mepmep find') }
let(:project) { issue.project }
let(:user) { issue.author }
let(:regex_match) { described_class.match("issue search find") }
subject do
described_class.new(project, user).execute(regex_match)
end
context 'when the user has no access' do
it 'only returns the open issues' do
expect(subject).not_to include(confidential)
end
end
context 'the user has access' do
before do
project.team << [user, :master]
end
it 'returns all results' do
expect(subject).to include(confidential, issue)
end
end
context 'without hits on the query' do
it 'returns an empty collection' do
expect(subject).to be_empty
end
end
end
describe 'self.match' do
let(:query) { "my search keywords" }
it 'matches the query' do
match = described_class.match("issue search #{query}")
expect(match[:query]).to eq(query)
end
end
end
...@@ -128,7 +128,7 @@ describe API::API, api: true do ...@@ -128,7 +128,7 @@ describe API::API, api: true do
) )
end end
it 'retusn status 200' do it 'returns status 200' do
post api("/projects/#{project.id}/services/mattermost_slash_commands/trigger"), params post api("/projects/#{project.id}/services/mattermost_slash_commands/trigger"), params
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment