Skip to content

Commit 0461f99

Browse files
authored
Merge pull request #1702 from AdityaSrikanth/topic-performance
C50-576 - When multiple github accounts are configured, the last successful sync account should be made default.
2 parents d8bd3cf + 48c52a1 commit 0461f99

File tree

13 files changed

+440
-244
lines changed

13 files changed

+440
-244
lines changed

client/cat3/src/partials/sections/dashboard/bots/controller/libraryCtrl.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,17 @@
247247
if($scope.failedBotsselected)
248248
var param={
249249
inlineLoader:true,
250-
url:'/audit-trail?startdate='+ $scope.ticketsResolveStartsOn+ '&enddate='+ $scope.ticketsResolveEndsOn +'&page=' + $scope.botServiceNowLibGridOptions.paginationCurrentPage +'&pageSize=' + $scope.paginationParams.pageSize +'&sortBy=' + $scope.paginationParams.sortBy +'&sortOrder=' + $scope.paginationParams.sortOrder + '&filterBy=actionStatus:failed'
250+
url:'/audit-trail?startdate='+ $scope.ticketsResolveStartsOn+ '&enddate='+ $scope.ticketsResolveEndsOn +'&page=' + $scope.botServiceNowLibGridOptions.paginationCurrentPage +'&pageSize=' + $scope.paginationParams.pageSize +'&sortBy=' + $scope.paginationParams.sortBy +'&sortOrder=' + $scope.paginationParams.sortOrder + '&filterBy=actionStatus:failed' + '&auditForDashboard=true'
251251
};
252252
else if($scope.scheduledBotsSelected)
253253
var param={
254254
inlineLoader:true,
255-
url:'/audit-trail?startdate='+ $scope.ticketsResolveStartsOn+ '&enddate='+ $scope.ticketsResolveEndsOn +'&filterBy=actionStatus:success&page=' + $scope.paginationParams.page +'&pageSize=' + $scope.paginationParams.pageSize +'&sortBy=startedOn&sortOrder=' + $scope.paginationParams.sortOrder+'&type=snow'
255+
url:'/audit-trail?startdate='+ $scope.ticketsResolveStartsOn+ '&enddate='+ $scope.ticketsResolveEndsOn +'&filterBy=actionStatus:success&page=' + $scope.paginationParams.page +'&pageSize=' + $scope.paginationParams.pageSize +'&sortBy=startedOn&sortOrder=' + $scope.paginationParams.sortOrder+'&type=snow' + '&auditForDashboard=true'
256256
};
257257
else if($scope.runningBotsselected)
258258
var param={
259259
inlineLoader:true,
260-
url:'/audit-trail?startdate='+ $scope.ticketsResolveStartsOn+ '&enddate='+ $scope.ticketsResolveEndsOn +'&page=' + $scope.botServiceNowLibGridOptions.paginationCurrentPage +'&pageSize=' + $scope.paginationParams.pageSize +'&sortBy=startedOn&sortOrder=' + $scope.paginationParams.sortOrder
260+
url:'/audit-trail?startdate='+ $scope.ticketsResolveStartsOn+ '&enddate='+ $scope.ticketsResolveEndsOn +'&page=' + $scope.botServiceNowLibGridOptions.paginationCurrentPage +'&pageSize=' + $scope.paginationParams.pageSize +'&sortBy=startedOn&sortOrder=' + $scope.paginationParams.sortOrder + '&auditForDashboard=true'
261261
};
262262

263263
$scope.dataTransform(param);
@@ -333,6 +333,23 @@
333333
$scope.errorMessage = "No Records found";
334334
});
335335
$scope.isBotDetailsLoading = false;
336+
var param = {
337+
inlineLoader: true,
338+
url: '/git-hub'
339+
};
340+
genSevs.promiseGet(param).then(function (result) {
341+
$scope.pageLoadBot=false;
342+
for(var i=0;i<result.data.length;i++){
343+
if(result && result.data[i].isDefault == true){
344+
$scope.gitHubRepoName = result.data[i].repositoryName;
345+
}
346+
}
347+
}, function (error) {
348+
$scope.pageLoadBot=false;
349+
toastr.error(error);
350+
$scope.errorMessage = "No Records found";
351+
});
352+
$scope.isBotDetailsLoading = false;
336353
}
337354
$scope.botLibraryGridView = function () {
338355
$rootScope.onBodyLoading = false;

client/cat3/src/partials/sections/dashboard/bots/view/library.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
<loading size="large" name="pageLoadBot" type="block" align="center"></loading>
33
<div id="botLibraryPage" ng-show="!pageLoadBot">
44
<div class="page-name">
5-
BOTs Library&nbsp;
6-
<!--<span class="label label-warning"><small>Time Saved: </small>{{botSummary.totalSavedTimeForBots.days ? botSummary.totalSavedTimeForBots.days:0}}d {{botSummary.totalSavedTimeForBots.hours ? botSummary.totalSavedTimeForBots.hours : 0}}h {{botSummary.totalSavedTimeForBots.minutes ? botSummary.totalSavedTimeForBots.minutes : 0}}m</span>-->
5+
BOTs Library : {{gitHubRepoName}} &nbsp;
6+
7+
<!--<span class="label label-warning"><small>Time Saved: </small>{{botSummary.totalSavedTimeForBots.days ? botSummary.totalSavedTimeForBots.days:0}}d {{botSummary.totalSavedTimeForBots.hours ? botSummary.totalSavedTimeForBots.hours : 0}}h {{botSummary.totalSavedTimeForBots.minutes ? botSummary.totalSavedTimeForBots.minutes : 0}}m</span>-->
78
<span class="pull-right">
89
<button type="button" title="Refresh" class="btn btn-xs cat-btn-update pull-right refresh-btn" ng-click="RefreshBotsLibrary();">
910
<i class="fa fa-refresh white"></i>
@@ -316,7 +317,7 @@ <h4 class="margintop-2"><small>{{statusBar}}</small></h4>
316317
ng-show="noShowForServiceNow">
317318
<div class="alert alert-info text-center no-data"
318319
ng-if="!botLibGridOptions.data.length > 0 && !isBotLibraryPageLoading">
319-
No data Available
320+
No BOTs available. Check if your BOT repository is synchronised
320321
</div>
321322
<div id="grid1"
322323
ng-show="!isCardViewActive"

client/htmls/private/ajax/Settings/githubList.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ <h5 class="widget-title widgetColor">
4040
<tbody id="githubInput">
4141
</tbody>
4242
</table>
43+
<h5 style="font-size: 12px;color: blue;">* This repository was successfully synchronised and BOTs from this repository are currently available to use.</h5>
4344
</div>
4445
</div>
4546
<!--widget main ends here-->

client/htmls/private/js/gitHubList.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,13 @@ function getGlobalGitServers() {
232232
return $tdAction;
233233
}
234234
}
235-
]
235+
],
236+
rowCallback: function(row, data, index){
237+
if(data.isDefault == true){
238+
$(row).find('td:eq(0)').css('color', 'blue');
239+
$(row).find('td:eq(0)').text('* '+data.repositoryName);
240+
}
241+
}
236242
} );
237243
};
238244

@@ -460,15 +466,30 @@ $('#gitCloneImport').submit(function(){
460466
$('#gitTable tbody').on( 'click', 'button.syncGitRepo', function(){
461467
$('#gitHubListLoader').show();
462468
var $this = $(this);
469+
var updateData = {
470+
"orgId":$this.parents('tr').attr('orgId'),
471+
"repositoryName":$this.parents('tr').attr('githubName'),
472+
"repositoryOwner":$this.parents('tr').attr('repositoryOwner'),
473+
"repositoryType":$this.parents('tr').attr('repositoryType'),
474+
"isDefault":"true"
475+
}
463476
$.ajax({
464477
url: '../git-hub/' + $this.parents('tr').attr('githubId') + '/sync',
465478
method: 'GET',
466479
success: function(data) {
467480
toastr.success('Successfully cloned.');
481+
$.ajax({
482+
url: '../git-hub/'+ $this.parents('tr').attr('githubId'),
483+
async:false,
484+
method: 'PUT',
485+
data: updateData,
486+
success: function(data) {
487+
getGlobalGitServers();
488+
}
489+
});
468490
$('#gitHubListLoader').hide();
469491
},
470492
error: function(jxhr) {
471-
console.log(jxhr);
472493
var msg = "Unable to Fetch GitRepo please try again later";
473494
if (jxhr.responseJSON && jxhr.responseJSON.message) {
474495
msg = jxhr.responseJSON.message;

server/app/engine/bots/scriptExecutor.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ scriptExecutor.execute = function execute(botsDetails,auditTrail,userName,execut
8383
botID: botDetails.id,
8484
user: userName,
8585
date: startHour,
86+
gitHubId: botDetails.gitHubId
8687
}, { $inc: { "failedCount": 1, "runningCount": -1} }, function (err, data) {
8788
if(err) logger.error(JSON.stringify(err))
8889
else logger.info("Running count of bot ", botDetails[0].name, "incremented successfully")
@@ -259,6 +260,7 @@ function executeScriptOnLocal(botsScriptDetails,auditTrail,userName,botHostDetai
259260
botID: botsScriptDetails.id,
260261
user: userName,
261262
date: startHour,
263+
gitHubId: botsScriptDetails.gitHubId
262264
}, { $inc: { "failedCount": 1, "runningCount": -1} }, function (err, data) {
263265
if(err) logger.error(JSON.stringify(err))
264266
else logger.info("Running count of bot ", botDetails[0].name, "incremented successfully")
@@ -321,6 +323,7 @@ function executeScriptOnLocal(botsScriptDetails,auditTrail,userName,botHostDetai
321323
botID: botsScriptDetails.id,
322324
user: userName,
323325
date: startHour,
326+
gitHubId: botsScriptDetails.gitHubId
324327
}, { $inc: { "failedCount": 1, "runningCount": -1} }, function (err, data) {
325328
if(err) logger.error(JSON.stringify(err))
326329
else logger.info("Running count of bot ", botsScriptDetails[0].name, "incremented successfully")
@@ -473,6 +476,7 @@ function executeScriptOnRemote(instance,botDetails,actionLogId,auditTrailId,user
473476
botID: botDetails.id,
474477
user: userName,
475478
date: startHour,
479+
gitHubId: botDetails.gitHubId
476480
}, { $inc: { "failedCount": 1, "runningCount": -1} }, function (err, data) {
477481
if(err) logger.error(JSON.stringify(err))
478482
else logger.info("Running count of bot ", botDetails[0].name, "incremented successfully")
@@ -548,6 +552,7 @@ function executeScriptOnRemote(instance,botDetails,actionLogId,auditTrailId,user
548552
botID: botDetails.id,
549553
user: userName,
550554
date: startHour,
555+
gitHubId: botDetails.gitHubId
551556
}, { $inc: { "failedCount": 1, "runningCount": -1} }, function (err, data) {
552557
if(err) logger.error(JSON.stringify(err))
553558
else logger.info("Running count of bot ", botDetails[0].name, "incremented successfully")

server/app/model/audit-trail/base-audit-trail.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ var AuditTrailSchema = function AuditTrail() {
125125
isDeleted: {
126126
type: Boolean,
127127
default:false
128+
},
129+
gitHubId: {
130+
type: String,
131+
required:true
128132
}
129133
});
130134
};

server/app/model/audit-trail/bot-audit-trail-summary.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ var BotAuditTrailSummarySchema= new Schema ({
5050
type: Number,
5151
default: 0
5252
},
53+
gitHubId: {
54+
type: String,
55+
required: true
56+
}
5357
})
5458

5559
BotAuditTrailSummarySchema.index({ user: 1, botID: 1, date:1}, { unique: true });

server/app/model/github/github.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ var GitHubSchema = new Schema({
9494
type: Number,
9595
required: false,
9696
default:Date.now()
97+
},
98+
isDefault:{
99+
type: Boolean,
100+
required: false,
101+
default:false
97102
}
98103
});
99104

@@ -120,6 +125,8 @@ GitHubSchema.statics.getGitHubList = function (params, callback) {
120125
error.status = 500;
121126
return callback(error);
122127
}
128+
params.options.sort = {};
129+
params.options.sort.isDefault = -1;
123130
GitHub.aggregate([
124131
{$match: params.queryObj},
125132
{
@@ -220,5 +227,19 @@ GitHubSchema.statics.getGitRepository = function (query,field, callback) {
220227
}
221228
);
222229
};
230+
GitHubSchema.statics.updateDefaultGitHub = function (gitHubIdQuery, fields, callback) {
231+
this.update(gitHubIdQuery, {$set: fields},{multi: true},
232+
function (err, result) {
233+
if (err) {
234+
logger.error(err);
235+
return callback(err, null);
236+
} else if ((result.ok === 1 && result.n == 1)) {
237+
return callback(null, true);
238+
} else {
239+
return callback(null, null);
240+
}
241+
}
242+
);
243+
};
223244
var GitHub = mongoose.model('github', GitHubSchema);
224245
module.exports = GitHub;

server/app/routes/v1.0/routes_audit_trails.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module.exports.setRoutes = function(app, sessionVerificationFunc) {
9292
logger.info('Entered - bots-summary')
9393
//Enabling session caching for summary data.
9494
if(req.session.botcache){
95-
if(moment().diff(req.session.botcache.lastrequestdate,'minutes') < 5){
95+
if(moment().diff(req.session.botcache.lastrequestdate,'minutes') < 2){
9696
//read from cache if query matches
9797
if(JSON.stringify(req.session.botcache.lastquery) === JSON.stringify(req.query) && req.session.botcache.botSummary){
9898
logger.info('Serving from cache..last request was sooner ');
@@ -117,12 +117,13 @@ module.exports.setRoutes = function(app, sessionVerificationFunc) {
117117
req.session.botcache.botSummary = botSummary;
118118

119119
}
120-
else
120+
else{
121121
botSummary.lastrequestdate = new Date();
122-
req.session.botcache = {
122+
req.session.botcache = {
123123
lastrequestdate : moment(),
124124
lastquery : req.query,
125125
botSummary : botSummary
126+
}
126127
}
127128
return res.status(200).send(botSummary);
128129
})

server/app/routes/v1.0/routes_github.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
var gitHubService = require('_pr/services/gitHubService');
1414
var noticeService = require('_pr/services/noticeService');
1515
var async = require('async');
16+
var gitHubModel = require('_pr/model/github/github.js');
1617
var validate = require('express-validation');
1718
var gitHubValidator = require('_pr/validators/gitHubValidator');
19+
var ObjectId = require('mongoose').Types.ObjectId;
1820

1921
module.exports.setRoutes = function(app, sessionVerificationFunc) {
2022

@@ -251,7 +253,21 @@ module.exports.setRoutes = function(app, sessionVerificationFunc) {
251253
if (err) {
252254
res.status(err.status).send(err);
253255
} else {
254-
return res.status(200).send(results);
256+
delete req.session.botcache;
257+
var query = {
258+
"_id" : {'$nin':[ObjectId(req.params.gitHubId)]}
259+
};
260+
var fields = {
261+
'isDefault' : false
262+
};
263+
gitHubModel.updateDefaultGitHub(query, fields, (err, resGithb) => {
264+
if (!err) {
265+
return res.status(200).send(resGithb);
266+
}
267+
else {
268+
logger.error("Error in getting GITHUB details "+err);
269+
}
270+
});
255271
}
256272
}
257273
);
@@ -550,6 +566,7 @@ module.exports.setRoutes = function(app, sessionVerificationFunc) {
550566
app.delete('/git-hub/:gitHubId', deleteGitHub);
551567

552568
function deleteGitHub(req, res) {
569+
delete req.session.botcache;
553570
async.waterfall(
554571
[
555572
function(next) {

0 commit comments

Comments
 (0)