summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZ.J. van de Weg <git@zjvandeweg.nl>2016-11-12 14:25:40 +0100
committerZ.J. van de Weg <git@zjvandeweg.nl>2016-11-17 21:34:23 +0100
commit242e291e8999705cb517b8c2dfa2c29704d4ace9 (patch)
treec9d19d19804915db35198e0a6a234743b54fb24d
parent657838f1c88ed823e33d0ee07f19410be908f09f (diff)
downloadgitlab-ce-242e291e8999705cb517b8c2dfa2c29704d4ace9.tar.gz
Add issue create subcommand
-rw-r--r--app/services/mattermost/command_service.rb2
-rw-r--r--app/services/mattermost/commands/issue_service.rb19
-rw-r--r--spec/services/mattermost/commands/issue_service_spec.rb13
3 files changed, 27 insertions, 7 deletions
diff --git a/app/services/mattermost/command_service.rb b/app/services/mattermost/command_service.rb
index b1017a1eb53..2a104174d97 100644
--- a/app/services/mattermost/command_service.rb
+++ b/app/services/mattermost/command_service.rb
@@ -24,7 +24,7 @@ module Mattermost
private
def command
- params[:text].match(/\A(?<command>\S+)/)[:command]
+ params[:text].split.first
end
def present(result)
diff --git a/app/services/mattermost/commands/issue_service.rb b/app/services/mattermost/commands/issue_service.rb
index 4472098e566..17407355547 100644
--- a/app/services/mattermost/commands/issue_service.rb
+++ b/app/services/mattermost/commands/issue_service.rb
@@ -20,9 +20,20 @@ module Mattermost
private
- # TODO implement create
+ def create(_)
+ return nil unless can?(current_user, :create_issue, project)
+
+ # We parse again as the previous split splits on continues whitespace
+ # per the ruby spec, but we loose information on where the new lines were
+ match = command.match(/\Aissue create (?<title>.*)\n*/)
+ title = match[:title]
+ description = match.post_match
+
+ Issues::CreateService.new(project, current_user, title: title, description: description).execute
+ end
+
def subcommands
- %w[creates search show]
+ %w[create search show]
end
def collection
@@ -33,10 +44,6 @@ module Mattermost
can?(current_user, :read_issue, issue)
end
- # 'issue create my new title\nmy new description
- # => 'create', ['my', 'new', 'title, ['my new description']]
- # 'issue show 123'
- # => 'show', ['123']
def parse_command
split = command.split
subcommand = split[1]
diff --git a/spec/services/mattermost/commands/issue_service_spec.rb b/spec/services/mattermost/commands/issue_service_spec.rb
index 67629d26bc0..5ef363274ad 100644
--- a/spec/services/mattermost/commands/issue_service_spec.rb
+++ b/spec/services/mattermost/commands/issue_service_spec.rb
@@ -56,6 +56,19 @@ describe Mattermost::Commands::IssueService do
end
end
end
+
+ context 'create as subcommand' do
+ let(:title) { 'my new issue' }
+ let(:params) { { text: "issue create #{title}" } }
+
+ it 'return the new issue' do
+ expect(subject).to be_a Issue
+ end
+
+ it 'creates a new issue' do
+ expect { subject }.to change { Issue.count }.by(1)
+ end
+ end
end
describe 'help_message' do