2016-11-16 12:28:38 -05:00
|
|
|
module Gitlab
|
2017-05-31 01:50:53 -04:00
|
|
|
module SlashCommands
|
2017-01-26 09:30:34 -05:00
|
|
|
class IssueNew < IssueCommand
|
2016-11-16 12:28:38 -05:00
|
|
|
def self.match(text)
|
2017-01-10 13:43:58 -05:00
|
|
|
# we can not match \n with the dot by passing the m modifier as than
|
2016-11-21 14:48:18 -05:00
|
|
|
# the title and description are not seperated
|
2016-11-28 07:18:06 -05:00
|
|
|
/\Aissue\s+(new|create)\s+(?<title>[^\n]*)\n*(?<description>(.|\n)*)/.match(text)
|
2016-11-16 12:28:38 -05:00
|
|
|
end
|
|
|
|
|
2016-11-17 06:57:27 -05:00
|
|
|
def self.help_message
|
2016-12-15 08:11:43 -05:00
|
|
|
'issue new <title> *`⇧ Shift`*+*`↵ Enter`* <description>'
|
2016-11-17 06:57:27 -05:00
|
|
|
end
|
|
|
|
|
2016-11-17 15:27:12 -05:00
|
|
|
def self.allowed?(project, user)
|
|
|
|
can?(user, :create_issue, project)
|
|
|
|
end
|
2016-11-17 06:06:45 -05:00
|
|
|
|
2016-11-17 15:27:12 -05:00
|
|
|
def execute(match)
|
2016-11-16 12:28:38 -05:00
|
|
|
title = match[:title]
|
2016-11-21 14:48:18 -05:00
|
|
|
description = match[:description].to_s.rstrip
|
2016-11-16 12:28:38 -05:00
|
|
|
|
2017-01-10 13:43:58 -05:00
|
|
|
issue = create_issue(title: title, description: description)
|
|
|
|
|
2017-01-26 09:30:34 -05:00
|
|
|
if issue.persisted?
|
2017-01-10 13:43:58 -05:00
|
|
|
presenter(issue).present
|
2017-01-26 09:30:34 -05:00
|
|
|
else
|
|
|
|
presenter(issue).display_errors
|
2017-01-10 13:43:58 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_issue(title:, description:)
|
2016-11-17 09:30:04 -05:00
|
|
|
Issues::CreateService.new(project, current_user, title: title, description: description).execute
|
2016-11-16 12:28:38 -05:00
|
|
|
end
|
2017-01-10 13:43:58 -05:00
|
|
|
|
|
|
|
def presenter(issue)
|
2017-05-31 01:50:53 -04:00
|
|
|
Gitlab::SlashCommands::Presenters::IssueNew.new(issue)
|
2017-01-10 13:43:58 -05:00
|
|
|
end
|
2016-11-16 12:28:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|