diff --git a/front/assets/js/core/plugin/CordonBleuInfo.class.js b/front/assets/js/core/plugin/CordonBleuInfo.class.js index 9f2cddf..2affee9 100644 --- a/front/assets/js/core/plugin/CordonBleuInfo.class.js +++ b/front/assets/js/core/plugin/CordonBleuInfo.class.js @@ -30,7 +30,6 @@ class CordonBleuInfo extends GetAndFillInfo { } - getResult(msg) { return msg[0]; } @@ -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()); @@ -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); } } diff --git a/server/package.json b/server/package.json index 5371cb5..e0311d6 100644 --- a/server/package.json +++ b/server/package.json @@ -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" }, diff --git a/server/reportCordonbleuJson.sh b/server/reportCordonbleuJson.sh deleted file mode 100755 index b042387..0000000 --- a/server/reportCordonbleuJson.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash - -begin_date=$1; -end_date=$2; -team=$3 - - -mongo cordonbleu --eval 'var printStats = function(db, team, dateDebut, dateFin, users) { - var teams;print(team); - if(team == null || team == undefined || team == "") { - teams = db.team.find({},{_id:1, name:1}); - } else { - teams = db.team.find({"name.unique" : team.toLowerCase()},{_id:1, name:1}); - } - print("{\"projects\":["); - - var cpt = 0; - teams.forEach(function (team) { - if(cpt > 0) { - print(","); - } - - print("{\"team\":\"" + team.name.value+"\","); - - var re = users; - - var nbCommitThisWeek = db.commit.find({ "_id.team" : team._id, "created": { $gt : ISODate(dateDebut), $lt : ISODate(dateFin) }, "author.name" : {$regex :eval(re)} }).count(); - print("\"commitNumber\" : " + nbCommitThisWeek + ","); - - var nbCommitApprove = db.commit.find({ "_id.team": team._id, "created": { $gt : ISODate(dateDebut), $lt : ISODate(dateFin) }, approval : {$ne: null}, "author.name" : {$regex :eval(re)}}).count(); - print("\"approveCommitNumber\" : " + nbCommitApprove + ","); - - var nbCommitComment = db.commit.find({ "_id.team": team._id, "created": { $gt : ISODate(dateDebut), $lt : ISODate(dateFin) }, comments : {$gt: []}, "author.name" : {$regex :eval(re)} }).count(); - print("\"commentCommitNumber\" : " + nbCommitComment + ","); - - var nbCommitWithoutReview = db.commit.find({ "_id.team": team._id, "created": { $gt : ISODate(dateDebut), $lt : ISODate(dateFin) }, approval : null, comments : [], "author.name" : {$regex :eval(re)}}).count(); - print("\"notReviewCommitNumber\" : " + nbCommitWithoutReview+ ","); - var nbCommitProposeToCollectiveReview = db.commit.find({ "_id.team": team._id, "created": { $gt : ISODate(dateDebut), $lt : ISODate(dateFin) }, proposeToCollectiveReview : true}).count(); - - print("\"ratioCommitReview\" : " + (nbCommitThisWeek === 0 ? "100" : Math.ceil(((nbCommitThisWeek-nbCommitWithoutReview)/nbCommitThisWeek) * 100)) + ""); - - print("}"); - - cpt=cpt+1; - }); - print("]}"); -}; - -printStats(db, "'$team'", "'+$begin_date+'T00:00:00Z", "'+$end_date+'T23:59:59Z", "/^/i"); -' - - - diff --git a/server/server.js b/server/server.js index 0abf627..6a14235 100644 --- a/server/server.js +++ b/server/server.js @@ -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); @@ -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) { @@ -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] = -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(); +})