* Finish task#44402

This commit is contained in:
zenggang
2021-11-19 08:19:21 +00:00
parent 15ce4de1e4
commit 7c6a0b0e4e
6 changed files with 35 additions and 16 deletions

View File

@@ -115,6 +115,22 @@ class gitlabModel extends model
->fetchPairs();
}
/**
* Get gitlab user id by zentao account.
*
* @param int $gitlabID
* @access public
* @return array
*/
public function getUserIDByZentaoAccount($gitlabID, $zentaoAccount)
{
return $this->dao->select('openID')->from(TABLE_OAUTH)
->where('providerType')->eq('gitlab')
->andWhere('providerID')->eq($gitlabID)
->andWhere('account')->eq($zentaoAccount)
->fetch('openID');
}
/**
* Get project pairs of one gitlab.
*

View File

@@ -80,6 +80,7 @@ class mr extends control
$this->app->loadLang('repo'); /* Import lang in repo module. */
$this->app->loadLang('compile');
$this->view->title = $this->lang->mr->create;
$this->view->users = $this->loadModel('user')->getPairs('noletter');
$this->view->jobList = $this->loadModel('job')->getList();
$this->view->gitlabHosts = $this->loadModel('gitlab')->getPairs();
$this->display();
@@ -146,8 +147,8 @@ class mr extends control
$this->view->title = $this->lang->mr->edit;
$this->view->MR = $MR;
$this->view->targetBranchList = $targetBranchList;
$this->view->users = array('' => '') + $users;
$this->view->assignee = zget($gitlabUsers, $MR->assignee, '');
$this->view->users = $this->loadModel('user')->getPairs('noletter');
$this->view->assignee = $MR->assignee;
$this->view->reviewer = zget($gitlabUsers, $MR->reviewer, '');
$this->display();

View File

@@ -44,6 +44,7 @@ $(function()
});
});
/*
$('#targetProject').change(function()
{
targetProject = $(this).val();
@@ -58,6 +59,7 @@ $(function()
reviewer.chosen().trigger("chosen:updated");;
});
});
*/
$('#repo').change(function()
{

View File

@@ -107,7 +107,7 @@ class mrModel extends model
}
/* Exec Job */
if(isset($MR->$jobID) && $MR->jobID)
if(isset($MR->jobID) && $MR->jobID)
{
$pipeline = $this->loadModel('job')->exec($MR->jobID);
if($pipeline->queue)
@@ -132,7 +132,11 @@ class mrModel extends model
$MRObject->target_branch = $MR->targetBranch;
$MRObject->title = $MR->title;
$MRObject->description = $MR->description;
$MRObject->assignee_ids = $MR->assignee;
if($MR->assignee)
{
$gitlabAssignee = $this->gitlab->getUserIDByZentaoAccount($this->post->gitlabID, $MR->assignee);
if($gitlabAssignee) $MRObject->assignee_ids = $gitlabAssignee;
}
$rawMR = $this->apiCreateMR($this->post->gitlabID, $this->post->sourceProject, $MRObject);
@@ -161,10 +165,6 @@ class mrModel extends model
$newMR->status = $rawMR->state;
$newMR->mergeStatus = $rawMR->merge_status;
/* Change gitlab user ID to zentao account. */
$gitlabUsers = $this->gitlab->getUserIdAccountPairs($MR->gitlabID);
$newMR->assignee = zget($gitlabUsers, $MR->assignee, '');
/* Update MR in Zentao database. */
$this->dao->update(TABLE_MR)->data($newMR)
->where('id')->eq($MRID)
@@ -204,7 +204,7 @@ class mrModel extends model
$oldMR = $this->getByID($MRID);
/* Exec Job */
if($MR->jobID)
if(isset($MR->jobID) && $MR->jobID)
{
$pipeline = $this->loadModel('job')->exec($MR->jobID);
@@ -220,16 +220,16 @@ class mrModel extends model
$newMR = new stdclass;
$newMR->title = $MR->title;
$newMR->description = $MR->description;
$newMR->assignee_ids = $MR->assignee;
$newMR->target_branch = $MR->targetBranch;
if($MR->assignee)
{
$gitlabAssignee = $this->gitlab->getUserIDByZentaoAccount($oldMR->gitlabID, $MR->assignee);
if($gitlabAssignee) $newMR->assignee_ids = $gitlabAssignee;
}
/* Known issue: `reviewer_ids` takes no effect. */
$rawMR = $this->apiUpdateMR($oldMR->gitlabID, $oldMR->targetProject, $oldMR->mriid, $newMR);
/* Change gitlab user ID to zentao account. */
$gitlabUsers = $this->gitlab->getUserIdAccountPairs($oldMR->gitlabID);
$MR->assignee = zget($gitlabUsers, $MR->assignee, '');
/* Update MR in Zentao database. */
$this->dao->update(TABLE_MR)->data($MR, $this->config->mr->edit->skippedFields)
->where('id')->eq($MRID)

View File

@@ -79,7 +79,7 @@
common::printLink('mr', 'view', "mr={$MR->id}", '<i class="icon icon-eye"></i>', '', "title='{$lang->mr->view}' class='btn btn-info'");
common::printLink('mr', 'edit', "mr={$MR->id}", '<i class="icon icon-edit"></i>', '', "title='{$lang->mr->edit}' class='btn btn-info'");
common::printLink('mr', 'diff', "mr={$MR->id}", '<i class="icon icon-review"></i>', '', "title='{$lang->mr->viewDiff}' class='btn btn-info'");
common::printLink('mr', 'link', "mr={$MR->id}", '<i class="icon icon-link"></i>', '', "title='{$lang->mr->link}' class='btn btn-info'");
common::printLink('mr', 'link', "mr={$MR->id}", '<i class="icon icon-link"></i>', '', "title='{$lang->mr->link}' class='btn btn-info'" . ($MR->linkButton == false ? 'disabled' : ''));
common::printLink('mr', 'delete', "mr={$MR->id}", '<i class="icon icon-trash"></i>', 'hiddenwin', "title='{$lang->mr->delete}' class='btn btn-info'");
?>
</td>

View File

@@ -70,7 +70,7 @@
</tr>
<tr>
<th><?php echo $lang->mr->assignee;?></th>
<td><?php echo html::select('assignee', array(''), '', "class='form-control chosen'");?></td>
<td><?php echo html::select('assignee', $users, '', "class='form-control chosen'");?></td>
</tr>
<tr>
<th></th>