* Using sudo to accept merge request.

This commit is contained in:
dingguodong
2021-09-02 15:21:19 +08:00
parent 8201fafc46
commit 1b41b61cee
2 changed files with 13 additions and 2 deletions
+12 -1
View File
@@ -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);
}
+1 -1
View File
@@ -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.
*