Class: Gitlab::SlashCommands::IssueNew

Inherits:
IssueCommand show all
Defined in:
lib/gitlab/slash_commands/issue_new.rb

Constant Summary

Constants inherited from BaseCommand

BaseCommand::QUERY_LIMIT

Instance Attribute Summary

Attributes inherited from BaseCommand

#chat_name, #current_user, #params, #project

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from IssueCommand

available?, #collection

Methods inherited from BaseCommand

available?, can?, #collection, #initialize

Constructor Details

This class inherits a constructor from Gitlab::SlashCommands::BaseCommand

Class Method Details

.allowed?(project, user) ⇒ Boolean

Returns:

  • (Boolean)

16
17
18
# File 'lib/gitlab/slash_commands/issue_new.rb', line 16

def self.allowed?(project, user)
  can?(user, :create_issue, project)
end

.help_messageObject


12
13
14
# File 'lib/gitlab/slash_commands/issue_new.rb', line 12

def self.help_message
  'issue new <title> *`⇧ Shift`*+*`↵ Enter`* <description>'
end

.match(text) ⇒ Object


6
7
8
9
10
# File 'lib/gitlab/slash_commands/issue_new.rb', line 6

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

Instance Method Details

#execute(match) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gitlab/slash_commands/issue_new.rb', line 20

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