Page MenuHomePhabricator
Paste P1832

circle-phab-glue.js
ActivePublic

Authored by nornagon on Jul 24 2015, 6:19 AM.
var request = require('request');
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var createCanduit = require('canduit');
app.set('port', (process.env.PORT || 5000));
app.use(bodyParser.json())
app.post('/build', function(req, res) {
var target_phid = req.query.target;
var diff_id = req.query.diff;
request.post({
url: 'https://circleci.com/api/v1/project/transcriptic/www/tree/circle',
qs: { "circle-token": process.env['CIRCLE_TOKEN'] },
json: true,
body: {
"build_parameters": {
"PHAB_DIFF_ID": diff_id,
"PHAB_TARGET_PHID": target_phid
}
}
}, function (err, res, body) {
console.log(err, body)
})
res.end();
});
app.post('/build-complete', function(req, res) {
var target_phid = req.body.payload.build_parameters['PHAB_TARGET_PHID'];
var outcome = req.body.payload.outcome
createCanduit({
api: "https://work.r23s.net/api/",
user: process.env['CONDUIT_USER'],
cert: process.env['CONDUIT_CERT'],
}, function(err, canduit) {
if (err) {
res.end();
return console.error("Error authenticating with conduit: %j", err);
}
canduit.exec('harbormaster.sendmessage', {
buildTargetPHID: target_phid,
type: (outcome == "success" ? "pass" : "fail"),
}, function(err, data) {
console.log("Called conduit", err, data)
res.end();
})
})
})
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});

Event Timeline

nornagon changed the title of this paste from untitled to circle-phab-glue.js.
nornagon updated the paste's language from autodetect to autodetect.