Skip to content

Commit

Permalink
use the new external api for cordonbleu to get the activity instead of
Browse files Browse the repository at this point in the history
creating a connection between quality dashboard and mongodb
  • Loading branch information
Gotier committed Jan 17, 2018
1 parent 72f4b4b commit 8f6105e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 192 deletions.
21 changes: 9 additions & 12 deletions front/assets/js/core/plugin/CordonBleuInfo.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class CordonBleuInfo extends GetAndFillInfo {

}


getResult(msg) {
return msg[0];
}
Expand All @@ -47,10 +46,8 @@ class CordonBleuInfo extends GetAndFillInfo {
}

fillInfo(info) {
let result = info[0];

let templateCodeReview = $("#templateCodeReview").clone();
templateCodeReview.find("div:first").attr("id", "codereview-" + result.team.toLowerCase());
templateCodeReview.find("div:first").attr("id", "codereview-" + info.team.toLowerCase());
templateCodeReview.find("div:first").css("padding-bottom","20px");

$("#codeReviewContent").append(templateCodeReview.html());
Expand All @@ -61,15 +58,15 @@ class CordonBleuInfo extends GetAndFillInfo {

$("#dateLegendCodeReview").text("Between " + Utils.formatDate(this.beginDate) + " and " + Utils.formatDate(this.endDate));

$(this.selecter.replace("?","commitNumber")).text(result.nbCommitThisWeek);
$(this.selecter.replace("?","approveCommitNumber")).text(result.nbCommitApprove);
$(this.selecter.replace("?","commentCommitNumber")).text(result.nbCommitComment);
$(this.selecter.replace("?","reviewCommitNumber")).text(result.nbCommitThisWeek-result.nbCommitWithoutReview);
$(this.selecter.replace("?","commitNumber")).text(info.nbCommitThisWeek);
$(this.selecter.replace("?","approveCommitNumber")).text(info.nbCommitApprove);
$(this.selecter.replace("?","commentCommitNumber")).text(info.nbCommitComment);
$(this.selecter.replace("?","reviewCommitNumber")).text(info.nbCommitThisWeek-info.nbCommitWithoutReview);

Utils.modifyChartOneValue(this.selecter.replace("?","chartCodeReview"), result.ratioCommitReview);
$(this.selecter.replace("?","smileyCodeReview")).addClass(Utils.getSmiley(result.ratioCommitReview, 100,50));
$(this.selecter.replace("?","seemore")).attr("href",codeReviewUrl+"/team/" + result.team);
$(this.selecter.replace("?","name")).text(result.team);
Utils.modifyChartOneValue(this.selecter.replace("?","chartCodeReview"), info.ratioCommitReview);
$(this.selecter.replace("?","smileyCodeReview")).addClass(Utils.getSmiley(info.ratioCommitReview, 100,50));
$(this.selecter.replace("?","seemore")).attr("href",codeReviewUrl+"/team/" + info.team);
$(this.selecter.replace("?","name")).text(info.team);
}

}
Expand Down
3 changes: 1 addition & 2 deletions server/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"name": "server",
"version": "1.2.1",
"version": "1.3.0",
"main": "server.js",
"dependencies": {
"async": "^2.6.0",
"exec": "^0.2.1",
"express": "^4.16.2",
"jenkins-api": "^0.3.1",
"mongodb": "^2.2.33",
"nodemon": "^1.12.1",
"request": "^2.83.0"
},
Expand Down
53 changes: 0 additions & 53 deletions server/reportCordonbleuJson.sh

This file was deleted.

162 changes: 37 additions & 125 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ var app = express();
var fs = require("fs");
var exec = require('exec');
var async = require('async');
var MongoClient = require("mongodb").MongoClient;
var jenkinsapi = require('jenkins-api');



// get verion
var pjson = require('./package.json');
console.log("Application QualityDashboard is in %s version", pjson.version);
Expand Down Expand Up @@ -143,13 +140,6 @@ app.get("/jenkinsDeployInfo", function (req, res) {
resRequest.on('end', function (body) {
var jsonData = JSON.parse(data);
var jenkinsBuilds = jsonData.builds;

// http.request(options, function(resRequest) {
// resRequest.setEncoding('utf8');
// resRequest.on('data', function (body) {
//
// var jsonData = JSON.parse(body);
// var jenkinsBuilds = jsonData.builds;
var cpt = 0;

for (var i = 0, len = jenkinsBuilds.length; i < len; ++i) {
Expand Down Expand Up @@ -239,122 +229,44 @@ app.get("/codeReviewStats", function (req, res) {
let endDate = req.query['endDate'];
let callback = req.query['callback'];

getInfoCordonBleu(function (infoCordonBleu) {

let result = infoCordonBleu;
if(callback != null) {
result = callback + "([" + JSON.stringify(infoCordonBleu) + "])";
}
res.end(result);
},team,beginDate,endDate, callback);

})

function SortByName(a, b){
var aName = a.toLowerCase();
var bName = b.toLowerCase();
return ((aName < bName) ? -1 : ((aName > bName) ? 1 : 0));
}

// le semaphore permet de savoir quand les toutes les requêtes mongo attendu sont terminées
// 1 semaphore par callback, donc un tableau du genre semaphore[callback] = <int>
var semaphore = [];
function getInfoCordonBleu(callback, team, dateDebutStr, dateFinStr, callbackName) {

let databaseConnectStr = "";
let options = {
host: applicationConf.cordonBleu.host,
port: applicationConf.cordonBleu.port,
path: "/api/activity/public?name=" + team + '&begin=' + beginDate + '&end=' + endDate,
method: 'GET'
};

if (applicationConf.cordonBleu.database_user != undefined && applicationConf.cordonBleu.database_user != ""
&& applicationConf.cordonBleu.database_password != undefined && applicationConf.cordonBleu.database_password != "") {
databaseConnectStr = "mongodb://" + applicationConf.cordonBleu.database_user + ":" + applicationConf.cordonBleu.database_password
+ "@" + applicationConf.cordonBleu.database_host + "/" + applicationConf.cordonBleu.database_name;
} else {
databaseConnectStr = "mongodb://" + applicationConf.cordonBleu.database_host + "/" + applicationConf.cordonBleu.database_name;
}

MongoClient.connect(databaseConnectStr, {poolSize: 10}, function(error, db) {
if (error) {
console.log(error);
}

let dateDebut=new Date(dateDebutStr);
let dateFin=new Date(dateFinStr);
// include current date, set to last second of the day
dateFin = new Date(dateFin.getFullYear(), dateFin.getMonth(), dateFin.getDate(), 23, 59, 59);

let teams;

if(team == null || team == undefined || team == "") {
teams = db.collection("team").find({},{_id:1, name:1});
} else {
teams = db.collection("team").find({"name.unique" : team.toLowerCase()},{_id:1, name:1});
}

let cpt = 0;
let cordonBleuInfos = new Array();

semaphore[callbackName]=1;

teams.count(function (errorTeaemsCount, teamsSize) {
teams.forEach(function (team) {
let cordonBleuInfo = new Object();
cordonBleuInfo.team=team.name.value;
cordonBleuInfos.push(cordonBleuInfo);

var re = "/^/i";

semaphore[callbackName]++;


db.collection("commit").find({ "_id.team" : team._id, "created": { $gt : dateDebut, $lt : dateFin }}).count(function (e, count) {
cordonBleuInfo.nbCommitThisWeek=count;
semaphore[callbackName]--;
});

semaphore[callbackName]++;
var nbCommitApprove = db.collection("commit").find({ "_id.team": team._id, "created": { $gt : dateDebut, $lt : dateFin}, approval : {$ne: null}}).count(function (e, count) {
cordonBleuInfo.nbCommitApprove=count;
semaphore[callbackName]--;
});

semaphore[callbackName]++;
var nbCommitComment = db.collection("commit").find({ "_id.team": team._id, "created": { $gt : dateDebut, $lt : dateFin }, comments : {$gt: []}}).count(function (e, count) {
cordonBleuInfo.nbCommitComment=count;
semaphore[callbackName]--;
});

semaphore[callbackName]++;
var nbCommitWithoutReview = db.collection("commit").find({ "_id.team": team._id, "created": { $gt : dateDebut, $lt : dateFin }, approval : null, comments : []}).count(function (e, count) {
cordonBleuInfo.nbCommitWithoutReview=count;
semaphore[callbackName]--;
});

// final condition
if(cpt === teamsSize-1) {
semaphore[callbackName]--;

wait_until_semaphore( function(){

cordonBleuInfos.forEach(function(cbi) {
if(cbi.nbCommitThisWeek==0) cbi.ratioCommitReview=100;
else cbi.ratioCommitReview = Math.round((((cbi.nbCommitThisWeek - cbi.nbCommitWithoutReview) / cbi.nbCommitThisWeek)*1000))/10.0;
}, callback);

callback(cordonBleuInfos);
}, callbackName);
}

cpt=cpt+1;
});
http.request(options, function(resRequest) {
resRequest.setEncoding('utf8');
var data = '';

resRequest.on('data', function (chunk){
data += chunk;
});
});
}

resRequest.on('end',function(){
var obj = JSON.parse(data);

let infoCordonBleu = new Object();
infoCordonBleu.team=team;
infoCordonBleu.nbCommitThisWeek=obj.nbCommit;
infoCordonBleu.nbCommitApprove=obj.nbCommitApproved;
infoCordonBleu.nbCommitComment=obj.nbCommitWithComments;
infoCordonBleu.nbCommitWithoutReview=obj.nbCommitWithoutReview;

if(obj.nbCommit==0) {
infoCordonBleu.ratioCommitReview=100;
} else {
infoCordonBleu.ratioCommitReview = Math.round(((infoCordonBleu.nbCommitThisWeek - infoCordonBleu.nbCommitWithoutReview) / infoCordonBleu.nbCommitThisWeek)*100);
}

function wait_until_semaphore(callback, callbackName) {
console.log("wait semaphore : " + semaphore[callbackName]);
if (semaphore[callbackName]==0) {
callback();
} else {
setTimeout(function(){wait_until_semaphore(callback, callbackName)},1000);
}
}
let result = "([" + JSON.stringify(infoCordonBleu) + "])";
if(callback != null) {
result = callback + "([" + JSON.stringify(infoCordonBleu) + "])";
}

res.end(result);
});

}).end();
})

0 comments on commit 8f6105e

Please sign in to comment.