Created
August 8, 2018 19:38
-
-
Save rusmichal/d597a02ae32a9e619bbefc8d77386011 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 request = require('request'); | |
exports.notifyApprove = (req, res) => { | |
var payload = JSON.parse(req.body.payload) | |
if(payload.action == 'submitted') { | |
if(payload.review.state == 'approved') { | |
handleApprove(res, payload.pull_request); | |
} | |
} else { | |
res.status(200).send(""); | |
} | |
}; | |
function handleApprove(res, pullRequest) { | |
var branch = pullRequest.head.ref; | |
var options = { | |
method: 'POST', | |
url: 'https://app.bitrise.io/app/' + process.env.APP_ID + '/build/start.json', | |
headers: { 'Content-Type': 'application/json' }, | |
body: { | |
hook_info: { type: 'bitrise', api_token: process.env.TOKEN }, | |
build_params: { branch: branch, commit_message: 'Triggered by Bitrise Build URL', workflow_id: process.env.WORKFLOW }, | |
triggered_by: 'curl' | |
}, | |
json: true | |
}; | |
request(options, function (error, response, body) { | |
if (error) throw new Error(error); | |
var responseJSON = { | |
"color": "green", | |
"message": "Build " + body.build_number + " Started\n Triggered Workflow: " + body.triggered_workflow + " \nView Build at: " + body.build_url, | |
"notify": false, | |
"message_format": "text" | |
}; | |
res.status(200).send(responseJSON); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment