* Modify merge request view.
This commit is contained in:
@@ -3127,7 +3127,7 @@ EOD;
|
||||
if(!empty($data))
|
||||
{
|
||||
if(is_object($data)) $data = (array) $data;
|
||||
if($method == 'POST') curl_setopt($curl, CURLOPT_POST, true);
|
||||
if($method == 'POST') curl_setopt($curl, CURLOPT_POST, true);
|
||||
if(in_array($method, array('PATCH', 'PUT'))) curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
}
|
||||
|
||||
+26
-2
@@ -376,8 +376,17 @@ class giteaModel extends model
|
||||
$apiRoot = $this->getApiRoot($giteaID);
|
||||
if(!$apiRoot) return array();
|
||||
|
||||
$url = sprintf($apiRoot, "/repos/$projectID");
|
||||
return json_decode(commonModel::http($url));
|
||||
$url = sprintf($apiRoot, "/repos/$projectID");
|
||||
$project = json_decode(commonModel::http($url));
|
||||
if(isset($project->name))
|
||||
{
|
||||
$project->name_with_namespace = $project->full_name;
|
||||
$project->path_with_namespace = $project->full_name;
|
||||
$project->http_url_to_repo = $project->html_url;
|
||||
$project->name_with_namespace = $project->full_name;
|
||||
}
|
||||
|
||||
return $project;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -542,4 +551,19 @@ class giteaModel extends model
|
||||
->andWhere('providerID')->eq($giteaID)
|
||||
->fetchPairs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single branch by API.
|
||||
*
|
||||
* @param int $giteaID
|
||||
* @param int $projectID
|
||||
* @param string $branch
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function apiGetSingleBranch($giteaID, $projectID, $branch)
|
||||
{
|
||||
$url = sprintf($this->getApiRoot($giteaID), "/repos/$projectID/branches/$branch");
|
||||
return json_decode(commonModel::http($url));
|
||||
}
|
||||
}
|
||||
|
||||
+9
-20
@@ -40,7 +40,6 @@ class mr extends control
|
||||
$repoID = $this->repo->saveState($repoID, $objectID);
|
||||
$repo = $this->repo->getRepoByID($repoID);
|
||||
if(!in_array(strtolower($repo->SCM), $this->config->mr->gitServiceList)) $repo = $repos[0];
|
||||
if($repo->SCM != 'Gitlab') unset($this->lang->mr->statusList['merged']);
|
||||
$this->loadModel('ci')->setMenu($repo->id);
|
||||
|
||||
$projects = $this->mr->getAllProjects($repoID, $repo->SCM);
|
||||
@@ -242,20 +241,22 @@ class mr extends control
|
||||
if(isset($MR->hostID)) $rawMR = $this->mr->apiGetSingleMR($MR->hostID, $MR->targetProject, $MR->mriid);
|
||||
if($MR->synced and (!isset($rawMR->id) or (isset($rawMR->message) and $rawMR->message == '404 Not found') or empty($rawMR))) return $this->display();
|
||||
|
||||
$this->loadModel('gitlab');
|
||||
$host = $this->loadModel('pipeline')->getByID($MR->hostID);
|
||||
$scm = $host->type;
|
||||
$this->loadModel($scm);
|
||||
$this->loadModel('job');
|
||||
|
||||
/* Sync MR from GitLab to ZentaoPMS. */
|
||||
$MR = $this->mr->apiSyncMR($MR);
|
||||
$sourceProject = $this->gitlab->apiGetSingleProject($MR->hostID, $MR->sourceProject);
|
||||
$targetProject = $this->gitlab->apiGetSingleProject($MR->hostID, $MR->targetProject);
|
||||
$sourceBranch = $this->gitlab->apiGetSingleBranch($MR->hostID, $MR->sourceProject, $MR->sourceBranch);
|
||||
$targetBranch = $this->gitlab->apiGetSingleBranch($MR->hostID, $MR->targetProject, $MR->targetBranch);
|
||||
$sourceProject = $this->$scm->apiGetSingleProject($MR->hostID, $MR->sourceProject);
|
||||
$targetProject = $this->$scm->apiGetSingleProject($MR->hostID, $MR->targetProject);
|
||||
$sourceBranch = $this->$scm->apiGetSingleBranch($MR->hostID, $MR->sourceProject, $MR->sourceBranch);
|
||||
$targetBranch = $this->$scm->apiGetSingleBranch($MR->hostID, $MR->targetProject, $MR->targetBranch);
|
||||
|
||||
$projectOwner = true;
|
||||
if(isset($MR->hostID) and !$this->app->user->admin)
|
||||
{
|
||||
$openID = $this->gitlab->getUserIDByZentaoAccount($MR->hostID, $this->app->user->account);
|
||||
$openID = $this->$scm->getUserIDByZentaoAccount($MR->hostID, $this->app->user->account);
|
||||
if(!$projectOwner and isset($sourceProject->owner->id) and $sourceProject->owner->id == $openID) $projectOwner = true;
|
||||
}
|
||||
|
||||
@@ -336,22 +337,10 @@ class mr extends control
|
||||
}
|
||||
}
|
||||
|
||||
/* Accept MR by using the mapped user in GitLab. */
|
||||
$sudoUser = $this->mr->getSudoUsername($MR->hostID, $MR->targetProject);
|
||||
|
||||
if(isset($MR->hostID))
|
||||
{
|
||||
if(!empty($sudoUser)) $rawMR = $this->mr->apiAcceptMR($MR->hostID, $MR->targetProject, $MR->mriid, $sudoUser);
|
||||
if(empty($sudoUser)) $rawMR = $this->mr->apiAcceptMR($MR->hostID, $MR->targetProject, $MR->mriid);
|
||||
}
|
||||
if(isset($MR->hostID)) $rawMR = $this->mr->apiAcceptMR($MR->hostID, $MR->targetProject, $MR->mriid, $MR);
|
||||
if(isset($rawMR->state) and $rawMR->state == 'merged')
|
||||
{
|
||||
///* Force reload when locate to the url. */
|
||||
//$random = uniqid();
|
||||
//return $this->send(array('result' => 'success', 'message' => $this->lang->mr->mergeSuccess, 'locate' => helper::createLink('mr', 'browse', "random={$random}")));
|
||||
|
||||
$this->mr->logMergedAction($MR);
|
||||
|
||||
return $this->send(array('result' => 'success', 'message' => $this->lang->mr->mergeSuccess, 'locate' => helper::createLink('mr', 'browse')));
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ $lang->mr->source = 'source';
|
||||
$lang->mr->target = 'target';
|
||||
$lang->mr->viewDiff = 'View diff';
|
||||
$lang->mr->diff = 'View diff';
|
||||
$lang->mr->viewInGitlab = 'View in GitLab';
|
||||
$lang->mr->viewInGit = 'View in APP';
|
||||
$lang->mr->link = 'Link of stories,Bugs,tasks';
|
||||
$lang->mr->createAction = '%s, <strong>%s</strong> submitted a <a href="%s">Merge Request</a>.';
|
||||
|
||||
@@ -39,8 +39,8 @@ $lang->mr->gitlabID = 'GitLab';
|
||||
$lang->mr->repoID = 'Repo';
|
||||
$lang->mr->jobID = 'Compile job';
|
||||
|
||||
$lang->mr->canMerge = "Can merge";
|
||||
$lang->mr->cantMerge = "不可合并";
|
||||
$lang->mr->canMerge = "Can be merged";
|
||||
$lang->mr->cantMerge = "Can not be merged";
|
||||
|
||||
$lang->mr->approval = 'Approval';
|
||||
$lang->mr->approve = 'Approve';
|
||||
@@ -117,11 +117,15 @@ $lang->mr->apiErrorMap[1] = "You can't use same project/branch for source and ta
|
||||
$lang->mr->apiErrorMap[2] = "/Another open merge request already exists for this source branch: !([0-9]+)/";
|
||||
$lang->mr->apiErrorMap[3] = "401 Unauthorized";
|
||||
$lang->mr->apiErrorMap[4] = "403 Forbidden";
|
||||
$lang->mr->apiErrorMap[5] = "/(pull request already exists for these targets).*/";
|
||||
$lang->mr->apiErrorMap[6] = "Invalid PullRequest: There are no changes between the head and the base";
|
||||
|
||||
$lang->mr->errorLang[1] = 'The source project branch cannot be the same as the target project branch';
|
||||
$lang->mr->errorLang[2] = 'Another open merge request already exists for this source branch: ID%u';
|
||||
$lang->mr->errorLang[3] = "Unauthorized";
|
||||
$lang->mr->errorLang[4] = 'Permission denied';
|
||||
$lang->mr->errorLang[5] = 'Another open merge request already exists for this source branch';
|
||||
$lang->mr->errorLang[6] = 'The source project branch cannot be the same as the target project branch';
|
||||
|
||||
$lang->mr->from = "from";
|
||||
$lang->mr->to = "to";
|
||||
@@ -178,7 +182,7 @@ $lang->mr->commandDocument = <<< EOD
|
||||
git merge --no-ff "%s"</pre>
|
||||
</p>
|
||||
<p>
|
||||
step 4. Push the result of the merge to GitLab
|
||||
step 4. Push the result of the merge to Git
|
||||
<pre> git push origin "%s" </pre>
|
||||
</p>
|
||||
</div>
|
||||
@@ -186,7 +190,7 @@ EOD;
|
||||
|
||||
$lang->mr->noChanges = "Currently there are no changes in this merge request's source branch. Please push new commits or use a different branch.";
|
||||
|
||||
$lang->mr->linkTask = 'Link Tasks';
|
||||
$lang->mr->linkTask = "Link task";
|
||||
$lang->mr->unlinkTask = "Remove task";
|
||||
$lang->mr->linkedTasks = 'Task';
|
||||
$lang->mr->unlinkedTasks = 'Task not linked';
|
||||
|
||||
@@ -14,7 +14,7 @@ $lang->mr->source = 'source';
|
||||
$lang->mr->target = 'target';
|
||||
$lang->mr->viewDiff = 'View diff';
|
||||
$lang->mr->diff = 'View diff';
|
||||
$lang->mr->viewInGitlab = 'View in GitLab';
|
||||
$lang->mr->viewInGit = 'View in APP';
|
||||
$lang->mr->link = 'Link of stories,Bugs,tasks';
|
||||
$lang->mr->createAction = '%s, <strong>%s</strong> submitted a <a href="%s">Merge Request</a>.';
|
||||
|
||||
@@ -39,8 +39,8 @@ $lang->mr->gitlabID = 'GitLab';
|
||||
$lang->mr->repoID = 'Repo';
|
||||
$lang->mr->jobID = 'Compile job';
|
||||
|
||||
$lang->mr->canMerge = "Can merge";
|
||||
$lang->mr->cantMerge = "不可合并";
|
||||
$lang->mr->canMerge = "Can be merged";
|
||||
$lang->mr->cantMerge = "Can not be merged";
|
||||
|
||||
$lang->mr->approval = 'Approval';
|
||||
$lang->mr->approve = 'Approve';
|
||||
@@ -182,7 +182,7 @@ $lang->mr->commandDocument = <<< EOD
|
||||
git merge --no-ff "%s"</pre>
|
||||
</p>
|
||||
<p>
|
||||
step 4. Push the result of the merge to GitLab
|
||||
step 4. Push the result of the merge to Git
|
||||
<pre> git push origin "%s" </pre>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -14,7 +14,7 @@ $lang->mr->source = 'source';
|
||||
$lang->mr->target = 'target';
|
||||
$lang->mr->viewDiff = 'View diff';
|
||||
$lang->mr->diff = 'View diff';
|
||||
$lang->mr->viewInGitlab = 'View in GitLab';
|
||||
$lang->mr->viewInGit = 'View in APP';
|
||||
$lang->mr->link = 'Link of stories,Bugs,tasks';
|
||||
$lang->mr->createAction = '%s, <strong>%s</strong> submitted a <a href="%s">Merge Request</a>.';
|
||||
|
||||
@@ -39,8 +39,8 @@ $lang->mr->gitlabID = 'GitLab';
|
||||
$lang->mr->repoID = 'Repo';
|
||||
$lang->mr->jobID = 'Compile job';
|
||||
|
||||
$lang->mr->canMerge = "Can merge";
|
||||
$lang->mr->cantMerge = "不可合并";
|
||||
$lang->mr->canMerge = "Can be merged";
|
||||
$lang->mr->cantMerge = "Can not be merged";
|
||||
|
||||
$lang->mr->approval = 'Approval';
|
||||
$lang->mr->approve = 'Approve';
|
||||
@@ -117,11 +117,15 @@ $lang->mr->apiErrorMap[1] = "You can't use same project/branch for source and ta
|
||||
$lang->mr->apiErrorMap[2] = "/Another open merge request already exists for this source branch: !([0-9]+)/";
|
||||
$lang->mr->apiErrorMap[3] = "401 Unauthorized";
|
||||
$lang->mr->apiErrorMap[4] = "403 Forbidden";
|
||||
$lang->mr->apiErrorMap[5] = "/(pull request already exists for these targets).*/";
|
||||
$lang->mr->apiErrorMap[6] = "Invalid PullRequest: There are no changes between the head and the base";
|
||||
|
||||
$lang->mr->errorLang[1] = 'The source project branch cannot be the same as the target project branch';
|
||||
$lang->mr->errorLang[2] = 'Another open merge request already exists for this source branch: ID%u';
|
||||
$lang->mr->errorLang[3] = "Unauthorized";
|
||||
$lang->mr->errorLang[4] = 'Permission denied';
|
||||
$lang->mr->errorLang[5] = 'Another open merge request already exists for this source branch';
|
||||
$lang->mr->errorLang[6] = 'The source project branch cannot be the same as the target project branch';
|
||||
|
||||
$lang->mr->from = "from";
|
||||
$lang->mr->to = "to";
|
||||
@@ -178,7 +182,7 @@ $lang->mr->commandDocument = <<< EOD
|
||||
git merge --no-ff "%s"</pre>
|
||||
</p>
|
||||
<p>
|
||||
step 4. Push the result of the merge to GitLab
|
||||
step 4. Push the result of the merge to Git
|
||||
<pre> git push origin "%s" </pre>
|
||||
</p>
|
||||
</div>
|
||||
@@ -186,7 +190,7 @@ EOD;
|
||||
|
||||
$lang->mr->noChanges = "Currently there are no changes in this merge request's source branch. Please push new commits or use a different branch.";
|
||||
|
||||
$lang->mr->linkTask = 'Link Tasks';
|
||||
$lang->mr->linkTask = "Link task";
|
||||
$lang->mr->unlinkTask = "Remove task";
|
||||
$lang->mr->linkedTasks = 'Task';
|
||||
$lang->mr->unlinkedTasks = 'Task not linked';
|
||||
|
||||
@@ -14,7 +14,7 @@ $lang->mr->source = 'source';
|
||||
$lang->mr->target = 'target';
|
||||
$lang->mr->viewDiff = 'View diff';
|
||||
$lang->mr->diff = 'View diff';
|
||||
$lang->mr->viewInGitlab = 'View in GitLab';
|
||||
$lang->mr->viewInGit = 'View in APP';
|
||||
$lang->mr->link = 'Link of stories,Bugs,tasks';
|
||||
$lang->mr->createAction = '%s, <strong>%s</strong> submitted a <a href="%s">Merge Request</a>.';
|
||||
|
||||
@@ -39,8 +39,8 @@ $lang->mr->gitlabID = 'GitLab';
|
||||
$lang->mr->repoID = 'Repo';
|
||||
$lang->mr->jobID = 'Compile job';
|
||||
|
||||
$lang->mr->canMerge = "Can merge";
|
||||
$lang->mr->cantMerge = "不可合并";
|
||||
$lang->mr->canMerge = "Can be merged";
|
||||
$lang->mr->cantMerge = "Can not be merged";
|
||||
|
||||
$lang->mr->approval = 'Approval';
|
||||
$lang->mr->approve = 'Approve';
|
||||
@@ -117,11 +117,15 @@ $lang->mr->apiErrorMap[1] = "You can't use same project/branch for source and ta
|
||||
$lang->mr->apiErrorMap[2] = "/Another open merge request already exists for this source branch: !([0-9]+)/";
|
||||
$lang->mr->apiErrorMap[3] = "401 Unauthorized";
|
||||
$lang->mr->apiErrorMap[4] = "403 Forbidden";
|
||||
$lang->mr->apiErrorMap[5] = "/(pull request already exists for these targets).*/";
|
||||
$lang->mr->apiErrorMap[6] = "Invalid PullRequest: There are no changes between the head and the base";
|
||||
|
||||
$lang->mr->errorLang[1] = 'The source project branch cannot be the same as the target project branch';
|
||||
$lang->mr->errorLang[2] = 'Another open merge request already exists for this source branch: ID%u';
|
||||
$lang->mr->errorLang[3] = "Unauthorized";
|
||||
$lang->mr->errorLang[4] = 'Permission denied';
|
||||
$lang->mr->errorLang[5] = 'Another open merge request already exists for this source branch';
|
||||
$lang->mr->errorLang[6] = 'The source project branch cannot be the same as the target project branch';
|
||||
|
||||
$lang->mr->from = "from";
|
||||
$lang->mr->to = "to";
|
||||
@@ -178,7 +182,7 @@ $lang->mr->commandDocument = <<< EOD
|
||||
git merge --no-ff "%s"</pre>
|
||||
</p>
|
||||
<p>
|
||||
step 4. Push the result of the merge to GitLab
|
||||
step 4. Push the result of the merge to Git
|
||||
<pre> git push origin "%s" </pre>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -14,7 +14,7 @@ $lang->mr->source = '源项目分支';
|
||||
$lang->mr->target = '目标项目分支';
|
||||
$lang->mr->viewDiff = '比对代码';
|
||||
$lang->mr->diff = '比对代码';
|
||||
$lang->mr->viewInGitlab = '在GitLab查看';
|
||||
$lang->mr->viewInGit = '在应用中查看';
|
||||
$lang->mr->link = '关联需求、Bug、任务';
|
||||
$lang->mr->createAction = '%s, 由 <strong>%s</strong> 提交了 <a href="%s">合并请求</a>。';
|
||||
|
||||
@@ -182,7 +182,7 @@ $lang->mr->commandDocument = <<< EOD
|
||||
git merge --no-ff "%s"</pre>
|
||||
</p>
|
||||
<p>
|
||||
第 4 步. 将合并结果推送到GitLab
|
||||
第 4 步. 将合并结果推送到Git
|
||||
<pre> git push origin "%s" </pre>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
+165
-56
@@ -669,6 +669,7 @@ class mrModel extends model
|
||||
if(!$mergeResult->mergeable) $mergeResult->merge_status = 'cannot_be_merged';
|
||||
}
|
||||
if(isset($mergeResult->state) and $mergeResult->state == 'open') $mergeResult->state = 'opened';
|
||||
if(isset($mergeResult->merged) and $mergeResult->merged) $mergeResult->state = 'merged';
|
||||
return $mergeResult;
|
||||
}
|
||||
}
|
||||
@@ -697,16 +698,18 @@ class mrModel extends model
|
||||
if(empty($response)) $response = array();
|
||||
if($scm == 'Gitea')
|
||||
{
|
||||
foreach($response as $mr)
|
||||
foreach($response as $MR)
|
||||
{
|
||||
$mr->iid = $mr->number;
|
||||
$mr->state = $mr->state == 'open' ? 'opened' : $mr->state;
|
||||
$mr->merge_status = $mr->mergeable ? 'can_be_merged' : 'cannot_be_merged';
|
||||
$mr->description = $mr->body;
|
||||
$mr->target_branch = $mr->base->ref;
|
||||
$mr->source_branch = $mr->head->ref;
|
||||
$mr->source_project_id = $projectID;
|
||||
$mr->target_project_id = $projectID;
|
||||
$MR->iid = $MR->number;
|
||||
$MR->state = $MR->state == 'open' ? 'opened' : $MR->state;
|
||||
if($MR->merged) $MR->state = 'merged';
|
||||
|
||||
$MR->merge_status = $MR->mergeable ? 'can_be_merged' : 'cannot_be_merged';
|
||||
$MR->description = $MR->body;
|
||||
$MR->target_branch = $MR->base->ref;
|
||||
$MR->source_branch = $MR->head->ref;
|
||||
$MR->source_project_id = $projectID;
|
||||
$MR->target_project_id = $projectID;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -733,10 +736,10 @@ class mrModel extends model
|
||||
|
||||
if($response)
|
||||
{
|
||||
foreach($response as $mr)
|
||||
foreach($response as $MR)
|
||||
{
|
||||
if(empty($mr->source_project_id) or empty($mr->target_project_id)) return null;
|
||||
if($mr->source_project_id == $sourceProject and $mr->target_project_id == $targetProject) return $mr;
|
||||
if(empty($MR->source_project_id) or empty($MR->target_project_id)) return null;
|
||||
if($MR->source_project_id == $sourceProject and $MR->target_project_id == $targetProject) return $MMRR;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -764,6 +767,24 @@ class mrModel extends model
|
||||
{
|
||||
$url = sprintf($this->loadModel('gitea')->getApiRoot($hostID), "/repos/$projectID/pulls/$MRID");
|
||||
$MR = json_decode(commonModel::http($url));
|
||||
if(isset($MR->url))
|
||||
{
|
||||
$diff = $this->apiGetDiffs($hostID, $projectID, $MRID);
|
||||
|
||||
$MR->web_url = $MR->url;
|
||||
$MR->iid = $MR->number;
|
||||
$MR->state = $MR->state == 'open' ? 'opened' : $MR->state;
|
||||
if($MR->merged) $MR->state = 'merged';
|
||||
|
||||
$MR->merge_status = $MR->mergeable ? 'can_be_merged' : 'cannot_be_merged';
|
||||
$MR->changes_count = (int)$diff;
|
||||
$MR->description = $MR->body;
|
||||
$MR->target_branch = $MR->base->ref;
|
||||
$MR->source_branch = $MR->head->ref;
|
||||
$MR->source_project_id = $projectID;
|
||||
$MR->target_project_id = $projectID;
|
||||
$MR->has_conflicts = !(bool)$diff;
|
||||
}
|
||||
|
||||
return $MR;
|
||||
}
|
||||
@@ -835,6 +856,7 @@ class mrModel extends model
|
||||
if(!$mergeResult->mergeable) $mergeResult->merge_status = 'cannot_be_merged';
|
||||
}
|
||||
if(isset($mergeResult->state) and $mergeResult->state == 'open') $mergeResult->state = 'opened';
|
||||
if(isset($mergeResult->merged) and $mergeResult->merged) $mergeResult->state = 'merged';
|
||||
return $mergeResult;
|
||||
}
|
||||
}
|
||||
@@ -876,8 +898,17 @@ class mrModel extends model
|
||||
*/
|
||||
public function apiCloseMR($hostID, $projectID, $MRID)
|
||||
{
|
||||
$url = sprintf($this->gitlab->getApiRoot($hostID), "/projects/$projectID/merge_requests/$MRID") . '&state_event=close';
|
||||
return json_decode(commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'PUT')));
|
||||
$host = $this->loadModel('pipeline')->getByID($hostID);
|
||||
if($host->type == 'gitlab')
|
||||
{
|
||||
$url = sprintf($this->gitlab->getApiRoot($hostID), "/projects/$projectID/merge_requests/$MRID") . '&state_event=close';
|
||||
return json_decode(commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'PUT')));
|
||||
}
|
||||
else
|
||||
{
|
||||
$url = sprintf($this->loadModel('gitea')->getApiRoot($hostID), "/repos/$projectID/pulls/$MRID");
|
||||
return json_decode(commonModel::http($url, array('state' => 'closed'), array(), array(), 'json', 'PATCH'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -892,8 +923,29 @@ class mrModel extends model
|
||||
*/
|
||||
public function apiReopenMR($hostID, $projectID, $MRID)
|
||||
{
|
||||
$url = sprintf($this->gitlab->getApiRoot($hostID), "/projects/$projectID/merge_requests/$MRID") . '&state_event=reopen';
|
||||
return json_decode(commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'PUT')));
|
||||
$host = $this->loadModel('pipeline')->getByID($hostID);
|
||||
if($host->type == 'gitlab')
|
||||
{
|
||||
$url = sprintf($this->gitlab->getApiRoot($hostID), "/projects/$projectID/merge_requests/$MRID") . '&state_event=reopen';
|
||||
return json_decode(commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'PUT')));
|
||||
}
|
||||
else
|
||||
{
|
||||
$url = sprintf($this->loadModel('gitea')->getApiRoot($hostID), "/repos/$projectID/pulls/$MRID");
|
||||
$MR = json_decode(commonModel::http($url, array('state' => 'open'), array(), array(), 'json', 'PATCH'));
|
||||
$MR->iid = $MR->number;
|
||||
$MR->state = $MR->state == 'open' ? 'opened' : $MR->state;
|
||||
if($MR->merged) $MR->state = 'merged';
|
||||
|
||||
$MR->merge_status = $MR->mergeable ? 'can_be_merged' : 'cannot_be_merged';
|
||||
$MR->description = $MR->body;
|
||||
$MR->target_branch = $MR->base->ref;
|
||||
$MR->source_branch = $MR->head->ref;
|
||||
$MR->source_project_id = $projectID;
|
||||
$MR->target_project_id = $projectID;
|
||||
|
||||
return $MR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -903,19 +955,44 @@ class mrModel extends model
|
||||
* @param int $hostID
|
||||
* @param int $projectID
|
||||
* @param int $MRID
|
||||
* @param string $sudo
|
||||
* @param object $MR
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function apiAcceptMR($hostID, $projectID, $MRID, $sudo = "")
|
||||
public function apiAcceptMR($hostID, $projectID, $MRID, $MR = null)
|
||||
{
|
||||
$apiRoot = $this->gitlab->getApiRoot($hostID);
|
||||
$approveUrl = sprintf($apiRoot, "/projects/$projectID/merge_requests/$MRID/approved");
|
||||
commonModel::http($approveUrl, null, array(CURLOPT_CUSTOMREQUEST => 'POST'));
|
||||
$host = $this->loadModel('pipeline')->getByID($hostID);
|
||||
if($host->type == 'gitlab')
|
||||
{
|
||||
$apiRoot = $this->gitlab->getApiRoot($hostID);
|
||||
$approveUrl = sprintf($apiRoot, "/projects/$projectID/merge_requests/$MRID/approved");
|
||||
commonModel::http($approveUrl, null, array(CURLOPT_CUSTOMREQUEST => 'POST'));
|
||||
|
||||
$url = sprintf($apiRoot, "/projects/$projectID/merge_requests/$MRID/merge");
|
||||
if($sudo != "") return json_decode(commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'PUT'), $headers = array("sudo: {$sudo}")));
|
||||
return json_decode(commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'PUT')));
|
||||
$url = sprintf($apiRoot, "/projects/$projectID/merge_requests/$MRID/merge");
|
||||
return json_decode(commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'PUT')));
|
||||
}
|
||||
elseif($host->type == 'gitea')
|
||||
{
|
||||
$apiRoot = $this->loadModel('gitea')->getApiRoot($hostID);
|
||||
$url = sprintf($apiRoot, "/repos/$projectID/pulls/$MRID/merge");
|
||||
$rowMR = json_decode(commonModel::http($url, array('Do' => 'merge'), array(), array(), 'json', 'POST'));
|
||||
if(!isset($rowMR->massage))
|
||||
{
|
||||
$rowMR = $this->apiGetSingleMR($hostID, $projectID, $MRID);
|
||||
|
||||
$this->dao->update(TABLE_MR)->data(array('status' => 'merged'))
|
||||
->where('id')->eq($MRID)
|
||||
->autoCheck()
|
||||
->exec();
|
||||
|
||||
if($MR and $MR->removeSourceBranch == '1')
|
||||
{
|
||||
$url = sprintf($apiRoot, "/repos/$projectID/branches/{$MR->sourceBranch}");
|
||||
json_decode(commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'DELETE')));
|
||||
}
|
||||
}
|
||||
return $rowMR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -930,40 +1007,49 @@ class mrModel extends model
|
||||
public function getDiffs($MR, $encoding = '')
|
||||
{
|
||||
$diffVersions = array();
|
||||
if($MR->synced) $diffVersions = $this->apiGetDiffVersions($MR->hostID, $MR->targetProject, $MR->mriid);
|
||||
|
||||
$gitlab = $this->gitlab->getByID($MR->hostID);
|
||||
$host = $this->loadModel('pipeline')->getByID($MR->hostID);
|
||||
$scm = $host->type;
|
||||
|
||||
$this->loadModel('repo');
|
||||
$repo = new stdclass;
|
||||
$repo->SCM = 'GitLab';
|
||||
$repo->gitlab = $gitlab->id;
|
||||
$repo->project = $MR->targetProject;
|
||||
$repo->path = sprintf($this->config->repo->gitlab->apiPath, $gitlab->url, $MR->targetProject);
|
||||
$repo->client = $gitlab->url;
|
||||
$repo->password = $gitlab->token;
|
||||
$repo->account = '';
|
||||
$repo->encoding = $encoding;
|
||||
$repo->SCM = $this->lang->repo->scmList[ucfirst($scm)];
|
||||
$repo->gitService = $host->id;
|
||||
$repo->project = $MR->targetProject;
|
||||
$repo->path = sprintf($this->config->repo->$scm->apiPath, $host->url, $MR->targetProject);
|
||||
$repo->client = $host->url;
|
||||
$repo->password = $host->token;
|
||||
$repo->account = '';
|
||||
$repo->encoding = $encoding;
|
||||
|
||||
$lines = array();
|
||||
$commitList = array();
|
||||
foreach($diffVersions as $diffVersion)
|
||||
if($scm == 'gitlab')
|
||||
{
|
||||
$singleDiff = $this->apiGetSingleDiffVersion($MR->hostID, $MR->targetProject, $MR->mriid, $diffVersion->id);
|
||||
if($singleDiff->state == 'empty') continue;
|
||||
|
||||
$commits = $singleDiff->commits;
|
||||
$diffs = $singleDiff->diffs;
|
||||
foreach($diffs as $index => $diff)
|
||||
if($MR->synced) $diffVersions = $this->apiGetDiffVersions($MR->hostID, $MR->targetProject, $MR->mriid);
|
||||
foreach($diffVersions as $diffVersion)
|
||||
{
|
||||
$lines[] = sprintf("diff --git a/%s b/%s", $diff->old_path, $diff->new_path);
|
||||
$lines[] = sprintf("index %s ... %s %s ", $singleDiff->head_commit_sha, $singleDiff->base_commit_sha, $diff->b_mode);
|
||||
$lines[] = sprintf("--a/%s", $diff->old_path);
|
||||
$lines[] = sprintf("--b/%s", $diff->new_path);
|
||||
$diffLines = explode("\n", $diff->diff);
|
||||
foreach($diffLines as $diffLine) $lines[] = $diffLine;
|
||||
$singleDiff = $this->apiGetSingleDiffVersion($MR->hostID, $MR->targetProject, $MR->mriid, $diffVersion->id);
|
||||
if($singleDiff->state == 'empty') continue;
|
||||
|
||||
$commits = $singleDiff->commits;
|
||||
$diffs = $singleDiff->diffs;
|
||||
foreach($diffs as $index => $diff)
|
||||
{
|
||||
$lines[] = sprintf("diff --git a/%s b/%s", $diff->old_path, $diff->new_path);
|
||||
$lines[] = sprintf("index %s ... %s %s ", $singleDiff->head_commit_sha, $singleDiff->base_commit_sha, $diff->b_mode);
|
||||
$lines[] = sprintf("--a/%s", $diff->old_path);
|
||||
$lines[] = sprintf("--b/%s", $diff->new_path);
|
||||
$diffLines = explode("\n", $diff->diff);
|
||||
foreach($diffLines as $diffLine) $lines[] = $diffLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$diffs = $this->apiGetDiffs($MR->hostID, $MR->targetProject, $MR->mriid);
|
||||
$lines = explode("\n", $diffs);
|
||||
}
|
||||
|
||||
if(empty($MR->synced))
|
||||
{
|
||||
@@ -1075,10 +1161,33 @@ class mrModel extends model
|
||||
*/
|
||||
public function apiGetDiffCommits($hostID, $projectID, $MRID)
|
||||
{
|
||||
$url = sprintf($this->gitlab->getApiRoot($hostID), "/projects/$projectID/merge_requests/$MRID/commits");
|
||||
$host = $this->loadModel('pipeline')->getByID($hostID);
|
||||
if($host->type == 'gitlab')
|
||||
{
|
||||
$url = sprintf($this->gitlab->getApiRoot($hostID), "/projects/$projectID/merge_requests/$MRID/commits");
|
||||
}
|
||||
else
|
||||
{
|
||||
$url = sprintf($this->loadModel('gitea')->getApiRoot($hostID), "/repos/$projectID/pulls/$MRID/commits");
|
||||
}
|
||||
return json_decode(commonModel::http($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get diff of MR from Gitea API.
|
||||
*
|
||||
* @param int $hostID
|
||||
* @param int $projectID
|
||||
* @param int $MRID
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function apiGetDiffs($hostID, $projectID, $MRID)
|
||||
{
|
||||
$url = sprintf($this->loadModel('gitea')->getApiRoot($hostID), "/repos/$projectID/pulls/$MRID.diff");
|
||||
return commonModel::http($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reject or Approve this MR.
|
||||
*
|
||||
@@ -1098,9 +1207,9 @@ class mrModel extends model
|
||||
$rawApprovalStatus = '';
|
||||
if(isset($MR->approvalStatus)) $rawApprovalStatus = $MR->approvalStatus;
|
||||
$MR->approver = $this->app->user->account;
|
||||
if ($action == 'reject' and $rawApprovalStatus != 'rejected') $MR->approvalStatus = 'rejected';
|
||||
if ($action == 'approve' and $rawApprovalStatus != 'approved') $MR->approvalStatus = 'approved';
|
||||
if (isset($MR->approvalStatus) and $rawApprovalStatus != $MR->approvalStatus)
|
||||
if($action == 'reject' and $rawApprovalStatus != 'rejected') $MR->approvalStatus = 'rejected';
|
||||
if($action == 'approve' and $rawApprovalStatus != 'approved') $MR->approvalStatus = 'approved';
|
||||
if(isset($MR->approvalStatus) and $rawApprovalStatus != $MR->approvalStatus)
|
||||
{
|
||||
$changes = common::createChanges($oldMR, $MR);
|
||||
$this->action->logHistory($actionID, $changes);
|
||||
@@ -1731,13 +1840,13 @@ class mrModel extends model
|
||||
/**
|
||||
* Get toList and ccList.
|
||||
*
|
||||
* @param object $mr
|
||||
* @param object $MR
|
||||
* @access public
|
||||
* @return bool|array
|
||||
*/
|
||||
public function getToAndCcList($mr)
|
||||
public function getToAndCcList($MR)
|
||||
{
|
||||
return array($mr->createdBy, $mr->assignee);
|
||||
return array($MR->createdBy, $MR->assignee);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1798,8 +1907,8 @@ class mrModel extends model
|
||||
->fetch('id');
|
||||
if(!empty($dbOpenedID)) return array('result' => 'fail', 'message' => sprintf($this->lang->mr->hasSameOpenedMR, $dbOpenedID));
|
||||
|
||||
$mr = $this->apiGetSameOpened($hostID, $sourceProject, $sourceBranch, $targetProject, $targetBranch);
|
||||
if($mr) return array('result' => 'fail', 'message' => sprintf($this->lang->mr->errorLang[2], $mr->iid));
|
||||
$MR = $this->apiGetSameOpened($hostID, $sourceProject, $sourceBranch, $targetProject, $targetBranch);
|
||||
if($MR) return array('result' => 'fail', 'message' => sprintf($this->lang->mr->errorLang[2], $MR->iid));
|
||||
return array('result' => 'success');
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<span class="label label-id"><?php echo $MR->id ?></span>
|
||||
<span class="text" title='<?php echo $MR->title; ?>'><?php echo $MR->title; ?></span>
|
||||
<?php if($MR->synced):?>
|
||||
<span class="text" title='<?php echo $MR->title; ?>' style='color: blue'><?php echo html::a($rawMR->web_url, $lang->mr->viewInGitlab, "_blank", "class='btn btn-link btn-active-text' style='color: blue'"); ?></span>
|
||||
<span class="text" title='<?php echo $MR->title; ?>' style='color: blue'><?php echo html::a($rawMR->web_url, $lang->mr->viewInGit, "_blank", "class='btn btn-link btn-active-text' style='color: blue'"); ?></span>
|
||||
<?php endif;?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -85,7 +85,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php echo $lang->mr->MRHasConflicts; ?></th>
|
||||
<?php $hasNoConflict = $MR->synced === '1' ? $rawMR->has_conflicts : (bool)$MR->hasNoConflict; ?>
|
||||
<?php $hasNoConflict = $MR->synced === '1' ? $rawMR->has_conflicts : (bool)$MR->hasNoConflict;?>
|
||||
<td><?php echo ($hasNoConflict ? $lang->mr->hasConflicts : $lang->mr->hasNoConflict);?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
Reference in New Issue
Block a user