introduce build numbers

This commit is contained in:
oleg 2015-05-17 13:26:28 +03:00
parent ba62e2d7b4
commit 40338bb654
5 changed files with 71 additions and 28 deletions

View File

@ -17,7 +17,7 @@ work in progress...
* Awesome build output (very close to terminal)
* Ability to change build parameters from ui (at least target branch)
* Semantic versioning and plugins
* Safe id and build numbers generation
## Roadmap

79
db.js
View File

@ -12,23 +12,73 @@ exports.builds = new nlevel.DocsSection(ldb, 'builds', {
projections: [
{key: {createDate: 1}, value: pickId},
{key: {descCreateDate: descCreateDate, id: 1}},
{key: {project: 1, descCreateDate: descCreateDate, id: 1}}
{key: {
projectName: function(build) {
return build.project.name;
},
descCreateDate: descCreateDate,
id: 1
}}
]
});
exports.builds._beforePut = function(docs, callback) {
generateIds(this, docs, callback);
exports.builds._beforePut = function(builds, callback) {
var self = this,
build;
Steppy(
function() {
if (builds.length > 1) {
throw new Error('Build put hooks work only with single build');
}
build = builds[0];
// generate number for build
if (!build.number && build.status === 'in-progress') {
// find last build with number in the same project
self.find({
start: {projectName: build.project.name, descCreateDate: ''},
filter: function(build) {
return 'number' in build;
},
limit: 1
}, this.slot());
} else {
this.pass([]);
}
generateIds(self, builds, this.slot());
},
function(err, prevBuilds) {
var prevBuild = prevBuilds[0];
if (!build.number && build.status === 'in-progress') {
build.number = prevBuild ? prevBuild.number + 1 : 1;
}
this.pass(null);
},
callback
);
};
function generateIds(section, docs, callback) {
Steppy(
function() {
if (isAllDocsWithId(docs)) {
var isAllDocsWithId = _(docs).all(function(doc) {
return 'id' in doc;
});
if (isAllDocsWithId) {
return callback();
}
var mixedIdsError = checkForMixedIds(docs);
if (mixedIdsError) throw mixedIdsError;
var isAllDocsWithoutId = _(docs).all(function(doc) {
return 'id' in doc === false;
});
if (!isAllDocsWithoutId) {
throw new Error(
'Documents with id and without should not be mixed'
);
}
section.find({
start: {createDate: ''}, limit: 1, reverse: true
@ -48,23 +98,6 @@ function generateIds(section, docs, callback) {
);
}
function isAllDocsWithId(docs) {
return _(docs).all(function(doc) {
return 'id' in doc;
});
}
function checkForMixedIds(docs) {
var isAllWithoutId = _(docs).all(function(doc) {
return 'id' in doc === false;
});
if (!isAllWithoutId) {
return new Error(
'Documents with id and without should not be mixed'
);
}
}
function pickId(doc) {
return {id: doc.id};
}

View File

@ -96,6 +96,7 @@ Distributor.prototype._runNext = function(callback) {
Distributor.prototype._updateBuild = function(build, changes, callback) {
var self = this;
callback = callback || _.noop;
var isWithNumber = Boolean(build.number);
Steppy(
function() {
@ -109,6 +110,14 @@ Distributor.prototype._updateBuild = function(build, changes, callback) {
}
},
function() {
// if number appear after save to db then add it to changes
// TODO: might be better to generate number right there (instead
// of hooks)
if (!isWithNumber && build.number) {
changes.number = build.number;
}
// emits only after get an id (at save build)
self.emit('buildUpdate', build, changes);

View File

@ -29,7 +29,7 @@
"dependencies": {
"data.io": "0.3.0",
"jade": "1.9.2",
"nlevel": "1.0.1",
"nlevel": "1.0.2",
"node-static": "0.7.6",
"socket.io": "1.3.5",
"twostep": "0.4.1",

View File

@ -18,10 +18,11 @@ mixin statusText(build)
i.fa.fa-2x.fa-terminal(title="Rebuild")
.build_header
span #
span= build.id
span
a(href="javascript:void(0)")= build.project.name
if build.number
span
span #
span= build.number
div
if build.scm
span.build_info