1 | _ = require "underscore"
|
2 |
|
3 | Config = require "../config"
|
4 | Utils = require "../utils"
|
5 |
|
6 | class Labels
|
7 |
|
8 | @forTicketWith: (ticket, labels, msg, includeAttachment=no, emit=yes) ->
|
9 | Utils.fetch "#{Config.jira.url}/rest/api/2/issue/#{ticket.key}",
|
10 | method: "PUT"
|
11 | body: JSON.stringify
|
12 | fields: labels: labels
|
13 | .then ->
|
14 | msg.robot.emit "JiraTicketLabelled", ticket, msg.message.room, includeAttachment if emit
|
15 | .catch (error) ->
|
16 | msg.robot.emit "JiraTicketLabelFailed", error, msg.message.room if emit
|
17 | Promise.reject error
|
18 |
|
19 | @forTicketKeyWith: (key, labels, msg, includeAttachment=no, emit=yes) ->
|
20 | Create = require "./create"
|
21 | Create.fromKey(key)
|
22 | .then (ticket) ->
|
23 | labels = _(labels).union ticket.fields.labels
|
24 | Labels.forTicketWith ticket, labels, msg, includeAttachment, emit
|
25 |
|
26 | module.exports = Labels
|