diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-11-17 12:57:27 +0100 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-11-17 21:34:24 +0100 |
commit | 6737ada0c8d980ed1bd8f425e885fa1b89930616 (patch) | |
tree | b2efd37f2450e137c15f5ee433046a7725202cda | |
parent | d4def9cbcd664b7067e7f9f4ea8be54463bd1d50 (diff) | |
download | gitlab-ce-6737ada0c8d980ed1bd8f425e885fa1b89930616.tar.gz |
Remove some commands for now
-rw-r--r-- | changelogs/unreleased/zj-slash-commands-mattermost.yml | 4 | ||||
-rw-r--r-- | lib/gitlab/chat_commands/command.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/chat_commands/issue_create.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/chat_commands/issue_search.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/chat_commands/merge_request_command.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/chat_commands/merge_request_search.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/chat_commands/merge_request_show.rb | 17 | ||||
-rw-r--r-- | lib/mattermost/presenter.rb | 12 | ||||
-rw-r--r-- | spec/lib/gitlab/chat_commands/command_spec.rb | 20 | ||||
-rw-r--r-- | spec/lib/gitlab/chat_commands/issue_search_spec.rb | 39 | ||||
-rw-r--r-- | spec/lib/gitlab/chat_commands/merge_request_search_spec.rb | 40 | ||||
-rw-r--r-- | spec/lib/gitlab/chat_commands/merge_request_show_spec.rb | 37 |
12 files changed, 30 insertions, 200 deletions
diff --git a/changelogs/unreleased/zj-slash-commands-mattermost.yml b/changelogs/unreleased/zj-slash-commands-mattermost.yml new file mode 100644 index 00000000000..84aca57e666 --- /dev/null +++ b/changelogs/unreleased/zj-slash-commands-mattermost.yml @@ -0,0 +1,4 @@ +--- +title: Add first slash commands +merge_request: 7438 +author: diff --git a/lib/gitlab/chat_commands/command.rb b/lib/gitlab/chat_commands/command.rb index f1490c045c3..0ed51d9b8fc 100644 --- a/lib/gitlab/chat_commands/command.rb +++ b/lib/gitlab/chat_commands/command.rb @@ -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 diff --git a/lib/gitlab/chat_commands/issue_create.rb b/lib/gitlab/chat_commands/issue_create.rb index b5cf85b58f1..0e2b4c0e9cd 100644 --- a/lib/gitlab/chat_commands/issue_create.rb +++ b/lib/gitlab/chat_commands/issue_create.rb @@ -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) diff --git a/lib/gitlab/chat_commands/issue_search.rb b/lib/gitlab/chat_commands/issue_search.rb deleted file mode 100644 index f64f3ad2680..00000000000 --- a/lib/gitlab/chat_commands/issue_search.rb +++ /dev/null @@ -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 diff --git a/lib/gitlab/chat_commands/merge_request_command.rb b/lib/gitlab/chat_commands/merge_request_command.rb deleted file mode 100644 index ad485483b8a..00000000000 --- a/lib/gitlab/chat_commands/merge_request_command.rb +++ /dev/null @@ -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 diff --git a/lib/gitlab/chat_commands/merge_request_search.rb b/lib/gitlab/chat_commands/merge_request_search.rb deleted file mode 100644 index 19a29546736..00000000000 --- a/lib/gitlab/chat_commands/merge_request_search.rb +++ /dev/null @@ -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 diff --git a/lib/gitlab/chat_commands/merge_request_show.rb b/lib/gitlab/chat_commands/merge_request_show.rb deleted file mode 100644 index 7ed5445e4c2..00000000000 --- a/lib/gitlab/chat_commands/merge_request_show.rb +++ /dev/null @@ -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 diff --git a/lib/mattermost/presenter.rb b/lib/mattermost/presenter.rb index 0f2beb2cd6b..b3d6c025109 100644 --- a/lib/mattermost/presenter.rb +++ b/lib/mattermost/presenter.rb @@ -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 diff --git a/spec/lib/gitlab/chat_commands/command_spec.rb b/spec/lib/gitlab/chat_commands/command_spec.rb index d28349ff1d8..bbd47f45761 100644 --- a/spec/lib/gitlab/chat_commands/command_spec.rb +++ b/spec/lib/gitlab/chat_commands/command_spec.rb @@ -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 diff --git a/spec/lib/gitlab/chat_commands/issue_search_spec.rb b/spec/lib/gitlab/chat_commands/issue_search_spec.rb deleted file mode 100644 index 3e54333528a..00000000000 --- a/spec/lib/gitlab/chat_commands/issue_search_spec.rb +++ /dev/null @@ -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 diff --git a/spec/lib/gitlab/chat_commands/merge_request_search_spec.rb b/spec/lib/gitlab/chat_commands/merge_request_search_spec.rb deleted file mode 100644 index 4033358ab2e..00000000000 --- a/spec/lib/gitlab/chat_commands/merge_request_search_spec.rb +++ /dev/null @@ -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 diff --git a/spec/lib/gitlab/chat_commands/merge_request_show_spec.rb b/spec/lib/gitlab/chat_commands/merge_request_show_spec.rb deleted file mode 100644 index ed63ffa5f85..00000000000 --- a/spec/lib/gitlab/chat_commands/merge_request_show_spec.rb +++ /dev/null @@ -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 |