2016-05-20 15:48:29 +02:00
|
|
|
var Handlebars = require('handlebars')
|
|
|
|
var request = require('request')
|
|
|
|
|
2017-01-10 09:30:56 +01:00
|
|
|
var handleNotify = function(metadata, notifyEntry) {
|
|
|
|
var regex
|
|
|
|
if(metadata.name && notifyEntry.packagePattern) {
|
|
|
|
regex = new RegExp(notifyEntry.packagePattern, notifyEntry.packagePatternFlags || '')
|
|
|
|
if(!regex.test(metadata.name)) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2016-05-20 15:48:29 +02:00
|
|
|
|
2017-01-10 09:30:56 +01:00
|
|
|
var template = Handlebars.compile(notifyEntry.content)
|
|
|
|
var content = template( metadata )
|
2016-05-20 15:48:29 +02:00
|
|
|
|
2017-01-10 09:30:56 +01:00
|
|
|
var options = {
|
|
|
|
body: content
|
|
|
|
}
|
2016-05-20 15:48:29 +02:00
|
|
|
|
2017-01-10 09:30:56 +01:00
|
|
|
if ( notifyEntry.headers ) {
|
|
|
|
options.headers = notifyEntry.headers
|
|
|
|
}
|
2016-05-20 15:48:29 +02:00
|
|
|
|
2017-01-10 09:30:56 +01:00
|
|
|
options.method = notifyEntry.method
|
2016-05-20 15:48:29 +02:00
|
|
|
|
2017-01-10 09:30:56 +01:00
|
|
|
if(notifyEntry.endpoint) {
|
|
|
|
options.url = notifyEntry.endpoint
|
|
|
|
}
|
2016-05-20 15:48:29 +02:00
|
|
|
|
2017-01-10 09:30:56 +01:00
|
|
|
request(options)
|
|
|
|
}
|
2016-05-20 15:48:29 +02:00
|
|
|
|
2017-01-10 09:30:56 +01:00
|
|
|
module.exports.notify = function(metadata, config) {
|
2016-05-20 15:48:29 +02:00
|
|
|
|
2017-01-10 09:30:56 +01:00
|
|
|
if (config.notify) {
|
|
|
|
if(config.notify.content) {
|
|
|
|
handleNotify(metadata, config.notify)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for(var key in config.notify) {
|
|
|
|
if(config.notify.hasOwnProperty(key)) {
|
|
|
|
handleNotify(metadata, config.notify[key])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-20 15:48:29 +02:00
|
|
|
}
|
|
|
|
}
|