From 66dc0e1cb6fe5943afa5c17a8c78cda2053c92f1 Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Wed, 11 Dec 2019 14:51:26 +0800 Subject: [PATCH 001/164] jenkins GRUD --- config/zentaopms.php | 14 +- module/ci/config.php | 12 ++ module/ci/control.php | 234 +++++++++++++++++++++++ module/ci/css/index.css | 1 + module/ci/js/browsecredential.js | 4 + module/ci/js/browsejenkins.js | 4 + module/ci/js/createcredential.js | 27 +++ module/ci/js/createjenkins.js | 23 +++ module/ci/js/editcredential.js | 27 +++ module/ci/js/editjenkins.js | 23 +++ module/ci/js/menu.js | 4 + module/ci/lang/en.php | 1 + module/ci/lang/zh-cn.php | 48 +++++ module/ci/model.php | 166 ++++++++++++++++ module/ci/view/browsecredential.html.php | 57 ++++++ module/ci/view/browsejenkins.html.php | 57 ++++++ module/ci/view/createcredential.html.php | 79 ++++++++ module/ci/view/createjenkins.html.php | 74 +++++++ module/ci/view/editcredential.html.php | 79 ++++++++ module/ci/view/editjenkins.html.php | 74 +++++++ module/ci/view/header.html.php | 28 +++ module/ci/view/index.html.php | 15 ++ module/ci/view/menu.html.php | 11 ++ module/common/lang/menuOrder.php | 2 + module/common/lang/zh-cn.php | 11 +- module/custom/view/set.html.php | 4 +- 26 files changed, 1070 insertions(+), 9 deletions(-) create mode 100644 module/ci/config.php create mode 100644 module/ci/control.php create mode 100644 module/ci/css/index.css create mode 100644 module/ci/js/browsecredential.js create mode 100644 module/ci/js/browsejenkins.js create mode 100644 module/ci/js/createcredential.js create mode 100644 module/ci/js/createjenkins.js create mode 100644 module/ci/js/editcredential.js create mode 100644 module/ci/js/editjenkins.js create mode 100644 module/ci/js/menu.js create mode 100644 module/ci/lang/en.php create mode 100644 module/ci/lang/zh-cn.php create mode 100644 module/ci/model.php create mode 100644 module/ci/view/browsecredential.html.php create mode 100644 module/ci/view/browsejenkins.html.php create mode 100644 module/ci/view/createcredential.html.php create mode 100644 module/ci/view/createjenkins.html.php create mode 100644 module/ci/view/editcredential.html.php create mode 100644 module/ci/view/editjenkins.html.php create mode 100644 module/ci/view/header.html.php create mode 100644 module/ci/view/index.html.php create mode 100644 module/ci/view/menu.html.php diff --git a/config/zentaopms.php b/config/zentaopms.php index 61d3d5e986..0efdf433a4 100644 --- a/config/zentaopms.php +++ b/config/zentaopms.php @@ -163,12 +163,14 @@ define('TABLE_TESTSUITE', '`' . $config->db->prefix . 'testsuite`'); define('TABLE_SUITECASE', '`' . $config->db->prefix . 'suitecase`'); define('TABLE_TESTREPORT', '`' . $config->db->prefix . 'testreport`'); -define('TABLE_ENTRY', '`' . $config->db->prefix . 'entry`'); -define('TABLE_WEBHOOK', '`' . $config->db->prefix . 'webhook`'); -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_ENTRY', '`' . $config->db->prefix . 'entry`'); +define('TABLE_WEBHOOK', '`' . $config->db->prefix . 'webhook`'); +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_CREDENTIAL', '`' . $config->db->prefix . 'credential`'); +define('TABLE_JENKINS', '`' . $config->db->prefix . 'jenkins`'); define('TABLE_REPO', '`' . $config->db->prefix . 'repo`'); define('TABLE_REPOHISTORY', '`' . $config->db->prefix . 'repohistory`'); diff --git a/module/ci/config.php b/module/ci/config.php new file mode 100644 index 0000000000..f003bd71b8 --- /dev/null +++ b/module/ci/config.php @@ -0,0 +1,12 @@ +credential->create = new stdclass(); +$config->credential->create->requiredFields = 'name'; + +$config->credential->edit = new stdclass(); +$config->credential->edit->requiredFields = 'name'; + +$config->jenkins->create = new stdclass(); +$config->jenkins->create->requiredFields = 'name'; + +$config->jenkins->edit = new stdclass(); +$config->jenkins->edit->requiredFields = 'name'; \ No newline at end of file diff --git a/module/ci/control.php b/module/ci/control.php new file mode 100644 index 0000000000..6e47655129 --- /dev/null +++ b/module/ci/control.php @@ -0,0 +1,234 @@ + + * @package product + * @version $Id: control.php 5144 2019-12-11 06:37:03Z chenqi@cnezsoft.com $ + * @link http://www.zentao.net + */ +class ci extends control +{ + /** + * Construct function. + * + * @access public + * @return void + */ + public function __construct($moduleName = '', $methodName = '') + { + parent::__construct($moduleName, $methodName); + + /* Load need modules. */ + $this->loadModel('credential'); + $this->loadModel('user'); + } + + /** + * CI index page. + * + * @access public + * @return void + */ + public function index() + { + $this->display(); + } + + /** + * Browse credentials. + * + * @param string $orderBy + * @param int $recTotal + * @param int $recPerPage + * @param int $pageID + * @access public + * @return void + */ + public function browseCredential($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) + { + $this->app->loadClass('pager', $static = true); + $pager = new pager($recTotal, $recPerPage, $pageID); + + $this->view->title = $this->lang->credential->common . $this->lang->colon . $this->lang->credential->list; + $this->view->credentialList = $this->ci->listCredential($orderBy, $pager); + + $this->view->position[] = $this->lang->ci->common; + $this->view->position[] = $this->lang->credential->common; + + $this->view->orderBy = $orderBy; + $this->view->pager = $pager; + $this->view->module = 'credential'; + $this->display(); + } + + /** + * Create a credential. + * + * @access public + * @return void + */ + public function createCredential() + { + if($_POST) + { + $this->ci->createCredential(); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseCredential'))); + } + + $this->app->loadLang('action'); + $this->view->title = $this->lang->credential->create . $this->lang->colon . $this->lang->credential->common; + $this->view->position[] = $this->lang->ci->common; + $this->view->position[] = html::a(inlink('browseCredential'), $this->lang->credential->common); + $this->view->position[] = $this->lang->credential->create; + + $this->view->module = 'credential'; + $this->display(); + } + + /** + * Edit a credential. + * + * @param int $id + * @access public + * @return void + */ + public function editCredential($id) + { + $credential = $this->ci->getCredentialByID($id); + if($_POST) + { + $this->ci->updateCredential($id); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseCredential'))); + } + + $this->app->loadLang('action'); + $this->view->title = $this->lang->credential->edit . $this->lang->colon . $credential->name; + + $this->view->position[] = $this->lang->ci->common; + $this->view->position[] = html::a(inlink('browseCredential'), $this->lang->credential->common); + $this->view->position[] = $this->lang->credential->edit; + + $this->view->credential = $credential; + + $this->view->module = 'credential'; + $this->display(); + } + + /** + * Delete a credential. + * + * @param int $id + * @access public + * @return void + */ + public function deleteCredential($id) + { + $this->ci->delete(TABLE_CREDENTIAL, $id); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + + $this->send(array('result' => 'success')); + } + + + /** + * Browse jenkinss. + * + * @param string $orderBy + * @param int $recTotal + * @param int $recPerPage + * @param int $pageID + * @access public + * @return void + */ + public function browseJenkins($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) + { + $this->app->loadClass('pager', $static = true); + $pager = new pager($recTotal, $recPerPage, $pageID); + + $this->view->title = $this->lang->jenkins->common . $this->lang->colon . $this->lang->jenkins->list; + $this->view->jenkinsList = $this->ci->listJenkins($orderBy, $pager); + + $this->view->position[] = $this->lang->ci->common; + $this->view->position[] = $this->lang->jenkins->common; + + $this->view->orderBy = $orderBy; + $this->view->pager = $pager; + $this->view->module = 'jenkins'; + $this->display(); + } + + /** + * Create a jenkins. + * + * @access public + * @return void + */ + public function createJenkins() + { + if($_POST) + { + $this->ci->createJenkins(); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseJenkins'))); + } + + $this->app->loadLang('action'); + $this->view->title = $this->lang->jenkins->create . $this->lang->colon . $this->lang->jenkins->common; + $this->view->position[] = $this->lang->ci->common; + $this->view->position[] = html::a(inlink('browseJenkins'), $this->lang->jenkins->common); + $this->view->position[] = $this->lang->jenkins->create; + + $this->view->module = 'jenkins'; + $this->display(); + } + + /** + * Edit a jenkins. + * + * @param int $id + * @access public + * @return void + */ + public function editJenkins($id) + { + $jenkins = $this->ci->getJenkinsByID($id); + if($_POST) + { + $this->ci->updateJenkins($id); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseJenkins'))); + } + + $this->app->loadLang('action'); + $this->view->title = $this->lang->jenkins->edit . $this->lang->colon . $jenkins->name; + + $this->view->position[] = $this->lang->ci->common; + $this->view->position[] = html::a(inlink('browseJenkins'), $this->lang->jenkins->common); + $this->view->position[] = $this->lang->jenkins->edit; + + $this->view->jenkins = $jenkins; + + $this->view->module = 'jenkins'; + $this->display(); + } + + /** + * Delete a jenkins. + * + * @param int $id + * @access public + * @return void + */ + public function deleteJenkins($id) + { + $this->ci->delete(TABLE_JENKINS, $id); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + + $this->send(array('result' => 'success')); + } +} diff --git a/module/ci/css/index.css b/module/ci/css/index.css new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/module/ci/css/index.css @@ -0,0 +1 @@ + diff --git a/module/ci/js/browsecredential.js b/module/ci/js/browsecredential.js new file mode 100644 index 0000000000..6126dd22b2 --- /dev/null +++ b/module/ci/js/browsecredential.js @@ -0,0 +1,4 @@ +$(function() +{ + $('#' + module + 'Tab').addClass('btn-active-text'); +}) \ No newline at end of file diff --git a/module/ci/js/browsejenkins.js b/module/ci/js/browsejenkins.js new file mode 100644 index 0000000000..6126dd22b2 --- /dev/null +++ b/module/ci/js/browsejenkins.js @@ -0,0 +1,4 @@ +$(function() +{ + $('#' + module + 'Tab').addClass('btn-active-text'); +}) \ No newline at end of file diff --git a/module/ci/js/createcredential.js b/module/ci/js/createcredential.js new file mode 100644 index 0000000000..499e5986ce --- /dev/null +++ b/module/ci/js/createcredential.js @@ -0,0 +1,27 @@ +$(function() +{ + $('#' + module + 'Tab').addClass('btn-active-text'); + + showByType(type); + $('#type').on('change', function() + { + showByType($(this).val()); + }); +}); + +function showByType(type) { + if(type == 'account') + { + $('#password-field').show(); + + $('#privateKey-field').hide(); + $('#passphrase-field').hide(); + } + else + { + $('#privateKey-field').show(); + $('#passphrase-field').show(); + + $('#password-field').hide(); + } +} \ No newline at end of file diff --git a/module/ci/js/createjenkins.js b/module/ci/js/createjenkins.js new file mode 100644 index 0000000000..675534f51e --- /dev/null +++ b/module/ci/js/createjenkins.js @@ -0,0 +1,23 @@ +$(function() +{ + $('#' + module + 'Tab').addClass('btn-active-text'); + + showByType(type); + $('#type').on('change', function() + { + showByType($(this).val()); + }); +}); + +function showByType(type) { + if(type == 'account') + { + $('#password-field').show(); + $('#token-field').hide(); + } + else + { + $('#token-field').show(); + $('#password-field').hide(); + } +} \ No newline at end of file diff --git a/module/ci/js/editcredential.js b/module/ci/js/editcredential.js new file mode 100644 index 0000000000..9a8b9cd05c --- /dev/null +++ b/module/ci/js/editcredential.js @@ -0,0 +1,27 @@ +$(function() +{ + $('#' + module + 'Tab').addClass('btn-active-text'); + + showByType(type); + $('#type').on('change', function() + { + showByType($(this).val()); + }); +}) + +function showByType(type) { + if(type == 'account') + { + $('#password-field').show(); + + $('#privateKey-field').hide(); + $('#passphrase-field').hide(); + } + else + { + $('#privateKey-field').show(); + $('#passphrase-field').show(); + + $('#password-field').hide(); + } +} \ No newline at end of file diff --git a/module/ci/js/editjenkins.js b/module/ci/js/editjenkins.js new file mode 100644 index 0000000000..675534f51e --- /dev/null +++ b/module/ci/js/editjenkins.js @@ -0,0 +1,23 @@ +$(function() +{ + $('#' + module + 'Tab').addClass('btn-active-text'); + + showByType(type); + $('#type').on('change', function() + { + showByType($(this).val()); + }); +}); + +function showByType(type) { + if(type == 'account') + { + $('#password-field').show(); + $('#token-field').hide(); + } + else + { + $('#token-field').show(); + $('#password-field').hide(); + } +} \ No newline at end of file diff --git a/module/ci/js/menu.js b/module/ci/js/menu.js new file mode 100644 index 0000000000..0a12f8df4f --- /dev/null +++ b/module/ci/js/menu.js @@ -0,0 +1,4 @@ +$(function() +{ + +}) \ No newline at end of file diff --git a/module/ci/lang/en.php b/module/ci/lang/en.php new file mode 100644 index 0000000000..b3d9bbc7f3 --- /dev/null +++ b/module/ci/lang/en.php @@ -0,0 +1 @@ +ci->common = '持续集成'; +$lang->ci->list = '列表'; +$lang->ci->create = '添加'; + +$lang->ci->subModules['credential'] = '凭证'; +$lang->ci->subModules['jenkins'] = 'Jenkins'; + +// credential +$lang->credential->common = '凭证'; +$lang->credential->browse = '浏览凭证'; +$lang->credential->create = '添加凭证'; +$lang->credential->edit = '编辑凭证'; +$lang->credential->delete = '删除凭证'; +$lang->credential->confirmDelete = '确认删除该凭证吗?'; + +$lang->credential->id = 'ID'; +$lang->credential->name = '名称'; +$lang->credential->type = '类型'; +$lang->credential->username = '用户名'; +$lang->credential->password = '密码'; +$lang->credential->privateKey = '私钥'; +$lang->credential->passphrase = '私钥密码'; +$lang->credential->desc = '描述'; + +$lang->credential->typeList[''] = ''; +$lang->credential->typeList['account'] = '用户名密码'; +$lang->credential->typeList['sshKey '] = '密钥'; + +// jenkins +$lang->jenkins->common = 'Jenkins'; +$lang->jenkins->browse = '浏览Jenkins'; +$lang->jenkins->create = '添加Jenkins'; +$lang->jenkins->edit = '编辑Jenkins'; +$lang->jenkins->delete = '删除Jenkins'; +$lang->jenkins->confirmDelete = '确认删除该Jenkins吗?'; + +$lang->jenkins->id = 'ID'; +$lang->jenkins->name = '名称'; +$lang->jenkins->type = '类型'; +$lang->jenkins->username = '用户名'; +$lang->jenkins->password = '密码'; +$lang->jenkins->token = 'Token'; +$lang->jenkins->desc = '描述'; + +$lang->jenkins->typeList[''] = ''; +$lang->jenkins->typeList['token '] = '用户Token'; +$lang->jenkins->typeList['account'] = '用户名密码'; diff --git a/module/ci/model.php b/module/ci/model.php new file mode 100644 index 0000000000..ceb1a49242 --- /dev/null +++ b/module/ci/model.php @@ -0,0 +1,166 @@ + + * @package product + * @version $Id: control.php 5144 2019-12-11 06:37:03Z chenqi@cnezsoft.com $ + * @link http://www.zentao.net + */ +?> +dao->select('*')->from(TABLE_CREDENTIAL)->where('id')->eq($id)->fetch(); + return $credential; + } + + /** + * Get credential list. + * + * @param string $orderBy + * @param object $pager + * @param bool $decode + * @access public + * @return array + */ + public function listCredential($orderBy = 'id_desc', $pager = null, $decode = true) + { + $credentials = $this->dao->select('*')->from(TABLE_CREDENTIAL) + ->where('deleted')->eq('0') + ->orderBy($orderBy) + ->page($pager) + ->fetchAll('id'); + return $credentials; + } + + /** + * Create a credential. + * + * @access public + * @return bool + */ + public function createCredential() + { + $credential = fixer::input('post') + ->add('createdBy', $this->app->user->account) + ->add('createdDate', helper::now()) +// ->remove('') + ->get(); + + $this->dao->insert(TABLE_CREDENTIAL)->data($credential) + ->batchCheck($this->config->credential->create->requiredFields, 'notempty') + ->autoCheck() + ->exec(); + return !dao::isError(); + } + + /** + * Update a credential. + * + * @param int $id + * @access public + * @return bool + */ + public function updateCredential($id) + { + $credential = fixer::input('post') + ->add('editedBy', $this->app->user->account) + ->add('editedDate', helper::now()) + ->get(); + + $this->dao->update(TABLE_CREDENTIAL)->data($credential) + ->batchCheck($this->config->credential->edit->requiredFields, 'notempty') + ->autoCheck() + ->where('id')->eq($id) + ->exec(); + return !dao::isError(); + } + + + /** + * Get a jenkins by id. + * + * @param int $id + * @access public + * @return object + */ + public function getJenkinsByID($id) + { + $jenkins = $this->dao->select('*')->from(TABLE_JENKINS)->where('id')->eq($id)->fetch(); + return $jenkins; + } + + /** + * Get jenkins list. + * + * @param string $orderBy + * @param object $pager + * @param bool $decode + * @access public + * @return array + */ + public function listJenkins($orderBy = 'id_desc', $pager = null, $decode = true) + { + $jenkinsList = $this->dao->select('*')->from(TABLE_JENKINS) + ->where('deleted')->eq('0') + ->orderBy($orderBy) + ->page($pager) + ->fetchAll('id'); + return $jenkinsList; + } + + /** + * Create a jenkins. + * + * @access public + * @return bool + */ + public function createJenkins() + { + $jenkins = fixer::input('post') + ->add('createdBy', $this->app->user->account) + ->add('createdDate', helper::now()) +// ->remove('') + ->get(); + + $this->dao->insert(TABLE_JENKINS)->data($jenkins) + ->batchCheck($this->config->jenkins->create->requiredFields, 'notempty') + ->autoCheck() + ->exec(); + return !dao::isError(); + } + + /** + * Update a jenkins. + * + * @param int $id + * @access public + * @return bool + */ + public function updateJenkins($id) + { + $jenkins = fixer::input('post') + ->add('editedBy', $this->app->user->account) + ->add('editedDate', helper::now()) + ->get(); + + $this->dao->update(TABLE_JENKINS)->data($jenkins) + ->batchCheck($this->config->jenkins->edit->requiredFields, 'notempty') + ->autoCheck() + ->where('id')->eq($id) + ->exec(); + return !dao::isError(); + } +} diff --git a/module/ci/view/browsecredential.html.php b/module/ci/view/browsecredential.html.php new file mode 100644 index 0000000000..c8ef56d0c9 --- /dev/null +++ b/module/ci/view/browsecredential.html.php @@ -0,0 +1,57 @@ + + * @package credential + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +credential->confirmDelete); ?> + +
+ +
+
+ + + + recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}"; ?> + + + + + + + + $credential): ?> + + + + + + + + +
credential->id); ?>credential->type); ?>credential->name); ?>actions; ?>
credential->typeList, $credential->type); ?>name; ?> + createLink('ci', 'deleteCredential', "credentialID=$id&confirm=yes"); + echo html::a("javascript:ajaxDelete(\"$deleteURL\", \"credentialList\", confirmDelete)", '', '', "title='{$lang->credential->delete}' class='btn'"); + } + ?> +
+ + + +
+
+
+ diff --git a/module/ci/view/browsejenkins.html.php b/module/ci/view/browsejenkins.html.php new file mode 100644 index 0000000000..2730fe4ac4 --- /dev/null +++ b/module/ci/view/browsejenkins.html.php @@ -0,0 +1,57 @@ + + * @package jenkins + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +jenkins->confirmDelete); ?> + +
+ +
+
+ + + + recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}"; ?> + + + + + + + + $jenkins): ?> + + + + + + + + +
jenkins->id); ?>jenkins->type); ?>jenkins->name); ?>actions; ?>
jenkins->typeList, $jenkins->type); ?>name; ?> + createLink('ci', 'deleteJenkins', "jenkinsID=$id&confirm=yes"); + echo html::a("javascript:ajaxDelete(\"$deleteURL\", \"jenkinsList\", confirmDelete)", '', '', "title='{$lang->jenkins->delete}' class='btn'"); + } + ?> +
+ + + +
+
+
+ diff --git a/module/ci/view/createcredential.html.php b/module/ci/view/createcredential.html.php new file mode 100644 index 0000000000..5af3729c4f --- /dev/null +++ b/module/ci/view/createcredential.html.php @@ -0,0 +1,79 @@ + + * @package credential + * @version $Id$ + * @link http://www.zentao.net + */ +?> + + + + + +
+ +
+
+
+

credential->create; ?>

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
credential->type; ?>credential->typeList, 'account', "class='form-control'"); ?>
credential->name; ?>
credential->username; ?>
credential->password; ?>
credential->privateKey; ?>
credential->passphrase; ?>
credential->desc; ?>
+ + +
+
+
+
+
+ + diff --git a/module/ci/view/createjenkins.html.php b/module/ci/view/createjenkins.html.php new file mode 100644 index 0000000000..720fbb2bed --- /dev/null +++ b/module/ci/view/createjenkins.html.php @@ -0,0 +1,74 @@ + + * @package jenkins + * @version $Id$ + * @link http://www.zentao.net + */ +?> + + + + + +
+ +
+
+
+

jenkins->create; ?>

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
jenkins->type; ?>jenkins->typeList, 'account', "class='form-control'"); ?>
jenkins->name; ?>
jenkins->username; ?>
jenkins->password; ?>
jenkins->token; ?>
jenkins->desc; ?>
+ + +
+
+
+
+
+ + diff --git a/module/ci/view/editcredential.html.php b/module/ci/view/editcredential.html.php new file mode 100644 index 0000000000..aa011cdd42 --- /dev/null +++ b/module/ci/view/editcredential.html.php @@ -0,0 +1,79 @@ + + * @package credential + * @version $Id$ + * @link http://www.zentao.net + */ +?> + + + +type)?> + +
+ +
+
+
+

credential->edit; ?>

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
credential->type; ?>credential->typeList, $credential->type, "class='form-control'"); ?>
credential->name; ?>name, "class='form-control'"); ?>
credential->username; ?>username, "rows='3' class='form-control'"); ?>
credential->password; ?>password, "rows='3' class='form-control'"); ?>
credential->privateKey; ?>privateKey, "rows='3' class='form-control'"); ?>
credential->passphrase; ?>passphrase, "rows='3' class='form-control'"); ?>
credential->desc; ?>desc, "rows='3' class='form-control'"); ?>
+ + +
+
+
+
+
+ diff --git a/module/ci/view/editjenkins.html.php b/module/ci/view/editjenkins.html.php new file mode 100644 index 0000000000..11a57841ae --- /dev/null +++ b/module/ci/view/editjenkins.html.php @@ -0,0 +1,74 @@ + + * @package jenkins + * @version $Id$ + * @link http://www.zentao.net + */ +?> + + + +type)?> + +
+ +
+
+
+

jenkins->edit; ?>

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
jenkins->type; ?>jenkins->typeList, $jenkins->type, "class='form-control'"); ?>
jenkins->name; ?>name, "class='form-control'"); ?>
jenkins->username; ?>username, "rows='3' class='form-control'"); ?>
jenkins->password; ?>password, "rows='3' class='form-control'"); ?>
jenkins->token; ?>token, "rows='3' class='form-control'"); ?>
jenkins->desc; ?>desc, "rows='3' class='form-control'"); ?>
+ + +
+
+
+
+
+ diff --git a/module/ci/view/header.html.php b/module/ci/view/header.html.php new file mode 100644 index 0000000000..1be09db581 --- /dev/null +++ b/module/ci/view/header.html.php @@ -0,0 +1,28 @@ + + * @package credential + * @version $Id$ + * @link http://www.zentao.net + */ +?> + + diff --git a/module/ci/view/index.html.php b/module/ci/view/index.html.php new file mode 100644 index 0000000000..aaecfaf60b --- /dev/null +++ b/module/ci/view/index.html.php @@ -0,0 +1,15 @@ + + + +
+ +
+
+ + diff --git a/module/ci/view/menu.html.php b/module/ci/view/menu.html.php new file mode 100644 index 0000000000..d50fc9d86b --- /dev/null +++ b/module/ci/view/menu.html.php @@ -0,0 +1,11 @@ + + +
+
+ admin->ci->fields as $key => $value) { + echo html::a(inlink('browse' . $key, '', ''), ''.$value.'', '', " id='{$key}Tab'"); + } + ?> +
+
diff --git a/module/common/lang/menuOrder.php b/module/common/lang/menuOrder.php index 2a563a5cd2..efa8e7aad5 100644 --- a/module/common/lang/menuOrder.php +++ b/module/common/lang/menuOrder.php @@ -126,6 +126,7 @@ $lang->admin->subMenuOrder->message[10] = 'webhook'; $lang->admin->subMenuOrder->message[15] = 'browser'; $lang->admin->subMenuOrder->message[20] = 'setting'; $lang->admin->subMenuOrder->sso[5] = 'ranzhi'; +$lang->admin->subMenuOrder->sso[9] = 'ci'; $lang->admin->subMenuOrder->dev[5] = 'api'; $lang->admin->subMenuOrder->dev[10] = 'db'; $lang->admin->subMenuOrder->dev[15] = 'editor'; @@ -146,3 +147,4 @@ $lang->mail->menuOrder = $lang->admin->menuOrder; $lang->dev->menuOrder = $lang->admin->menuOrder; $lang->entry->menuOrder = $lang->admin->menuOrder; $lang->webhook->menuOrder = $lang->admin->menuOrder; +$lang->ci->menuOrder = $lang->admin->menuOrder; \ No newline at end of file diff --git a/module/common/lang/zh-cn.php b/module/common/lang/zh-cn.php index af7f5d4a44..4f147ba3c4 100644 --- a/module/common/lang/zh-cn.php +++ b/module/common/lang/zh-cn.php @@ -381,7 +381,7 @@ $lang->admin->menu = new stdclass(); $lang->admin->menu->index = array('link' => '首页|admin|index', 'alias' => 'register,certifytemail,certifyztmobile,ztcompany'); $lang->admin->menu->message = array('link' => '通知|message|index', 'subModule' => 'message,mail,webhook'); $lang->admin->menu->custom = array('link' => '自定义|custom|set', 'subModule' => 'custom'); -$lang->admin->menu->sso = array('link' => '集成|admin|sso'); +$lang->admin->menu->sso = array('link' => '集成|admin|sso', 'subModule' => 'ci'); $lang->admin->menu->extension = array('link' => '插件|extension|browse', 'subModule' => 'extension'); $lang->admin->menu->dev = array('link' => '二次开发|dev|api', 'alias' => 'db', 'subModule' => 'dev,entry'); $lang->admin->menu->translate = array('link' => '翻译|dev|translate'); @@ -398,6 +398,12 @@ $lang->admin->subMenu->message->setting = array('link' => '设置|message|settin $lang->admin->subMenu->sso = new stdclass(); $lang->admin->subMenu->sso->ranzhi = '然之协同|admin|sso'; +$lang->admin->subMenu->sso->ci = array('link' => '持续集成|ci|index', + 'alias' => 'browsecredential,createcredential,editcredential,browsejenkins,createjenkins,editjenkins'); + +$lang->admin->ci = new stdClass(); +$lang->admin->ci->fields['credential'] = '凭证'; +$lang->admin->ci->fields['jenkins'] = 'Jenkins'; $lang->admin->subMenu->dev = new stdclass(); $lang->admin->subMenu->dev->api = array('link' => 'API|dev|api'); @@ -426,6 +432,7 @@ $lang->entry = new stdclass(); $lang->webhook = new stdclass(); $lang->message = new stdclass(); $lang->search = new stdclass(); +$lang->ci = new stdclass(); $lang->convert->menu = $lang->admin->menu; $lang->upgrade->menu = $lang->admin->menu; @@ -439,6 +446,7 @@ $lang->dev->menu = $lang->admin->menu; $lang->entry->menu = $lang->admin->menu; $lang->webhook->menu = $lang->admin->menu; $lang->message->menu = $lang->admin->menu; +$lang->ci->menu = $lang->admin->menu; /* 菜单分组。*/ $lang->menugroup = new stdclass(); @@ -474,6 +482,7 @@ $lang->menugroup->dev = 'admin'; $lang->menugroup->entry = 'admin'; $lang->menugroup->webhook = 'admin'; $lang->menugroup->message = 'admin'; +$lang->menugroup->ci = 'admin'; /* 错误提示信息。*/ $lang->error = new stdclass(); diff --git a/module/custom/view/set.html.php b/module/custom/view/set.html.php index 55fc05dd45..aed1198fa0 100644 --- a/module/custom/view/set.html.php +++ b/module/custom/view/set.html.php @@ -28,9 +28,9 @@ $itemRow = << EOT; ?> - + - +
+ + diff --git a/module/ci/view/editcredential.html.php b/module/ci/view/editcredential.html.php index aa011cdd42..39a09f0c53 100644 --- a/module/ci/view/editcredential.html.php +++ b/module/ci/view/editcredential.html.php @@ -39,12 +39,12 @@ credential->username; ?> - username, "rows='3' class='form-control'"); ?> + username, "class='form-control'"); ?> credential->password; ?> - password, "rows='3' class='form-control'"); ?> + password, "class='form-control'"); ?> @@ -57,6 +57,11 @@ passphrase, "rows='3' class='form-control'"); ?> + + credential->token; ?> + token, "class='form-control'"); ?> + + credential->desc; ?> diff --git a/module/ci/view/editjenkins.html.php b/module/ci/view/editjenkins.html.php index b3d42e1cca..5b17717a0b 100644 --- a/module/ci/view/editjenkins.html.php +++ b/module/ci/view/editjenkins.html.php @@ -13,8 +13,6 @@ -type)?> -
- - - - - @@ -41,19 +34,9 @@ - - - - - - - - - - - - - + + + diff --git a/module/ci/view/editrepo.html.php b/module/ci/view/editrepo.html.php new file mode 100644 index 0000000000..4c3746006e --- /dev/null +++ b/module/ci/view/editrepo.html.php @@ -0,0 +1,92 @@ + + * @package repo + * @version $Id$ + * @link http://www.zentao.net + */ +?> + + + +type)?> + +
+ +
+
+
+

repo->edit; ?>

+
+ +
jenkins->type; ?>jenkins->typeList, $jenkins->type, "class='form-control'"); ?>
jenkins->name; ?> name, "class='form-control'"); ?>serviceUrl, "class='form-control'"); ?>
jenkins->username; ?>username, "rows='3' class='form-control'"); ?>
jenkins->password; ?>password, "rows='3' class='form-control'"); ?>
jenkins->token; ?>token, "rows='3' class='form-control'"); ?>
credential->common; ?>credential, "class='form-control'"); ?>
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
repo->type; ?>repo->scmList, $repo->SCM, "class='form-control'"); ?>
repo->name; ?>name, "class='form-control'"); ?>
repo->path; ?>path, "class='form-control'"); ?>repo->example->path;?>
repo->encoding; ?>encoding, "class='form-control'"); ?>
repo->client;?>client, "class='form-control'")?>repo->example->client;?>
credential->common; ?>credential, "class='form-control'"); ?>
repo->acl;?> +
+ repo->group?> + acl->groups) ? '' : join(',', $repo->acl->groups), "class='form-control chosen' multiple")?> +
+
+ repo->user?> + acl->users) ? '' : join(',', $repo->acl->users), "class='form-control chosen' multiple")?> +
+
repo->desc; ?>desc, "rows='3' class='form-control'"); ?>
+ + +
+
+
+
+ + diff --git a/module/ci/view/menu.html.php b/module/ci/view/menu.html.php index d50fc9d86b..d5e9b1cfa7 100644 --- a/module/ci/view/menu.html.php +++ b/module/ci/view/menu.html.php @@ -3,7 +3,7 @@
admin->ci->fields as $key => $value) { + foreach ($lang->ci->subModules as $key => $value) { echo html::a(inlink('browse' . $key, '', ''), ''.$value.'', '', " id='{$key}Tab'"); } ?> diff --git a/module/ci/view/showsynccomment.html.php b/module/ci/view/showsynccomment.html.php new file mode 100644 index 0000000000..c5cdaeb7ed --- /dev/null +++ b/module/ci/view/showsynccomment.html.php @@ -0,0 +1,45 @@ + + * @package repo + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +
+
+
+ +
+

repo->notice->syncing;?>

+
+

repo->notice->syncedCount?>

+
+
+
+
+ + diff --git a/module/common/lang/zh-cn.php b/module/common/lang/zh-cn.php index 4f147ba3c4..68e30fccbf 100644 --- a/module/common/lang/zh-cn.php +++ b/module/common/lang/zh-cn.php @@ -401,10 +401,6 @@ $lang->admin->subMenu->sso->ranzhi = '然之协同|admin|sso'; $lang->admin->subMenu->sso->ci = array('link' => '持续集成|ci|index', 'alias' => 'browsecredential,createcredential,editcredential,browsejenkins,createjenkins,editjenkins'); -$lang->admin->ci = new stdClass(); -$lang->admin->ci->fields['credential'] = '凭证'; -$lang->admin->ci->fields['jenkins'] = 'Jenkins'; - $lang->admin->subMenu->dev = new stdclass(); $lang->admin->subMenu->dev->api = array('link' => 'API|dev|api'); $lang->admin->subMenu->dev->db = array('link' => '数据库|dev|db'); From a325418a09d557284f822550556155babf753cd1 Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Thu, 12 Dec 2019 19:43:32 +0800 Subject: [PATCH 006/164] git support --- config/zentaopms.php | 1 - module/ci/control.php | 23 ++- module/ci/model.php | 185 ++++++++++++++++++++++-- module/ci/view/browserepo.html.php | 2 +- module/ci/view/showsynccomment.html.php | 2 +- 5 files changed, 185 insertions(+), 28 deletions(-) diff --git a/config/zentaopms.php b/config/zentaopms.php index afb01c655d..0efdf433a4 100644 --- a/config/zentaopms.php +++ b/config/zentaopms.php @@ -171,7 +171,6 @@ define('TABLE_NOTIFY', '`' . $config->db->prefix . 'notify`'); define('TABLE_OAUTH', '`' . $config->db->prefix . 'oauth`'); define('TABLE_CREDENTIAL', '`' . $config->db->prefix . 'credential`'); define('TABLE_JENKINS', '`' . $config->db->prefix . 'jenkins`'); -define('TABLE_REPO_CI', '`' . $config->db->prefix . 'repo_ci`'); define('TABLE_REPO', '`' . $config->db->prefix . 'repo`'); define('TABLE_REPOHISTORY', '`' . $config->db->prefix . 'repohistory`'); diff --git a/module/ci/control.php b/module/ci/control.php index c54deb2db9..da9c87e279 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -250,9 +250,6 @@ class ci extends control */ public function browseRepo($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { - a('browseRepo'); - die('browseRepo'); - $this->app->loadClass('pager', $static = true); $pager = new pager($recTotal, $recPerPage, $pageID); @@ -308,18 +305,18 @@ class ci extends control * @access public * @return void */ - public function editRepo($id) + public function editRepo($repoID) { - $repo = $this->ci->getRepoByID($id); + $repo = $this->ci->getRepoByID($repoID); if($_POST) { - $needSync = $this->ci->updateRepo($id); + $needSync = $this->ci->updateRepo($repoID); if(dao::isError()) die(js::error(dao::getError())); if(!$needSync) { die(js::locate($this->ci->createLink('showSyncComment', "repoID=$repoID"), 'parent')); } - die(js::locate($this->ci->createLink('log', "repoID=$repoID"), 'parent')); + die(js::locate($this->ci->createLink('browseRepo'), 'parent')); } $this->app->loadLang('action'); @@ -385,7 +382,7 @@ class ci extends control public function ajaxSyncComment($repoID = 0, $type = 'batch') { set_time_limit(0); - $repo = $this->repo->getRepoByID($repoID); + $repo = $this->ci->getRepoByID($repoID); if(empty($repo)) die(); if($repo->synced) die('finish'); @@ -408,7 +405,7 @@ class ci extends control unset($branches[$branch]); if($branch == $branchID) { - $this->repo->setRepoBranch($branchID); + $this->ci->setRepoBranch($branchID); setcookie("syncBranch", $branchID, 0, $this->config->webRoot); break; } @@ -436,24 +433,24 @@ class ci extends control $logs = $this->scm->getCommits($revision, 0, $branchID); } - $commitCount = $this->repo->saveCommit($repoID, $logs, $version, $branchID); + $commitCount = $this->ci->saveCommit($repoID, $logs, $version, $branchID); if(empty($commitCount)) { if(!$repo->synced) { if($repo->SCM == 'Git') { - if($branchID) $this->repo->saveExistsLogBranch($repo->id, $branchID); + if($branchID) $this->ci->saveExistsLogBranch($repo->id, $branchID); $branchID = reset($branches); setcookie("syncBranch", $branchID, 0, $this->config->webRoot); - if($branchID) $this->repo->fixCommit($repoID); + if($branchID) $this->ci->fixCommit($repoID); } if(empty($branchID)) { - $this->repo->markSynced($repoID); + $this->ci->markSynced($repoID); die('finish'); } } diff --git a/module/ci/model.php b/module/ci/model.php index 5dd09417cc..c222e1a7a5 100644 --- a/module/ci/model.php +++ b/module/ci/model.php @@ -98,7 +98,7 @@ class ciModel extends model */ public function getJenkinsByID($id) { - $jenkins = $this->dao->select('*')->from(TABLE_REPO_CI)->where('id')->eq($id)->fetch(); + $jenkins = $this->dao->select('*')->from(TABLE_JENKINS)->where('id')->eq($id)->fetch(); return $jenkins; } @@ -113,7 +113,7 @@ class ciModel extends model */ public function listJenkins($orderBy = 'id_desc', $pager = null, $decode = true) { - $jenkinsList = $this->dao->select('*')->from(TABLE_REPO_CI) + $jenkinsList = $this->dao->select('*')->from(TABLE_JENKINS) ->where('deleted')->eq('0') ->orderBy($orderBy) ->page($pager) @@ -134,7 +134,7 @@ class ciModel extends model ->add('createdDate', helper::now()) ->get(); - $this->dao->insert(TABLE_REPO_CI)->data($jenkins) + $this->dao->insert(TABLE_JENKINS)->data($jenkins) ->batchCheck($this->config->jenkins->create->requiredFields, 'notempty') ->batchCheck("serviceUrl", 'URL') ->batchCheckIF($jenkins->type === 'credential', "credential", 'notempty') @@ -157,7 +157,7 @@ class ciModel extends model ->add('editedDate', helper::now()) ->get(); - $this->dao->update(TABLE_REPO_CI)->data($jenkins) + $this->dao->update(TABLE_JENKINS)->data($jenkins) ->batchCheck($this->config->jenkins->edit->requiredFields, 'notempty') ->batchCheck("serviceUrl", 'URL') ->batchCheckIF($jenkins->type === 'credential', "credential", 'notempty') @@ -187,7 +187,7 @@ class ciModel extends model */ public function getRepoByID($id) { - $repo = $this->dao->select('*')->from(TABLE_REPO_CI)->where('id')->eq($id)->fetch(); + $repo = $this->dao->select('*')->from(TABLE_REPO)->where('id')->eq($id)->fetch(); return $repo; } @@ -202,7 +202,7 @@ class ciModel extends model */ public function listRepo($orderBy = 'id_desc', $pager = null, $decode = true) { - $repoList = $this->dao->select('*')->from(TABLE_REPO_CI) + $repoList = $this->dao->select('*')->from(TABLE_REPO) ->where('deleted')->eq('0') ->orderBy($orderBy) ->page($pager) @@ -244,7 +244,7 @@ class ciModel extends model } if($data->encrypt == 'base64') $data->password = base64_encode($data->password); - $this->dao->insert(TABLE_REPO_CI)->data($data) + $this->dao->insert(TABLE_REPO)->data($data) ->batchCheck($this->config->repo->create->requiredFields, 'notempty') ->autoCheck() ->exec(); @@ -258,7 +258,7 @@ class ciModel extends model * @access public * @return bool */ - public function updateRepo($id) + public function updateRepo($repoID) { $this->checkRepoConnection(); $data = fixer::input('post')->skipSpecial('path,client,account,password')->get(); @@ -282,14 +282,14 @@ class ciModel extends model if($data->path != $repo->path) $data->synced = 0; if($data->encrypt == 'base64') $data->password = base64_encode($data->password); - $this->dao->update(TABLE_REPO_CI)->data($data) + $this->dao->update(TABLE_REPO)->data($data) ->batchCheck($this->config->repo->create->requiredFields, 'notempty') ->autoCheck() ->where('id')->eq($repoID)->exec(); if($repo->path != $data->path) { - $this->dao->delete()->from(TABLE_REPO_CIHISTORY)->where('repo')->eq($repoID)->exec(); - $this->dao->delete()->from(TABLE_REPO_CIFILES)->where('repo')->eq($repoID)->exec(); + $this->dao->delete()->from(TABLE_REPOHISTORY)->where('repo')->eq($repoID)->exec(); + $this->dao->delete()->from(TABLE_REPOFILES)->where('repo')->eq($repoID)->exec(); return false; } return true; @@ -390,6 +390,167 @@ class ciModel extends model return true; } + /** + * Get latest comment. + * + * @param int $repoID + * @access public + * @return object + */ + public function getLatestComment($repoID) + { + $count = $this->dao->select('count(DISTINCT t1.id) as count')->from(TABLE_REPOHISTORY)->alias('t1') + ->leftJoin(TABLE_REPOBRANCH)->alias('t2')->on('t1.id=t2.revision') + ->where('t1.repo')->eq($repoID) + ->beginIF($this->cookie->repoBranch)->andWhere('t2.branch')->eq($this->cookie->repoBranch)->fi() + ->fetch('count'); + + $lastComment = $this->dao->select('t1.*')->from(TABLE_REPOHISTORY)->alias('t1') + ->leftJoin(TABLE_REPOBRANCH)->alias('t2')->on('t1.id=t2.revision') + ->where('t1.repo')->eq($repoID) + ->beginIF($this->cookie->repoBranch)->andWhere('t2.branch')->eq($this->cookie->repoBranch)->fi() + ->orderBy('t1.time desc') + ->limit(1) + ->fetch(); + if(empty($lastComment)) return null; + + $repo = $this->getRepoByID($repoID); + if($repo->SCM == 'Git' and $lastComment->commit != $count) + { + $this->fixCommit($repo->id); + $lastComment->commit = $count; + } + + return $lastComment; + } + + /** + * Set repo branch. + * + * @param string $branch + * @access public + * @return void + */ + public function setRepoBranch($branch) + { + setcookie("repoBranch", $branch, 0, $this->config->webRoot); + $_COOKIE['repoBranch'] = $branch; + } + + /** + * Save commit. + * + * @param int $repoID + * @param array $logs + * @param int $version + * @param string $branch + * @access public + * @return int + */ + public function saveCommit($repoID, $logs, $version, $branch = '') + { + $count = 0; + if(empty($logs)) return $count; + + foreach($logs['commits'] as $i => $commit) + { + $existsRevision = $this->dao->select('id,revision')->from(TABLE_REPOHISTORY)->where('repo')->eq($repoID)->andWhere('revision')->eq($commit->revision)->fetch(); + if($existsRevision) + { + if($branch) $this->dao->replace(TABLE_REPOBRANCH)->set('repo')->eq($repoID)->set('revision')->eq($existsRevision->id)->set('branch')->eq($branch)->exec(); + continue; + } + + $commit->repo = $repoID; + $commit->commit = $version; + $commit->comment = htmlspecialchars($commit->comment); + $this->dao->insert(TABLE_REPOHISTORY)->data($commit)->exec(); + if(!dao::isError()) + { + $commitID = $this->dao->lastInsertID(); + if($branch) $this->dao->replace(TABLE_REPOBRANCH)->set('repo')->eq($repoID)->set('revision')->eq($commitID)->set('branch')->eq($branch)->exec(); + foreach($logs['files'][$i] as $file) + { + $parentPath = dirname($file->path); + + $file->parent = $parentPath == '\\' ? '/' : $parentPath; + $file->revision = $commitID; + $file->repo = $repoID; + $this->dao->insert(TABLE_REPOFILES)->data($file)->exec(); + } + $revisionPairs[$commit->revision] = $commit->revision; + $version++; + $count++; + } + else + { + dao::getError(); + } + } + return $count; + } + + /** + * Save exists log branch. + * + * @param int $repoID + * @param string $branch + * @access public + * @return void + */ + public function saveExistsLogBranch($repoID, $branch) + { + $lastBranchLog = $this->dao->select('t1.time')->from(TABLE_REPOHISTORY)->alias('t1') + ->leftJoin(TABLE_REPOBRANCH)->alias('t2')->on('t1.id=t2.revision') + ->where('t1.repo')->eq($repoID) + ->andWhere('t2.branch')->eq($branch) + ->orderBy('time') + ->limit(1) + ->fetch(); + $stmt = $this->dao->select('*')->from(TABLE_REPOHISTORY)->where('repo')->eq($repoID)->andWhere('time')->lt($lastBranchLog->time)->query(); + while($log = $stmt->fetch()) + { + $this->dao->REPLACE(TABLE_REPOBRANCH)->set('repo')->eq($repoID)->set('revision')->eq($log->id)->set('branch')->eq($branch)->exec(); + } + } + + /** + * Fix commit. + * + * @param int $repoID + * @access public + * @return void + */ + public function fixCommit($repoID) + { + $stmt = $this->dao->select('DISTINCT t1.id')->from(TABLE_REPOHISTORY)->alias('t1') + ->leftJoin(TABLE_REPOBRANCH)->alias('t2')->on('t1.id=t2.revision') + ->where('t1.repo')->eq($repoID) + ->beginIF($this->cookie->repoBranch)->andWhere('t2.branch')->eq($this->cookie->repoBranch)->fi() + ->orderBy('time') + ->query(); + + $i = 1; + while($repoHistory = $stmt->fetch()) + { + $this->dao->update(TABLE_REPOHISTORY)->set('`commit`')->eq($i)->where('id')->eq($repoHistory->id)->exec(); + $i++; + } + } + + /** + * Mark synced status. + * + * @param int $repoID + * @access public + * @return void + */ + public function markSynced($repoID) + { + $this->fixCommit($repoID); + $this->dao->update(TABLE_REPO)->set('synced')->eq(1)->where('id')->eq($repoID)->exec(); + } + /** * Create link for repo * @@ -403,7 +564,7 @@ class ciModel extends model */ public function createLink($method, $params = '', $pathParams = '', $viewType = '', $onlybody = false) { - $link = helper::createLink('repo', $method, $params, $viewType, $onlybody); + $link = helper::createLink('ci', $method, $params, $viewType, $onlybody); if(empty($pathParams)) return $link; $link .= strpos($link, '?') === false ? '?' : '&'; diff --git a/module/ci/view/browserepo.html.php b/module/ci/view/browserepo.html.php index 22a6fd80c7..dc11b8d8fb 100644 --- a/module/ci/view/browserepo.html.php +++ b/module/ci/view/browserepo.html.php @@ -34,7 +34,7 @@ $repo): ?> - repo->typeList, $repo->SCM); ?> + repo->scmList, $repo->SCM); ?> name; ?> path; ?> diff --git a/module/ci/view/showsynccomment.html.php b/module/ci/view/showsynccomment.html.php index c5cdaeb7ed..14bcb83d6e 100644 --- a/module/ci/view/showsynccomment.html.php +++ b/module/ci/view/showsynccomment.html.php @@ -33,7 +33,7 @@ $(function(){ if(data == 'finish') { $('#caption').text('repo->notice->syncComplete?>'); - return self.location = createLink('ci', 'browserepo', "repoID="); + return self.location = createLink('ci', 'browserepo'); } $('#commits').html(parseInt($('#commits').html()) + parseInt(data)); setTimeout(syncComments, 10); From 8e146a8362d87a98517ae44254e17bcaf2e23a20 Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Thu, 12 Dec 2019 20:04:00 +0800 Subject: [PATCH 007/164] git support --- module/ci/control.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/ci/control.php b/module/ci/control.php index da9c87e279..9afdd755e1 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -280,7 +280,7 @@ class ci extends control if(dao::isError()) die(js::error(dao::getError())); $link = $this->ci->createLink('showSyncComment', "repoID=$repoID"); - die(js::locate($link, 'parent')); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $link)); } $this->app->loadLang('action'); @@ -316,7 +316,7 @@ class ci extends control { die(js::locate($this->ci->createLink('showSyncComment', "repoID=$repoID"), 'parent')); } - die(js::locate($this->ci->createLink('browseRepo'), 'parent')); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseRepo'))); } $this->app->loadLang('action'); From 1933a29ac602096dca62444fe74b8e7443adfa2f Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Fri, 13 Dec 2019 09:38:19 +0800 Subject: [PATCH 008/164] git support --- module/ci/config.php | 5 +++++ module/ci/control.php | 9 +++++---- module/ci/model.php | 16 ++++++++-------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/module/ci/config.php b/module/ci/config.php index 12f4a8ca55..7af713433a 100644 --- a/module/ci/config.php +++ b/module/ci/config.php @@ -7,3 +7,8 @@ $config->jenkins->edit->requiredFields = 'name'; $config->repo->create->requiredFields = 'SCM,name,path,encoding,client,credential'; $config->repo->edit->requiredFields = 'SCM,name,path,encoding,client,credential'; +$config->repo->cacheTime = 10; +$config->repo->syncTime = 10; +$config->repo->batchNum = 100; +$config->repo->images = '|png|gif|jpg|ico|jpeg|bmp|'; +$config->repo->binary = '|pdf|'; \ No newline at end of file diff --git a/module/ci/control.php b/module/ci/control.php index 9afdd755e1..8ca97cdaa6 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -314,7 +314,8 @@ class ci extends control if(dao::isError()) die(js::error(dao::getError())); if(!$needSync) { - die(js::locate($this->ci->createLink('showSyncComment', "repoID=$repoID"), 'parent')); + $link = $this->ci->createLink('showSyncComment', "repoID=$repoID"); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $link)); } $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseRepo'))); } @@ -405,8 +406,8 @@ class ci extends control unset($branches[$branch]); if($branch == $branchID) { - $this->ci->setRepoBranch($branchID); - setcookie("syncBranch", $branchID, 0, $this->config->webRoot); +// $this->ci->setRepoBranch($branchID); +// setcookie("syncBranch", $branchID, 0, $this->config->webRoot); break; } } @@ -416,7 +417,7 @@ class ci extends control $latestInDB = $this->dao->select('DISTINCT t1.*')->from(TABLE_REPOHISTORY)->alias('t1') ->leftJoin(TABLE_REPOBRANCH)->alias('t2')->on('t1.id=t2.revision') ->where('t1.repo')->eq($repoID) - ->beginIF($repo->SCM == 'Git' and $this->cookie->repoBranch)->andWhere('t2.branch')->eq($this->cookie->repoBranch)->fi() +// ->beginIF($repo->SCM == 'Git' and $this->cookie->repoBranch)->andWhere('t2.branch')->eq($this->cookie->repoBranch)->fi() ->orderBy('t1.time') ->limit(1) ->fetch(); diff --git a/module/ci/model.php b/module/ci/model.php index c222e1a7a5..a91fd957e1 100644 --- a/module/ci/model.php +++ b/module/ci/model.php @@ -402,13 +402,13 @@ class ciModel extends model $count = $this->dao->select('count(DISTINCT t1.id) as count')->from(TABLE_REPOHISTORY)->alias('t1') ->leftJoin(TABLE_REPOBRANCH)->alias('t2')->on('t1.id=t2.revision') ->where('t1.repo')->eq($repoID) - ->beginIF($this->cookie->repoBranch)->andWhere('t2.branch')->eq($this->cookie->repoBranch)->fi() +// ->beginIF($this->cookie->repoBranch)->andWhere('t2.branch')->eq($this->cookie->repoBranch)->fi() ->fetch('count'); $lastComment = $this->dao->select('t1.*')->from(TABLE_REPOHISTORY)->alias('t1') ->leftJoin(TABLE_REPOBRANCH)->alias('t2')->on('t1.id=t2.revision') ->where('t1.repo')->eq($repoID) - ->beginIF($this->cookie->repoBranch)->andWhere('t2.branch')->eq($this->cookie->repoBranch)->fi() +// ->beginIF($this->cookie->repoBranch)->andWhere('t2.branch')->eq($this->cookie->repoBranch)->fi() ->orderBy('t1.time desc') ->limit(1) ->fetch(); @@ -431,11 +431,11 @@ class ciModel extends model * @access public * @return void */ - public function setRepoBranch($branch) - { - setcookie("repoBranch", $branch, 0, $this->config->webRoot); - $_COOKIE['repoBranch'] = $branch; - } +// public function setRepoBranch($branch) +// { +// setcookie("repoBranch", $branch, 0, $this->config->webRoot); +// $_COOKIE['repoBranch'] = $branch; +// } /** * Save commit. @@ -526,7 +526,7 @@ class ciModel extends model $stmt = $this->dao->select('DISTINCT t1.id')->from(TABLE_REPOHISTORY)->alias('t1') ->leftJoin(TABLE_REPOBRANCH)->alias('t2')->on('t1.id=t2.revision') ->where('t1.repo')->eq($repoID) - ->beginIF($this->cookie->repoBranch)->andWhere('t2.branch')->eq($this->cookie->repoBranch)->fi() +// ->beginIF($this->cookie->repoBranch)->andWhere('t2.branch')->eq($this->cookie->repoBranch)->fi() ->orderBy('time') ->query(); From d8676c8b89be9c6d499a672a2420cbb039c63f4c Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Fri, 13 Dec 2019 09:40:58 +0800 Subject: [PATCH 009/164] git support --- module/ci/control.php | 1 + 1 file changed, 1 insertion(+) diff --git a/module/ci/control.php b/module/ci/control.php index 8ca97cdaa6..f7911dca57 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -414,6 +414,7 @@ class ci extends control } } + $latestInDB = $this->dao->select('DISTINCT t1.*')->from(TABLE_REPOHISTORY)->alias('t1') ->leftJoin(TABLE_REPOBRANCH)->alias('t2')->on('t1.id=t2.revision') ->where('t1.repo')->eq($repoID) From 98746091802da3ccf18f00ca73d4c29d73bf4506 Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Fri, 13 Dec 2019 09:44:53 +0800 Subject: [PATCH 010/164] git support --- module/ci/control.php | 1 - 1 file changed, 1 deletion(-) diff --git a/module/ci/control.php b/module/ci/control.php index f7911dca57..8ca97cdaa6 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -414,7 +414,6 @@ class ci extends control } } - $latestInDB = $this->dao->select('DISTINCT t1.*')->from(TABLE_REPOHISTORY)->alias('t1') ->leftJoin(TABLE_REPOBRANCH)->alias('t2')->on('t1.id=t2.revision') ->where('t1.repo')->eq($repoID) From 79591ae2f9b8ba5a291d3fd70892331ab122dde6 Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Fri, 13 Dec 2019 09:49:46 +0800 Subject: [PATCH 011/164] git support --- module/ci/view/createcredential.html.php | 1 + 1 file changed, 1 insertion(+) diff --git a/module/ci/view/createcredential.html.php b/module/ci/view/createcredential.html.php index 2831174067..5682caac9c 100644 --- a/module/ci/view/createcredential.html.php +++ b/module/ci/view/createcredential.html.php @@ -42,6 +42,7 @@ + credential->password; ?> From 28a2ead76ab86745eb0d22f076a26eab5f4a42d4 Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Fri, 13 Dec 2019 10:46:44 +0800 Subject: [PATCH 012/164] git support --- module/ci/view/browserepo.html.php | 1 + 1 file changed, 1 insertion(+) diff --git a/module/ci/view/browserepo.html.php b/module/ci/view/browserepo.html.php index dc11b8d8fb..f8181f9d42 100644 --- a/module/ci/view/browserepo.html.php +++ b/module/ci/view/browserepo.html.php @@ -39,6 +39,7 @@ path; ?> createLink('ci', 'deleteRepo', "repoID=$id&confirm=yes"); From 2b4fbf2355a0fad4768486b7e2bffcc0413de6b1 Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Fri, 13 Dec 2019 14:32:24 +0800 Subject: [PATCH 013/164] git support --- module/ci/control.php | 21 +++++++++- module/ci/js/browsebranch.js | 4 ++ module/ci/js/browserepo.js | 4 ++ module/ci/js/createrepo.js | 4 ++ module/ci/js/editrepo.js | 4 ++ module/ci/lang/zh-cn.php | 3 ++ module/ci/model.php | 33 ++++++++-------- module/ci/view/browseBranch.html.php | 58 ++++++++++++++++++++++++++++ module/ci/view/browserepo.html.php | 2 +- module/ci/view/header.html.php | 7 +++- module/common/lang/zh-cn.php | 2 +- 11 files changed, 121 insertions(+), 21 deletions(-) create mode 100644 module/ci/js/browsebranch.js create mode 100644 module/ci/js/browserepo.js create mode 100644 module/ci/js/createrepo.js create mode 100644 module/ci/js/editrepo.js create mode 100644 module/ci/view/browseBranch.html.php diff --git a/module/ci/control.php b/module/ci/control.php index 8ca97cdaa6..c627aa5889 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -352,6 +352,25 @@ class ci extends control $this->send(array('result' => 'success')); } + /** + * browse branches. + * + * @param int $repoID + * @access public + * @return void + */ + public function browseBranch($repoID = 0) + { + $repo = $this->ci->getRepoByID($repoID); + $branches = $this->ci->getBranches($repo); + + $this->view->repo = $repo; + $this->view->branches = $branches; + + $this->view->module = 'repo'; + $this->display(); + } + /** * Show sync comment. * @@ -366,7 +385,7 @@ class ci extends control $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->showSyncComment; $this->view->position[] = $this->lang->repo->showSyncComment; - $latestInDB = $this->ci->getLatestComment($repoID); + $latestInDB = $this->ci->getLatestComment($repoID, ); $this->view->version = $latestInDB ? (int)$latestInDB->commit : 1; $this->view->repoID = $repoID; $this->display(); diff --git a/module/ci/js/browsebranch.js b/module/ci/js/browsebranch.js new file mode 100644 index 0000000000..6126dd22b2 --- /dev/null +++ b/module/ci/js/browsebranch.js @@ -0,0 +1,4 @@ +$(function() +{ + $('#' + module + 'Tab').addClass('btn-active-text'); +}) \ No newline at end of file diff --git a/module/ci/js/browserepo.js b/module/ci/js/browserepo.js new file mode 100644 index 0000000000..6126dd22b2 --- /dev/null +++ b/module/ci/js/browserepo.js @@ -0,0 +1,4 @@ +$(function() +{ + $('#' + module + 'Tab').addClass('btn-active-text'); +}) \ No newline at end of file diff --git a/module/ci/js/createrepo.js b/module/ci/js/createrepo.js new file mode 100644 index 0000000000..6126dd22b2 --- /dev/null +++ b/module/ci/js/createrepo.js @@ -0,0 +1,4 @@ +$(function() +{ + $('#' + module + 'Tab').addClass('btn-active-text'); +}) \ No newline at end of file diff --git a/module/ci/js/editrepo.js b/module/ci/js/editrepo.js new file mode 100644 index 0000000000..420e3dd30d --- /dev/null +++ b/module/ci/js/editrepo.js @@ -0,0 +1,4 @@ +$(function() +{ + $('#' + module + 'Tab').addClass('btn-active-text'); +}); \ No newline at end of file diff --git a/module/ci/lang/zh-cn.php b/module/ci/lang/zh-cn.php index 59007634d3..d925dd8716 100644 --- a/module/ci/lang/zh-cn.php +++ b/module/ci/lang/zh-cn.php @@ -2,6 +2,8 @@ $lang->ci->common = '持续集成'; $lang->ci->list = '列表'; $lang->ci->create = '添加'; +$lang->ci->numb = '序号'; +$lang->ci->name = '名称'; $lang->ci->subModules['credential'] = '凭证'; $lang->ci->subModules['jenkins'] = 'Jenkins'; @@ -75,6 +77,7 @@ $lang->repo->example->encoding = "填写版本库中文件的编码"; $lang->repo->svnCredentialLimt = "Subversion版本库的凭证必须为用户名密码类型"; $lang->repo->showSyncComment = '显示同步进度'; +$lang->repo->watch = '监听'; $lang->repo->notice = new stdclass(); $lang->repo->notice->syncing = '正在同步中, 请稍等...'; diff --git a/module/ci/model.php b/module/ci/model.php index a91fd957e1..2db3349bc0 100644 --- a/module/ci/model.php +++ b/module/ci/model.php @@ -295,6 +295,20 @@ class ciModel extends model return true; } + /** + * Get git branches. + * + * @param object $repo + * @access public + * @return array + */ + public function getBranches($repo) + { + $this->scm = $this->app->loadClass('scm'); + $this->scm->setEngine($repo); + return $this->scm->branch(); + } + /** * Check repo connection * @@ -397,18 +411,18 @@ class ciModel extends model * @access public * @return object */ - public function getLatestComment($repoID) + public function getLatestComment($repoID, $branchID='') { $count = $this->dao->select('count(DISTINCT t1.id) as count')->from(TABLE_REPOHISTORY)->alias('t1') ->leftJoin(TABLE_REPOBRANCH)->alias('t2')->on('t1.id=t2.revision') ->where('t1.repo')->eq($repoID) -// ->beginIF($this->cookie->repoBranch)->andWhere('t2.branch')->eq($this->cookie->repoBranch)->fi() + ->beginIF($branchID)->andWhere('t2.branch')->eq($branchID)->fi() ->fetch('count'); $lastComment = $this->dao->select('t1.*')->from(TABLE_REPOHISTORY)->alias('t1') ->leftJoin(TABLE_REPOBRANCH)->alias('t2')->on('t1.id=t2.revision') ->where('t1.repo')->eq($repoID) -// ->beginIF($this->cookie->repoBranch)->andWhere('t2.branch')->eq($this->cookie->repoBranch)->fi() + ->beginIF($branchID)->andWhere('t2.branch')->eq($branchID)->fi() ->orderBy('t1.time desc') ->limit(1) ->fetch(); @@ -424,19 +438,6 @@ class ciModel extends model return $lastComment; } - /** - * Set repo branch. - * - * @param string $branch - * @access public - * @return void - */ -// public function setRepoBranch($branch) -// { -// setcookie("repoBranch", $branch, 0, $this->config->webRoot); -// $_COOKIE['repoBranch'] = $branch; -// } - /** * Save commit. * diff --git a/module/ci/view/browseBranch.html.php b/module/ci/view/browseBranch.html.php new file mode 100644 index 0000000000..6e3f556bd8 --- /dev/null +++ b/module/ci/view/browseBranch.html.php @@ -0,0 +1,58 @@ + + * @package ci + * @version $Id$ + * @link http://www.zentao.net + */ +?> + + +
+ +
+
+ + + + + + + + + + + $branch): ?> + + + + + + + + +
ci->numb; ?>ci->name; ?>repo->watch; ?>actions; ?>
+ + + createLink('ci', 'deleteRepo', "branchID=$id&confirm=yes"); + echo html::a("javascript:ajaxDelete(\"$deleteURL\", \"branchList\", confirmDelete)", '', '', "title='{$lang->branch->delete}' class='btn'"); + } + ?> +
+ + + +
+
+
+ diff --git a/module/ci/view/browserepo.html.php b/module/ci/view/browserepo.html.php index f8181f9d42..7d077d195e 100644 --- a/module/ci/view/browserepo.html.php +++ b/module/ci/view/browserepo.html.php @@ -39,7 +39,7 @@ path; ?> createLink('ci', 'deleteRepo', "repoID=$id&confirm=yes"); diff --git a/module/ci/view/header.html.php b/module/ci/view/header.html.php index 1be09db581..5148069ae1 100644 --- a/module/ci/view/header.html.php +++ b/module/ci/view/header.html.php @@ -17,11 +17,14 @@
methodName,'browse') > -1 && (true || common::hasPriv($module, 'create'))) { + if($this->methodName !== 'browsebranch' && strpos($this->methodName,'browse') > -1 && common::hasPriv($module, 'create')) { echo html::a(inlink('create' . $module), " {$lang->ci->create}{$lang->ci->subModules[$module]}", '', "class='btn btn-primary'"); - }?> + } else if($this->methodName == 'browsebranch') { + echo html::backButton(); + } + ?>
diff --git a/module/common/lang/zh-cn.php b/module/common/lang/zh-cn.php index 68e30fccbf..ded0ba018b 100644 --- a/module/common/lang/zh-cn.php +++ b/module/common/lang/zh-cn.php @@ -399,7 +399,7 @@ $lang->admin->subMenu->message->setting = array('link' => '设置|message|settin $lang->admin->subMenu->sso = new stdclass(); $lang->admin->subMenu->sso->ranzhi = '然之协同|admin|sso'; $lang->admin->subMenu->sso->ci = array('link' => '持续集成|ci|index', - 'alias' => 'browsecredential,createcredential,editcredential,browsejenkins,createjenkins,editjenkins'); + 'alias' => 'browsecredential,createcredential,editcredential,browsejenkins,createjenkins,editjenkins,browserepo,editrepo,browsebranch'); $lang->admin->subMenu->dev = new stdclass(); $lang->admin->subMenu->dev->api = array('link' => 'API|dev|api'); From 4ec2ad34195d9a01d938083cc54061057c65060c Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Fri, 13 Dec 2019 14:33:41 +0800 Subject: [PATCH 014/164] git support --- module/ci/control.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/module/ci/control.php b/module/ci/control.php index c627aa5889..612661a774 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -425,8 +425,6 @@ class ci extends control unset($branches[$branch]); if($branch == $branchID) { -// $this->ci->setRepoBranch($branchID); -// setcookie("syncBranch", $branchID, 0, $this->config->webRoot); break; } } From 93329f50fd7b3630cb9c0c1f25535678bc7d5f55 Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Fri, 13 Dec 2019 14:34:43 +0800 Subject: [PATCH 015/164] git support --- module/ci/control.php | 1 - 1 file changed, 1 deletion(-) diff --git a/module/ci/control.php b/module/ci/control.php index 612661a774..5b1181a197 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -407,7 +407,6 @@ class ci extends control if($repo->synced) die('finish'); $this->scm->setEngine($repo); - $branchID = ''; if($repo->SCM == 'Git' and empty($branchID)) { From ece270825290ae9ad73b703e69da2b403261a9c6 Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Fri, 13 Dec 2019 14:37:53 +0800 Subject: [PATCH 016/164] git support --- module/ci/control.php | 1 + 1 file changed, 1 insertion(+) diff --git a/module/ci/control.php b/module/ci/control.php index 5b1181a197..612661a774 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -407,6 +407,7 @@ class ci extends control if($repo->synced) die('finish'); $this->scm->setEngine($repo); + $branchID = ''; if($repo->SCM == 'Git' and empty($branchID)) { From 5e01c90a6e198489db4935fb0b9c372f12831cde Mon Sep 17 00:00:00 2001 From: aaronchen2k <462826@qq.com> Date: Fri, 13 Dec 2019 14:43:50 +0800 Subject: [PATCH 017/164] git support --- module/ci/control.php | 1 + 1 file changed, 1 insertion(+) diff --git a/module/ci/control.php b/module/ci/control.php index 612661a774..c89ce952cd 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -412,6 +412,7 @@ class ci extends control if($repo->SCM == 'Git' and empty($branchID)) { $branches = $this->scm->branch(); + if($branches) { /* Init branchID. */ From f00f2bfa64649ee6ca0edc171ad3c47f9fe7781e Mon Sep 17 00:00:00 2001 From: aaronchen2k <462826@qq.com> Date: Fri, 13 Dec 2019 14:46:46 +0800 Subject: [PATCH 018/164] git support --- module/ci/control.php | 1 - 1 file changed, 1 deletion(-) diff --git a/module/ci/control.php b/module/ci/control.php index c89ce952cd..612661a774 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -412,7 +412,6 @@ class ci extends control if($repo->SCM == 'Git' and empty($branchID)) { $branches = $this->scm->branch(); - if($branches) { /* Init branchID. */ From 0451789e3aa9781a37020a92bd287dc041f1a7a6 Mon Sep 17 00:00:00 2001 From: aaronchen2k <462826@qq.com> Date: Fri, 13 Dec 2019 16:20:46 +0800 Subject: [PATCH 019/164] watch branch --- module/ci/control.php | 19 ++++++++++++++++++- module/ci/js/browsebranch.js | 17 ++++++++++++++++- module/ci/lang/zh-cn.php | 4 +++- module/ci/model.php | 17 ++++++++++++++++- module/ci/view/browseBranch.html.php | 7 ++++--- 5 files changed, 57 insertions(+), 7 deletions(-) diff --git a/module/ci/control.php b/module/ci/control.php index 612661a774..5b96a25a12 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -362,7 +362,7 @@ class ci extends control public function browseBranch($repoID = 0) { $repo = $this->ci->getRepoByID($repoID); - $branches = $this->ci->getBranches($repo); + $branches = $this->ci->getBranchesFromDb($repoID); $this->view->repo = $repo; $this->view->branches = $branches; @@ -371,6 +371,23 @@ class ci extends control $this->display(); } + /** + * watch branche. + * + * @param int $repoID + * @access public + * @return void + */ + public function watchBranch($repoID = 0, $branch=0, $status=0) + { + $this->dao->update(TABLE_REPOBRANCH) + ->set('watch=' . $status) + ->where('repo')->eq($repoID) + ->andWhere('branch')->eq($branch) + ->exec(); + echo true; + } + /** * Show sync comment. * diff --git a/module/ci/js/browsebranch.js b/module/ci/js/browsebranch.js index 6126dd22b2..07f6e9ba98 100644 --- a/module/ci/js/browsebranch.js +++ b/module/ci/js/browsebranch.js @@ -1,4 +1,19 @@ $(function() { $('#' + module + 'Tab').addClass('btn-active-text'); -}) \ No newline at end of file +}) + +function watch(ths){ + var elem = $(ths); + var newVal = elem.prop('checked'); + + var repoID = elem.attr('data-repo'); + var branch = elem.attr('data-branch'); + + var link = createLink('ci', 'watchBranch', "repoID=" + repoID + "&branch=" + branch + "&status=" + newVal); + console.log(link); + $.get(link, function(data) + { + elem.prop(newVal); + }); +} \ No newline at end of file diff --git a/module/ci/lang/zh-cn.php b/module/ci/lang/zh-cn.php index d925dd8716..400715100c 100644 --- a/module/ci/lang/zh-cn.php +++ b/module/ci/lang/zh-cn.php @@ -110,4 +110,6 @@ $lang->repo->error->clientVersion = "客户端版本过低,请升级或更换S $lang->repo->error->encoding = "编码可能错误,请更换编码重试。"; $lang->repo->scmList['Subversion'] = 'Subversion'; -$lang->repo->scmList['Git'] = 'Git'; \ No newline at end of file +$lang->repo->scmList['Git'] = 'Git'; + +$lang->repo->watchList['1'] = ''; \ No newline at end of file diff --git a/module/ci/model.php b/module/ci/model.php index 2db3349bc0..47658bd8d3 100644 --- a/module/ci/model.php +++ b/module/ci/model.php @@ -296,7 +296,7 @@ class ciModel extends model } /** - * Get git branches. + * Get git branches from scm. * * @param object $repo * @access public @@ -309,6 +309,21 @@ class ciModel extends model return $this->scm->branch(); } + /** + * Get git branches from db. + * + * @param object $repo + * @access public + * @return array + */ + public function getBranchesFromDb($repoID) + { + $branches = $this->dao->select('*')->from(TABLE_REPOBRANCH) + ->where('repo')->eq($repoID) + ->fetchAll('repo'); + return $branches; + } + /** * Check repo connection * diff --git a/module/ci/view/browseBranch.html.php b/module/ci/view/browseBranch.html.php index 6e3f556bd8..a917fcc625 100644 --- a/module/ci/view/browseBranch.html.php +++ b/module/ci/view/browseBranch.html.php @@ -29,12 +29,13 @@ $branch): ?> + foreach ($branches as $branch): ?> - + branch; ?> - + repo->watchList, $branch->watch, + "data-branch='" . $branch->branch . "' data-repo='" . $branch->repo . "' onclick='watch(this)'");?> Date: Wed, 8 Jan 2020 19:56:47 +0800 Subject: [PATCH 020/164] fix issues for code standards --- module/ci/view/{browseBranch.html.php => browsebranch.html.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename module/ci/view/{browseBranch.html.php => browsebranch.html.php} (100%) diff --git a/module/ci/view/browseBranch.html.php b/module/ci/view/browsebranch.html.php similarity index 100% rename from module/ci/view/browseBranch.html.php rename to module/ci/view/browsebranch.html.php From a786e50b33ea4b63fe53dbf4e6ba4f5849fdc1eb Mon Sep 17 00:00:00 2001 From: aaronchen2k <462826@qq.com> Date: Wed, 8 Jan 2020 20:24:31 +0800 Subject: [PATCH 021/164] fix issues for code standards --- lib/scm/subversion.class.php | 5 --- module/ci/control.php | 56 ++++++++++++++------------------- module/ci/lang/zh-cn.php | 36 ++++++++++++--------- module/ci/model.php | 13 +++++--- module/common/lang/zh-cn.php | 7 ++--- module/custom/view/set.html.php | 4 +-- 6 files changed, 58 insertions(+), 63 deletions(-) diff --git a/lib/scm/subversion.class.php b/lib/scm/subversion.class.php index ef8872c2bf..d5075c150b 100644 --- a/lib/scm/subversion.class.php +++ b/lib/scm/subversion.class.php @@ -262,14 +262,11 @@ class Subversion $entry = '"' . $this->root . '/' . str_replace('%2F', '/', urlencode($entry)) . '"'; $svnInfo = $this->replaceAuth(escapeCmd($this->buildCMD($entry, 'info', "-r $revision --xml"))); - a($svnInfo); - $svninfo = execCmd($svnInfo, 'string', $result); if($result) { $entry = '"' . $this->root . '/' . $resourcePath . '"'; $svnInfo = $this->replaceAuth(escapeCmd($this->buildCMD($entry, 'info', "-r $revision --xml"))); - echo $svnInfo; $svninfo = execCmd($svnInfo, 'string', $result); if($result) $svninfo = ''; @@ -464,8 +461,6 @@ class Subversion $cmd = str_replace("\\", "/", "$this->client $action $param --no-auth-cache $path"); } - a($cmd); - return $cmd; } } diff --git a/module/ci/control.php b/module/ci/control.php index 5b96a25a12..db290e1add 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -1,4 +1,5 @@ * @package product - * @version $Id: control.php 5144 2019-12-11 06:37:03Z chenqi@cnezsoft.com $ + * @version $Id: ${FILE_NAME} 5144 2020/1/8 8:10 下午 chenqi@cnezsoft.com $ * @link http://www.zentao.net */ class ci extends control { /** - * Construct function. - * - * @access public - * @return void + * ci constructor. + * @param string $moduleName + * @param string $methodName */ public function __construct($moduleName = '', $methodName = '') { parent::__construct($moduleName, $methodName); - - /* Load need modules. */ - $this->loadModel('credential'); - $this->loadModel('user'); - $this->scm = $this->app->loadClass('scm'); } @@ -40,14 +35,12 @@ class ci extends control } /** - * Browse credentials. + * Browse credentials * - * @param string $orderBy - * @param int $recTotal - * @param int $recPerPage - * @param int $pageID - * @access public - * @return void + * @param string $orderBy + * @param int $recTotal + * @param int $recPerPage + * @param int $pageID */ public function browseCredential($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { @@ -136,7 +129,6 @@ class ci extends control $this->send(array('result' => 'success')); } - /** * Browse jenkinss. * @@ -254,14 +246,14 @@ class ci extends control $pager = new pager($recTotal, $recPerPage, $pageID); $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->list; - $this->view->repoList = $this->ci->listRepo($orderBy, $pager); + $this->view->position[] = $this->lang->ci->common; + $this->view->position[] = $this->lang->repo->common; - $this->view->position[] = $this->lang->ci->common; - $this->view->position[] = $this->lang->repo->common; + $this->view->repoList = $this->ci->listRepo($orderBy, $pager); $this->view->orderBy = $orderBy; $this->view->pager = $pager; - $this->view->module = 'repo'; + $this->view->module = 'repo'; $this->display(); } @@ -301,7 +293,7 @@ class ci extends control /** * Edit a repo. * - * @param int $id + * @param int $repoID * @access public * @return void */ @@ -322,7 +314,6 @@ class ci extends control $this->app->loadLang('action'); $this->view->title = $this->lang->repo->edit . $this->lang->colon . $repo->name; - $this->view->position[] = $this->lang->ci->common; $this->view->position[] = html::a(inlink('browseRepo'), $this->lang->repo->common); $this->view->position[] = $this->lang->repo->edit; @@ -340,7 +331,7 @@ class ci extends control /** * Delete a repo. * - * @param int $id + * @param int $id * @access public * @return void */ @@ -355,7 +346,7 @@ class ci extends control /** * browse branches. * - * @param int $repoID + * @param int $repoID * @access public * @return void */ @@ -372,26 +363,25 @@ class ci extends control } /** - * watch branche. + * watch branch. * - * @param int $repoID - * @access public - * @return void + * @param int $repoID + * @param int $branch + * @param int $status */ - public function watchBranch($repoID = 0, $branch=0, $status=0) + public function watchBranch($repoID = 0, $branch = 0, $status = 0) { $this->dao->update(TABLE_REPOBRANCH) ->set('watch=' . $status) ->where('repo')->eq($repoID) ->andWhere('branch')->eq($branch) ->exec(); - echo true; } /** * Show sync comment. * - * @param int $repoID + * @param int $repoID * @access public * @return void */ diff --git a/module/ci/lang/zh-cn.php b/module/ci/lang/zh-cn.php index 400715100c..9aa7eb0eb6 100644 --- a/module/ci/lang/zh-cn.php +++ b/module/ci/lang/zh-cn.php @@ -52,22 +52,28 @@ $lang->jenkins->desc = '描述'; $lang->jenkins->typeList['token'] = 'Token'; $lang->jenkins->typeList['credential'] = '凭证'; - // repo -$lang->repo->id = 'ID'; -$lang->repo->name = '名称'; -$lang->repo->path = '地址'; -$lang->repo->type = '类型'; -$lang->repo->client = '客户端'; -$lang->repo->credential = '凭证'; -$lang->repo->encoding = '编码'; -$lang->repo->account = '用户名'; -$lang->repo->password = '密码'; -$lang->repo->token = 'Token'; -$lang->repo->acl = '权限'; -$lang->repo->group = '分组'; -$lang->repo->user = '用户'; -$lang->repo->desc = '描述'; +$lang->repo->common = '代码库'; +$lang->repo->browse = '浏览代码库'; +$lang->repo->create = '添加代码库'; +$lang->repo->edit = '编辑代码库'; +$lang->repo->delete = '删除代码库'; +$lang->repo->confirmDelete = '确认删除该代码库吗?'; + +$lang->repo->id = 'ID'; +$lang->repo->name = '名称'; +$lang->repo->path = '地址'; +$lang->repo->type = '类型'; +$lang->repo->client = '客户端'; +$lang->repo->credential = '凭证'; +$lang->repo->encoding = '编码'; +$lang->repo->account = '用户名'; +$lang->repo->password = '密码'; +$lang->repo->token = 'Token'; +$lang->repo->acl = '权限'; +$lang->repo->group = '分组'; +$lang->repo->user = '用户'; +$lang->repo->desc = '描述'; $lang->repo->example = new stdclass(); $lang->repo->example->client = "例如:/usr/bin/svn, C:\subversion\svn.exe, /usr/bin/git"; diff --git a/module/ci/model.php b/module/ci/model.php index 47658bd8d3..5cb12c5f7a 100644 --- a/module/ci/model.php +++ b/module/ci/model.php @@ -1,16 +1,15 @@ * @package product - * @version $Id: control.php 5144 2019-12-11 06:37:03Z chenqi@cnezsoft.com $ + * @version $Id: $ * @link http://www.zentao.net */ -?> -dao->select('id, name')->from(TABLE_CREDENTIAL) diff --git a/module/common/lang/zh-cn.php b/module/common/lang/zh-cn.php index ded0ba018b..1d028338ae 100644 --- a/module/common/lang/zh-cn.php +++ b/module/common/lang/zh-cn.php @@ -398,8 +398,7 @@ $lang->admin->subMenu->message->setting = array('link' => '设置|message|settin $lang->admin->subMenu->sso = new stdclass(); $lang->admin->subMenu->sso->ranzhi = '然之协同|admin|sso'; -$lang->admin->subMenu->sso->ci = array('link' => '持续集成|ci|index', - 'alias' => 'browsecredential,createcredential,editcredential,browsejenkins,createjenkins,editjenkins,browserepo,editrepo,browsebranch'); +$lang->admin->subMenu->sso->ci = array('link' => '持续集成|ci|index', 'alias' => 'browsecredential,createcredential,editcredential,browsejenkins,createjenkins,editjenkins,browserepo,editrepo,browsebranch'); $lang->admin->subMenu->dev = new stdclass(); $lang->admin->subMenu->dev->api = array('link' => 'API|dev|api'); @@ -428,7 +427,7 @@ $lang->entry = new stdclass(); $lang->webhook = new stdclass(); $lang->message = new stdclass(); $lang->search = new stdclass(); -$lang->ci = new stdclass(); +$lang->ci = new stdclass(); $lang->convert->menu = $lang->admin->menu; $lang->upgrade->menu = $lang->admin->menu; @@ -442,7 +441,7 @@ $lang->dev->menu = $lang->admin->menu; $lang->entry->menu = $lang->admin->menu; $lang->webhook->menu = $lang->admin->menu; $lang->message->menu = $lang->admin->menu; -$lang->ci->menu = $lang->admin->menu; +$lang->ci->menu = $lang->admin->menu; /* 菜单分组。*/ $lang->menugroup = new stdclass(); diff --git a/module/custom/view/set.html.php b/module/custom/view/set.html.php index aed1198fa0..55fc05dd45 100644 --- a/module/custom/view/set.html.php +++ b/module/custom/view/set.html.php @@ -28,9 +28,9 @@ $itemRow = << EOT; ?> - + - +