From 39786933dea635f15dbadaf81d3d7ac234ccbc20 Mon Sep 17 00:00:00 2001 From: oleg Date: Sat, 9 May 2015 19:59:27 +0300 Subject: [PATCH] provide scm info for build --- README.md | 4 ++-- lib/distributor.js | 7 +++++++ lib/executor/base.js | 3 ++- lib/executor/local.js | 19 ++++++++++++++++++- test/executor.js | 14 ++++++++++++-- 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 287cdee..509aafc 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,10 @@ work in progress... ## TODO for release 1.0 -* Dashboard(builds list, projects autocomlete) +* Dashboard (builds list, projects autocomlete) * Build page (build info, console) * Url for trigger build run -* YAML project configs +* YAML project and server(executors count, etc) configs * Persistent builds * Project relations (blocks, triggers, etc) * Mail and jabber notifications (with commits, current step and error) diff --git a/lib/distributor.js b/lib/distributor.js index be30ddf..579db10 100644 --- a/lib/distributor.js +++ b/lib/distributor.js @@ -51,6 +51,7 @@ Distributor.prototype._runNext = function(callback) { var queueItem = self.queue[queueItemIndex]; this.pass(queueItemIndex, queueItem); + queueItem.build.startDate = Date.now(); queueItem.build.status = 'in-progress'; self._updateBuild(queueItem.build, this.slot()); }, @@ -59,6 +60,7 @@ Distributor.prototype._runNext = function(callback) { var stepCallback = this.slot(); var executor = node.run(queueItem.project, build.params, function(err) { + build.endDate = Date.now(); build.status = err ? 'error' : 'done'; build.error = err; self._updateBuild(build, function(err, build) { @@ -75,6 +77,11 @@ Distributor.prototype._runNext = function(callback) { executor.on('data', function(data) { self.onBuildData(build, data); }); + + executor.once('scmData', function(scmData) { + build.scm = scmData; + self._updateBuild(build); + }); }, callback ); diff --git a/lib/executor/base.js b/lib/executor/base.js index 36f13cb..21e827d 100644 --- a/lib/executor/base.js +++ b/lib/executor/base.js @@ -31,7 +31,8 @@ Executor.prototype.run = function(params, callback) { self.emit('currentStep', 'get sources'); self._getSources(project.scm, this.slot()); }, - function() { + function(err, scmData) { + self.emit('scmData', scmData); var funcs = project.steps.map(function(step, index) { return function() { var stepLabel = step.name || utils.prune(step.cmd, 15); diff --git a/lib/executor/local.js b/lib/executor/local.js index b7d721c..8f0d6ec 100644 --- a/lib/executor/local.js +++ b/lib/executor/local.js @@ -18,7 +18,7 @@ exports.Executor = Executor; Executor.prototype._getSources = function(params, callback) { var self = this, - scm, isFirstRun; + scm, isFirstRun, oldRev; Steppy( function() { var slot = this.slot(); @@ -36,6 +36,16 @@ Executor.prototype._getSources = function(params, callback) { isFirstRun = true; } scm = createScm(scmParams); + + if (isFirstRun) { + this.pass(null); + } else { + scm.getCurrent(this.slot()); + } + }, + function(err, id) { + oldRev = id; + if (isFirstRun) { scm.clone(self.cwd, params.rev, this.slot()); } else { @@ -49,6 +59,13 @@ Executor.prototype._getSources = function(params, callback) { this.pass(null); } }, + function() { + scm.getCurrent(this.slot()); + scm.getChanges(oldRev && oldRev.id, params.rev, this.slot()); + }, + function(err, rev, changes) { + this.pass({rev: rev, changes: changes}); + }, callback ); }; diff --git a/test/executor.js b/test/executor.js index 7884aee..9260fa2 100644 --- a/test/executor.js +++ b/test/executor.js @@ -46,8 +46,18 @@ var expect = require('expect.js'), }); }); - it('should run', function(done) { - executor.run({}, done); + it('should run', function() { + executor.run({}, function(err) { + expect(err).not.ok(); + }); }); + + it('should emit scm data', function(done) { + executor.on('scmData', function(scmData) { + expect(scmData).have.keys('rev', 'changes'); + done(); + }); + }); + }); });