Created
March 12, 2016 18:28
-
-
Save mindstorms6/ce2f3352dfa0bb42b417 to your computer and use it in GitHub Desktop.
BitRise + Lambda + CodeCommit
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
var https = require('https'); | |
/** | |
* Calls bitrise to build your app, using the most recent commit | |
*/ | |
var BITRISE_API_TOKEN=""; | |
var BITRISE_APP=""; | |
var BRANCH="master"; | |
exports.handler = function(event, context) { | |
var aws = require('aws-sdk'); | |
//var codecommit = new aws.CodeCommit(); | |
//Log the updated references from the event | |
var references = event.Records[0].codecommit.references.map(function(reference) {return reference.ref;}); | |
var commit = event.Records[0].codecommit.references.map(function(reference) { return reference.commit;}); | |
console.log('References:', references); | |
console.log('Commit :', commit); | |
//Get the repository from the event and show its git clone URL | |
var repository = event.Records[0].eventSourceARN.split(":")[5]; | |
var params = { | |
repositoryName: repository, | |
commitId:commit | |
}; | |
var postData = '{"hook_info":{"type":"bitrise","api_token":"' + BITRISE_API_TOKEN + '"},"build_params":{"branch":"' + BRANCH + '","commit_hash":"' + commit + '","commit_message":"' + "message_disabled" + '"}}'; | |
var options = { | |
hostname : 'www.bitrise.io', | |
port : 443, | |
path : '/app/' + BITRISE_APP + '/build/start.json', | |
method : 'POST', | |
headers : { | |
'Content-Type' : 'application/x-www-form-urlencoded', | |
'User-Agent' : 'curl/7.43.0', | |
'Content-Length': postData.length | |
} | |
}; | |
var req = https.request(options, function(res) { | |
var body = ''; | |
console.log('Status:', res.statusCode); | |
console.log('Headers:', JSON.stringify(res.headers)); | |
res.setEncoding('utf8'); | |
res.on('data', function(chunk) { | |
body += chunk; | |
}); | |
res.on('end', function() { | |
console.log('Successfully processed HTTPS response'); | |
// If we know it's JSON, parse it | |
if (res.headers['content-type'] === 'application/json') { | |
body = JSON.parse(body); | |
} | |
context.succeed(body); | |
}); | |
}); | |
req.on('error', context.fail); | |
req.write(postData); | |
req.end(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment