mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-02-10 19:09:16 +00:00
move functions for getting recent bulds and done streak to builds collection
This commit is contained in:
parent
3858c3a0d0
commit
0c119b0d67
61
lib/build.js
61
lib/build.js
@ -132,3 +132,64 @@ BuildsCollection.prototype.getProjectAvgBuildDuration = function(params, callbac
|
||||
callback
|
||||
);
|
||||
};
|
||||
|
||||
BuildsCollection.prototype.getRecent = function(params, callback) {
|
||||
params.limit = params.limit || 20;
|
||||
var self = this;
|
||||
|
||||
Steppy(
|
||||
function() {
|
||||
var findParams = {start: {}, limit: params.limit};
|
||||
|
||||
// such condition for match one of projections:
|
||||
// projectName, descCreateDate
|
||||
// projectName, status, descCreateDate
|
||||
// or just descCreateDate projection if project name is not set
|
||||
if (params.projectName) {
|
||||
findParams.start.projectName = params.projectName;
|
||||
if (params.status) findParams.start.status = params.status;
|
||||
}
|
||||
|
||||
findParams.descCreateDate = '';
|
||||
|
||||
self.db.builds.find(findParams, this.slot());
|
||||
},
|
||||
callback
|
||||
);
|
||||
};
|
||||
|
||||
BuildsCollection.prototype.getDoneStreak = function(params, callback) {
|
||||
var self = this;
|
||||
|
||||
Steppy(
|
||||
function() {
|
||||
var start = {};
|
||||
|
||||
if (params.projectName) start.projectName = params.projectName;
|
||||
|
||||
start.descCreateDate = '';
|
||||
|
||||
// tricky but effective streak counting inside filter goes below
|
||||
var doneBuildsStreakCallback = _(this.slot()).once(),
|
||||
doneBuildsStreak = 0;
|
||||
|
||||
self.db.builds.find({
|
||||
start: start,
|
||||
filter: function(build) {
|
||||
// error exits streak
|
||||
if (build.status === 'error') {
|
||||
doneBuildsStreakCallback(null, doneBuildsStreak);
|
||||
return true;
|
||||
}
|
||||
if (build.status === 'done') {
|
||||
doneBuildsStreak++;
|
||||
}
|
||||
},
|
||||
limit: 1
|
||||
}, function(err) {
|
||||
doneBuildsStreakCallback(err, doneBuildsStreak);
|
||||
});
|
||||
},
|
||||
callback
|
||||
);
|
||||
};
|
@ -39,38 +39,13 @@ module.exports = function(app) {
|
||||
}, this.slot());
|
||||
|
||||
// get last done build
|
||||
app.builds.find({
|
||||
start: {
|
||||
projectName: project.name,
|
||||
status: 'done',
|
||||
descCreateDate: ''
|
||||
},
|
||||
app.builds.getRecent({
|
||||
projectName: project.name,
|
||||
status: 'done',
|
||||
limit: 1
|
||||
}, this.slot());
|
||||
|
||||
// tricky but effective streak counting inside filter goes below
|
||||
var doneBuildsStreakCallback = _(this.slot()).once(),
|
||||
doneBuildsStreak = 0;
|
||||
|
||||
app.builds.find({
|
||||
start: {
|
||||
projectName: project.name,
|
||||
descCreateDate: ''
|
||||
},
|
||||
filter: function(build) {
|
||||
// error exits streak
|
||||
if (build.status === 'error') {
|
||||
doneBuildsStreakCallback(null, doneBuildsStreak);
|
||||
return true;
|
||||
}
|
||||
if (build.status === 'done') {
|
||||
doneBuildsStreak++;
|
||||
}
|
||||
},
|
||||
limit: 1
|
||||
}, function(err) {
|
||||
doneBuildsStreakCallback(err, doneBuildsStreak);
|
||||
});
|
||||
app.builds.getDoneStreak({projectName: project.name}, this.slot());
|
||||
},
|
||||
function(err, avgProjectBuildDuration, lastDoneBuilds, doneBuildsStreak) {
|
||||
project.lastDoneBuild = lastDoneBuilds[0];
|
||||
|
Loading…
Reference in New Issue
Block a user