UNPKG

1.2 kBtext/coffeescriptView Raw
1Config = require "../config"
2Utils = require "../utils"
3
4class Comment
5
6 @forTicketWith: (ticket, comment, context, includeAttachment=no, emit=yes) ->
7 room = Utils.JiraBot.adapter.getRoomName context
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 #{context.message.user.name} in ##{room} on #{context.robot.adapterName}
15 #{Utils.JiraBot.adapter.getPermalink context}
16 """
17 .then ->
18 Utils.robot.logger.debug "#{ticket.key}:Comment", context.message.user.profile.email
19 Utils.cache.put "#{ticket.key}:Comment", context.message.user.profile.email
20 context.robot.emit "JiraTicketCommented", ticket, context, includeAttachment if emit
21 .catch (error) ->
22 context.robot.emit "JiraTicketCommentFailed", error, context if emit
23 Promise.reject error
24
25 @forTicketKeyWith: (key, comment, context, includeAttachment=no, emit=yes) ->
26 Create = require "./create"
27 Create.fromKey(key)
28 .then (ticket) ->
29 Comment.forTicketWith ticket, comment, context, includeAttachment, emit
30
31module.exports = Comment