gitlab-org--gitlab-foss/lib/gitlab/chat_commands/issue_new.rb

43 lines
1.1 KiB
Ruby
Raw Normal View History

module Gitlab
module ChatCommands
2017-01-26 09:30:34 -05:00
class IssueNew < IssueCommand
def self.match(text)
# we can not match \n with the dot by passing the m modifier as than
# the title and description are not seperated
/\Aissue\s+(new|create)\s+(?<title>[^\n]*)\n*(?<description>(.|\n)*)/.match(text)
end
2016-11-17 06:57:27 -05:00
def self.help_message
'issue new <title> *`⇧ Shift`*+*`↵ Enter`* <description>'
2016-11-17 06:57:27 -05:00
end
def self.allowed?(project, user)
can?(user, :create_issue, project)
end
def execute(match)
title = match[:title]
description = match[:description].to_s.rstrip
issue = create_issue(title: title, description: description)
2017-01-26 09:30:34 -05:00
if issue.persisted?
presenter(issue).present
2017-01-26 09:30:34 -05:00
else
presenter(issue).display_errors
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
end
def presenter(issue)
2017-01-26 09:30:34 -05:00
Gitlab::ChatCommands::Presenters::IssueNew.new(issue)
end
end
end
end