This commit is contained in:
Guanxiying
2021-06-10 14:09:12 +08:00
4 changed files with 46 additions and 73 deletions
+2 -2
View File
@@ -471,8 +471,8 @@ CREATE TABLE IF NOT EXISTS `zt_history` (
PRIMARY KEY (`id`),
KEY `action` (`action`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- DROP TABLE IF EXISTS `zt_pipeline`;
CREATE TABLE IF NOT EXISTS `zt_pipeline` (
-- DROP TABLE IF EXISTS `zt_pipline`;
CREATE TABLE IF NOT EXISTS `zt_pipline` (
`id` smallint(8) unsigned NOT NULL AUTO_INCREMENT,
`type` char(30) NOT NULL,
`name` varchar(50) NOT NULL,
+4 -1
View File
@@ -75,7 +75,10 @@ class gitlab extends control
*/
public function bind()
{
var_dump($this->gitlab->getPermissionsByToken('http://127.0.0.1:8090/','rpz2PZKriNE6TD34QtDA'));
$gitlabUserData = $this->gitlab->getUserBindList('http://127.0.0.1:8090/','xV8EKDyCY7Sb5j1-FxyZ');
var_dump($gitlabUserData);die;
die;
$this->display();
+40 -21
View File
@@ -85,31 +85,50 @@ class gitlabModel extends model
$host = rtrim($host, '/') . "/api/v4/user?private_token=$token";
$response = json_decode(commonModel::http($host));
if(!is_object($response)) return array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)));
if(!is_object($response)) return array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)));
if(isset($response->is_admin) and $response->is_admin == true) return array('result' => 'success');
return array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)));
}
/**
* Get projects of one gitlab.
*
* @param int $id
* @access public
* @return void
*/
public function getProjectsByID($id)
{
$gitlab = $this->getByID($id);
$host = rtrim($gitlab->url, '/');
$host .= '/api/v4/projects';
$allResults = array();
for($page = 1; true; $page ++)
{
$results = json_decode(file_get_contents($host . "?private_token={$gitlab->token}&simple=true&membership=true&page={$page}&per_page=100"));
if(empty($results) or $page > 10) break;
$allResults = $allResults + $results;
}
return $allResults;
/**
* Get gitlab user list.
*
* @param string $host
* @param string $token
* @access public
* @return array
*/
public function getUserBindList($host, $token)
{
$host = rtrim($host, '/') .'/api/v4/users?private_token='.$token ;
$response = json_decode(commonModel::http($host),true);
if (!$response) return array();
$localUsersList = $this->dao->select('id,account,email,realname')->from(TABLE_USER)->fetchAll();
$responseAllId = array();
$matchUserIds = array();
$responseMatchIds = array();
foreach ($response as $i => $gitlabId) {
$responseAllId[] = $gitlabId['id'];
foreach ($localUsersList as $local) {
if ( $gitlabId['email'] == $local->email && $gitlabId['username'] == $local->realname && $gitlabId['name'] == $local->account)
{
$matchUserIds[$i][$local->realname] = $local->id .'-'. $gitlabId['id'];
$responseMatchIds[] = $gitlabId['id'];
}
}
}
$notMatchUserIds = array_diff($responseAllId,$responseMatchIds);
foreach ($notMatchUserIds as $k => $v)
{
$notMatchUserId[$k]['Not matched'] = 0 .'-'. $v;
}
return array_merge($notMatchUserId,$matchUserIds);
}
}
-49
View File
@@ -1,49 +0,0 @@
<?php
/**
* The edit view file of gitlab module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package gitlab
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php'; ?>
<div id='mainContent' class='main-row'>
<div class='main-col main-content'>
<div class='center-block'>
<div class='main-header'>
<h2><?php echo $lang->gitlab->edit; ?></h2>
</div>
<form id='gitlabForm' method='post' class='form-ajax'>
<table class='table table-form'>
<tr>
<th><?php echo $lang->gitlab->name; ?></th>
<td class='required'><?php echo html::input('name', $gitlab->name, "class='form-control'"); ?></td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->gitlab->url; ?></th>
<td class='required'><?php echo html::input('url', $gitlab->url, "class='form-control'"); ?></td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->gitlab->token;?></th>
<td><?php echo html::input('token', $gitlab->token, "class='form-control'");?></td>
<td><?php echo $lang->gitlab->tokenFirst;?></td>
</tr>
<tr>
<th></th>
<td class='text-center form-actions'>
<?php echo html::submitButton(); ?>
<?php echo html::backButton() ?>
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
<?php include '../../common/view/footer.html.php'; ?>