Skip to content

Instantly share code, notes, and snippets.

@davidosomething
Last active August 29, 2015 14:15
Show Gist options
  • Save davidosomething/43fdf7426bfb0529ca8a to your computer and use it in GitHub Desktop.
Save davidosomething/43fdf7426bfb0529ca8a to your computer and use it in GitHub Desktop.
hook.io - time2014 theme committed to WordPress VIP SVN
/**
* Hook.io - time2014 theme committed to WordPress VIP
*
* Hosted:
*
*
* @see https://github.com/TimeInc/time2014/blob/master/wpcom-meta.php
* @see http://lobby.vip.wordpress.com/2014/03/05/commit-webhook/
*
* WordPress posts to wpcom-meta on SVN commit
* That forwards the post data to this gist and hook.io
* hook.io returns data to slack as JSON in content body
*/
// Sample post data from WordPress
// array (
// 'repo' => 'vip',
// 'theme' => 'test-theme',
// 'revision' => '1234',
// 'committer' => 'batmoo',
//)
module.exports = function echoHttp (hook) {
var SLACK_CHANNEL = 'time-notifications';
var SLACK_WEBHOOK_URL = hook.env.TIME_SLACK_INCOMING;
var slack = require('slack-notify')(SLACK_WEBHOOK_URL);
var subject = [
hook.params.theme + ' theme committed to SVN (in VIP deploy queue)',
'by ' + hook.params.committer,
'at r' + hook.params.revision
].join(' ');
// put the output into this mappedData
var mappedData = {};
mappedData.name = 'davidbot';
mappedData.icon_url = 'https://s.w.org/about/images/logos/wordpress-logo-32-blue.png';
mappedData.text = subject;
slack.send({
channel: SLACK_CHANNEL,
username: mappedData.name,
icon_url: mappedData.icon_url,
text: mappedData.text
});
var body = JSON.stringify(mappedData, true, 2);
var headers = {
'Content-Length': body.length,
'Content-Type': 'application/json'
};
hook.res.writeHead(200, headers);
hook.res.end(body);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment