From e5ad9b5a9853b65acd399ee8504c960433e2c81b Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Tue, 10 Mar 2020 12:49:35 +0500 Subject: [PATCH] count total commits in repo --- .../websiteFunctions/websiteFunctions.js | 62 +++++++++++++++++++ .../templates/websiteFunctions/manageGIT.html | 52 ++++++++++++++-- websiteFunctions/urls.py | 1 + websiteFunctions/views.py | 8 +++ websiteFunctions/website.py | 50 ++++++++++++++- 5 files changed, 168 insertions(+), 5 deletions(-) diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 509085a75..dcb72ef15 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -5790,6 +5790,7 @@ app.controller('installMagentoCTRL', function ($scope, $http, $timeout) { app.controller('manageGIT', function ($scope, $http, $timeout, $window) { $scope.cyberpanelLoading = true; + $scope.loadingSticks = true; $scope.gitTracking = true; $scope.gitEnable = true; @@ -5827,6 +5828,7 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) { $scope.deploymentKey = response.data.deploymentKey; $scope.remote = response.data.remote; $scope.remoteResult = response.data.remoteResult; + $scope.totalCommits = response.data.totalCommits; } else { $scope.gitTracking = false; $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() { url = "/websites/installWordpressStatus"; diff --git a/websiteFunctions/templates/websiteFunctions/manageGIT.html b/websiteFunctions/templates/websiteFunctions/manageGIT.html index defdfa350..886d0dfe4 100755 --- a/websiteFunctions/templates/websiteFunctions/manageGIT.html +++ b/websiteFunctions/templates/websiteFunctions/manageGIT.html @@ -43,18 +43,21 @@ + - + + + + -
Total Commits Branch RemoteStatusManage
{$ totalCommits $} - -
+ diff --git a/websiteFunctions/urls.py b/websiteFunctions/urls.py index b31ffb8b7..212c0e448 100755 --- a/websiteFunctions/urls.py +++ b/websiteFunctions/urls.py @@ -123,6 +123,7 @@ urlpatterns = [ url(r'^fetchFolderDetails$', views.fetchFolderDetails, name='fetchFolderDetails'), url(r'^initRepo$', views.initRepo, name='initRepo'), url(r'^setupRemote$', views.setupRemote, name='setupRemote'), + url(r'^changeGitBranch$', views.changeGitBranch, name='changeGitBranch'), ## Catch all for domains url(r'^(?P(.*))/(?P(.*))$', views.launchChild, name='launchChild'), url(r'^(?P(.*))$', views.domain, name='domain'), diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py index dc59d27dc..113ea683f 100755 --- a/websiteFunctions/views.py +++ b/websiteFunctions/views.py @@ -747,5 +747,13 @@ def setupRemote(request): userID = request.session['userID'] wm = WebsiteManager() 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: return redirect(loadLoginPage) \ No newline at end of file diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index 1806cd6c0..4cbdf8a38 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -2992,7 +2992,16 @@ StrictHostKeyChecking no remote = 0 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) return HttpResponse(json_data) @@ -3092,3 +3101,42 @@ StrictHostKeyChecking no data_ret = {'status': 0, 'installStatus': 0, 'error_message': str(msg)} json_data = json.dumps(data_ret) 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)