debian-mirror-gitlab/lib/gitlab/slash_commands/issue_new.rb

43 lines
1.1 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
module Gitlab
2017-09-10 17:25:29 +05:30
module SlashCommands
2017-08-17 22:00:37 +05:30
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
def self.help_message
'issue new <title> *`⇧ Shift`*+*`↵ Enter`* <description>'
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)
if issue.persisted?
presenter(issue).present
else
presenter(issue).display_errors
end
end
private
def create_issue(title:, description:)
Issues::CreateService.new(project, current_user, title: title, description: description).execute
end
def presenter(issue)
2017-09-10 17:25:29 +05:30
Gitlab::SlashCommands::Presenters::IssueNew.new(issue)
2017-08-17 22:00:37 +05:30
end
end
end
end