|
From 8e00b74c72d0bb15e2f6db2a4936a927af842d43 Mon Sep 17 00:00:00 2001
From: Guanxiying
Date: Mon, 7 Jun 2021 16:43:21 +0800
Subject: [PATCH 004/269] * Add pipline module.
---
module/pipline/lang/zh-cn.php | 7 +++
module/pipline/model.php | 114 ++++++++++++++++++++++++++++++++++
2 files changed, 121 insertions(+)
create mode 100644 module/pipline/lang/zh-cn.php
create mode 100644 module/pipline/model.php
diff --git a/module/pipline/lang/zh-cn.php b/module/pipline/lang/zh-cn.php
new file mode 100644
index 0000000000..8d81ee7093
--- /dev/null
+++ b/module/pipline/lang/zh-cn.php
@@ -0,0 +1,7 @@
+pipline->id = 'ID';
+$lang->pipline->name = '名称';
+$lang->pipline->url = '服务地址';
+$lang->pipline->token = 'Token';
+$lang->pipline->account = '用户名';
+$lang->pipline->password = '密码';
diff --git a/module/pipline/model.php b/module/pipline/model.php
new file mode 100644
index 0000000000..eb73a6a595
--- /dev/null
+++ b/module/pipline/model.php
@@ -0,0 +1,114 @@
+
+ * @package product
+ * @version $Id: $
+ * @link http://www.zentao.net
+ */
+
+class piplineModel extends model
+{
+ /**
+ * Get a pipline by id.
+ *
+ * @param int $id
+ * @access public
+ * @return object
+ */
+ public function getByID($id)
+ {
+ $pipline = $this->dao->select('*')->from(TABLE_PIPLINE)->where('id')->eq($id)->fetch();
+ $pipline->password = base64_decode($pipline->password);
+ return $pipline;
+ }
+
+ /**
+ * Get pipline list.
+ *
+ * @param string $type jenkins|gitlab
+ * @param string $orderBy
+ * @param object $pager
+ * @access public
+ * @return array
+ */
+ public function getList($type = 'jenkins', $orderBy = 'id_desc', $pager = null)
+ {
+ return $this->dao->select('*')->from(TABLE_PIPLINE)
+ ->where('deleted')->eq('0')
+ ->AndWhere('type')->eq($type)
+ ->orderBy($orderBy)
+ ->page($pager)
+ ->fetchAll('id');
+ }
+
+ /**
+ * Get pipline pairs
+ *
+ * @return array
+ */
+ public function getPairs($type)
+ {
+ $pipline = $this->dao->select('id,name')->from(TABLE_PIPLINE)
+ ->where('deleted')->eq('0')
+ ->AndWhere('type')->eq($type)
+ ->orderBy('id')->fetchPairs('id', 'name');
+ $pipline = array('' => '') + $pipline;
+ return $pipline;
+ }
+
+ /**
+ * Create a pipline.
+ *
+ * @access public
+ * @return bool
+ */
+ public function create($type)
+ {
+ $pipline = fixer::input('post')
+ ->add('type', $type)
+ ->add('createdBy', $this->app->user->account)
+ ->add('createdDate', helper::now())
+ ->skipSpecial('url,token,account,password')
+ ->get();
+
+ $pipline->password = base64_encode($pipline->password);
+
+ $this->dao->insert(TABLE_PIPLINE)->data($pipline)
+ ->batchCheck($this->config->pipline->create->requiredFields, 'notempty')
+ ->batchCheck("url", 'URL')
+ ->autoCheck()
+ ->exec();
+ if(dao::isError()) return false;
+ return $this->dao->lastInsertId();
+ }
+
+ /**
+ * Update a pipline.
+ *
+ * @param int $id
+ * @access public
+ * @return bool
+ */
+ public function update($id)
+ {
+ $pipline = fixer::input('post')
+ ->add('editedBy', $this->app->user->account)
+ ->add('editedDate', helper::now())
+ ->skipSpecial('url,token,account,password')
+ ->get();
+
+ $pipline->password = base64_encode($pipline->password);
+
+ $this->dao->update(TABLE_PIPLINE)->data($pipline)
+ ->batchCheck($this->config->pipline->edit->requiredFields, 'notempty')
+ ->batchCheck("url", 'URL')
+ ->autoCheck()
+ ->where('id')->eq($id)
+ ->exec();
+ return !dao::isError();
+ }
+}
From 08567f098a89edb1c74cc1130320cbc2fdfed79a Mon Sep 17 00:00:00 2001
From: Guanxiying
Date: Mon, 7 Jun 2021 18:53:52 +0800
Subject: [PATCH 005/269] * Rename jenkins table. + Add pipline module.
---
module/pipline/config.php | 5 +++++
1 file changed, 5 insertions(+)
create mode 100644 module/pipline/config.php
diff --git a/module/pipline/config.php b/module/pipline/config.php
new file mode 100644
index 0000000000..0228d4f00c
--- /dev/null
+++ b/module/pipline/config.php
@@ -0,0 +1,5 @@
+pipline->create = new stdclass();
+$config->pipline->edit = new stdclass();
+$config->pipline->create->requiredFields = 'name,url,type';
+$config->pipline->edit->requiredFields = 'name,url,type';
From 7ea2322002bfaf63b4d3451b0c252af700c4b6f0 Mon Sep 17 00:00:00 2001
From: dingguodong
Date: Tue, 8 Jun 2021 11:45:32 +0800
Subject: [PATCH 006/269] * Rename PIPLINE to PIPELINE.
---
config/zentaopms.php | 2 +-
module/{pipline => pipeline}/config.php | 0
module/{pipline => pipeline}/lang/zh-cn.php | 0
module/{pipline => pipeline}/model.php | 10 +++++-----
4 files changed, 6 insertions(+), 6 deletions(-)
rename module/{pipline => pipeline}/config.php (100%)
rename module/{pipline => pipeline}/lang/zh-cn.php (100%)
rename module/{pipline => pipeline}/model.php (91%)
diff --git a/config/zentaopms.php b/config/zentaopms.php
index b5e0f771de..5777863d6e 100644
--- a/config/zentaopms.php
+++ b/config/zentaopms.php
@@ -179,7 +179,7 @@ define('TABLE_LOG', '`' . $config->db->prefix . 'log`');
define('TABLE_SCORE', '`' . $config->db->prefix . 'score`');
define('TABLE_NOTIFY', '`' . $config->db->prefix . 'notify`');
define('TABLE_OAUTH', '`' . $config->db->prefix . 'oauth`');
-define('TABLE_PIPLINE', '`' . $config->db->prefix . 'jenkins`');
+define('TABLE_PIPELINE', '`' . $config->db->prefix . 'jenkins`');
define('TABLE_JOB', '`' . $config->db->prefix . 'job`');
define('TABLE_COMPILE', '`' . $config->db->prefix . 'compile`');
diff --git a/module/pipline/config.php b/module/pipeline/config.php
similarity index 100%
rename from module/pipline/config.php
rename to module/pipeline/config.php
diff --git a/module/pipline/lang/zh-cn.php b/module/pipeline/lang/zh-cn.php
similarity index 100%
rename from module/pipline/lang/zh-cn.php
rename to module/pipeline/lang/zh-cn.php
diff --git a/module/pipline/model.php b/module/pipeline/model.php
similarity index 91%
rename from module/pipline/model.php
rename to module/pipeline/model.php
index eb73a6a595..38fc423af9 100644
--- a/module/pipline/model.php
+++ b/module/pipeline/model.php
@@ -21,7 +21,7 @@ class piplineModel extends model
*/
public function getByID($id)
{
- $pipline = $this->dao->select('*')->from(TABLE_PIPLINE)->where('id')->eq($id)->fetch();
+ $pipline = $this->dao->select('*')->from(TABLE_PIPELINE)->where('id')->eq($id)->fetch();
$pipline->password = base64_decode($pipline->password);
return $pipline;
}
@@ -37,7 +37,7 @@ class piplineModel extends model
*/
public function getList($type = 'jenkins', $orderBy = 'id_desc', $pager = null)
{
- return $this->dao->select('*')->from(TABLE_PIPLINE)
+ return $this->dao->select('*')->from(TABLE_PIPELINE)
->where('deleted')->eq('0')
->AndWhere('type')->eq($type)
->orderBy($orderBy)
@@ -52,7 +52,7 @@ class piplineModel extends model
*/
public function getPairs($type)
{
- $pipline = $this->dao->select('id,name')->from(TABLE_PIPLINE)
+ $pipline = $this->dao->select('id,name')->from(TABLE_PIPELINE)
->where('deleted')->eq('0')
->AndWhere('type')->eq($type)
->orderBy('id')->fetchPairs('id', 'name');
@@ -77,7 +77,7 @@ class piplineModel extends model
$pipline->password = base64_encode($pipline->password);
- $this->dao->insert(TABLE_PIPLINE)->data($pipline)
+ $this->dao->insert(TABLE_PIPELINE)->data($pipline)
->batchCheck($this->config->pipline->create->requiredFields, 'notempty')
->batchCheck("url", 'URL')
->autoCheck()
@@ -103,7 +103,7 @@ class piplineModel extends model
$pipline->password = base64_encode($pipline->password);
- $this->dao->update(TABLE_PIPLINE)->data($pipline)
+ $this->dao->update(TABLE_PIPELINE)->data($pipline)
->batchCheck($this->config->pipline->edit->requiredFields, 'notempty')
->batchCheck("url", 'URL')
->autoCheck()
From e2157697e8ba4e1e01c3ebf6f9d32f133fad35d5 Mon Sep 17 00:00:00 2001
From: dingguodong
Date: Tue, 8 Jun 2021 12:13:16 +0800
Subject: [PATCH 007/269] * Rename pipline to pipeline.
---
module/pipeline/config.php | 8 +++----
module/pipeline/lang/zh-cn.php | 12 +++++-----
module/pipeline/model.php | 42 +++++++++++++++++-----------------
3 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/module/pipeline/config.php b/module/pipeline/config.php
index 0228d4f00c..29bc37b2ea 100644
--- a/module/pipeline/config.php
+++ b/module/pipeline/config.php
@@ -1,5 +1,5 @@
pipline->create = new stdclass();
-$config->pipline->edit = new stdclass();
-$config->pipline->create->requiredFields = 'name,url,type';
-$config->pipline->edit->requiredFields = 'name,url,type';
+$config->pipeline->create = new stdclass();
+$config->pipeline->edit = new stdclass();
+$config->pipeline->create->requiredFields = 'name,url,type';
+$config->pipeline->edit->requiredFields = 'name,url,type';
diff --git a/module/pipeline/lang/zh-cn.php b/module/pipeline/lang/zh-cn.php
index 8d81ee7093..b949e9998d 100644
--- a/module/pipeline/lang/zh-cn.php
+++ b/module/pipeline/lang/zh-cn.php
@@ -1,7 +1,7 @@
pipline->id = 'ID';
-$lang->pipline->name = '名称';
-$lang->pipline->url = '服务地址';
-$lang->pipline->token = 'Token';
-$lang->pipline->account = '用户名';
-$lang->pipline->password = '密码';
+$lang->pipeline->id = 'ID';
+$lang->pipeline->name = '名称';
+$lang->pipeline->url = '服务地址';
+$lang->pipeline->token = 'Token';
+$lang->pipeline->account = '用户名';
+$lang->pipeline->password = '密码';
diff --git a/module/pipeline/model.php b/module/pipeline/model.php
index 38fc423af9..b650093146 100644
--- a/module/pipeline/model.php
+++ b/module/pipeline/model.php
@@ -1,6 +1,6 @@
dao->select('*')->from(TABLE_PIPELINE)->where('id')->eq($id)->fetch();
- $pipline->password = base64_decode($pipline->password);
- return $pipline;
+ $pipeline = $this->dao->select('*')->from(TABLE_PIPELINE)->where('id')->eq($id)->fetch();
+ $pipeline->password = base64_decode($pipeline->password);
+ return $pipeline;
}
/**
- * Get pipline list.
+ * Get pipeline list.
*
* @param string $type jenkins|gitlab
* @param string $orderBy
@@ -46,39 +46,39 @@ class piplineModel extends model
}
/**
- * Get pipline pairs
+ * Get pipeline pairs
*
* @return array
*/
public function getPairs($type)
{
- $pipline = $this->dao->select('id,name')->from(TABLE_PIPELINE)
+ $pipeline = $this->dao->select('id,name')->from(TABLE_PIPELINE)
->where('deleted')->eq('0')
->AndWhere('type')->eq($type)
->orderBy('id')->fetchPairs('id', 'name');
- $pipline = array('' => '') + $pipline;
- return $pipline;
+ $pipeline = array('' => '') + $pipeline;
+ return $pipeline;
}
/**
- * Create a pipline.
+ * Create a pipeline.
*
* @access public
* @return bool
*/
public function create($type)
{
- $pipline = fixer::input('post')
+ $pipeline = fixer::input('post')
->add('type', $type)
->add('createdBy', $this->app->user->account)
->add('createdDate', helper::now())
->skipSpecial('url,token,account,password')
->get();
- $pipline->password = base64_encode($pipline->password);
+ $pipeline->password = base64_encode($pipeline->password);
- $this->dao->insert(TABLE_PIPELINE)->data($pipline)
- ->batchCheck($this->config->pipline->create->requiredFields, 'notempty')
+ $this->dao->insert(TABLE_PIPELINE)->data($pipeline)
+ ->batchCheck($this->config->pipeline->create->requiredFields, 'notempty')
->batchCheck("url", 'URL')
->autoCheck()
->exec();
@@ -87,7 +87,7 @@ class piplineModel extends model
}
/**
- * Update a pipline.
+ * Update a pipeline.
*
* @param int $id
* @access public
@@ -95,16 +95,16 @@ class piplineModel extends model
*/
public function update($id)
{
- $pipline = fixer::input('post')
+ $pipeline = fixer::input('post')
->add('editedBy', $this->app->user->account)
->add('editedDate', helper::now())
->skipSpecial('url,token,account,password')
->get();
- $pipline->password = base64_encode($pipline->password);
+ $pipeline->password = base64_encode($pipeline->password);
- $this->dao->update(TABLE_PIPELINE)->data($pipline)
- ->batchCheck($this->config->pipline->edit->requiredFields, 'notempty')
+ $this->dao->update(TABLE_PIPELINE)->data($pipeline)
+ ->batchCheck($this->config->pipeline->edit->requiredFields, 'notempty')
->batchCheck("url", 'URL')
->autoCheck()
->where('id')->eq($id)
From 4492f5f23c12e101cf054a07f3ffbbd7453d44fd Mon Sep 17 00:00:00 2001
From: Guanxiying
Date: Tue, 8 Jun 2021 13:04:03 +0800
Subject: [PATCH 008/269] * Rename jenkins table.
---
db/zentao.sql | 5 ++--
module/ci/control.php | 2 +-
module/ci/model.php | 2 +-
module/compile/model.php | 4 ++--
module/gitlab/model.php | 10 ++++----
module/jenkins/control.php | 2 +-
module/jenkins/model.php | 49 ++++----------------------------------
module/job/model.php | 4 ++--
8 files changed, 20 insertions(+), 58 deletions(-)
diff --git a/db/zentao.sql b/db/zentao.sql
index fa9301cc1e..adcd1b45d3 100644
--- a/db/zentao.sql
+++ b/db/zentao.sql
@@ -471,9 +471,10 @@ CREATE TABLE IF NOT EXISTS `zt_history` (
PRIMARY KEY (`id`),
KEY `action` (`action`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--- DROP TABLE IF EXISTS `zt_jenkins`;
-CREATE TABLE IF NOT EXISTS `zt_jenkins` (
+-- 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,
`url` varchar(255) DEFAULT NULL,
`account` varchar(30) DEFAULT NULL,
diff --git a/module/ci/control.php b/module/ci/control.php
index b22366f61e..654a48a2a1 100644
--- a/module/ci/control.php
+++ b/module/ci/control.php
@@ -104,7 +104,7 @@ class ci extends control
{
$compile = $this->dao->select('t1.*, t2.jkJob,t2.product,t2.frame,t3.name as jenkinsName,t3.url,t3.account,t3.token,t3.password')->from(TABLE_COMPILE)->alias('t1')
->leftJoin(TABLE_JOB)->alias('t2')->on('t1.job=t2.id')
- ->leftJoin(TABLE_JENKINS)->alias('t3')->on('t2.jkHost=t3.id')
+ ->leftJoin(TABLE_PIPELINE)->alias('t3')->on('t2.jkHost=t3.id')
->where('t1.id')->eq($compileID)
->fetch();
diff --git a/module/ci/model.php b/module/ci/model.php
index 46ff711cc9..3a0093d85e 100644
--- a/module/ci/model.php
+++ b/module/ci/model.php
@@ -31,7 +31,7 @@ class ciModel extends model
$compiles = $this->dao->select('t1.*, t2.jkJob, t3.name as jenkinsName,t3.url,t3.account,t3.token,t3.password')
->from(TABLE_COMPILE)->alias('t1')
->leftJoin(TABLE_JOB)->alias('t2')->on('t1.job=t2.id')
- ->leftJoin(TABLE_JENKINS)->alias('t3')->on('t2.jkHost=t3.id')
+ ->leftJoin(TABLE_PIPELINE)->alias('t3')->on('t2.jkHost=t3.id')
->where('t1.status')->ne('success')
->andWhere('t1.status')->ne('failure')
->andWhere('t1.status')->ne('create_fail')
diff --git a/module/compile/model.php b/module/compile/model.php
index 7f82a344ce..f9f1646335 100644
--- a/module/compile/model.php
+++ b/module/compile/model.php
@@ -37,7 +37,7 @@ class compileModel extends model
return $this->dao->select('t1.id, t1.name, t1.job, t1.status, t1.createdDate,t1.testtask, t2.jkJob,t2.triggerType,t2.comment,t2.atDay,t2.atTime, t3.name as repoName, t4.name as jenkinsName')->from(TABLE_COMPILE)->alias('t1')
->leftJoin(TABLE_JOB)->alias('t2')->on('t1.job=t2.id')
->leftJoin(TABLE_REPO)->alias('t3')->on('t2.repo=t3.id')
- ->leftJoin(TABLE_JENKINS)->alias('t4')->on('t2.jkHost=t4.id')
+ ->leftJoin(TABLE_PIPELINE)->alias('t4')->on('t2.jkHost=t4.id')
->where('t1.deleted')->eq('0')
->andWhere('t1.job')->ne('0')
->beginIF(!empty($jobID))->andWhere('t1.job')->eq($jobID)->fi()
@@ -123,7 +123,7 @@ class compileModel extends model
{
$job = $this->dao->select('t1.id,t1.name,t1.repo,t1.jkJob,t2.name as jenkinsName,t2.url,t2.account,t2.token,t2.password')
->from(TABLE_JOB)->alias('t1')
- ->leftJoin(TABLE_JENKINS)->alias('t2')->on('t1.jkHost=t2.id')
+ ->leftJoin(TABLE_PIPELINE)->alias('t2')->on('t1.jkHost=t2.id')
->where('t1.id')->eq($compile->job)
->fetch();
diff --git a/module/gitlab/model.php b/module/gitlab/model.php
index 51d296384a..9ede8dfaa1 100644
--- a/module/gitlab/model.php
+++ b/module/gitlab/model.php
@@ -21,7 +21,7 @@ class gitlabModel extends model
*/
public function getByID($id)
{
- $gitlab = $this->dao->select('*')->from(TABLE_JENKINS)->where('id')->eq($id)->fetch();
+ $gitlab = $this->dao->select('*')->from(TABLE_PIPELINE)->where('id')->eq($id)->fetch();
$gitlab->password = base64_decode($gitlab->password);
return $gitlab;
@@ -37,7 +37,7 @@ class gitlabModel extends model
*/
public function getList($orderBy = 'id_desc', $pager = null)
{
- return $this->dao->select('*')->from(TABLE_JENKINS)
+ return $this->dao->select('*')->from(TABLE_PIPELINE)
->where('deleted')->eq('0')
->andwhere('type')->eq('1')
->orderBy($orderBy)
@@ -52,7 +52,7 @@ class gitlabModel extends model
*/
public function getPairs()
{
- $gitlab = $this->dao->select('id,name')->from(TABLE_JENKINS)
+ $gitlab = $this->dao->select('id,name')->from(TABLE_PIPELINE)
->where('deleted')->eq('0')
->orderBy('id')->fetchPairs('id', 'name');
$gitlab = array('' => '') + $gitlab;
@@ -74,7 +74,7 @@ class gitlabModel extends model
->skipSpecial('url,token')
->get();
- $this->dao->insert(TABLE_JENKINS)->data($gitlab)
+ $this->dao->insert(TABLE_PIPELINE)->data($gitlab)
->batchCheck($this->config->gitlab->create->requiredFields, 'notempty')
->batchCheck("url", 'URL')
->autoCheck()
@@ -98,7 +98,7 @@ class gitlabModel extends model
->skipSpecial('url,token')
->get();
- $this->dao->update(TABLE_JENKINS)->data($gitlab)
+ $this->dao->update(TABLE_PIPELINE)->data($gitlab)
->batchCheck($this->config->gitlab->edit->requiredFields, 'notempty')
->batchCheck("url", 'URL')
->autoCheck()
diff --git a/module/jenkins/control.php b/module/jenkins/control.php
index 70c030d2a4..1a77a02d27 100644
--- a/module/jenkins/control.php
+++ b/module/jenkins/control.php
@@ -111,7 +111,7 @@ class jenkins extends control
{
if($confim != 'yes') die(js::confirm($this->lang->jenkins->confirmDelete, inlink('delete', "id=$id&confirm=yes")));
- $this->jenkins->delete(TABLE_JENKINS, $id);
+ $this->jenkins->delete(TABLE_PIPELINE, $id);
die(js::reload('parent'));
}
diff --git a/module/jenkins/model.php b/module/jenkins/model.php
index 2d12469a3f..2c7eab673a 100644
--- a/module/jenkins/model.php
+++ b/module/jenkins/model.php
@@ -21,10 +21,7 @@ class jenkinsModel extends model
*/
public function getByID($id)
{
- $jenkins = $this->dao->select('*')->from(TABLE_JENKINS)->where('id')->eq($id)->fetch();
- $jenkins->password = base64_decode($jenkins->password);
-
- return $jenkins;
+ return $this->loadModel('pipline')->getByID($id);
}
/**
@@ -37,11 +34,7 @@ class jenkinsModel extends model
*/
public function getList($orderBy = 'id_desc', $pager = null)
{
- return $this->dao->select('*')->from(TABLE_JENKINS)
- ->where('deleted')->eq('0')
- ->orderBy($orderBy)
- ->page($pager)
- ->fetchAll('id');
+ return $this->loadModel('pipline')->getList('jenkins', $orderBy, $pager);
}
/**
@@ -51,11 +44,7 @@ class jenkinsModel extends model
*/
public function getPairs()
{
- $jenkins = $this->dao->select('id,name')->from(TABLE_JENKINS)
- ->where('deleted')->eq('0')
- ->orderBy('id')->fetchPairs('id', 'name');
- $jenkins = array('' => '') + $jenkins;
- return $jenkins;
+ return $this->loadModel('pipline')->getPairs('jenkins');
}
/**
@@ -94,21 +83,7 @@ class jenkinsModel extends model
*/
public function create()
{
- $jenkins = fixer::input('post')
- ->add('createdBy', $this->app->user->account)
- ->add('createdDate', helper::now())
- ->skipSpecial('url,token,account,password')
- ->get();
-
- $jenkins->password = base64_encode($jenkins->password);
-
- $this->dao->insert(TABLE_JENKINS)->data($jenkins)
- ->batchCheck($this->config->jenkins->create->requiredFields, 'notempty')
- ->batchCheck("url", 'URL')
- ->autoCheck()
- ->exec();
- if(dao::isError()) return false;
- return $this->dao->lastInsertId();
+ return $this->loadModel('pipline')->create('jenkins');
}
/**
@@ -120,20 +95,6 @@ class jenkinsModel extends model
*/
public function update($id)
{
- $jenkins = fixer::input('post')
- ->add('editedBy', $this->app->user->account)
- ->add('editedDate', helper::now())
- ->skipSpecial('url,token,account,password')
- ->get();
-
- $jenkins->password = base64_encode($jenkins->password);
-
- $this->dao->update(TABLE_JENKINS)->data($jenkins)
- ->batchCheck($this->config->jenkins->edit->requiredFields, 'notempty')
- ->batchCheck("url", 'URL')
- ->autoCheck()
- ->where('id')->eq($id)
- ->exec();
- return !dao::isError();
+ return $this->loadModel('pipline')->update($id);
}
}
diff --git a/module/job/model.php b/module/job/model.php
index 5d19e6c298..c948ada4e7 100644
--- a/module/job/model.php
+++ b/module/job/model.php
@@ -35,7 +35,7 @@ class jobModel extends model
{
return $this->dao->select('t1.*, t2.name as repoName, t3.name as jenkinsName')->from(TABLE_JOB)->alias('t1')
->leftJoin(TABLE_REPO)->alias('t2')->on('t1.repo=t2.id')
- ->leftJoin(TABLE_JENKINS)->alias('t3')->on('t1.jkHost=t3.id')
+ ->leftJoin(TABLE_PIPELINE)->alias('t3')->on('t1.jkHost=t3.id')
->where('t1.deleted')->eq('0')
->orderBy($orderBy)
->page($pager)
@@ -290,7 +290,7 @@ class jobModel extends model
{
$job = $this->dao->select('t1.id,t1.name,t1.product,t1.repo,t1.jkJob,t1.triggerType,t1.atTime,t1.customParam,t2.name as jenkinsName,t2.url,t2.account,t2.token,t2.password')
->from(TABLE_JOB)->alias('t1')
- ->leftJoin(TABLE_JENKINS)->alias('t2')->on('t1.jkHost=t2.id')
+ ->leftJoin(TABLE_PIPELINE)->alias('t2')->on('t1.jkHost=t2.id')
->where('t1.id')->eq($id)
->fetch();
if(!$job) return false;
From f27fef0b00c4e6339c7da43017805de2cea8c4c2 Mon Sep 17 00:00:00 2001
From: Guanxiying
Date: Tue, 8 Jun 2021 13:16:58 +0800
Subject: [PATCH 009/269] * Call pipeline model in gitlab model.
---
config/zentaopms.php | 2 +-
module/gitlab/model.php | 49 ++++------------------------------------
module/jenkins/model.php | 10 ++++----
3 files changed, 11 insertions(+), 50 deletions(-)
diff --git a/config/zentaopms.php b/config/zentaopms.php
index 5777863d6e..6a8fe3ca3a 100644
--- a/config/zentaopms.php
+++ b/config/zentaopms.php
@@ -179,7 +179,7 @@ define('TABLE_LOG', '`' . $config->db->prefix . 'log`');
define('TABLE_SCORE', '`' . $config->db->prefix . 'score`');
define('TABLE_NOTIFY', '`' . $config->db->prefix . 'notify`');
define('TABLE_OAUTH', '`' . $config->db->prefix . 'oauth`');
-define('TABLE_PIPELINE', '`' . $config->db->prefix . 'jenkins`');
+define('TABLE_PIPELINE', '`' . $config->db->prefix . 'pipeline`');
define('TABLE_JOB', '`' . $config->db->prefix . 'job`');
define('TABLE_COMPILE', '`' . $config->db->prefix . 'compile`');
diff --git a/module/gitlab/model.php b/module/gitlab/model.php
index 9ede8dfaa1..0e123d100c 100644
--- a/module/gitlab/model.php
+++ b/module/gitlab/model.php
@@ -21,10 +21,7 @@ class gitlabModel extends model
*/
public function getByID($id)
{
- $gitlab = $this->dao->select('*')->from(TABLE_PIPELINE)->where('id')->eq($id)->fetch();
- $gitlab->password = base64_decode($gitlab->password);
-
- return $gitlab;
+ return $this->loadModel('pipeline')->getByID($id);
}
/**
@@ -37,12 +34,7 @@ class gitlabModel extends model
*/
public function getList($orderBy = 'id_desc', $pager = null)
{
- return $this->dao->select('*')->from(TABLE_PIPELINE)
- ->where('deleted')->eq('0')
- ->andwhere('type')->eq('1')
- ->orderBy($orderBy)
- ->page($pager)
- ->fetchAll('id');
+ return $this->loadModel('pipeline')->getList('gitlab', $orderBy, $pager);
}
/**
@@ -52,11 +44,7 @@ class gitlabModel extends model
*/
public function getPairs()
{
- $gitlab = $this->dao->select('id,name')->from(TABLE_PIPELINE)
- ->where('deleted')->eq('0')
- ->orderBy('id')->fetchPairs('id', 'name');
- $gitlab = array('' => '') + $gitlab;
- return $gitlab;
+ return $this->loadModel('pipeline')->getPairs('gitlab');
}
/**
@@ -67,20 +55,7 @@ class gitlabModel extends model
*/
public function create()
{
- $gitlab = fixer::input('post')
- ->add('createdBy', $this->app->user->account)
- ->add('createdDate', helper::now())
- ->add('type', 1)
- ->skipSpecial('url,token')
- ->get();
-
- $this->dao->insert(TABLE_PIPELINE)->data($gitlab)
- ->batchCheck($this->config->gitlab->create->requiredFields, 'notempty')
- ->batchCheck("url", 'URL')
- ->autoCheck()
- ->exec();
- if(dao::isError()) return false;
- return $this->dao->lastInsertId();
+ return $this->loadModel('pipeline')->create('gitlab');
}
/**
@@ -92,19 +67,7 @@ class gitlabModel extends model
*/
public function update($id)
{
- $gitlab = fixer::input('post')
- ->add('editedBy', $this->app->user->account)
- ->add('editedDate', helper::now())
- ->skipSpecial('url,token')
- ->get();
-
- $this->dao->update(TABLE_PIPELINE)->data($gitlab)
- ->batchCheck($this->config->gitlab->edit->requiredFields, 'notempty')
- ->batchCheck("url", 'URL')
- ->autoCheck()
- ->where('id')->eq($id)
- ->exec();
- return !dao::isError();
+ return $this->loadModel('pipeline')->update($id);
}
/**
@@ -119,10 +82,8 @@ class gitlabModel extends model
{
$host = rtrim($host, '/');
$host .= '/api/v4/activities';
-
$results = json_decode(file_get_contents($host . "?private_token=$token"));
return $results;
}
-
}
diff --git a/module/jenkins/model.php b/module/jenkins/model.php
index 2c7eab673a..48eaa13a1b 100644
--- a/module/jenkins/model.php
+++ b/module/jenkins/model.php
@@ -21,7 +21,7 @@ class jenkinsModel extends model
*/
public function getByID($id)
{
- return $this->loadModel('pipline')->getByID($id);
+ return $this->loadModel('pipeline')->getByID($id);
}
/**
@@ -34,7 +34,7 @@ class jenkinsModel extends model
*/
public function getList($orderBy = 'id_desc', $pager = null)
{
- return $this->loadModel('pipline')->getList('jenkins', $orderBy, $pager);
+ return $this->loadModel('pipeline')->getList('jenkins', $orderBy, $pager);
}
/**
@@ -44,7 +44,7 @@ class jenkinsModel extends model
*/
public function getPairs()
{
- return $this->loadModel('pipline')->getPairs('jenkins');
+ return $this->loadModel('pipeline')->getPairs('jenkins');
}
/**
@@ -83,7 +83,7 @@ class jenkinsModel extends model
*/
public function create()
{
- return $this->loadModel('pipline')->create('jenkins');
+ return $this->loadModel('pipeline')->create('jenkins');
}
/**
@@ -95,6 +95,6 @@ class jenkinsModel extends model
*/
public function update($id)
{
- return $this->loadModel('pipline')->update($id);
+ return $this->loadModel('pipeline')->update($id);
}
}
From 42eb835fa33d8b98d56c650a72a95fd8468f5b19 Mon Sep 17 00:00:00 2001
From: "David.li" <1441836644@qq.com>
Date: Tue, 8 Jun 2021 13:31:44 +0800
Subject: [PATCH 010/269] * Add
---
config/zentaopms.php | 2 +-
module/gitlab/config.php | 4 +--
module/gitlab/control.php | 6 +++--
module/gitlab/js/create.js | 39 +++++++++++++++---------------
module/gitlab/model.php | 14 +++++------
module/gitlab/view/create.html.php | 2 +-
6 files changed, 35 insertions(+), 32 deletions(-)
diff --git a/config/zentaopms.php b/config/zentaopms.php
index b5e0f771de..a0b8dc0ede 100644
--- a/config/zentaopms.php
+++ b/config/zentaopms.php
@@ -179,7 +179,7 @@ define('TABLE_LOG', '`' . $config->db->prefix . 'log`');
define('TABLE_SCORE', '`' . $config->db->prefix . 'score`');
define('TABLE_NOTIFY', '`' . $config->db->prefix . 'notify`');
define('TABLE_OAUTH', '`' . $config->db->prefix . 'oauth`');
-define('TABLE_PIPLINE', '`' . $config->db->prefix . 'jenkins`');
+define('TABLE_PIPLINE', '`' . $config->db->prefix . 'pipline`');
define('TABLE_JOB', '`' . $config->db->prefix . 'job`');
define('TABLE_COMPILE', '`' . $config->db->prefix . 'compile`');
diff --git a/module/gitlab/config.php b/module/gitlab/config.php
index 854bdb3c4d..3a840d46db 100644
--- a/module/gitlab/config.php
+++ b/module/gitlab/config.php
@@ -2,5 +2,5 @@
$config->gitlab->create = new stdclass();
$config->gitlab->edit = new stdclass();
-$config->gitlab->create->requiredFields = 'name,url';
-$config->gitlab->edit->requiredFields = 'name,url';
+$config->gitlab->create->requiredFields = 'name,url,token';
+$config->gitlab->edit->requiredFields = 'name,url,token';
diff --git a/module/gitlab/control.php b/module/gitlab/control.php
index f00cc8b081..c83b1e0103 100644
--- a/module/gitlab/control.php
+++ b/module/gitlab/control.php
@@ -72,7 +72,9 @@ class gitlab extends control
*/
public function bind()
{
- echo 123;die;
+ var_dump($this->gitlab->getPermissionsByToken('http://127.0.0.1:8090/','rpz2PZKriNE6TD34QtDA'));
+ die;
+
$this->display();
}
@@ -113,7 +115,7 @@ class gitlab extends control
{
if($confim != 'yes') die(js::confirm($this->lang->gitlab->confirmDelete, inlink('delete', "id=$id&confirm=yes")));
- $this->gitlab->delete(TABLE_GITLAB, $id);
+ $this->gitlab->delete(TABLE_PIPLINE, $id);
die(js::reload('parent'));
}
diff --git a/module/gitlab/js/create.js b/module/gitlab/js/create.js
index 6410b0fdc0..549191d4ee 100644
--- a/module/gitlab/js/create.js
+++ b/module/gitlab/js/create.js
@@ -1,24 +1,25 @@
$(function () {
- $('#token, #url').change(function () {
- //取用户名
- var uid = $("#uid").val();
+ $('#url,#token').change(function () {
+ $('#url, #url').change(function () {
+ host = Base64.encode($('#url').val());
+ token = $('#token').val();
+ url = createLink('gitlab', 'ajaxCheckToken', "host=" + host + '&token=' + token);
+ if (host == '' || token == '') return false;
+
+ $.get(url, function (response) {
+ if(response.message == '401 Unauthorized')
+ {
+ $('td.demand').each(function() {
+ var dl = $(this).text();
+ // change the td html to the link, referencing the DL-XXX number
+ $(this).html('' + dl + '');
+ });
+ }else if (response.message == '403 Forbidden'){
+
+ }else {
- //调ajax
- $.ajax({
- url: "uidchuli.php",
- data: {u: uid},
- type: "POST",
- dataType: "TEXT",
- success: function (data) {
- if (data > 0) {
- $("#ts").html("该应户名已存在");
- $("#ts").css("color", "red");
- } else {
- $("#ts").html("该应户名可用");
- $("#ts").css("color", "green");
}
- }
-
+ });
});
- })
+ });
});
diff --git a/module/gitlab/model.php b/module/gitlab/model.php
index 51d296384a..e1a9f6873b 100644
--- a/module/gitlab/model.php
+++ b/module/gitlab/model.php
@@ -21,7 +21,7 @@ class gitlabModel extends model
*/
public function getByID($id)
{
- $gitlab = $this->dao->select('*')->from(TABLE_JENKINS)->where('id')->eq($id)->fetch();
+ $gitlab = $this->dao->select('*')->from(TABLE_PIPLINE)->where('id')->eq($id)->fetch();
$gitlab->password = base64_decode($gitlab->password);
return $gitlab;
@@ -37,7 +37,7 @@ class gitlabModel extends model
*/
public function getList($orderBy = 'id_desc', $pager = null)
{
- return $this->dao->select('*')->from(TABLE_JENKINS)
+ return $this->dao->select('*')->from(TABLE_PIPLINE)
->where('deleted')->eq('0')
->andwhere('type')->eq('1')
->orderBy($orderBy)
@@ -52,7 +52,7 @@ class gitlabModel extends model
*/
public function getPairs()
{
- $gitlab = $this->dao->select('id,name')->from(TABLE_JENKINS)
+ $gitlab = $this->dao->select('id,name')->from(TABLE_PIPLINE)
->where('deleted')->eq('0')
->orderBy('id')->fetchPairs('id', 'name');
$gitlab = array('' => '') + $gitlab;
@@ -74,9 +74,9 @@ class gitlabModel extends model
->skipSpecial('url,token')
->get();
- $this->dao->insert(TABLE_JENKINS)->data($gitlab)
+
+ $this->dao->insert(TABLE_PIPLINE)->data($gitlab)
->batchCheck($this->config->gitlab->create->requiredFields, 'notempty')
- ->batchCheck("url", 'URL')
->autoCheck()
->exec();
if(dao::isError()) return false;
@@ -98,7 +98,7 @@ class gitlabModel extends model
->skipSpecial('url,token')
->get();
- $this->dao->update(TABLE_JENKINS)->data($gitlab)
+ $this->dao->update(TABLE_PIPLINE)->data($gitlab)
->batchCheck($this->config->gitlab->edit->requiredFields, 'notempty')
->batchCheck("url", 'URL')
->autoCheck()
@@ -118,7 +118,7 @@ class gitlabModel extends model
public function getPermissionsByToken($host, $token)
{
$host = rtrim($host, '/');
- $host .= '/api/v4/activities';
+ $host .= '/api/v4/user/activities';
$results = json_decode(file_get_contents($host . "?private_token=$token"));
diff --git a/module/gitlab/view/create.html.php b/module/gitlab/view/create.html.php
index c34e0d8d05..9340117584 100644
--- a/module/gitlab/view/create.html.php
+++ b/module/gitlab/view/create.html.php
@@ -32,7 +32,7 @@
| gitlab->token;?> |
|
- gitlab->tokenFirst;?> |
+ Store Pickup Store Pickup |
|
From b9584dc3c2d0f4c49e20d44199252681b28c6de2 Mon Sep 17 00:00:00 2001
From: Guanxiying
Date: Tue, 8 Jun 2021 16:53:22 +0800
Subject: [PATCH 011/269] * Finish task 38937.
---
module/gitlab/control.php | 8 +++++++-
module/gitlab/js/create.js | 25 -------------------------
module/gitlab/lang/zh-cn.php | 5 +++--
module/gitlab/model.php | 11 +++++++----
module/gitlab/view/create.html.php | 7 ++++---
module/gitlab/view/edit.html.php | 3 +--
module/pipeline/model.php | 4 ++--
7 files changed, 24 insertions(+), 39 deletions(-)
delete mode 100644 module/gitlab/js/create.js
diff --git a/module/gitlab/control.php b/module/gitlab/control.php
index c83b1e0103..0abef3a2cf 100644
--- a/module/gitlab/control.php
+++ b/module/gitlab/control.php
@@ -50,6 +50,9 @@ class gitlab extends control
{
if($_POST)
{
+ $tokenValid = $this->gitlab->getPermissionsByToken($this->post->url, $this->post->token);
+ if($tokenValid['result'] == 'fail') $this->send($tokenValid);
+
$gitlabID = $this->gitlab->create();
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $gitlabID));
@@ -90,6 +93,9 @@ class gitlab extends control
$gitlab = $this->gitlab->getByID($id);
if($_POST)
{
+ $tokenValid = $this->gitlab->getPermissionsByToken($this->post->url, $this->post->token);
+ if($tokenValid['result'] == 'fail') $this->send($tokenValid);
+
$this->gitlab->update($id);
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
$this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse')));
@@ -131,6 +137,6 @@ class gitlab extends control
{
$host = helper::safe64Decode($host);
$permissions = $this->gitlab->getPermissionsByToken($host, $token);
-
+ $this->send($permissions);
}
}
diff --git a/module/gitlab/js/create.js b/module/gitlab/js/create.js
deleted file mode 100644
index 549191d4ee..0000000000
--- a/module/gitlab/js/create.js
+++ /dev/null
@@ -1,25 +0,0 @@
-$(function () {
- $('#url,#token').change(function () {
- $('#url, #url').change(function () {
- host = Base64.encode($('#url').val());
- token = $('#token').val();
- url = createLink('gitlab', 'ajaxCheckToken', "host=" + host + '&token=' + token);
- if (host == '' || token == '') return false;
-
- $.get(url, function (response) {
- if(response.message == '401 Unauthorized')
- {
- $('td.demand').each(function() {
- var dl = $(this).text();
- // change the td html to the link, referencing the DL-XXX number
- $(this).html('' + dl + '');
- });
- }else if (response.message == '403 Forbidden'){
-
- }else {
-
- }
- });
- });
- });
-});
diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php
index 1a5c554701..e02c2e3ddc 100644
--- a/module/gitlab/lang/zh-cn.php
+++ b/module/gitlab/lang/zh-cn.php
@@ -1,4 +1,5 @@
gitlab = new stdclass;
$lang->gitlab->common = 'Gitlab';
$lang->gitlab->browse = '浏览gitlab';
$lang->gitlab->create = '添加gitlab';
@@ -20,5 +21,5 @@ $lang->gitlab->desc = '描述';
$lang->gitlab->tokenFirst = 'Token不为空时,优先使用Token。';
$lang->gitlab->tips = '使用密码时,请在gitlab全局安全设置中禁用"防止跨站点请求伪造"选项。';
-/* 交互提示。*/
-$lang->gitlab->tokenPermissions = "当前token非root权限。";
+$lang->gitlab->tokenError = "当前token非管理员权限。";
+$lang->gitlab->hostError = "无效的gitlab服务地址。";
diff --git a/module/gitlab/model.php b/module/gitlab/model.php
index 0e123d100c..f1838c8ac8 100644
--- a/module/gitlab/model.php
+++ b/module/gitlab/model.php
@@ -80,10 +80,13 @@ class gitlabModel extends model
*/
public function getPermissionsByToken($host, $token)
{
- $host = rtrim($host, '/');
- $host .= '/api/v4/activities';
- $results = json_decode(file_get_contents($host . "?private_token=$token"));
+ if(strpos($host, 'http') !== 0) return array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)));
+ if(!$this->post->token) return array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)));
+ $host = rtrim($host, '/') . "/api/v4/user?private_token=$token";
+ $response = json_decode(commonModel::http($host));
- return $results;
+ 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)));
}
}
diff --git a/module/gitlab/view/create.html.php b/module/gitlab/view/create.html.php
index 9340117584..36d3dc6a8d 100644
--- a/module/gitlab/view/create.html.php
+++ b/module/gitlab/view/create.html.php
@@ -11,6 +11,7 @@
*/
?>
+
@@ -32,13 +33,13 @@
| gitlab->token;?> |
|
- Store Pickup Store Pickup |
+ |
|
-
-
+
+
|
diff --git a/module/gitlab/view/edit.html.php b/module/gitlab/view/edit.html.php
index d9af48a455..88d5c0767c 100644
--- a/module/gitlab/view/edit.html.php
+++ b/module/gitlab/view/edit.html.php
@@ -37,8 +37,7 @@
|
-
-
+
|
diff --git a/module/pipeline/model.php b/module/pipeline/model.php
index b650093146..ab5f8796d3 100644
--- a/module/pipeline/model.php
+++ b/module/pipeline/model.php
@@ -75,7 +75,7 @@ class pipelineModel extends model
->skipSpecial('url,token,account,password')
->get();
- $pipeline->password = base64_encode($pipeline->password);
+ if(isset($pipeline->password)) $pipeline->password = base64_encode($pipeline->password);
$this->dao->insert(TABLE_PIPELINE)->data($pipeline)
->batchCheck($this->config->pipeline->create->requiredFields, 'notempty')
@@ -101,7 +101,7 @@ class pipelineModel extends model
->skipSpecial('url,token,account,password')
->get();
- $pipeline->password = base64_encode($pipeline->password);
+ if(isset($pipeline->password)) $pipeline->password = base64_encode($pipeline->password);
$this->dao->update(TABLE_PIPELINE)->data($pipeline)
->batchCheck($this->config->pipeline->edit->requiredFields, 'notempty')
From f3f5574ad0f143a1e774e1d75fd2f7b7b4609290 Mon Sep 17 00:00:00 2001
From: Guanxiying
Date: Wed, 9 Jun 2021 19:16:30 +0800
Subject: [PATCH 012/269] * Change pipeline table name.
---
db/zentao.sql | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/db/zentao.sql b/db/zentao.sql
index adcd1b45d3..df7b01a6e7 100644
--- a/db/zentao.sql
+++ b/db/zentao.sql
@@ -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_pipline`;
-CREATE TABLE IF NOT EXISTS `zt_pipline` (
+-- DROP TABLE IF EXISTS `zt_pipeline`;
+CREATE TABLE IF NOT EXISTS `zt_pipeline` (
`id` smallint(8) unsigned NOT NULL AUTO_INCREMENT,
`type` char(30) NOT NULL,
`name` varchar(50) NOT NULL,
From a10130df5c4a398bc329b71734c208bafa8a79ba Mon Sep 17 00:00:00 2001
From: Guanxiying
Date: Wed, 9 Jun 2021 19:49:43 +0800
Subject: [PATCH 013/269] * Add getProjectsByID function.
---
module/gitlab/model.php | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/module/gitlab/model.php b/module/gitlab/model.php
index f1838c8ac8..6e090fb271 100644
--- a/module/gitlab/model.php
+++ b/module/gitlab/model.php
@@ -89,4 +89,27 @@ class gitlabModel extends model
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;
+ }
}
From 45412184bbeb9613934218eb135c11daf7f88e9d Mon Sep 17 00:00:00 2001
From: "David.li" <1441836644@qq.com>
Date: Wed, 9 Jun 2021 23:03:15 +0800
Subject: [PATCH 014/269] * Add getUserBindList Function.
---
module/gitlab/control.php | 5 ++++-
module/gitlab/model.php | 44 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/module/gitlab/control.php b/module/gitlab/control.php
index 0abef3a2cf..7a6df74d83 100644
--- a/module/gitlab/control.php
+++ b/module/gitlab/control.php
@@ -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();
diff --git a/module/gitlab/model.php b/module/gitlab/model.php
index f1838c8ac8..530cc97a13 100644
--- a/module/gitlab/model.php
+++ b/module/gitlab/model.php
@@ -85,8 +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 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);
+ }
}
From 3fd9aed0ce5c496efc4ef86414d260392d06710e Mon Sep 17 00:00:00 2001
From: Guanxiying
Date: Thu, 10 Jun 2021 13:48:44 +0800
Subject: [PATCH 015/269] * Fix TABLE_PIPELINE table.
---
module/gitlab/control.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/module/gitlab/control.php b/module/gitlab/control.php
index 0abef3a2cf..203de5bf1d 100644
--- a/module/gitlab/control.php
+++ b/module/gitlab/control.php
@@ -121,7 +121,7 @@ class gitlab extends control
{
if($confim != 'yes') die(js::confirm($this->lang->gitlab->confirmDelete, inlink('delete', "id=$id&confirm=yes")));
- $this->gitlab->delete(TABLE_PIPLINE, $id);
+ $this->gitlab->delete(TABLE_PIPELINE, $id);
die(js::reload('parent'));
}
@@ -135,7 +135,7 @@ class gitlab extends control
*/
public function ajaxCheckToken($host, $token)
{
- $host = helper::safe64Decode($host);
+ $host = helper::safe64Decode($host);
$permissions = $this->gitlab->getPermissionsByToken($host, $token);
$this->send($permissions);
}
From f918d0c652b7f59c95ba03ab86c508e2716ecbc9 Mon Sep 17 00:00:00 2001
From: Guanxiying
Date: Thu, 10 Jun 2021 13:59:44 +0800
Subject: [PATCH 016/269] * Set gitlab info by gitlab server.
---
module/repo/control.php | 56 +++++++++++++++++++++--------------------
1 file changed, 29 insertions(+), 27 deletions(-)
diff --git a/module/repo/control.php b/module/repo/control.php
index 4a747571c8..fb0183ddeb 100644
--- a/module/repo/control.php
+++ b/module/repo/control.php
@@ -129,11 +129,12 @@ class repo extends control
$this->app->loadLang('action');
- $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->create;
- $this->view->position[] = $this->lang->repo->create;
- $this->view->groups = $this->loadModel('group')->getPairs();
- $this->view->users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted');
- $this->view->products = $this->loadModel('product')->getProductPairsByProject($objectID);
+ $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->create;
+ $this->view->position[] = $this->lang->repo->create;
+ $this->view->groups = $this->loadModel('group')->getPairs();
+ $this->view->users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted');
+ $this->view->products = $this->loadModel('product')->getProductPairsByProject($objectID);
+ $this->view->gitlabHosts = $this->loadModel('gitlab')->getPairs();
$this->display();
}
@@ -168,21 +169,24 @@ class repo extends control
if($repo->SCM == 'Gitlab')
{
- $projects = $this->repo->getGitlabProjects($repo->client, $repo->password);
+ $projects = $this->loadModel('gitlab')->getProjectsByID($repo->client, $repo->password);
+
$options = array();
foreach($projects as $project) $options[$project->id] = $project->name . ':' . $project->http_url_to_repo;
+
$this->view->projects = $options;
}
- $repo->repoType = $repo->id . '-' . $repo->SCM;
- $this->view->repo = $repo;
- $this->view->repoID = $repoID;
- $this->view->objectID = $objectID;
- $this->view->groups = $this->loadModel('group')->getPairs();
- $this->view->users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted');
- $this->view->products = $objectID ? $this->loadModel('product')->getProductPairsByProject($objectID) : $this->loadModel('product')->getPairs();
+ $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->edit;
+ $repo->repoType = $repo->id . '-' . $repo->SCM;
+ $this->view->repo = $repo;
+ $this->view->repoID = $repoID;
+ $this->view->objectID = $objectID;
+ $this->view->groups = $this->loadModel('group')->getPairs();
+ $this->view->users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted');
+ $this->view->products = $objectID ? $this->loadModel('product')->getProductPairsByProject($objectID) : $this->loadModel('product')->getPairs();
+ $this->view->gitlabHosts = $this->loadModel('gitlab')->getPairs();
- $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->edit;
$this->view->position[] = html::a(inlink('maintain'), $this->lang->repo->common);
$this->view->position[] = $this->lang->repo->edit;
@@ -1105,25 +1109,23 @@ class repo extends control
/**
* Ajax get gitlab projects.
*
- * @param string $host
- * @param string $token
+ * @param int $host
* @access public
* @return void
*/
- public function ajaxGetGitlabProjects($host, $token)
+ public function ajaxGetGitlabProjects($host)
{
- $host = helper::safe64Decode($host);
- $projects = $this->repo->getGitlabProjects($host, $token);
+ $projects = $this->loadModel('gitlab')->getProjectsByID($host);
- if(!$projects) $this->send(array('message' => array()));
+ if(!$projects) $this->send(array('message' => array()));
- $options = "";
- foreach($projects as $project)
- {
- $options .= "";
- }
- die($options);
- }
+ $options = "";
+ foreach($projects as $project)
+ {
+ $options .= "";
+ }
+ die($options);
+ }
/**
* Ajax get branch drop menu.
From b995276fb103bbca8fa4cb2af51f163e3726f4a5 Mon Sep 17 00:00:00 2001
From: Guanxiying
Date: Thu, 10 Jun 2021 14:06:04 +0800
Subject: [PATCH 017/269] * Fix gitlab repo path and client field.
---
module/repo/model.php | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/module/repo/model.php b/module/repo/model.php
index c726c22366..9c04aa41ae 100644
--- a/module/repo/model.php
+++ b/module/repo/model.php
@@ -195,9 +195,9 @@ class repoModel extends model
if(!$this->checkConnection()) return false;
$data = fixer::input('post')
- ->setIf($this->post->SCM == 'Gitlab', 'password', $this->post->gitlabToken)
+ ->setIf($this->post->SCM == 'Gitlab', 'password', '')
+ ->setIf($this->post->SCM == 'Gitlab', 'path', $this->post->gitlabProject)
->setIf($this->post->SCM == 'Gitlab', 'client', $this->post->gitlabHost)
- ->setIf($this->post->SCM == 'Gitlab', 'extra', $this->post->gitlabProject)
->skipSpecial('path,client,account,password')
->setDefault('product', '')
->join('product', ',')
@@ -241,9 +241,9 @@ class repoModel extends model
$repo = $this->getRepoByID($id);
$data = fixer::input('post')
- ->setIf($this->post->SCM == 'Gitlab', 'password', $this->post->gitlabToken)
+ ->setIf($this->post->SCM == 'Gitlab', 'password', '')
+ ->setIf($this->post->SCM == 'Gitlab', 'path', $this->post->gitlabProject)
->setIf($this->post->SCM == 'Gitlab', 'client', $this->post->gitlabHost)
- ->setIf($this->post->SCM == 'Gitlab', 'extra', $this->post->gitlabProject)
->setDefault('client', 'svn')
->setDefault('prefix', $repo->prefix)
->setDefault('product', '')
@@ -251,7 +251,6 @@ class repoModel extends model
->join('product', ',')
->get();
- if($this->post->SCM == 'Gitlab') $data->path = sprintf($this->config->repo->gitlab->apiPath, $data->gitlabHost, $this->post->gitlabProject);
if($data->path != $repo->path) $data->synced = 0;
$data->acl = empty($data->acl) ? '' : json_encode($data->acl);
@@ -371,6 +370,7 @@ class repoModel extends model
if(!$repo) return false;
if($repo->encrypt == 'base64') $repo->password = base64_decode($repo->password);
+ if($repo->SCM == 'Gitlab') $reps = $this->processGitlab($repo);
$repo->acl = json_decode($repo->acl);
return $repo;
}
@@ -1752,4 +1752,14 @@ class repoModel extends model
return $allResults;
}
+
+ public function processGitlab($repo)
+ {
+ $gitlab = $this->loadModel('gitlab')->getByID($repo->client);
+ if(!$gitlab) return $repo;
+ $repo->path = sprintf($this->config->repo->gitlab->apiPath, $gitlab->url, $repo->path);
+ $repo->client = $gitlab->url;
+ $repo->password = $gitlab->token;
+ return $repo;
+ }
}
From 1847e38c73db0495d07036f4e47cceb2d0f2cb42 Mon Sep 17 00:00:00 2001
From: Guanxiying
Date: Thu, 10 Jun 2021 14:08:06 +0800
Subject: [PATCH 018/269] * Finish task 39216.
---
module/repo/js/create.js | 9 ++++-----
module/repo/js/edit.js | 10 ++++------
module/repo/view/create.html.php | 6 +-----
module/repo/view/edit.html.php | 18 ++++++------------
4 files changed, 15 insertions(+), 28 deletions(-)
diff --git a/module/repo/js/create.js b/module/repo/js/create.js
index 0af0d52404..2b9bff72e5 100644
--- a/module/repo/js/create.js
+++ b/module/repo/js/create.js
@@ -7,12 +7,11 @@ $(function()
$form.css('min-height', $form.height());
})
- $('#gitlabHost, #gitlabToken').change(function()
+ $('#gitlabHost').change(function()
{
- host = Base64.encode($('#gitlabHost').val());
- token = $('#gitlabToken').val();
- url = createLink('repo', 'ajaxgetgitlabprojects', "host=" + host + '&token=' + token);
- if(host == '' || token == '') return false;
+ host = $('#gitlabHost').val();
+ url = createLink('repo', 'ajaxgetgitlabprojects', "host=" + host);
+ if(host == '') return false;
$.get(url, function(response)
{
diff --git a/module/repo/js/edit.js b/module/repo/js/edit.js
index cc79cbb2a5..e500686f04 100644
--- a/module/repo/js/edit.js
+++ b/module/repo/js/edit.js
@@ -7,12 +7,11 @@ $(function()
$form.css('min-height', $form.height());
})
- $('#gitlabHost, #gitlabToken').change(function()
+ $('#gitlabHost').change(function()
{
- host = Base64.encode($('#gitlabHost').val());
- token = $('#gitlabToken').val();
- url = createLink('repo', 'ajaxgetgitlabprojects', "host=" + host + '&token=' + token);
- if(host == '' || token == '') return false;
+ host = $('#gitlabHost').val();
+ if(host == '') return false;
+ url = createLink('repo', 'ajaxgetgitlabprojects', "host=" + host);
$.get(url, function(response)
{
@@ -28,7 +27,6 @@ $(function()
$('#name').val($option.data('name'));
$(this).chosen().trigger("chosen:updated");
});
-
});
function scmChanged(scm)
diff --git a/module/repo/view/create.html.php b/module/repo/view/create.html.php
index 446da06b4e..62536c4a24 100644
--- a/module/repo/view/create.html.php
+++ b/module/repo/view/create.html.php
@@ -34,11 +34,7 @@
| repo->gitlabHost;?> |
- repo->placeholder->gitlabHost}'");?>
- |
-
- | repo->gitlabToken;?> |
-
+ | repo->placeholder->gitlabHost}'");?>
|
| repo->gitlabProject;?> |
diff --git a/module/repo/view/edit.html.php b/module/repo/view/edit.html.php
index 15f6d76846..f2352a2338 100644
--- a/module/repo/view/edit.html.php
+++ b/module/repo/view/edit.html.php
@@ -34,17 +34,11 @@
| repo->type; ?> |
repo->scmList, $repo->SCM, "onchange='scmChanged(this.value)' class='form-control'"); ?> |
-
- repo->syncTips; ?>
- |
+ repo->syncTips; ?> |
| repo->gitlabHost;?> |
- client, "class='form-control' placeholder='{$lang->repo->placeholder->gitlabHost}'");?>
- |
-
- | repo->gitlabToken;?> |
- password, "class='form-control'");?>
+ | client, "class='form-control' placeholder='{$lang->repo->placeholder->gitlabHost}'");?>
|
| repo->gitlabProject;?> |
@@ -59,8 +53,8 @@
repo->path; ?> |
path, "class='form-control'"); ?> |
- repo->example->path->git;?>
- repo->example->path->svn;?>
+ repo->example->path->git;?>
+ repo->example->path->svn;?>
|
@@ -72,8 +66,8 @@
| repo->client;?> |
client, "class='form-control'")?> |
- repo->example->client->git;?>
- repo->example->client->svn;?>
+ repo->example->client->git;?>
+ repo->example->client->svn;?>
|
From 7f211e633e85edfbf1b42d1e8e019aff9d2fa967 Mon Sep 17 00:00:00 2001
From: dingguodong
Date: Thu, 10 Jun 2021 14:53:27 +0800
Subject: [PATCH 019/269] * Increase robustness.
---
module/pipeline/model.php | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/module/pipeline/model.php b/module/pipeline/model.php
index ab5f8796d3..151ff01194 100644
--- a/module/pipeline/model.php
+++ b/module/pipeline/model.php
@@ -22,7 +22,10 @@ class pipelineModel extends model
public function getByID($id)
{
$pipeline = $this->dao->select('*')->from(TABLE_PIPELINE)->where('id')->eq($id)->fetch();
- $pipeline->password = base64_decode($pipeline->password);
+ if($pipeline)
+ {
+ $pipeline->password = base64_decode($pipeline->password);
+ }
return $pipeline;
}
From 7e8c167b87685fbd110443b6a90b6287990eae15 Mon Sep 17 00:00:00 2001
From: Lichengjun
Date: Thu, 10 Jun 2021 14:55:50 +0800
Subject: [PATCH 020/269] * Add test commit
---
module/gitlab/model.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/module/gitlab/model.php b/module/gitlab/model.php
index 530cc97a13..b7b969c988 100644
--- a/module/gitlab/model.php
+++ b/module/gitlab/model.php
@@ -99,6 +99,7 @@ class gitlabModel extends model
* @access public
* @return array
*/
+
public function getUserBindList($host, $token)
{
$host = rtrim($host, '/') .'/api/v4/users?private_token='.$token ;
From 0c0a1dbcc9e7194f63cd1959566e8d3d10568036 Mon Sep 17 00:00:00 2001
From: Lichengjun
Date: Thu, 10 Jun 2021 14:56:29 +0800
Subject: [PATCH 021/269] Revert "* Add test commit"
This reverts commit 7e8c167b87685fbd110443b6a90b6287990eae15.
---
module/gitlab/model.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/module/gitlab/model.php b/module/gitlab/model.php
index b7b969c988..530cc97a13 100644
--- a/module/gitlab/model.php
+++ b/module/gitlab/model.php
@@ -99,7 +99,6 @@ class gitlabModel extends model
* @access public
* @return array
*/
-
public function getUserBindList($host, $token)
{
$host = rtrim($host, '/') .'/api/v4/users?private_token='.$token ;
From a45167b6558e2709b163138d0a4f7b693980686f Mon Sep 17 00:00:00 2001
From: Lichengjun
Date: Thu, 10 Jun 2021 14:57:04 +0800
Subject: [PATCH 022/269] Revert "Revert "* Add test commit""
This reverts commit 0c0a1dbcc9e7194f63cd1959566e8d3d10568036.
---
module/gitlab/model.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/module/gitlab/model.php b/module/gitlab/model.php
index 530cc97a13..b7b969c988 100644
--- a/module/gitlab/model.php
+++ b/module/gitlab/model.php
@@ -99,6 +99,7 @@ class gitlabModel extends model
* @access public
* @return array
*/
+
public function getUserBindList($host, $token)
{
$host = rtrim($host, '/') .'/api/v4/users?private_token='.$token ;
From be7bfdb515bd5b5151312ca97d45b68d5cdefb63 Mon Sep 17 00:00:00 2001
From: Guanxiying
Date: Thu, 10 Jun 2021 15:38:46 +0800
Subject: [PATCH 023/269] * Revert getProjectsByID function.
---
module/gitlab/model.php | 67 +++++++++++++++++++++++++++--------------
1 file changed, 45 insertions(+), 22 deletions(-)
diff --git a/module/gitlab/model.php b/module/gitlab/model.php
index b7b969c988..1516f0d611 100644
--- a/module/gitlab/model.php
+++ b/module/gitlab/model.php
@@ -34,7 +34,7 @@ class gitlabModel extends model
*/
public function getList($orderBy = 'id_desc', $pager = null)
{
- return $this->loadModel('pipeline')->getList('gitlab', $orderBy, $pager);
+ return $this->loadModel('pipeline')->getList('gitlab', $orderBy, $pager);
}
/**
@@ -44,7 +44,7 @@ class gitlabModel extends model
*/
public function getPairs()
{
- return $this->loadModel('pipeline')->getPairs('gitlab');
+ return $this->loadModel('pipeline')->getPairs('gitlab');
}
/**
@@ -55,7 +55,7 @@ class gitlabModel extends model
*/
public function create()
{
- return $this->loadModel('pipeline')->create('gitlab');
+ return $this->loadModel('pipeline')->create('gitlab');
}
/**
@@ -67,7 +67,7 @@ class gitlabModel extends model
*/
public function update($id)
{
- return $this->loadModel('pipeline')->update($id);
+ return $this->loadModel('pipeline')->update($id);
}
/**
@@ -106,30 +106,53 @@ class gitlabModel extends model
$response = json_decode(commonModel::http($host),true);
if (!$response) return array();
- $localUsersList = $this->dao->select('id,account,email,realname')->from(TABLE_USER)->fetchAll();
+ $localUsersList = $this->dao->select('id,account,email,realname')->from(TABLE_USER)->fetchAll();
- $responseAllId = array();
- $matchUserIds = array();
- $responseMatchIds = array();
- foreach ($response as $i => $gitlabId) {
+ $responseAllId = array();
+ $matchUserIds = array();
+ $responseMatchIds = array();
+ foreach ($response as $i => $gitlabId) {
- $responseAllId[] = $gitlabId['id'];
+ $responseAllId[] = $gitlabId['id'];
- foreach ($localUsersList as $local) {
+ 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'];
- }
+ 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);
+ }
+ $notMatchUserIds = array_diff($responseAllId,$responseMatchIds);
- foreach ($notMatchUserIds as $k => $v)
- {
- $notMatchUserId[$k]['Not matched'] = 0 .'-'. $v;
- }
- return array_merge($notMatchUserId,$matchUserIds);
+ foreach ($notMatchUserIds as $k => $v)
+ {
+ $notMatchUserId[$k]['Not matched'] = 0 .'-'. $v;
+ }
+ return array_merge($notMatchUserId,$matchUserIds);
}
+
+ /**
+ * 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;
+ }
}
From 61debf97e9e56bed9cad9e9b40301dbe2305af5d Mon Sep 17 00:00:00 2001
From: dingguodong
Date: Fri, 11 Jun 2021 11:41:04 +0800
Subject: [PATCH 024/269] + Add some tips for user when adding gitlab server.
---
module/repo/view/create.html.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/module/repo/view/create.html.php b/module/repo/view/create.html.php
index 62536c4a24..49a7a42c35 100644
--- a/module/repo/view/create.html.php
+++ b/module/repo/view/create.html.php
@@ -34,7 +34,7 @@
| repo->gitlabHost;?> |
- repo->placeholder->gitlabHost}'");?>
+ | repo->placeholder->gitlabHost}'");?>
|
| repo->gitlabProject;?> |
From 3441ea0ad69cad42e226a65def3f79a7b519c921 Mon Sep 17 00:00:00 2001
From: dingguodong
Date: Fri, 11 Jun 2021 11:47:25 +0800
Subject: [PATCH 025/269] * Add tips for when adding gitlab server.
---
module/gitlab/lang/zh-cn.php | 4 ++++
module/gitlab/view/create.html.php | 6 +++---
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php
index e02c2e3ddc..dcd874762b 100644
--- a/module/gitlab/lang/zh-cn.php
+++ b/module/gitlab/lang/zh-cn.php
@@ -21,5 +21,9 @@ $lang->gitlab->desc = '描述';
$lang->gitlab->tokenFirst = 'Token不为空时,优先使用Token。';
$lang->gitlab->tips = '使用密码时,请在gitlab全局安全设置中禁用"防止跨站点请求伪造"选项。';
+$lang->gitlab->gitlabNameTips = '该名称会显示在其他相应模块中 可使用便于识别的友好名称';
+$lang->gitlab->gitlabUrlTips = "填写示例:https://gitlab.zcorp.cc 仅填写gitlab服务地址,不需要填写其他URI";
+$lang->gitlab->gitlabTokenTips = "请填写具有admin权限账户的access token 可在:https://<gitlab url>/-/profile/personal_access_tokens 创建";
+
$lang->gitlab->tokenError = "当前token非管理员权限。";
$lang->gitlab->hostError = "无效的gitlab服务地址。";
diff --git a/module/gitlab/view/create.html.php b/module/gitlab/view/create.html.php
index 36d3dc6a8d..86215af1d3 100644
--- a/module/gitlab/view/create.html.php
+++ b/module/gitlab/view/create.html.php
@@ -23,17 +23,17 @@
| gitlab->name; ?> |
|
- |
+ gitlab->gitlabNameTips; ?> |
| gitlab->url; ?> |
|
- |
+ gitlab->gitlabUrlTips; ?> |
| gitlab->token;?> |
|
- |
+ gitlab->gitlabTokenTips; ?> |
|
From 797b84bbb636ae3feb568980f3d45a9b1eaeae57 Mon Sep 17 00:00:00 2001
From: dingguodong
Date: Fri, 11 Jun 2021 13:47:02 +0800
Subject: [PATCH 026/269] * Improve code robustness.
---
module/gitlab/model.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/module/gitlab/model.php b/module/gitlab/model.php
index 1516f0d611..31a4537a9a 100644
--- a/module/gitlab/model.php
+++ b/module/gitlab/model.php
@@ -143,6 +143,7 @@ class gitlabModel extends model
public function getProjectsByID($id)
{
$gitlab = $this->getByID($id);
+ if( ! $gitlab ) return array();
$host = rtrim($gitlab->url, '/');
$host .= '/api/v4/projects';
From bbe13d5077f3f332b30b03312eeb9d0be4f2d4d1 Mon Sep 17 00:00:00 2001
From: Guanxiying
Date: Fri, 11 Jun 2021 13:56:23 +0800
Subject: [PATCH 027/269] * Use commonModel::http.
---
module/gitlab/model.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/module/gitlab/model.php b/module/gitlab/model.php
index 31a4537a9a..4b242e23ce 100644
--- a/module/gitlab/model.php
+++ b/module/gitlab/model.php
@@ -143,14 +143,14 @@ class gitlabModel extends model
public function getProjectsByID($id)
{
$gitlab = $this->getByID($id);
- if( ! $gitlab ) return array();
+ if(!$gitlab) return array();
$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"));
+ $results = json_decode(commonModel::http($host . "?private_token={$gitlab->token}&simple=true&membership=true&page={$page}&per_page=100"));
if(empty($results) or $page > 10) break;
$allResults = $allResults + $results;
}
From 76b44aa43101e01506a65fc5a8c0155620cac6ce Mon Sep 17 00:00:00 2001
From: dingguodong
Date: Fri, 11 Jun 2021 14:32:55 +0800
Subject: [PATCH 028/269] * Optimize the text of the gitlab project id.
---
module/repo/lang/zh-cn.php | 5 +++--
module/repo/view/maintain.html.php | 2 +-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/module/repo/lang/zh-cn.php b/module/repo/lang/zh-cn.php
index d073a70b36..34c1dd5dba 100644
--- a/module/repo/lang/zh-cn.php
+++ b/module/repo/lang/zh-cn.php
@@ -174,8 +174,9 @@ $lang->repo->error->encoding = "编码可能错误,请更换编码重试
$lang->repo->error->deleted = "删除版本库失败,当前版本库有提交记录与设计关联";
$lang->repo->error->clientPath = "客户端安装目录不能有空格!";
-$lang->repo->syncTips = '请参照这里,设置版本库定时同步。';
-$lang->repo->encodingsTips = "提交日志的编码,可以用逗号连接起来的多个,比如utf-8。";
+$lang->repo->syncTips = '请参照这里,设置版本库定时同步。';
+$lang->repo->encodingsTips = "提交日志的编码,可以用逗号连接起来的多个,比如utf-8。";
+$lang->repo->pathTipsForGitlab = "GitLab 项目编号";
$lang->repo->example = new stdclass();
$lang->repo->example->client = new stdclass();
diff --git a/module/repo/view/maintain.html.php b/module/repo/view/maintain.html.php
index 2cb0aced53..e7a0e9391d 100644
--- a/module/repo/view/maintain.html.php
+++ b/module/repo/view/maintain.html.php
@@ -45,7 +45,7 @@
}
?>
- path; ?> |
+ path; ?> |
id&objectID=$objectID", '', 'list', 'edit');
From f927d0e9085fe5118ede428577f90e4d1cc501c7 Mon Sep 17 00:00:00 2001
From: Guanxiying
Date: Fri, 11 Jun 2021 14:35:20 +0800
Subject: [PATCH 029/269] * Fix repo path when get repo list.
---
module/pipeline/model.php | 3 +++
module/repo/model.php | 5 ++++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/module/pipeline/model.php b/module/pipeline/model.php
index 151ff01194..7a2d669a1f 100644
--- a/module/pipeline/model.php
+++ b/module/pipeline/model.php
@@ -77,6 +77,7 @@ class pipelineModel extends model
->add('createdDate', helper::now())
->skipSpecial('url,token,account,password')
->get();
+ if($type == 'gitlab') $pipeline->url = rtrim($pipeline->url, '/');
if(isset($pipeline->password)) $pipeline->password = base64_encode($pipeline->password);
@@ -104,6 +105,8 @@ class pipelineModel extends model
->skipSpecial('url,token,account,password')
->get();
+ $type = $this->dao->select('type')->from(TABLE_PIPELINE)->where('id')->eq($id)->fetch('type');
+ if($type == 'gitlab') $pipeline->url = rtrim($pipeline->url, '/');
if(isset($pipeline->password)) $pipeline->password = base64_encode($pipeline->password);
$this->dao->update(TABLE_PIPELINE)->data($pipeline)
diff --git a/module/repo/model.php b/module/repo/model.php
index 9c04aa41ae..32feb9147a 100644
--- a/module/repo/model.php
+++ b/module/repo/model.php
@@ -128,7 +128,8 @@ class repoModel extends model
$repos = $this->dao->select('*')->from(TABLE_REPO)
->where('deleted')->eq('0')
->orderBy($orderBy)
- ->page($pager)->fetchAll('id');
+ ->page($pager)
+ ->fetchAll('id');
/* Get products. */
$productIdList = $this->loadModel('product')->getProductIDByProject($projectID, false);
@@ -152,6 +153,8 @@ class repoModel extends model
if(!$hasPriv) unset($repos[$i]);
}
}
+
+ if($repo->SCM == 'Gitlab') $repo = $this->processGitlab($repo);
}
return $repos;
From b25645732d7b259a665cddf1cc60f911e63519d9 Mon Sep 17 00:00:00 2001
From: dingguodong
Date: Fri, 11 Jun 2021 14:37:48 +0800
Subject: [PATCH 030/269] * Change the display text of the gitlab project url.
---
module/repo/lang/zh-cn.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/module/repo/lang/zh-cn.php b/module/repo/lang/zh-cn.php
index 34c1dd5dba..19d6729576 100644
--- a/module/repo/lang/zh-cn.php
+++ b/module/repo/lang/zh-cn.php
@@ -176,7 +176,7 @@ $lang->repo->error->clientPath = "客户端安装目录不能有空格!";
$lang->repo->syncTips = '请参照这里,设置版本库定时同步。';
$lang->repo->encodingsTips = "提交日志的编码,可以用逗号连接起来的多个,比如utf-8。";
-$lang->repo->pathTipsForGitlab = "GitLab 项目编号";
+$lang->repo->pathTipsForGitlab = "GitLab 项目URL";
$lang->repo->example = new stdclass();
$lang->repo->example->client = new stdclass();
From dfda9e84453e662c025e94ef25e19656e5bfb38d Mon Sep 17 00:00:00 2001
From: dingguodong
Date: Fri, 11 Jun 2021 16:43:58 +0800
Subject: [PATCH 031/269] + Add a icon of webhook ext using printLink.
---
module/gitlab/view/browse.html.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php
index 7a0f96b962..11df8a7e6e 100644
--- a/module/gitlab/view/browse.html.php
+++ b/module/gitlab/view/browse.html.php
@@ -25,7 +25,7 @@
| gitlab->id); ?> |
gitlab->name); ?> |
gitlab->url); ?> |
- actions; ?> |
+ actions; ?> |
|
@@ -36,6 +36,7 @@
url; ?> |
");
common::printIcon('gitlab', 'edit', "gitlabID=$id", '', 'list', 'edit');
common::printIcon('gitlab', 'bind', "gitlabID=$id", '', 'list', 'group');
if(common::hasPriv('gitlab', 'delete')) echo html::a($this->createLink('gitlab', 'delete', "gitlabID=$id"), '', 'hiddenwin', "title='{$lang->gitlab->delete}' class='btn'");
From daec205b9a119655afe2560072f409a20c35219c Mon Sep 17 00:00:00 2001
From: dingguodong
Date: Fri, 11 Jun 2021 16:51:29 +0800
Subject: [PATCH 032/269] * Keep the edit and create action in a same ui.
---
module/gitlab/view/edit.html.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/module/gitlab/view/edit.html.php b/module/gitlab/view/edit.html.php
index 88d5c0767c..e8ee46842d 100644
--- a/module/gitlab/view/edit.html.php
+++ b/module/gitlab/view/edit.html.php
@@ -22,17 +22,17 @@
| gitlab->name; ?> |
name, "class='form-control'"); ?> |
- |
+ gitlab->gitlabNameTips; ?> |
| gitlab->url; ?> |
url, "class='form-control'"); ?> |
- |
+ gitlab->gitlabUrlTips; ?> |
| gitlab->token;?> |
token, "class='form-control'");?> |
- gitlab->tokenFirst;?> |
+ gitlab->gitlabTokenTips; ?> |
|
From 15987dd3083e97c7fa8fbddba583f7196d782cbb Mon Sep 17 00:00:00 2001
From: dingguodong
Date: Tue, 15 Jun 2021 11:07:22 +0800
Subject: [PATCH 033/269] * Add JMESPath lib.
---
.gitignore | 2 ++
composer.json | 3 ++-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index b0628fb53a..ad25ba4508 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,3 +17,5 @@ tmp/extension/*
.gitignore
.DS_Store
vendor/
+composer.lock
+
diff --git a/composer.json b/composer.json
index 797156678b..ef47b9d7ce 100644
--- a/composer.json
+++ b/composer.json
@@ -7,6 +7,7 @@
"php": "~5.2||~7.0",
"ext-json" : "*",
"ext-mbstring" : "*",
- "ext-curl" : "*"
+ "ext-curl" : "*",
+ "mtdowling/jmespath.php": "2.6.*"
}
}
From 36cb1b7c7a30c0abc7cd2964d3f0a59fad7f7530 Mon Sep 17 00:00:00 2001
From: dingguodong
Date: Tue, 15 Jun 2021 11:08:09 +0800
Subject: [PATCH 034/269] * Add funcs for getting gitlab api url with
access_token.
---
module/gitlab/model.php | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/module/gitlab/model.php b/module/gitlab/model.php
index 4b242e23ce..48a39a7626 100644
--- a/module/gitlab/model.php
+++ b/module/gitlab/model.php
@@ -10,6 +10,11 @@
* @link http://www.zentao.net
*/
+
+/* enable JMESPath */
+require __DIR__ . '/../../vendor/autoload.php';
+
+
class gitlabModel extends model
{
/**
@@ -155,5 +160,31 @@ class gitlabModel extends model
$allResults = $allResults + $results;
}
return $allResults;
- }
+ }
+
+
+ /**
+ * Get gitlab api base url with access_token
+ *
+ * @param int $id
+ * @access public
+ * @return string gitlab api base url with access_token
+ */
+ public function getGitlabBaseApiUrl($id)
+ {
+ $gitlab = $this->getByID($id);
+ if(!$gitlab) return array();
+ $gitlab_url = rtrim($gitlab->url, '/').'/api/v4%s'."?private_token={$gitlab->token}";
+ return $gitlab_url;
+ }
+
+
+ public function getHooksOfProject($gitlab_id, $project_id)
+ {
+ $host = $this->getGitlabBaseApiUrl($gitlab_id);
+ $api_path = sprintf('/projects/%s/hooks', $project_id);
+ $host = sprintf($host, $api_path);
+ $api_json = commonModel::http($host);
+ return $api_json;
+ }
}
From 5ebf525b9b4de748ff61d253195d9b81c4ec3bcd Mon Sep 17 00:00:00 2001
From: dingguodong
Date: Tue, 15 Jun 2021 11:20:59 +0800
Subject: [PATCH 035/269] * Simplify the func name.
---
module/gitlab/model.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/module/gitlab/model.php b/module/gitlab/model.php
index 48a39a7626..b74baf5b31 100644
--- a/module/gitlab/model.php
+++ b/module/gitlab/model.php
@@ -170,10 +170,10 @@ class gitlabModel extends model
* @access public
* @return string gitlab api base url with access_token
*/
- public function getGitlabBaseApiUrl($id)
+ public function getApiRoot($id)
{
$gitlab = $this->getByID($id);
- if(!$gitlab) return array();
+ if(!$gitlab) return "";
$gitlab_url = rtrim($gitlab->url, '/').'/api/v4%s'."?private_token={$gitlab->token}";
return $gitlab_url;
}
@@ -181,7 +181,7 @@ class gitlabModel extends model
public function getHooksOfProject($gitlab_id, $project_id)
{
- $host = $this->getGitlabBaseApiUrl($gitlab_id);
+ $host = $this->getApiRoot($gitlab_id);
$api_path = sprintf('/projects/%s/hooks', $project_id);
$host = sprintf($host, $api_path);
$api_json = commonModel::http($host);
From 3b7a2c21d0916370809ec8570c43772a11758482 Mon Sep 17 00:00:00 2001
From: dingguodong
Date: Tue, 15 Jun 2021 12:29:02 +0800
Subject: [PATCH 036/269] * Add empty funcs of webhooks.
---
module/gitlab/model.php | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/module/gitlab/model.php b/module/gitlab/model.php
index b74baf5b31..5ec7c4e2b8 100644
--- a/module/gitlab/model.php
+++ b/module/gitlab/model.php
@@ -10,11 +10,9 @@
* @link http://www.zentao.net
*/
-
/* enable JMESPath */
require __DIR__ . '/../../vendor/autoload.php';
-
class gitlabModel extends model
{
/**
@@ -162,7 +160,6 @@ class gitlabModel extends model
return $allResults;
}
-
/**
* Get gitlab api base url with access_token
*
@@ -187,4 +184,30 @@ class gitlabModel extends model
$api_json = commonModel::http($host);
return $api_json;
}
+
+ public function ListHooks($gitlab_id, $project_id)
+ {
+ return $this->getHooksOfProject();
+ }
+
+ public function GetHook($gitlab_id, $project_id, $hook_id)
+ {
+ return;
+ }
+
+ public function CreateHooks($gitlab_id, $project_id, $url, $token)
+ {
+ return;
+ }
+
+ public function DeleteHooks($gitlab_id, $project_id, $hook_id)
+ {
+ return;
+ }
+
+ public function UpdateHooks($gitlab_id, $project_id, $hook_id)
+ {
+ return;
+ }
+
}
From 8deca355ba01acbe4f7467c27448290c497057b6 Mon Sep 17 00:00:00 2001
From: dingguodong
Date: Tue, 15 Jun 2021 15:26:11 +0800
Subject: [PATCH 037/269] * Add gitlab binduser funcs.
---
module/gitlab/control.php | 21 +++----
module/gitlab/model.php | 94 ++++++++++++++++------------
module/gitlab/view/binduser.html.php | 93 +++++++++++++++++++++++++++
module/gitlab/view/browse.html.php | 2 +-
4 files changed, 159 insertions(+), 51 deletions(-)
create mode 100644 module/gitlab/view/binduser.html.php
diff --git a/module/gitlab/control.php b/module/gitlab/control.php
index c81c96a0f1..b7ac6fdb0b 100644
--- a/module/gitlab/control.php
+++ b/module/gitlab/control.php
@@ -50,7 +50,7 @@ class gitlab extends control
{
if($_POST)
{
- $tokenValid = $this->gitlab->getPermissionsByToken($this->post->url, $this->post->token);
+ $tokenValid = $this->gitlab->apiGetCurrentUser($this->post->url, $this->post->token);
if($tokenValid['result'] == 'fail') $this->send($tokenValid);
$gitlabID = $this->gitlab->create();
@@ -68,19 +68,18 @@ class gitlab extends control
}
/**
- * bind a gitlab.
+ * bind gitlab user to zentao users.
*
* @access public
* @return void
*/
- public function bind()
+ public function bindUser($id)
{
- $gitlabUserData = $this->gitlab->getUserBindList('http://127.0.0.1:8090/','xV8EKDyCY7Sb5j1-FxyZ');
-
- var_dump($gitlabUserData);die;
-
- die;
-
+ $gitlab = $this->gitlab->getByID($id);
+ $this->view->title = $this->lang->gitlab->bind;
+ $this->view->zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account');
+ $this->view->gitlabUsers = $this->gitlab->apiGetUsers($gitlab);
+ $this->view->matchedInfo = $this->gitlab->getMatchedUsers($this->view->gitlabUsers);
$this->display();
}
@@ -96,7 +95,7 @@ class gitlab extends control
$gitlab = $this->gitlab->getByID($id);
if($_POST)
{
- $tokenValid = $this->gitlab->getPermissionsByToken($this->post->url, $this->post->token);
+ $tokenValid = $this->gitlab->apiGetCurrentUser($this->post->url, $this->post->token);
if($tokenValid['result'] == 'fail') $this->send($tokenValid);
$this->gitlab->update($id);
@@ -139,7 +138,7 @@ class gitlab extends control
public function ajaxCheckToken($host, $token)
{
$host = helper::safe64Decode($host);
- $permissions = $this->gitlab->getPermissionsByToken($host, $token);
+ $permissions = $this->gitlab->apiGetCurrentUser($host, $token);
$this->send($permissions);
}
}
diff --git a/module/gitlab/model.php b/module/gitlab/model.php
index 5ec7c4e2b8..5b0b7cfbe7 100644
--- a/module/gitlab/model.php
+++ b/module/gitlab/model.php
@@ -10,9 +10,6 @@
* @link http://www.zentao.net
*/
-/* enable JMESPath */
-require __DIR__ . '/../../vendor/autoload.php';
-
class gitlabModel extends model
{
/**
@@ -74,26 +71,25 @@ class gitlabModel extends model
}
/**
- * Get gitlab token permissions.
+ * Get current user.
*
* @param string $host
* @param string $token
* @access public
* @return array
*/
- public function getPermissionsByToken($host, $token)
+ public function apiGetCurrentUser($host, $token)
{
if(strpos($host, 'http') !== 0) return array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)));
if(!$this->post->token) return array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)));
- $host = rtrim($host, '/') . "/api/v4/user?private_token=$token";
- $response = json_decode(commonModel::http($host));
+ $api = rtrim($host, '/') . "/api/v4/user?private_token=$token";
+ $response = json_decode(commonModel::http($api));
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 gitlab user list.
*
@@ -103,37 +99,62 @@ class gitlabModel extends model
* @return array
*/
- public function getUserBindList($host, $token)
+ public function apiGetUsers($gitlab)
{
- $host = rtrim($host, '/') .'/api/v4/users?private_token='.$token ;
- $response = json_decode(commonModel::http($host),true);
-
+ $api = rtrim($gitlab->url, '/') . '/api/v4/users?private_token=' . $gitlab->token;
+ $response = json_decode(commonModel::http($api));
+
if (!$response) return array();
- $localUsersList = $this->dao->select('id,account,email,realname')->from(TABLE_USER)->fetchAll();
+ $users = array();
- $responseAllId = array();
- $matchUserIds = array();
- $responseMatchIds = array();
- foreach ($response as $i => $gitlabId) {
+ foreach($response as $gitlabUser)
+ {
+ $user = new stdclass;
+ $user->id = $gitlabUser->id;
+ $user->realname = $gitlabUser->name;
+ $user->account = $gitlabUser->username;
+ $user->email = $gitlabUser->email;
- $responseAllId[] = $gitlabId['id'];
+ $users[] = $user;
+ }
+ a($users);
+ return $users;
+ }
- foreach ($localUsersList as $local) {
+ public function getMatchedUsers($gitlabUsers)
+ {
+ $zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account');
- if ( $gitlabId['email'] == $local->email && $gitlabId['username'] == $local->realname && $gitlabId['name'] == $local->account)
- {
- $matchUserIds[$i][$local->realname] = $local->id .'-'. $gitlabId['id'];
- $responseMatchIds[] = $gitlabId['id'];
- }
+ $matches = new stdclass;
+ foreach($gitlabUsers as $gitlabUser)
+ {
+ foreach($zentaoUsers as $zentaoUser)
+ {
+ if($gitlabUser->account == $zentaoUser->account) $matches->accounts[$gitlabUser->account][] = $zentaoUser->account;
+ if($gitlabUser->realname == $zentaoUser->realname) $matches->names[$gitlabUser->realname][] = $zentaoUser->account;
+ if($gitlabUser->email == $zentaoUser->email) $matches->emails[$gitlabUser->email][] = $zentaoUser->account;
}
}
- $notMatchUserIds = array_diff($responseAllId,$responseMatchIds);
- foreach ($notMatchUserIds as $k => $v)
+ foreach($gitlabUser as $gitlabUser)
{
- $notMatchUserId[$k]['Not matched'] = 0 .'-'. $v;
+ $matchedZentaoUsers = array();
+ if(isset($matches->accounts[$gitlabUser->account])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->accounts[$gitlabUser->account]);
+ if(isset($matches->emails[$gitlabUser->email])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->emails[$gitlabUser->email]);
+ if(isset($matches->names[$gitlabUser->realname])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->names[$gitlabUser->realname]);
+
+ $matchedZentaoUsers = array_unique($matchedZentaoUsers);
+ if(count($matchedZentaoUsers) == 1)
+ {
+ $matchedUsers[$gitlabUser->id] = current($matchedZentaoUsers);
+ }
+ else
+ {
+ $unmatchedUsers[$gitlabUser->id] = $gitlabUser;
+ }
}
- return array_merge($notMatchUserId,$matchUserIds);
+
+ return array('matched' => $matchedUsers, 'unmatched' => $unmatchedUsers);
}
/**
@@ -143,7 +164,7 @@ class gitlabModel extends model
* @access public
* @return void
*/
- public function getProjectsByID($id)
+ public function apiGetProjects($id)
{
$gitlab = $this->getByID($id);
if(!$gitlab) return array();
@@ -176,7 +197,7 @@ class gitlabModel extends model
}
- public function getHooksOfProject($gitlab_id, $project_id)
+ public function apiGetHooks($gitlab_id, $project_id)
{
$host = $this->getApiRoot($gitlab_id);
$api_path = sprintf('/projects/%s/hooks', $project_id);
@@ -185,27 +206,22 @@ class gitlabModel extends model
return $api_json;
}
- public function ListHooks($gitlab_id, $project_id)
- {
- return $this->getHooksOfProject();
- }
-
- public function GetHook($gitlab_id, $project_id, $hook_id)
+ public function apiGetHook($gitlab_id, $project_id, $hook_id)
{
return;
}
- public function CreateHooks($gitlab_id, $project_id, $url, $token)
+ public function apiCreateHook($gitlab_id, $project_id, $url, $token)
{
return;
}
- public function DeleteHooks($gitlab_id, $project_id, $hook_id)
+ public function apiDeleteHook($gitlab_id, $project_id, $hook_id)
{
return;
}
- public function UpdateHooks($gitlab_id, $project_id, $hook_id)
+ public function apiUpdateHook($gitlab_id, $project_id, $hook_id)
{
return;
}
diff --git a/module/gitlab/view/binduser.html.php b/module/gitlab/view/binduser.html.php
new file mode 100644
index 0000000000..dbf69d2414
--- /dev/null
+++ b/module/gitlab/view/binduser.html.php
@@ -0,0 +1,93 @@
+
+ * @package story
+ * @version $Id$
+ * @link http://www.zentao.net
+ */
+?>
+
+
+
+ gitlab->bindUser;?>
+
+
+
+
+
+
+
+
diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php
index 11df8a7e6e..ede244f79b 100644
--- a/module/gitlab/view/browse.html.php
+++ b/module/gitlab/view/browse.html.php
@@ -38,7 +38,7 @@
");
common::printIcon('gitlab', 'edit', "gitlabID=$id", '', 'list', 'edit');
- common::printIcon('gitlab', 'bind', "gitlabID=$id", '', 'list', 'group');
+ common::printIcon('gitlab', 'binduser', "id=$id", '', 'list', 'group');
if(common::hasPriv('gitlab', 'delete')) echo html::a($this->createLink('gitlab', 'delete', "gitlabID=$id"), '', 'hiddenwin', "title='{$lang->gitlab->delete}' class='btn'");
?>
From 8ff0636eac49fffb05818c112fa3688c298914e1 Mon Sep 17 00:00:00 2001
From: dingguodong
Date: Tue, 15 Jun 2021 15:27:26 +0800
Subject: [PATCH 038/269] - Remove jmespath.
---
composer.json | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/composer.json b/composer.json
index ef47b9d7ce..797156678b 100644
--- a/composer.json
+++ b/composer.json
@@ -7,7 +7,6 @@
"php": "~5.2||~7.0",
"ext-json" : "*",
"ext-mbstring" : "*",
- "ext-curl" : "*",
- "mtdowling/jmespath.php": "2.6.*"
+ "ext-curl" : "*"
}
}
From 50a934f3c4e918ce0a390ecdd4ed805361763a7e Mon Sep 17 00:00:00 2001
From: dingguodong
Date: Tue, 15 Jun 2021 16:36:57 +0800
Subject: [PATCH 039/269] * Adjust display style.
---
module/gitlab/control.php | 23 +++++----
module/gitlab/lang/zh-cn.php | 4 +-
module/gitlab/model.php | 27 +++-------
module/gitlab/view/binduser.html.php | 75 +++++++++-------------------
4 files changed, 48 insertions(+), 81 deletions(-)
diff --git a/module/gitlab/control.php b/module/gitlab/control.php
index b7ac6fdb0b..52fa0b9749 100644
--- a/module/gitlab/control.php
+++ b/module/gitlab/control.php
@@ -24,8 +24,6 @@ class gitlab extends control
*/
public function browse($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
{
- if(common::hasPriv('gitlab', 'create')) $this->lang->TRActions = html::a(helper::createLink('gitlab', 'create'), " " . $this->lang->gitlab->create, '', "class='btn btn-primary'");
-
$this->app->loadClass('pager', $static = true);
$pager = new pager($recTotal, $recPerPage, $pageID);
@@ -50,12 +48,18 @@ class gitlab extends control
{
if($_POST)
{
- $tokenValid = $this->gitlab->apiGetCurrentUser($this->post->url, $this->post->token);
- if($tokenValid['result'] == 'fail') $this->send($tokenValid);
+ if(strpos($host, 'http') !== 0) $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError))));
+ if(!$this->post->token) $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError))));
+
+ $user = $this->gitlab->apiGetCurrentUser($this->post->url, $this->post->token);
+
+ if(!is_object($user)) $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError))));
+ if(isset($user->is_admin) and $user->is_admin == true) $this->send(array('result' => 'success'));
+ $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError))));
$gitlabID = $this->gitlab->create();
+
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
- if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $gitlabID));
$this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse')));
}
@@ -76,10 +80,11 @@ class gitlab extends control
public function bindUser($id)
{
$gitlab = $this->gitlab->getByID($id);
- $this->view->title = $this->lang->gitlab->bind;
- $this->view->zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account');
- $this->view->gitlabUsers = $this->gitlab->apiGetUsers($gitlab);
- $this->view->matchedInfo = $this->gitlab->getMatchedUsers($this->view->gitlabUsers);
+ $this->view->title = $this->lang->gitlab->bindUser;
+ $zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account');
+ $this->view->userPairs = $this->loadModel('user')->getPairs();
+ $this->view->gitlabUsers = $this->gitlab->apiGetUsers($gitlab);
+ $this->view->matchedResult = $this->gitlab->getMatchedUsers($this->view->gitlabUsers, $zentaoUsers);
$this->display();
}
diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php
index dcd874762b..4389a02c38 100644
--- a/module/gitlab/lang/zh-cn.php
+++ b/module/gitlab/lang/zh-cn.php
@@ -4,9 +4,11 @@ $lang->gitlab->common = 'Gitlab';
$lang->gitlab->browse = '浏览gitlab';
$lang->gitlab->create = '添加gitlab';
$lang->gitlab->edit = '编辑gitlab';
-$lang->gitlab->bind = '绑定用户';
+$lang->gitlab->bindUser = '绑定用户';
$lang->gitlab->delete = '删除';
$lang->gitlab->confirmDelete = '确认删除该gitlab吗?';
+$lang->gitlab->gitlabAccount = 'gitlab用户';
+$lang->gitlab->zentaoAccount = '禅道用户';
$lang->gitlab->browseAction = 'gitlab列表';
$lang->gitlab->deleteAction = '删除gitlab';
diff --git a/module/gitlab/model.php b/module/gitlab/model.php
index 5b0b7cfbe7..e2280be116 100644
--- a/module/gitlab/model.php
+++ b/module/gitlab/model.php
@@ -80,14 +80,8 @@ class gitlabModel extends model
*/
public function apiGetCurrentUser($host, $token)
{
- if(strpos($host, 'http') !== 0) return array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)));
- if(!$this->post->token) return array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)));
$api = rtrim($host, '/') . "/api/v4/user?private_token=$token";
- $response = json_decode(commonModel::http($api));
-
- 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)));
+ return json_decode(commonModel::http($api));
}
/**
@@ -114,17 +108,15 @@ class gitlabModel extends model
$user->realname = $gitlabUser->name;
$user->account = $gitlabUser->username;
$user->email = $gitlabUser->email;
+ $user->avatar = $gitlabUser->avatar_url;
$users[] = $user;
}
- a($users);
return $users;
}
- public function getMatchedUsers($gitlabUsers)
+ public function getMatchedUsers($gitlabUsers, $zentaoUsers)
{
- $zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account');
-
$matches = new stdclass;
foreach($gitlabUsers as $gitlabUser)
{
@@ -136,7 +128,8 @@ class gitlabModel extends model
}
}
- foreach($gitlabUser as $gitlabUser)
+ $matchedUsers = array();
+ foreach($gitlabUsers as $gitlabUser)
{
$matchedZentaoUsers = array();
if(isset($matches->accounts[$gitlabUser->account])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->accounts[$gitlabUser->account]);
@@ -146,15 +139,11 @@ class gitlabModel extends model
$matchedZentaoUsers = array_unique($matchedZentaoUsers);
if(count($matchedZentaoUsers) == 1)
{
- $matchedUsers[$gitlabUser->id] = current($matchedZentaoUsers);
- }
- else
- {
- $unmatchedUsers[$gitlabUser->id] = $gitlabUser;
+ $gitlabUser->zentaoAccount = current($matchedZentaoUsers);
+ $matchedUsers[] = $gitlabUser;
}
}
-
- return array('matched' => $matchedUsers, 'unmatched' => $unmatchedUsers);
+ return $matchedUsers;
}
/**
diff --git a/module/gitlab/view/binduser.html.php b/module/gitlab/view/binduser.html.php
index dbf69d2414..2618efc9cf 100644
--- a/module/gitlab/view/binduser.html.php
+++ b/module/gitlab/view/binduser.html.php
@@ -17,20 +17,35 @@
| |