From d95711841d4895003443c3e5df70d4fdd3bc7ff0 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 19 Aug 2021 18:22:42 +0800 Subject: [PATCH] * Add some functions to creating MR(staging). --- module/mr/control.php | 25 +++++++++++++++++++------ module/mr/model.php | 32 ++++++++++---------------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index cf57c98c72..ff28a8efb4 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -42,7 +42,7 @@ class mr extends control $this->view->title = $this->lang->mr->create; $this->view->gitlabHosts = $this->loadModel('gitlab')->getPairs(); - + $this->view->users = $this->gitlab->getUserIdRealnamePairs(14); $this->display(); } @@ -71,24 +71,37 @@ class mr extends control } /** - * AJAX: Get forked projects. + * AJAX: Get MR target projects. * * @param int $gitlabID * @param int $projectID * @access public * @return void */ - public function ajaxGetForkedProjects($gitlabID, $projectID) + public function ajaxGetMRTragetProjects($gitlabID, $projectID) { - $projects = $this->mr->apiGetForks($gitlabID, $projectID); + $this->loadModel('gitlab'); + /* First step: get forks. */ + $projects = $this->gitlab->apiGetForks($gitlabID, $projectID); + /* Second step: get project itself. */ + $projects[] = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); + + /* Last step: find its upstream recursively. */ + $project = $this->gitlab->apiGetUpstream($gitlabID, $projectID); + if(!empty($project)) $projects[] = $project; + + while(!empty($project) and isset($project->id)) + { + $project = $this->gitlab->apiGetUpstream($gitlabID, $project->id); + if(empty($project)) break; + $projects[] = $project; + } if(!$projects) return $this->send(array('message' => array())); - $projectIdList = $projectIdList ? explode(',', $projectIdList) : null; $options = ""; foreach($projects as $project) { - if(!empty($projectIdList) and $project and !in_array($project->id, $projectIdList)) continue; $options .= ""; } diff --git a/module/mr/model.php b/module/mr/model.php index 0d9320ebf6..f2e1195416 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -120,27 +120,16 @@ class mrModel extends model $gitlabID = $this->post->gitlabID; $projectID = $this->post->projectID; - $sourceProject = $this->post->sourceProject; - $sourceBranch = $this->post->sourceBranch; - $targetProject = $this->post->targetProject; - $targetBranch = $this->post->targetBranch; + $MR = new stdclass; + $MR->target_project_id = $this->post->targetProject; + $MR->source_branch = $this->post->sourceBranch; + $MR->target_branch = $this->post->targetBranch; + $MR->title = $this->post->title; + $MR->description = $this->post->description; + $MR->assignee_ids = $this->post->assignee; + $MR->reviewer_ids = $this->post->reviewer; - if($projectID != $sourceProject) return false; - } - - /** - * Get Forks of a project. - * - * @docs https://docs.gitlab.com/ee/api/projects.html#list-forks-of-a-project - * @param int $gitlabID - * @param int $projectID - * @access public - * @return object - */ - public function apiGetForks($gitlabID, $projectID) - { - $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/forks"); - return json_decode(commonModel::http($url)); + $rawMR = $this->apiCreateMR($gitlabID, $projectID, $MR); } /** @@ -156,8 +145,7 @@ class mrModel extends model public function apiCreateMR($gitlabID, $projectID, $params) { $url = sprintf($this->gitlab->getApiRoot($gitlabID), "/projects/$projectID/merge_requests"); - $MR = new stdclass; - return json_decode(commonModel::http($url, $MR)); + return json_decode(commonModel::http($url, $data=$params, $options = array())); } /**