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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.4 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
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
2018-12-13 13:39:08 +05:30
# the title and description are not separated
2017-08-17 22:00:37 +05:30
/\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
2022-11-25 23:54:43 +05:30
result = create_issue(title: title, description: description)
2017-08-17 22:00:37 +05:30
2022-11-25 23:54:43 +05:30
if result.success?
presenter(result[:issue]).present
elsif result[:issue]
presenter(result[:issue]).display_errors
2017-08-17 22:00:37 +05:30
else
2022-11-25 23:54:43 +05:30
Gitlab::SlashCommands::Presenters::Error.new(
result.errors.join(', ')
).message
2017-08-17 22:00:37 +05:30
end
end
private
def create_issue(title:, description:)
2021-11-11 11:23:49 +05:30
::Issues::CreateService.new(project: project, current_user: current_user, params: { title: title, description: description }, spam_params: nil).execute
2017-08-17 22:00:37 +05:30
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