diff --git a/module/mr/control.php b/module/mr/control.php index 4c9450be56..12ad6a9ef5 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -174,8 +174,19 @@ class mr extends control public function accept($MRID) { $MR = $this->mr->getByID($MRID); - if(isset($MR->gitlabID)) $rawMR = $this->mr->apiAcceptMR($MR->gitlabID, $MR->targetProject, $MR->mriid); + + /* Accept MR by using the mapped user in GitLab. */ + $sudoUser = $this->mr->getSudoUsername($MR->gitlabID, $MR->targetProject); + + if(isset($MR->gitlabID)) + { + if(!empty($sudoUser)) $rawMR = $this->mr->apiAcceptMR($MR->gitlabID, $MR->targetProject, $MR->mriid, $sudo = $sudoUser); + if(empty($sudoUser)) $rawMR = $this->mr->apiAcceptMR($MR->gitlabID, $MR->targetProject, $MR->mriid); + } if(isset($rawMR->state) and $rawMR->state == 'merged') return array('result' => 'success', 'message' => $this->lang->mr->mergeSuccess); + + /* The type of variable `$rawMR->message` is string. This is different with apiCreateMR. */ + if(isset($rawMR->message)) return array('result' => 'fail', 'message' => sprintf($this->lang->mr->apiError->sudo, $rawMR->message)); return array('result' => 'fail', 'message' => $this->lang->mr->mergeFailed); } diff --git a/module/mr/lang/zh-cn.php b/module/mr/lang/zh-cn.php index 9a83adbd96..92bfc96367 100644 --- a/module/mr/lang/zh-cn.php +++ b/module/mr/lang/zh-cn.php @@ -44,6 +44,7 @@ $lang->mr->notFound = "此{$lang->mr->common}不存在。"; $lang->mr->apiError = new stdclass; $lang->mr->apiError->createMR = "通过API创建合并请求失败,失败原因:%s"; +$lang->mr->apiError->sudo = "无法以当前用户绑定的GitLab账户进行操作,失败原因:%s"; $lang->mr->createFailedFromAPI = "创建合并请求失败。"; $lang->mr->accessGitlabFailed = "当前无法连接到GitLab服务器。"; @@ -72,7 +73,6 @@ $lang->mr->acceptMR = "合并"; $lang->mr->mergeFailed = "无法合并,请核对合并请求状态"; $lang->mr->mergeSuccess = "已成功合并"; - /** * Merge Command Document. *