-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathjira-bug.coffee
More file actions
59 lines (53 loc) · 1.83 KB
/
jira-bug.coffee
File metadata and controls
59 lines (53 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Description:
# Quickly file JIRA issues with hubot
#
# Dependencies:
# lodash
#
# Configuration:
# HUBOT_JIRA_URL (format: "https://jira-domain.com:9090")
# HUBOT_JIRA_USERNAME
# HUBOT_JIRA_PASSWORD
# HUBOT_JIRA_PROJECTS_MAP (format: {\"web\":\"WEB\",\"android\":\"AN\",\"ios\":\"IOS\",\"platform\":\"PLAT\"}
#
# Commands:
# hubot bug - File a bug in JIRA corresponding to the project
#
# Author:
# ndaversa
_ = require "lodash"
module.exports = (robot) ->
projects = JSON.parse process.env.HUBOT_JIRA_PROJECTS_MAP
jiraUrl = process.env.HUBOT_JIRA_URL
jiraUsername = process.env.HUBOT_JIRA_USERNAME
jiraPassword = process.env.HUBOT_JIRA_PASSWORD
if jiraUsername != undefined && jiraUsername.length > 0
auth = "#{jiraUsername}:#{jiraPassword}"
robot.hear /bug (.+)/i, (msg) ->
room = msg.message.room
user = msg.message.user.name
text = msg.match[1]
project = projects[room]
return msg.reply "Bugs most be submitted in one of the following rooms: " + _(projects).keys() if not project
issue = JSON.stringify
fields:
project:
key: project
summary: text
labels: ["triage"]
description: "Reported by #{user} in ##{room} on #{robot.adapterName}"
issuetype:
name: "Bug"
robot.http(jiraUrl + "/rest/api/2/issue")
.header("Content-Type", "application/json")
.auth(auth)
.post(issue) (err, res, body) ->
try
if res.statusCode is 201 and res.statusMessage is "Created"
json = JSON.parse body
msg.reply "Issue created: #{jiraUrl}/browse/#{json.key}"
else
msg.reply "Unable to file issue please notify @ndaversa"
console.log err, body
catch error
msg.reply "Unable to file issue: #{error}"