2016-11-16 12:28:38 -05:00
|
|
|
module Gitlab
|
|
|
|
module ChatCommands
|
2016-11-17 09:30:04 -05:00
|
|
|
class IssueCreate < IssueCommand
|
2016-11-16 12:28:38 -05:00
|
|
|
def self.match(text)
|
2016-11-21 14:48:18 -05:00
|
|
|
# we can not match \n with the dot by passing the m modifier as than
|
|
|
|
# the title and description are not seperated
|
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-11-30 11:04:32 -05:00
|
|
|
'issue create <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
|
|
|
|
2016-11-17 09:30:04 -05:00
|
|
|
Issues::CreateService.new(project, current_user, title: title, description: description).execute
|
2016-11-16 12:28:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|