Commit 6737ada0 authored by Z.J. van de Weg's avatar Z.J. van de Weg

Remove some commands for now

parent d4def9cb
---
title: Add first slash commands
merge_request: 7438
author:
...@@ -3,11 +3,7 @@ module Gitlab ...@@ -3,11 +3,7 @@ module Gitlab
class Command < BaseCommand class Command < BaseCommand
COMMANDS = [ COMMANDS = [
Gitlab::ChatCommands::IssueShow, Gitlab::ChatCommands::IssueShow,
Gitlab::ChatCommands::IssueSearch,
Gitlab::ChatCommands::IssueCreate, Gitlab::ChatCommands::IssueCreate,
Gitlab::ChatCommands::MergeRequestShow,
Gitlab::ChatCommands::MergeRequestSearch,
].freeze ].freeze
def execute def execute
......
module Gitlab module Gitlab
module ChatCommands module ChatCommands
class IssueCreate < BaseCommand class IssueCreate < IssueCommand
def self.match(text) def self.match(text)
/\Aissue\s+create\s+(?<title>[^\n]*)\n*(?<description>.*)\z/.match(text) /\Aissue\s+create\s+(?<title>[^\n]*)\n*(?<description>.*)\z/.match(text)
end end
def self.help_message
'issue create <title>\n<description>'
end
def execute(match) def execute(match)
present nil unless can?(current_user, :create_issue, project) present nil unless can?(current_user, :create_issue, project)
......
module Gitlab
module ChatCommands
class IssueSearch < IssueCommand
def self.match(text)
/\Aissue\s+search\s+(?<query>.*)\s*/.match(text)
end
def self.help_message
"issue search <query>"
end
def execute(match)
present search_results(match[:query])
end
end
end
end
module Gitlab
module ChatCommands
class MergeRequestCommand < BaseCommand
def self.available?(project)
project.merge_requests_enabled?
end
def collection
project.merge_requests
end
def readable?(merge_request)
can?(current_user, :read_merge_request, merge_request)
end
end
end
end
module Gitlab
module ChatCommands
class MergeRequestSearch < MergeRequestCommand
def self.match(text)
/\Amergerequest\s+search\s+(?<query>.*)\s*/.match(text)
end
def self.help_message
"mergerequest search <query>"
end
def execute(match)
present search_results(match[:query])
end
end
end
end
module Gitlab
module ChatCommands
class MergeRequestShow < MergeRequestCommand
def self.match(text)
/\Amergerequest\s+show\s+(?<iid>\d+)/.match(text)
end
def self.help_message
"mergerequest show <id>"
end
def execute(match)
present find_by_iid(match[:iid])
end
end
end
end
module Mattermost module Mattermost
class Presenter class Presenter
class << self class << self
include Rails.application.routes.url_helpers
def authorize_chat_name(url) 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](#{url})!"
...@@ -59,7 +61,7 @@ module Mattermost ...@@ -59,7 +61,7 @@ module Mattermost
message = "The action was not succesfull because:\n" message = "The action was not succesfull because:\n"
message << resource.errors.messages.map { |message| "- #{message}" }.join("\n") message << resource.errors.messages.map { |message| "- #{message}" }.join("\n")
ephemeral_response(resource.errors.messages.join("\n") ephemeral_response(resource.errors.messages.join("\n"))
end end
def title(resource) def title(resource)
...@@ -67,14 +69,12 @@ module Mattermost ...@@ -67,14 +69,12 @@ module Mattermost
end end
def url(resource) def url(resource)
polymorphic_url( url_for(
[ [
resource.project.namespace.becomes(Namespace), resource.project.namespace.becomes(Namespace),
resource.project, resource.project,
resource resource
], ]
id: resource_id,
routing_type: :url
) )
end end
......
...@@ -7,12 +7,22 @@ describe Gitlab::ChatCommands::Command, service: true do ...@@ -7,12 +7,22 @@ describe Gitlab::ChatCommands::Command, service: true do
subject { described_class.new(project, user, params).execute } subject { described_class.new(project, user, params).execute }
xdescribe '#execute' do describe '#execute' do
context 'when issue show is triggered' do context 'when the command is not available' do
it 'calls IssueShowService' do let(:project) { create(:project, has_external_issue_tracker: true) }
expect_any_instance_of(Mattermost::Commands::IssueShowService).to receive(:new).with(project, user, params)
subject it 'displays the help message' do
expect(subject[:response_type]).to be(:ephemeral)
expect(subject[:text]).to start_with('Available commands')
end
end
context 'when an unknown command is triggered' do
let(:params) { { text: "unknown command 123" } }
it 'displays the help message' do
expect(subject[:response_type]).to be(:ephemeral)
expect(subject[:text]).to start_with('Available commands')
end end
end end
end end
......
require 'spec_helper'
describe Gitlab::ChatCommands::IssueSearch, service: true do
describe '#execute' do
let!(:issue) { create(:issue, title: 'The bird is the word') }
let(:project) { issue.project }
let(:user) { issue.author }
let(:regex_match) { described_class.match("issue search bird is the") }
before { project.team << [user, :master] }
subject { described_class.new(project, user).execute(regex_match) }
context 'without results' do
let(:regex_match) { described_class.match("issue search no results for this one") }
it "returns nil" do
expect(subject[:response_type]).to be :ephemeral
expect(subject[:text]).to start_with '404 not found!'
end
end
context 'with 1 result' do
it 'returns the issue' do
expect(subject[:response_type]).to be :in_channel
expect(subject[:text]).to match issue.title
end
end
context 'with 2 or more results' do
let!(:issue2) { create(:issue, project: project, title: 'bird is the word!') }
it 'returns multiple resources' do
expect(subject[:response_type]).to be :ephemeral
expect(subject[:text]).to start_with 'Multiple results were found'
end
end
end
end
require 'spec_helper'
describe Gitlab::ChatCommands::MergeRequestSearch, service: true do
describe '#execute' do
let!(:merge_request) { create(:merge_request, title: 'The bird is the word') }
let(:project) { merge_request.source_project }
let(:user) { merge_request.author }
let(:regex_match) { described_class.match("mergerequest search #{merge_request.title}") }
before do
project.team << [user, :master]
end
subject do
described_class.new(project, user).execute(regex_match)
end
context 'the merge request exists' do
it 'returns the merge request' do
expect(subject[:response_type]).to be(:in_channel)
expect(subject[:text]).to match(merge_request.title)
end
end
context 'no results can be found' do
let(:regex_match) { described_class.match("mergerequest search 12334") }
it "returns a 404 message" do
expect(subject[:response_type]).to be(:ephemeral)
expect(subject[:text]).to start_with('404 not found!')
end
end
end
describe 'self.match' do
it 'matches a valid query' do
expect(described_class.match("mergerequest search my title here")).to be_truthy
end
end
end
require 'spec_helper'
describe Gitlab::ChatCommands::MergeRequestShow, service: true do
describe '#execute' do
let!(:merge_request) { create(:merge_request) }
let(:project) { merge_request.source_project }
let(:user) { merge_request.author }
let(:regex_match) { described_class.match("mergerequest show #{merge_request.iid}") }
before { project.team << [user, :master] }
subject { described_class.new(project, user).execute(regex_match) }
context 'the merge request exists' do
it 'returns the merge request' do
expect(subject[:response_type]).to be :in_channel
expect(subject[:text]).to match merge_request.title
end
end
context 'the merge request does not exist' do
let(:regex_match) { described_class.match("mergerequest show 12345") }
it "returns nil" do
expect(subject[:response_type]).to be :ephemeral
expect(subject[:text]).to start_with '404 not found!'
end
end
end
describe "self.match" do
it 'matches valid strings' do
expect(described_class.match("mergerequest show 123")).to be_truthy
expect(described_class.match("mergerequest show sdf23")).to be_falsy
end
end
end
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