From de5ddcbc88b7ae895231f99c204df84533b0104a Mon Sep 17 00:00:00 2001 From: oleg Date: Sun, 28 Jun 2015 13:23:34 +0300 Subject: [PATCH] catch revisions by tag --- README.md | 2 +- lib/executor/base.js | 15 ++++++ test/executor.js | 124 +++++++++++++++++++++++++++++++------------ 3 files changed, 105 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index c3d0136..ca3a352 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ work in progress... * Mail and jabber notifications (with commits, current step and error) * ~~Rename notification strategies according to statuses~~ * Work with git -* Build every commit, commit with tag, etc +* ~~Build every commit, commit with tag, etc~~ * Safe id and build numbers generation * Scheduler * ~~Better tests coverage~~ diff --git a/lib/executor/base.js b/lib/executor/base.js index c9d22f2..09a6f72 100644 --- a/lib/executor/base.js +++ b/lib/executor/base.js @@ -72,6 +72,21 @@ Executor.prototype._getTarget = function(rev, changes) { }); } + var tag = catchRev.tag; + if (tag) { + index = _(changes).findIndex(function(change) { + if (change.tags) { + if (_(tag).isRegExp()) { + return _(change.tags).find(function(changeTag) { + return tag.test(changeTag); + }); + } else { + return _(change.tags).contains(tag); + } + } + }); + } + if (index !== -1) { result.rev = changes[index].id; result.changes = changes.slice(0, index + 1); diff --git a/test/executor.js b/test/executor.js index ef8d135..ae622fb 100644 --- a/test/executor.js +++ b/test/executor.js @@ -67,50 +67,104 @@ var expect = require('expect.js'), ); }); - describe('with scm rev default and catch rev "first revision"', function() { - before(clearWorkspace); + _(['first revision', /^first revision$/]).each(function(comment) { - it('instance should be created without errors', function() { - executor = createExecutor(makeExecutorParams({ - project: { - catchRev: {comment: 'first revision'} + describe('with scm rev default and catch rev ' + comment, function() { + before(clearWorkspace); + + it('instance should be created without errors', function() { + executor = createExecutor(makeExecutorParams({ + project: { + catchRev: {comment: comment} + } + })); + }); + + it('should run without errors', function(done) { + executor.run({}, function(err) { + expect(err).not.ok(); + done(); + }); + executor.on('scmData', function(data) { + scmData = data; + }); + }); + + it('scm data should be rev: 1, changes: [0, 1], not latest', + function() { + expect(scmData).eql({ + rev: mercurialRevs[1], + changes: mercurialRevs.slice(0, 2).reverse(), + isLatest: false + }); + }); + + it('should run it again without errors', function(done) { + executor.run({}, done); + }); + + it( + 'scm data should be rev: last, changes: [2-last], is latest', + function() { + expect(scmData).eql({ + rev: mercurialRevs[mercurialRevs.length - 1], + changes: mercurialRevs.slice(2).reverse(), + isLatest: true + }); } - })); + ); }); - it('should run without errors', function(done) { - executor.run({}, function(err) { - expect(err).not.ok(); - done(); - }); - executor.on('scmData', function(data) { - scmData = data; - }); - }); + }); - it('scm data should be rev: 1, changes: [0, 1], not latest', - function() { - expect(scmData).eql({ - rev: mercurialRevs[1], - changes: mercurialRevs.slice(0, 2).reverse(), - isLatest: false + _(['second revision', /^second revision$/]).each(function(tag) { + + describe('with scm rev default and catch tag ' + tag, function() { + before(clearWorkspace); + + it('instance should be created without errors', function() { + executor = createExecutor(makeExecutorParams({ + project: { + catchRev: {tag: tag} + } + })); + }); + + it('should run without errors', function(done) { + executor.run({}, function(err) { + expect(err).not.ok(); + done(); + }); + executor.on('scmData', function(data) { + scmData = data; }); }); - it('should run it again without errors', function(done) { - executor.run({}, done); - }); - - it( - 'scm data should be rev: last, changes: [2-last], is latest', - function() { - expect(scmData).eql({ - rev: mercurialRevs[mercurialRevs.length - 1], - changes: mercurialRevs.slice(2).reverse(), - isLatest: true + it('scm data should be rev: 2, changes: [0, 2], not latest', + function() { + expect(scmData).eql({ + rev: mercurialRevs[2], + changes: mercurialRevs.slice(0, 3).reverse(), + isLatest: false + }); }); - } - ); + + it('should run it again without errors', function(done) { + executor.run({}, done); + }); + + it( + 'scm data should be rev: last, changes: [3-last], is latest', + function() { + expect(scmData).eql({ + rev: mercurialRevs[mercurialRevs.length - 1], + changes: mercurialRevs.slice(3).reverse(), + isLatest: true + }); + } + ); + + }); });