count total commits in repo

This commit is contained in:
Usman Nasir
2020-03-10 12:49:35 +05:00
parent ca9c4ff966
commit e5ad9b5a98
5 changed files with 168 additions and 5 deletions

View File

@@ -5790,6 +5790,7 @@ app.controller('installMagentoCTRL', function ($scope, $http, $timeout) {
app.controller('manageGIT', function ($scope, $http, $timeout, $window) { app.controller('manageGIT', function ($scope, $http, $timeout, $window) {
$scope.cyberpanelLoading = true; $scope.cyberpanelLoading = true;
$scope.loadingSticks = true;
$scope.gitTracking = true; $scope.gitTracking = true;
$scope.gitEnable = true; $scope.gitEnable = true;
@@ -5827,6 +5828,7 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) {
$scope.deploymentKey = response.data.deploymentKey; $scope.deploymentKey = response.data.deploymentKey;
$scope.remote = response.data.remote; $scope.remote = response.data.remote;
$scope.remoteResult = response.data.remoteResult; $scope.remoteResult = response.data.remoteResult;
$scope.totalCommits = response.data.totalCommits;
} else { } else {
$scope.gitTracking = false; $scope.gitTracking = false;
$scope.gitEnable = true; $scope.gitEnable = true;
@@ -5967,6 +5969,66 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) {
}; };
$scope.changeBranch = function () {
$scope.loadingSticks = false;
$("#showStatus").modal();
url = "/websites/changeGitBranch";
var data = {
domain: $("#domain").text(),
folder: $scope.folder,
branchName: $scope.branchName
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.loadingSticks = true;
if (response.data.status === 1) {
new PNotify({
title: 'Success',
text: 'Changes applied.',
type: 'success'
});
$scope.commandStatus = response.data.commandStatus;
$timeout(function () {
$window.location.reload();
}, 3000);
} else {
new PNotify({
title: 'Operation Failed!',
text: response.data.error_message,
type: 'error'
});
$scope.commandStatus = response.data.commandStatus;
}
}
function cantLoadInitialDatas(response) {
$scope.loadingSticks = true;
new PNotify({
title: 'Operation Failed!',
text: 'Could not connect to server, please refresh this page.',
type: 'error'
});
}
};
function getCreationStatus() { function getCreationStatus() {
url = "/websites/installWordpressStatus"; url = "/websites/installWordpressStatus";

View File

@@ -43,18 +43,21 @@
<table ng-hide="gitEnable" style="margin-top: 2%" class="table"> <table ng-hide="gitEnable" style="margin-top: 2%" class="table">
<thead> <thead>
<tr> <tr>
<th>Total Commits</th>
<th>Branch</th> <th>Branch</th>
<th>Remote</th> <th>Remote</th>
<th>Status</th>
<th>Manage</th> <th>Manage</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>{$ totalCommits $}</td>
<td> <td>
<select ng-change="fetchFolderDetails()" ng-model="branchName" class="form-control"> <select ng-change="changeBranch()" ng-model="branchName" class="form-control">
<option ng-repeat="branch in branches track by $index">{$ branch $}</option> <option ng-repeat="branch in branches track by $index">{$ branch $}</option>
</select></td> </select>
</td>
<td> <td>
<button data-toggle="modal" data-target="#settings" style="margin-left: 2%" <button data-toggle="modal" data-target="#settings" style="margin-left: 2%"
@@ -177,10 +180,51 @@
</td> </td>
<td></td> <td></td>
<td></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<div id="showStatus" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-body">
<form name="containerSettingsForm" action="/" class="form-horizontal">
<div ng-hide="loadingSticks" class="form-group">
<div class="col-sm-12">
<div class="loading-stick">
<div class="stick bg-azure"></div>
<div class="stick bg-azure"></div>
<div class="stick bg-azure"></div>
<div class="stick bg-azure"></div>
<div class="stick bg-azure"></div>
<div class="stick bg-azure"></div>
<div class="stick bg-azure"></div>
<div class="stick bg-azure"></div>
<div class="stick bg-azure"></div>
<div class="stick bg-azure"></div>
<h1>Pleas wait...</h1>
</div>
</div>
</div>
<hr>
<div class="form-group">
<div class="col-sm-12">
<textarea rows="3"
class="form-control">{$ commandStatus $}</textarea>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -123,6 +123,7 @@ urlpatterns = [
url(r'^fetchFolderDetails$', views.fetchFolderDetails, name='fetchFolderDetails'), url(r'^fetchFolderDetails$', views.fetchFolderDetails, name='fetchFolderDetails'),
url(r'^initRepo$', views.initRepo, name='initRepo'), url(r'^initRepo$', views.initRepo, name='initRepo'),
url(r'^setupRemote$', views.setupRemote, name='setupRemote'), url(r'^setupRemote$', views.setupRemote, name='setupRemote'),
url(r'^changeGitBranch$', views.changeGitBranch, name='changeGitBranch'),
## Catch all for domains ## Catch all for domains
url(r'^(?P<domain>(.*))/(?P<childDomain>(.*))$', views.launchChild, name='launchChild'), url(r'^(?P<domain>(.*))/(?P<childDomain>(.*))$', views.launchChild, name='launchChild'),
url(r'^(?P<domain>(.*))$', views.domain, name='domain'), url(r'^(?P<domain>(.*))$', views.domain, name='domain'),

View File

@@ -747,5 +747,13 @@ def setupRemote(request):
userID = request.session['userID'] userID = request.session['userID']
wm = WebsiteManager() wm = WebsiteManager()
return wm.setupRemote(userID, json.loads(request.body)) return wm.setupRemote(userID, json.loads(request.body))
except KeyError:
return redirect(loadLoginPage)
def changeGitBranch(request):
try:
userID = request.session['userID']
wm = WebsiteManager()
return wm.changeGitBranch(userID, json.loads(request.body))
except KeyError: except KeyError:
return redirect(loadLoginPage) return redirect(loadLoginPage)

View File

@@ -2992,7 +2992,16 @@ StrictHostKeyChecking no
remote = 0 remote = 0
remoteResult = 'Remote currently not set.' remoteResult = 'Remote currently not set.'
data_ret = {'status': 1, 'repo': 1, 'finalBranches': branches, 'deploymentKey': deploymentKey, 'remote': remote, 'remoteResult': remoteResult} ## Find Total commits on current branch
command = 'git -C %s rev-list --count HEAD' % (self.folder)
totalCommits = ProcessUtilities.outputExecutioner(command)
if totalCommits.find('fatal') > -1:
totalCommits = '0'
data_ret = {'status': 1, 'repo': 1, 'finalBranches': branches, 'deploymentKey': deploymentKey,
'remote': remote, 'remoteResult': remoteResult, 'totalCommits': totalCommits}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
@@ -3092,3 +3101,42 @@ StrictHostKeyChecking no
data_ret = {'status': 0, 'installStatus': 0, 'error_message': str(msg)} data_ret = {'status': 0, 'installStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
def changeGitBranch(self, userID=None, data=None):
try:
currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID)
self.domain = data['domain']
self.folder = data['folder']
self.branchName = data['branchName']
if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1:
pass
else:
return ACLManager.loadErrorJson('status', 0)
if self.folderCheck():
pass
else:
return ACLManager.loadErrorJson()
## Check if remote exists
command = 'git -C %s checkout %s' % (self.folder, self.branchName.strip(' '))
commandStatus = ProcessUtilities.outputExecutioner(command)
if commandStatus.find('Switched to branch') > -1:
data_ret = {'status': 1, 'commandStatus': commandStatus + 'Refreshing page in 3 seconds..'}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
else:
data_ret = {'status': 0, 'error_message': 'Failed to change branch', 'commandStatus': commandStatus}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException as msg:
data_ret = {'status': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)