fetch git branches

This commit is contained in:
Usman Nasir
2020-03-07 23:25:58 +05:00
parent 46e2005a41
commit 0ad5a76221
4 changed files with 85 additions and 18 deletions

View File

@@ -5823,6 +5823,8 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) {
if (response.data.repo === 1) { if (response.data.repo === 1) {
$scope.gitTracking = true; $scope.gitTracking = true;
$scope.gitEnable = false; $scope.gitEnable = false;
$scope.branches = response.data.finalBranches;
$scope.deploymentKey = response.data.deploymentKey;
} else { } else {
$scope.gitTracking = false; $scope.gitTracking = false;
$scope.gitEnable = true; $scope.gitEnable = true;

View File

@@ -33,28 +33,61 @@
</div> </div>
</div> </div>
</form> </form>
<p style="margin: 2%" ng-hide="gitTracking">{% trans "This folder does not have Git tracking, click below to initiate a repository and start tracking files." %}</p> <p style="margin: 2%"
ng-hide="gitTracking">{% trans "This folder does not have Git tracking, click below to initiate a repository and start tracking files." %}</p>
<button ng-hide="gitTracking" style="margin-left: 2%" type="button" class="btn btn-primary" <button ng-hide="gitTracking" style="margin-left: 2%" type="button" class="btn btn-primary"
ng-click="initRepo()"> ng-click="initRepo()">
Init Repo Init Repo
</button> </button>
<form action="/" class="form-horizontal bordered-row">
<div class="form-group">
<div class="col-sm-12">
<table class="table">
<thead>
<tr>
<th>{% trans "Deployment Key" %}</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="form-group">
<div class="col-sm-12">
<textarea rows="5"
class="form-control">{$ deploymentKey $}</textarea>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</form>
<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>Folder</th>
<th>Remote</th>
<th>Branch</th> <th>Branch</th>
<th>Remote</th>
<th>Status</th> <th>Status</th>
<th>Manage</th> <th>Manage</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr ng-repeat="record in records | filter:logSearch"> <tr>
<td ng-bind="record.domain"></td> <td>
<td ng-bind="record.ipAddress"></td> <select ng-change="fetchFolderDetails()" ng-model="branchName" class="form-control">
<td ng-bind="record.time"></td> <option ng-repeat="branch in branches track by $index">{$ branch $}</option>
<td ng-bind="record.resource"></td> </select></td>
<td ng-bind="record.size"></td> <td></td>
<td></td>
<td></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@@ -166,7 +166,8 @@
<td> <td>
<div class="form-group"> <div class="form-group">
<div class="col-sm-12"> <div class="col-sm-12">
<textarea rows="5" class="form-control">{{ deploymentKey }}</textarea> <textarea rows="5"
class="form-control">{{ deploymentKey }}</textarea>
</div> </div>
</div> </div>
</td> </td>
@@ -177,7 +178,6 @@
</div> </div>
<!------ List of records ---------------> <!------ List of records --------------->
</form> </form>

View File

@@ -2070,7 +2070,7 @@ StrictHostKeyChecking no
command = 'mv %s /home/%s/.ssh/config' % (path, self.domain) command = 'mv %s /home/%s/.ssh/config' % (path, self.domain)
ProcessUtilities.executioner(command) ProcessUtilities.executioner(command)
command = 'sudo chown %s:%s /home/%s/.ssh/config' % (website.externalApp, website.externalApp, self.domain) command = 'chown %s:%s /home/%s/.ssh/config' % (website.externalApp, website.externalApp, self.domain)
ProcessUtilities.executioner(command) ProcessUtilities.executioner(command)
command = 'cat /home/%s/.ssh/%s.pub' % (self.domain, website.externalApp) command = 'cat /home/%s/.ssh/%s.pub' % (self.domain, website.externalApp)
@@ -2934,8 +2934,9 @@ StrictHostKeyChecking no
return ACLManager.loadErrorJson() return ACLManager.loadErrorJson()
gitPath = '%s/.git' % (self.folder) website = Websites.objects.get(domain=self.domain)
gitPath = '%s/.git' % (self.folder)
command = 'ls -la %s' % (gitPath) command = 'ls -la %s' % (gitPath)
if ProcessUtilities.outputExecutioner(command).find('No such file or directory') > -1: if ProcessUtilities.outputExecutioner(command).find('No such file or directory') > -1:
@@ -2943,7 +2944,38 @@ StrictHostKeyChecking no
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
else: else:
data_ret = {'status': 1, 'repo': 1}
## Find git branches
command = 'git --git-dir=%s/.git branch' % (self.folder)
branches = ProcessUtilities.outputExecutioner(command).split('\n')
## Fetch key
command = 'cat /home/%s/.ssh/config' % (self.domain)
if ProcessUtilities.outputExecutioner(command).find('No such file or directory') == -1:
configContent = """Host github.com
IdentityFile /home/%s/.ssh/%s
StrictHostKeyChecking no
""" % (self.domain, website.externalApp)
path = "/home/cyberpanel/config"
writeToFile = open(path, 'w')
writeToFile.writelines(configContent)
writeToFile.close()
command = 'mv %s /home/%s/.ssh/config' % (path, self.domain)
ProcessUtilities.executioner(command)
command = 'chown %s:%s /home/%s/.ssh/config' % (website.externalApp, website.externalApp, self.domain)
ProcessUtilities.executioner(command)
command = 'cat /home/%s/.ssh/%s.pub' % (self.domain, website.externalApp)
deploymentKey = ProcessUtilities.outputExecutioner(command, website.externalApp)
data_ret = {'status': 1, 'repo': 1, 'finalBranches': branches, 'deploymentKey': deploymentKey}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)