Commit 242e291e authored by Z.J. van de Weg's avatar Z.J. van de Weg

Add issue create subcommand

parent 657838f1
...@@ -24,7 +24,7 @@ module Mattermost ...@@ -24,7 +24,7 @@ module Mattermost
private private
def command def command
params[:text].match(/\A(?<command>\S+)/)[:command] params[:text].split.first
end end
def present(result) def present(result)
......
...@@ -20,9 +20,20 @@ module Mattermost ...@@ -20,9 +20,20 @@ module Mattermost
private 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 def subcommands
%w[creates search show] %w[create search show]
end end
def collection def collection
...@@ -33,10 +44,6 @@ module Mattermost ...@@ -33,10 +44,6 @@ module Mattermost
can?(current_user, :read_issue, issue) can?(current_user, :read_issue, issue)
end end
# 'issue create my new title\nmy new description
# => 'create', ['my', 'new', 'title, ['my new description']]
# 'issue show 123'
# => 'show', ['123']
def parse_command def parse_command
split = command.split split = command.split
subcommand = split[1] subcommand = split[1]
......
...@@ -56,6 +56,19 @@ describe Mattermost::Commands::IssueService do ...@@ -56,6 +56,19 @@ describe Mattermost::Commands::IssueService do
end end
end 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 end
describe 'help_message' do describe 'help_message' do
......
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