summaryrefslogtreecommitdiff
path: root/lib/gitlab/chat_commands/issue_create.rb
blob: 1dba85c1b513959444b4fd115d422e772a932790 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module Gitlab
  module ChatCommands
    class IssueCreate < 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>\n<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

        Issues::CreateService.new(project, current_user, title: title, description: description).execute
      end
    end
  end
end