2018-11-19 21:01:13 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
2018-10-30 06:53:01 -04:00
|
|
|
# the title and description are not separated
|
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
|
|
|
|
2022-09-22 14:11:12 -04:00
|
|
|
result = create_issue(title: title, description: description)
|
2017-01-10 13:43:58 -05:00
|
|
|
|
2022-09-22 14:11:12 -04:00
|
|
|
if result.success?
|
|
|
|
presenter(result[:issue]).present
|
|
|
|
elsif result[:issue]
|
|
|
|
presenter(result[:issue]).display_errors
|
2017-01-26 09:30:34 -05:00
|
|
|
else
|
2022-09-22 14:11:12 -04:00
|
|
|
Gitlab::SlashCommands::Presenters::Error.new(
|
|
|
|
result.errors.join(', ')
|
|
|
|
).message
|
2017-01-10 13:43:58 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_issue(title:, description:)
|
2021-09-15 08:11:13 -04:00
|
|
|
::Issues::CreateService.new(project: project, current_user: current_user, params: { title: title, description: description }, spam_params: nil).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
|