1 | Config = require "../config"
|
2 | Utils = require "../utils"
|
3 |
|
4 | class Ticket
|
5 | constructor: (json) ->
|
6 | @[k] = v for k,v of json
|
7 |
|
8 | toAttachment: (includeFields=yes) ->
|
9 | colors = [
|
10 | keywords: "story feature improvement epic"
|
11 | color: "#14892c"
|
12 | ,
|
13 | keywords: "bug"
|
14 | color: "#d04437"
|
15 | ,
|
16 | keywords: "experiment exploratory task"
|
17 | color: "#f6c342"
|
18 | ]
|
19 | result = Utils.fuzzyFind @fields.issuetype.name, colors, ['keywords']
|
20 | result = color: "#003366" unless result
|
21 |
|
22 | fields = []
|
23 | fieldsFallback = ""
|
24 | if includeFields
|
25 | if @watchers?.length > 0
|
26 | watchers = []
|
27 | fallbackWatchers = []
|
28 | for watcher in @watchers
|
29 | watchers.push Utils.lookupUserWithJira watcher
|
30 | fallbackWatchers.push Utils.lookupUserWithJira watcher, yes
|
31 | fields = [
|
32 | title: "Status"
|
33 | value: @fields.status.name
|
34 | short: yes
|
35 | ,
|
36 | title: "Assignee"
|
37 | value: Utils.lookupUserWithJira @fields.assignee
|
38 | short: yes
|
39 | ,
|
40 | title: "Reporter"
|
41 | value: Utils.lookupUserWithJira @fields.reporter
|
42 | short: yes
|
43 | ,
|
44 | title: "Watchers"
|
45 | value: if watchers then watchers.join ', ' else "None"
|
46 | short: yes
|
47 | ]
|
48 | fieldsFallback = """
|
49 | Status: #{@fields.status.name}
|
50 | Assignee: #{Utils.lookupUserWithJira @fields.assignee, yes}
|
51 | Reporter: #{Utils.lookupUserWithJira @fields.reporter, yes}
|
52 | Watchers: #{if fallbackWatchers then fallbackWatchers.join ', ' else "None"}
|
53 | """
|
54 |
|
55 | color: result.color
|
56 | type: "JiraTicketAttachment"
|
57 | author_name: @key
|
58 | author_link: "#{Config.jira.url}/browse/#{@key}"
|
59 | author_icon: if @fields.assignee? then @fields.assignee.avatarUrls["32x32"] else "https://slack.global.ssl.fastly.net/12d4/img/services/jira_128.png"
|
60 | title: @fields.summary.trim()
|
61 | title_link: "#{Config.jira.url}/browse/#{@key}"
|
62 | fields: fields
|
63 | fallback: """
|
64 | *#{@key} - #{@fields.summary.trim()}*
|
65 | #{Config.jira.url}/browse/#{@key}
|
66 | #{fieldsFallback}
|
67 | """
|
68 | module.exports = Ticket
|