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
private
def command
params[:text].match(/\A(?<command>\S+)/)[:command]
params[:text].split.first
end
def present(result)
......
......@@ -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]
......
......@@ -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
......
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