bugsnag-notification-plugins
Version:
Notification plugins (chat and issue tracking integrations) for Bugsnag.
76 lines (60 loc) • 2.05 kB
text/coffeescript
NotificationPlugin = require "../../notification-plugin"
Handlebars = require "handlebars"
url = require "url"
cookie = require "cookie"
class YouTrack extends NotificationPlugin
resolveUrl = (config, path) ->
url.resolve config.url, path
handleCookies = (res) ->
res.headers['set-cookie'].map((item) ->
parsed = cookie.parse item
key = Object.keys(parsed)[0]
cookie.serialize key, parsed[key],
path: parsed.Path
).join '; '
loginUrl = (config) -> resolveUrl config, 'rest/user/login'
ticketUrl = (config) -> resolveUrl config, 'rest/issue'
.post loginUrl(config)
.type 'form'
.send
login: config.username
password: config.password
.on 'error', (err) ->
callback err
.end (res) ->
return callback res.error if res.error
callback null, handleCookies res
.put ticketUrl config
.type 'form' # This isn't documented
.set 'Cookie', token
.query
project: config.project
summary: @title event
description: @render event
.on 'error', (err) ->
callback err
.end (res) ->
return callback res.error if res.error
callback null,
url: res.header.location
return callback err if err # Unable to authenticate
module.exports = YouTrack