Skip to content

Instantly share code, notes, and snippets.

@mucbuc
Last active March 31, 2017 19:14
Show Gist options
  • Save mucbuc/3fabfb103ef96cbf468d06e0b2e227b1 to your computer and use it in GitHub Desktop.
Save mucbuc/3fabfb103ef96cbf468d06e0b2e227b1 to your computer and use it in GitHub Desktop.
test-bot-invoke
/*
Example of aws-lambda kicking off unit tests triggered by github commits. Amazon SNS
is used for integration with github
*/
'use strict';
const http = require( 'http' )
, ip = process.env.BOT_IP;
exports.handler = (event, context, callback) => {
try {
const msg = JSON.parse(event.Records[0].Sns.Message)
, repo = msg.repository.name
, ref = msg.ref
, sha = msg.after;
, url = 'http://' + ip + '/' + repo + '/' + ref + '/' + sha;
http.get( url, (result) => {
callback( null, 'success:' + result.statusMessage );
})
.on( 'error', (error) => {
callback( null, 'failed:' + error );
});
}
catch( error ) {
callback( null, 'failed:' + error );
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment