diff --git a/README.md b/README.md index 397689e..2859eaa 100644 --- a/README.md +++ b/README.md @@ -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)~~ diff --git a/app.js b/app.js index 9473912..c3254ba 100644 --- a/app.js +++ b/app.js @@ -135,6 +135,8 @@ Steppy( // init resources require('./resources')(app); + + require('./httpApi').register(app); }, function(err) { if (err) throw err; diff --git a/data/config.yaml b/data/config.yaml index b4af7d2..3c30a60 100644 --- a/data/config.yaml +++ b/data/config.yaml @@ -4,3 +4,7 @@ nodes: maxExecutorsCount: 2 notify: {} + +httpApi: + host: 127.0.0.1 + port: 3030 diff --git a/httpApi/index.js b/httpApi/index.js new file mode 100644 index 0000000..ab2950c --- /dev/null +++ b/httpApi/index.js @@ -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); +}; diff --git a/resources/projects.js b/resources/projects.js index be5cab7..3d1c42e 100644 --- a/resources/projects.js +++ b/resources/projects.js @@ -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'); }; diff --git a/static/js/app/components/builds/view.jade b/static/js/app/components/builds/view.jade index 274c85e..edb2128 100644 --- a/static/js/app/components/builds/view.jade +++ b/static/js/app/components/builds/view.jade @@ -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