* Add some functions to creating MR(staging).

This commit is contained in:
dingguodong
2021-08-19 18:22:42 +08:00
parent 2999fd6e49
commit d95711841d
2 changed files with 29 additions and 28 deletions
+19 -6
View File
@@ -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 = "<option value=''></option>";
foreach($projects as $project)
{
if(!empty($projectIdList) and $project and !in_array($project->id, $projectIdList)) continue;
$options .= "<option value='{$project->id}' data-name='{$project->name}'>{$project->name_with_namespace}</option>";
}
+10 -22
View File
@@ -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()));
}
/**