* Add Gogs mr param.
This commit is contained in:
@@ -517,4 +517,53 @@ class gogsModel extends model
|
||||
->andWhere('providerID')->eq($gogsID)
|
||||
->fetchPairs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single branch by API.
|
||||
*
|
||||
* @param int $gogsID
|
||||
* @param string $project
|
||||
* @param string $branchName
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function apiGetSingleBranch($gogsID, $project, $branchName)
|
||||
{
|
||||
$url = sprintf($this->getApiRoot($gogsID), "/repos/$project/branches/$branchName");
|
||||
$branch = json_decode(commonModel::http($url));
|
||||
if($branch)
|
||||
{
|
||||
$gogs = $this->getByID($gogsID);
|
||||
$branch->web_url = "{$gogs->url}/$project/src/branch/$branchName";
|
||||
}
|
||||
|
||||
return $branch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get protect branches of one project.
|
||||
*
|
||||
* @param int $gogsID
|
||||
* @param string $project
|
||||
* @param string $keyword
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function apiGetBranchPrivs($gogsID, $project, $keyword = '')
|
||||
{
|
||||
$keyword = urlencode($keyword);
|
||||
$url = sprintf($this->getApiRoot($gogsID), "/repos/$project/branch_protections");
|
||||
$branches = json_decode(commonModel::http($url));
|
||||
|
||||
if(!is_array($branches)) return array();
|
||||
|
||||
$newBranches = array();
|
||||
foreach($branches as $branch)
|
||||
{
|
||||
$branch->name = $branch->branch_name;
|
||||
if(empty($keyword) || stristr($branch->name, $keyword)) $newBranches[] = $branch;
|
||||
}
|
||||
|
||||
return $newBranches;
|
||||
}
|
||||
}
|
||||
|
||||
+18
-14
@@ -34,7 +34,7 @@ class mr extends control
|
||||
$this->app->loadClass('pager', $static = true);
|
||||
$pager = new pager($recTotal, $recPerPage, $pageID);
|
||||
|
||||
$repos = $this->loadModel('repo')->getListBySCM(array('Gitlab', 'Gitea'));
|
||||
$repos = $this->loadModel('repo')->getListBySCM(array('Gitlab', 'Gitea', 'Gogs'));
|
||||
if(empty($repos)) $this->locate($this->repo->createLink('create'));
|
||||
|
||||
$repoID = $this->repo->saveState($repoID, $objectID);
|
||||
@@ -69,10 +69,14 @@ class mr extends control
|
||||
{
|
||||
$openIDList = $this->loadModel('gitlab')->getGitLabListByAccount($this->app->user->account);
|
||||
}
|
||||
else
|
||||
elseif($repo->SCM == 'Gitea')
|
||||
{
|
||||
$openIDList = $this->loadModel('gitea')->getGiteaListByAccount($this->app->user->account);
|
||||
}
|
||||
elseif($repo->SCM == 'Gogs')
|
||||
{
|
||||
$openIDList = $this->loadModel('gogs')->getGogsListByAccount($this->app->user->account);
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->title = $this->lang->mr->common . $this->lang->colon . $this->lang->mr->browse;
|
||||
@@ -108,22 +112,26 @@ class mr extends control
|
||||
$repoID = $this->loadModel('repo')->saveState(0);
|
||||
$repo = $this->repo->getRepoByID($repoID);
|
||||
|
||||
$this->loadModel('gitlab');
|
||||
$this->loadModel('gitea');
|
||||
$this->loadModel('gogs');
|
||||
if($repo->SCM == 'Gitea')
|
||||
{
|
||||
$project = $this->gitea->apiGetSingleProject($repo->gitService, $repo->project);
|
||||
if(empty($project) or !$project->allow_merge_commits) $repo = array();
|
||||
}
|
||||
|
||||
$hosts = $this->loadModel('pipeline')->getList(array('gitea', 'gitlab'));
|
||||
$hosts = $this->loadModel('pipeline')->getList(array('gitea', 'gitlab', 'gogs'));
|
||||
if(!$this->app->user->admin)
|
||||
{
|
||||
$gitlabUsers = $this->loadModel('gitlab')->getGitLabListByAccount();
|
||||
$gitlabUsers = $this->gitlab->getGitLabListByAccount();
|
||||
$giteaUsers = $this->gitea->getGiteaListByAccount();
|
||||
$gogsUsers = $this->gogs->getGogsListByAccount();
|
||||
foreach($hosts as $hostID => $host)
|
||||
{
|
||||
if($host->type == 'gitLab' and isset($gitlabUsers[$hostID])) continue;
|
||||
if($host->type == 'gitea' and isset($giteaUsers[$hostID])) continue;
|
||||
if($host->type == 'gitea' and isset($giteaUsers[$hostID])) continue;
|
||||
if($host->type == 'gogs' and isset($gogsUsers[$hostID])) continue;
|
||||
|
||||
unset($hosts[$hostID]);
|
||||
}
|
||||
@@ -1039,7 +1047,7 @@ class mr extends control
|
||||
$targetBranch = $this->post->targetBranch;
|
||||
|
||||
$result = $this->mr->checkSameOpened($hostID, $sourceProject, $sourceBranch, $targetProject, $targetBranch);
|
||||
echo json_encode($result);
|
||||
return print(json_encode($result));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1054,15 +1062,11 @@ class mr extends control
|
||||
{
|
||||
$host = $this->loadModel('pipeline')->getByID($hostID);
|
||||
$scm = $host->type;
|
||||
if($scm == 'gitea') $project = urldecode(base64_decode($project));
|
||||
if(in_array($scm, array('gitea', 'gogs'))) $project = urldecode(base64_decode($project));
|
||||
|
||||
$branchPrivs = array();
|
||||
|
||||
if($scm != 'gogs')
|
||||
{
|
||||
$branches = $this->loadModel($scm)->apiGetBranchPrivs($hostID, $project);
|
||||
foreach($branches as $branch) $branchPrivs[$branch->name] = $branch->name;
|
||||
}
|
||||
echo json_encode($branchPrivs);
|
||||
$branches = $this->loadModel($scm)->apiGetBranchPrivs($hostID, $project);
|
||||
foreach($branches as $branch) $branchPrivs[$branch->name] = $branch->name;
|
||||
return print(json_encode($branchPrivs));
|
||||
}
|
||||
}
|
||||
|
||||
+66
-10
@@ -437,9 +437,9 @@ class mrModel extends model
|
||||
{
|
||||
$gitUsers = $this->loadModel('gitlab')->getUserIdAccountPairs($MR->hostID);
|
||||
}
|
||||
elseif($rawMR->gitService == 'gitea')
|
||||
else
|
||||
{
|
||||
$gitUsers = $this->loadModel('gitea')->getUserAccountIdPairs($MR->hostID, 'openID,account');
|
||||
$gitUsers = $this->loadModel($rawMR->gitService)->getUserAccountIdPairs($MR->hostID, 'openID,account');
|
||||
}
|
||||
|
||||
$newMR = new stdclass;
|
||||
@@ -670,21 +670,21 @@ class mrModel extends model
|
||||
}
|
||||
return json_decode(commonModel::http($url, $MRObject));
|
||||
}
|
||||
elseif($host->type == 'gitea')
|
||||
elseif(in_array($host->type, array('gitea', 'gogs')))
|
||||
{
|
||||
$url = sprintf($this->loadModel('gitea')->getApiRoot($hostID), "/repos/$projectID/pulls");
|
||||
$url = sprintf($this->loadModel($host->type)->getApiRoot($hostID), "/repos/$projectID/pulls");
|
||||
|
||||
$MRObject->head = $MR->sourceBranch;
|
||||
$MRObject->base = $MR->targetBranch;
|
||||
$MRObject->body = $MR->description;
|
||||
if($MR->assignee)
|
||||
{
|
||||
$assignee = $this->gitea->getUserIDByZentaoAccount($this->post->hostID, $MR->assignee);
|
||||
$assignee = $this->{$host->type}->getUserIDByZentaoAccount($this->post->hostID, $MR->assignee);
|
||||
if($assignee) $MRObject->assignee = $assignee;
|
||||
}
|
||||
|
||||
$mergeResult = json_decode(commonModel::http($url, $MRObject));
|
||||
if(isset($mergeResult->number)) $mergeResult->iid = $mergeResult->number;
|
||||
if(isset($mergeResult->number)) $mergeResult->iid = $host->type == 'gitea' ? $mergeResult->number : $mergeResult->id;
|
||||
if(isset($mergeResult->mergeable))
|
||||
{
|
||||
if($mergeResult->mergeable) $mergeResult->merge_status = 'can_be_merged';
|
||||
@@ -735,6 +735,22 @@ class mrModel extends model
|
||||
$MR->target_project_id = $projectID;
|
||||
}
|
||||
}
|
||||
elseif($scm == 'Gogs')
|
||||
{
|
||||
foreach($response as $MR)
|
||||
{
|
||||
$MR->iid = $MR->id;
|
||||
$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_branch;
|
||||
$MR->source_branch = $MR->head_branch;
|
||||
$MR->source_project_id = $projectID;
|
||||
$MR->target_project_id = $projectID;
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
@@ -786,7 +802,7 @@ class mrModel extends model
|
||||
$url = sprintf($this->gitlab->getApiRoot($hostID), "/projects/$projectID/merge_requests/$MRID");
|
||||
$MR = json_decode(commonModel::http($url));
|
||||
}
|
||||
else
|
||||
else if($host->type == 'gitea')
|
||||
{
|
||||
$url = sprintf($this->loadModel('gitea')->getApiRoot($hostID), "/repos/$projectID/pulls/$MRID");
|
||||
$MR = json_decode(commonModel::http($url));
|
||||
@@ -809,6 +825,29 @@ class mrModel extends model
|
||||
$MR->has_conflicts = empty($diff) ? true : false;
|
||||
}
|
||||
}
|
||||
else if($host->type == 'gogs')
|
||||
{
|
||||
$url = sprintf($this->loadModel('gogs')->getApiRoot($hostID), "/repos/$projectID/pulls/$MRID");
|
||||
$MR = json_decode(commonModel::http($url));
|
||||
if(isset($MR->html_url))
|
||||
{
|
||||
$diff = $this->apiGetDiffs($hostID, $projectID, $MRID);
|
||||
|
||||
$MR->web_url = $MR->html_url;
|
||||
$MR->iid = $MR->id;
|
||||
$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 = empty($diff) ? 0 : 1;
|
||||
$MR->description = $MR->body;
|
||||
$MR->target_branch = $MR->base_branch;
|
||||
$MR->source_branch = $MR->head_branch;
|
||||
$MR->source_project_id = $projectID;
|
||||
$MR->target_project_id = $projectID;
|
||||
$MR->has_conflicts = empty($diff) ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
$MR->gitService = $host->type;
|
||||
return $MR;
|
||||
@@ -873,7 +912,7 @@ class mrModel extends model
|
||||
}
|
||||
|
||||
$mergeResult = json_decode(commonModel::http($url, $newMR, array(), array(), 'json', 'PATCH'));
|
||||
if(isset($mergeResult->number)) $mergeResult->iid = $mergeResult->number;
|
||||
if(isset($mergeResult->number)) $mergeResult->iid = $host->type == 'gitea' ? $mergeResult->number : $mergeResult->id;
|
||||
if(isset($mergeResult->mergeable))
|
||||
{
|
||||
if($mergeResult->mergeable) $mergeResult->merge_status = 'can_be_merged';
|
||||
@@ -936,7 +975,7 @@ class mrModel extends model
|
||||
}
|
||||
else
|
||||
{
|
||||
$url = sprintf($this->loadModel('gitea')->getApiRoot($hostID), "/repos/$projectID/pulls/$MRID");
|
||||
$url = sprintf($this->loadModel($host->type)->getApiRoot($hostID), "/repos/$projectID/pulls/$MRID");
|
||||
return json_decode(commonModel::http($url, array('state' => 'closed'), array(), array(), 'json', 'PATCH'));
|
||||
}
|
||||
}
|
||||
@@ -959,7 +998,7 @@ class mrModel extends model
|
||||
$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
|
||||
elseif($host->type == 'gitea')
|
||||
{
|
||||
$url = sprintf($this->loadModel('gitea')->getApiRoot($hostID), "/repos/$projectID/pulls/$MRID");
|
||||
$MR = json_decode(commonModel::http($url, array('state' => 'open'), array(), array(), 'json', 'PATCH'));
|
||||
@@ -974,6 +1013,23 @@ class mrModel extends model
|
||||
$MR->source_project_id = $projectID;
|
||||
$MR->target_project_id = $projectID;
|
||||
|
||||
return $MR;
|
||||
}
|
||||
elseif($host->type == 'gogs')
|
||||
{
|
||||
$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->id;
|
||||
$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_branch;
|
||||
$MR->source_branch = $MR->head_branch;
|
||||
$MR->source_project_id = $projectID;
|
||||
$MR->target_project_id = $projectID;
|
||||
|
||||
return $MR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1254,10 +1254,11 @@ class repo extends control
|
||||
public function ajaxGetGogsProjects($gogsID)
|
||||
{
|
||||
$projects = $this->loadModel('gogs')->apiGetProjects($gogsID);
|
||||
if(!$projects) $this->send(array('message' => array()));
|
||||
|
||||
$options = "<option value=''></option>";
|
||||
foreach($projects as $project) $options .= "<option value='{$project->full_name}' data-name='{$project->name}'>{$project->full_name}</option>";
|
||||
if(!empty($projects))
|
||||
{
|
||||
foreach($projects as $project) $options .= "<option value='{$project->full_name}' data-name='{$project->name}'>{$project->full_name}</option>";
|
||||
}
|
||||
|
||||
return print($options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user