UNPKG

grunt-alert

Version:

Sends alerts about failing builds using different channels

45 lines (38 loc) 1.27 kB
/*request is injected*/ module.exports = function(request){ return function alertSlack(config, grunt, done, logger) { var payload = {}, url = config.webhookUrl; if(!url) { grunt.log.error('Webhook URL for Slack is not set'); logger.error('Webhook URL for Slack is not set'); return done(); } if(config.iconUrl) { payload.icon_url = config.iconUrl; } else if(config.iconEmoji) { payload.icon_emoji = config.iconEmoji; } payload.text = config.message; if(config.channel) { payload.channel = config.channel; } if(config.username) { payload.username = config.username; } request({ url: url, json: true, body: payload, method: 'POST' }, function(e, r, body){ if(e) { grunt.log.error('Failed to post to slack: ' + JSON.stringify(e)); logger.error('Failed to post to slack: ' + JSON.stringify(e)); return done(); } logger.log('Successfully posted to slack <' + config.message + '>'); return done(body); }); }; };