f93f8f569d
Enables frozen string for the following: * lib/gitlab/patch/**/*.rb * lib/gitlab/popen/**/*.rb * lib/gitlab/profiler/**/*.rb * lib/gitlab/project_authorizations/**/*.rb * lib/gitlab/prometheus/**/*.rb * lib/gitlab/query_limiting/**/*.rb * lib/gitlab/quick_actions/**/*.rb * lib/gitlab/redis/**/*.rb * lib/gitlab/request_profiler/**/*.rb * lib/gitlab/search/**/*.rb * lib/gitlab/sherlock/**/*.rb * lib/gitlab/sidekiq_middleware/**/*.rb * lib/gitlab/slash_commands/**/*.rb * lib/gitlab/sql/**/*.rb * lib/gitlab/template/**/*.rb * lib/gitlab/testing/**/*.rb * lib/gitlab/utils/**/*.rb * lib/gitlab/webpack/**/*.rb Partially addresses gitlab-org/gitlab-ce#47424.
44 lines
1.2 KiB
Ruby
44 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Gitlab
|
|
module SlashCommands
|
|
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 separated
|
|
/\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)
|
|
Gitlab::SlashCommands::Presenters::IssueNew.new(issue)
|
|
end
|
|
end
|
|
end
|
|
end
|