Merge branch 'cyy_bug' into 'zenops_38'

Fix bug and optimize repo load.

See merge request easycorp/zentaopms!4497
This commit is contained in:
李玉春
2022-07-13 03:18:58 +00:00
6 changed files with 51 additions and 41 deletions
+26 -20
View File
@@ -68,7 +68,7 @@ class gitea
else
{
$commits = $this->getCommitsByPath($file->path, '', '', 1);
if(empty($commits)) continue;
if(empty($commits) or !is_array($commits)) continue;
$commit = $commits[0];
$info->revision = $commit->sha;
@@ -527,7 +527,7 @@ class gitea
if(!empty($version) and $count == 1)
{
$api .= '/' . $version;
$commit = $this->fetch($api);
$commit = $this->fetch($api, array('limit' => 1));
if(isset($commit->sha))
{
$log = new stdclass;
@@ -543,10 +543,8 @@ class gitea
}
}
$params = array();
$params['ref_name'] = $branch;
$params['per_page'] = $count;
$params['all'] = 0;
$params['sha'] = $branch;
$params['page'] = $count;
if($version and $version != 'HEAD')
{
@@ -605,8 +603,11 @@ class gitea
$time = $dao->select('time')->from(TABLE_REPOHISTORY)->where('revision')->eq($sha)->fetch('time');
if($time) return date('c', strtotime($time));
$result = $this->fetch("commits/$sha");
return (isset($result->committed_date)) ? $result->committed_date : false;
$params = array();
$params['sha'] = $sha;
$params['limit'] = 1;
$result = $this->fetch("commits", $params);
return (isset($resulti[0]->created)) ? date('Y-m-d H:i:s', strtotime($result->created)) : false;
}
/**
@@ -622,13 +623,14 @@ class gitea
public function getCommitsByPath($path, $fromRevision = '', $toRevision = '', $perPage = 0)
{
$path = ltrim($path, DIRECTORY_SEPARATOR);
$api = "commits";
$api = "commits";
$param = new stdclass();
$param->path = urldecode($path);
$param->sha = ($toRevision != 'HEAD' and $toRevision) ? $toRevision : $this->branch;
$param->path = urldecode($path);
$param->limit = 1;
$param->sha = ($toRevision != 'HEAD' and $toRevision) ? $toRevision : $this->branch;
if($perPage) $param->per_page = $perPage;
if($perPage) $param->page = $perPage;
return $this->fetch($api, $param);
}
@@ -646,18 +648,23 @@ class gitea
$results = $this->fetch($api, array('ref' => $revision));
if(empty($results)) return array();
$diffApi = "git/commits/$revision.patch";
$diffs = commonModel::http($diffApi);
if(!empty(commonModel::$requestErrors) or empty($diffs)) return array();
$files = array();
foreach($results as $row)
{
$file = new stdclass();
$file->revision = $revision;
$file->action = 'A';
$file->type = $row->type;
$file->path = '/' . trim($row->path);
$files[] = $file;
$file->type = $row->type;
$file->path = '/' . $row->path;
$files[$file->path] = $file;
}
return $files;
return array_values($files);
}
/**
@@ -689,8 +696,8 @@ class gitea
public function fetch($api, $params = array(), $needToLoop = false)
{
$params = (array) $params;
$params['token'] = $this->token;
$params['per_page'] = isset($params['per_page']) ? $params['per_page'] : 100;
$params['token'] = $this->token;
$params['limit'] = isset($params['limit']) ? $params['limit'] : 100;
$api = ltrim($api, '/');
$api = $this->root . $api . '?' . http_build_query($params);
@@ -716,8 +723,7 @@ class gitea
return array();
}
$res = json_decode($response);
return empty($res) ? trim($response) : $res;
return json_decode($response);
}
}
+6 -4
View File
@@ -42,20 +42,20 @@ function addItem(obj)
{
var item = $('#addItem').html().replace(/%i%/g, itemIndex);
var $tr = $('<tr class="addedItem">' + item + '</tr>').insertAfter($(obj).closest('tr'));
var $accounts = $tr.find('select:first').addClass('user-picker').trigger('list:updated').picker({type: 'user'});
var $branches = $tr.find('select').addClass('user-picker').trigger('list:updated').picker({type: 'user'});
itemIndex++;
var disabledItems = [];
$('.user-picker[name^=branches]').each(function()
{
if(this === $accounts[0]) return;
if(this === $branches[0]) return;
var $select = $(this);
var picker = $select.data('zui.picker');
if(!picker) return;
var selectItem = picker.getListItem(picker.getValue());
if(selectItem) disabledItems.push($.extend({}, selectItem, {disabled: true}));
});
if(disabledItems.length) $accounts.data('zui.picker').updateOptionList(disabledItems);
if(disabledItems.length) $branches.data('zui.picker').updateOptionList(disabledItems);
}
/**
@@ -67,6 +67,8 @@ function addItem(obj)
*/
function deleteItem(obj)
{
if($('#privForm .table-form tbody').children().length < 2) return false;
if($('#privForm .table tbody').children().length < 2) return false;
$(obj).closest('tr').find('.picker .picker-selection-remove').click();
$(obj).closest('tr').remove();
}
+8 -6
View File
@@ -40,22 +40,22 @@ function savePriv()
*/
function addItem(obj)
{
var item = $('#addItem').html().replace(/%i%/g, itemIndex);
var $tr = $('<tr class="addedItem">' + item + '</tr>').insertAfter($(obj).closest('tr'));
var $accounts = $tr.find('select:first').addClass('user-picker').trigger('list:updated').picker({type: 'user'});
var item = $('#addItem').html().replace(/%i%/g, itemIndex);
var $tr = $('<tr class="addedItem">' + item + '</tr>').insertAfter($(obj).closest('tr'));
var $tags = $tr.find('select').addClass('user-picker').trigger('list:updated').picker({type: 'user'});
itemIndex++;
var disabledItems = [];
$('.user-picker[name^=tags]').each(function()
{
if(this === $accounts[0]) return;
if(this === $tags[0]) return;
var $select = $(this);
var picker = $select.data('zui.picker');
if(!picker) return;
var selectItem = picker.getListItem(picker.getValue());
if(selectItem) disabledItems.push($.extend({}, selectItem, {disabled: true}));
});
if(disabledItems.length) $accounts.data('zui.picker').updateOptionList(disabledItems);
if(disabledItems.length) $tags.data('zui.picker').updateOptionList(disabledItems);
}
/**
@@ -67,6 +67,8 @@ function addItem(obj)
*/
function deleteItem(obj)
{
if($('#privForm .table-form tbody').children().length < 2) return false;
if($('#privForm .table tbody').children().length < 2) return false;
$(obj).closest('tr').find('.picker .picker-selection-remove').click();
$(obj).closest('tr').remove();
}
+6 -6
View File
@@ -23,9 +23,9 @@
<?php foreach($hasAccessBranches as $branch):?>
<tr>
<td><?php echo html::input("names[$i]", $branch->name, "class='form-control' readonly");?></td>
<td><?php echo html::select("mergeLevels[$i]", $lang->gitlab->branch->branchCreationLevelList, $branch->mergeAccess, "class='form-control chosen'");?></td>
<td><?php echo html::select("mergeLevels[$i]", $lang->gitlab->branch->branchCreationLevelList, $branch->mergeAccess, "class='form-control user-picker'");?></td>
<td>
<?php echo html::select("pushLevels[$i]", $lang->gitlab->branch->branchCreationLevelList, $branch->pushAccess, "class='form-control chosen'");?>
<?php echo html::select("pushLevels[$i]", $lang->gitlab->branch->branchCreationLevelList, $branch->pushAccess, "class='form-control user-picker'");?>
<?php echo html::hidden("branches[$i]", $branch->name);?>
</td>
<td class='c-actions text-center'>
@@ -40,8 +40,8 @@
<?php for($j = 0; $j < 5; $j ++):?>
<tr class='addedItem'>
<td><?php echo html::select("branches[$i]", array(''=>'') + $noAccessBranches, '', "class='form-control user-picker'");?></td>
<td><?php echo html::select("mergeLevels[$i]", $lang->gitlab->branch->branchCreationLevelList, 40, "class='form-control chosen'");?></td>
<td><?php echo html::select("pushLevels[$i]", $lang->gitlab->branch->branchCreationLevelList, 40, "class='form-control chosen'");?></td>
<td><?php echo html::select("mergeLevels[$i]", $lang->gitlab->branch->branchCreationLevelList, 40, "class='form-control user-picker'");?></td>
<td><?php echo html::select("pushLevels[$i]", $lang->gitlab->branch->branchCreationLevelList, 40, "class='form-control user-picker'");?></td>
<td class='c-actions text-center'>
<?php echo html::a('javascript:;', "<i class='icon-plus'></i>", '', "onclick='addItem(this)' class='btn btn-link'");?>
<?php echo html::a('javascript:;', "<i class='icon icon-close'></i>", '', "onclick='deleteItem(this)' class='btn btn-link'");?>
@@ -70,8 +70,8 @@
<table class='hidden'>
<tr id='addItem' class='hidden'>
<td><?php echo html::select("branches[]", array(''=>'') + $noAccessBranches, '', "class='form-control'");?></td>
<td><?php echo html::select("mergeLevels[]", $lang->gitlab->branch->branchCreationLevelList, 40, "class='form-control chosen'");?></td>
<td><?php echo html::select("pushLevels[]", $lang->gitlab->branch->branchCreationLevelList, 40, "class='form-control chosen'");?></td>
<td><?php echo html::select("mergeLevels[]", $lang->gitlab->branch->branchCreationLevelList, 40, "class='form-control'");?></td>
<td><?php echo html::select("pushLevels[]", $lang->gitlab->branch->branchCreationLevelList, 40, "class='form-control'");?></td>
<td class='c-actions text-center'>
<?php echo html::a('javascript:;', "<i class='icon-plus'></i>", '', "onclick='addItem(this)' class='btn btn-link'");?>
<?php echo html::a('javascript:;', "<i class='icon icon-close'></i>", '', "onclick='deleteItem(this)' class='btn btn-link'");?>
+3 -3
View File
@@ -22,7 +22,7 @@
<?php foreach($hasAccessTags as $tag):?>
<tr>
<td><?php echo html::input("names[$i]", $tag->name, "class='form-control' readonly");?></td>
<td><?php echo html::select("createLevels[$i]", $lang->gitlab->branch->branchCreationLevelList, $tag->createAccess, "class='form-control chosen'");?></td>
<td><?php echo html::select("createLevels[$i]", $lang->gitlab->branch->branchCreationLevelList, $tag->createAccess, "class='form-control user-picker'");?></td>
<td class='c-actions text-center'>
<?php echo html::hidden("tags[$i]", $tag->name);?>
<?php echo html::a('javascript:;', "<i class='icon-plus'></i>", '', "onclick='addItem(this)' class='btn btn-link'");?>
@@ -36,7 +36,7 @@
<?php for($j = 0; $j < 5; $j ++):?>
<tr class='addedItem'>
<td><?php echo html::select("tags[$i]", array(''=>'') + $noAccessTags, '', "class='form-control user-picker'");?></td>
<td><?php echo html::select("createLevels[$i]", $lang->gitlab->branch->branchCreationLevelList, 40, "class='form-control chosen'");?></td>
<td><?php echo html::select("createLevels[$i]", $lang->gitlab->branch->branchCreationLevelList, 40, "class='form-control user-picker'");?></td>
<td class='c-actions text-center'>
<?php echo html::a('javascript:;', "<i class='icon-plus'></i>", '', "onclick='addItem(this)' class='btn btn-link'");?>
<?php echo html::a('javascript:;', "<i class='icon icon-close'></i>", '', "onclick='deleteItem(this)' class='btn btn-link'");?>
@@ -65,7 +65,7 @@
<table class='hidden'>
<tr id='addItem' class='hidden'>
<td><?php echo html::select("tags[]", array(''=>'') + $noAccessTags, '', "class='form-control'");?></td>
<td><?php echo html::select("createLevels[]", $lang->gitlab->branch->branchCreationLevelList, 40, "class='form-control chosen'");?></td>
<td><?php echo html::select("createLevels[]", $lang->gitlab->branch->branchCreationLevelList, 40, "class='form-control'");?></td>
<td class='c-actions text-center'>
<?php echo html::a('javascript:;', "<i class='icon-plus'></i>", '', "onclick='addItem(this)' class='btn btn-link'");?>
<?php echo html::a('javascript:;', "<i class='icon icon-close'></i>", '', "onclick='deleteItem(this)' class='btn btn-link'");?>
+2 -2
View File
@@ -145,7 +145,7 @@ class repo extends control
$this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->create;
$this->view->position[] = $this->lang->repo->create;
$this->view->groups = $this->loadModel('group')->getPairs();
$this->view->users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted');
$this->view->users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted|noclosed');
$this->view->products = $products;
$this->view->productID = $productID;
$this->view->serviceHosts = $this->loadModel('gitlab')->getPairs();
@@ -202,7 +202,7 @@ class repo extends control
$this->view->repoID = $repoID;
$this->view->objectID = $objectID;
$this->view->groups = $this->loadModel('group')->getPairs();
$this->view->users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted');
$this->view->users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted|noclosed');
$this->view->products = $objectID ? $this->loadModel('product')->getProductPairsByProject($objectID) : $this->loadModel('product')->getPairs();
$this->view->serviceHosts = array('' => '') + $this->loadModel('pipeline')->getPairs($repo->SCM);