Remove some commands for now
This commit is contained in:
parent
d4def9cbcd
commit
6737ada0c8
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Add first slash commands
|
||||
merge_request: 7438
|
||||
author:
|
|
@ -3,11 +3,7 @@ module Gitlab
|
|||
class Command < BaseCommand
|
||||
COMMANDS = [
|
||||
Gitlab::ChatCommands::IssueShow,
|
||||
Gitlab::ChatCommands::IssueSearch,
|
||||
Gitlab::ChatCommands::IssueCreate,
|
||||
|
||||
Gitlab::ChatCommands::MergeRequestShow,
|
||||
Gitlab::ChatCommands::MergeRequestSearch,
|
||||
].freeze
|
||||
|
||||
def execute
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
module Gitlab
|
||||
module ChatCommands
|
||||
class IssueCreate < BaseCommand
|
||||
class IssueCreate < IssueCommand
|
||||
def self.match(text)
|
||||
/\Aissue\s+create\s+(?<title>[^\n]*)\n*(?<description>.*)\z/.match(text)
|
||||
end
|
||||
|
||||
def self.help_message
|
||||
'issue create <title>\n<description>'
|
||||
end
|
||||
|
||||
def execute(match)
|
||||
present nil unless can?(current_user, :create_issue, project)
|
||||
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
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
|
|
@ -1,17 +0,0 @@
|
|||
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
|
|
@ -1,17 +0,0 @@
|
|||
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
|
|
@ -1,17 +0,0 @@
|
|||
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
|
|
@ -1,6 +1,8 @@
|
|||
module Mattermost
|
||||
class Presenter
|
||||
class << self
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
def authorize_chat_name(url)
|
||||
message = "Hi there! We've yet to get acquainted! Please [introduce yourself](#{url})!"
|
||||
|
||||
|
@ -59,7 +61,7 @@ module Mattermost
|
|||
message = "The action was not succesfull because:\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
|
||||
|
||||
def title(resource)
|
||||
|
@ -67,14 +69,12 @@ module Mattermost
|
|||
end
|
||||
|
||||
def url(resource)
|
||||
polymorphic_url(
|
||||
url_for(
|
||||
[
|
||||
resource.project.namespace.becomes(Namespace),
|
||||
resource.project,
|
||||
resource
|
||||
],
|
||||
id: resource_id,
|
||||
routing_type: :url
|
||||
resource
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -7,12 +7,22 @@ describe Gitlab::ChatCommands::Command, service: true do
|
|||
|
||||
subject { described_class.new(project, user, params).execute }
|
||||
|
||||
xdescribe '#execute' do
|
||||
context 'when issue show is triggered' do
|
||||
it 'calls IssueShowService' do
|
||||
expect_any_instance_of(Mattermost::Commands::IssueShowService).to receive(:new).with(project, user, params)
|
||||
describe '#execute' do
|
||||
context 'when the command is not available' do
|
||||
let(:project) { create(:project, has_external_issue_tracker: true) }
|
||||
|
||||
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
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
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
|
|
@ -1,40 +0,0 @@
|
|||
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
|
|
@ -1,37 +0,0 @@
|
|||
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
|
Loading…
Reference in New Issue