* Correct or Optimize codes to meet code styles.

This commit is contained in:
dingguodong
2021-11-16 10:46:48 +08:00
parent f1de062231
commit 2d9d95cc98
13 changed files with 76 additions and 70 deletions
+3 -2
View File
@@ -375,7 +375,8 @@ $filter->gitlab->importissue->get['project'] = 'int';
$filter->gitlab->importissue->get['repo'] = 'int';
$filter->mr->diff->cookie['arrange'] = 'reg::word';
$filter->mr->browse->get['assignee'] = 'string';
$filter->mr->browse->get['creator'] = 'string';
$filter->mr->browse->get['mode'] = 'string';
$filter->mr->browse->get['param'] = 'string';
$filter->ci->checkCompileStatus->get['gitlabOnly'] = 'string';
+1 -1
View File
@@ -665,7 +665,7 @@ CREATE TABLE IF NOT EXISTS `zt_mr` (
`mergeStatus` char(30) NOT NULL,
`approvalStatus` char(30) NOT NULL,
`needApproved` enum('0','1') NOT NULL DEFAULT '0',
`needPassCI` enum('0','1') NOT NULL DEFAULT '0',
`needCI` enum('0','1') NOT NULL DEFAULT '0',
`repoID` mediumint(8) unsigned NOT NULL,
`jobID` mediumint(8) unsigned NOT NULL,
`compileID` mediumint(8) unsigned NOT NULL,
+2 -2
View File
@@ -1053,10 +1053,10 @@ class gitlabModel extends model
$hook->push_events = true;
$hook->merge_requests_events = true;
/* Return a empty array if where is a existing webhook. */
/* Return an empty array if where is one existing webhook. */
if($this->isWebhookExists($repo, $hook->url)) return array();
$result = $this->apiCreateHook($repo->gitlab, $repo->project, $hook);
$result = $this->apiCreateHook($repo->gitlab, $repo->project, $hook);
if(!empty($result->id)) return true;
return false;
+9 -9
View File
@@ -18,6 +18,8 @@ class mr extends control
/**
* Browse mr.
*
* @param string $mode
* @param string $param
* @param int $objectID
* @param string $orderBy
* @param int $recTotal
@@ -26,14 +28,13 @@ class mr extends control
* @access public
* @return void
*/
public function browse($browseType = 'all', $assignee = 'all', $creator = 'all', $objectID = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
public function browse($mode = 'all', $param = 'all', $objectID = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
{
$assignee = isset($_GET['assignee']) ? $this->get->assignee : "all";
$creator = isset($_GET['creator']) ? $this->get->creator : "all";
$param = isset($_GET['param']) ? $this->get->param : "all";
$this->app->loadClass('pager', $static = true);
$pager = new pager($recTotal, $recPerPage, $pageID);
$MRList = $this->mr->getList($browseType, $assignee, $creator, $orderBy, $pager);
$MRList = $this->mr->getList($mode, $param, $orderBy, $pager);
/* Save current URI to session. */
$this->session->set('mrList', $this->app->getURI(true), 'repo');
@@ -47,9 +48,8 @@ class mr extends control
$this->view->title = $this->lang->mr->common . $this->lang->colon . $this->lang->mr->browse;
$this->view->MRList = $MRList;
$this->view->pager = $pager;
$this->view->browseType = $browseType;
$this->view->assignee = $assignee;
$this->view->creator = $creator;
$this->view->mode = $mode;
$this->view->param = $param;
$this->view->objectID = $objectID;
$this->view->orderBy = $orderBy;
$this->display();
@@ -231,13 +231,13 @@ class mr extends control
$MR = $this->mr->getByID($MRID);
/* Judge that if this MR can be accepted. */
if(isset($MR->needPassCI) and $MR->needPassCI == '1')
if(isset($MR->needCI) and $MR->needCI == '1')
{
$compileStatus = empty($MR->compileID) ? 'fail' : $this->loadModel('compile')->getByID($MR->compileID)->status;
if(isset($compileStatus) and $compileStatus != 'success')
{
return $this->send(array('result' => 'fail', 'message' => $this->lang->mr->needPassCI, 'locate' => helper::createLink('mr', 'view', "mr={$MRID}")));
return $this->send(array('result' => 'fail', 'message' => $this->lang->mr->needCI, 'locate' => helper::createLink('mr', 'view', "mr={$MRID}")));
}
}
if(isset($MR->needApproved) and $MR->needApproved == '1')
+23 -18
View File
@@ -1,20 +1,25 @@
$(function () {
$('#repo').change(function () {
repoID = $(this).val();
jobUrl = createLink('mr', 'ajaxGetJobList', "repoID=" + repoID);
$.get(jobUrl, function (response) {
$('#job').html('').append(response);
$('#job').chosen().trigger("chosen:updated");;
});
});
$(function ()
{
$('#repo').change(function ()
{
repoID = $(this).val();
jobUrl = createLink('mr', 'ajaxGetJobList', "repoID=" + repoID);
$.get(jobUrl, function (response)
{
$('#job').html('').append(response);
$('#job').chosen().trigger("chosen:updated");;
});
});
$('#job').change(function () {
jobID = $(this).val();
compileUrl = createLink('mr', 'ajaxGetCompileList', "job=" + jobID);
$.get(compileUrl, function (response) {
$('#compile').html('').append(response);
$('#compile').chosen().trigger("chosen:updated");;
});
});
$('#job').change(function ()
{
jobID = $(this).val();
compileUrl = createLink('mr', 'ajaxGetCompileList', "job=" + jobID);
$.get(compileUrl, function (response)
{
$('#compile').html('').append(response);
$('#compile').chosen().trigger("chosen:updated");;
});
});
});
});
+3 -3
View File
@@ -31,13 +31,13 @@ $lang->mr->reject = 'Reject';
$lang->mr->close = 'Close';
$lang->mr->reopen = 'Reopen';
$lang->mr->approvalResult = 'Approval result';
$lang->mr->approvalResultList = array();
$lang->mr->approvalResult = 'Approval result';
$lang->mr->approvalResultList = array();
$lang->mr->approvalResultList['approve'] = 'Approve';
$lang->mr->approvalResultList['reject'] = 'Reject';
$lang->mr->needApproved = 'This MR should be approved before merge';
$lang->mr->needPassCI = 'This MR should be passed CI before merge';
$lang->mr->needCI = 'This MR should be passed CI before merge';
$lang->mr->repeatedOperation = 'Do not repeat operations';
+3 -3
View File
@@ -31,13 +31,13 @@ $lang->mr->reject = '拒绝';
$lang->mr->close = '关闭';
$lang->mr->reopen = '重新打开';
$lang->mr->approvalResult = '评审意见';
$lang->mr->approvalResultList = array();
$lang->mr->approvalResult = '评审意见';
$lang->mr->approvalResultList = array();
$lang->mr->approvalResultList['approve'] = '通过';
$lang->mr->approvalResultList['reject'] = '拒绝';
$lang->mr->needApproved = '需要通过评审才能合并';
$lang->mr->needPassCI = '需要通过构建才能合并';
$lang->mr->needCI = '需要通过构建才能合并';
$lang->mr->repeatedOperation = '请勿重复操作';
+3 -3
View File
@@ -31,13 +31,13 @@ $lang->mr->reject = '拒絕';
$lang->mr->close = '關閉';
$lang->mr->reopen = '重新打開';
$lang->mr->approvalResult = '評審意見';
$lang->mr->approvalResultList = array();
$lang->mr->approvalResult = '評審意見';
$lang->mr->approvalResultList = array();
$lang->mr->approvalResultList['approve'] = '通過';
$lang->mr->approvalResultList['reject'] = '拒絕';
$lang->mr->needApproved = '需要通過評審才能合併';
$lang->mr->needPassCI = '需要通過構建才能合併';
$lang->mr->needCI = '需要通過構建才能合併';
$lang->mr->repeatedOperation = '請勿重複操作';
+15 -15
View File
@@ -38,22 +38,21 @@ class mrModel extends model
/**
* Get MR list of gitlab project.
*
* @param string $browseType
* @param string $assignee
* @param string $creator
* @param string $mode
* @param string $param
* @param string $orderBy
* @param object $pager
* @access public
* @return array
*/
public function getList($browseType = 'all', $assignee = 'all', $creator = 'all', $orderBy = 'id_desc', $pager)
public function getList($mode = 'all', $param = 'all', $orderBy = 'id_desc', $pager)
{
$MRList = $this->dao->select('*')
->from(TABLE_MR)
->where('deleted')->eq('0')
->beginIF($browseType != 'all')->andWhere('status')->eq($browseType)->fi()
->beginIF($assignee != 'all')->andWhere('assignee')->eq($assignee)->fi()
->beginIF($creator != 'all')->andWhere('createdBy')->eq($creator)->fi()
->beginIF($mode == 'status' and $param != 'all')->andWhere('status')->eq($param)->fi()
->beginIF($mode == 'assignee' and $param != 'all')->andWhere('assignee')->eq($param)->fi()
->beginIF($mode == 'creator' and $param != 'all')->andWhere('createdBy')->eq($param)->fi()
->orderBy($orderBy)
->page($pager)
->fetchAll('id');
@@ -317,7 +316,7 @@ class mrModel extends model
if(empty($condition)) continue;
/* Update compile status of current MR object */
if(isset($MR->needPassCI) and $MR->needPassCI == '1')
if(isset($MR->needCI) and $MR->needCI == '1')
{
$newMR->compileStatus = empty($MR->compileID) ? 'fail' : $this->loadModel('compile')->getByID($MR->compileID)->status;
}
@@ -564,8 +563,8 @@ class mrModel extends model
$repo->account = '';
$repo->encoding = $encoding;
$lines = array();
$commitsAdded = array();
$lines = array();
$commitList = array();
foreach ($diffVersions as $diffVersion)
{
$singleDiff = $this->apiGetSingleDiffVersion($MR->gitlabID, $MR->targetProject, $MR->mriid, $diffVersion->id);
@@ -576,8 +575,8 @@ class mrModel extends model
{
/* Make sure every file with same commitID is unique in $lines. */
$shortID = $commits[$index]->short_id;
if(in_array($shortID, $commitsAdded)) continue;
$commitsAdded[] = $shortID;
if(in_array($shortID, $commitList)) continue;
$commitList[] = $shortID;
$lines[] = sprintf("diff --git a/%s b/%s", $diff->old_path, $diff->new_path);
$lines[] = sprintf("index %s ... %s %s ", $singleDiff->head_commit_sha, $singleDiff->base_commit_sha, $diff->b_mode);
@@ -631,7 +630,7 @@ class mrModel extends model
if(!empty($bindedUsers[$rawProjectUser->username])) $users[$rawProjectUser->username] = $bindedUsers[$rawProjectUser->username];
}
if(!empty($users[$zentaoUser])) return $users[$zentaoUser];
return "";
return '';
}
/**
@@ -692,15 +691,16 @@ class mrModel extends model
{
$this->loadModel('action');
$actionID = $this->action->create('mrapproval', $MR->id, $action);
$oldMR = $MR;
if(isset($MR->status) and $MR->status == 'opened')
if(isset($MR->status) and $MR->status == 'opened')
{
$rawApprovalStatus = '';
if(isset($MR->approvalStatus)) $rawApprovalStatus = $MR->approvalStatus;
$MR->approver = $this->app->user->account;
if ($action == 'reject' and $rawApprovalStatus != 'rejected') $MR->approvalStatus = 'rejected';
if ($action == 'approve' and $rawApprovalStatus != 'approved') $MR->approvalStatus = 'approved';
if (isset($MR->approvalStatus) and $rawApprovalStatus != $MR->approvalStatus)
if (isset($MR->approvalStatus) and $rawApprovalStatus != $MR->approvalStatus)
{
$changes = common::createChanges($oldMR, $MR);
$this->action->logHistory($actionID, $changes);
+6 -6
View File
@@ -19,13 +19,13 @@
<?php endif;?>
<div class="btn-toolBar pull-left">
<?php foreach($lang->mr->statusList as $key => $label):?>
<?php $active = $browseType == $key ? 'btn-active-text' : '';?>
<?php $active = $param == $key ? 'btn-active-text' : '';?>
<?php $label = "<span class='text'>$label</span>";?>
<?php if($browseType == $key) $label .= " <span class='label label-light label-badge'>{$pager->recTotal}</span>";?>
<?php echo html::a(inlink('browse', "browseType=$key"), $label, '', "class='btn btn-link $active'");?>
<?php if($param == $key) $label .= " <span class='label label-light label-badge'>{$pager->recTotal}</span>";?>
<?php echo html::a(inlink('browse', "mode=status&param=$key"), $label, '', "class='btn btn-link $active'");?>
<?php endforeach;?>
<?php echo html::a(inlink('browse', "browseType=all&assignee={$this->app->user->account}&creator=all"), $lang->mr->assignedToMe, '', "class='btn btn-link $active'");?>
<?php echo html::a(inlink('browse', "browseType=all&assignee=all&creator={$this->app->user->account}"), $lang->mr->createdByMe, '', "class='btn btn-link $active'");?>
<?php echo html::a(inlink('browse', "mode=assignee&param={$this->app->user->account}"), $lang->mr->assignedToMe, '', "class='btn btn-link $active'");?>
<?php echo html::a(inlink('browse', "mode=creator&param={$this->app->user->account}"), $lang->mr->createdByMe, '', "class='btn btn-link $active'");?>
</div>
<div class="btn-toolbar pull-right">
<?php common::printLink('mr', 'create', '', "<i class='icon icon-plus'></i> " . $lang->mr->create, '', "class='btn btn-primary'");?>
@@ -46,7 +46,7 @@
<table id='gitlabProjectList' class='table has-sort-head table-fixed'>
<thead>
<tr>
<?php $vars = "browseType=$browseType&assignee=$assignee&creator=$creator&objectID=$objectID&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}"; ?>
<?php $vars = "mode=$mode&param=$param&objectID=$objectID&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}"; ?>
<th class='w-60px text-left'><?php common::printOrderLink('id', $orderBy, $vars, $lang->mr->id); ?></th>
<th class='w-200px text-left'><?php common::printOrderLink('title', $orderBy, $vars, $lang->mr->title); ?></th>
<th class='text-left'><?php common::printOrderLink('sourceProject', $orderBy, $vars, $lang->mr->sourceProject); ?></th>
+3 -3
View File
@@ -52,11 +52,11 @@
<td colspan='1'><?php echo html::textarea('description', '', "rows='3' class='form-control'"); ?></td>
</tr>
<tr>
<th><?php echo $lang->mr->needPassCI; ?></th>
<th><?php echo $lang->mr->needCI; ?></th>
<td colspan='1'>
<div class="checkbox-primary">
<input type="checkbox" name="needPassCI" value="1" id="needPassCI">
<label for="needPassCI"></label>
<input type="checkbox" name="needCI" value="1" id="needCI">
<label for="needCI"></label>
</div>
</td>
</tr>
+1 -1
View File
@@ -137,7 +137,7 @@
</div>
<?php endforeach?>
</div>
<?php if(empty($diffs)): echo $lang->mr->noChanges; endif;?>
<?php if(empty($diffs)) echo $lang->mr->noChanges;?>
<form method="post" id="exchange" class="hidden">
<input type="hidden" name="revision[]" value="<?php echo $oldRevision;?>"/>
<input type="hidden" name="revision[]" value="<?php echo $newRevision;?>"/>
+4 -4
View File
@@ -66,12 +66,12 @@
<td colspan='1'><?php echo html::textarea('description', $MR->description, "rows='3' class='form-control'"); ?></td>
</tr>
<tr>
<th><?php echo $lang->mr->needPassCI; ?></th>
<th><?php echo $lang->mr->needCI; ?></th>
<td colspan='1'>
<div class="checkbox-primary">
<?php $checked = $MR->needPassCI == '1' ? 'checked' : '' ?>
<input type="checkbox" <?php echo $checked; ?> name="needPassCI" value="1" id="needPassCI">
<label for="needPassCI"></label>
<?php $checked = $MR->needCI == '1' ? 'checked' : '' ?>
<input type="checkbox" <?php echo $checked; ?> name="needCI" value="1" id="needCI">
<label for="needCI"></label>
</div>
</td>
</tr>