diff --git a/module/mr/config.php b/module/mr/config.php index c64305044e..34ab48ebaf 100644 --- a/module/mr/config.php +++ b/module/mr/config.php @@ -1,19 +1,22 @@ MR = new stdclass(); -$config->MR->create = new stdclass(); -$config->MR->create->requiredFields = 'gitlabID,sourceProject,sourceBranch,targetProject,targetBranch,title'; -$config->MR->create->skippedFields = 'projectID'; +$config->mr = new stdclass(); +$config->mr->create->skippedFields = 'projectID'; -$config->MR->maps = new stdclass; -$config->MR->maps->sync = array(); -$config->MR->maps->sync['title'] = 'title|field|'; -$config->MR->maps->sync['description'] = 'description|field|'; -$config->MR->maps->sync['assignee'] = 'assignees|userPairs|id'; -$config->MR->maps->sync['reviewer'] = 'reviewers|userPairs|id'; -$config->MR->maps->sync['targetBranch'] = 'target_branch|field|'; -$config->MR->maps->sync['sourceBranch'] = 'source_branch|field|'; -$config->MR->maps->sync['sourceProject'] = 'source_project_id|field|'; -$config->MR->maps->sync['targetProject'] = 'target_project_id|field|'; -$config->MR->maps->sync['status'] = 'state|field|'; -$config->MR->maps->sync['mergeStatus'] = 'merge_status|field|'; +$config->mr->create = new stdclass(); +$config->mr->create->requiredFields = 'gitlabID,sourceProject,sourceBranch,targetProject,targetBranch,title'; +$config->mr->edit = new stdclass; +$config->mr->edit->requiredFields = 'gitlabID,sourceProject,sourceBranch,targetProject,targetBranch,title'; + +$config->mr->maps = new stdclass; +$config->mr->maps->sync = array(); +$config->mr->maps->sync['title'] = 'title|field|'; +$config->mr->maps->sync['description'] = 'description|field|'; +$config->mr->maps->sync['assignee'] = 'assignees|userPairs|id'; +$config->mr->maps->sync['reviewer'] = 'reviewers|userPairs|id'; +$config->mr->maps->sync['targetBranch'] = 'target_branch|field|'; +$config->mr->maps->sync['sourceBranch'] = 'source_branch|field|'; +$config->mr->maps->sync['sourceProject'] = 'source_project_id|field|'; +$config->mr->maps->sync['targetProject'] = 'target_project_id|field|'; +$config->mr->maps->sync['status'] = 'state|field|'; +$config->mr->maps->sync['mergeStatus'] = 'merge_status|field|'; diff --git a/module/mr/control.php b/module/mr/control.php index 8798eabf5d..9668c7ce32 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -74,7 +74,8 @@ class mr extends control /* Fetch user list both in Zentao and current GitLab project. */ $bindedUsers = $this->gitlab->getUserIdRealnamePairs($MR->gitlabID); $rawProjectUsers = $this->gitlab->apiGetProjectUsers($MR->gitlabID, $MR->targetProject); - $users = array(); + + $users = array(); foreach($rawProjectUsers as $rawProjectUser) { if(!empty($bindedUsers[$rawProjectUser->id])) $users[$rawProjectUser->id] = $bindedUsers[$rawProjectUser->id]; diff --git a/module/mr/lang/en.php b/module/mr/lang/en.php index 61e7e883d2..d2b1e12aaa 100644 --- a/module/mr/lang/en.php +++ b/module/mr/lang/en.php @@ -13,7 +13,7 @@ $lang->mr->viewInGitlab = 'view in GitLab'; $lang->mr->id = 'ID'; $lang->mr->mriid = "raw MR ID"; -$lang->mr->name = 'Name'; +$lang->mr->title = 'Name'; $lang->mr->status = 'Status'; $lang->mr->author = 'Author'; $lang->mr->assignee = 'Assignee'; diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 1f88c3e478..f88043106d 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -13,7 +13,7 @@ $lang->mr->viewInGitlab = '在GitLab查看'; $lang->mr->id = 'ID'; $lang->mr->mriid = "MR原始ID"; -$lang->mr->name = '名称'; +$lang->mr->title = '名称'; $lang->mr->status = '状态'; $lang->mr->author = '创建人'; $lang->mr->assignee = '指派给'; diff --git a/module/mr/model.php b/module/mr/model.php index fd4f449500..4901bd1a8d 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -84,8 +84,8 @@ class mrModel extends model ->add('createdDate', helper::now()) ->get(); - $this->dao->insert(TABLE_MR)->data($MR, $this->config->MR->create->skippedFields) - ->batchCheck($this->config->MR->create->requiredFields, 'notempty') + $this->dao->insert(TABLE_MR)->data($MR, $this->config->mr->create->skippedFields) + ->batchCheck($this->config->mr->create->requiredFields, 'notempty') ->autoCheck() ->exec(); if(dao::isError()) return array('result' => 'fail', 'message' => dao::getError()); @@ -173,6 +173,7 @@ class mrModel extends model /* Update MR in Zentao database. */ $this->dao->update(TABLE_MR)->data($MR) ->where('id')->eq($MRID) + ->batchCheck($this->config->mr->edit->requiredFields, 'notempty') ->autoCheck() ->exec(); $MR = $this->getByID($MRID); @@ -194,7 +195,7 @@ class mrModel extends model /* Sync MR in ZenTao database whatever status of MR in GitLab. */ if(isset($rawMR->iid)) { - $map = $this->config->MR->maps->sync; + $map = $this->config->mr->maps->sync; $gitlabUsers = $this->gitlab->getUserIdAccountPairs($MR->gitlabID); $newMR = new stdclass; @@ -238,12 +239,13 @@ class mrModel extends model { if($MR->status != 'opened') continue; $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); + if(isset($rawMR->iid)) { /* create gitlab mr todo to zentao todo */ $this->batchSyncTodo($MR->gitlabID, $MR->targetProject); - $map = $this->config->MR->maps->sync; + $map = $this->config->mr->maps->sync; $gitlabUsers = $this->gitlab->getUserIdAccountPairs($MR->gitlabID); $newMR = new stdclass; @@ -266,6 +268,9 @@ class mrModel extends model if($value) $newMR->$syncField = $value; } + + if(empty((array)$newMR)) continue; + /* Update MR in Zentao database. */ $this->dao->update(TABLE_MR)->data($newMR) ->where('id')->eq($MR->id) diff --git a/module/mr/view/browse.html.php b/module/mr/view/browse.html.php index 45cc7ecb4c..d6dc697129 100644 --- a/module/mr/view/browse.html.php +++ b/module/mr/view/browse.html.php @@ -31,7 +31,7 @@