add pure http api - currently only trigger build

This commit is contained in:
oleg 2015-06-19 01:01:09 +03:00
parent e51656e05a
commit f212f443ed
6 changed files with 69 additions and 1 deletions

View File

@ -9,7 +9,7 @@ work in progress...
* Dashboard (builds list, projects autocomlete)
* Build page (build info, console)
* Awesome build output (very close to terminal)
* Url for trigger build run
* ~~Url for trigger build run~~
* ~~YAML project and server(executors count, etc) configs~~
* ~~Persistent build and console output information~~
* ~~Project relations (blocks, triggers, etc)~~

2
app.js
View File

@ -135,6 +135,8 @@ Steppy(
// init resources
require('./resources')(app);
require('./httpApi').register(app);
},
function(err) {
if (err) throw err;

View File

@ -4,3 +4,7 @@ nodes:
maxExecutorsCount: 2
notify: {}
httpApi:
host: 127.0.0.1
port: 3030

57
httpApi/index.js Normal file
View File

@ -0,0 +1,57 @@
'use strict';
var Steppy = require('twostep').Steppy,
_ = require('underscore'),
http = require('http');
/*
* Pure rest api on pure nodejs follows below
*/
exports.register = function(app) {
var config = app.config.httpApi,
projects = app.projects,
distributor = app.distributor;
var server = http.createServer(function(req, res) {
Steppy(
function() {
var stepCallback = this.slot();
req.setEncoding('utf-8');
var bodyString = '';
req.on('data', function(data) {
bodyString += data;
});
req.on('end', function() {
var body = JSON.parse(bodyString);
stepCallback(null, body);
});
req.on('error', stepCallback);
},
function(err, body) {
res.statusCode = 404;
// run building of a project
if (req.url === '/builds' && req.method === 'POST') {
var projectName = body.project,
project = _(projects).findWhere({name: projectName});
if (project) {
res.statusCode = 204;
distributor.run({
projectName: projectName,
initiator: {type: 'httpApi'}
}, _.noop);
}
}
res.end();
},
function(err) {
console.log('Error occurred during request: ', err.stack || err);
}
);
});
server.listen(config.port, config.host);
};

View File

@ -28,6 +28,9 @@ module.exports = function(app) {
}
});
// expose distributor to the app
app.distributor = distributor;
var getBuildLogPath = function(buildId) {
return path.join(app.config.paths.builds, buildId + '.log');
};

View File

@ -13,6 +13,8 @@ if this.state.build
span= initiator.project.name
span build #
span= initiator.number
else
span= initiator.type
if this.state.build.startDate
div