diff --git a/module/gitlab/model.php b/module/gitlab/model.php index b7056df41c..dd35e3f51c 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -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. * diff --git a/module/mr/control.php b/module/mr/control.php index 548e5d9ad8..c0f7f7c909 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -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(); diff --git a/module/mr/js/create.js b/module/mr/js/create.js index 5314ad3f82..fe07e22044 100644 --- a/module/mr/js/create.js +++ b/module/mr/js/create.js @@ -44,6 +44,7 @@ $(function() }); }); + /* $('#targetProject').change(function() { targetProject = $(this).val(); @@ -58,6 +59,7 @@ $(function() reviewer.chosen().trigger("chosen:updated");; }); }); + */ $('#repo').change(function() { diff --git a/module/mr/model.php b/module/mr/model.php index 5cef8690fd..25dec54103 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -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) diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index 10e9b3cd4f..d3f2262913 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -79,7 +79,7 @@ common::printLink('mr', 'view', "mr={$MR->id}", '', '', "title='{$lang->mr->view}' class='btn btn-info'"); common::printLink('mr', 'edit', "mr={$MR->id}", '', '', "title='{$lang->mr->edit}' class='btn btn-info'"); common::printLink('mr', 'diff', "mr={$MR->id}", '', '', "title='{$lang->mr->viewDiff}' class='btn btn-info'"); - common::printLink('mr', 'link', "mr={$MR->id}", '', '', "title='{$lang->mr->link}' class='btn btn-info'"); + common::printLink('mr', 'link', "mr={$MR->id}", '', '', "title='{$lang->mr->link}' class='btn btn-info'" . ($MR->linkButton == false ? 'disabled' : '')); common::printLink('mr', 'delete', "mr={$MR->id}", '', 'hiddenwin', "title='{$lang->mr->delete}' class='btn btn-info'"); ?> diff --git a/module/mr/view/create.html.php b/module/mr/view/create.html.php index 13047d7611..7156cb83b3 100644 --- a/module/mr/view/create.html.php +++ b/module/mr/view/create.html.php @@ -70,7 +70,7 @@ mr->assignee;?> - +