Created
October 11, 2014 01:11
-
-
Save sirkirby/48a580d6bc850ab6836e to your computer and use it in GitHub Desktop.
process a team city webhook and post to slack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.post = function(request, response) { | |
var p = request.body; | |
var Slack = require('slack-node'); | |
var slack = new Slack("[mywebhookskey]", "[myteamname]"); | |
// let me specify the destination and noise level via the query string | |
var channel = "#devops"; | |
if (request.query.channel != undefined && request.query.channel != null) | |
channel = request.query.channel; | |
var alert = false; | |
if (request.query.alert != undefined && request.query.alert != null) | |
alert = true; | |
var status = p.buildResult === 'success' ? "has *succeeded*" : "has *failed*"; | |
var color = p.buildResult === 'success' ? "good" : "danger"; | |
var message = alert ? (channel.indexOf("#") < 0 ? "<!group> " : "<!everyone> ") : ""; | |
message += "<http://mytcserver.com/project.html?projectId=" + p.projectId + "|" + p.projectName + "> :: <" + p.buildStatusUrl + "|" + p.buildName + " #" + p.buildNumber + "> " + status + " and was triggered by *" + p.triggeredBy + "*" | |
slack.webhook({ | |
channel: channel, | |
attachments: [ | |
{ | |
"text": message, | |
"fallback": message, | |
"color": color, | |
"mrkdwn_in": ["text", "fallback"] | |
} | |
] | |
}, function(err, response) { | |
}); | |
response.send(statusCodes.OK, { message : 'Message Sent' }); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment