Merge branch 'jihuMR'

This commit is contained in:
dingguodong
2021-09-07 20:47:10 +08:00
48 changed files with 2303 additions and 261 deletions
+86 -2
View File
@@ -58,6 +58,8 @@ class gitlab extends control
$gitlabID = $this->gitlab->create();
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
$this->loadModel('action');
$actionID = $this->action->create('gitlab', $gitlabID, 'create');
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse')));
}
@@ -66,6 +68,24 @@ class gitlab extends control
$this->display();
}
/**
* view a gitlab.
* @param int $id
* @access public
* @return void
*/
public function view($id)
{
$gitlab = $this->gitlab->getByID($id);
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->view;
$this->view->gitlab = $gitlab;
$this->view->users = $this->loadModel('user')->getPairs('noclosed');
$this->view->actions = $this->loadModel('action')->getList('gitlab', $id);
$this->view->preAndNext = $this->loadModel('common')->getPreAndNextObject('pipeline', $id);
$this->display();
}
/**
* Edit a gitlab.
*
@@ -75,17 +95,24 @@ class gitlab extends control
*/
public function edit($id)
{
$gitlab = $this->gitlab->getByID($id);
$oldGitLab = $this->gitlab->getByID($id);
if($_POST)
{
$this->checkToken();
$this->gitlab->update($id);
$gitLab = $this->gitlab->getByID($id);
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
$this->loadModel('action');
$actionID = $this->action->create('gitlab', $id, 'edit');
$changes = common::createChanges($oldGitLab, $gitLab);
$this->action->logHistory($actionID, $changes);
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse')));
}
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->edit;
$this->view->gitlab = $gitlab;
$this->view->gitlab = $oldGitLab;
$this->display();
}
@@ -178,7 +205,14 @@ class gitlab extends control
{
if($confim != 'yes') die(js::confirm($this->lang->gitlab->confirmDelete, inlink('delete', "id=$id&confirm=yes")));
$oldGitLab = $this->gitlab->getByID($id);
$this->loadModel('action');
$this->gitlab->delete(TABLE_PIPELINE, $id);
$gitLab = $this->gitlab->getByID($id);
$actionID = $this->action->create('gitlab', $id, 'delete');
$changes = common::createChanges($oldGitLab, $gitLab);
$this->action->logHistory($actionID, $changes);
die(js::reload('parent'));
}
@@ -367,4 +401,54 @@ class gitlab extends control
}
return $this->send($options);
}
/**
* AJAX: Get project branches.
*
* @param int $gitlabID
* @param int $projectID
* @access public
* @return void
*/
public function ajaxGetProjectBranches($gitlabID, $projectID)
{
if(!$gitlabID or !$projectID) return $this->send(array('message' => array()));
$branches = $this->gitlab->apiGetBranches($gitlabID, $projectID);
$options = "<option value=''></option>";
foreach($branches as $branch)
{
$options .= "<option value='{$branch->name}'>{$branch->name}</option>";
}
$this->send($options);
}
/**
* AJAX: Get MR user pairs to select assignee_ids and reviewer_ids.
* Attention: The user must be a member of the GitLab project.
*
* @param int $gitlabID
* @param int $projectID
* @access public
* @return void
*/
public function ajaxGetMRUserPairs($gitlabID, $projectID)
{
if(!$gitlabID) return $this->send(array('message' => array()));
$bindedUsers = $this->gitlab->getUserIdRealnamePairs($gitlabID);
$rawProjectUsers = $this->gitlab->apiGetProjectUsers($gitlabID, $projectID);
$users = array();
foreach($rawProjectUsers as $rawProjectUser)
{
if(!empty($bindedUsers[$rawProjectUser->id])) $users[$rawProjectUser->id] = $bindedUsers[$rawProjectUser->id];
}
$options = "<option value=''></option>";
foreach($users as $index => $user)
{
$options .= "<option value='{$index}'>{$user}</option>";
}
$this->send($options);
}
}
+1
View File
@@ -4,6 +4,7 @@ $lang->gitlab->common = 'GitLab';
$lang->gitlab->browse = '浏览GitLab';
$lang->gitlab->create = '添加GitLab';
$lang->gitlab->edit = '编辑GitLab';
$lang->gitlab->view = '查看GitLab';
$lang->gitlab->bindUser = '绑定用户';
$lang->gitlab->webhook = 'webhook';
$lang->gitlab->bindProduct = '关联产品';
+178 -35
View File
@@ -34,12 +34,15 @@ class gitlabModel extends model
*/
public function getList($orderBy = 'id_desc', $pager = null)
{
return $this->loadModel('pipeline')->getList('gitlab', $orderBy, $pager);
$gitlabList = $this->loadModel('pipeline')->getList('gitlab', $orderBy, $pager);
return $gitlabList;
}
/**
* Get gitlab pairs.
*
* @access public
* @return array
*/
@@ -63,7 +66,25 @@ class gitlabModel extends model
}
/**
* Get gitlab user id zentao account pairs of one gitlab.
* Get gitlab user id and realname pairs of one gitlab.
*
* @param int $gitlabID
* @access public
* @return void
*/
public function getUserIdRealnamePairs($gitlabID)
{
return $this->dao->select('oauth.openID as openID,user.realname as realname')
->from(TABLE_OAUTH)->alias('oauth')
->leftJoin(TABLE_USER)->alias('user')
->on("oauth.account = user.account")
->where('providerType')->eq('gitlab')
->andWhere('providerID')->eq($gitlabID)
->fetchPairs();
}
/**
* Get gitlab user id and zentao account pairs of one gitlab.
*
* @param int $gitlab
* @access public
@@ -255,42 +276,60 @@ class gitlabModel extends model
/**
* Get gitlab project name of one gitlab project.
*
* @param int $jobID
* @param int $gitlabID
* @param int $projectID
* @access public
* @return string|false
*/
public function getObjectNameForJob($gitlabID, $projectID)
public function getProjectName($gitlabID, $projectID)
{
$project = $this->apiGetSingleProject($gitlabID, $projectID);
if(isset($project->name)) return $project->name;
if(is_object($project) and isset($project->name)) return $project->name;
return false;
}
/**
* Get ref option menus.
* Get reference option menus.
*
* @param int $gitlabID
* @param int $projectID
* @access public
* @return array
*/
public function getRefOptions($gitlabID, $projectID)
public function getReferenceOptions($gitlabID, $projectID)
{
$refList = array();
$branches = $this->loadModel('gitlab')->apiGetBranches($gitlabID, $projectID);
$tags = $this->loadModel('gitlab')->apiGetTags($gitlabID, $projectID);
$refList = array();
/* fix bug 14612*/
if(isset($branches->message)) return array();
$branches = $this->apiGetBranches($gitlabID, $projectID);
foreach($branches as $branch) $refList[$branch->name] = "Branch::" . $branch->name;
if(isset($branches->error)) return array();
$tags = $this->apiGetTags($gitlabID, $projectID);
foreach($tags as $tag) $refList[$tag->name] = "Tag::" . $tag->name;
foreach($branches as $branch) $refList[] = "Branch::" . $branch->name;
foreach($tags as $tag) $refList[] = "Tag::" . $tag->name;
return $refList;
}
/**
* Get branches.
*
* @param int $gitlabID
* @param int $projectID
* @access public
* @return array
*/
public function getBranches($gitlabID, $projectID)
{
$rawBranches = $this->apiGetBranches($gitlabID, $projectID);
$branches = array();
foreach($rawBranches as $branch)
{
$branches[] = $branch->name;
}
return $branches;
}
/**
* Create a gitlab.
*
@@ -352,6 +391,23 @@ class gitlabModel extends model
return json_decode(commonModel::http($url, $data, $options));
}
/**
* Get a list of to-do items.
*
* @see https://docs.gitlab.com/ee/api/todos.html
* @param int $gitlabID
* @param int $projectID
* @access public
* @return object
*/
public function apiTodoList($gitlabID, $projectID)
{
$gitlab = $this->loadModel('gitlab')->getByID($gitlabID);
if(!$gitlab) return '';
$url = rtrim($gitlab->url, '/')."/api/v4/todos?project_id=$projectID&type=MergeRequest&private_token={$gitlab->token}";
return json_decode(commonModel::http($url));
}
/**
* Get current user.
*
@@ -413,10 +469,8 @@ class gitlabModel extends model
$allResults = array();
for($page = 1; true; $page ++)
{
$results = json_decode(commonModel::http($host . "?private_token={$gitlab->token}&simple=true&membership=true&page={$page}&per_page=100"));
if(isset($results->error)) break;
$results = json_decode(commonModel::http($host . "?private_token={$gitlab->token}&simple=true&page={$page}&per_page=100"));
if(empty($results) or $page > 10) break;
$allResults = array_merge($allResults, $results);
}
@@ -437,6 +491,94 @@ class gitlabModel extends model
return json_decode(commonModel::http($url));
}
/**
* Get project users.
*
* @param int $gitlabID
* @param int $projectID
* @access public
* @return object
*/
public function apiGetProjectUsers($gitlabID, $projectID)
{
$url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/users");
return json_decode(commonModel::http($url));
}
/**
* Get project all members(users and users in groups).
*
* @param int $gitlabID
* @param int $projectID
* @access public
* @return object
*/
public function apiGetProjectMembers($gitlabID, $projectID)
{
$url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/members/all");
return json_decode(commonModel::http($url));
}
/**
* Get the member detail in project.
*
* @param int $gitlabID
* @param int $projectID
* @param int $userID
* @access public
* @return object
*/
public function apiGetProjectMember($gitlabID, $projectID, $userID)
{
$url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/members/all/$userID");
return json_decode(commonModel::http($url));
}
/**
* Get single branch by API.
*
* @param int $gitlabID
* @param int $projectID
* @param string $branch
* @access public
* @return object
*/
public function apiGetSingleBranch($gitlabID, $projectID, $branch)
{
$url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/repository/branches/$branch");
return json_decode(commonModel::http($url));
}
/**
* Get Forks of a project by API.
*
* @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->getApiRoot($gitlabID), "/projects/$projectID/forks");
return json_decode(commonModel::http($url));
}
/**
* Get upstream project by API.
*
* @param int $gitlabID
* @param int $projectID
* @access public
* @return void
*/
public function apiGetUpstream($gitlabID,$projectID)
{
$currentProject = $this->apiGetSingleProject($gitlabID, $projectID);
if(isset($currentProject->forked_from_project)) return $currentProject->forked_from_project;
return array();
}
/**
* Get hooks.
*
@@ -726,25 +868,26 @@ class gitlabModel extends model
/**
* Create a new pipeline by api.
*
* @param integer $gitlabID
* @param integer $projectID
* @param string $reference
* @param int $gitlabID
* @param int $projectID
* @param object $params
* @access public
* @return object
* @docment https://docs.gitlab.com/ee/api/pipelines.html#create-a-new-pipeline
*/
public function apiCreatePipeline($gitlabID, $projectID, $reference)
public function apiCreatePipeline($gitlabID, $projectID, $params)
{
if(!is_string($params)) $params = json_encode($params);
$url = sprintf($this->getApiRoot($gitlabID), "/projects/{$projectID}/pipeline");
return json_decode(commonModel::http($url, $reference, null, array("Content-Type: application/json")));
return json_decode(commonModel::http($url, $params, null, array("Content-Type: application/json")));
}
/**
* Get single pipline by api.
*
* @param integer $gitlabID
* @param integer $projectID
* @param integer $pipelineID
* @param int $gitlabID
* @param int $projectID
* @param int $pipelineID
* @access public
* @return object
* @docment https://docs.gitlab.com/ee/api/pipelines.html#get-a-single-pipeline
@@ -758,9 +901,9 @@ class gitlabModel extends model
/**
* List pipeline jobs by api.
*
* @param integer $gitlabID
* @param integer $projectID
* @param integer $pipelineID
* @param int $gitlabID
* @param int $projectID
* @param int $pipelineID
* @return object
* @docment https://docs.gitlab.com/ee/api/jobs.html#list-pipeline-jobs
*/
@@ -773,9 +916,9 @@ class gitlabModel extends model
/**
* Get a single job by api.
*
* @param integer $gitlabID
* @param integer $projectID
* @param integer $jobID
* @param int $gitlabID
* @param int $projectID
* @param int $jobID
* @return object
* @docment https://docs.gitlab.com/ee/api/jobs.html#get-a-single-job
*/
@@ -788,9 +931,9 @@ class gitlabModel extends model
/**
* Get a log file by api.
*
* @param integer $gitlabID
* @param integer $projectID
* @param integer $jobID
* @param int $gitlabID
* @param int $projectID
* @param int $jobID
* @return string
* @docment https://docs.gitlab.com/ee/api/jobs.html#get-a-log-file
*/
+1 -1
View File
@@ -42,7 +42,7 @@
<?php foreach ($gitlabList as $id => $gitlab): ?>
<tr class='text' title='<?php if(!$gitlab->isAdminToken) echo $lang->gitlab->tokenLimit;?>'>
<td class='text-center'><?php echo $id;?></td>
<td class='text c-name' title='<?php echo $gitlab->name;?>'><?php echo $gitlab->name;?></td>
<td class='text-c-name' title='<?php echo $gitlab->name;?>'><a class="iframe" data-width="90%" href="<?php echo $this->createLink('gitlab', 'view', "id=$id", '', true); ?>"><?php echo $gitlab->name;?></a></td>
<td class='text' title='<?php echo $gitlab->url;?>'><?php echo $gitlab->url;?></td>
<td class='c-actions text-left'>
<?php
+30
View File
@@ -0,0 +1,30 @@
<?php
/**
* The view file of GitLab module of ZenTaoPMS.
*
* @copyright Copyright 2009-2015 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author dave.li <lichengjun@cnezsoft.com>
* @package GitLab
* @version $Id: view.html.php 4728 2013-05-03 06:14:34Z david18810279601@gmail.com $
* @link http://www.zentao.net
* */
?>
<?php include '../../common/view/header.html.php';?>
<?php js::set('sysurl', common::getSysUrl());?>
<div id="mainMenu" class="clearfix">
<div class="btn-toolbar pull-left">
<div class="page-title">
<span class="label label-id"><?php echo $gitlab->id?></span>
<span class="text" title="<?php echo $gitlab->name;?>" style='color: #3c4354'><?php echo $gitlab->name;?></span>
</div>
</div>
</div>
<div id="mainContent" class="main-row">
<div class="main-col col-8">
<div class='cell'><?php include '../../common/view/action.html.php';?></div>
</div>
</div>
<?php include '../../common/view/footer.html.php';?>