Merge branch 'jihuMR' into 'jihuMR'
Finish task#41303 See merge request easycorp/zentaopms!8
This commit is contained in:
@@ -417,16 +417,25 @@ class gitlab extends control
|
||||
|
||||
/**
|
||||
* AJAX: Get MR user pairs to select assignee_ids and reviewer_ids.
|
||||
* Attention: The user must be a member of the GitLab project.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @param int $projectID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxGetMRUserPairs($gitlabID)
|
||||
public function ajaxGetMRUserPairs($gitlabID, $projectID)
|
||||
{
|
||||
if(!$gitlabID) return $this->send(array('message' => array()));
|
||||
|
||||
$users = $this->gitlab->getUserIdRealnamePairs($gitlabID);
|
||||
$bindedUsers = $this->gitlab->getUserIdRealnamePairs($gitlabID);
|
||||
$rawProjectUsers = $this->gitlab->apiGetProjectUsers($gitlabID, $projectID);
|
||||
$users = array();
|
||||
foreach($rawProjectUsers as $rawProjectUser)
|
||||
{
|
||||
if(!empty($bindedUsers[$rawProjectUser->id])) $users[$rawProjectUser->id] = $bindedUsers[$rawProjectUser->id];
|
||||
}
|
||||
|
||||
$options = "<option value=''></option>";
|
||||
foreach($users as $index => $user)
|
||||
{
|
||||
|
||||
@@ -470,6 +470,20 @@ class gitlabModel extends model
|
||||
return json_decode(commonModel::http($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get project users.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @param int $projectID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function apiGetProjectUsers($gitlabID, $projectID)
|
||||
{
|
||||
$url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/users");
|
||||
return json_decode(commonModel::http($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single branch by API.
|
||||
*
|
||||
|
||||
+25
-1
@@ -67,12 +67,21 @@ class mr extends control
|
||||
$targetBranchList = array();
|
||||
foreach($branchList as $branch) $targetBranchList[$branch] = $branch;
|
||||
|
||||
/* 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();
|
||||
foreach($rawProjectUsers as $rawProjectUser)
|
||||
{
|
||||
if(!empty($bindedUsers[$rawProjectUser->id])) $users[$rawProjectUser->id] = $bindedUsers[$rawProjectUser->id];
|
||||
}
|
||||
|
||||
$gitlabUsers = $this->gitlab->getUserAccountIdPairs($MR->gitlabID);
|
||||
|
||||
$this->view->title = $this->lang->mr->edit;
|
||||
$this->view->MR = $MR;
|
||||
$this->view->targetBranchList = $targetBranchList;
|
||||
$this->view->users = array("" => "") + $this->loadModel('gitlab')->getUserIdRealnamePairs($MR->gitlabID);
|
||||
$this->view->users = array("" => "") + $users;
|
||||
$this->view->assignee = zget($gitlabUsers, $MR->assignee, '');
|
||||
$this->view->reviewer = zget($gitlabUsers, $MR->reviewer, '');
|
||||
|
||||
@@ -150,6 +159,21 @@ class mr extends control
|
||||
echo 'success';
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept a MR.
|
||||
*
|
||||
* @param int $MRID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function accept($MRID)
|
||||
{
|
||||
$MR = $this->mr->getByID($MRID);
|
||||
if(isset($MR->gitlabID)) $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);
|
||||
return array('result' => 'fail', 'message' => $this->lang->mr->mergeFailed);
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX: Get MR target projects.
|
||||
*
|
||||
|
||||
+18
-13
@@ -11,19 +11,7 @@ $(function()
|
||||
$('#sourceProject').html('').append(response);
|
||||
$('#sourceProject').chosen().trigger("chosen:updated");;
|
||||
});
|
||||
|
||||
var assignee = $("#assignee").parents('td').find('select[name*=assignee]');
|
||||
var reviewer = $("#reviewer").parents('td').find('select[name*=reviewer]');
|
||||
usersUrl = createLink('gitlab', 'ajaxgetmruserpairs', "gitlabID=" + gitlabID);
|
||||
$.get(usersUrl, function(response)
|
||||
{
|
||||
assignee.html('').append(response);
|
||||
assignee.chosen().trigger("chosen:updated");;
|
||||
reviewer.html('').append(response);
|
||||
reviewer.chosen().trigger("chosen:updated");;
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
$('#sourceProject,#targetProject').change(function()
|
||||
{
|
||||
@@ -48,4 +36,21 @@ $(function()
|
||||
$('#targetProject').chosen().trigger("chosen:updated");;
|
||||
});
|
||||
});
|
||||
|
||||
$('#targetProject').change(function()
|
||||
{
|
||||
targetProject = $(this).val();
|
||||
var assignee = $("#assignee").parents('td').find('select[name*=assignee]');
|
||||
var reviewer = $("#reviewer").parents('td').find('select[name*=reviewer]');
|
||||
usersUrl = createLink('gitlab', 'ajaxgetmruserpairs', "gitlabID=" + gitlabID + "&projectID=" + targetProject);
|
||||
$.get(usersUrl, function(response)
|
||||
{
|
||||
assignee.html('').append(response);
|
||||
assignee.chosen().trigger("chosen:updated");;
|
||||
reviewer.html('').append(response);
|
||||
reviewer.chosen().trigger("chosen:updated");;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
@@ -30,7 +30,7 @@ $lang->mr->statusList['merged'] = '已合并';
|
||||
$lang->mr->mergeStatusList = array();
|
||||
$lang->mr->mergeStatusList['checking'] = '检查中';
|
||||
$lang->mr->mergeStatusList['can_be_merged'] = '可合并';
|
||||
$lang->mr->mergeStatusList['cannot_be_merged'] = '不可合并';
|
||||
$lang->mr->mergeStatusList['cannot_be_merged'] = '不可自动合并';
|
||||
|
||||
$lang->mr->description = '描述';
|
||||
$lang->mr->confirmDelete = '确认删除该合并请求吗?';
|
||||
@@ -68,6 +68,10 @@ $lang->mr->hasConflicts = "存在合并冲突";
|
||||
$lang->mr->hasNoConflict = "可以合并请求";
|
||||
$lang->mr->mergeByManual = "此合并请求可以手动合并,请使用以下";
|
||||
$lang->mr->commandLine = "合并命令";
|
||||
$lang->mr->acceptMR = "合并";
|
||||
$lang->mr->mergeFailed = "无法合并,请核对合并请求状态";
|
||||
$lang->mr->mergeSuccess = "已成功合并";
|
||||
|
||||
|
||||
/**
|
||||
* Merge Command Document.
|
||||
@@ -80,7 +84,7 @@ $lang->mr->commandLine = "合并命令";
|
||||
* %s mr::target_branch
|
||||
*/
|
||||
$lang->mr->commandDocument = <<< EOD
|
||||
<div class='detail-title'>在本地检出、审核和合并</div>
|
||||
<div class='detail-title'>在本地检出、审核和手动合并</div>
|
||||
<div class='detail-content'>
|
||||
<p>
|
||||
第 1 步. 获取并查看此合并请求的分支
|
||||
|
||||
+10
-8
@@ -153,15 +153,16 @@ class mrModel extends model
|
||||
|
||||
/* Update MR in GitLab. */
|
||||
$newMR = new stdclass;
|
||||
$newMR->title = $MR->title;
|
||||
$newMR->description = $MR->description;
|
||||
$newMR->assignee = $MR->assignee;
|
||||
$newMR->reviewer = $MR->reviewer;
|
||||
$newMR->targetBranch = $MR->targetBranch;
|
||||
$newMR->title = $MR->title;
|
||||
$newMR->description = $MR->description;
|
||||
$newMR->assignee_ids = $MR->assignee;
|
||||
$newMR->reviewer_ids = $MR->reviewer;
|
||||
$newMR->target_branch = $MR->targetBranch;
|
||||
|
||||
$oldMR = $this->getByID($MRID);
|
||||
|
||||
$this->apiUpdateMR($oldMR->gitlabID, $oldMR->targetProject, $oldMR->mriid, $newMR);
|
||||
/* 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);
|
||||
@@ -173,6 +174,7 @@ class mrModel extends model
|
||||
->where('id')->eq($MRID)
|
||||
->autoCheck()
|
||||
->exec();
|
||||
$MR = $this->getByID($MRID);
|
||||
|
||||
if(dao::isError()) return array('result' => 'fail', 'message' => dao::getError());
|
||||
return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => helper::createLink('mr', 'browse'));
|
||||
@@ -314,8 +316,8 @@ class mrModel extends model
|
||||
*/
|
||||
public function apiAcceptMR($gitlabID, $projectID, $MRID)
|
||||
{
|
||||
$url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID");
|
||||
return json_decode(commonModel::http($url, $data, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT')));
|
||||
$url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests/$MRID/merge");
|
||||
return json_decode(commonModel::http($url, array(), $options = array(CURLOPT_CUSTOMREQUEST => 'PUT')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
<div><?php echo $lang->mr->from . html::a($sourceProjectURL, $sourceProjectName . ":" . $MR->sourceBranch, "_blank", "class='btn btn-link btn-active-text' style='color: blue'") . $lang->mr->to . html::a($targetProjectURL, $targetProjectName . ":" . $MR->targetBranch, "_blank", "class='btn btn-link btn-active-text' style='color: blue'");?></div>
|
||||
</div>
|
||||
<div class="detail-content article-content">
|
||||
<strong><?php echo $lang->mr->status;?></strong>
|
||||
<?php echo zget($lang->mr->statusList, $MR->status);?>
|
||||
<br>
|
||||
<?php if(isset($rawMR->head_pipeline->status)):?>
|
||||
<div>
|
||||
<strong><?php echo "{$lang->mr->pipeline}{$lang->mr->status}";?></strong>
|
||||
@@ -51,8 +54,12 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php if($rawMR->state == 'opened'):?>
|
||||
<div class="cell"><?php echo sprintf($lang->mr->commandDocument, $httpRepoURL, $MR->sourceBranch, $branchPath, $MR->targetBranch, $branchPath, $MR->targetBranch);?></div>
|
||||
<?php endif;?>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<?php if($rawMR->state == 'opened' and !$rawMR->has_conflicts) echo html::linkButton('<i class="icon icon-checked"></i> ' . $lang->mr->acceptMR, inlink( 'accept', "mr=$MR->id"), 'self', '', 'btn btn-wide btn-primary');?>
|
||||
<?php endif;?>
|
||||
<?php include '../../common/view/footer.html.php';?>
|
||||
|
||||
Reference in New Issue
Block a user