mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-02-10 17:39:15 +00:00
add pure http api - currently only trigger build
This commit is contained in:
parent
e51656e05a
commit
f212f443ed
@ -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
2
app.js
@ -135,6 +135,8 @@ Steppy(
|
||||
|
||||
// init resources
|
||||
require('./resources')(app);
|
||||
|
||||
require('./httpApi').register(app);
|
||||
},
|
||||
function(err) {
|
||||
if (err) throw err;
|
||||
|
@ -4,3 +4,7 @@ nodes:
|
||||
maxExecutorsCount: 2
|
||||
|
||||
notify: {}
|
||||
|
||||
httpApi:
|
||||
host: 127.0.0.1
|
||||
port: 3030
|
||||
|
57
httpApi/index.js
Normal file
57
httpApi/index.js
Normal 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);
|
||||
};
|
@ -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');
|
||||
};
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user