diff --git a/lib/scm/gitfox.class.php b/lib/scm/gitfox.class.php index 3f6a0e5972..805b6a0951 100644 --- a/lib/scm/gitfox.class.php +++ b/lib/scm/gitfox.class.php @@ -943,7 +943,7 @@ class gitfoxRepo $MR->id = $MR->number; $MR->iid = $MR->number; $MR->state = $MR->state == 'open' ? 'opened' : $MR->state; - $MR->merge_status = $MR->merge_check_status ? 'cannot_be_merged' : 'can_be_merged'; + $MR->merge_status = $MR->merge_check_status != 'mergeable' ? 'cannot_be_merged' : 'can_be_merged'; $MR->changes_count = $MR->stats->commits; $MR->source_project_id = $MR->source_repo_id; $MR->target_project_id = $MR->target_repo_id; diff --git a/module/gitfox/model.php b/module/gitfox/model.php index 10b4d1e7fe..49b96e0b04 100644 --- a/module/gitfox/model.php +++ b/module/gitfox/model.php @@ -558,4 +558,25 @@ class gitfoxModel extends model return $matchedUsers; } + + /** + * 通过API删除GitFox分支。 + * Api delete branch. + * + * @param int $gitfoxID + * @param string $project + * @param string $branch + * @access public + * @return object|null + */ + public function apiDeleteBranch(int $gitfoxID, string $project, string $branch): object|null + { + if(empty($branch) || empty($project)) return null; + + $apiRoot = $this->getApiRoot($gitfoxID); + $url = sprintf($apiRoot->url, "/repos/$project/branches/$branch"); + if(!$url) return null; + + return json_decode(commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'DELETE'), $apiRoot->header)); + } } diff --git a/module/mr/config.php b/module/mr/config.php index cbf323f9a9..43ef6c3a9a 100644 --- a/module/mr/config.php +++ b/module/mr/config.php @@ -70,10 +70,11 @@ $config->mr->actionList['delete']['className'] = 'ajax-submit'; $config->mr->actionList['delete']['data-app'] = $app->tab; $config->mr->actionList['accept'] = array(); -$config->mr->actionList['accept']['icon'] = 'flow'; -$config->mr->actionList['accept']['text'] = $lang->mr->acceptMR; -$config->mr->actionList['accept']['url'] = helper::createLink('mr', 'accept', "MRID={id}"); -$config->mr->actionList['accept']['data-app'] = $app->tab; +$config->mr->actionList['accept']['icon'] = 'flow'; +$config->mr->actionList['accept']['text'] = $lang->mr->acceptMR; +$config->mr->actionList['accept']['url'] = helper::createLink('mr', 'accept', "MRID={id}"); +$config->mr->actionList['accept']['data-app'] = $app->tab; +$config->mr->actionList['accept']['className'] = 'ajax-submit'; $config->mr->actionList['approval'] = array(); $config->mr->actionList['approval']['icon'] = 'ok'; diff --git a/module/mr/model.php b/module/mr/model.php index d8f4a9bfa7..c435722be4 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -805,22 +805,27 @@ class mrModel extends model $url = sprintf($apiRoot, "/projects/$MR->targetProject/merge_requests/$MR->mriid/merge"); return json_decode(commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'PUT'))); } + elseif($host->type == 'gitfox') + { + $rowMR = $this->apiGetSingleMR($MR->repoID, $MR->mriid); + $url = sprintf($apiRoot->url, "/repos/$MR->targetProject/pullreq/$MR->mriid/merge"); + $data = array('dry_run' => false, 'bypass_rules' => false, 'source_sha' => $rowMR->source_sha, 'method' => $MR->squash == '1' ? 'squash' : 'merege'); + } else { - $url = sprintf($apiRoot, "/repos/$MR->targetProject/pulls/$MR->mriid/merge"); - $merge = $MR->squash == '1' ? 'squash' : 'merge'; - $data = array('Do' => $merge); + $url = sprintf($apiRoot, "/repos/$MR->targetProject/pulls/$MR->mriid/merge"); + $data = array('Do' => $MR->squash == '1' ? 'squash' : 'merge'); if($MR->removeSourceBranch == '1') $data['delete_branch_after_merge'] = true; - - $rowMR = json_decode(commonModel::http($url, $data, array(), array(), 'json', 'POST')); - if(!isset($rowMR->massage)) - { - $rowMR = $this->apiGetSingleMR($MR->repoID, $MR->mriid); - if($MR->removeSourceBranch == '1') $this->loadModel('gogs')->apiDeleteBranch($MR->hostID, $MR->targetProject, $MR->sourceBranch); - } - - return $rowMR; } + + $rowMR = json_decode(commonModel::http($url, $data, array(), $host->type == 'gitfox' ? $apiRoot->header : array(), 'json', 'POST')); + if(!isset($rowMR->massage)) + { + $rowMR = $this->apiGetSingleMR($MR->repoID, $MR->mriid); + if($MR->removeSourceBranch == '1' && in_array($host->type, array('gogs', 'gitfox'))) $this->loadModel($host->type)->apiDeleteBranch($MR->hostID, $MR->sourceProject, $MR->sourceBranch); + } + + return $rowMR; } /**