UNPKG

1.17 kBtext/coffeescriptView Raw
1Config = require "../config"
2Utils = require "../utils"
3
4class Comment
5
6 @forTicketWith: (ticket, comment, msg, includeAttachment=no, emit=yes) ->
7 room = Utils.JiraBot.adapter.getRoomName msg
8 Utils.fetch "#{Config.jira.url}/rest/api/2/issue/#{ticket.key}/comment",
9 method: "POST"
10 body: JSON.stringify
11 body:"""
12 #{comment}
13
14 Comment left by #{msg.message.user.name} in ##{room} on #{msg.robot.adapterName}
15 #{Utils.JiraBot.adapter.getPermalink msg}
16 """
17 .then ->
18 Utils.robot.logger.debug "#{ticket.key}:Comment", msg.message.user.profile.email
19 Utils.cache.put "#{ticket.key}:Comment", msg.message.user.profile.email
20 msg.robot.emit "JiraTicketCommented", ticket, msg.message.room, includeAttachment if emit
21 .catch (error) ->
22 msg.robot.emit "JiraTicketCommentFailed", error, msg.message.room if emit
23 Promise.reject error
24
25 @forTicketKeyWith: (key, comment, msg, includeAttachment=no, emit=yes) ->
26 Create = require "./create"
27 Create.fromKey(key)
28 .then (ticket) ->
29 Comment.forTicketWith ticket, comment, msg, includeAttachment, emit
30
31module.exports = Comment