+ " . $lang->gitlab->create, '', "class='btn btn-primary'");?>
+
+diff --git a/config/zentaopms.php b/config/zentaopms.php index 082f797671..09b2262b4a 100644 --- a/config/zentaopms.php +++ b/config/zentaopms.php @@ -180,6 +180,7 @@ define('TABLE_SCORE', '`' . $config->db->prefix . 'score`'); define('TABLE_NOTIFY', '`' . $config->db->prefix . 'notify`'); define('TABLE_OAUTH', '`' . $config->db->prefix . 'oauth`'); define('TABLE_JENKINS', '`' . $config->db->prefix . 'jenkins`'); +define('TABLE_GITLAB', '`' . $config->db->prefix . 'gitlab`'); define('TABLE_JOB', '`' . $config->db->prefix . 'job`'); define('TABLE_COMPILE', '`' . $config->db->prefix . 'compile`'); @@ -225,5 +226,5 @@ $config->objectTables['team'] = TABLE_TEAM; /* Program privs.*/ $config->programPriv = new stdclass(); -$config->programPriv->scrum = array('product', 'story', 'productplan', 'release', 'project', 'task', 'build', 'qa', 'bug', 'testcase', 'testsuite', 'testreport', 'caselib', 'doc', 'report', 'repo', 'svn', 'git', 'search', 'tree', 'file', 'jenkins', 'job', 'ci', 'branch'); +$config->programPriv->scrum = array('product', 'story', 'productplan', 'release', 'project', 'task', 'build', 'qa', 'bug', 'testcase', 'testsuite', 'testreport', 'caselib', 'doc', 'report', 'repo', 'svn', 'git', 'search', 'tree', 'file', 'jenkins', 'gitlab', 'job', 'ci', 'branch'); $config->programPriv->waterfall = $config->programPriv->scrum + array('workestimation', 'durationestimation', 'budget', 'programplan', 'review', 'reviewissue', 'weekly', 'milestone', 'design', 'issue', 'risk', 'auditplan', 'nc', 'cm', 'pssp'); diff --git a/module/common/lang/common.php b/module/common/lang/common.php index 00f346a769..20e9eebdcf 100644 --- a/module/common/lang/common.php +++ b/module/common/lang/common.php @@ -38,6 +38,7 @@ $lang->user = new stdclass(); $lang->report = new stdclass(); $lang->repo = new stdclass(); $lang->jenkins = new stdclass(); +$lang->gitlab = new stdclass(); $lang->compile = new stdclass(); $lang->job = new stdclass(); $lang->svn = new stdclass(); @@ -150,4 +151,4 @@ $lang->icons['unlock'] = 'unlock-alt'; $lang->icons['confirmStoryChange'] = 'search'; $lang->icons['score'] = 'tint'; -$lang->noMenuModule = array('report', 'my', 'todo', 'effort', 'program', 'product', 'execution', 'task', 'build', 'productplan', 'project', 'projectrelease', 'projectstory', 'story', 'branch', 'release', 'attend', 'leave', 'makeup', 'overtime', 'lieu', 'custom', 'admin', 'mail', 'extension', 'dev', 'backup', 'action', 'cron', 'pssp', 'sms', 'message', 'webhook', 'search', 'score', 'stage', 'entry', 'jenkins'); +$lang->noMenuModule = array('report', 'my', 'todo', 'effort', 'program', 'product', 'execution', 'task', 'build', 'productplan', 'project', 'projectrelease', 'projectstory', 'story', 'branch', 'release', 'attend', 'leave', 'makeup', 'overtime', 'lieu', 'custom', 'admin', 'mail', 'extension', 'dev', 'backup', 'action', 'cron', 'pssp', 'sms', 'message', 'webhook', 'search', 'score', 'stage', 'entry', 'jenkins','gitlab'); diff --git a/module/common/lang/menu.php b/module/common/lang/menu.php index 2e2107aefa..fdb26efab4 100644 --- a/module/common/lang/menu.php +++ b/module/common/lang/menu.php @@ -318,12 +318,14 @@ $lang->devops->menu = new stdclass(); $lang->devops->menu->code = array('link' => "{$lang->repo->common}|repo|browse|repoID=%s", 'alias' => 'diff,view,revision,log,blame,showsynccomment'); $lang->devops->menu->compile = array('link' => "{$lang->devops->compile}|job|browse", 'subModule' => 'compile,job'); $lang->devops->menu->jenkins = array('link' => "Jenkins|jenkins|browse", 'alias' => 'create,edit'); +$lang->devops->menu->gitlab = array('link' => "gitlab|gitlab|browse", 'alias' => 'create,edit'); $lang->devops->menu->maintain = array('link' => "{$lang->devops->repo}|repo|maintain", 'alias' => 'create,edit'); $lang->devops->menu->rules = array('link' => "{$lang->devops->rules}|repo|setrules"); $lang->devops->menuOrder[5] = 'code'; $lang->devops->menuOrder[10] = 'compile'; $lang->devops->menuOrder[15] = 'jenkins'; +$lang->devops->menuOrder[16] = 'gitlab'; $lang->devops->menuOrder[20] = 'maintain'; $lang->devops->menuOrder[25] = 'rules'; @@ -520,6 +522,7 @@ $lang->navGroup->devops = 'devops'; $lang->navGroup->repo = 'devops'; $lang->navGroup->job = 'devops'; $lang->navGroup->jenkins = 'devops'; +$lang->navGroup->gitlab = 'devops'; $lang->navGroup->compile = 'devops'; $lang->navGroup->ci = 'devops'; $lang->navGroup->svn = 'devops'; diff --git a/module/gitlab/config.php b/module/gitlab/config.php new file mode 100644 index 0000000000..854bdb3c4d --- /dev/null +++ b/module/gitlab/config.php @@ -0,0 +1,6 @@ +gitlab->create = new stdclass(); +$config->gitlab->edit = new stdclass(); + +$config->gitlab->create->requiredFields = 'name,url'; +$config->gitlab->edit->requiredFields = 'name,url'; diff --git a/module/gitlab/control.php b/module/gitlab/control.php new file mode 100644 index 0000000000..69953d6795 --- /dev/null +++ b/module/gitlab/control.php @@ -0,0 +1,122 @@ + + * @package product + * @version $Id: ${FILE_NAME} 5144 2020/1/8 8:10 下午 chenqi@cnezsoft.com $ + * @link http://www.zentao.net + */ +class gitlab extends control +{ + /** + * Browse gitlab. + * + * @param string $orderBy + * @param int $recTotal + * @param int $recPerPage + * @param int $pageID + * @access public + * @return void + */ + 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); + + $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browse; + $this->view->position[] = $this->lang->gitlab->common; + $this->view->position[] = $this->lang->gitlab->browse; + + $this->view->gitlabList = $this->gitlab->getList($orderBy, $pager); + $this->view->orderBy = $orderBy; + $this->view->pager = $pager; + + $this->display(); + } + + /** + * Create a gitlab. + * + * @access public + * @return void + */ + public function create() + { + if($_POST) + { + $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'))); + } + + $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->create; + + $this->view->position[] = html::a(inlink('browse'), $this->lang->gitlab->common); + $this->view->position[] = $this->lang->gitlab->create; + + $this->display(); + } + + /** + * Edit a gitlab. + * + * @param int $id + * @access public + * @return void + */ + public function edit($id) + { + $gitlab = $this->gitlab->getByID($id); + if($_POST) + { + $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'))); + } + + $this->view->position[] = html::a(inlink('browse'), $this->lang->gitlab->common); + $this->view->position[] = $this->lang->gitlab->edit; + + $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->edit; + $this->view->gitlab = $gitlab; + + $this->display(); + } + + /** + * Delete a gitlab. + * + * @param int $id + * @access public + * @return void + */ + public function delete($id, $confim = 'no') + { + if($confim != 'yes') die(js::confirm($this->lang->gitlab->confirmDelete, inlink('delete', "id=$id&confirm=yes"))); + + $this->gitlab->delete(TABLE_GITLAB, $id); + die(js::reload('parent')); + } + + /** + * Ajax get tasks. + * + * @param int $id + * @access public + * @return void + */ + public function ajaxGetTasks($id) + { + if(empty($id)) die(json_encode(array('' => ''))); + + $tasks = $this->gitlab->getTasks($id); + die(json_encode($tasks)); + } +} diff --git a/module/gitlab/lang/de.php b/module/gitlab/lang/de.php new file mode 100644 index 0000000000..4e2c99ff52 --- /dev/null +++ b/module/gitlab/lang/de.php @@ -0,0 +1,19 @@ +jenkins->common = 'Jenkins'; +$lang->jenkins->browse = 'Browse Jenkins'; +$lang->jenkins->create = 'Create Jenkins'; +$lang->jenkins->edit = 'Edit Jenkins'; +$lang->jenkins->delete = 'Delete'; +$lang->jenkins->confirmDelete = 'Do you want to delete this Jenkins server?'; + +$lang->jenkins->id = 'ID'; +$lang->jenkins->name = 'Name'; +$lang->jenkins->url = 'Service URL'; +$lang->jenkins->token = 'Token'; +$lang->jenkins->account = 'UserName'; +$lang->jenkins->password = 'Password'; + +$lang->jenkins->lblCreate = 'Create Jenkins Server'; +$lang->jenkins->desc = 'Description'; +$lang->jenkins->tokenFirst = 'Use token if not empty.'; +$lang->jenkins->tips = 'Cancel "Prevent Cross Site Request Forgery exploits" when using password.'; diff --git a/module/gitlab/lang/en.php b/module/gitlab/lang/en.php new file mode 100644 index 0000000000..dd8b436308 --- /dev/null +++ b/module/gitlab/lang/en.php @@ -0,0 +1,22 @@ +jenkins->common = 'Jenkins'; +$lang->jenkins->browse = 'Jenkins'; +$lang->jenkins->create = 'Create Jenkins'; +$lang->jenkins->edit = 'Edit Jenkins'; +$lang->jenkins->delete = 'Delete'; +$lang->jenkins->confirmDelete = 'Do you want to delete this Jenkins server?'; + +$lang->jenkins->browseAction = 'Jenkins List'; +$lang->jenkins->deleteAction = 'Delete Jenkins'; + +$lang->jenkins->id = 'ID'; +$lang->jenkins->name = 'Name'; +$lang->jenkins->url = 'URL'; +$lang->jenkins->token = 'Token'; +$lang->jenkins->account = 'Username'; +$lang->jenkins->password = 'Password'; + +$lang->jenkins->lblCreate = 'Create Jenkins Server'; +$lang->jenkins->desc = 'Description'; +$lang->jenkins->tokenFirst = 'Use token if not empty.'; +$lang->jenkins->tips = 'Cancel "Prevent Cross Site Request Forgery exploits" when using password.'; diff --git a/module/gitlab/lang/fr.php b/module/gitlab/lang/fr.php new file mode 100644 index 0000000000..d3dcf35cbd --- /dev/null +++ b/module/gitlab/lang/fr.php @@ -0,0 +1,20 @@ +jenkins->common = 'Jenkins'; +$lang->jenkins->browse = 'Afficher Jenkins'; +$lang->jenkins->create = 'Cr閑r Jenkins'; +$lang->jenkins->edit = 'Editer Jenkins'; +$lang->jenkins->delete = 'Supprimer'; +$lang->jenkins->confirmDelete = 'Voulez-vous supprimer ce serveur Jenkins ?'; + +$lang->jenkins->id = 'ID'; +$lang->jenkins->name = 'Nom'; +$lang->jenkins->url = 'Service URL'; +$lang->jenkins->token = 'Token'; +$lang->jenkins->account = 'UserName'; +$lang->jenkins->password = 'Password'; + +$lang->jenkins->lblCreate = 'Cr閑r Serveur Jenkins'; +$lang->jenkins->desc = 'Description'; +$lang->jenkins->tokenFirst = 'Utiliser un Token si non vide.'; +$lang->jenkins->tips = 'Cancel "Prevent Cross Site Request Forgery exploits" when using password.'; +$lang->jenkins->tips = "Annuler Emp阠her les exploits de contrefa鏾n de demande intersite lors de l'utilisation du mot de passe."; diff --git a/module/gitlab/lang/vi.php b/module/gitlab/lang/vi.php new file mode 100644 index 0000000000..b5a5f5d46d --- /dev/null +++ b/module/gitlab/lang/vi.php @@ -0,0 +1,19 @@ +jenkins->common = 'Jenkins'; +$lang->jenkins->browse = 'Jenkins'; +$lang->jenkins->create = 'Tạo Jenkins'; +$lang->jenkins->edit = 'Sửa Jenkins'; +$lang->jenkins->delete = 'Xóa'; +$lang->jenkins->confirmDelete = 'Bạn có muốn xóa máy chủ Jenkins này?'; + +$lang->jenkins->id = 'ID'; +$lang->jenkins->name = 'Tên'; +$lang->jenkins->url = 'URL'; +$lang->jenkins->token = 'Token'; +$lang->jenkins->account = 'Người dùng'; +$lang->jenkins->password = 'Mật khẩu'; + +$lang->jenkins->lblCreate = 'Tạo Jenkins Server'; +$lang->jenkins->desc = 'Mô tả'; +$lang->jenkins->tokenFirst = 'Sử dụng token nếu không trống.'; +$lang->jenkins->tips = 'Hủy "Ngăn chặn khai thác yêu cầu trang web giả mạo" khi sử dụng mật khẩu.'; diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php new file mode 100644 index 0000000000..1e64004c55 --- /dev/null +++ b/module/gitlab/lang/zh-cn.php @@ -0,0 +1,22 @@ +gitlab->common = 'gitlab'; +$lang->gitlab->browse = '浏览gitlab'; +$lang->gitlab->create = '添加gitlab'; +$lang->gitlab->edit = '编辑gitlab'; +$lang->gitlab->delete = '删除'; +$lang->gitlab->confirmDelete = '确认删除该gitlab吗?'; + +$lang->gitlab->browseAction = 'gitlab列表'; +$lang->gitlab->deleteAction = '删除gitlab'; + +$lang->gitlab->id = 'ID'; +$lang->gitlab->name = '名称'; +$lang->gitlab->url = '服务地址'; +$lang->gitlab->token = 'Token'; +$lang->gitlab->account = '用户名'; +$lang->gitlab->password = '密码'; + +$lang->gitlab->lblCreate = '添加gitlab服务器'; +$lang->gitlab->desc = '描述'; +$lang->gitlab->tokenFirst = 'Token不为空时,优先使用Token。'; +$lang->gitlab->tips = '使用密码时,请在gitlab全局安全设置中禁用"防止跨站点请求伪造"选项。'; diff --git a/module/gitlab/lang/zh-tw.php b/module/gitlab/lang/zh-tw.php new file mode 100644 index 0000000000..e19ffbbae3 --- /dev/null +++ b/module/gitlab/lang/zh-tw.php @@ -0,0 +1,22 @@ +jenkins->common = 'Jenkins'; +$lang->jenkins->browse = '瀏覽Jenkins'; +$lang->jenkins->create = '添加Jenkins'; +$lang->jenkins->edit = '編輯Jenkins'; +$lang->jenkins->delete = '刪除'; +$lang->jenkins->confirmDelete = '確認刪除該Jenkins嗎?'; + +$lang->jenkins->browseAction = 'Jenkins列表'; +$lang->jenkins->deleteAction = '刪除Jenkins'; + +$lang->jenkins->id = 'ID'; +$lang->jenkins->name = '名稱'; +$lang->jenkins->url = '服務地址'; +$lang->jenkins->token = 'Token'; +$lang->jenkins->account = '用戶名'; +$lang->jenkins->password = '密碼'; + +$lang->jenkins->lblCreate = '添加Jenkins伺服器'; +$lang->jenkins->desc = '描述'; +$lang->jenkins->tokenFirst = 'Token不為空時,優先使用Token。'; +$lang->jenkins->tips = '使用密碼時,請在Jenkins全局安全設置中禁用"防止跨站點請求偽造"選項。'; diff --git a/module/gitlab/model.php b/module/gitlab/model.php new file mode 100644 index 0000000000..f0bc79d668 --- /dev/null +++ b/module/gitlab/model.php @@ -0,0 +1,139 @@ + + * @package product + * @version $Id: $ + * @link http://www.zentao.net + */ + +class gitlabModel extends model +{ + /** + * Get a gitlab by id. + * + * @param int $id + * @access public + * @return object + */ + public function getByID($id) + { + $gitlab = $this->dao->select('*')->from(TABLE_GITLAB)->where('id')->eq($id)->fetch(); + $gitlab->password = base64_decode($gitlab->password); + + return $gitlab; + } + + /** + * Get gitlab list. + * + * @param string $orderBy + * @param object $pager + * @access public + * @return array + */ + public function getList($orderBy = 'id_desc', $pager = null) + { + return $this->dao->select('*')->from(TABLE_GITLAB) + ->where('deleted')->eq('0') + ->orderBy($orderBy) + ->page($pager) + ->fetchAll('id'); + } + + /** + * Get gitlab pairs + * + * @return array + */ + public function getPairs() + { + $gitlab = $this->dao->select('id,name')->from(TABLE_GITLAB) + ->where('deleted')->eq('0') + ->orderBy('id')->fetchPairs('id', 'name'); + $gitlab = array('' => '') + $gitlab; + return $gitlab; + } + + /** + * Get gitlab tasks. + * + * @param int $id + * @access public + * @return array + */ + public function getTasks($id) + { + $gitlab = $this->getById($id); + + $gitlabServer = $gitlab->url; + $gitlabUser = $gitlab->account; + $gitlabPassword = $gitlab->token ? $gitlab->token : $gitlab->password; + + $userPWD = "$gitlabUser:$gitlabPassword"; + $response = common::http($gitlabServer . '/api/json/items/list', '', array(CURLOPT_USERPWD => $userPWD)); + $response = json_decode($response); + + $tasks = array(); + if(isset($response->jobs)) + { + foreach($response->jobs as $job) $tasks[basename($job->url)] = $job->name; + } + return $tasks; + + } + + /** + * Create a gitlab. + * + * @access public + * @return bool + */ + public function create() + { + $gitlab = fixer::input('post') + ->add('createdBy', $this->app->user->account) + ->add('createdDate', helper::now()) + ->skipSpecial('url,token,account,password') + ->get(); + + $gitlab->password = base64_encode($gitlab->password); + + $this->dao->insert(TABLE_GITLAB)->data($gitlab) + ->batchCheck($this->config->gitlab->create->requiredFields, 'notempty') + ->batchCheck("url", 'URL') + ->autoCheck() + ->exec(); + if(dao::isError()) return false; + return $this->dao->lastInsertId(); + } + + /** + * Update a gitlab. + * + * @param int $id + * @access public + * @return bool + */ + public function update($id) + { + $gitlab = fixer::input('post') + ->add('editedBy', $this->app->user->account) + ->add('editedDate', helper::now()) + ->skipSpecial('url,token,account,password') + ->get(); + + $gitlab->password = base64_encode($gitlab->password); + + $this->dao->update(TABLE_GITLAB)->data($gitlab) + ->batchCheck($this->config->gitlab->edit->requiredFields, 'notempty') + ->batchCheck("url", 'URL') + ->autoCheck() + ->where('id')->eq($id) + ->exec(); + return !dao::isError(); + } +} diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php new file mode 100644 index 0000000000..dbda72f37f --- /dev/null +++ b/module/gitlab/view/browse.html.php @@ -0,0 +1,52 @@ + + * @package gitlab + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +