Forked from davidosomething/time2014-wpvip-committed.js
Last active
August 29, 2015 14:15
-
-
Save johnciacia/112ba04522fd7c65e1cd to your computer and use it in GitHub Desktop.
WordPress.com VIP Commit Hook
This file contains 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
/** | |
* Hook.io - fortune theme committed to WordPress VIP | |
* | |
* Hosted: | |
* | |
* | |
* @see https://github.com/TimeInc/fortune/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 = 'fortune-engineering'; | |
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 = 'WordPress.com VIP'; | |
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