From f61d966f07ba170b93a40a62df7b715cb42ec8ca Mon Sep 17 00:00:00 2001 From: "David.li" <1441836644@qq.com> Date: Mon, 7 Jun 2021 12:03:42 +0800 Subject: [PATCH 001/269] Add Gitlab module. --- config/zentaopms.php | 3 +- module/common/lang/common.php | 3 +- module/common/lang/menu.php | 3 + module/gitlab/config.php | 6 ++ module/gitlab/control.php | 122 +++++++++++++++++++++++++ module/gitlab/lang/de.php | 19 ++++ module/gitlab/lang/en.php | 22 +++++ module/gitlab/lang/fr.php | 20 +++++ module/gitlab/lang/vi.php | 19 ++++ module/gitlab/lang/zh-cn.php | 22 +++++ module/gitlab/lang/zh-tw.php | 22 +++++ module/gitlab/model.php | 139 +++++++++++++++++++++++++++++ module/gitlab/view/browse.html.php | 52 +++++++++++ module/gitlab/view/create.html.php | 58 ++++++++++++ module/gitlab/view/edit.html.php | 58 ++++++++++++ 15 files changed, 566 insertions(+), 2 deletions(-) create mode 100644 module/gitlab/config.php create mode 100644 module/gitlab/control.php create mode 100644 module/gitlab/lang/de.php create mode 100644 module/gitlab/lang/en.php create mode 100644 module/gitlab/lang/fr.php create mode 100644 module/gitlab/lang/vi.php create mode 100644 module/gitlab/lang/zh-cn.php create mode 100644 module/gitlab/lang/zh-tw.php create mode 100644 module/gitlab/model.php create mode 100644 module/gitlab/view/browse.html.php create mode 100644 module/gitlab/view/create.html.php create mode 100644 module/gitlab/view/edit.html.php 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 + */ +?> + + +
+
+ + + + recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}"; ?> + + + + + + + + $gitlab): ?> + + + + + + + + +
gitlab->id); ?>gitlab->name); ?>gitlab->url); ?>actions; ?>
name; ?>url; ?> + createLink('gitlab', 'delete', "gitlabID=$id"), '', 'hiddenwin', "title='{$lang->gitlab->delete}' class='btn'"); + ?> +
+ + + +
+
+ diff --git a/module/gitlab/view/create.html.php b/module/gitlab/view/create.html.php new file mode 100644 index 0000000000..0db7f42698 --- /dev/null +++ b/module/gitlab/view/create.html.php @@ -0,0 +1,58 @@ + + * @package gitlab + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +
+
+
+
+

gitlab->lblCreate;?>

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
gitlab->name; ?>
gitlab->url; ?>
gitlab->account;?>
gitlab->token;?>gitlab->tokenFirst;?>
gitlab->password;?>gitlab->tips;?>
+ + +
+
+
+
+
+ diff --git a/module/gitlab/view/edit.html.php b/module/gitlab/view/edit.html.php new file mode 100644 index 0000000000..74e69b0033 --- /dev/null +++ b/module/gitlab/view/edit.html.php @@ -0,0 +1,58 @@ + + * @package gitlab + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +
+
+
+
+

gitlab->edit; ?>

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
gitlab->name; ?>name, "class='form-control'"); ?>
gitlab->url; ?>url, "class='form-control'"); ?>
gitlab->account;?>account, "class='form-control'");?>
gitlab->token;?>token, "class='form-control'");?>gitlab->tokenFirst;?>
gitlab->password;?>password, "class='form-control'");?>gitlab->tips;?>
+ + +
+
+
+
+
+ From 3716f8568e491f5ddc150c52d1ef3380ca0e9c9e Mon Sep 17 00:00:00 2001 From: Guanxiying Date: Mon, 7 Jun 2021 15:53:43 +0800 Subject: [PATCH 002/269] * Add pipline table. --- config/zentaopms.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config/zentaopms.php b/config/zentaopms.php index 09b2262b4a..b5e0f771de 100644 --- a/config/zentaopms.php +++ b/config/zentaopms.php @@ -179,8 +179,7 @@ define('TABLE_LOG', '`' . $config->db->prefix . 'log`'); define('TABLE_SCORE', '`' . $config->db->prefix . 'score`'); define('TABLE_NOTIFY', '`' . $config->db->prefix . 'notify`'); define('TABLE_OAUTH', '`' . $config->db->prefix . 'oauth`'); -define('TABLE_JENKINS', '`' . $config->db->prefix . 'jenkins`'); -define('TABLE_GITLAB', '`' . $config->db->prefix . 'gitlab`'); +define('TABLE_PIPLINE', '`' . $config->db->prefix . 'jenkins`'); define('TABLE_JOB', '`' . $config->db->prefix . 'job`'); define('TABLE_COMPILE', '`' . $config->db->prefix . 'compile`'); From 6be518e93b2b497bdc1669d2354f4b0d76228eb3 Mon Sep 17 00:00:00 2001 From: "David.li" <1441836644@qq.com> Date: Mon, 7 Jun 2021 16:36:46 +0800 Subject: [PATCH 003/269] * gitlab for upgrade. --- module/common/lang/menu.php | 4 +- module/gitlab/control.php | 24 ++++++++--- module/gitlab/js/create.js | 24 +++++++++++ module/gitlab/lang/zh-cn.php | 8 ++-- module/gitlab/model.php | 67 +++++++++++++----------------- module/gitlab/view/bind.html.php | 49 ++++++++++++++++++++++ module/gitlab/view/browse.html.php | 1 + module/gitlab/view/create.html.php | 9 ---- module/gitlab/view/edit.html.php | 9 ---- 9 files changed, 127 insertions(+), 68 deletions(-) create mode 100644 module/gitlab/js/create.js create mode 100644 module/gitlab/view/bind.html.php diff --git a/module/common/lang/menu.php b/module/common/lang/menu.php index fdb26efab4..dcc63f3625 100644 --- a/module/common/lang/menu.php +++ b/module/common/lang/menu.php @@ -318,14 +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->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[14] = 'gitlab'; $lang->devops->menuOrder[20] = 'maintain'; $lang->devops->menuOrder[25] = 'rules'; diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 69953d6795..f00cc8b081 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -64,6 +64,18 @@ class gitlab extends control $this->display(); } + /** + * bind a gitlab. + * + * @access public + * @return void + */ + public function bind() + { + echo 123;die; + $this->display(); + } + /** * Edit a gitlab. * @@ -106,17 +118,17 @@ class gitlab extends control } /** - * Ajax get tasks. + * Ajax get gitlab token permissions. * - * @param int $id + * @param string $host + * @param string $token * @access public * @return void */ - public function ajaxGetTasks($id) + public function ajaxCheckToken($host, $token) { - if(empty($id)) die(json_encode(array('' => ''))); + $host = helper::safe64Decode($host); + $permissions = $this->gitlab->getPermissionsByToken($host, $token); - $tasks = $this->gitlab->getTasks($id); - die(json_encode($tasks)); } } diff --git a/module/gitlab/js/create.js b/module/gitlab/js/create.js new file mode 100644 index 0000000000..6410b0fdc0 --- /dev/null +++ b/module/gitlab/js/create.js @@ -0,0 +1,24 @@ +$(function () { + $('#token, #url').change(function () { + //取用户名 + var uid = $("#uid").val(); + + //调ajax + $.ajax({ + url: "uidchuli.php", + data: {u: uid}, + type: "POST", + dataType: "TEXT", + success: function (data) { + if (data > 0) { + $("#ts").html("该应户名已存在"); + $("#ts").css("color", "red"); + } else { + $("#ts").html("该应户名可用"); + $("#ts").css("color", "green"); + } + } + + }); + }) +}); diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index 1e64004c55..1a5c554701 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -1,8 +1,9 @@ gitlab->common = 'gitlab'; +$lang->gitlab->common = 'Gitlab'; $lang->gitlab->browse = '浏览gitlab'; $lang->gitlab->create = '添加gitlab'; $lang->gitlab->edit = '编辑gitlab'; +$lang->gitlab->bind = '绑定用户'; $lang->gitlab->delete = '删除'; $lang->gitlab->confirmDelete = '确认删除该gitlab吗?'; @@ -13,10 +14,11 @@ $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全局安全设置中禁用"防止跨站点请求伪造"选项。'; + +/* 交互提示。*/ +$lang->gitlab->tokenPermissions = "当前token非root权限。"; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index f0bc79d668..51d296384a 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -21,7 +21,7 @@ class gitlabModel extends model */ public function getByID($id) { - $gitlab = $this->dao->select('*')->from(TABLE_GITLAB)->where('id')->eq($id)->fetch(); + $gitlab = $this->dao->select('*')->from(TABLE_JENKINS)->where('id')->eq($id)->fetch(); $gitlab->password = base64_decode($gitlab->password); return $gitlab; @@ -37,8 +37,9 @@ class gitlabModel extends model */ public function getList($orderBy = 'id_desc', $pager = null) { - return $this->dao->select('*')->from(TABLE_GITLAB) + return $this->dao->select('*')->from(TABLE_JENKINS) ->where('deleted')->eq('0') + ->andwhere('type')->eq('1') ->orderBy($orderBy) ->page($pager) ->fetchAll('id'); @@ -51,41 +52,13 @@ class gitlabModel extends model */ public function getPairs() { - $gitlab = $this->dao->select('id,name')->from(TABLE_GITLAB) + $gitlab = $this->dao->select('id,name')->from(TABLE_JENKINS) ->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. * @@ -97,12 +70,11 @@ class gitlabModel extends model $gitlab = fixer::input('post') ->add('createdBy', $this->app->user->account) ->add('createdDate', helper::now()) - ->skipSpecial('url,token,account,password') + ->add('type', 1) + ->skipSpecial('url,token') ->get(); - $gitlab->password = base64_encode($gitlab->password); - - $this->dao->insert(TABLE_GITLAB)->data($gitlab) + $this->dao->insert(TABLE_JENKINS)->data($gitlab) ->batchCheck($this->config->gitlab->create->requiredFields, 'notempty') ->batchCheck("url", 'URL') ->autoCheck() @@ -123,12 +95,10 @@ class gitlabModel extends model $gitlab = fixer::input('post') ->add('editedBy', $this->app->user->account) ->add('editedDate', helper::now()) - ->skipSpecial('url,token,account,password') + ->skipSpecial('url,token') ->get(); - $gitlab->password = base64_encode($gitlab->password); - - $this->dao->update(TABLE_GITLAB)->data($gitlab) + $this->dao->update(TABLE_JENKINS)->data($gitlab) ->batchCheck($this->config->gitlab->edit->requiredFields, 'notempty') ->batchCheck("url", 'URL') ->autoCheck() @@ -136,4 +106,23 @@ class gitlabModel extends model ->exec(); return !dao::isError(); } + + /** + * Get gitlab token permissions. + * + * @param string $host + * @param string $token + * @access public + * @return array + */ + public function getPermissionsByToken($host, $token) + { + $host = rtrim($host, '/'); + $host .= '/api/v4/activities'; + + $results = json_decode(file_get_contents($host . "?private_token=$token")); + + return $results; + } + } diff --git a/module/gitlab/view/bind.html.php b/module/gitlab/view/bind.html.php new file mode 100644 index 0000000000..d9af48a455 --- /dev/null +++ b/module/gitlab/view/bind.html.php @@ -0,0 +1,49 @@ + + * @package gitlab + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +
+
+
+
+

gitlab->edit; ?>

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

gitlab->bindUser;?>

+
+
+
+ + + + + + + + + + + + + + + + + + + + + +
gitlab->gitlabAccount;?>gitlab->zentaoAccount;?>
$idPlus'>
+ save);?> + +
+
+
+
+ + + + + diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php index 11df8a7e6e..ede244f79b 100644 --- a/module/gitlab/view/browse.html.php +++ b/module/gitlab/view/browse.html.php @@ -38,7 +38,7 @@ "); common::printIcon('gitlab', 'edit', "gitlabID=$id", '', 'list', 'edit'); - common::printIcon('gitlab', 'bind', "gitlabID=$id", '', 'list', 'group'); + common::printIcon('gitlab', 'binduser', "id=$id", '', 'list', 'group'); if(common::hasPriv('gitlab', 'delete')) echo html::a($this->createLink('gitlab', 'delete', "gitlabID=$id"), '', 'hiddenwin', "title='{$lang->gitlab->delete}' class='btn'"); ?> From 8ff0636eac49fffb05818c112fa3688c298914e1 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 15 Jun 2021 15:27:26 +0800 Subject: [PATCH 038/269] - Remove jmespath. --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ef47b9d7ce..797156678b 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,6 @@ "php": "~5.2||~7.0", "ext-json" : "*", "ext-mbstring" : "*", - "ext-curl" : "*", - "mtdowling/jmespath.php": "2.6.*" + "ext-curl" : "*" } } From 50a934f3c4e918ce0a390ecdd4ed805361763a7e Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 15 Jun 2021 16:36:57 +0800 Subject: [PATCH 039/269] * Adjust display style. --- module/gitlab/control.php | 23 +++++---- module/gitlab/lang/zh-cn.php | 4 +- module/gitlab/model.php | 27 +++------- module/gitlab/view/binduser.html.php | 75 +++++++++------------------- 4 files changed, 48 insertions(+), 81 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index b7ac6fdb0b..52fa0b9749 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -24,8 +24,6 @@ class gitlab extends control */ public function browse($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { - if(common::hasPriv('gitlab', 'create')) $this->lang->TRActions = html::a(helper::createLink('gitlab', 'create'), " " . $this->lang->gitlab->create, '', "class='btn btn-primary'"); - $this->app->loadClass('pager', $static = true); $pager = new pager($recTotal, $recPerPage, $pageID); @@ -50,12 +48,18 @@ class gitlab extends control { if($_POST) { - $tokenValid = $this->gitlab->apiGetCurrentUser($this->post->url, $this->post->token); - if($tokenValid['result'] == 'fail') $this->send($tokenValid); + if(strpos($host, 'http') !== 0) $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)))); + if(!$this->post->token) $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)))); + + $user = $this->gitlab->apiGetCurrentUser($this->post->url, $this->post->token); + + if(!is_object($user)) $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)))); + if(isset($user->is_admin) and $user->is_admin == true) $this->send(array('result' => 'success')); + $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)))); $gitlabID = $this->gitlab->create(); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); - if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $gitlabID)); $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); } @@ -76,10 +80,11 @@ class gitlab extends control public function bindUser($id) { $gitlab = $this->gitlab->getByID($id); - $this->view->title = $this->lang->gitlab->bind; - $this->view->zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account'); - $this->view->gitlabUsers = $this->gitlab->apiGetUsers($gitlab); - $this->view->matchedInfo = $this->gitlab->getMatchedUsers($this->view->gitlabUsers); + $this->view->title = $this->lang->gitlab->bindUser; + $zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account'); + $this->view->userPairs = $this->loadModel('user')->getPairs(); + $this->view->gitlabUsers = $this->gitlab->apiGetUsers($gitlab); + $this->view->matchedResult = $this->gitlab->getMatchedUsers($this->view->gitlabUsers, $zentaoUsers); $this->display(); } diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index dcd874762b..4389a02c38 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -4,9 +4,11 @@ $lang->gitlab->common = 'Gitlab'; $lang->gitlab->browse = '浏览gitlab'; $lang->gitlab->create = '添加gitlab'; $lang->gitlab->edit = '编辑gitlab'; -$lang->gitlab->bind = '绑定用户'; +$lang->gitlab->bindUser = '绑定用户'; $lang->gitlab->delete = '删除'; $lang->gitlab->confirmDelete = '确认删除该gitlab吗?'; +$lang->gitlab->gitlabAccount = 'gitlab用户'; +$lang->gitlab->zentaoAccount = '禅道用户'; $lang->gitlab->browseAction = 'gitlab列表'; $lang->gitlab->deleteAction = '删除gitlab'; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 5b0b7cfbe7..e2280be116 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -80,14 +80,8 @@ class gitlabModel extends model */ public function apiGetCurrentUser($host, $token) { - if(strpos($host, 'http') !== 0) return array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError))); - if(!$this->post->token) return array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError))); $api = rtrim($host, '/') . "/api/v4/user?private_token=$token"; - $response = json_decode(commonModel::http($api)); - - if(!is_object($response)) return array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError))); - if(isset($response->is_admin) and $response->is_admin == true) return array('result' => 'success'); - return array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError))); + return json_decode(commonModel::http($api)); } /** @@ -114,17 +108,15 @@ class gitlabModel extends model $user->realname = $gitlabUser->name; $user->account = $gitlabUser->username; $user->email = $gitlabUser->email; + $user->avatar = $gitlabUser->avatar_url; $users[] = $user; } - a($users); return $users; } - public function getMatchedUsers($gitlabUsers) + public function getMatchedUsers($gitlabUsers, $zentaoUsers) { - $zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account'); - $matches = new stdclass; foreach($gitlabUsers as $gitlabUser) { @@ -136,7 +128,8 @@ class gitlabModel extends model } } - foreach($gitlabUser as $gitlabUser) + $matchedUsers = array(); + foreach($gitlabUsers as $gitlabUser) { $matchedZentaoUsers = array(); if(isset($matches->accounts[$gitlabUser->account])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->accounts[$gitlabUser->account]); @@ -146,15 +139,11 @@ class gitlabModel extends model $matchedZentaoUsers = array_unique($matchedZentaoUsers); if(count($matchedZentaoUsers) == 1) { - $matchedUsers[$gitlabUser->id] = current($matchedZentaoUsers); - } - else - { - $unmatchedUsers[$gitlabUser->id] = $gitlabUser; + $gitlabUser->zentaoAccount = current($matchedZentaoUsers); + $matchedUsers[] = $gitlabUser; } } - - return array('matched' => $matchedUsers, 'unmatched' => $unmatchedUsers); + return $matchedUsers; } /** diff --git a/module/gitlab/view/binduser.html.php b/module/gitlab/view/binduser.html.php index dbf69d2414..2618efc9cf 100644 --- a/module/gitlab/view/binduser.html.php +++ b/module/gitlab/view/binduser.html.php @@ -17,20 +17,35 @@
- +
- - + + - - - - + zentaoAccount)) continue;?> + + + + + + + zentaoAccount)) continue;?> + + + @@ -46,48 +61,4 @@ - - - - From a17f6627fee611e3b21254512b23ecbd156c1c98 Mon Sep 17 00:00:00 2001 From: Guanxiying Date: Tue, 15 Jun 2021 16:58:19 +0800 Subject: [PATCH 040/269] * Adjust style of gitlab avatar. --- module/gitlab/view/binduser.html.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/module/gitlab/view/binduser.html.php b/module/gitlab/view/binduser.html.php index 2618efc9cf..9eb34410a2 100644 --- a/module/gitlab/view/binduser.html.php +++ b/module/gitlab/view/binduser.html.php @@ -17,41 +17,40 @@
-
gitlab->gitlabAccount;?>gitlab->zentaoAccount;?>gitlab->gitlabAccount;?>gitlab->zentaoAccount;?>
$idPlus'>
+ avatar, "height=40");?> + + id) . $gitlabUser->realname;?> +
account . ") <" . $gitlabUser->email . ">"; ?> +
+
+ id) . $gitlabUser->realname;?> +

account . ") <" . $gitlabUser->email . ">"; ?>

+
zentaoAccount, "class='form-control select chosen'" );?>
+
- - + + zentaoAccount)) continue;?> - + - + zentaoAccount)) continue;?> + - + - From 742f61ce6cf2fdab6652c1e7c69a4476cac3ca96 Mon Sep 17 00:00:00 2001 From: Guanxiying Date: Tue, 15 Jun 2021 16:59:43 +0800 Subject: [PATCH 041/269] * Format code. --- module/gitlab/control.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 52fa0b9749..1df27782eb 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -79,9 +79,15 @@ class gitlab extends control */ public function bindUser($id) { - $gitlab = $this->gitlab->getByID($id); - $this->view->title = $this->lang->gitlab->bindUser; + if($_POST) + { + + } + + $gitlab = $this->gitlab->getByID($id); $zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account'); + + $this->view->title = $this->lang->gitlab->bindUser; $this->view->userPairs = $this->loadModel('user')->getPairs(); $this->view->gitlabUsers = $this->gitlab->apiGetUsers($gitlab); $this->view->matchedResult = $this->gitlab->getMatchedUsers($this->view->gitlabUsers, $zentaoUsers); From 78151f19e1b22ac260044456a903974c1a824777 Mon Sep 17 00:00:00 2001 From: Guanxiying Date: Tue, 15 Jun 2021 17:25:50 +0800 Subject: [PATCH 042/269] * Format codes. --- module/gitlab/model.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index e2280be116..0068f76078 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -115,6 +115,14 @@ class gitlabModel extends model return $users; } + /** + * Get matched gitlab users. + * + * @param array $gitlabUsers + * @param array $zentaoUsers + * @access public + * @return array + */ public function getMatchedUsers($gitlabUsers, $zentaoUsers) { $matches = new stdclass; @@ -143,6 +151,7 @@ class gitlabModel extends model $matchedUsers[] = $gitlabUser; } } + return $matchedUsers; } @@ -214,5 +223,14 @@ class gitlabModel extends model { return; } + + public function pushTask($task, $gitlab) + { + + } + public function pushBug($task, $gitlab) + { + + } } From cf22c9e6b3c451ad78182ecb90b139bf38094f39 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 16 Jun 2021 12:53:21 +0800 Subject: [PATCH 043/269] * Add funcs for webhooks. --- module/gitlab/control.php | 7 +++++++ module/gitlab/model.php | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 1df27782eb..0310f78c5c 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -152,4 +152,11 @@ class gitlab extends control $permissions = $this->gitlab->apiGetCurrentUser($host, $token); $this->send($permissions); } + + public function createHook($gitlab_id, $project_id, $url, $token) + { + $res = $this->gitlab->apiCreateHook($gitlab_id, $project_id, $url, $token); + return $res; + } + } diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 0068f76078..adbb3226a5 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -194,34 +194,52 @@ class gitlabModel extends model return $gitlab_url; } - public function apiGetHooks($gitlab_id, $project_id) { - $host = $this->getApiRoot($gitlab_id); - $api_path = sprintf('/projects/%s/hooks', $project_id); - $host = sprintf($host, $api_path); - $api_json = commonModel::http($host); + $api_root = $this->getApiRoot($gitlab_id); + $api_path = "/projects/{$project_id}/hooks"; + $url = sprintf($api_root, $api_path); + $api_json = commonModel::http($url); return $api_json; } - public function apiGetHook($gitlab_id, $project_id, $hook_id) + public function apiGetHook($gitlab_id, $project_id, $hook_id) { + $api_root = $this->getApiRoot($gitlab_id); + $api_path = "/projects/$project_id/hooks/$hook_id)"; + $url = sprintf($api_root, $api_path); + $api_json = commonModel::http($url); return; } public function apiCreateHook($gitlab_id, $project_id, $url, $token) - { - return; + { + $api_root = $this->getApiRoot($gitlab_id); + $args = "&enable_ssl_verification=false&issues_events=true&merge_requests_events=true&push_events=true&tag_push_events=true&url={$url}&token={$token}"; + $api_path = "/projects/{$project_id}/hooks"; + $url = sprintf($api_root, $api_path) . $args; + $api_json = commonModel::http($url,"options=array('CURLOPT_CUSTOMREQUEST'=>'post')"); + return $api_json; + } public function apiDeleteHook($gitlab_id, $project_id, $hook_id) { - return; + $api_root = $this->getApiRoot($gitlab_id); + $api_path = "/projects/{$project_id}/hooks/{$hook_id}"; + $url = sprintf($api_root, $api_path); + $api_json = commonModel::http($url,"options=array('CURLOPT_CUSTOMREQUEST'=>'delete')"); + return $api_json; } public function apiUpdateHook($gitlab_id, $project_id, $hook_id) { - return; + $api_root = $this->getApiRoot($gitlab_id); + $args = "&enable_ssl_verification=false&issues_events=true&merge_requests_events=true&push_events=true&tag_push_events=true&url={$url}&token={$token}"; + $api_path = "/projects/{$project_id}/hooks/{$hook_id}"; + $url = sprintf($api_root, $api_path) . $args; + $api_json = commonModel::http($url,"options=array('CURLOPT_CUSTOMREQUEST'=>'put')"); + return $api_json; } public function pushTask($task, $gitlab) From ef3a445ff0ba76ffa48010a6b6bca3bc0819fca3 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 16 Jun 2021 13:16:17 +0800 Subject: [PATCH 044/269] * Change snake name to camel name. --- module/gitlab/model.php | 107 ++++++++++++++++++++++++++++------------ 1 file changed, 76 insertions(+), 31 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index adbb3226a5..d59d760e5b 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -194,60 +194,105 @@ class gitlabModel extends model return $gitlab_url; } - public function apiGetHooks($gitlab_id, $project_id) + /** + * Get hooks. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ + public function apiGetHooks($gitlabID, $projectID) { - $api_root = $this->getApiRoot($gitlab_id); - $api_path = "/projects/{$project_id}/hooks"; - $url = sprintf($api_root, $api_path); - $api_json = commonModel::http($url); - return $api_json; + $apiRoot = $this->getApiRoot($gitlabID); + $apiPath = "/projects/{$projectID}/hooks"; + $url = sprintf($apiRoot, $apiPath); + $apiJsonRes = commonModel::http($url); + return $apiJsonRes; } - public function apiGetHook($gitlab_id, $project_id, $hook_id) + /** + * Get specific hook. + * + * @param int $gitlabID + * @param int $projectID + * @param int $hookID + * @access public + * @return void + */ + public function apiGetHook($gitlabID, $projectID, $hookID) { - $api_root = $this->getApiRoot($gitlab_id); - $api_path = "/projects/$project_id/hooks/$hook_id)"; - $url = sprintf($api_root, $api_path); - $api_json = commonModel::http($url); + $apiRoot = $this->getApiRoot($gitlabID); + $apiPath = "/projects/$projectID/hooks/$hookID)"; + $url = sprintf($apiRoot, $apiPath); + $apiJsonRes = commonModel::http($url); return; } - public function apiCreateHook($gitlab_id, $project_id, $url, $token) + /** + * Create hook. + * + * @param int $gitlabID + * @param int $projectID + * @param int $url + * @param int $token + * @access public + * @return void + */ + public function apiCreateHook($gitlabID, $projectID, $url, $token) { - $api_root = $this->getApiRoot($gitlab_id); + $apiRoot = $this->getApiRoot($gitlabID); $args = "&enable_ssl_verification=false&issues_events=true&merge_requests_events=true&push_events=true&tag_push_events=true&url={$url}&token={$token}"; - $api_path = "/projects/{$project_id}/hooks"; - $url = sprintf($api_root, $api_path) . $args; - $api_json = commonModel::http($url,"options=array('CURLOPT_CUSTOMREQUEST'=>'post')"); - return $api_json; + $apiPath = "/projects/{$projectID}/hooks"; + $url = sprintf($apiRoot, $apiPath) . $args; + $apiJsonRes = commonModel::http($url,"options=array('CURLOPT_CUSTOMREQUEST'=>'post')"); + return $apiJsonRes; } - public function apiDeleteHook($gitlab_id, $project_id, $hook_id) + /** + * Delete hook. + * + * @param int $gitlabID + * @param int $projectID + * @param int $hookID + * @access public + * @return void + */ + public function apiDeleteHook($gitlabID, $projectID, $hookID) { - $api_root = $this->getApiRoot($gitlab_id); - $api_path = "/projects/{$project_id}/hooks/{$hook_id}"; - $url = sprintf($api_root, $api_path); - $api_json = commonModel::http($url,"options=array('CURLOPT_CUSTOMREQUEST'=>'delete')"); - return $api_json; + $apiRoot = $this->getApiRoot($gitlabID); + $apiPath = "/projects/{$projectID}/hooks/{$hookID}"; + $url = sprintf($apiRoot, $apiPath); + $apiJsonRes = commonModel::http($url,"options=array('CURLOPT_CUSTOMREQUEST'=>'delete')"); + return $apiJsonRes; } - public function apiUpdateHook($gitlab_id, $project_id, $hook_id) + /** + * Update hook. + * + * @param int $gitlabID + * @param int $projectID + * @param int $hookID + * @access public + * @return void + */ + public function apiUpdateHook($gitlabID, $projectID, $hookID) { - $api_root = $this->getApiRoot($gitlab_id); + $apiRoot = $this->getApiRoot($gitlabID); $args = "&enable_ssl_verification=false&issues_events=true&merge_requests_events=true&push_events=true&tag_push_events=true&url={$url}&token={$token}"; - $api_path = "/projects/{$project_id}/hooks/{$hook_id}"; - $url = sprintf($api_root, $api_path) . $args; - $api_json = commonModel::http($url,"options=array('CURLOPT_CUSTOMREQUEST'=>'put')"); - return $api_json; + $apiPath = "/projects/{$projectID}/hooks/{$hookID}"; + $url = sprintf($apiRoot, $apiPath) . $args; + $apiJsonRes = commonModel::http($url,"options=array('CURLOPT_CUSTOMREQUEST'=>'put')"); + return $apiJsonRes; } - public function pushTask($task, $gitlab) + public function pushTask($task, $gitlabID,$projectID) { } - public function pushBug($task, $gitlab) + public function pushBug($bug, $gitlabID,$projectID) { } From 26315605a27827a8d3f900d7c5f2ea1d7974a9c4 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 16 Jun 2021 13:30:56 +0800 Subject: [PATCH 045/269] * Rename funcs on need. --- module/repo/control.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/repo/control.php b/module/repo/control.php index fb0183ddeb..c963af340f 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -169,7 +169,7 @@ class repo extends control if($repo->SCM == 'Gitlab') { - $projects = $this->loadModel('gitlab')->getProjectsByID($repo->client, $repo->password); + $projects = $this->loadModel('gitlab')->apiGetProjects($repo->client, $repo->password); $options = array(); foreach($projects as $project) $options[$project->id] = $project->name . ':' . $project->http_url_to_repo; @@ -1115,7 +1115,7 @@ class repo extends control */ public function ajaxGetGitlabProjects($host) { - $projects = $this->loadModel('gitlab')->getProjectsByID($host); + $projects = $this->loadModel('gitlab')->apiGetProjects($host); if(!$projects) $this->send(array('message' => array())); From 65a6b38fae1d68cfd44679d457cdaa874e9e48eb Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 16 Jun 2021 17:34:44 +0800 Subject: [PATCH 046/269] + Create labels when gitlab server added successfully. --- module/common/model.php | 3 +- module/gitlab/model.php | 95 ++++++++++++++++++++++++++++++++++++--- module/pipeline/model.php | 6 +++ module/repo/model.php | 7 ++- 4 files changed, 102 insertions(+), 9 deletions(-) diff --git a/module/common/model.php b/module/common/model.php index 31181f9425..7e872be987 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -2236,10 +2236,11 @@ EOD; if(!empty($data)) { + if(is_object($data)) $data = (array) $data; curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } - + if($options) curl_setopt_array($curl, $options); $response = curl_exec($curl); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index d59d760e5b..c0619ce7f3 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -242,10 +242,19 @@ class gitlabModel extends model public function apiCreateHook($gitlabID, $projectID, $url, $token) { $apiRoot = $this->getApiRoot($gitlabID); - $args = "&enable_ssl_verification=false&issues_events=true&merge_requests_events=true&push_events=true&tag_push_events=true&url={$url}&token={$token}"; + + $postData = new stdclass; + $postData->enable_ssl_verification = "false"; + $postData->issues_events = "true"; + $postData->merge_requests_events = "true"; + $postData->push_events = "true"; + $postData->tag_push_events = "true"; + $postData->url = $url; + $postData->token = $token; + $apiPath = "/projects/{$projectID}/hooks"; - $url = sprintf($apiRoot, $apiPath) . $args; - $apiJsonRes = commonModel::http($url,"options=array('CURLOPT_CUSTOMREQUEST'=>'post')"); + $url = sprintf($apiRoot, $apiPath); + $apiJsonRes = commonModel::http($url, $postData); return $apiJsonRes; } @@ -264,7 +273,7 @@ class gitlabModel extends model $apiRoot = $this->getApiRoot($gitlabID); $apiPath = "/projects/{$projectID}/hooks/{$hookID}"; $url = sprintf($apiRoot, $apiPath); - $apiJsonRes = commonModel::http($url,"options=array('CURLOPT_CUSTOMREQUEST'=>'delete')"); + $apiJsonRes = commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'delete')); return $apiJsonRes; } @@ -280,13 +289,85 @@ class gitlabModel extends model public function apiUpdateHook($gitlabID, $projectID, $hookID) { $apiRoot = $this->getApiRoot($gitlabID); - $args = "&enable_ssl_verification=false&issues_events=true&merge_requests_events=true&push_events=true&tag_push_events=true&url={$url}&token={$token}"; + + $postData = new stdclass; + $postData->enable_ssl_verification = "false"; + $postData->issues_events = "true"; + $postData->merge_requests_events = "true"; + $postData->push_events = "true"; + $postData->tag_push_events = "true"; + $postData->url = $url; + $postData->token = $token; + $apiPath = "/projects/{$projectID}/hooks/{$hookID}"; - $url = sprintf($apiRoot, $apiPath) . $args; - $apiJsonRes = commonModel::http($url,"options=array('CURLOPT_CUSTOMREQUEST'=>'put')"); + $url = sprintf($apiRoot, $apiPath); + $apiJsonRes = commonModel::http($url, $postData, $options = array(CURLOPT_CUSTOMREQUEST => 'put')); return $apiJsonRes; } + + public function apiCreateLabel($gitlabID, $projectID, $label) + { + $apiRoot = $this->getApiRoot($gitlabID); + + if(empty($label->name) or empty($label->color)) return false; + + $apiPath = "/projects/{$projectID}/labels/"; + $url = sprintf($apiRoot, $apiPath); + $response = commonModel::http($url, $label); + return $response; + } + + public function apiGetLabels($gitlabID, $projectID) + { + $apiRoot = $this->getApiRoot($gitlabID); + $apiPath = "/projects/{$projectID}/labels/"; + $url = sprintf($apiRoot, $apiPath); + $response = commonModel::http($url); + $labels = json_decode($response); + return $labels; + } + + public function isLabelExists($gitlabID, $projectID) + { + $labels = $this->apiGetLabels($gitlabID, $projectID); + foreach($labels as $label) + { + if(strpos($label->title, "zentao task") == 0) return true; + } + + return false; + + } + + public function initLabels($gitlabID, $projectID) + { + if($this->isLabelExists($gitlabID, $projectID)) return true; + + $taskLabel = new stdclass(); + $taskLabel->name = "zentao task"; + $taskLabel->description = "task label from zentao"; + $taskLabel->color = "#0033CC"; + $taskLabel->priority = "0"; + + $bugLabel = new stdclass(); + $bugLabel->name = "zentao bug"; + $bugLabel->description = "bug label from zentao"; + $bugLabel->color = "#D10069"; + $bugLabel->priority = "0"; + + $this->apiCreateLabel($gitlabID, $projectID, $taskLabel); + $this->apiCreateLabel($gitlabID, $projectID, $bugLabel); + + return; + } + + public function apiCreateIssue($gitlabID, $projectID) + { + + } + + public function pushTask($task, $gitlabID,$projectID) { diff --git a/module/pipeline/model.php b/module/pipeline/model.php index 7a2d669a1f..67f562cdc6 100644 --- a/module/pipeline/model.php +++ b/module/pipeline/model.php @@ -87,6 +87,9 @@ class pipelineModel extends model ->autoCheck() ->exec(); if(dao::isError()) return false; + + $this->loadModel("gitlab")->initLabels($this->post->gitlabID, $this->post->projectID); + return $this->dao->lastInsertId(); } @@ -115,6 +118,9 @@ class pipelineModel extends model ->autoCheck() ->where('id')->eq($id) ->exec(); + + if(!dao::isError()) $this->loadModel("gitlab")->initLabels($this->post->gitlabID, $this->post->projectID); + return !dao::isError(); } } diff --git a/module/repo/model.php b/module/repo/model.php index 32feb9147a..1d50f2efbf 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -229,6 +229,8 @@ class repoModel extends model if(!dao::isError()) $this->rmClientVersionFile(); + if($this->post->SCM == 'Gitlab') $this->loadModel("gitlab")->initLabels($this->post->gitlabHost, $this->post->gitlabProject); + return $this->dao->lastInsertID(); } @@ -274,6 +276,7 @@ class repoModel extends model if($data->client != $repo->client and !$this->checkClient()) return false; if(!$this->checkConnection()) return false; + if($data->encrypt == 'base64') $data->password = base64_encode($data->password); $this->dao->update(TABLE_REPO)->data($data, $skip = 'gitlabHost,gitlabToken,gitlabProject') ->batchCheck($this->config->repo->edit->requiredFields, 'notempty') @@ -288,8 +291,10 @@ class repoModel extends model { $this->dao->delete()->from(TABLE_REPOHISTORY)->where('repo')->eq($id)->exec(); $this->dao->delete()->from(TABLE_REPOFILES)->where('repo')->eq($id)->exec(); - return false; + if($repo->SCM == 'Gitlab') $this->loadModel("gitlab")->initLabels($this->post->gitlabHost, $this->post->gitlabProject); + return false; } + return true; } From 829e5eaa5c9667002556dc387b351690238ea289 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 16 Jun 2021 18:37:13 +0800 Subject: [PATCH 047/269] * Rename some variables and add docs. --- module/gitlab/model.php | 54 +++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index c0619ce7f3..803f950361 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -207,8 +207,8 @@ class gitlabModel extends model $apiRoot = $this->getApiRoot($gitlabID); $apiPath = "/projects/{$projectID}/hooks"; $url = sprintf($apiRoot, $apiPath); - $apiJsonRes = commonModel::http($url); - return $apiJsonRes; + $response = commonModel::http($url); + return $response; } /** @@ -225,7 +225,7 @@ class gitlabModel extends model $apiRoot = $this->getApiRoot($gitlabID); $apiPath = "/projects/$projectID/hooks/$hookID)"; $url = sprintf($apiRoot, $apiPath); - $apiJsonRes = commonModel::http($url); + $response = commonModel::http($url); return; } @@ -254,8 +254,8 @@ class gitlabModel extends model $apiPath = "/projects/{$projectID}/hooks"; $url = sprintf($apiRoot, $apiPath); - $apiJsonRes = commonModel::http($url, $postData); - return $apiJsonRes; + $response = commonModel::http($url, $postData); + return $response; } @@ -273,8 +273,8 @@ class gitlabModel extends model $apiRoot = $this->getApiRoot($gitlabID); $apiPath = "/projects/{$projectID}/hooks/{$hookID}"; $url = sprintf($apiRoot, $apiPath); - $apiJsonRes = commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'delete')); - return $apiJsonRes; + $response = commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'delete')); + return $response; } /** @@ -301,10 +301,19 @@ class gitlabModel extends model $apiPath = "/projects/{$projectID}/hooks/{$hookID}"; $url = sprintf($apiRoot, $apiPath); - $apiJsonRes = commonModel::http($url, $postData, $options = array(CURLOPT_CUSTOMREQUEST => 'put')); - return $apiJsonRes; + $response = commonModel::http($url, $postData, $options = array(CURLOPT_CUSTOMREQUEST => 'put')); + return $response; } + /** + * Create Label for gitlab project. + * + * @param int $gitlabID + * @param int $projectID + * @param int $label + * @access public + * @return void + */ public function apiCreateLabel($gitlabID, $projectID, $label) { $apiRoot = $this->getApiRoot($gitlabID); @@ -317,6 +326,14 @@ class gitlabModel extends model return $response; } + /** + * Get labels of project. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ public function apiGetLabels($gitlabID, $projectID) { $apiRoot = $this->getApiRoot($gitlabID); @@ -327,12 +344,21 @@ class gitlabModel extends model return $labels; } + /** + * Check if predefined label exist in project. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ public function isLabelExists($gitlabID, $projectID) { $labels = $this->apiGetLabels($gitlabID, $projectID); foreach($labels as $label) { - if(strpos($label->title, "zentao task") == 0) return true; + if(strpos($label->name, "zentao task") == 0) return true; + if(strpos($label->name, "zentao bug") == 0) return true; } return false; @@ -340,6 +366,14 @@ class gitlabModel extends model } + /** + * Create predefined labels for project. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ public function initLabels($gitlabID, $projectID) { if($this->isLabelExists($gitlabID, $projectID)) return true; From d8a99bcf9e97ace029c3c9c7f843218c68b61b8d Mon Sep 17 00:00:00 2001 From: Guanxiying Date: Wed, 16 Jun 2021 19:45:23 +0800 Subject: [PATCH 048/269] * Process gitlab id and gitlab project of one repo. --- module/repo/control.php | 6 +++--- module/repo/model.php | 2 ++ module/repo/view/edit.html.php | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/module/repo/control.php b/module/repo/control.php index c963af340f..b759f05aeb 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -169,10 +169,10 @@ class repo extends control if($repo->SCM == 'Gitlab') { - $projects = $this->loadModel('gitlab')->apiGetProjects($repo->client, $repo->password); + $projects = $this->loadModel('gitlab')->apiGetProjects($repo->gitlab, $repo->password); $options = array(); - foreach($projects as $project) $options[$project->id] = $project->name . ':' . $project->http_url_to_repo; + foreach($projects as $project) $options[$project->id] = $project->name_with_namespace; $this->view->projects = $options; } @@ -1122,7 +1122,7 @@ class repo extends control $options = ""; foreach($projects as $project) { - $options .= ""; + $options .= ""; } die($options); } diff --git a/module/repo/model.php b/module/repo/model.php index 32feb9147a..e1c1176f91 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -1760,6 +1760,8 @@ class repoModel extends model { $gitlab = $this->loadModel('gitlab')->getByID($repo->client); if(!$gitlab) return $repo; + $repo->gitlab = $gitlab->id; + $repo->project = $repo->path; $repo->path = sprintf($this->config->repo->gitlab->apiPath, $gitlab->url, $repo->path); $repo->client = $gitlab->url; $repo->password = $gitlab->token; diff --git a/module/repo/view/edit.html.php b/module/repo/view/edit.html.php index f2352a2338..cda78336be 100644 --- a/module/repo/view/edit.html.php +++ b/module/repo/view/edit.html.php @@ -38,11 +38,11 @@ - - From eb59efcbcae28c10abc9eab71ca23a583305722d Mon Sep 17 00:00:00 2001 From: Guanxiying Date: Wed, 16 Jun 2021 19:46:30 +0800 Subject: [PATCH 049/269] * Fix get commits function. --- lib/scm/gitlab.class.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/scm/gitlab.class.php b/lib/scm/gitlab.class.php index e825ba7d04..7a5636101c 100644 --- a/lib/scm/gitlab.class.php +++ b/lib/scm/gitlab.class.php @@ -498,12 +498,11 @@ class gitlab if(!scm::checkRevision($version)) return array(); $api = "commits"; - if(empty($count)) $count = 100; + if(empty($count)) $count = 1; $params = array(); $params['ref_name'] = $branch; - $params['per_page'] = $count; + $params['per_page'] = 11; $params['all'] = 1; - if($version and $version != 'HEAD') { $lastCommit = $this->getSingleCommit($version); @@ -594,13 +593,15 @@ class gitlab $api = "commits/{$revision}/diff"; $params = new stdclass; $params->page = 1; - $params->per_page = 200; + $params->per_page = 100; $allResults = array(); - while($results = $this->fetch($api, $params)) + while(true) { + $results = $this->fetch($api, $params); $params->page ++; $allResults = $allResults + $results; + if(count($results) < 100) break; } $files = array(); From 9c3c8022c9d6e7a82f98531aff677a21c766cf5c Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 16 Jun 2021 20:04:47 +0800 Subject: [PATCH 050/269] * Put name used frequently into config. --- module/gitlab/config.php | 15 +++++++++++++++ module/gitlab/model.php | 31 ++++++++++++++++++------------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 3a840d46db..6f7828f459 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -4,3 +4,18 @@ $config->gitlab->edit = new stdclass(); $config->gitlab->create->requiredFields = 'name,url,token'; $config->gitlab->edit->requiredFields = 'name,url,token'; + +$config->gitlab->taskLabel = new stdclass(); +$config->gitlab->taskLabel->name = "zentao task"; +$config->gitlab->taskLabel->description = "task label from zentao"; +$config->gitlab->taskLabel->color = "#0033CC"; +$config->gitlab->taskLabel->priority = "0"; + +$config->gitlab->bugLabel = new stdclass(); +$config->gitlab->bugLabel->name = "zentao bug"; +$config->gitlab->bugLabel->description = "bug label from zentao"; +$config->gitlab->bugLabel->color = "#D10069"; +$config->gitlab->bugLabel->priority = "0"; + + + diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 803f950361..0e22c70fef 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -357,8 +357,8 @@ class gitlabModel extends model $labels = $this->apiGetLabels($gitlabID, $projectID); foreach($labels as $label) { - if(strpos($label->name, "zentao task") == 0) return true; - if(strpos($label->name, "zentao bug") == 0) return true; + if(strpos($label->name, $this->config->gitlab->taskLabel->name) == 0) return true; + if(strpos($label->name, $this->config->gitlab->bugLabel->name) == 0) return true; } return false; @@ -379,16 +379,16 @@ class gitlabModel extends model if($this->isLabelExists($gitlabID, $projectID)) return true; $taskLabel = new stdclass(); - $taskLabel->name = "zentao task"; - $taskLabel->description = "task label from zentao"; - $taskLabel->color = "#0033CC"; - $taskLabel->priority = "0"; + $taskLabel->name = $this->config->gitlab->taskLabel->name; + $taskLabel->description = $this->config->gitlab->taskLabel->description; + $taskLabel->color = $this->config->gitlab->taskLabel->color; + $taskLabel->priority = $this->config->gitlab->taskLabel->priority; $bugLabel = new stdclass(); - $bugLabel->name = "zentao bug"; - $bugLabel->description = "bug label from zentao"; - $bugLabel->color = "#D10069"; - $bugLabel->priority = "0"; + $bugLabel->name = $this->config->gitlab->bugLabel->name; + $bugLabel->description = $this->config->gitlab->bugLabel->description; + $bugLabel->color = $this->config->gitlab->bugLabel->color; + $bugLabel->priority = $this->config->gitlab->bugLabel->priority; $this->apiCreateLabel($gitlabID, $projectID, $taskLabel); $this->apiCreateLabel($gitlabID, $projectID, $bugLabel); @@ -396,15 +396,20 @@ class gitlabModel extends model return; } - public function apiCreateIssue($gitlabID, $projectID) + public function apiCreateIssue($gitlabID, $projectID, $issue) { + $apiRoot = $this->getApiRoot($gitlabID); + $apiPath = "/projects/{$projectID}/issues/"; + $url = sprintf($apiRoot, $apiPath); + $response = commonModel::http($url, $issue); + $labels = json_decode($response); + return $labels; } - public function pushTask($task, $gitlabID,$projectID) { - + } public function pushBug($bug, $gitlabID,$projectID) From 06c6deb1ea166cd8daccb5ed004b5a8b865c6da2 Mon Sep 17 00:00:00 2001 From: z Date: Thu, 17 Jun 2021 10:12:24 +0800 Subject: [PATCH 051/269] * Adjust code. --- module/gitlab/control.php | 26 ++++++++++++++++++++++++++ module/gitlab/model.php | 15 ++++++++++++++- module/gitlab/view/binduser.html.php | 2 +- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 0310f78c5c..e82e3a6089 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -81,7 +81,33 @@ class gitlab extends control { if($_POST) { + if($this->post->zentaoUsers) + { + $data = array(); + $number = 0; + foreach($this->post->zentaoUsers as $gitlabId => $account) + { + if($account) + { + $data[$number]['openID'] = $gitlabId; + $data[$number]['account'] = $account; + $data[$number]['providerType'] = 'gitlab'; + $data[$number]['providerID'] = $id; + $number++; + } + } + } + foreach($data as $bindUser) + { + if(!$this->gitlab->checkAccountId($bindUser['openID'],$bindUser['providerID'])) + { + $this->dao->insert(TABLE_OAUTH)->data($bindUser)->exec(); + }else + { + $this->dao->update(TABLE_OAUTH)->data($bindUser)->where('openID')->eq($bindUser['openID'])->andWhere('providerID')->eq($bindUser['providerID'])->exec(); + } + } } $gitlab = $this->gitlab->getByID($id); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 0e22c70fef..72d4cfcbae 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -97,7 +97,7 @@ class gitlabModel extends model { $api = rtrim($gitlab->url, '/') . '/api/v4/users?private_token=' . $gitlab->token; $response = json_decode(commonModel::http($api)); - + if (!$response) return array(); $users = array(); @@ -194,6 +194,19 @@ class gitlabModel extends model return $gitlab_url; } + + /** + * check if gitlab id exists + * + * @param string + * @access public + * @return array + */ + public function checkAccountId($openID,$providerID) + { + return $this->dao->select('openID')->from(TABLE_OAUTH)->where('openID')->eq($openID)->andWhere('providerID')->eq($providerID)->fetch('openID'); + } + /** * Get hooks. * diff --git a/module/gitlab/view/binduser.html.php b/module/gitlab/view/binduser.html.php index 9eb34410a2..380a0550c6 100644 --- a/module/gitlab/view/binduser.html.php +++ b/module/gitlab/view/binduser.html.php @@ -15,7 +15,7 @@

gitlab->bindUser;?>

- +
gitlab->gitlabAccount;?>gitlab->zentaoAccount;?>gitlab->gitlabAccount;?>gitlab->zentaoAccount;?>
- avatar, "height=40");?> - - id) . $gitlabUser->realname;?> -
account . ") <" . $gitlabUser->email . ">"; ?> -
+
avatar, "height=40");?> + realname;?> +
account . " <" . $gitlabUser->email . ">"; ?>
id]", $userPairs, '', "class='form-control select chosen'" );?>
avatar, "height=40");?> - id) . $gitlabUser->realname;?> -

account . ") <" . $gitlabUser->email . ">"; ?>

+ realname;?> +
account . " <" . $gitlabUser->email . ">";?>
zentaoAccount, "class='form-control select chosen'" );?>id]", $userPairs, $gitlabUser->zentaoAccount, "class='form-control select chosen'" );?>
+ save);?>
repo->gitlabHost;?>client, "class='form-control' placeholder='{$lang->repo->placeholder->gitlabHost}'");?> + gitlab, "class='form-control' placeholder='{$lang->repo->placeholder->gitlabHost}'");?>
repo->gitlabProject;?>extra, "class='form-control chosen'");?> + project, "class='form-control chosen'");?>
repo->name; ?>
From 2c97d3cc2d45667549e7b1f2069314c8785c182b Mon Sep 17 00:00:00 2001 From: lichengjun Date: Thu, 17 Jun 2021 13:05:31 +0800 Subject: [PATCH 052/269] * Adjust the code --- module/gitlab/control.php | 25 +++++++++++++++++-------- module/gitlab/lang/zh-cn.php | 5 +++-- module/gitlab/model.php | 2 ++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index e82e3a6089..ddbc422eb6 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -83,17 +83,22 @@ class gitlab extends control { if($this->post->zentaoUsers) { + if(count($this->post->zentaoUsers) != count(array_unique($this->post->zentaoUsers))) + { + $this->send(array('result' => 'fail', 'message' => $this->lang->gitlab->bindUserError, 'locate' => inlink('binduser'))); + } + $data = array(); $number = 0; foreach($this->post->zentaoUsers as $gitlabId => $account) { - if($account) + if($account) { - $data[$number]['openID'] = $gitlabId; - $data[$number]['account'] = $account; - $data[$number]['providerType'] = 'gitlab'; - $data[$number]['providerID'] = $id; - $number++; + $data[$number]['openID'] = $gitlabId; + $data[$number]['account'] = $account; + $data[$number]['providerType'] = 'gitlab'; + $data[$number]['providerID'] = $id; + $number++; } } } @@ -102,10 +107,14 @@ class gitlab extends control { if(!$this->gitlab->checkAccountId($bindUser['openID'],$bindUser['providerID'])) { - $this->dao->insert(TABLE_OAUTH)->data($bindUser)->exec(); + $this->dao->insert(TABLE_OAUTH)->data($bindUser)->exec(); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('binduser'))); }else { - $this->dao->update(TABLE_OAUTH)->data($bindUser)->where('openID')->eq($bindUser['openID'])->andWhere('providerID')->eq($bindUser['providerID'])->exec(); + $this->dao->update(TABLE_OAUTH)->data($bindUser)->where('openID')->eq($bindUser['openID'])->andWhere('providerID')->eq($bindUser['providerID'])->exec(); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('binduser'))); } } } diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index 4389a02c38..8f1a3ecd4a 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -27,5 +27,6 @@ $lang->gitlab->gitlabNameTips = '该名称会显示在其他相应模块中 $lang->gitlab->gitlabUrlTips = "填写示例:https://gitlab.zcorp.cc
仅填写gitlab服务地址,不需要填写其他URI"; $lang->gitlab->gitlabTokenTips = "请填写具有admin权限账户的access token
可在:https://<gitlab url>/-/profile/personal_access_tokens 创建"; -$lang->gitlab->tokenError = "当前token非管理员权限。"; -$lang->gitlab->hostError = "无效的gitlab服务地址。"; +$lang->gitlab->tokenError = "当前token非管理员权限。"; +$lang->gitlab->hostError = "无效的gitlab服务地址。"; +$lang->gitlab->bindUserError = "禅道用户绑定gitlab服务号失败"; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 72d4cfcbae..d20a815ae3 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -135,6 +135,8 @@ class gitlabModel extends model if($gitlabUser->email == $zentaoUser->email) $matches->emails[$gitlabUser->email][] = $zentaoUser->account; } } + + /*Get binded users from db.*/ $matchedUsers = array(); foreach($gitlabUsers as $gitlabUser) From 1969d12f2fc0910e5cd683037a204ce97f0049bb Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 17 Jun 2021 14:27:23 +0800 Subject: [PATCH 053/269] * Fix bind gitlab user function. --- module/gitlab/control.php | 69 +++++++++++++--------------- module/gitlab/lang/zh-cn.php | 2 +- module/gitlab/model.php | 27 +++++------ module/gitlab/view/binduser.html.php | 2 +- 4 files changed, 47 insertions(+), 53 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index ddbc422eb6..572b99662b 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -72,60 +72,57 @@ class gitlab extends control } /** - * bind gitlab user to zentao users. + * Bind gitlab user to zentao users. * * @access public * @return void */ - public function bindUser($id) + public function bindUser($gitlabID) { + $userPairs = $this->loadModel('user')->getPairs(); if($_POST) { - if($this->post->zentaoUsers) + $users = $this->post->zentaoUsers; + $accountList = array(); + $repeatUsers = array(); + foreach($users as $openID => $user) { - if(count($this->post->zentaoUsers) != count(array_unique($this->post->zentaoUsers))) - { - $this->send(array('result' => 'fail', 'message' => $this->lang->gitlab->bindUserError, 'locate' => inlink('binduser'))); - } - - $data = array(); - $number = 0; - foreach($this->post->zentaoUsers as $gitlabId => $account) - { - if($account) - { - $data[$number]['openID'] = $gitlabId; - $data[$number]['account'] = $account; - $data[$number]['providerType'] = 'gitlab'; - $data[$number]['providerID'] = $id; - $number++; - } - } + if(empty($user)) continue; + if(isset($accountList[$user])) $repeatUsers[] = zget($userPairs, $user); + $accountList[$user] = $openID; } - foreach($data as $bindUser) + if(count($repeatUsers)) $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->gitlab->bindUserError, join(',', $repeatUsers)))); + + $user = new stdclass; + $user->providerID = $gitlabID; + $user->providerType = 'gitlab'; + + foreach($users as $openID => $account) { - if(!$this->gitlab->checkAccountId($bindUser['openID'],$bindUser['providerID'])) - { - $this->dao->insert(TABLE_OAUTH)->data($bindUser)->exec(); - if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); - $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('binduser'))); - }else - { - $this->dao->update(TABLE_OAUTH)->data($bindUser)->where('openID')->eq($bindUser['openID'])->andWhere('providerID')->eq($bindUser['providerID'])->exec(); - if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); - $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('binduser'))); - } + if(!$account) continue; + $user->account = $account; + $user->openID = $openID; + + $this->dao->delete(TABLE_OAUTH) + ->where('openID')->eq($user->openID) + ->andWhere('providerType')->eq('gitlab') + ->andWhere('providerID')->eq($id) + ->andWhere('account')->eq($user->account) + ->exec(); + + $this->dao->insert(TABLE_OAUTH)->data($user)->exec(); } + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->sever->http_referer)); } - $gitlab = $this->gitlab->getByID($id); + $gitlab = $this->gitlab->getByID($gitlabID); $zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account'); $this->view->title = $this->lang->gitlab->bindUser; - $this->view->userPairs = $this->loadModel('user')->getPairs(); + $this->view->userPairs = $userPairs; $this->view->gitlabUsers = $this->gitlab->apiGetUsers($gitlab); - $this->view->matchedResult = $this->gitlab->getMatchedUsers($this->view->gitlabUsers, $zentaoUsers); + $this->view->matchedResult = $this->gitlab->getMatchedUsers($gitlabID, $this->view->gitlabUsers, $zentaoUsers); $this->display(); } diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index 8f1a3ecd4a..bd77ff6bc6 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -29,4 +29,4 @@ $lang->gitlab->gitlabTokenTips = "请填写具有admin权限账户的access $lang->gitlab->tokenError = "当前token非管理员权限。"; $lang->gitlab->hostError = "无效的gitlab服务地址。"; -$lang->gitlab->bindUserError = "禅道用户绑定gitlab服务号失败"; +$lang->gitlab->bindUserError = "不能重复绑定用户 %s"; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index d20a815ae3..bc2bb9e2d7 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -123,7 +123,7 @@ class gitlabModel extends model * @access public * @return array */ - public function getMatchedUsers($gitlabUsers, $zentaoUsers) + public function getMatchedUsers($gitlabID, $gitlabUsers, $zentaoUsers) { $matches = new stdclass; foreach($gitlabUsers as $gitlabUser) @@ -136,11 +136,21 @@ class gitlabModel extends model } } - /*Get binded users from db.*/ + $bindedUsers = $this->dao->select('openID,account')->from(TABLE_OAUTH) + ->where('providerType')->eq('gitlab') + ->andWhere('providerID')->eq($gitlabID) + ->fetchPairs(); $matchedUsers = array(); foreach($gitlabUsers as $gitlabUser) { + if(isset($bindedUsers[$gitlabUser->id])) + { + $gitlabUser->zentaoAccount = $bindedUsers[$gitlabUser->id]; + $matchedUsers[] = $gitlabUser; + continue; + } + $matchedZentaoUsers = array(); if(isset($matches->accounts[$gitlabUser->account])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->accounts[$gitlabUser->account]); if(isset($matches->emails[$gitlabUser->email])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->emails[$gitlabUser->email]); @@ -196,19 +206,6 @@ class gitlabModel extends model return $gitlab_url; } - - /** - * check if gitlab id exists - * - * @param string - * @access public - * @return array - */ - public function checkAccountId($openID,$providerID) - { - return $this->dao->select('openID')->from(TABLE_OAUTH)->where('openID')->eq($openID)->andWhere('providerID')->eq($providerID)->fetch('openID'); - } - /** * Get hooks. * diff --git a/module/gitlab/view/binduser.html.php b/module/gitlab/view/binduser.html.php index 380a0550c6..a0cf0dd17f 100644 --- a/module/gitlab/view/binduser.html.php +++ b/module/gitlab/view/binduser.html.php @@ -15,7 +15,7 @@

gitlab->bindUser;?>

- +
From 012f334c2e5bead13764b582976734de8c2f32b0 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 17 Jun 2021 14:51:39 +0800 Subject: [PATCH 054/269] * Add bindproduct. --- module/gitlab/control.php | 5 ++ module/gitlab/model.php | 7 ++- module/gitlab/view/bindproduct.html.php | 63 +++++++++++++++++++++++++ module/gitlab/view/browse.html.php | 1 + 4 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 module/gitlab/view/bindproduct.html.php diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 0310f78c5c..b8d2f1a1a4 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -94,6 +94,11 @@ class gitlab extends control $this->display(); } + public function bindProduct($gitlabID) + { + } + + /** * Edit a gitlab. * diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 0e22c70fef..bcdc639d49 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -402,18 +402,17 @@ class gitlabModel extends model $apiPath = "/projects/{$projectID}/issues/"; $url = sprintf($apiRoot, $apiPath); $response = commonModel::http($url, $issue); - $labels = json_decode($response); - - return $labels; + return $response; } public function pushTask($task, $gitlabID,$projectID) { - + $task->label = $this->config->gitlab->taskLabel->name; } public function pushBug($bug, $gitlabID,$projectID) { + $bug->label = $this->config->gitlab->bugLabel->name; } } diff --git a/module/gitlab/view/bindproduct.html.php b/module/gitlab/view/bindproduct.html.php new file mode 100644 index 0000000000..9eb34410a2 --- /dev/null +++ b/module/gitlab/view/bindproduct.html.php @@ -0,0 +1,63 @@ + + * @package story + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +
+
+

gitlab->bindUser;?>

+
+ +
+
+ + + + + + + + + zentaoAccount)) continue;?> + + + + + + + + zentaoAccount)) continue;?> + + + + + + + + + + + + +
gitlab->gitlabAccount;?>gitlab->zentaoAccount;?>
avatar, "height=40");?> + realname;?> +
account . " <" . $gitlabUser->email . ">"; ?> +
id]", $userPairs, '', "class='form-control select chosen'" );?>
avatar, "height=40");?> + realname;?> +
account . " <" . $gitlabUser->email . ">";?> +
id]", $userPairs, $gitlabUser->zentaoAccount, "class='form-control select chosen'" );?>
+ save);?> + +
+
+ +
+ diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php index ede244f79b..3ff20a928b 100644 --- a/module/gitlab/view/browse.html.php +++ b/module/gitlab/view/browse.html.php @@ -37,6 +37,7 @@ "); + common::printLink('gitlab', 'bindproduct', "gitlabID=$id", ""); common::printIcon('gitlab', 'edit', "gitlabID=$id", '', 'list', 'edit'); common::printIcon('gitlab', 'binduser', "id=$id", '', 'list', 'group'); if(common::hasPriv('gitlab', 'delete')) echo html::a($this->createLink('gitlab', 'delete', "gitlabID=$id"), '', 'hiddenwin', "title='{$lang->gitlab->delete}' class='btn'"); From 19aac233744b2491c8f482780b2d9a63a9b1a3a9 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 17 Jun 2021 16:05:55 +0800 Subject: [PATCH 055/269] * Add product and gitlab relationship. --- module/gitlab/control.php | 4 ++ module/gitlab/lang/zh-cn.php | 16 ++++--- module/gitlab/model.php | 26 ++++++++-- module/gitlab/view/bindproduct.html.php | 63 ------------------------- module/repo/model.php | 11 ++++- 5 files changed, 47 insertions(+), 73 deletions(-) delete mode 100644 module/gitlab/view/bindproduct.html.php diff --git a/module/gitlab/control.php b/module/gitlab/control.php index a33c609923..e44af26243 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -128,6 +128,10 @@ class gitlab extends control public function bindProduct($gitlabID) { + $this->view->projectPairs = $this->gitlab->getProjectPairs($gitlabID); + $this->view->title = $this->lang->gitlab->bindProduct; + $this->display(); + } diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index bd77ff6bc6..c66aee04a6 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -5,18 +5,22 @@ $lang->gitlab->browse = '浏览gitlab'; $lang->gitlab->create = '添加gitlab'; $lang->gitlab->edit = '编辑gitlab'; $lang->gitlab->bindUser = '绑定用户'; +$lang->gitlab->bindProduct = '关联产品'; $lang->gitlab->delete = '删除'; $lang->gitlab->confirmDelete = '确认删除该gitlab吗?'; $lang->gitlab->gitlabAccount = 'gitlab用户'; $lang->gitlab->zentaoAccount = '禅道用户'; -$lang->gitlab->browseAction = 'gitlab列表'; -$lang->gitlab->deleteAction = '删除gitlab'; +$lang->gitlab->browseAction = 'gitlab列表'; +$lang->gitlab->deleteAction = '删除gitlab'; +$lang->gitlab->gitlabProject = 'gitlab项目'; +$lang->gitlab->zentaoProduct = '禅道产品'; -$lang->gitlab->id = 'ID'; -$lang->gitlab->name = '名称'; -$lang->gitlab->url = '服务地址'; -$lang->gitlab->token = 'Token'; +$lang->gitlab->id = 'ID'; +$lang->gitlab->name = '名称'; +$lang->gitlab->url = '服务地址'; +$lang->gitlab->token = 'Token'; +$lang->gitlab->defaultProject = '默认项目'; $lang->gitlab->lblCreate = '添加gitlab服务器'; $lang->gitlab->desc = '描述'; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 1da694669f..abda26460f 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -170,13 +170,13 @@ class gitlabModel extends model /** * Get projects of one gitlab. * - * @param int $id + * @param int $gitlabID * @access public * @return void */ - public function apiGetProjects($id) + public function apiGetProjects($gitlabID) { - $gitlab = $this->getByID($id); + $gitlab = $this->getByID($gitlabID); if(!$gitlab) return array(); $host = rtrim($gitlab->url, '/'); $host .= '/api/v4/projects'; @@ -191,6 +191,26 @@ class gitlabModel extends model return $allResults; } + public function getProjectPairs($gitlabID) + { + $projects = $this->apiGetProjects($gitlabID); + $projectPairs = array(); + foreach($projects as $project) + { + $projectPairs[$project->id] = $project->name_with_namespace; + } + + return $projectPairs; + } + + public funciton getProjectDisplayName($gitlabID, $projectID) + { + return array_key_exists($gitlabID, $projectID) ? $this->gitlab->getProjectPairs($gitlabID)[$projectID]: ""; + } + + + + /** * Get gitlab api base url with access_token * diff --git a/module/gitlab/view/bindproduct.html.php b/module/gitlab/view/bindproduct.html.php deleted file mode 100644 index 9eb34410a2..0000000000 --- a/module/gitlab/view/bindproduct.html.php +++ /dev/null @@ -1,63 +0,0 @@ - - * @package story - * @version $Id$ - * @link http://www.zentao.net - */ -?> - -
-
-

gitlab->bindUser;?>

-
-
-
- - - - - - - - - - zentaoAccount)) continue;?> - - - - - - - - zentaoAccount)) continue;?> - - - - - - - - - - - - -
gitlab->gitlabAccount;?>gitlab->zentaoAccount;?>
avatar, "height=40");?> - realname;?> -
account . " <" . $gitlabUser->email . ">"; ?> -
id]", $userPairs, '', "class='form-control select chosen'" );?>
avatar, "height=40");?> - realname;?> -
account . " <" . $gitlabUser->email . ">";?> -
id]", $userPairs, $gitlabUser->zentaoAccount, "class='form-control select chosen'" );?>
- save);?> - -
-
-
-
- diff --git a/module/repo/model.php b/module/repo/model.php index eafdaeff90..e4e512e54a 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -229,7 +229,16 @@ class repoModel extends model if(!dao::isError()) $this->rmClientVersionFile(); - if($this->post->SCM == 'Gitlab') $this->loadModel("gitlab")->initLabels($this->post->gitlabHost, $this->post->gitlabProject); + if($this->post->SCM == 'Gitlab') + { + $this->loadModel("gitlab")->initLabels($this->post->gitlabHost, $this->post->gitlabProject); + + // save the relationship between zentao product and gitlab project to zt_relation table. + + } + + + return $this->dao->lastInsertID(); } From 94f7cde43c52a7ca9617140a241bdb56ae63e797 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 18 Jun 2021 09:38:20 +0800 Subject: [PATCH 056/269] * Correct misspelled word. --- module/gitlab/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index abda26460f..60b1d84562 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -203,7 +203,7 @@ class gitlabModel extends model return $projectPairs; } - public funciton getProjectDisplayName($gitlabID, $projectID) + public function getProjectDisplayName($gitlabID, $projectID) { return array_key_exists($gitlabID, $projectID) ? $this->gitlab->getProjectPairs($gitlabID)[$projectID]: ""; } From ffac7cdd45285ecac7c79c22d345b051c266988a Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Fri, 18 Jun 2021 09:55:41 +0800 Subject: [PATCH 057/269] * Format code. --- module/gitlab/model.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index bc2bb9e2d7..20f6cbdafb 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -136,7 +136,8 @@ class gitlabModel extends model } } - $bindedUsers = $this->dao->select('openID,account')->from(TABLE_OAUTH) + $bindedUsers = $this->dao->select('openID,account') + ->from(TABLE_OAUTH) ->where('providerType')->eq('gitlab') ->andWhere('providerID')->eq($gitlabID) ->fetchPairs(); From 444566afb55225ef09e47bee648ef6cb215bf9a3 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 18 Jun 2021 09:58:45 +0800 Subject: [PATCH 058/269] + Create webhook when create map for product and gitlab project. --- module/gitlab/config.php | 2 ++ module/gitlab/model.php | 15 +++++++++++++++ module/repo/model.php | 3 +++ 3 files changed, 20 insertions(+) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 6f7828f459..2f66c83ed7 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -17,5 +17,7 @@ $config->gitlab->bugLabel->description = "bug label from zentao"; $config->gitlab->bugLabel->color = "#D10069"; $config->gitlab->bugLabel->priority = "0"; +$config->gitlab->zentaoApiWebhookUrl = "https://zentao/api/v1/webhook/callback"; +$config->gitlab->zentaoApiWebhookToken = ""; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 60b1d84562..4e8631aa3b 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -226,6 +226,21 @@ class gitlabModel extends model return $gitlab_url; } + /** + * Create webhook for zentao. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ + public function createWebhook($gitlabID, $projectID) + { + // TODO(dingguodong) add more robust code here. + $response = $this->apiCreateHook($gitlabID, $projectID, $this->config->gitlab->zentaoApiWebhookUrl, $this->config->gitlab->zentaoApiWebhookToken); + return $response; + } + /** * Get hooks. * diff --git a/module/repo/model.php b/module/repo/model.php index e4e512e54a..165533741a 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -235,6 +235,9 @@ class repoModel extends model // save the relationship between zentao product and gitlab project to zt_relation table. + /* create webhook for zentao */ + $this->loadModel("gitlab")->createWebhook($this->post->gitlabHost, $this->post->gitlabProject); + } From a657124b4892e45b525011edc5dc8a00313cb284 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Fri, 18 Jun 2021 10:21:37 +0800 Subject: [PATCH 059/269] * Add checkToken function and remove unused functions. --- module/gitlab/control.php | 101 +++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 55 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index e44af26243..9e91202ba3 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -48,15 +48,7 @@ class gitlab extends control { if($_POST) { - if(strpos($host, 'http') !== 0) $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)))); - if(!$this->post->token) $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)))); - - $user = $this->gitlab->apiGetCurrentUser($this->post->url, $this->post->token); - - if(!is_object($user)) $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)))); - if(isset($user->is_admin) and $user->is_admin == true) $this->send(array('result' => 'success')); - $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)))); - + $this->checkToken(); $gitlabID = $this->gitlab->create(); if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); @@ -71,6 +63,33 @@ class gitlab extends control $this->display(); } + /** + * Edit a gitlab. + * + * @param int $id + * @access public + * @return void + */ + public function edit($id) + { + $gitlab = $this->gitlab->getByID($id); + if($_POST) + { + $this->checkToken(); + $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(); + } + /** * Bind gitlab user to zentao users. * @@ -79,7 +98,8 @@ class gitlab extends control */ public function bindUser($gitlabID) { - $userPairs = $this->loadModel('user')->getPairs(); + $userPairs = $this->loadModel('user')->getPairs(); + if($_POST) { $users = $this->post->zentaoUsers; @@ -126,44 +146,20 @@ class gitlab extends control $this->display(); } + /** + * Bind product and gitlab projects. + * + * @param int $gitlabID + * @access public + * @return void + */ public function bindProduct($gitlabID) { $this->view->projectPairs = $this->gitlab->getProjectPairs($gitlabID); $this->view->title = $this->lang->gitlab->bindProduct; $this->display(); - } - - /** - * Edit a gitlab. - * - * @param int $id - * @access public - * @return void - */ - public function edit($id) - { - $gitlab = $this->gitlab->getByID($id); - if($_POST) - { - $tokenValid = $this->gitlab->apiGetCurrentUser($this->post->url, $this->post->token); - if($tokenValid['result'] == 'fail') $this->send($tokenValid); - - $this->gitlab->update($id); - if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); - $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); - } - - $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. * @@ -180,24 +176,19 @@ class gitlab extends control } /** - * Ajax get gitlab token permissions. - * - * @param string $host - * @param string $token + * Check post token has admin permissions. + * * @access public * @return void */ - public function ajaxCheckToken($host, $token) + public function checkToken() { - $host = helper::safe64Decode($host); - $permissions = $this->gitlab->apiGetCurrentUser($host, $token); - $this->send($permissions); - } + if(strpos($this->post->url, 'http') !== 0) $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)))); + if(!$this->post->token) $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)))); - public function createHook($gitlab_id, $project_id, $url, $token) - { - $res = $this->gitlab->apiCreateHook($gitlab_id, $project_id, $url, $token); - return $res; - } + $user = $this->gitlab->apiGetCurrentUser($this->post->url, $this->post->token); + if(!is_object($user)) $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)))); + if(!isset($user->is_admin) or !$user->is_admin) $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)))); + } } From 019e946496603527eeb48802ac3a208ef7eaca43 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Fri, 18 Jun 2021 10:41:15 +0800 Subject: [PATCH 060/269] * Fix gitlab api hook url. --- module/gitlab/config.php | 2 +- module/gitlab/model.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 2f66c83ed7..275bf96a15 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -17,7 +17,7 @@ $config->gitlab->bugLabel->description = "bug label from zentao"; $config->gitlab->bugLabel->color = "#D10069"; $config->gitlab->bugLabel->priority = "0"; -$config->gitlab->zentaoApiWebhookUrl = "https://zentao/api/v1/webhook/callback"; +$config->gitlab->zentaoApiWebhookUrl = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s&project=%s"; $config->gitlab->zentaoApiWebhookToken = ""; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 8358d2b929..3e2375e6d1 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -235,10 +235,10 @@ class gitlabModel extends model * @access public * @return void */ - public function createWebhook($gitlabID, $projectID) + public function createWebhook($products, $gitlabID, $projectID) { - // TODO(dingguodong) add more robust code here. - $response = $this->apiCreateHook($gitlabID, $projectID, $this->config->gitlab->zentaoApiWebhookUrl, $this->config->gitlab->zentaoApiWebhookToken); + $webhook = sprintf($this->config->gitlab->zentaoApiWebhookUrl, commonModel::getSysURL(), $gitlabID); + $response = $this->apiCreateHook($gitlabID, $projectID, $webhook, $this->config->gitlab->zentaoApiWebhookToken); return $response; } From 51b2a70308f4442ae3830f8509a2279abfb95c9f Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 18 Jun 2021 10:51:31 +0800 Subject: [PATCH 061/269] * Create webhook for each products. --- module/gitlab/model.php | 9 ++++++--- module/repo/model.php | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 3e2375e6d1..419a94d231 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -237,9 +237,12 @@ class gitlabModel extends model */ public function createWebhook($products, $gitlabID, $projectID) { - $webhook = sprintf($this->config->gitlab->zentaoApiWebhookUrl, commonModel::getSysURL(), $gitlabID); - $response = $this->apiCreateHook($gitlabID, $projectID, $webhook, $this->config->gitlab->zentaoApiWebhookToken); - return $response; + foreach($products as $index => $product) + { + $webhook = sprintf($this->config->gitlab->zentaoApiWebhookUrl, commonModel::getSysURL(), $product, $gitlabID, $projectID); + $response = $this->apiCreateHook($gitlabID, $projectID, $webhook, $this->config->gitlab->zentaoApiWebhookToken); + } + return true; } /** diff --git a/module/repo/model.php b/module/repo/model.php index 165533741a..abe3a502af 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -236,7 +236,7 @@ class repoModel extends model // save the relationship between zentao product and gitlab project to zt_relation table. /* create webhook for zentao */ - $this->loadModel("gitlab")->createWebhook($this->post->gitlabHost, $this->post->gitlabProject); + $this->loadModel("gitlab")->createWebhook($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); } From 52dde68865bc328268841dde7eb28d40f154a738 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 18 Jun 2021 11:01:37 +0800 Subject: [PATCH 062/269] * Create webhook when update product and project mapping. --- module/repo/model.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/module/repo/model.php b/module/repo/model.php index abe3a502af..df6ec01cb9 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -303,7 +303,13 @@ class repoModel extends model { $this->dao->delete()->from(TABLE_REPOHISTORY)->where('repo')->eq($id)->exec(); $this->dao->delete()->from(TABLE_REPOFILES)->where('repo')->eq($id)->exec(); - if($repo->SCM == 'Gitlab') $this->loadModel("gitlab")->initLabels($this->post->gitlabHost, $this->post->gitlabProject); + if($repo->SCM == 'Gitlab') + { + $this->loadModel("gitlab")->initLabels($this->post->gitlabHost, $this->post->gitlabProject); + + $this->loadModel("gitlab")->createWebhook($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); + + } return false; } From 8e176c30010e6fd9905bd1421f25b6d79ce5a1f7 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 18 Jun 2021 11:05:45 +0800 Subject: [PATCH 063/269] * Fix bug when empty labels exists. --- module/gitlab/model.php | 1 + 1 file changed, 1 insertion(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 419a94d231..5877268dfd 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -406,6 +406,7 @@ class gitlabModel extends model public function isLabelExists($gitlabID, $projectID) { $labels = $this->apiGetLabels($gitlabID, $projectID); + if(empty($labels)) return false; foreach($labels as $label) { if(strpos($label->name, $this->config->gitlab->taskLabel->name) == 0) return true; From cdbcb418a874e5f299dcf995edb66993dca36fc0 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 18 Jun 2021 13:38:24 +0800 Subject: [PATCH 064/269] * Improve code robustness. --- module/gitlab/model.php | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 5877268dfd..f7c102d75e 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -237,10 +237,15 @@ class gitlabModel extends model */ public function createWebhook($products, $gitlabID, $projectID) { + $urls = $this->getWebhookUrls($gitlabID, $projectID); + foreach($products as $index => $product) { - $webhook = sprintf($this->config->gitlab->zentaoApiWebhookUrl, commonModel::getSysURL(), $product, $gitlabID, $projectID); - $response = $this->apiCreateHook($gitlabID, $projectID, $webhook, $this->config->gitlab->zentaoApiWebhookToken); + $url = sprintf($this->config->gitlab->zentaoApiWebhookUrl, commonModel::getSysURL(), $product, $gitlabID, $projectID); + if(! array_key_exists($url, array_flip($urls))) + { + $response = $this->apiCreateHook($gitlabID, $projectID, $url, $this->config->gitlab->zentaoApiWebhookToken); + } } return true; } @@ -258,7 +263,7 @@ class gitlabModel extends model $apiRoot = $this->getApiRoot($gitlabID); $apiPath = "/projects/{$projectID}/hooks"; $url = sprintf($apiRoot, $apiPath); - $response = commonModel::http($url); + $response = json_decode(commonModel::http($url)); return $response; } @@ -277,9 +282,28 @@ class gitlabModel extends model $apiPath = "/projects/$projectID/hooks/$hookID)"; $url = sprintf($apiRoot, $apiPath); $response = commonModel::http($url); - return; + return $response; } + /** + * Get webhook urls + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return array $urls; + */ + public function getWebhookUrls($gitlabID, $projectID) + { + $urls = array(); + $webhooks = $this->apiGetHooks($gitlabID, $projectID); + foreach($webhooks as $index => $webhook) + { + $urls[] = $webhook->url; + } + return $urls; + } + /** * Create hook. * From 0fce5f06f37ba869b4a12d8a063367b40d64bbfe Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 18 Jun 2021 15:05:01 +0800 Subject: [PATCH 065/269] * Remove bad blank lines. --- module/repo/model.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/module/repo/model.php b/module/repo/model.php index df6ec01cb9..ff5bdfe8de 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -240,9 +240,6 @@ class repoModel extends model } - - - return $this->dao->lastInsertID(); } From 7a67b762c4140f7c5f2417a4db41a7acf9425f51 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Fri, 18 Jun 2021 17:35:53 +0800 Subject: [PATCH 066/269] * Add Associat function --- module/gitlab/model.php | 34 +++++++++++++++++++++++++++++++--- module/repo/model.php | 3 ++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index f7c102d75e..db0a24aa17 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -209,9 +209,6 @@ class gitlabModel extends model return array_key_exists($gitlabID, $projectID) ? $this->gitlab->getProjectPairs($gitlabID)[$projectID]: ""; } - - - /** * Get gitlab api base url with access_token * @@ -227,6 +224,37 @@ class gitlabModel extends model return $gitlab_url; } + /** + * Create relationship between zentao product and gitlab project. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ + public function createAssociat($products, $gitlabID, $projectID) + { + $gitlabNamespace = $this->getProjectPairs($gitlabID); + + $gitlabAssociat = new stdclass; + $gitlabAssociat->execution = 0; + $gitlabAssociat->AVersion = 0; + $gitlabAssociat->relation = 'interrated'; + $gitlabAssociat->BVersion = 0; + $gitlabAssociat->extra = 0; + + foreach($products as $index => $prodcuct) + { + $gitlabAssociat->BType = $gitlabNamespace[$gitlabID]; + $gitlabAssociat->BID = $gitlabID; + $gitlabAssociat->Project = $ProjectID;; + $gitlabAssociat->Product = $product; + + $this->dao->insert(TABLE_RELATION)->data($gitlabAssociat)->exec(); + } + return true; + } + /** * Create webhook for zentao. * diff --git a/module/repo/model.php b/module/repo/model.php index ff5bdfe8de..9f7ee2f3ae 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -233,7 +233,8 @@ class repoModel extends model { $this->loadModel("gitlab")->initLabels($this->post->gitlabHost, $this->post->gitlabProject); - // save the relationship between zentao product and gitlab project to zt_relation table. + /* save the relationship between zentao product and gitlab project to zt_relation table.*/ + $this->loadModel("gitlab")->createAssociat($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); /* create webhook for zentao */ $this->loadModel("gitlab")->createWebhook($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); From b90639355dc6ee4b8c670b88c171573fc26e3d4d Mon Sep 17 00:00:00 2001 From: dingguodong Date: Sat, 19 Jun 2021 11:35:15 +0800 Subject: [PATCH 067/269] * Reformat codes and prepare for call. --- module/gitlab/model.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index db0a24aa17..21a7cc26ec 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -359,7 +359,6 @@ class gitlabModel extends model $url = sprintf($apiRoot, $apiPath); $response = commonModel::http($url, $postData); return $response; - } /** @@ -466,8 +465,6 @@ class gitlabModel extends model } return false; - - } /** @@ -505,18 +502,21 @@ class gitlabModel extends model $apiRoot = $this->getApiRoot($gitlabID); $apiPath = "/projects/{$projectID}/issues/"; $url = sprintf($apiRoot, $apiPath); - $response = commonModel::http($url, $issue); + $response = json_decode(commonModel::http($url, $issue)); return $response; } - public function pushTask($task, $gitlabID,$projectID) + public function pushTask($gitlabID, $projectID, $task) { $task->label = $this->config->gitlab->taskLabel->name; + $response = $this->apiCreateIssue($gitlabID, $projectID, $task); + return $response; } - public function pushBug($bug, $gitlabID,$projectID) + public function pushBug($gitlabID, $projectID, $bug) { - $bug->label = $this->config->gitlab->bugLabel->name; + $response = $this->apiCreateIssue($gitlabID, $projectID, $bug); + return $response; } } From 6b9867c68345b430c12ce78ede3453ae43cf1750 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Sat, 19 Jun 2021 15:23:59 +0800 Subject: [PATCH 068/269] * fix Associat bug --- module/gitlab/model.php | 25 ++++++++++++++----------- module/repo/model.php | 10 +++------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index db0a24aa17..47c4fdc614 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -179,12 +179,12 @@ class gitlabModel extends model { $gitlab = $this->getByID($gitlabID); if(!$gitlab) return array(); - $host = rtrim($gitlab->url, '/'); + $host = rtrim($gitlab->url, '/'); $host .= '/api/v4/projects'; $allResults = array(); for($page = 1; true; $page ++) - { + { $results = json_decode(commonModel::http($host . "?private_token={$gitlab->token}&simple=true&membership=true&page={$page}&per_page=100")); if(empty($results) or $page > 10) break; $allResults = $allResults + $results; @@ -232,9 +232,12 @@ class gitlabModel extends model * @access public * @return void */ - public function createAssociat($products, $gitlabID, $projectID) + public function createAssociat($products, $gitlabID, $gitlabProjectID) { - $gitlabNamespace = $this->getProjectPairs($gitlabID); + $productIDs = $this->dao->select('id,program')->from(TABLE_PRODUCT)->fetchAll(); + + $projectID = array(); + foreach($productIDs as $project) $projectID[$project->id] = $project->program; $gitlabAssociat = new stdclass; $gitlabAssociat->execution = 0; @@ -242,15 +245,15 @@ class gitlabModel extends model $gitlabAssociat->relation = 'interrated'; $gitlabAssociat->BVersion = 0; $gitlabAssociat->extra = 0; + $gitlabAssociat->BID = $gitlabID; - foreach($products as $index => $prodcuct) - { - $gitlabAssociat->BType = $gitlabNamespace[$gitlabID]; - $gitlabAssociat->BID = $gitlabID; - $gitlabAssociat->Project = $ProjectID;; - $gitlabAssociat->Product = $product; + foreach($products as $index => $prodcut) + { + $gitlabAssociat->BType = $this->getprojectpairs($gitlabID)[$gitlabProjectID]; + $gitlabAssociat->Project = $projectID[$prodcut]; + $gitlabAssociat->Product = $prodcut; - $this->dao->insert(TABLE_RELATION)->data($gitlabAssociat)->exec(); + $this->dao->replace(TABLE_RELATION)->data($gitlabAssociat)->exec(); } return true; } diff --git a/module/repo/model.php b/module/repo/model.php index 9f7ee2f3ae..220dae63e4 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -231,16 +231,12 @@ class repoModel extends model if($this->post->SCM == 'Gitlab') { - $this->loadModel("gitlab")->initLabels($this->post->gitlabHost, $this->post->gitlabProject); - - /* save the relationship between zentao product and gitlab project to zt_relation table.*/ - $this->loadModel("gitlab")->createAssociat($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); + $this->loadModel("gitlab")->initLabels($this->post->gitlabHost, $this->post->gitlabProject); + $this->loadModel("gitlab")->createAssociat($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); /* create webhook for zentao */ - $this->loadModel("gitlab")->createWebhook($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); - + $this->loadModel("gitlab")->createWebhook($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); } - return $this->dao->lastInsertID(); } From ab37633ba6e0070a03c182dd9e3359931ad8297d Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 21 Jun 2021 10:01:41 +0800 Subject: [PATCH 069/269] * Add openmethod config. --- config/zentaopms.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/config/zentaopms.php b/config/zentaopms.php index 6a8fe3ca3a..18f88739f9 100644 --- a/config/zentaopms.php +++ b/config/zentaopms.php @@ -109,6 +109,29 @@ $config->charsets['fr']['GBK'] = 'GBK'; $config->charsets['vi']['utf-8'] = 'UTF-8'; $config->charsets['vi']['GBK'] = 'GBK'; +$config->openMethods = array(); +$config->openMethods[] = 'gitlab.webhook'; +$config->openMethods[] = 'upgrade.ajaxupdatefile'; +$config->openMethods[] = 'user.login'; +$config->openMethods[] = 'user.logout'; +$config->openMethods[] = 'user.deny'; +$config->openMethods[] = 'user.reset'; +$config->openMethods[] = 'user.refreshrandom'; +$config->openMethods[] = 'api.getsessionid'; +$config->openMethods[] = 'misc.checktable'; +$config->openMethods[] = 'misc.qrcode'; +$config->openMethods[] = 'misc.about'; +$config->openMethods[] = 'misc.checkupdate'; +$config->openMethods[] = 'misc.ping'; +$config->openMethods[] = 'misc.captcha'; +$config->openMethods[] = 'sso.login'; +$config->openMethods[] = 'sso.logout'; +$config->openMethods[] = 'sso.bind'; +$config->openMethods[] = 'sso.gettodolist'; +$config->openMethods[] = 'file.read'; +$config->openMethods[] = 'index.changelog'; +$config->openMethods[] = 'my.preference'; + /* Define the tables. */ define('TABLE_COMPANY', '`' . $config->db->prefix . 'company`'); define('TABLE_DEPT', '`' . $config->db->prefix . 'dept`'); From f853b676e0ad541485e28ab4191522aa32033ce8 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 21 Jun 2021 10:03:21 +0800 Subject: [PATCH 070/269] * Remov utf8 bom. --- www/api.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/www/api.php b/www/api.php index abe85d249b..1b6cd85a47 100644 --- a/www/api.php +++ b/www/api.php @@ -42,8 +42,7 @@ $config->default->view = 'json'; $app->parseRequest(); $common->checkPriv(); $app->loadModule(); - -$output = json_decode(ob_get_clean()); +$output = json_decode(helper::removeUTF8Bom(ob_get_clean())); $data = new stdClass(); $data->status = isset($output->status) ? $output->status : $output->result; if(isset($output->message)) $data->message = $output->message; From 1ebdebd16c45a5cfb5e2a96b6626e5e2651d22ca Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 21 Jun 2021 10:03:48 +0800 Subject: [PATCH 071/269] * Check open method in config->openMethods. --- module/common/model.php | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/module/common/model.php b/module/common/model.php index 7e872be987..28a7c62617 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -178,23 +178,9 @@ class commonModel extends model */ public function isOpenMethod($module, $method) { - if($module == 'upgrade' and $method == 'ajaxupdatefile') return true; - if($module == 'user' and strpos('login|logout|deny|reset|refreshrandom', $method) !== false) return true; - if($module == 'api' and $method == 'getsessionid') return true; - if($module == 'misc' and $method == 'checktable') return true; - if($module == 'misc' and $method == 'qrcode') return true; - if($module == 'misc' and $method == 'about') return true; - if($module == 'misc' and $method == 'checkupdate') return true; - if($module == 'misc' and $method == 'ping') return true; - if($module == 'misc' and $method == 'captcha') return true; - if($module == 'sso' and $method == 'login') return true; - if($module == 'sso' and $method == 'logout') return true; - if($module == 'sso' and $method == 'bind') return true; - if($module == 'sso' and $method == 'gettodolist') return true; + if(in_array("$module.$method", $this->config->openMethods)) return true; + if($module == 'block' and $method == 'main' and isset($_GET['hash'])) return true; - if($module == 'file' and $method == 'read') return true; - if($module == 'index' and $method == 'changelog') return true; - if($module == 'my' and $method == 'preference') return true; if($this->loadModel('user')->isLogon() or ($this->app->company->guest and $this->app->user->account == 'guest')) { @@ -2021,6 +2007,8 @@ EOD; */ public function checkEntry() { + if($this->isOpenMethod($_GET[$this->config->moduleVar], $_GET[$this->config->methodVar])) return true; + $this->loadModel('entry'); if($this->session->valid_entry) { @@ -2033,10 +2021,10 @@ EOD; if(!$this->get->token) $this->response('PARAM_TOKEN_MISSING'); $entry = $this->entry->getByCode($this->get->code); - if(!$entry) $this->response('EMPTY_ENTRY'); - if(!$entry->key) $this->response('EMPTY_KEY'); - if(!$this->checkIP($entry->ip)) $this->response('IP_DENIED'); - if(!$this->checkEntryToken($entry)) $this->response('INVALID_TOKEN'); + if(!$entry) $this->response('EMPTY_ENTRY'); + if(!$entry->key) $this->response('EMPTY_KEY'); + if(!$this->checkIP($entry->ip)) $this->response('IP_DENIED'); + if(!$this->checkEntryToken($entry)) $this->response('INVALID_TOKEN'); if($entry->freePasswd == 0 and empty($entry->account)) $this->response('ACCOUNT_UNBOUND'); $isFreepasswd = ($_GET['m'] == 'user' and strtolower($_GET['f']) == 'apilogin' and $_GET['account'] and $entry->freePasswd); From b5f32bf347b42ec1f1fe764f49764d3be2b5742a Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 21 Jun 2021 10:05:12 +0800 Subject: [PATCH 072/269] * Add check webhook api of gitlab module. --- module/gitlab/control.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 9e91202ba3..4919d0bf15 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -191,4 +191,35 @@ class gitlab extends control if(!is_object($user)) $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)))); if(!isset($user->is_admin) or !$user->is_admin) $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)))); } + + /** + * Webhook api. + * + * @access public + * @return void + */ + public function webhook() + { + $product = $this->get->product; + $gitlab = $this->get->gitlab; + $project = $this->get->project; + + $logFile = $this->app->getLogRoot() . 'webhook.'. date('Ymd') . '.log.php'; + if(!file_exists($logFile)) file_put_contents($logFile, ''); + + $fh = @fopen($logFile, 'a'); + if($fh) + { + fwrite($fh, date('Ymd H:i:s') . ": " . $this->app->getURI() . "\n"); + if(!empty($_POST)) fwrite($fh, "data: " . var_export($_POST, true) . "\n"); + //fwrite($fh, "results:" . print_r($response, true) . "\n"); + if(!empty($errors)) fwrite($fh, "errors: " . $errors . "\n"); + fclose($fh); + } + + $this->view->result = 'success'; + $this->view->status = 'ok'; + $this->view->data = 'ougiugjvh'; + $this->display(); + } } From 45fd0977284e713d6ff7eaf0701afbb9ed57acc1 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 21 Jun 2021 11:16:37 +0800 Subject: [PATCH 073/269] * Add parse webhook functions. --- module/gitlab/config.php | 2 +- module/gitlab/control.php | 17 +++++++++++++++-- module/gitlab/model.php | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 275bf96a15..a4bff19207 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -17,7 +17,7 @@ $config->gitlab->bugLabel->description = "bug label from zentao"; $config->gitlab->bugLabel->color = "#D10069"; $config->gitlab->bugLabel->priority = "0"; -$config->gitlab->zentaoApiWebhookUrl = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s&project=%s"; +$config->gitlab->zentaoApiWebhookUrl = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s"; $config->gitlab->zentaoApiWebhookToken = ""; diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 4919d0bf15..7002a860d8 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -204,6 +204,19 @@ class gitlab extends control $gitlab = $this->get->gitlab; $project = $this->get->project; + $requestBody = json_decode(file_get_contents('php://input')); + $request = $this->gitlab->parseWebhookBody($requestBody); + + switch($request->type) + { + case 'issue_create': + $this->createTaskFromIssue($request); + break; + case 'issue_update': + $this->updateTaskFromIssue($request); + break; + } + $logFile = $this->app->getLogRoot() . 'webhook.'. date('Ymd') . '.log.php'; if(!file_exists($logFile)) file_put_contents($logFile, ''); @@ -211,8 +224,8 @@ class gitlab extends control if($fh) { fwrite($fh, date('Ymd H:i:s') . ": " . $this->app->getURI() . "\n"); - if(!empty($_POST)) fwrite($fh, "data: " . var_export($_POST, true) . "\n"); - //fwrite($fh, "results:" . print_r($response, true) . "\n"); + fwrite($fh, "GET: " . var_export($_GET, true) . "\n"); + fwrite($fh, "Body: " . var_export($requestBody, true) . "\n"); if(!empty($errors)) fwrite($fh, "errors: " . $errors . "\n"); fclose($fh); } diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 987f453162..3e1af87946 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -522,4 +522,22 @@ class gitlabModel extends model $response = $this->apiCreateIssue($gitlabID, $projectID, $bug); return $response; } + + public function parseWebhookBody($body) + { + $type = zget($body, 'object_kind', ''); + if(!$type or !is_callable(array($this, "parse{$type}Webhook"))) return false; + return call_user_func_array(array($this, "parse{$type}Webhook"), array('body' => $body)); + } + + public function parseIssueWebhook($body) + { + $request = new stdclass; + $request->type = $body->object_kind; + $issue = $body->object_attributes; + + $request->labels = $body->labels; + $request->project = $body->project->id; + } + } From 8b0bbb62cceacbf5f1e40fc75f6e009430dd02bd Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 21 Jun 2021 13:24:38 +0800 Subject: [PATCH 074/269] * Add comment event support for creating webhook. --- module/gitlab/model.php | 1 + 1 file changed, 1 insertion(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 3e1af87946..7c51dc2f50 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -401,6 +401,7 @@ class gitlabModel extends model $postData->merge_requests_events = "true"; $postData->push_events = "true"; $postData->tag_push_events = "true"; + $postData->note_events = "true"; $postData->url = $url; $postData->token = $token; From 19eb443a069208e173369a811f4ff902d5084cc3 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 21 Jun 2021 13:58:04 +0800 Subject: [PATCH 075/269] * Fix bug when bind user. --- module/gitlab/control.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 7002a860d8..0649511f5f 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -124,16 +124,17 @@ class gitlab extends control $user->account = $account; $user->openID = $openID; - $this->dao->delete(TABLE_OAUTH) + $this->dao->delete() + ->from(TABLE_OAUTH) ->where('openID')->eq($user->openID) - ->andWhere('providerType')->eq('gitlab') - ->andWhere('providerID')->eq($id) + ->andWhere('providerType')->eq($user->providerType) + ->andWhere('providerID')->eq($user->providerID) ->andWhere('account')->eq($user->account) ->exec(); $this->dao->insert(TABLE_OAUTH)->data($user)->exec(); } - $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->sever->http_referer)); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->server->http_referer)); } $gitlab = $this->gitlab->getByID($gitlabID); From 8235310ef9aae4b4a4121c4a247ef7362bdd427d Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 21 Jun 2021 15:39:54 +0800 Subject: [PATCH 076/269] * Bug fix when binding user from gitlab to zentao. --- module/gitlab/control.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 0649511f5f..2fd9c19f64 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -118,6 +118,12 @@ class gitlab extends control $user->providerID = $gitlabID; $user->providerType = 'gitlab'; + $this->dao->delete() + ->from(TABLE_OAUTH) + ->where('providerType')->eq($user->providerType) + ->andWhere('providerID')->eq($user->providerID) + ->exec(); + foreach($users as $openID => $account) { if(!$account) continue; From 9ed83f977d62e7db4603aff9dfe0d1fe53958147 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 21 Jun 2021 16:03:51 +0800 Subject: [PATCH 077/269] - Remove unused codes. --- module/gitlab/view/browse.html.php | 1 - 1 file changed, 1 deletion(-) diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php index 3ff20a928b..19f7e339c4 100644 --- a/module/gitlab/view/browse.html.php +++ b/module/gitlab/view/browse.html.php @@ -36,7 +36,6 @@ url; ?> "); common::printLink('gitlab', 'bindproduct', "gitlabID=$id", ""); common::printIcon('gitlab', 'edit', "gitlabID=$id", '', 'list', 'edit'); common::printIcon('gitlab', 'binduser', "id=$id", '', 'list', 'group'); From ae96cd1161ef1034d4fee1a658efefd5e71479bb Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 21 Jun 2021 16:17:37 +0800 Subject: [PATCH 078/269] * Show placeholders. --- module/gitlab/lang/zh-cn.php | 7 ++++--- module/gitlab/view/create.html.php | 10 ++++------ module/gitlab/view/edit.html.php | 13 ++++++------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index c66aee04a6..5cfdc0fbe3 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -27,9 +27,10 @@ $lang->gitlab->desc = '描述'; $lang->gitlab->tokenFirst = 'Token不为空时,优先使用Token。'; $lang->gitlab->tips = '使用密码时,请在gitlab全局安全设置中禁用"防止跨站点请求伪造"选项。'; -$lang->gitlab->gitlabNameTips = '该名称会显示在其他相应模块中
可使用便于识别的友好名称'; -$lang->gitlab->gitlabUrlTips = "填写示例:https://gitlab.zcorp.cc
仅填写gitlab服务地址,不需要填写其他URI"; -$lang->gitlab->gitlabTokenTips = "请填写具有admin权限账户的access token
可在:https://<gitlab url>/-/profile/personal_access_tokens 创建"; +$lang->gitlab->placeholder = new stdclass; +$lang->gitlab->placeholder->name = ''; +$lang->gitlab->placeholder->url = "请填写Gitlab Server首页的访问地址,如:https://gitlab.zentao.net。"; +$lang->gitlab->placeholder->token = "请填写具有admin权限账户的access token"; $lang->gitlab->tokenError = "当前token非管理员权限。"; $lang->gitlab->hostError = "无效的gitlab服务地址。"; diff --git a/module/gitlab/view/create.html.php b/module/gitlab/view/create.html.php index 86215af1d3..1675041925 100644 --- a/module/gitlab/view/create.html.php +++ b/module/gitlab/view/create.html.php @@ -22,18 +22,16 @@ - - + + - - + - - + diff --git a/module/gitlab/view/edit.html.php b/module/gitlab/view/edit.html.php index e8ee46842d..81d37d99f6 100644 --- a/module/gitlab/view/edit.html.php +++ b/module/gitlab/view/edit.html.php @@ -21,20 +21,19 @@
gitlab->name; ?>gitlab->gitlabNameTips; ?>gitlab->placeholder->name}'"); ?>
gitlab->url; ?>gitlab->gitlabUrlTips; ?>gitlab->placeholder->url}'"); ?>
gitlab->token;?>gitlab->gitlabTokenTips; ?>gitlab->placeholder->token}'");?>
- - + + - - + - - + - + + + + + + diff --git a/module/user/model.php b/module/user/model.php index f2b301d7af..0591d273bc 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -2388,20 +2388,25 @@ class userModel extends model * @access public * @return array */ - public function getTeamMemberPairs($objectID, $type = 'project', $params = '', $usersToAppended = '') + public function getTeamMemberPairs($objectID, $type = 'project', $params = '', $usersToAppended = '', $sync = '') { if(defined('TUTORIAL')) return $this->loadModel('tutorial')->getTeamMembersPairs(); $keyField = strpos($params, 'useid') !== false ? 'id' : 'account'; $users = $this->dao->select("t2.id, t2.account, t2.realname")->from(TABLE_TEAM)->alias('t1') ->leftJoin(TABLE_USER)->alias('t2')->on('t1.account = t2.account') + ->leftJoin(TABLE_OAUTH)->alias('t3')->on('t2.account = t3.account') ->where('t1.root')->eq((int)$objectID) ->andWhere('t1.type')->eq($type) ->beginIF($params == 'nodeleted' or empty($this->config->user->showDeleted)) ->andWhere('t2.deleted')->eq(0) ->fi() + ->beginIF(!empty($sync)) + ->andWhere('providerType')->eq($sync) + ->fi() ->fetchAll($keyField); + a($this->dao->get());exit; if($usersToAppended) $users += $this->dao->select("id, account, realname")->from(TABLE_USER)->where('account')->in($usersToAppended)->fetchAll($keyField); if(!$users) return array('' => ''); From 9069e4044a5a5960588880f045a7c873942728db Mon Sep 17 00:00:00 2001 From: lichengjun Date: Mon, 21 Jun 2021 16:58:01 +0800 Subject: [PATCH 080/269] * Fix bug. --- module/user/model.php | 1 - 1 file changed, 1 deletion(-) diff --git a/module/user/model.php b/module/user/model.php index 0591d273bc..218cb201bc 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -2406,7 +2406,6 @@ class userModel extends model ->fi() ->fetchAll($keyField); - a($this->dao->get());exit; if($usersToAppended) $users += $this->dao->select("id, account, realname")->from(TABLE_USER)->where('account')->in($usersToAppended)->fetchAll($keyField); if(!$users) return array('' => ''); From 7712eb9fdaa0c3669027796381b91ba87b133825 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 21 Jun 2021 17:46:11 +0800 Subject: [PATCH 081/269] * Bug fix when displaying gitlab proj address. --- module/repo/model.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/repo/model.php b/module/repo/model.php index 220dae63e4..639e67d651 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -206,7 +206,8 @@ class repoModel extends model ->join('product', ',') ->get(); - if($this->post->SCM == 'Gitlab') $data->path = sprintf($this->config->repo->gitlab->apiPath, $data->gitlabHost, $this->post->gitlabProject); + /* see this file in 1783G: processGitlab::$repo->path */ + if($this->post->SCM == 'Gitlab') $data->path = $this->post->gitlabProject; $data->acl = empty($data->acl) ? '' : json_encode($data->acl); From ccf132cc87575a237009e81f993bda4750f36a01 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 22 Jun 2021 11:47:24 +0800 Subject: [PATCH 082/269] * Add more issue params. --- module/gitlab/model.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 7c51dc2f50..86c757c9a9 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -536,9 +536,21 @@ class gitlabModel extends model $request = new stdclass; $request->type = $body->object_kind; $issue = $body->object_attributes; + + $request->labels = $labels; + $request->type = $labelType; + $request->typeID = $labelTypeID; + + $request->project = $body->project->id; + $request->title = $issue->title; + $request->description = $issue->description; + $request->action = $issue->action; + $request->created_at = $issue->created_at; + $request->due_date = $issue->due_date; - $request->labels = $body->labels; - $request->project = $body->project->id; + $request->assignees = $issue->assignee_id; + $request->url = $issue->url; + a($request);exit(); } } From 3e18bc7e1955bbfd977a1ab8c576dd317bd086ed Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 22 Jun 2021 12:17:19 +0800 Subject: [PATCH 083/269] + Add story label func. --- module/gitlab/config.php | 12 +++++++++--- module/gitlab/model.php | 8 ++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index a4bff19207..86296f77f6 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -7,17 +7,23 @@ $config->gitlab->edit->requiredFields = 'name,url,token'; $config->gitlab->taskLabel = new stdclass(); $config->gitlab->taskLabel->name = "zentao task"; -$config->gitlab->taskLabel->description = "task label from zentao"; +$config->gitlab->taskLabel->description = "task label from zentao, do NOT remove this"; $config->gitlab->taskLabel->color = "#0033CC"; $config->gitlab->taskLabel->priority = "0"; $config->gitlab->bugLabel = new stdclass(); $config->gitlab->bugLabel->name = "zentao bug"; -$config->gitlab->bugLabel->description = "bug label from zentao"; +$config->gitlab->bugLabel->description = "bug label from zentao, do NOT remove this"; $config->gitlab->bugLabel->color = "#D10069"; $config->gitlab->bugLabel->priority = "0"; -$config->gitlab->zentaoApiWebhookUrl = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s"; +$config->gitlab->storyLabel = new stdclass(); +$config->gitlab->storyLabel->name = "zentao story"; +$config->gitlab->storyLabel->description = "story label from zentao, do NOT remove this"; +$config->gitlab->storyLabel->color = "##69D100"; +$config->gitlab->storyLabel->priority = "0"; + +config->gitlab->zentaoApiWebhookUrl = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s"; $config->gitlab->zentaoApiWebhookToken = ""; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 86c757c9a9..b167d485fb 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -466,6 +466,7 @@ class gitlabModel extends model { if(strpos($label->name, $this->config->gitlab->taskLabel->name) == 0) return true; if(strpos($label->name, $this->config->gitlab->bugLabel->name) == 0) return true; + if(strpos($label->name, $this->config->gitlab->storyLabel->name) == 0) return true; } return false; @@ -494,9 +495,16 @@ class gitlabModel extends model $bugLabel->description = $this->config->gitlab->bugLabel->description; $bugLabel->color = $this->config->gitlab->bugLabel->color; $bugLabel->priority = $this->config->gitlab->bugLabel->priority; + + $storyLabel = new stdclass(); + $storyLabel->name = $this->config->gitlab->storyLabel->name; + $storyLabel->description = $this->config->gitlab->storyLabel->description; + $storyLabel->color = $this->config->gitlab->storyLabel->color; + $storyLabel->priority = $this->config->gitlab->storyLabel->priority; $this->apiCreateLabel($gitlabID, $projectID, $taskLabel); $this->apiCreateLabel($gitlabID, $projectID, $bugLabel); + $this->apiCreateLabel($gitlabID, $projectID, $storyLabel); return; } From 4542208cf8854a3b257f216692931210fc9e9a39 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Tue, 22 Jun 2021 12:43:15 +0800 Subject: [PATCH 084/269] * Fix bug of module. --- module/gitlab/model.php | 26 ++++++++++++++++++++++++++ module/task/control.php | 32 +++++++++++++++++--------------- module/task/lang/zh-cn.php | 5 +---- module/task/model.php | 9 ++++++--- module/task/view/create.html.php | 2 +- module/user/model.php | 2 ++ 6 files changed, 53 insertions(+), 23 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 7c51dc2f50..1d1ecfc666 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -501,6 +501,32 @@ class gitlabModel extends model return; } + /** + * sync gitlab Issue. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ + public function syncGitlabIssue($taskID, $task, $gitlabID, $projectID) + { + $issue = new stdClass(); + $issue->assignee_id = $taskID; + $issue->created_at = $task->create_at; + $issue->description = $task->description; + $issue->labelType = $task->labelType; + $issue->due_date = $task->data; + $issue->id = $task->project; + $issue->title = $task->title; + $issue->weight = $task->weight; + $issue->labels = $task->labels; + + $response = $this->loadModel('gitlab')->apiCreateIssue($gitlabID, $projectID, $issue); + + return $response; + } + public function apiCreateIssue($gitlabID, $projectID, $issue) { $apiRoot = $this->getApiRoot($gitlabID); diff --git a/module/task/control.php b/module/task/control.php index c86f3c476d..b4678c81b8 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -170,10 +170,11 @@ class task extends control } } - $users = $this->loadModel('user')->getPairs('noclosed|nodeleted'); - $members = $this->loadModel('user')->getTeamMemberPairs($executionID, 'execution', 'nodeleted'); - $showAllModule = isset($this->config->execution->task->allModule) ? $this->config->execution->task->allModule : ''; - $moduleOptionMenu = $this->tree->getTaskOptionMenu($executionID, 0, 0, $showAllModule ? 'allModule' : ''); + $users = $this->loadModel('user')->getPairs('noclosed|nodeleted'); + $members = $this->loadModel('user')->getTeamMemberPairs($executionID, 'execution', 'nodeleted'); + $syncGitlabMembers = $this->loadModel('user')->getTeamMemberPairs($executionID, 'execution', 'nodeleted', 'gitlab'); + $showAllModule = isset($this->config->execution->task->allModule) ? $this->config->execution->task->allModule : ''; + $moduleOptionMenu = $this->tree->getTaskOptionMenu($executionID, 0, 0, $showAllModule ? 'allModule' : ''); /* Fix bug #3381. When the story module is the root module. */ if($storyID) @@ -219,17 +220,18 @@ class task extends control $this->view->showFields = $this->config->task->custom->createFields; $this->view->showAllModule = $showAllModule; - $this->view->title = $title; - $this->view->position = $position; - $this->view->execution = $execution; - $this->view->executions = $this->config->systemMode == 'classic' ? $executions : $this->execution->getByProject(0, 'all', 0, true); - $this->view->task = $task; - $this->view->users = $users; - $this->view->stories = $stories; - $this->view->testStoryIdList = $this->loadModel('story')->getTestStories(array_keys($stories), $execution->id); - $this->view->members = $members; - $this->view->blockID = $blockID; - $this->view->moduleOptionMenu = $moduleOptionMenu; + $this->view->title = $title; + $this->view->position = $position; + $this->view->execution = $execution; + $this->view->syncGitlabMembers = $syncGitlabMembers; + $this->view->executions = $this->config->systemMode == 'classic' ? $executions : $this->execution->getByProject(0, 'all', 0, true); + $this->view->task = $task; + $this->view->users = $users; + $this->view->stories = $stories; + $this->view->testStoryIdList = $this->loadModel('story')->getTestStories(array_keys($stories), $execution->id); + $this->view->members = $members; + $this->view->blockID = $blockID; + $this->view->moduleOptionMenu = $moduleOptionMenu; $this->display(); } diff --git a/module/task/lang/zh-cn.php b/module/task/lang/zh-cn.php index cde88378fe..fb047b2f74 100644 --- a/module/task/lang/zh-cn.php +++ b/module/task/lang/zh-cn.php @@ -67,7 +67,7 @@ $lang->task->storyVersion = "{$lang->SRCommon}版本"; $lang->task->color = '标题颜色'; $lang->task->name = '任务名称'; $lang->task->type = '任务类型'; -$lang->task->sync = '同步平台'; +$lang->task->sync = 'gitlab同步'; $lang->task->pri = '优先级'; $lang->task->mailto = '抄送给'; $lang->task->estimate = '最初预计'; @@ -164,9 +164,6 @@ $lang->task->typeList['ui'] = '界面'; $lang->task->typeList['affair'] = '事务'; $lang->task->typeList['misc'] = '其他'; -$lang->task->syncList[''] = ''; -$lang->task->syncList['gitlab'] = 'gitlab'; - $lang->task->priList[0] = ''; $lang->task->priList[1] = '1'; $lang->task->priList[2] = '2'; diff --git a/module/task/model.php b/module/task/model.php index 1c52542220..d15807aa76 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -64,10 +64,10 @@ class taskModel extends model ->cleanINT('execution,story,module') ->stripTags($this->config->task->editor->create['id'], $this->config->allowedTags) ->join('mailto', ',') - ->remove('after,files,labels,assignedTo,uid,storyEstimate,storyDesc,storyPri,team,teamEstimate,teamMember,multiple,teams,contactListMenu,selectTestStory,testStory,testPri,testEstStarted,testDeadline,testAssignedTo,testEstimate') + ->remove('after,files,labels,assignedTo,uid,storyEstimate,storyDesc,storyPri,team,teamEstimate,teamMember,multiple,teams,contactListMenu,selectTestStory,testStory,testPri,testEstStarted,testDeadline,testAssignedTo,testEstimate,sync') ->add('version', 1) ->get(); - + if($task->type != 'test') $this->post->set('selectTestStory', 0); foreach($this->post->assignedTo as $assignedTo) @@ -115,11 +115,14 @@ class taskModel extends model ->checkIF($task->estimate != '', 'estimate', 'float') ->checkIF(!helper::isZeroDate($task->deadline), 'deadline', 'ge', $task->estStarted) ->exec(); - + if(dao::isError()) return false; $taskID = $this->dao->lastInsertID(); + /*sync gitlab Issue*/ + $this->loadModel('gitlab')->syncGitlabIssue($taskID, $gitlabID, $projectID); + /* Mark design version.*/ if(isset($task->design) && !empty($task->design)) { diff --git a/module/task/view/create.html.php b/module/task/view/create.html.php index 1bcb421ffe..9eaa508cf2 100644 --- a/module/task/view/create.html.php +++ b/module/task/view/create.html.php @@ -47,7 +47,7 @@ - + diff --git a/module/user/model.php b/module/user/model.php index 218cb201bc..a84b0998f3 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -2395,7 +2395,9 @@ class userModel extends model $keyField = strpos($params, 'useid') !== false ? 'id' : 'account'; $users = $this->dao->select("t2.id, t2.account, t2.realname")->from(TABLE_TEAM)->alias('t1') ->leftJoin(TABLE_USER)->alias('t2')->on('t1.account = t2.account') + ->beginIF(!empty($sync)) ->leftJoin(TABLE_OAUTH)->alias('t3')->on('t2.account = t3.account') + ->fi() ->where('t1.root')->eq((int)$objectID) ->andWhere('t1.type')->eq($type) ->beginIF($params == 'nodeleted' or empty($this->config->user->showDeleted)) From 925d5f72b0031a58c9d72bcaa467d55ea99274c0 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Tue, 22 Jun 2021 13:50:03 +0800 Subject: [PATCH 085/269] * Add gitlab->zentaoLabel. --- module/gitlab/config.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index a4bff19207..a6af4fe97a 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -1,9 +1,11 @@ gitlab->create = new stdclass(); -$config->gitlab->edit = new stdclass(); - $config->gitlab->create->requiredFields = 'name,url,token'; -$config->gitlab->edit->requiredFields = 'name,url,token'; + +$config->gitlab->edit = new stdclass(); +$config->gitlab->edit->requiredFields = 'name,url,token'; + +$config->gitlab->zentaoLabel = 'Zentao'; $config->gitlab->taskLabel = new stdclass(); $config->gitlab->taskLabel->name = "zentao task"; @@ -19,5 +21,3 @@ $config->gitlab->bugLabel->priority = "0"; $config->gitlab->zentaoApiWebhookUrl = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s"; $config->gitlab->zentaoApiWebhookToken = ""; - - From cd65a3a41ffadf9faa86724e04893d72fa425c7a Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Tue, 22 Jun 2021 13:54:02 +0800 Subject: [PATCH 086/269] * Add parse gitlab issue functions. --- module/gitlab/model.php | 90 ++++++++++++++++++++++++++++++++++------- 1 file changed, 75 insertions(+), 15 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 7c51dc2f50..84a4a41176 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -135,7 +135,7 @@ class gitlabModel extends model if($gitlabUser->email == $zentaoUser->email) $matches->emails[$gitlabUser->email][] = $zentaoUser->account; } } - + $bindedUsers = $this->dao->select('openID,account') ->from(TABLE_OAUTH) ->where('providerType')->eq('gitlab') @@ -156,7 +156,7 @@ class gitlabModel extends model if(isset($matches->accounts[$gitlabUser->account])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->accounts[$gitlabUser->account]); if(isset($matches->emails[$gitlabUser->email])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->emails[$gitlabUser->email]); if(isset($matches->names[$gitlabUser->realname])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->names[$gitlabUser->realname]); - + $matchedZentaoUsers = array_unique($matchedZentaoUsers); if(count($matchedZentaoUsers) == 1) { @@ -239,13 +239,13 @@ class gitlabModel extends model $projectID = array(); foreach($productIDs as $project) $projectID[$project->id] = $project->program; - $gitlabAssociat = new stdclass; - $gitlabAssociat->execution = 0; - $gitlabAssociat->AVersion = 0; - $gitlabAssociat->relation = 'interrated'; - $gitlabAssociat->BVersion = 0; - $gitlabAssociat->extra = 0; - $gitlabAssociat->BID = $gitlabID; + $gitlabAssociat = new stdclass; + $gitlabAssociat->execution = 0; + $gitlabAssociat->AVersion = 0; + $gitlabAssociat->relation = 'interrated'; + $gitlabAssociat->BVersion = 0; + $gitlabAssociat->extra = 0; + $gitlabAssociat->BID = $gitlabID; foreach($products as $index => $prodcut) { @@ -253,7 +253,7 @@ class gitlabModel extends model $gitlabAssociat->Project = $projectID[$prodcut]; $gitlabAssociat->Product = $prodcut; - $this->dao->replace(TABLE_RELATION)->data($gitlabAssociat)->exec(); + $this->dao->replace(TABLE_RELATION)->data($gitlabAssociat)->exec(); } return true; } @@ -269,7 +269,7 @@ class gitlabModel extends model public function createWebhook($products, $gitlabID, $projectID) { $urls = $this->getWebhookUrls($gitlabID, $projectID); - + foreach($products as $index => $product) { $url = sprintf($this->config->gitlab->zentaoApiWebhookUrl, commonModel::getSysURL(), $product, $gitlabID, $projectID); @@ -348,7 +348,7 @@ class gitlabModel extends model public function apiCreateHook($gitlabID, $projectID, $url, $token) { $apiRoot = $this->getApiRoot($gitlabID); - + $postData = new stdclass; $postData->enable_ssl_verification = "false"; $postData->issues_events = "true"; @@ -394,7 +394,7 @@ class gitlabModel extends model public function apiUpdateHook($gitlabID, $projectID, $hookID) { $apiRoot = $this->getApiRoot($gitlabID); - + $postData = new stdclass; $postData->enable_ssl_verification = "false"; $postData->issues_events = "true"; @@ -494,7 +494,7 @@ class gitlabModel extends model $bugLabel->description = $this->config->gitlab->bugLabel->description; $bugLabel->color = $this->config->gitlab->bugLabel->color; $bugLabel->priority = $this->config->gitlab->bugLabel->priority; - + $this->apiCreateLabel($gitlabID, $projectID, $taskLabel); $this->apiCreateLabel($gitlabID, $projectID, $bugLabel); @@ -536,9 +536,69 @@ class gitlabModel extends model $request = new stdclass; $request->type = $body->object_kind; $issue = $body->object_attributes; - + $request->labels = $body->labels; $request->project = $body->project->id; } + public function parseNoteWebhook($body) + { + $request = new stdclass; + $request->type = $body->object_kind; + if(isset($body->issue)) $body->issue = $this->parseIssue($body->issue); + + $request->labels = $body->labels; + $request->project = $body->project->id; + } + + /** + * Parse zentao object from labels. + * + * @param array $labels + * @access public + * @return object|false + */ + public function parseObjectFromLabels($labels) + { + foreach($body->labels as $label) + { + if($label->title == $config->gitlab->zentaoLabel) + { + $object = json_decode($label->description); + if(!$object or !isset($object->type)) continue; + return $object; + } + } + return false; + } + + /** + * Parse issue from gitlab. + * + * @param object $issue + * @access public + * @return object + */ + public function parseIssue($issue) + { + $object = $this->parseObjectFromLabels($issue->labels); + if(!$object) return false; + if($object->type == 'task') $object->object = $this->issue2Task($issue); + if($object->type == 'story') $object->object = $this->issue2Story($issue); + if($object->type == 'bug') $object->object = $this->issue2Bug($issue); + return $object; + } + + public function issue2Task($issue) + { + } + + public function issue2Story($issue) + { + } + + public function issue2Bug($issue) + { + + } } From 35d95e043b74f55ffb213b0ee8d3105d7d203ffb Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 22 Jun 2021 13:54:29 +0800 Subject: [PATCH 087/269] * Correct bad spells. --- module/gitlab/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 86296f77f6..a1cbc5ee08 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -23,7 +23,7 @@ $config->gitlab->storyLabel->description = "story label from zentao, do NOT rem $config->gitlab->storyLabel->color = "##69D100"; $config->gitlab->storyLabel->priority = "0"; -config->gitlab->zentaoApiWebhookUrl = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s"; +$config->gitlab->zentaoApiWebhookUrl = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s"; $config->gitlab->zentaoApiWebhookToken = ""; From 3c2450701510a365be0b16792bb9992c2643bf0b Mon Sep 17 00:00:00 2001 From: lichengjun Date: Tue, 22 Jun 2021 13:59:31 +0800 Subject: [PATCH 088/269] * fix gitlab config bug. --- module/gitlab/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 86296f77f6..a1cbc5ee08 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -23,7 +23,7 @@ $config->gitlab->storyLabel->description = "story label from zentao, do NOT rem $config->gitlab->storyLabel->color = "##69D100"; $config->gitlab->storyLabel->priority = "0"; -config->gitlab->zentaoApiWebhookUrl = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s"; +$config->gitlab->zentaoApiWebhookUrl = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s"; $config->gitlab->zentaoApiWebhookToken = ""; From 5a36acb96e93f6e5f7ecf025b88ee70fe10b1316 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 22 Jun 2021 15:10:58 +0800 Subject: [PATCH 089/269] + Add get account name in zentaopms. --- module/gitlab/model.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 1d8fa02159..2fd8bf87a9 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -648,4 +648,24 @@ class gitlabModel extends model { } + + /** + * Get account name in zentao sys. + * + * @param int $gitlabID + * @param int $userID + * @access public + * @return string|false + */ + public function getAccountName($gitlabID, $userID) + { + $account = $this->dao->select("account") + ->from(TABLE_OAUTH) + ->where('providerType')->eq('gitlab') + ->andwhere('providerID')->eq($gitlabID) + ->andwhere('openID')->eq($userID) + ->fetch(); + if(!dao::isError()) return $account->account; + return false; + } } From ffa7de4e72e0839fd9850df200dafe6135606316 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 22 Jun 2021 16:09:16 +0800 Subject: [PATCH 090/269] * Rename func for getting account in zentaopms and etc. --- module/gitlab/model.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 2fd8bf87a9..0184bff48c 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -650,22 +650,20 @@ class gitlabModel extends model } /** - * Get account name in zentao sys. + * Get account in zentaopms. * * @param int $gitlabID * @param int $userID * @access public * @return string|false */ - public function getAccountName($gitlabID, $userID) + public function getAccount($gitlabID, $userID) { - $account = $this->dao->select("account") - ->from(TABLE_OAUTH) - ->where('providerType')->eq('gitlab') - ->andwhere('providerID')->eq($gitlabID) - ->andwhere('openID')->eq($userID) - ->fetch(); - if(!dao::isError()) return $account->account; - return false; + retrun $this->dao->select('account') + ->from(TABLE_OAUTH) + ->where('providerType')->eq('gitlab') + ->andwhere('providerID')->eq($gitlabID) + ->andwhere('openID')->eq($userID) + ->fetch('account'); } } From 7975f38ecaf2fdc2653624d21da8e03448611191 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 22 Jun 2021 16:10:11 +0800 Subject: [PATCH 091/269] * Corrent bad spells for getting account in zentaopms and etc. --- module/gitlab/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 0184bff48c..1faf64c76b 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -659,7 +659,7 @@ class gitlabModel extends model */ public function getAccount($gitlabID, $userID) { - retrun $this->dao->select('account') + return $this->dao->select('account') ->from(TABLE_OAUTH) ->where('providerType')->eq('gitlab') ->andwhere('providerID')->eq($gitlabID) From d5b0d363306651869bd6c09d62c8cbecde20005f Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Tue, 22 Jun 2021 17:27:12 +0800 Subject: [PATCH 092/269] * Rename saveRelation. --- module/gitlab/config.php | 24 +++++++++++++++++ module/gitlab/model.php | 58 ++++++++++++++++++---------------------- 2 files changed, 50 insertions(+), 32 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 19d3542e97..67dea62ab6 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -7,6 +7,9 @@ $config->gitlab->edit->requiredFields = 'name,url,token'; $config->gitlab->zentaoLabel = 'Zentao'; +$config->gitlab->actions = array(); +$config->gitlab->actions['issue'] = array(); + $config->gitlab->taskLabel = new stdclass(); $config->gitlab->taskLabel->name = "zentao task"; $config->gitlab->taskLabel->description = "task label from zentao, do NOT remove this"; @@ -27,3 +30,24 @@ $config->gitlab->storyLabel->priority = "0"; $config->gitlab->zentaoApiWebhookUrl = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s"; $config->gitlab->zentaoApiWebhookToken = ""; + +$config->gitlab->maps = new stdclass; +$config->gitlab->maps->task = array(); +$config->gitlab->maps->task['execution'] = 'execution'; +$config->gitlab->maps->task['name'] = 'title'; +$config->gitlab->maps->task['desc'] = 'description'; +$config->gitlab->maps->task['deadline'] = 'due_date'; + +$config->gitlab->maps->task['openedBy'] = 'due_date'; +$config->gitlab->maps->task['openedDate'] = 'created_at'; +$config->gitlab->maps->task['assignedTo'] = 'due_date'; +$config->gitlab->maps->task['closedBy'] = 'due_date'; +$config->gitlab->maps->task['closedDate'] = 'due_date'; +$config->gitlab->maps->task['finishedDate'] = 'closed_at'; +$config->gitlab->maps->task['lastEditedDate'] = 'last_edited_at'; +$config->gitlab->maps->task['deadline'] = 'due_date'; + +$config->gitlab->issueOptions = new stdclass; +$config->gitlab->issueOptions->task['type'] = 'devel'; +$config->gitlab->issueOptions->task['pri'] = '3'; +$config->gitlab->issueOptions->task['status'] = array(); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 2fd8bf87a9..d458546e7a 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -232,28 +232,26 @@ class gitlabModel extends model * @access public * @return void */ - public function createAssociat($products, $gitlabID, $gitlabProjectID) + public function saveRelation($products, $gitlabID, $gitlabProjectID) { - $productIDs = $this->dao->select('id,program')->from(TABLE_PRODUCT)->fetchAll(); + $programs = $this->dao->select('id,program')->from(TABLE_PRODUCT)->where('id')->in($products)->fetchPairs(); - $projectID = array(); - foreach($productIDs as $project) $projectID[$project->id] = $project->program; + $relation = new stdclass; + $relation->execution = 0; + $relation->AType = 'gitlab'; + $relation->AID = $gitlabID; + $relation->AVersion = ''; + $relation->relation = 'interrated'; + $relation->BType = 'gitlabProject'; + $relation->BID = $gitlabProjectID; + $relation->BVersion = ''; + $relation->extra = ''; - $gitlabAssociat = new stdclass; - $gitlabAssociat->execution = 0; - $gitlabAssociat->AVersion = 0; - $gitlabAssociat->relation = 'interrated'; - $gitlabAssociat->BVersion = 0; - $gitlabAssociat->extra = 0; - $gitlabAssociat->BID = $gitlabID; - - foreach($products as $index => $prodcut) + foreach($products as $product) { - $gitlabAssociat->BType = $this->getprojectpairs($gitlabID)[$gitlabProjectID]; - $gitlabAssociat->Project = $projectID[$prodcut]; - $gitlabAssociat->Product = $prodcut; - - $this->dao->replace(TABLE_RELATION)->data($gitlabAssociat)->exec(); + $relation->project = zget($programs, $product, 0); + $relation->product = $product; + $this->dao->replace(TABLE_RELATION)->data($relation)->exec(); } return true; } @@ -567,12 +565,10 @@ class gitlabModel extends model public function parseIssueWebhook($body) { - $request = new stdclass; - $request->type = $body->object_kind; - $issue = $body->object_attributes; - - $request->labels = $body->labels; - $request->project = $body->project->id; + $issue = new stdclass; + $issue->action = $body->object_attributes->action . $body->object_kind; + $issue->issue = $body->object_attributes; + $object = $this->parseObjectFromLabels($issue->labels); } public function parseNoteWebhook($body) @@ -659,13 +655,11 @@ class gitlabModel extends model */ public function getAccountName($gitlabID, $userID) { - $account = $this->dao->select("account") - ->from(TABLE_OAUTH) - ->where('providerType')->eq('gitlab') - ->andwhere('providerID')->eq($gitlabID) - ->andwhere('openID')->eq($userID) - ->fetch(); - if(!dao::isError()) return $account->account; - return false; + return $this->dao->select("account") + ->from(TABLE_OAUTH) + ->where('providerType')->eq('gitlab') + ->andwhere('providerID')->eq($gitlabID) + ->andwhere('openID')->eq($userID) + ->fetch('account'); } } From fca78aed23fa6c43e73f296a91633e2eabf0aea3 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Tue, 22 Jun 2021 17:45:51 +0800 Subject: [PATCH 093/269] * Add get user pairs functions. --- module/gitlab/model.php | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index afd50000f2..33dc95460e 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -47,6 +47,30 @@ class gitlabModel extends model return $this->loadModel('pipeline')->getPairs('gitlab'); } + /** + * Get gitlab user id zentao account pairs of one gitlab. + * + * @param int $gitlab + * @access public + * @return void + */ + public function getUserIdAccountPairs($gitlab) + { + return $this->dao->select('id,account')->from(TABLE_OAUTH)->where('providerType')->eq('gitlab')->andwhere('providerID')->eq($gitlabID)->fetchPairs(); + } + + /** + * Get zentao account gitlab user id pairs of one gitlab. + * + * @param int $gitlab + * @access public + * @return void + */ + public function getUserAccountIdPairs($gitlab) + { + return $this->dao->select('account,id')->from(TABLE_OAUTH)->where('providerType')->eq('gitlab')->andwhere('providerID')->eq($gitlabID)->fetchPairs(); + } + /** * Create a gitlab. * @@ -556,14 +580,14 @@ class gitlabModel extends model return $response; } - public function parseWebhookBody($body) + public function webhookParseBody($body) { $type = zget($body, 'object_kind', ''); - if(!$type or !is_callable(array($this, "parse{$type}Webhook"))) return false; - return call_user_func_array(array($this, "parse{$type}Webhook"), array('body' => $body)); + if(!$type or !is_callable(array($this, "webhookParse{$type}"))) return false; + $result = call_user_func_array(array($this, "webhookParse{$type}Webhook"), array('body' => $body)); } - public function parseIssueWebhook($body) + public function WebhookParseIssue($body) { $issue = new stdclass; $issue->action = $body->object_attributes->action . $body->object_kind; @@ -571,7 +595,7 @@ class gitlabModel extends model $object = $this->parseObjectFromLabels($issue->labels); } - public function parseNoteWebhook($body) + public function webhookParseNote($body) { $request = new stdclass; $request->type = $body->object_kind; @@ -601,7 +625,7 @@ class gitlabModel extends model * @access public * @return object|false */ - public function parseObjectFromLabels($labels) + public function webhookParseZentaoLabel($labels) { foreach($body->labels as $label) { From d4de46f619369ff280a6fcba4704238013091615 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Tue, 22 Jun 2021 17:46:21 +0800 Subject: [PATCH 094/269] * rename parseWebhookBody to webhookParseBody. --- module/gitlab/control.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 4ee4ac3b1d..546948c484 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -214,7 +214,8 @@ class gitlab extends control $json = '{"object_kind":"note","event_type":"note","user":{"id":1,"name":"Administrator","username":"root","avatar_url":"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon","email":"admin@example.com"},"project_id":36,"project":{"id":36,"name":"zenops202106dgd","description":"repo for dingguodong dev env","web_url":"http://192.168.1.161:51080/root/zenops202106dgd","avatar_url":null,"git_ssh_url":"ssh://git@192.168.1.161:51022/root/zenops202106dgd.git","git_http_url":"http://192.168.1.161:51080/root/zenops202106dgd.git","namespace":"Administrator","visibility_level":0,"path_with_namespace":"root/zenops202106dgd","default_branch":"master","ci_config_path":null,"homepage":"http://192.168.1.161:51080/root/zenops202106dgd","url":"ssh://git@192.168.1.161:51022/root/zenops202106dgd.git","ssh_url":"ssh://git@192.168.1.161:51022/root/zenops202106dgd.git","http_url":"http://192.168.1.161:51080/root/zenops202106dgd.git"},"object_attributes":{"attachment":null,"author_id":1,"change_position":null,"commit_id":null,"created_at":"2021-06-22 03:04:00 UTC","discussion_id":"1e66ea56b811ac13502252c62e1d22a6ddcf4340","id":705,"line_code":null,"note":"124ds q ew 1234 142dsf ssdfgsdg","noteable_id":32,"noteable_type":"Issue","original_position":null,"position":null,"project_id":36,"resolved_at":null,"resolved_by_id":null,"resolved_by_push":null,"st_diff":null,"system":false,"type":null,"updated_at":"2021-06-22 03:04:00 UTC","updated_by_id":null,"description":"124ds q ew 1234 142dsf ssdfgsdg","url":"http://192.168.1.161:51080/root/zenops202106dgd/-/issues/2#note_705"},"repository":{"name":"zenops202106dgd","url":"ssh://git@192.168.1.161:51022/root/zenops202106dgd.git","description":"repo for dingguodong dev env","homepage":"http://192.168.1.161:51080/root/zenops202106dgd"},"issue":{"author_id":1,"closed_at":null,"confidential":false,"created_at":"2021-06-16 10:52:00 UTC","description":"the issue description","discussion_locked":null,"due_date":null,"id":32,"iid":2,"last_edited_at":null,"last_edited_by_id":null,"milestone_id":null,"moved_to_id":null,"duplicated_to_id":null,"project_id":36,"relative_position":1026,"state_id":1,"time_estimate":0,"title":"test issue","updated_at":"2021-06-22 03:04:00 UTC","updated_by_id":1,"url":"http://192.168.1.161:51080/root/zenops202106dgd/-/issues/2","total_time_spent":0,"human_total_time_spent":null,"human_time_estimate":null,"assignee_ids":[],"assignee_id":null,"labels":[{"id":38,"title":"zentao task","color":"#0033CC","project_id":36,"created_at":"2021-06-16 12:04:23 UTC","updated_at":"2021-06-16 12:04:23 UTC","template":false,"description":"task label from zentao","type":"ProjectLabel","group_id":null},{"id":40,"title":"zentao task : 121","color":"#428BCA","project_id":36,"created_at":"2021-06-21 08:58:17 UTC","updated_at":"2021-06-21 08:58:17 UTC","template":false,"description":"121","type":"ProjectLabel","group_id":null}],"state":"opened"}}'; //$json = file_get_contents('php://input'); $requestBody = json_decode($json); - $request = $this->gitlab->parseWebhookBody($requestBody); + $request = $this->gitlab->webhookParseBody($requestBody); + exit; switch($request->type) From 8defd7528f0882c957097ad3e8b6130188e552d8 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Wed, 23 Jun 2021 13:44:01 +0800 Subject: [PATCH 095/269] * Add code for gitlab. --- module/common/model.php | 1 + module/execution/model.php | 4 +++- module/gitlab/model.php | 19 +++++++++++++++++++ module/task/control.php | 7 ++++--- module/task/view/create.html.php | 8 ++++---- module/user/model.php | 8 +------- 6 files changed, 32 insertions(+), 15 deletions(-) diff --git a/module/common/model.php b/module/common/model.php index 28a7c62617..242e393959 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -2233,6 +2233,7 @@ EOD; $response = curl_exec($curl); $errors = curl_error($curl); + curl_close($curl); $logFile = $app->getLogRoot() . 'saas.'. date('Ymd') . '.log.php'; diff --git a/module/execution/model.php b/module/execution/model.php index dcbb5b83a0..a6f82063d6 100644 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -1548,7 +1548,7 @@ class executionModel extends model * @access public * @return array */ - public function getProducts($executionID, $withBranch = true) + public function getProducts($executionID, $withBranch = true, $gitlab = false) { if(defined('TUTORIAL')) { @@ -1556,12 +1556,14 @@ class executionModel extends model return $this->loadModel('tutorial')->getExecutionProducts(); } + $query = $this->dao->select('t2.id, t2.name, t2.type, t1.branch, t1.plan')->from(TABLE_PROJECTPRODUCT)->alias('t1') ->leftJoin(TABLE_PRODUCT)->alias('t2') ->on('t1.product = t2.id') ->where('t1.project')->eq((int)$executionID) ->andWhere('t2.deleted')->eq(0) ->beginIF(!$this->app->user->admin)->andWhere('t2.id')->in($this->app->user->view->products)->fi(); + if($gitlab) return implode(',' ,$query->fetchPairs('id','id')); if(!$withBranch) return $query->fetchPairs('id', 'name'); return $query->fetchAll('id'); } diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 33dc95460e..a2cb544c9d 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -248,6 +248,25 @@ class gitlabModel extends model return $gitlab_url; } + /** + * Bind gitlab project. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ + public function bindGitlabProject($executionID) + { + $products = $this->loadModel('execution')->getProducts($executionID, false, 'gitlab'); + + $bindGitlabAIDS = $this->dao->select('AID')->from(TABLE_RELATION)->where('product')->in($products)->fetchPairs(); + + $nameList = $this->dao->select('id,name')->from(TABLE_PIPELINE)->where('id')->in(implode(',' ,$bindGitlabAIDS))->fetchPairs(); + + return $nameList; + } + /** * Create relationship between zentao product and gitlab project. * diff --git a/module/task/control.php b/module/task/control.php index b4678c81b8..5fa0a7bb61 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -172,7 +172,6 @@ class task extends control $users = $this->loadModel('user')->getPairs('noclosed|nodeleted'); $members = $this->loadModel('user')->getTeamMemberPairs($executionID, 'execution', 'nodeleted'); - $syncGitlabMembers = $this->loadModel('user')->getTeamMemberPairs($executionID, 'execution', 'nodeleted', 'gitlab'); $showAllModule = isset($this->config->execution->task->allModule) ? $this->config->execution->task->allModule : ''; $moduleOptionMenu = $this->tree->getTaskOptionMenu($executionID, 0, 0, $showAllModule ? 'allModule' : ''); @@ -211,11 +210,14 @@ class task extends control $position[] = html::a($taskLink, $execution->name); $position[] = $this->lang->task->common; $position[] = $this->lang->task->create; - + /* Set Custom*/ foreach(explode(',', $this->config->task->customCreateFields) as $field) $customFields[$field] = $this->lang->task->$field; if($execution->type == 'ops') unset($customFields['story']); + /* */ + $this->loadModel('gitlab')->bindGitlabProject($executionID); + $this->view->customFields = $customFields; $this->view->showFields = $this->config->task->custom->createFields; $this->view->showAllModule = $showAllModule; @@ -223,7 +225,6 @@ class task extends control $this->view->title = $title; $this->view->position = $position; $this->view->execution = $execution; - $this->view->syncGitlabMembers = $syncGitlabMembers; $this->view->executions = $this->config->systemMode == 'classic' ? $executions : $this->execution->getByProject(0, 'all', 0, true); $this->view->task = $task; $this->view->users = $users; diff --git a/module/task/view/create.html.php b/module/task/view/create.html.php index 9eaa508cf2..188714ab0c 100644 --- a/module/task/view/create.html.php +++ b/module/task/view/create.html.php @@ -45,10 +45,6 @@ - - - - @@ -245,6 +241,10 @@ + + + + diff --git a/module/user/model.php b/module/user/model.php index a84b0998f3..f2b301d7af 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -2388,24 +2388,18 @@ class userModel extends model * @access public * @return array */ - public function getTeamMemberPairs($objectID, $type = 'project', $params = '', $usersToAppended = '', $sync = '') + public function getTeamMemberPairs($objectID, $type = 'project', $params = '', $usersToAppended = '') { if(defined('TUTORIAL')) return $this->loadModel('tutorial')->getTeamMembersPairs(); $keyField = strpos($params, 'useid') !== false ? 'id' : 'account'; $users = $this->dao->select("t2.id, t2.account, t2.realname")->from(TABLE_TEAM)->alias('t1') ->leftJoin(TABLE_USER)->alias('t2')->on('t1.account = t2.account') - ->beginIF(!empty($sync)) - ->leftJoin(TABLE_OAUTH)->alias('t3')->on('t2.account = t3.account') - ->fi() ->where('t1.root')->eq((int)$objectID) ->andWhere('t1.type')->eq($type) ->beginIF($params == 'nodeleted' or empty($this->config->user->showDeleted)) ->andWhere('t2.deleted')->eq(0) ->fi() - ->beginIF(!empty($sync)) - ->andWhere('providerType')->eq($sync) - ->fi() ->fetchAll($keyField); if($usersToAppended) $users += $this->dao->select("id, account, realname")->from(TABLE_USER)->where('account')->in($usersToAppended)->fetchAll($keyField); From 953fec21f988946a1fda4ca1d059346f23449f33 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Wed, 23 Jun 2021 15:14:28 +0800 Subject: [PATCH 096/269] * Add getProjectsByExecution function. --- module/gitlab/model.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index a2cb544c9d..4429bf8e4d 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -254,17 +254,20 @@ class gitlabModel extends model * @param int $gitlabID * @param int $projectID * @access public - * @return void + * @return array */ - public function bindGitlabProject($executionID) + public function getProjectsByExecution($executionID) { - $products = $this->loadModel('execution')->getProducts($executionID, false, 'gitlab'); + $products = $this->loadModel('execution')->getProducts($executionID, false); + $productIdList = array_keys($products); - $bindGitlabAIDS = $this->dao->select('AID')->from(TABLE_RELATION)->where('product')->in($products)->fetchPairs(); - - $nameList = $this->dao->select('id,name')->from(TABLE_PIPELINE)->where('id')->in(implode(',' ,$bindGitlabAIDS))->fetchPairs(); - - return $nameList; + return $this->dao->select('AID,BID as gitlabProject') + ->from(TABLE_RELATION) + ->where('relation')->eq('interrated') + ->andWhere('AType')->eq('gitlab') + ->andWhere('BType')->eq('gitlabProject') + ->andWhere('product')->in($productIdList) + ->fetchGroup('AID'); } /** From 69764ec2e28f06e590369cb3cbaede2e6885c2ba Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Wed, 23 Jun 2021 15:14:56 +0800 Subject: [PATCH 097/269] * Remove gitlab param from getProducts function. --- module/execution/model.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/module/execution/model.php b/module/execution/model.php index a6f82063d6..1d723041dd 100644 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -1545,10 +1545,11 @@ class executionModel extends model * Get products of a execution. * * @param int $executionID + * @param bool $withBranch * @access public * @return array */ - public function getProducts($executionID, $withBranch = true, $gitlab = false) + public function getProducts($executionID, $withBranch = true) { if(defined('TUTORIAL')) { @@ -1556,14 +1557,12 @@ class executionModel extends model return $this->loadModel('tutorial')->getExecutionProducts(); } - $query = $this->dao->select('t2.id, t2.name, t2.type, t1.branch, t1.plan')->from(TABLE_PROJECTPRODUCT)->alias('t1') ->leftJoin(TABLE_PRODUCT)->alias('t2') ->on('t1.product = t2.id') ->where('t1.project')->eq((int)$executionID) ->andWhere('t2.deleted')->eq(0) ->beginIF(!$this->app->user->admin)->andWhere('t2.id')->in($this->app->user->view->products)->fi(); - if($gitlab) return implode(',' ,$query->fetchPairs('id','id')); if(!$withBranch) return $query->fetchPairs('id', 'name'); return $query->fetchAll('id'); } From cd891c90cb7629468380e6c18bdc58665f074e00 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Wed, 23 Jun 2021 15:15:36 +0800 Subject: [PATCH 098/269] * Fix save relation of gitlab's project and product bug. --- module/repo/model.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/module/repo/model.php b/module/repo/model.php index 9d4bfb0eb5..973bab455a 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -293,16 +293,12 @@ class repoModel extends model $this->rmClientVersionFile(); + if($repo->SCM == 'Gitlab') $this->loadModel("gitlab")->saveRelation($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); if($repo->path != $data->path) { $this->dao->delete()->from(TABLE_REPOHISTORY)->where('repo')->eq($id)->exec(); $this->dao->delete()->from(TABLE_REPOFILES)->where('repo')->eq($id)->exec(); - if($repo->SCM == 'Gitlab') - { - $this->loadModel("gitlab")->createWebhook($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); - $this->loadModel("gitlab")->saveRelation($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); - - } + if($repo->SCM == 'Gitlab') $this->loadModel("gitlab")->createWebhook($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); return false; } From 2891589492e546ce312cceb23e790174ee69f579 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Wed, 23 Jun 2021 15:16:54 +0800 Subject: [PATCH 099/269] * Show gitlab and gitlab projects selector in create task view. --- module/repo/control.php | 7 ++++--- module/task/control.php | 10 +++++++--- module/task/js/create.js | 17 +++++++++++++++++ module/task/lang/zh-cn.php | 2 +- module/task/view/create.html.php | 8 ++++++-- 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/module/repo/control.php b/module/repo/control.php index b759f05aeb..ea6137605b 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -1113,15 +1113,16 @@ class repo extends control * @access public * @return void */ - public function ajaxGetGitlabProjects($host) + public function ajaxGetGitlabProjects($host, $projectIdList) { $projects = $this->loadModel('gitlab')->apiGetProjects($host); - + if(!$projects) $this->send(array('message' => array())); - + $projectIdList = explode(',', $projectIdList); $options = ""; foreach($projects as $project) { + if($project and !in_array($project->id, $projectIdList)) continue; $options .= ""; } die($options); diff --git a/module/task/control.php b/module/task/control.php index 5fa0a7bb61..773f58e46c 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -215,9 +215,12 @@ class task extends control foreach(explode(',', $this->config->task->customCreateFields) as $field) $customFields[$field] = $this->lang->task->$field; if($execution->type == 'ops') unset($customFields['story']); - /* */ - $this->loadModel('gitlab')->bindGitlabProject($executionID); - + $allGitlabs = $this->loadModel('gitlab')->getPairs(); + $gitlabProjects = $this->loadModel('gitlab')->getProjectsByExecution($executionID); + foreach($allGitlabs as $id => $name) if($id and !isset($gitlabProjects[$id])) unset($allGitlabs[$id]); + $this->view->gitlabList = $allGitlabs; + $this->view->gitlabProjects = $gitlabProjects; + $this->view->customFields = $customFields; $this->view->showFields = $this->config->task->custom->createFields; $this->view->showAllModule = $showAllModule; @@ -233,6 +236,7 @@ class task extends control $this->view->members = $members; $this->view->blockID = $blockID; $this->view->moduleOptionMenu = $moduleOptionMenu; + $this->display(); } diff --git a/module/task/js/create.js b/module/task/js/create.js index 71bb2b8f52..da042ebfd4 100644 --- a/module/task/js/create.js +++ b/module/task/js/create.js @@ -467,6 +467,23 @@ $(document).ready(function() $('#moduleIdBox #module').val(moduleID).attr('onchange', "setStories(this.value, " + executionID + ")").chosen(); }); }); + + $('#gitlab').change(function() + { + host = $('#gitlab').val(); + if(host == '') return false; + projects = ''; + $.each(gitlabProjects[host], function(id, obj){projects = projects + ',' + obj.gitlabProject}); + url = createLink('repo', 'ajaxgetgitlabprojects', "host=" + host + "&projects=" + projects); + + $.get(url, function(response) + { + $('#gitlabProject').html('').append(response); + $('#gitlabProject').chosen().trigger("chosen:updated");; + }); + + }); + }); $(document).on('click', '#testStory_chosen,#story_chosen', function() diff --git a/module/task/lang/zh-cn.php b/module/task/lang/zh-cn.php index fb047b2f74..a0119d0fe1 100644 --- a/module/task/lang/zh-cn.php +++ b/module/task/lang/zh-cn.php @@ -67,7 +67,7 @@ $lang->task->storyVersion = "{$lang->SRCommon}版本"; $lang->task->color = '标题颜色'; $lang->task->name = '任务名称'; $lang->task->type = '任务类型'; -$lang->task->sync = 'gitlab同步'; +$lang->task->sync2Gitlab = '同步到Gitlab'; $lang->task->pri = '优先级'; $lang->task->mailto = '抄送给'; $lang->task->estimate = '最初预计'; diff --git a/module/task/view/create.html.php b/module/task/view/create.html.php index 188714ab0c..5f9ffd2e92 100644 --- a/module/task/view/create.html.php +++ b/module/task/view/create.html.php @@ -15,6 +15,7 @@ id));?> +
@@ -241,10 +242,13 @@
+ - - + + + + From b9eda36d99e6cdef0f7ad86bd4fb631e8fddf005 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 23 Jun 2021 15:17:36 +0800 Subject: [PATCH 100/269] * Put product into the unique key relation. --- db/zentao.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/zentao.sql b/db/zentao.sql index adcd1b45d3..7146cad404 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -750,7 +750,7 @@ CREATE TABLE IF NOT EXISTS `zt_relation` ( `BVersion` char(30) NOT NULL, `extra` char(30) NOT NULL, PRIMARY KEY (`id`), - UNIQUE KEY `relation` (`relation`,`AType`,`BType`, `AID`, `BID`) + UNIQUE KEY `relation` (`product`,`relation`,`AType`,`BType`, `AID`, `BID`) ) ENGINE='MyISAM' DEFAULT CHARSET=utf8; -- DROP TABLE IF EXISTS `zt_release`; CREATE TABLE IF NOT EXISTS `zt_release` ( From 88ffd1682026060d6ceaa1fde2addaeb856d6bc7 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Wed, 23 Jun 2021 17:29:04 +0800 Subject: [PATCH 101/269] * Add test function and sync issue function. --- module/gitlab/config.php | 40 ++++++++------ module/gitlab/control.php | 16 ++++++ module/gitlab/model.php | 113 +++++++++++++++++++++++++++++++------- module/task/model.php | 4 +- 4 files changed, 134 insertions(+), 39 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 67dea62ab6..bc042904bb 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -31,23 +31,31 @@ $config->gitlab->storyLabel->priority = "0"; $config->gitlab->zentaoApiWebhookUrl = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s"; $config->gitlab->zentaoApiWebhookToken = ""; +$config->gitlab->skippedFields = new stdclass; +$config->gitlab->skippedFields->issueCreate = array(); +$config->gitlab->skippedFields->issueCreate[] = ''; + $config->gitlab->maps = new stdclass; $config->gitlab->maps->task = array(); -$config->gitlab->maps->task['execution'] = 'execution'; -$config->gitlab->maps->task['name'] = 'title'; -$config->gitlab->maps->task['desc'] = 'description'; -$config->gitlab->maps->task['deadline'] = 'due_date'; +$config->gitlab->maps->task['name'] = 'title|field|'; +$config->gitlab->maps->task['desc'] = 'description|field|'; +$config->gitlab->maps->task['openedDate'] = 'created_at|field|'; +$config->gitlab->maps->task['assignedTo'] = 'assignee_id|userPairs|'; +$config->gitlab->maps->task['lastEditedDate'] = 'updated_at|field|'; +$config->gitlab->maps->task['deadline'] = 'due_date|field|'; +$config->gitlab->maps->task['status'] = 'state_event|configItems|taskStateMap'; +$config->gitlab->maps->task['pri'] = 'weight|configItems|taskWeightMap'; -$config->gitlab->maps->task['openedBy'] = 'due_date'; -$config->gitlab->maps->task['openedDate'] = 'created_at'; -$config->gitlab->maps->task['assignedTo'] = 'due_date'; -$config->gitlab->maps->task['closedBy'] = 'due_date'; -$config->gitlab->maps->task['closedDate'] = 'due_date'; -$config->gitlab->maps->task['finishedDate'] = 'closed_at'; -$config->gitlab->maps->task['lastEditedDate'] = 'last_edited_at'; -$config->gitlab->maps->task['deadline'] = 'due_date'; +$config->gitlab->taskWeightMap = array(); +$config->gitlab->taskWeightMap['1'] = '1'; +$config->gitlab->taskWeightMap['2'] = '2'; +$config->gitlab->taskWeightMap['3'] = '3'; -$config->gitlab->issueOptions = new stdclass; -$config->gitlab->issueOptions->task['type'] = 'devel'; -$config->gitlab->issueOptions->task['pri'] = '3'; -$config->gitlab->issueOptions->task['status'] = array(); +$config->gitlab->taskStateMap = array(); +$config->gitlab->taskStateMap['doing'] = 'reopen'; +$config->gitlab->taskStateMap['wait'] = 'reopen'; +$config->gitlab->taskStateMap['done'] = 'close'; +$config->gitlab->taskStateMap['cancel'] = 'close'; +$config->gitlab->taskStateMap['closed'] = 'close'; + +$config->gitlab->taskTypesToSync = 'design,devel,request,discuss,ui,affair,misc'; diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 546948c484..e61210e52a 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -246,4 +246,20 @@ class gitlab extends control $this->view->data = 'ougiugjvh'; $this->display(); } + + public function test($id = 11) + { + $gitlabID = 11; $projectID = 36; + $task = $this->loadModel('task')->getByID($id); + $issue = $this->gitlab->taskToIssue($gitlabID, $projectID, $task); + $issue = $this->gitlab->apiCreateIssue($gitlabID, $projectID, $issue); + a($issue); + $this->gitlab->saveSyncedIssue('task', $task, $gitlabID, $issue); + + exit; + } + + + + } diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 4429bf8e4d..543b6f65e7 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -56,7 +56,7 @@ class gitlabModel extends model */ public function getUserIdAccountPairs($gitlab) { - return $this->dao->select('id,account')->from(TABLE_OAUTH)->where('providerType')->eq('gitlab')->andwhere('providerID')->eq($gitlabID)->fetchPairs(); + return $this->dao->select('openID,account')->from(TABLE_OAUTH)->where('providerType')->eq('gitlab')->andwhere('providerID')->eq($gitlab)->fetchPairs(); } /** @@ -68,7 +68,7 @@ class gitlabModel extends model */ public function getUserAccountIdPairs($gitlab) { - return $this->dao->select('account,id')->from(TABLE_OAUTH)->where('providerType')->eq('gitlab')->andwhere('providerID')->eq($gitlabID)->fetchPairs(); + return $this->dao->select('account,openID')->from(TABLE_OAUTH)->where('providerType')->eq('gitlab')->andwhere('providerID')->eq($gitlab)->fetchPairs(); } /** @@ -554,38 +554,109 @@ class gitlabModel extends model } /** - * sync gitlab Issue. + * Sync task to gitlab issue. * - * @param int $gitlabID - * @param int $projectID + * @param int $taskID + * @param int $gitlab + * @param int $gitlabProject * @access public * @return void */ - public function syncGitlabIssue($taskID, $task, $gitlabID, $projectID) + public function syncTask($taskID, $gitlab, $gitlabProject) { - $issue = new stdClass(); - $issue->assignee_id = $taskID; - $issue->created_at = $task->create_at; - $issue->description = $task->description; - $issue->labelType = $task->labelType; - $issue->due_date = $task->data; - $issue->id = $task->project; - $issue->title = $task->title; - $issue->weight = $task->weight; - $issue->labels = $task->labels; - - $response = $this->loadModel('gitlab')->apiCreateIssue($gitlabID, $projectID, $issue); + $task = $this->loadModel('task')->getByID($taskID); + $syncedIssue = $this->getSyncedIssue($objectType = 'task', $objectID = $taskID, $gitlab); - return $response; + $issue = $this->taskToIssue($gitlab, $gitlabProject, $task); + if($syncedIssue) $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); + $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); + + $this->saveSyncedIssue('task', $taskID, $gitlab, $issue); + } + + /** + * Get synced issue from relation table. + * + * @param string $objectType + * @param int $objectID + * @param int $gitlab + * @access public + * @return object + */ + public function getSyncedIssue($objectType, $objectID, $gitlab) + { + return $this->dao->select('*')->from(TABLE_RELATION) + ->where('AType')->eq($objectType) + ->andWhere('AID')->eq($objectID) + ->andWhere('extra')->eq($gitlab) + ->fetch(); + } + + /** + * Save synced issue to relation table. + * + * @param string $objectType + * @param object $object + * @param int $gitlab + * @param object $issue + * @access public + * @return void + */ + public function saveSyncedIssue($objectType, $object, $gitlab, $issue) + { + $relation = new stdclass; + $relation->execution = zget($object, 'execution', 0); + $relation->AType = $objectType; + $relation->AID = $object->id; + $relation->AVersion = ''; + $relation->relation = 'gitlab'; + $relation->BType = 'issue'; + $relation->BID = $issue->iid; + $relation->BVersion = $issue->project_id; + $relation->extra = $gitlab; + $this->dao->replace(TABLE_RELATION)->data($relation)->exec(); + } + + /** + * Parse task to issue. + * + * @param int $gitlabID + * @param int $gitlabProjectID + * @param object $task + * @access public + * @return object + */ + public function taskToIssue($gitlabID, $gitlabProjectID, $task) + { + $map = $this->config->gitlab->maps->task; + $issue = new stdclass; + $gitlabUsers = $this->getUserAccountIdPairs($gitlabID); + foreach($map as $taskField => $config) + { + $value = ''; + list($field, $optionType, $options) = explode('|', $config); + if($optionType == 'field') $value = $task->$taskField; + if($optionType == 'userPairs') $value = zget($gitlabUsers, $task->$taskField); + if($optionType == 'configItems') + { + $value = zget($this->config->gitlab->$options, $task->$taskField, ''); + } + if($value) $issue->$field = $value; + } + return $issue; } public function apiCreateIssue($gitlabID, $projectID, $issue) { $apiRoot = $this->getApiRoot($gitlabID); $apiPath = "/projects/{$projectID}/issues/"; + foreach($this->config->gitlab->skippedFields->issueCreate as $field) + { + if(isset($issue->$field)) unset($issue->$field); + } + $url = sprintf($apiRoot, $apiPath); - $response = json_decode(commonModel::http($url, $issue)); - return $response; + return json_decode(commonModel::http($url, $issue)); } public function pushTask($gitlabID, $projectID, $task) diff --git a/module/task/model.php b/module/task/model.php index d15807aa76..35c5b55716 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -120,8 +120,8 @@ class taskModel extends model $taskID = $this->dao->lastInsertID(); - /*sync gitlab Issue*/ - $this->loadModel('gitlab')->syncGitlabIssue($taskID, $gitlabID, $projectID); + /* Sync this task to gitlab issue. */ + $this->loadModel('gitlab')->syncTask($taskID, $this->post->gitlab, $this->post->gitlabProject); /* Mark design version.*/ if(isset($task->design) && !empty($task->design)) From a55f27056ea7f08743949d07fd5bec9b7d1964e5 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 24 Jun 2021 09:37:50 +0800 Subject: [PATCH 102/269] * Fix bug when create a repo with gitlab. --- module/repo/control.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/module/repo/control.php b/module/repo/control.php index ea6137605b..c16b3c61cb 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -1113,16 +1113,16 @@ class repo extends control * @access public * @return void */ - public function ajaxGetGitlabProjects($host, $projectIdList) + public function ajaxGetGitlabProjects($host, $projectIdList = '') { $projects = $this->loadModel('gitlab')->apiGetProjects($host); - + if(!$projects) $this->send(array('message' => array())); - $projectIdList = explode(',', $projectIdList); + $projectIdList = $projectIdList ? explode(',', $projectIdList) : null; $options = ""; foreach($projects as $project) { - if($project and !in_array($project->id, $projectIdList)) continue; + if(!empty($projectIdList) and $project and !in_array($project->id, $projectIdList)) continue; $options .= ""; } die($options); From a907eb4b246fb896c5869379ae60444bdbcf827d Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 24 Jun 2021 10:15:56 +0800 Subject: [PATCH 103/269] * Fix bug when creating task and sync to gitlab issue. --- module/gitlab/model.php | 2 +- module/task/control.php | 2 ++ module/task/model.php | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 543b6f65e7..5fb82be978 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -571,7 +571,7 @@ class gitlabModel extends model if($syncedIssue) $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); - $this->saveSyncedIssue('task', $taskID, $gitlab, $issue); + $this->saveSyncedIssue('task', $task, $gitlab, $issue); } /** diff --git a/module/task/control.php b/module/task/control.php index 773f58e46c..601c8bc479 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -92,6 +92,8 @@ class task extends control setcookie('lastTaskModule', (int)$this->post->module, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, false); if($this->post->execution) $executionID = (int)$this->post->execution; + + /* Create task here. */ $tasksID = $this->task->create($executionID); if(dao::isError()) { diff --git a/module/task/model.php b/module/task/model.php index 35c5b55716..41d0b5a067 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -22,6 +22,7 @@ class taskModel extends model */ public function create($executionID) { + if($this->post->estimate < 0) { dao::$errors[] = $this->lang->task->error->recordMinus; @@ -67,7 +68,11 @@ class taskModel extends model ->remove('after,files,labels,assignedTo,uid,storyEstimate,storyDesc,storyPri,team,teamEstimate,teamMember,multiple,teams,contactListMenu,selectTestStory,testStory,testPri,testEstStarted,testDeadline,testAssignedTo,testEstimate,sync') ->add('version', 1) ->get(); - + + /* Remove gitlab attributes in task object */ + if(isset($task->gitlab)) unset($task->gitlab); + if(isset($task->gitlabProject)) unset($task->gitlabProject); + if($task->type != 'test') $this->post->set('selectTestStory', 0); foreach($this->post->assignedTo as $assignedTo) From b3248d21055a3159a4d2a649a3374ff8ec8bbac7 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 24 Jun 2021 10:22:47 +0800 Subject: [PATCH 104/269] * Remove extra attributes of task with bp. --- module/task/model.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/module/task/model.php b/module/task/model.php index 41d0b5a067..329799e567 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -69,10 +69,6 @@ class taskModel extends model ->add('version', 1) ->get(); - /* Remove gitlab attributes in task object */ - if(isset($task->gitlab)) unset($task->gitlab); - if(isset($task->gitlabProject)) unset($task->gitlabProject); - if($task->type != 'test') $this->post->set('selectTestStory', 0); foreach($this->post->assignedTo as $assignedTo) @@ -114,7 +110,7 @@ class taskModel extends model /* Fix Bug #2466 */ if($this->post->multiple) $task->assignedTo = ''; - $this->dao->insert(TABLE_TASK)->data($task) + $this->dao->insert(TABLE_TASK)->data($task, $skip = 'gitlab,gitlabProject') ->autoCheck() ->batchCheck($requiredFields, 'notempty') ->checkIF($task->estimate != '', 'estimate', 'float') From 49af2b3bb1837de98f3c728cca356ada86143fee Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 24 Jun 2021 13:15:55 +0800 Subject: [PATCH 105/269] + Add func to find the issue by object type and id. --- module/gitlab/model.php | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 5fb82be978..00716526d5 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -56,7 +56,7 @@ class gitlabModel extends model */ public function getUserIdAccountPairs($gitlab) { - return $this->dao->select('openID,account')->from(TABLE_OAUTH)->where('providerType')->eq('gitlab')->andwhere('providerID')->eq($gitlab)->fetchPairs(); + return $this->dao->select('openID,account')->from(TABLE_OAUTH)->where('providerType')->eq('gitlab')->andWhere('providerID')->eq($gitlab)->fetchPairs(); } /** @@ -68,7 +68,7 @@ class gitlabModel extends model */ public function getUserAccountIdPairs($gitlab) { - return $this->dao->select('account,openID')->from(TABLE_OAUTH)->where('providerType')->eq('gitlab')->andwhere('providerID')->eq($gitlab)->fetchPairs(); + return $this->dao->select('account,openID')->from(TABLE_OAUTH)->where('providerType')->eq('gitlab')->andWhere('providerID')->eq($gitlab)->fetchPairs(); } /** @@ -772,11 +772,27 @@ class gitlabModel extends model */ public function getAccount($gitlabID, $userID) { - return $this->dao->select('account') - ->from(TABLE_OAUTH) - ->where('providerType')->eq('gitlab') - ->andwhere('providerID')->eq($gitlabID) - ->andwhere('openID')->eq($userID) - ->fetch('account'); + return $this->dao->select('account')->from(TABLE_OAUTH) + ->where('providerType')->eq('gitlab') + ->andWhere('providerID')->eq($gitlabID) + ->andWhere('openID')->eq($userID) + ->fetch('account'); + } + + /** + * Get gitlab issue from relation by object type and id. + * + * @param string $objectType + * @param int $objectID + * @access public + * @return object + */ + public function getGitlabIssueFromRelation($objectType,$objectID) + { + return $this->dao->select('extra as gitlabID,BVersion as projectID,BID as issueID,AType,AID')->from(TABLE_RELATION) + ->where('relation')->eq('gitlab') + ->andWhere('AType')->eq($objectType) + ->andWhere('AID')->eq($objectID) + ->fetch(); } } From 2a274668fcf288a1de025b83b81b030bb05b6f75 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 24 Jun 2021 13:27:41 +0800 Subject: [PATCH 106/269] * Finish parse issue webhook function. --- module/gitlab/model.php | 85 ++++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 19 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 543b6f65e7..bfeb01d7e7 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -673,21 +673,52 @@ class gitlabModel extends model return $response; } - public function webhookParseBody($body) + /** + * Parse webhook body function. + * + * @param object $body + * @param int $gitlabID + * @access public + * @return object + */ + public function webhookParseBody($body, $gitlabID) { $type = zget($body, 'object_kind', ''); if(!$type or !is_callable(array($this, "webhookParse{$type}"))) return false; - $result = call_user_func_array(array($this, "webhookParse{$type}Webhook"), array('body' => $body)); + return call_user_func_array(array($this, "webhookParse{$type}"), array('body' => $body, $gitlabID)); } - public function WebhookParseIssue($body) + /** + * Parse Webhook issue. + * + * @param object $body + * @param int $gitlabID + * @access public + * @return object + */ + public function WebhookParseIssue($body, $gitlabID) { + $object = $this->parseObjectFromLabel($body->labels); + if(empty($object)) return null; + $issue = new stdclass; - $issue->action = $body->object_attributes->action . $body->object_kind; - $issue->issue = $body->object_attributes; - $object = $this->parseObjectFromLabels($issue->labels); + $issue->action = $body->object_attributes->action . $body->object_kind; + $issue->issue = $body->object_attributes; + $issue->objectType = $object->type; + $issue->objectID = $object->id; + + if(!is_callable(array($this, "issueTo{$object->type}"))) return false; + $issue->object = call_user_func_array(array($this, "issueTo{$object->type}"), array('body' => $issue->issue, 'gitlab' => $gitlabID)); + return $issue; } + /** + * Webhook parse note. + * + * @param object $body + * @access public + * @return void + */ public function webhookParseNote($body) { $request = new stdclass; @@ -718,18 +749,20 @@ class gitlabModel extends model * @access public * @return object|false */ - public function webhookParseZentaoLabel($labels) + public function parseObjectFromLabel($labels) { - foreach($body->labels as $label) + $object = null; + foreach($labels as $label) { - if($label->title == $config->gitlab->zentaoLabel) + if(preg_match($this->config->gitlab->labelPattern->task, $label->title)) { - $object = json_decode($label->description); - if(!$object or !isset($object->type)) continue; - return $object; + list($prefix, $id) = explode('/', $label->title); + $object = new stdclass; + $object->type = 'task'; + $object->id = $id; } } - return false; + return $object; } /** @@ -749,15 +782,29 @@ class gitlabModel extends model return $object; } - public function issue2Task($issue) + public function issueToTask($issue, $gitlabID) + { + $task = new stdclass; + $maps = $this->config->gitlab->maps->task; + $gitlabUsers = $this->getUserAccountIdPairs($gitlabID); + + foreach($maps as $taskField => $config) + { + $value = ''; + list($field, $optionType, $options) = explode('|', $config); + if($optionType == 'field') $value = $issue->$field; + if($optionType == 'userPairs') $value = zget($gitlabUsers, $issue->$field); + if($optionType == 'configItems' and isset($issue->$field)) $value = array_search($issue->$field, $this->config->gitlab->$options); + if($value) $task->$taskField = $value; + } + return $task; + } + + public function issueToStory($issue) { } - public function issue2Story($issue) - { - } - - public function issue2Bug($issue) + public function issueToBug($issue) { } From 86c7e9b4ccd86f09318cdb5bc18bcbfb84f42c1a Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 24 Jun 2021 14:56:23 +0800 Subject: [PATCH 107/269] + Add funcs to update issue when the assigned user changed in task. --- module/gitlab/model.php | 38 ++++++++++++++++++++++++++++++++++++-- module/task/model.php | 10 ++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 00716526d5..31e37a404c 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -56,7 +56,10 @@ class gitlabModel extends model */ public function getUserIdAccountPairs($gitlab) { - return $this->dao->select('openID,account')->from(TABLE_OAUTH)->where('providerType')->eq('gitlab')->andWhere('providerID')->eq($gitlab)->fetchPairs(); + return $this->dao->select('openID,account')->from(TABLE_OAUTH) + ->where('providerType')->eq('gitlab') + ->andWhere('providerID')->eq($gitlab) + ->fetchPairs(); } /** @@ -68,7 +71,10 @@ class gitlabModel extends model */ public function getUserAccountIdPairs($gitlab) { - return $this->dao->select('account,openID')->from(TABLE_OAUTH)->where('providerType')->eq('gitlab')->andWhere('providerID')->eq($gitlab)->fetchPairs(); + return $this->dao->select('account,openID')->from(TABLE_OAUTH) + ->where('providerType')->eq('gitlab') + ->andWhere('providerID')->eq($gitlab) + ->fetchPairs(); } /** @@ -659,6 +665,25 @@ class gitlabModel extends model return json_decode(commonModel::http($url, $issue)); } + /** + * Update issue with new attribute using gitlab API. + * + * @param int $gitlabID + * @param int $projectID + * @param int $issueID + * @param object $attribute + * @access public + * @return object + */ + public function apiUpdateIssue($gitlabID, $projectID, $issueID, $attribute) + { + $apiRoot = $this->getApiRoot($gitlabID); + $apiPath = "/projects/{$projectID}/issues/{$issueID}"; + $url = sprintf($apiRoot, $apiPath); + $response = json_decode(commonModel::http($url, $attribute, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); + return $response; + } + public function pushTask($gitlabID, $projectID, $task) { $task->label = $this->config->gitlab->taskLabel->name; @@ -779,6 +804,15 @@ class gitlabModel extends model ->fetch('account'); } + public function getGitlabUserID($gitlabID, $account) + { + return $this->dao->select('openID')->from(TABLE_OAUTH) + ->where('providerType')->eq('gitlab') + ->andWhere('providerID')->eq($gitlabID) + ->andWhere('account')->eq($account) + ->fetch('openID'); + } + /** * Get gitlab issue from relation by object type and id. * diff --git a/module/task/model.php b/module/task/model.php index 329799e567..f465c053d9 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -1325,6 +1325,16 @@ class taskModel extends model ->autoCheck() ->check('left', 'float') ->where('id')->eq($taskID)->exec(); + + $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('task', $taskID); + + $attribute = new stdclass(); + $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $task->assignedTo); + if($attribute->assignee_id != '') + { + // TODO(dingguodong) we should alert to operator when can not find the user, and the operator should reconfigure user binding. + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID , $attribute); + } if(!dao::isError()) return common::createChanges($oldTask, $task); } From 04d32851c3d7e8403e46ec82b09172861ed5ce70 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 24 Jun 2021 15:02:04 +0800 Subject: [PATCH 108/269] * Change put to PUT when using curl. --- module/gitlab/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 036c970a15..9284aec93d 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -457,7 +457,7 @@ class gitlabModel extends model $apiPath = "/projects/{$projectID}/hooks/{$hookID}"; $url = sprintf($apiRoot, $apiPath); - $response = commonModel::http($url, $postData, $options = array(CURLOPT_CUSTOMREQUEST => 'put')); + $response = commonModel::http($url, $postData, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT')); return $response; } From a7d476e8823942cf6eec40d0706d85feef56a3dc Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 24 Jun 2021 16:36:23 +0800 Subject: [PATCH 109/269] * Format codes. --- module/gitlab/model.php | 390 ++++++++++++++++++++-------------------- 1 file changed, 190 insertions(+), 200 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 79b47d77c8..06d9f6baa5 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -47,6 +47,21 @@ class gitlabModel extends model return $this->loadModel('pipeline')->getPairs('gitlab'); } + /** + * Get gitlab api base url with access_token + * + * @param int $id + * @access public + * @return string gitlab api base url with access_token + */ + public function getApiRoot($id) + { + $gitlab = $this->getByID($id); + if(!$gitlab) return ""; + $gitlab_url = rtrim($gitlab->url, '/').'/api/v4%s'."?private_token={$gitlab->token}"; + return $gitlab_url; + } + /** * Get gitlab user id zentao account pairs of one gitlab. * @@ -116,7 +131,6 @@ class gitlabModel extends model * @access public * @return array */ - public function apiGetUsers($gitlab) { $api = rtrim($gitlab->url, '/') . '/api/v4/users?private_token=' . $gitlab->token; @@ -139,59 +153,6 @@ class gitlabModel extends model return $users; } - /** - * Get matched gitlab users. - * - * @param array $gitlabUsers - * @param array $zentaoUsers - * @access public - * @return array - */ - public function getMatchedUsers($gitlabID, $gitlabUsers, $zentaoUsers) - { - $matches = new stdclass; - foreach($gitlabUsers as $gitlabUser) - { - foreach($zentaoUsers as $zentaoUser) - { - if($gitlabUser->account == $zentaoUser->account) $matches->accounts[$gitlabUser->account][] = $zentaoUser->account; - if($gitlabUser->realname == $zentaoUser->realname) $matches->names[$gitlabUser->realname][] = $zentaoUser->account; - if($gitlabUser->email == $zentaoUser->email) $matches->emails[$gitlabUser->email][] = $zentaoUser->account; - } - } - - $bindedUsers = $this->dao->select('openID,account') - ->from(TABLE_OAUTH) - ->where('providerType')->eq('gitlab') - ->andWhere('providerID')->eq($gitlabID) - ->fetchPairs(); - - $matchedUsers = array(); - foreach($gitlabUsers as $gitlabUser) - { - if(isset($bindedUsers[$gitlabUser->id])) - { - $gitlabUser->zentaoAccount = $bindedUsers[$gitlabUser->id]; - $matchedUsers[] = $gitlabUser; - continue; - } - - $matchedZentaoUsers = array(); - if(isset($matches->accounts[$gitlabUser->account])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->accounts[$gitlabUser->account]); - if(isset($matches->emails[$gitlabUser->email])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->emails[$gitlabUser->email]); - if(isset($matches->names[$gitlabUser->realname])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->names[$gitlabUser->realname]); - - $matchedZentaoUsers = array_unique($matchedZentaoUsers); - if(count($matchedZentaoUsers) == 1) - { - $gitlabUser->zentaoAccount = current($matchedZentaoUsers); - $matchedUsers[] = $gitlabUser; - } - } - - return $matchedUsers; - } - /** * Get projects of one gitlab. * @@ -200,7 +161,7 @@ class gitlabModel extends model * @return void */ public function apiGetProjects($gitlabID) - { + { $gitlab = $this->getByID($gitlabID); if(!$gitlab) return array(); $host = rtrim($gitlab->url, '/'); @@ -216,115 +177,6 @@ class gitlabModel extends model return $allResults; } - public function getProjectPairs($gitlabID) - { - $projects = $this->apiGetProjects($gitlabID); - $projectPairs = array(); - foreach($projects as $project) - { - $projectPairs[$project->id] = $project->name_with_namespace; - } - - return $projectPairs; - } - - public function getProjectDisplayName($gitlabID, $projectID) - { - return array_key_exists($gitlabID, $projectID) ? $this->gitlab->getProjectPairs($gitlabID)[$projectID]: ""; - } - - /** - * Get gitlab api base url with access_token - * - * @param int $id - * @access public - * @return string gitlab api base url with access_token - */ - public function getApiRoot($id) - { - $gitlab = $this->getByID($id); - if(!$gitlab) return ""; - $gitlab_url = rtrim($gitlab->url, '/').'/api/v4%s'."?private_token={$gitlab->token}"; - return $gitlab_url; - } - - /** - * Bind gitlab project. - * - * @param int $gitlabID - * @param int $projectID - * @access public - * @return array - */ - public function getProjectsByExecution($executionID) - { - $products = $this->loadModel('execution')->getProducts($executionID, false); - $productIdList = array_keys($products); - - return $this->dao->select('AID,BID as gitlabProject') - ->from(TABLE_RELATION) - ->where('relation')->eq('interrated') - ->andWhere('AType')->eq('gitlab') - ->andWhere('BType')->eq('gitlabProject') - ->andWhere('product')->in($productIdList) - ->fetchGroup('AID'); - } - - /** - * Create relationship between zentao product and gitlab project. - * - * @param int $gitlabID - * @param int $projectID - * @access public - * @return void - */ - public function saveRelation($products, $gitlabID, $gitlabProjectID) - { - $programs = $this->dao->select('id,program')->from(TABLE_PRODUCT)->where('id')->in($products)->fetchPairs(); - - $relation = new stdclass; - $relation->execution = 0; - $relation->AType = 'gitlab'; - $relation->AID = $gitlabID; - $relation->AVersion = ''; - $relation->relation = 'interrated'; - $relation->BType = 'gitlabProject'; - $relation->BID = $gitlabProjectID; - $relation->BVersion = ''; - $relation->extra = ''; - - foreach($products as $product) - { - $relation->project = zget($programs, $product, 0); - $relation->product = $product; - $this->dao->replace(TABLE_RELATION)->data($relation)->exec(); - } - return true; - } - - /** - * Create webhook for zentao. - * - * @param int $gitlabID - * @param int $projectID - * @access public - * @return void - */ - public function createWebhook($products, $gitlabID, $projectID) - { - $urls = $this->getWebhookUrls($gitlabID, $projectID); - - foreach($products as $index => $product) - { - $url = sprintf($this->config->gitlab->zentaoApiWebhookUrl, commonModel::getSysURL(), $product, $gitlabID, $projectID); - if(! array_key_exists($url, array_flip($urls))) - { - $response = $this->apiCreateHook($gitlabID, $projectID, $url, $this->config->gitlab->zentaoApiWebhookToken); - } - } - return true; - } - /** * Get hooks. * @@ -360,25 +212,6 @@ class gitlabModel extends model return $response; } - /** - * Get webhook urls - * - * @param int $gitlabID - * @param int $projectID - * @access public - * @return array $urls; - */ - public function getWebhookUrls($gitlabID, $projectID) - { - $urls = array(); - $webhooks = $this->apiGetHooks($gitlabID, $projectID); - foreach($webhooks as $index => $webhook) - { - $urls[] = $webhook->url; - } - return $urls; - } - /** * Create hook. * @@ -494,6 +327,172 @@ class gitlabModel extends model return $labels; } + /** + * Get project pairs of one gitlab. + * + * @param int $gitlabID + * @access public + * @return array + */ + public function getProjectPairs($gitlabID) + { + $projects = $this->apiGetProjects($gitlabID); + + $projectPairs = array(); + foreach($projects as $project) $projectPairs[$project->id] = $project->name_with_namespace; + + return $projectPairs; + } + + /** + * Get matched gitlab users. + * + * @param array $gitlabUsers + * @param array $zentaoUsers + * @access public + * @return array + */ + public function getMatchedUsers($gitlabID, $gitlabUsers, $zentaoUsers) + { + $matches = new stdclass; + foreach($gitlabUsers as $gitlabUser) + { + foreach($zentaoUsers as $zentaoUser) + { + if($gitlabUser->account == $zentaoUser->account) $matches->accounts[$gitlabUser->account][] = $zentaoUser->account; + if($gitlabUser->realname == $zentaoUser->realname) $matches->names[$gitlabUser->realname][] = $zentaoUser->account; + if($gitlabUser->email == $zentaoUser->email) $matches->emails[$gitlabUser->email][] = $zentaoUser->account; + } + } + + $bindedUsers = $this->dao->select('openID,account') + ->from(TABLE_OAUTH) + ->where('providerType')->eq('gitlab') + ->andWhere('providerID')->eq($gitlabID) + ->fetchPairs(); + + $matchedUsers = array(); + foreach($gitlabUsers as $gitlabUser) + { + if(isset($bindedUsers[$gitlabUser->id])) + { + $gitlabUser->zentaoAccount = $bindedUsers[$gitlabUser->id]; + $matchedUsers[] = $gitlabUser; + continue; + } + + $matchedZentaoUsers = array(); + if(isset($matches->accounts[$gitlabUser->account])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->accounts[$gitlabUser->account]); + if(isset($matches->emails[$gitlabUser->email])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->emails[$gitlabUser->email]); + if(isset($matches->names[$gitlabUser->realname])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->names[$gitlabUser->realname]); + + $matchedZentaoUsers = array_unique($matchedZentaoUsers); + if(count($matchedZentaoUsers) == 1) + { + $gitlabUser->zentaoAccount = current($matchedZentaoUsers); + $matchedUsers[] = $gitlabUser; + } + } + + return $matchedUsers; + } + + /** + * Bind gitlab project. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return array + */ + public function getProjectsByExecution($executionID) + { + $products = $this->loadModel('execution')->getProducts($executionID, false); + $productIdList = array_keys($products); + + return $this->dao->select('AID,BID as gitlabProject') + ->from(TABLE_RELATION) + ->where('relation')->eq('interrated') + ->andWhere('AType')->eq('gitlab') + ->andWhere('BType')->eq('gitlabProject') + ->andWhere('product')->in($productIdList) + ->fetchGroup('AID'); + } + + /** + * Create relationship between zentao product and gitlab project. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ + public function saveRelation($products, $gitlabID, $gitlabProjectID) + { + $programs = $this->dao->select('id,program')->from(TABLE_PRODUCT)->where('id')->in($products)->fetchPairs(); + + $relation = new stdclass; + $relation->execution = 0; + $relation->AType = 'gitlab'; + $relation->AID = $gitlabID; + $relation->AVersion = ''; + $relation->relation = 'interrated'; + $relation->BType = 'gitlabProject'; + $relation->BID = $gitlabProjectID; + $relation->BVersion = ''; + $relation->extra = ''; + + foreach($products as $product) + { + $relation->project = zget($programs, $product, 0); + $relation->product = $product; + $this->dao->replace(TABLE_RELATION)->data($relation)->exec(); + } + return true; + } + + /** + * Create webhook for zentao. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ + public function createWebhook($products, $gitlabID, $projectID) + { + $urls = $this->getWebhookUrls($gitlabID, $projectID); + + foreach($products as $index => $product) + { + $url = sprintf($this->config->gitlab->zentaoApiWebhookUrl, commonModel::getSysURL(), $product, $gitlabID, $projectID); + if(! array_key_exists($url, array_flip($urls))) + { + $response = $this->apiCreateHook($gitlabID, $projectID, $url, $this->config->gitlab->zentaoApiWebhookToken); + } + } + return true; + } + + /** + * Get webhook urls + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return array $urls; + */ + public function getWebhookUrls($gitlabID, $projectID) + { + $urls = array(); + $webhooks = $this->apiGetHooks($gitlabID, $projectID); + foreach($webhooks as $index => $webhook) + { + $urls[] = $webhook->url; + } + return $urls; + } + /** * Check if predefined label exist in project. * @@ -782,6 +781,14 @@ class gitlabModel extends model return $object; } + /** + * parse issue To Task. + * + * @param object $issue + * @param int $gitlabID + * @access public + * @return object + */ public function issueToTask($issue, $gitlabID) { $task = new stdclass; @@ -809,23 +816,6 @@ class gitlabModel extends model } - /** - * Get account in zentaopms. - * - * @param int $gitlabID - * @param int $userID - * @access public - * @return string|false - */ - public function getAccount($gitlabID, $userID) - { - return $this->dao->select('account')->from(TABLE_OAUTH) - ->where('providerType')->eq('gitlab') - ->andWhere('providerID')->eq($gitlabID) - ->andWhere('openID')->eq($userID) - ->fetch('account'); - } - /** * Get gitlab issue from relation by object type and id. * From b16d5bab3e6f2ca00f6cd8c13ce3b2b794d0de53 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 24 Jun 2021 16:47:17 +0800 Subject: [PATCH 110/269] + Add funcs of sync story to gitlab issue. --- module/story/control.php | 7 +++++++ module/story/js/create.js | 19 +++++++++++++++++++ module/story/lang/zh-cn.php | 2 ++ module/story/model.php | 5 ++++- module/story/view/create.html.php | 9 +++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/module/story/control.php b/module/story/control.php index 7a47d54b07..869e0c053a 100644 --- a/module/story/control.php +++ b/module/story/control.php @@ -295,6 +295,13 @@ class story extends control $this->view->customFields = $customFields; $this->view->showFields = $this->config->story->custom->createFields; + $allGitlabs = $this->loadModel('gitlab')->getPairs(); + $executionID = $objectID; + $gitlabProjects = $this->loadModel('gitlab')->getProjectsByExecution($executionID); + foreach($allGitlabs as $id => $name) if($id and !isset($gitlabProjects[$id])) unset($allGitlabs[$id]); + $this->view->gitlabList = $allGitlabs; + $this->view->gitlabProjects = $gitlabProjects; + $this->view->title = $product->name . $this->lang->colon . $this->lang->story->create; $this->view->position[] = html::a($this->createLink('product', 'browse', "product=$productID&branch=$branch"), $product->name); $this->view->position[] = $this->lang->story->common; diff --git a/module/story/js/create.js b/module/story/js/create.js index 473c38bd5f..4f410a918b 100644 --- a/module/story/js/create.js +++ b/module/story/js/create.js @@ -34,3 +34,22 @@ function refreshPlan() $(window).unload(function(){ if(blockID) window.parent.refreshBlock($('#block' + blockID)); }); + +$(document).ready(function() +{ + $('#gitlab').change(function() + { + host = $('#gitlab').val(); + if(host == '') return false; + projects = ''; + $.each(gitlabProjects[host], function(id, obj){projects = projects + ',' + obj.gitlabProject}); + url = createLink('repo', 'ajaxgetgitlabprojects', "host=" + host + "&projects=" + projects); + + $.get(url, function(response) + { + $('#gitlabProject').html('').append(response); + $('#gitlabProject').chosen().trigger("chosen:updated");; + }); + + }); +}); diff --git a/module/story/lang/zh-cn.php b/module/story/lang/zh-cn.php index c32023f07a..5bd7dde722 100644 --- a/module/story/lang/zh-cn.php +++ b/module/story/lang/zh-cn.php @@ -405,3 +405,5 @@ $lang->story->categoryList['safe'] = '安全'; $lang->story->categoryList['experience'] = '体验'; $lang->story->categoryList['improve'] = '改进'; $lang->story->categoryList['other'] = '其他'; + +$lang->story->sync2Gitlab = '同步到Gitlab'; diff --git a/module/story/model.php b/module/story/model.php index 707c9b0fe7..194ab52831 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -233,7 +233,7 @@ class storyModel extends model $requiredFields = trim($requiredFields, ','); - $this->dao->insert(TABLE_STORY)->data($story, 'spec,verify')->autoCheck()->batchCheck($requiredFields, 'notempty')->exec(); + $this->dao->insert(TABLE_STORY)->data($story, 'spec,verify,gitlab,gitlabProject')->autoCheck()->batchCheck($requiredFields, 'notempty')->exec(); if(!dao::isError()) { $storyID = $this->dao->lastInsertID(); @@ -339,6 +339,9 @@ class storyModel extends model /* Callback the callable method to process the related data for object that is transfered to story. */ if($from && is_callable(array($this, $this->config->story->fromObjects[$from]['callback']))) call_user_func(array($this, $this->config->story->fromObjects[$from]['callback']), $storyID); + /* sync this story to gitlab issue */ + $this->loadModel('gitlab')->syncStory($storyID, $this->post->gitlab, $this->post->gitlabProject); + return array('status' => 'created', 'id' => $storyID); } return false; diff --git a/module/story/view/create.html.php b/module/story/view/create.html.php index 147187c88c..7c272cfd97 100644 --- a/module/story/view/create.html.php +++ b/module/story/view/create.html.php @@ -17,6 +17,7 @@ story->placeholder); ?> + @@ -251,6 +252,14 @@ + + + + + + + + From 74070508afe3277d70d04ded5820135fd1cc107f Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 24 Jun 2021 16:59:15 +0800 Subject: [PATCH 111/269] + Add story to issue funcs. --- module/gitlab/model.php | 52 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 9284aec93d..27efcb26d1 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -579,7 +579,28 @@ class gitlabModel extends model $this->saveSyncedIssue('task', $task, $gitlab, $issue); } - + + /** + * Sync story to gitlab issue. + * + * @param int $storyID + * @param int $gitlab + * @param int $gitlabProject + * @access public + * @return void + */ + public function syncStory($storyID, $gitlab, $gitlabProject) + { + $story = $this->loadModel('story')->getByID($storyID); + $syncedIssue = $this->getSyncedIssue($objectType = 'story', $objectID = $storyID, $gitlab); + + $issue = $this->storyToIssue($gitlab, $gitlabProject, $story); + if($syncedIssue) $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); + $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); + + $this->saveSyncedIssue('story', $story, $gitlab, $issue); + } + /** * Get synced issue from relation table. * @@ -652,6 +673,35 @@ class gitlabModel extends model return $issue; } + /** + * Parse story to issue. + * + * @param int $gitlabID + * @param int $gitlabProjectID + * @param object $story + * @access public + * @return object + */ + public function storyToIssue($gitlabID, $gitlabProjectID, $story) + { + $map = $this->config->gitlab->maps->story; + $issue = new stdclass; + $gitlabUsers = $this->getUserAccountIdPairs($gitlabID); + foreach($map as $storyField => $config) + { + $value = ''; + list($field, $optionType, $options) = explode('|', $config); + if($optionType == 'field') $value = $story->$storyField; + if($optionType == 'userPairs') $value = zget($gitlabUsers, $story->$storyField); + if($optionType == 'configItems') + { + $value = zget($this->config->gitlab->$options, $story->$storyField, ''); + } + if($value) $issue->$field = $value; + } + return $issue; + } + public function apiCreateIssue($gitlabID, $projectID, $issue) { $apiRoot = $this->getApiRoot($gitlabID); From 501be95bec42336a4ab91169d9ba83eafddeae57 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Fri, 25 Jun 2021 11:09:20 +0800 Subject: [PATCH 112/269] * Adjust function names of gitlabModel. --- module/gitlab/model.php | 104 ++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 62 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 0a3a2e900b..23aef46b0b 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -772,17 +772,18 @@ class gitlabModel extends model */ public function WebhookParseIssue($body, $gitlabID) { - $object = $this->parseObjectFromLabel($body->labels); + $object = $this->webhookParseObject($body->labels); if(empty($object)) return null; $issue = new stdclass; - $issue->action = $body->object_attributes->action . $body->object_kind; - $issue->issue = $body->object_attributes; - $issue->objectType = $object->type; - $issue->objectID = $object->id; + $issue->action = $body->object_attributes->action . $body->object_kind; + $issue->issue = $body->object_attributes; - if(!is_callable(array($this, "issueTo{$object->type}"))) return false; - $issue->object = call_user_func_array(array($this, "issueTo{$object->type}"), array('body' => $issue->issue, 'gitlab' => $gitlabID)); + $issue->issue->objectType = $object->type; + $issue->issue->objectID = $object->id; + + if(!isset($this->config->gitlab->maps->$object->type)) return false; + $issue->object = $this->issueToZentaoObject($issue->issue, $gitlabID); return $issue; } @@ -816,6 +817,22 @@ class gitlabModel extends model $request->url = $issue->url; } + /** + * Webhook sync issue. + * + * @param object $issue + * @param int $objectType + * @param int $objectID + * @access public + * @return void + */ + public function webhookSyncIssue($issue) + { + $tableName = zget($this->config->gitlab->objectTables, $issue->objectType, ''); + if($tableName) $this->dao->update($tableName)->data($issue->object)->where('id')->eq($issue->objectID)->exec(); + return !dao::isError(); + } + /** * Parse zentao object from labels. * @@ -823,7 +840,7 @@ class gitlabModel extends model * @access public * @return object|false */ - public function parseObjectFromLabel($labels) + public function webhookParseObject($labels) { $object = null; foreach($labels as $label) @@ -831,6 +848,7 @@ class gitlabModel extends model if(preg_match($this->config->gitlab->labelPattern->task, $label->title)) { list($prefix, $id) = explode('/', $label->title); + $object = new stdclass; $object->type = 'task'; $object->id = $id; @@ -840,71 +858,33 @@ class gitlabModel extends model } /** - * Parse issue from gitlab. - * - * @param object $issue - * @access public - * @return object - */ - public function parseIssue($issue) - { - $object = $this->parseObjectFromLabels($issue->labels); - if(!$object) return false; - if($object->type == 'task') $object->object = $this->issue2Task($issue); - if($object->type == 'story') $object->object = $this->issue2Story($issue); - if($object->type == 'bug') $object->object = $this->issue2Bug($issue); - return $object; - } - - /** - * Parse issue to task. + * Parse issue to zentao object. * * @param object $issue * @param int $gitlabID * @access public * @return object */ - public function issueToTask($issue, $gitlabID) + public function issueToZentaoObject($issue, $gitlabID) { - $task = new stdclass; - $maps = $this->config->gitlab->maps->task; + if(!isset($this->config->gitlab->maps->{$issue->objectType}) return null; + + $maps = $this->config->gitlab->maps->{$issue->objectType}; $gitlabUsers = $this->getUserAccountIdPairs($gitlabID); - foreach($maps as $taskField => $config) + $object = new stdclass; + $object->id = $issue->objectID; + foreach($maps as $zentaoField => $config) { $value = ''; - list($field, $optionType, $options) = explode('|', $config); - if($optionType == 'field') $value = $issue->$field; - if($optionType == 'userPairs') $value = zget($gitlabUsers, $issue->$field); - if($optionType == 'configItems' and isset($issue->$field)) $value = array_search($issue->$field, $this->config->gitlab->$options); - if($value) $task->$taskField = $value; + list($gitlabField, $optionType, $options) = explode('|', $config); + if($optionType == 'field') $value = $issue->$gitlabField; + if($optionType == 'field') $value = $issue->$gitlabField; + if($optionType == 'userPairs') $value = zget($gitlabUsers, $issue->$gitlabField); + if($optionType == 'configItems' and isset($issue->$gitlabField)) $value = array_search($issue->$gitlabField, $this->config->gitlab->$options); + if($value) $object->$zentaoField = $value; } - return $task; - } - - /** - * Parse issue to story. - * - * @param object $issue - * @param int $gitlabID - * @access public - * @return object - */ - public function issueToStory($issue, $gitlabID) - { - } - - /** - * Parse issue to task. - * - * @param object $issue - * @param int $gitlabID - * @access public - * @return object - */ - public function issueToBug($issue, $gitlabID) - { - + return $object; } /** @@ -913,7 +893,7 @@ class gitlabModel extends model * @param int $gitlabID * @param string $account * @access public - * @return void + * @return arary */ public function getGitlabUserID($gitlabID, $account) { From 7b313fd10b549c88273edeb8f0df4c50db0fb2bd Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Fri, 25 Jun 2021 11:10:20 +0800 Subject: [PATCH 113/269] * Adjust indent and remove debug code. --- module/gitlab/control.php | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index b559ae27fa..201f13f110 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -119,10 +119,10 @@ class gitlab extends control $user->providerType = 'gitlab'; $this->dao->delete() - ->from(TABLE_OAUTH) - ->where('providerType')->eq($user->providerType) - ->andWhere('providerID')->eq($user->providerID) - ->exec(); + ->from(TABLE_OAUTH) + ->where('providerType')->eq($user->providerType) + ->andWhere('providerID')->eq($user->providerID) + ->exec(); foreach($users as $openID => $account) { @@ -131,12 +131,12 @@ class gitlab extends control $user->openID = $openID; $this->dao->delete() - ->from(TABLE_OAUTH) - ->where('openID')->eq($user->openID) - ->andWhere('providerType')->eq($user->providerType) - ->andWhere('providerID')->eq($user->providerID) - ->andWhere('account')->eq($user->account) - ->exec(); + ->from(TABLE_OAUTH) + ->where('openID')->eq($user->openID) + ->andWhere('providerType')->eq($user->providerType) + ->andWhere('providerID')->eq($user->providerID) + ->andWhere('account')->eq($user->account) + ->exec(); $this->dao->insert(TABLE_OAUTH)->data($user)->exec(); } @@ -162,8 +162,8 @@ class gitlab extends control */ public function bindProduct($gitlabID) { - $this->view->projectPairs = $this->gitlab->getProjectPairs($gitlabID); - $this->view->title = $this->lang->gitlab->bindProduct; + $this->view->projectPairs = $this->gitlab->getProjectPairs($gitlabID); + $this->view->title = $this->lang->gitlab->bindProduct; $this->display(); } @@ -215,7 +215,7 @@ class gitlab extends control //$input = file_get_contents('php://input'); $requestBody = json_decode($input); $result = $this->gitlab->webhookParseBody($requestBody, $gitlab); - + a($result);exit; $logFile = $this->app->getLogRoot() . 'webhook.'. date('Ymd') . '.log.php'; if(!file_exists($logFile)) file_put_contents($logFile, ''); @@ -228,12 +228,7 @@ class gitlab extends control fclose($fh); } - switch($result->objectType) - { - case 'task': - $this->updateTaskFromIssue($request); - break; - } + if($result->action = 'updateissue') $this->gitlab->webhookSyncIssue($gitlab, $result); $this->view->result = 'success'; $this->view->status = 'ok'; @@ -248,7 +243,6 @@ class gitlab extends control $issue = $this->gitlab->taskToIssue($gitlabID, $projectID, $task); $issue = $this->gitlab->apiCreateIssue($gitlabID, $projectID, $issue); $this->gitlab->saveSyncedIssue('task', $task, $gitlabID, $issue); - exit; } } From 9d1058018d3d86d9b03aebb36d28c88072118492 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 25 Jun 2021 11:24:34 +0800 Subject: [PATCH 114/269] + Sync story to issue when create it. --- module/gitlab/config.php | 14 ++++++++++++++ module/gitlab/model.php | 13 +++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 8a97ecd2bd..e2f4508018 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -62,3 +62,17 @@ $config->gitlab->taskStateMap['cancel'] = 'close'; $config->gitlab->taskStateMap['closed'] = 'close'; $config->gitlab->taskTypesToSync = 'design,devel,request,discuss,ui,affair,misc'; + +$config->gitlab->maps = new stdclass; +$config->gitlab->maps->story = array(); +$config->gitlab->maps->story['title'] = 'title|field|'; +$config->gitlab->maps->story['spec'] = 'description|fields|verify'; +$config->gitlab->maps->story['openedDate'] = 'created_at|field|'; +$config->gitlab->maps->story['openedBy'] = 'assignee_id|userPairs|'; +$config->gitlab->maps->story['pri'] = 'weight|configItems|storyWeightMap'; + +$config->gitlab->storyWeightMap = array(); +$config->gitlab->storyWeightMap['1'] = '1'; +$config->gitlab->storyWeightMap['2'] = '2'; +$config->gitlab->storyWeightMap['3'] = '3'; + diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 0a3a2e900b..8b3e690fcb 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -592,12 +592,10 @@ class gitlabModel extends model { $story = $this->loadModel('story')->getByID($storyID); $syncedIssue = $this->getSyncedIssue($objectType = 'story', $objectID = $storyID, $gitlab); - $issue = $this->storyToIssue($gitlab, $gitlabProject, $story); if($syncedIssue) $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); - - $this->saveSyncedIssue('story', $story, $gitlab, $issue); + if($issue) $this->saveSyncedIssue('story', $story, $gitlab, $issue); } /** @@ -686,18 +684,25 @@ class gitlabModel extends model $map = $this->config->gitlab->maps->story; $issue = new stdclass; $gitlabUsers = $this->getUserAccountIdPairs($gitlabID); + if(empty($gitlabUsers)) return false; + foreach($map as $storyField => $config) { $value = ''; list($field, $optionType, $options) = explode('|', $config); if($optionType == 'field') $value = $story->$storyField; - if($optionType == 'userPairs') $value = zget($gitlabUsers, $story->$storyField); + if($optionType == 'fields') $value = $story->$storyField . "\n\n" . $story->$options; + if($optionType == 'userPairs') + { + $value = zget($gitlabUsers, $story->$storyField); + } if($optionType == 'configItems') { $value = zget($this->config->gitlab->$options, $story->$storyField, ''); } if($value) $issue->$field = $value; } + return $issue; } From ed22d7e58182ca4421dc817f4d3f5b9079d0c4da Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 25 Jun 2021 11:42:07 +0800 Subject: [PATCH 115/269] + Add config for labels. --- module/gitlab/config.php | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index e2f4508018..a85fb61f9f 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -13,23 +13,13 @@ $config->gitlab->labelPattern->story = '/^zentao_story\/\d+$/'; $config->gitlab->actions = array(); $config->gitlab->actions['issue'] = array(); -$config->gitlab->taskLabel = new stdclass(); -$config->gitlab->taskLabel->name = "zentao task"; -$config->gitlab->taskLabel->description = "task label from zentao, do NOT remove this"; -$config->gitlab->taskLabel->color = "#0033CC"; -$config->gitlab->taskLabel->priority = "0"; - -$config->gitlab->bugLabel = new stdclass(); -$config->gitlab->bugLabel->name = "zentao bug"; -$config->gitlab->bugLabel->description = "bug label from zentao, do NOT remove this"; -$config->gitlab->bugLabel->color = "#D10069"; -$config->gitlab->bugLabel->priority = "0"; - -$config->gitlab->storyLabel = new stdclass(); -$config->gitlab->storyLabel->name = "zentao story"; -$config->gitlab->storyLabel->description = "story label from zentao, do NOT remove this"; -$config->gitlab->storyLabel->color = "##69D100"; -$config->gitlab->storyLabel->priority = "0"; +$config->gitlab->zentaoObjectLabel = new stdclass(); +$config->gitlab->zentaoObjectLabel->name = "zentao_%s/%s"; +$config->gitlab->zentaoObjectLabel->description = "%s"; +$config->gitlab->zentaoObjectLabel->taskColor = '#0033CC'; +$config->gitlab->zentaoObjectLabel->storyColor = '#69D100'; +$config->gitlab->zentaoObjectLabel->bugColor = '#D10069'; +$config->gitlab->zentaoObjectLabel->priority = "0"; $config->gitlab->zentaoApiWebhookUrl = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s"; $config->gitlab->zentaoApiWebhookToken = ""; From 8431d0f6c2d5c5a07347e855c4d50e4e9a4721fb Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 25 Jun 2021 13:10:42 +0800 Subject: [PATCH 116/269] - Remove deprecated label funcs and codes. --- module/gitlab/model.php | 59 --------------------------------------- module/pipeline/model.php | 4 --- 2 files changed, 63 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 4732dabbaf..08cab87e6a 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -499,65 +499,6 @@ class gitlabModel extends model return $urls; } - /** - * Check if predefined label exist in project. - * - * @param int $gitlabID - * @param int $projectID - * @access public - * @return void - */ - public function isLabelExists($gitlabID, $projectID) - { - $labels = $this->apiGetLabels($gitlabID, $projectID); - if(empty($labels)) return false; - foreach($labels as $label) - { - if(strpos($label->name, $this->config->gitlab->taskLabel->name) == 0) return true; - if(strpos($label->name, $this->config->gitlab->bugLabel->name) == 0) return true; - if(strpos($label->name, $this->config->gitlab->storyLabel->name) == 0) return true; - } - - return false; - } - - /** - * Create predefined labels for project. - * - * @param int $gitlabID - * @param int $projectID - * @access public - * @return void - */ - public function initLabels($gitlabID, $projectID) - { - if($this->isLabelExists($gitlabID, $projectID)) return true; - - $taskLabel = new stdclass(); - $taskLabel->name = $this->config->gitlab->taskLabel->name; - $taskLabel->description = $this->config->gitlab->taskLabel->description; - $taskLabel->color = $this->config->gitlab->taskLabel->color; - $taskLabel->priority = $this->config->gitlab->taskLabel->priority; - - $bugLabel = new stdclass(); - $bugLabel->name = $this->config->gitlab->bugLabel->name; - $bugLabel->description = $this->config->gitlab->bugLabel->description; - $bugLabel->color = $this->config->gitlab->bugLabel->color; - $bugLabel->priority = $this->config->gitlab->bugLabel->priority; - - $storyLabel = new stdclass(); - $storyLabel->name = $this->config->gitlab->storyLabel->name; - $storyLabel->description = $this->config->gitlab->storyLabel->description; - $storyLabel->color = $this->config->gitlab->storyLabel->color; - $storyLabel->priority = $this->config->gitlab->storyLabel->priority; - - $this->apiCreateLabel($gitlabID, $projectID, $taskLabel); - $this->apiCreateLabel($gitlabID, $projectID, $bugLabel); - $this->apiCreateLabel($gitlabID, $projectID, $storyLabel); - - return; - } - /** * Sync task to gitlab issue. * diff --git a/module/pipeline/model.php b/module/pipeline/model.php index 67f562cdc6..0fb35d711d 100644 --- a/module/pipeline/model.php +++ b/module/pipeline/model.php @@ -88,8 +88,6 @@ class pipelineModel extends model ->exec(); if(dao::isError()) return false; - $this->loadModel("gitlab")->initLabels($this->post->gitlabID, $this->post->projectID); - return $this->dao->lastInsertId(); } @@ -119,8 +117,6 @@ class pipelineModel extends model ->where('id')->eq($id) ->exec(); - if(!dao::isError()) $this->loadModel("gitlab")->initLabels($this->post->gitlabID, $this->post->projectID); - return !dao::isError(); } } From 898cf8a923d434df653b7edf4e7cdf2938ff8f20 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Fri, 25 Jun 2021 13:21:16 +0800 Subject: [PATCH 117/269] * Add gitlab bug config. --- module/gitlab/config.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index a85fb61f9f..6b56cb98b5 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -66,3 +66,27 @@ $config->gitlab->storyWeightMap['1'] = '1'; $config->gitlab->storyWeightMap['2'] = '2'; $config->gitlab->storyWeightMap['3'] = '3'; +$config->gitlab->maps = new stdclass; +$config->gitlab->maps->bug = array(); +$config->gitlab->maps->bug['title'] = 'title|field|'; +$config->gitlab->maps->bug['spec'] = 'description|field|'; +$config->gitlab->maps->bug['openedDate'] = 'created_at|field|'; +$config->gitlab->maps->bug['openedBy'] = 'assignee_id|userPairs|'; +$config->gitlab->maps->bug['pri'] = 'weight|configItems|bugWeightMap'; + +$config->gitlab->bugWeightMap = array(); +$config->gitlab->bugWeightMap['1'] = '1'; +$config->gitlab->bugWeightMap['2'] = '2'; +$config->gitlab->bugWeightMap['3'] = '3'; +$config->gitlab->bugWeightMap['4'] = '4'; + +$config->gitlab->bugStateMap = array(); +$config->gitlab->bugStateMap['active'] = 'reopen'; +$config->gitlab->bugStateMap['resolved'] = 'reopen'; +$config->gitlab->bugStateMap['closed'] = 'close'; + + + + + + From bf6cf641f0b624e384c6912c6bc5fb321a636d0f Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 25 Jun 2021 13:57:42 +0800 Subject: [PATCH 118/269] + Create zentao object label for gitlab project. --- module/gitlab/model.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 08cab87e6a..e9047a459c 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -333,6 +333,42 @@ class gitlabModel extends model return $labels; } + /** + * Create zentao object label for gitlab project. + * + * @param int $gitlabID + * @param int $projectID + * @param object $object + * @access public + * @return object|false + */ + public function createZentaoObjectLabel($gitlabID, $projectID, $object) + { + if(empty($object->type) or empty($object->objectID)) return false; + + $label = new stdclass; + if($object->type == 'task') + { + $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $object->type, $object->objectID); + $label->color = $config->gitlab->zentaoObjectLabel->taskColor; + $label->description = $this->createLink('task', 'view', "taskID={$object->taskID}"); + } + elseif($object->type == 'bug') + { + $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $object->type, $object->objectID); + $label->color = $config->gitlab->zentaoObjectLabel->taskColor; + $label->description = $this->createLink('bug', 'view', "taskID={$object->bugID}"); + } + elseif($object->type == 'story') + { + $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $object->type, $object->objectID); + $label->color = $config->gitlab->zentaoObjectLabel->taskColor; + $label->description = $this->createLink('story', 'view', "storyID={$object->storyID}"); + } + + return $this->apiCreateLabel($gitlabID, $projectID, $label); + } + /** * Get project pairs of one gitlab. * From 6a64f459bc3e3aa64b1e814bdd7994548356ce08 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 25 Jun 2021 14:05:33 +0800 Subject: [PATCH 119/269] * Optimize create label func and call it. --- module/gitlab/model.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index e9047a459c..0f1b944c13 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -338,30 +338,29 @@ class gitlabModel extends model * * @param int $gitlabID * @param int $projectID - * @param object $object + * @param string $object + * @param string $objectID * @access public - * @return object|false + * @return object */ - public function createZentaoObjectLabel($gitlabID, $projectID, $object) + public function createZentaoObjectLabel($gitlabID, $projectID, $object, $objectID) { - if(empty($object->type) or empty($object->objectID)) return false; - $label = new stdclass; - if($object->type == 'task') + if($object == 'task') { - $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $object->type, $object->objectID); + $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $object, $objectID); $label->color = $config->gitlab->zentaoObjectLabel->taskColor; $label->description = $this->createLink('task', 'view', "taskID={$object->taskID}"); } - elseif($object->type == 'bug') + elseif($object == 'bug') { - $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $object->type, $object->objectID); + $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $object, $objectID); $label->color = $config->gitlab->zentaoObjectLabel->taskColor; $label->description = $this->createLink('bug', 'view', "taskID={$object->bugID}"); } - elseif($object->type == 'story') + elseif($object == 'story') { - $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $object->type, $object->objectID); + $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $object, $objectID); $label->color = $config->gitlab->zentaoObjectLabel->taskColor; $label->description = $this->createLink('story', 'view', "storyID={$object->storyID}"); } @@ -554,6 +553,7 @@ class gitlabModel extends model $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); $this->saveSyncedIssue('task', $task, $gitlab, $issue); + $this->createZentaoObjectLabel($gitlab, $gitlabProject, 'task', $taskID); } /** @@ -573,6 +573,7 @@ class gitlabModel extends model if($syncedIssue) $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); if($issue) $this->saveSyncedIssue('story', $story, $gitlab, $issue); + $this->createZentaoObjectLabel($gitlab, $gitlabProject, 'story', $storyID); } /** From 3188d293a8485a91c64ca0ab471908d041843720 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Fri, 25 Jun 2021 14:32:10 +0800 Subject: [PATCH 120/269] * Adjust create webhook function and format codes. --- module/gitlab/model.php | 93 +++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 60 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 08cab87e6a..ba5d40cd9d 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -139,12 +139,13 @@ class gitlabModel extends model */ public function apiGetUsers($gitlab) { - $api = rtrim($gitlab->url, '/') . '/api/v4/users?private_token=' . $gitlab->token; + $apiRoot = $this->getApiRoot($gitlabID); + $url = sprintf($apiRoot, '/users'); $response = json_decode(commonModel::http($api)); if (!$response) return array(); - $users = array(); + $users = array(); foreach($response as $gitlabUser) { $user = new stdclass; @@ -156,6 +157,7 @@ class gitlabModel extends model $users[] = $user; } + return $users; } @@ -221,14 +223,13 @@ class gitlabModel extends model /** * Create hook. * - * @param int $gitlabID - * @param int $projectID - * @param int $url - * @param int $token + * @param int $gitlabID + * @param int $projectID + * @param string $url * @access public * @return void */ - public function apiCreateHook($gitlabID, $projectID, $url, $token) + public function apiCreateHook($gitlabID, $projectID, $url) { $apiRoot = $this->getApiRoot($gitlabID); @@ -239,12 +240,9 @@ class gitlabModel extends model $postData->push_events = "true"; $postData->tag_push_events = "true"; $postData->url = $url; - $postData->token = $token; - $apiPath = "/projects/{$projectID}/hooks"; - $url = sprintf($apiRoot, $apiPath); - $response = commonModel::http($url, $postData); - return $response; + $url = sprintf($apiRoot, "/projects/{$projectID}/hooks"); + return commonModel::http($url, $postData); } /** @@ -259,10 +257,9 @@ class gitlabModel extends model public function apiDeleteHook($gitlabID, $projectID, $hookID) { $apiRoot = $this->getApiRoot($gitlabID); - $apiPath = "/projects/{$projectID}/hooks/{$hookID}"; - $url = sprintf($apiRoot, $apiPath); - $response = commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'delete')); - return $response; + $url = sprintf($apiRoot, "/projects/{$projectID}/hooks/{$hookID}"); + + return commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'delete')); } /** @@ -297,22 +294,20 @@ class gitlabModel extends model /** * Create Label for gitlab project. * - * @param int $gitlabID - * @param int $projectID - * @param int $label + * @param int $gitlabID + * @param int $projectID + * @param object $label * @access public - * @return void + * @return object */ public function apiCreateLabel($gitlabID, $projectID, $label) { - $apiRoot = $this->getApiRoot($gitlabID); - if(empty($label->name) or empty($label->color)) return false; - $apiPath = "/projects/{$projectID}/labels/"; - $url = sprintf($apiRoot, $apiPath); - $response = commonModel::http($url, $label); - return $response; + $apiRoot = $this->getApiRoot($gitlabID); + + $url = sprintf($apiRoot, "/projects/{$projectID}/labels/"); + return commonModel::http($url, $label); } /** @@ -325,12 +320,11 @@ class gitlabModel extends model */ public function apiGetLabels($gitlabID, $projectID) { - $apiRoot = $this->getApiRoot($gitlabID); - $apiPath = "/projects/{$projectID}/labels/"; - $url = sprintf($apiRoot, $apiPath); + $apiRoot = $this->getApiRoot($gitlabID); + $url = sprintf($apiRoot, "/projects/{$projectID}/labels/"); $response = commonModel::http($url); - $labels = json_decode($response); - return $labels; + + return json_decode($response); } /** @@ -404,10 +398,9 @@ class gitlabModel extends model } /** - * Bind gitlab project. + * Get projects by executionID. * - * @param int $gitlabID - * @param int $projectID + * @param int $executionID * @access public * @return array */ @@ -467,36 +460,16 @@ class gitlabModel extends model */ public function createWebhook($products, $gitlabID, $projectID) { - $urls = $this->getWebhookUrls($gitlabID, $projectID); - + $gitlab = $this->getByID($gitlabID); + $webhooks = $this->apiGetHooks($gitlabID, $projectID); foreach($products as $index => $product) { - $url = sprintf($this->config->gitlab->zentaoApiWebhookUrl, commonModel::getSysURL(), $product, $gitlabID, $projectID); - if(! array_key_exists($url, array_flip($urls))) - { - $response = $this->apiCreateHook($gitlabID, $projectID, $url, $this->config->gitlab->zentaoApiWebhookToken); - } + $url = sprintf($this->config->gitlab->webhookURL, commonModel::getSysURL(), $product, $gitlabID, $gitlab->private); + foreach($webhooks as $webhook) if($webhook->url == $url) continue; + $response = $this->apiCreateHook($gitlabID, $projectID, $url); } - return true; - } - /** - * Get webhook urls - * - * @param int $gitlabID - * @param int $projectID - * @access public - * @return array $urls; - */ - public function getWebhookUrls($gitlabID, $projectID) - { - $urls = array(); - $webhooks = $this->apiGetHooks($gitlabID, $projectID); - foreach($webhooks as $index => $webhook) - { - $urls[] = $webhook->url; - } - return $urls; + return true; } /** From 16488940d4c34057f5d809487f7c72a0cd0cb2d4 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 25 Jun 2021 14:39:31 +0800 Subject: [PATCH 121/269] + Delete a Label by labelName. --- module/gitlab/model.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 0f1b944c13..3289873501 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -333,6 +333,31 @@ class gitlabModel extends model return $labels; } + /** + * Delete a Label by labelName. + * + * @param int $gitlabID + * @param int $projectID + * @param string $labelName + * @access public + * @return void + */ + public function apiDeleteLabel($gitlabID, $projectID, $labelName) + { + $labels = $this->apiGetLabels($gitlabID, $projectID); + foreach($labels as $label) + { + if($label->name == $labelName) $labelID = $label->id; + } + + if(empty($labelID)) return false; + + $apiRoot = $this->getApiRoot($gitlabID); + $url = sprintf($apiRoot, "/projects/{$projectID}/labels/{$labelID}"; + + return json_decode(commonModel::http($url, $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE'))); + } + /** * Create zentao object label for gitlab project. * From 5ca01706dcf93c607e69adbf64f5bcbb11787244 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 25 Jun 2021 14:47:16 +0800 Subject: [PATCH 122/269] * Correct syntax error. --- module/gitlab/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 77724d0e34..f9806e1540 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -347,7 +347,7 @@ class gitlabModel extends model if(empty($labelID)) return false; $apiRoot = $this->getApiRoot($gitlabID); - $url = sprintf($apiRoot, "/projects/{$projectID}/labels/{$labelID}"; + $url = sprintf($apiRoot, "/projects/{$projectID}/labels/{$labelID}"); return json_decode(commonModel::http($url, $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE'))); } From 903f361882899523bcd34f9f4147aeb4be3807f6 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 25 Jun 2021 14:49:42 +0800 Subject: [PATCH 123/269] * Correct syntax error. --- module/gitlab/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index f9806e1540..195338a8fc 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -848,7 +848,7 @@ class gitlabModel extends model */ public function issueToZentaoObject($issue, $gitlabID) { - if(!isset($this->config->gitlab->maps->{$issue->objectType}) return null; + if(!isset($this->config->gitlab->maps->{$issue->objectType})) return null; $maps = $this->config->gitlab->maps->{$issue->objectType}; $gitlabUsers = $this->getUserAccountIdPairs($gitlabID); From 88b5382ce8ee8aa9242eaf88d71323b979daf007 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Fri, 25 Jun 2021 14:55:47 +0800 Subject: [PATCH 124/269] * Add checkwebhook token function. --- module/gitlab/model.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 74e7b3526d..11964b98c5 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -703,6 +703,18 @@ class gitlabModel extends model return $response; } + /** + * webhook check token. + * + * @access public + * @return void + */ + public function webhookCheckToken() + { + $gitlab = $this->getByID($this->get->gitlab); + if($gitlab->private != $this->get->token) die(); + } + /** * Parse webhook body function. * From 9485858e27218aa6b60483dddfa0c101d3d44e10 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Fri, 25 Jun 2021 14:56:24 +0800 Subject: [PATCH 125/269] * Add check webhook token function. --- module/gitlab/control.php | 1 + 1 file changed, 1 insertion(+) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 201f13f110..95120075f8 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -207,6 +207,7 @@ class gitlab extends control */ public function webhook() { + $this->gitlab->webhookCheckToken(); $product = $this->get->product; $gitlab = $this->get->gitlab; $project = $this->get->project; From 354d13f907cbdae9ab316ee9fce03678ab9fa31e Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 25 Jun 2021 15:08:11 +0800 Subject: [PATCH 126/269] * Fix bug when creating zentao object label. --- module/gitlab/model.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 195338a8fc..5c37d82ea7 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -368,20 +368,20 @@ class gitlabModel extends model if($object == 'task') { $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $object, $objectID); - $label->color = $config->gitlab->zentaoObjectLabel->taskColor; - $label->description = $this->createLink('task', 'view', "taskID={$object->taskID}"); + $label->color = $this->config->gitlab->zentaoObjectLabel->taskColor; + $label->description = helper::createLink('task', 'view', "taskID={$object->taskID}"); } elseif($object == 'bug') { $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $object, $objectID); - $label->color = $config->gitlab->zentaoObjectLabel->taskColor; - $label->description = $this->createLink('bug', 'view', "taskID={$object->bugID}"); + $label->color = $this->config->gitlab->zentaoObjectLabel->taskColor; + $label->description = helper::createLink('bug', 'view', "taskID={$object->bugID}"); } elseif($object == 'story') { $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $object, $objectID); - $label->color = $config->gitlab->zentaoObjectLabel->taskColor; - $label->description = $this->createLink('story', 'view', "storyID={$object->storyID}"); + $label->color = $this->config->gitlab->zentaoObjectLabel->taskColor; + $label->description = helper::createLink('story', 'view', "storyID={$object->storyID}"); } return $this->apiCreateLabel($gitlabID, $projectID, $label); From 076cc8b94a5226eff5ca1ab30369a282f8f16b98 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Fri, 25 Jun 2021 15:10:32 +0800 Subject: [PATCH 127/269] *Add private field --- module/gitlab/lang/zh-cn.php | 1 + module/pipeline/model.php | 1 + 2 files changed, 2 insertions(+) diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index 5cfdc0fbe3..24226ad028 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -21,6 +21,7 @@ $lang->gitlab->name = '名称'; $lang->gitlab->url = '服务地址'; $lang->gitlab->token = 'Token'; $lang->gitlab->defaultProject = '默认项目'; +$lang->gitlab->private = 'MD5验证'; $lang->gitlab->lblCreate = '添加gitlab服务器'; $lang->gitlab->desc = '描述'; diff --git a/module/pipeline/model.php b/module/pipeline/model.php index 0fb35d711d..5e7fdba12e 100644 --- a/module/pipeline/model.php +++ b/module/pipeline/model.php @@ -73,6 +73,7 @@ class pipelineModel extends model { $pipeline = fixer::input('post') ->add('type', $type) + ->add('private',md5(rand(10,113450))) ->add('createdBy', $this->app->user->account) ->add('createdDate', helper::now()) ->skipSpecial('url,token,account,password') From 8d7b7316705f98463adff5d0b33564f2e2b65537 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Fri, 25 Jun 2021 15:16:13 +0800 Subject: [PATCH 128/269] * Change zentaoApiWebhookUrl to webhookURL. --- module/gitlab/config.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 6b56cb98b5..8843b49996 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -21,8 +21,7 @@ $config->gitlab->zentaoObjectLabel->storyColor = '#69D100'; $config->gitlab->zentaoObjectLabel->bugColor = '#D10069'; $config->gitlab->zentaoObjectLabel->priority = "0"; -$config->gitlab->zentaoApiWebhookUrl = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s"; -$config->gitlab->zentaoApiWebhookToken = ""; +$config->gitlab->webhookURL = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s&token=%s"; $config->gitlab->skippedFields = new stdclass; $config->gitlab->skippedFields->issueCreate = array(); @@ -84,9 +83,3 @@ $config->gitlab->bugStateMap = array(); $config->gitlab->bugStateMap['active'] = 'reopen'; $config->gitlab->bugStateMap['resolved'] = 'reopen'; $config->gitlab->bugStateMap['closed'] = 'close'; - - - - - - From 179bc3018b2d2b7b170f209f5f8295fb64d62af4 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 25 Jun 2021 15:33:47 +0800 Subject: [PATCH 129/269] * Fix bug when sync task to issue. --- module/gitlab/config.php | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 6b56cb98b5..2b6ef0a344 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -39,6 +39,20 @@ $config->gitlab->maps->task['deadline'] = 'due_date|field|'; $config->gitlab->maps->task['status'] = 'state|configItems|taskStateMap'; $config->gitlab->maps->task['pri'] = 'weight|configItems|taskWeightMap'; +$config->gitlab->maps->story = array(); +$config->gitlab->maps->story['title'] = 'title|field|'; +$config->gitlab->maps->story['spec'] = 'description|fields|verify'; +$config->gitlab->maps->story['openedDate'] = 'created_at|field|'; +$config->gitlab->maps->story['openedBy'] = 'assignee_id|userPairs|'; +$config->gitlab->maps->story['pri'] = 'weight|configItems|storyWeightMap'; + +$config->gitlab->maps->bug = array(); +$config->gitlab->maps->bug['title'] = 'title|field|'; +$config->gitlab->maps->bug['spec'] = 'description|field|'; +$config->gitlab->maps->bug['openedDate'] = 'created_at|field|'; +$config->gitlab->maps->bug['openedBy'] = 'assignee_id|userPairs|'; +$config->gitlab->maps->bug['pri'] = 'weight|configItems|bugWeightMap'; + $config->gitlab->taskWeightMap = array(); $config->gitlab->taskWeightMap['1'] = '1'; $config->gitlab->taskWeightMap['2'] = '2'; @@ -53,27 +67,11 @@ $config->gitlab->taskStateMap['closed'] = 'close'; $config->gitlab->taskTypesToSync = 'design,devel,request,discuss,ui,affair,misc'; -$config->gitlab->maps = new stdclass; -$config->gitlab->maps->story = array(); -$config->gitlab->maps->story['title'] = 'title|field|'; -$config->gitlab->maps->story['spec'] = 'description|fields|verify'; -$config->gitlab->maps->story['openedDate'] = 'created_at|field|'; -$config->gitlab->maps->story['openedBy'] = 'assignee_id|userPairs|'; -$config->gitlab->maps->story['pri'] = 'weight|configItems|storyWeightMap'; - $config->gitlab->storyWeightMap = array(); $config->gitlab->storyWeightMap['1'] = '1'; $config->gitlab->storyWeightMap['2'] = '2'; $config->gitlab->storyWeightMap['3'] = '3'; -$config->gitlab->maps = new stdclass; -$config->gitlab->maps->bug = array(); -$config->gitlab->maps->bug['title'] = 'title|field|'; -$config->gitlab->maps->bug['spec'] = 'description|field|'; -$config->gitlab->maps->bug['openedDate'] = 'created_at|field|'; -$config->gitlab->maps->bug['openedBy'] = 'assignee_id|userPairs|'; -$config->gitlab->maps->bug['pri'] = 'weight|configItems|bugWeightMap'; - $config->gitlab->bugWeightMap = array(); $config->gitlab->bugWeightMap['1'] = '1'; $config->gitlab->bugWeightMap['2'] = '2'; @@ -85,8 +83,3 @@ $config->gitlab->bugStateMap['active'] = 'reopen'; $config->gitlab->bugStateMap['resolved'] = 'reopen'; $config->gitlab->bugStateMap['closed'] = 'close'; - - - - - From 5a931d88b9468433f2892eda472add451f20eb31 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 25 Jun 2021 15:34:46 +0800 Subject: [PATCH 130/269] * Optimize codes of label related and etc. --- module/gitlab/model.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 0c3c56d65b..9269fa382f 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -357,31 +357,31 @@ class gitlabModel extends model * * @param int $gitlabID * @param int $projectID - * @param string $object + * @param string $objectType * @param string $objectID * @access public * @return object */ - public function createZentaoObjectLabel($gitlabID, $projectID, $object, $objectID) + public function createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID) { $label = new stdclass; - if($object == 'task') + if($objectType == 'task') { - $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $object, $objectID); + $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); $label->color = $this->config->gitlab->zentaoObjectLabel->taskColor; - $label->description = helper::createLink('task', 'view', "taskID={$object->taskID}"); + $label->description = helper::createLink('task', 'view', "taskID={$objectID}"); } - elseif($object == 'bug') + elseif($objectType == 'bug') { - $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $object, $objectID); + $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); $label->color = $this->config->gitlab->zentaoObjectLabel->taskColor; - $label->description = helper::createLink('bug', 'view', "taskID={$object->bugID}"); + $label->description = helper::createLink('bug', 'view', "bugID={$objectID}"); } - elseif($object == 'story') + elseif($objectType == 'story') { - $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $object, $objectID); + $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); $label->color = $this->config->gitlab->zentaoObjectLabel->taskColor; - $label->description = helper::createLink('story', 'view', "storyID={$object->storyID}"); + $label->description = helper::createLink('story', 'view', "storyID={$objectID}"); } return $this->apiCreateLabel($gitlabID, $projectID, $label); @@ -604,6 +604,8 @@ class gitlabModel extends model */ public function saveSyncedIssue($objectType, $object, $gitlab, $issue) { + if(empty($issue->iid) or empty($issue->project_id)) return false; + $relation = new stdclass; $relation->execution = zget($object, 'execution', 0); $relation->AType = $objectType; From ad0175744bdf78398e68c11e5b8efbcfb9b2fb4d Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 25 Jun 2021 15:53:07 +0800 Subject: [PATCH 131/269] + Put root URL to created link. --- module/gitlab/model.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 9269fa382f..cb1f05b8c9 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -369,19 +369,19 @@ class gitlabModel extends model { $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); $label->color = $this->config->gitlab->zentaoObjectLabel->taskColor; - $label->description = helper::createLink('task', 'view', "taskID={$objectID}"); + $label->description = common::getSysURL() . helper::createLink('task', 'view', "taskID={$objectID}"); } elseif($objectType == 'bug') { $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); $label->color = $this->config->gitlab->zentaoObjectLabel->taskColor; - $label->description = helper::createLink('bug', 'view', "bugID={$objectID}"); + $label->description = common::getSysURL() . helper::createLink('bug', 'view', "bugID={$objectID}"); } elseif($objectType == 'story') { $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); $label->color = $this->config->gitlab->zentaoObjectLabel->taskColor; - $label->description = helper::createLink('story', 'view', "storyID={$objectID}"); + $label->description = common::getSysURL() . helper::createLink('story', 'view', "storyID={$objectID}"); } return $this->apiCreateLabel($gitlabID, $projectID, $label); From 758f1b7d69c102be06ea8b6cc2d79fa1f32074d8 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 25 Jun 2021 16:43:56 +0800 Subject: [PATCH 132/269] * Bind label when create issue for sync task and story. --- module/gitlab/model.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index cb1f05b8c9..9026a14c15 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -547,11 +547,14 @@ class gitlabModel extends model $syncedIssue = $this->getSyncedIssue($objectType = 'task', $objectID = $taskID, $gitlab); $issue = $this->taskToIssue($gitlab, $gitlabProject, $task); + + $this->createZentaoObjectLabel($gitlab, $gitlabProject, 'task', $taskID); + $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'task', $taskID); + if($syncedIssue) $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); $this->saveSyncedIssue('task', $task, $gitlab, $issue); - $this->createZentaoObjectLabel($gitlab, $gitlabProject, 'task', $taskID); } /** @@ -568,10 +571,13 @@ class gitlabModel extends model $story = $this->loadModel('story')->getByID($storyID); $syncedIssue = $this->getSyncedIssue($objectType = 'story', $objectID = $storyID, $gitlab); $issue = $this->storyToIssue($gitlab, $gitlabProject, $story); + + $this->createZentaoObjectLabel($gitlab, $gitlabProject, 'story', $storyID); + $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'story', $storyID); + if($syncedIssue) $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); if($issue) $this->saveSyncedIssue('story', $story, $gitlab, $issue); - $this->createZentaoObjectLabel($gitlab, $gitlabProject, 'story', $storyID); } /** From 10ad9f6010a8bec66c439c43934ccb52569e8fd9 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Fri, 25 Jun 2021 16:55:40 +0800 Subject: [PATCH 133/269] * Fix params of webhookSyncIssue function. --- module/gitlab/model.php | 44 ++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index cb1f05b8c9..871ebbfb3e 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -535,9 +535,9 @@ class gitlabModel extends model /** * Sync task to gitlab issue. * - * @param int $taskID - * @param int $gitlab - * @param int $gitlabProject + * @param int $taskID + * @param int $gitlab + * @param int $gitlabProject * @access public * @return void */ @@ -586,10 +586,10 @@ class gitlabModel extends model public function getSyncedIssue($objectType, $objectID, $gitlab) { return $this->dao->select('*')->from(TABLE_RELATION) - ->where('AType')->eq($objectType) - ->andWhere('AID')->eq($objectID) - ->andWhere('extra')->eq($gitlab) - ->fetch(); + ->where('AType')->eq($objectType) + ->andWhere('AID')->eq($objectID) + ->andWhere('extra')->eq($gitlab) + ->fetch(); } /** @@ -684,6 +684,15 @@ class gitlabModel extends model return $issue; } + /** + * Api create issue. + * + * @param int $gitlabID + * @param int $projectID + * @param object $issue + * @access public + * @return void + */ public function apiCreateIssue($gitlabID, $projectID, $issue) { $apiRoot = $this->getApiRoot($gitlabID); @@ -700,10 +709,10 @@ class gitlabModel extends model /** * Update issue with new attribute using gitlab API. * - * @param int $gitlabID - * @param int $projectID - * @param int $issueID - * @param object $attribute + * @param int $gitlabID + * @param int $projectID + * @param int $issueID + * @param object $attribute * @access public * @return object */ @@ -726,7 +735,7 @@ class gitlabModel extends model public function pushBug($gitlabID, $projectID, $bug) { $bug->label = $this->config->gitlab->bugLabel->name; - $response = $this->apiCreateIssue($gitlabID, $projectID, $bug); + $response = $this->apiCreateIssue($gitlabID, $projectID, $bug); return $response; } @@ -771,13 +780,15 @@ class gitlabModel extends model if(empty($object)) return null; $issue = new stdclass; - $issue->action = $body->object_attributes->action . $body->object_kind; - $issue->issue = $body->object_attributes; + $issue->action = $body->object_attributes->action . $body->object_kind; + $issue->issue = $body->object_attributes; + $issue->objectType = $object->type; + $issue->objectID = $object->id; $issue->issue->objectType = $object->type; $issue->issue->objectID = $object->id; - if(!isset($this->config->gitlab->maps->$object->type)) return false; + if(!isset($this->config->gitlab->maps->{$object->type})) return false; $issue->object = $this->issueToZentaoObject($issue->issue, $gitlabID); return $issue; } @@ -821,10 +832,11 @@ class gitlabModel extends model * @access public * @return void */ - public function webhookSyncIssue($issue) + public function webhookSyncIssue($gitlabID, $issue) { $tableName = zget($this->config->gitlab->objectTables, $issue->objectType, ''); if($tableName) $this->dao->update($tableName)->data($issue->object)->where('id')->eq($issue->objectID)->exec(); + a($this->dao->get());exit; return !dao::isError(); } From 6957dcadef5eb583a5117107698d6f87ee6f8ea5 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Fri, 25 Jun 2021 16:58:53 +0800 Subject: [PATCH 134/269] * Fix apigetuser bug. --- module/gitlab/model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 064e1b26a9..7f75fad7e3 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -139,9 +139,9 @@ class gitlabModel extends model */ public function apiGetUsers($gitlab) { - $apiRoot = $this->getApiRoot($gitlabID); + $apiRoot = $this->getApiRoot($gitlab->id); $url = sprintf($apiRoot, '/users'); - $response = json_decode(commonModel::http($api)); + $response = json_decode(commonModel::http($url)); if (!$response) return array(); From af7ac63f2edc11e39e43c17cb282b94f1eff7c02 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Fri, 25 Jun 2021 17:20:40 +0800 Subject: [PATCH 135/269] * Add gitlab webhook filter config. --- config/filter.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config/filter.php b/config/filter.php index f69a51cd97..680245f08b 100644 --- a/config/filter.php +++ b/config/filter.php @@ -56,6 +56,7 @@ $filter->webhook = new stdclass(); $filter->git = new stdclass(); $filter->svn = new stdclass(); $filter->search = new stdclass(); +$filter->gitlab = new stdclass(); $filter->block->default = new stdclass(); $filter->block->main = new stdclass(); @@ -130,6 +131,7 @@ $filter->webhook->bind = new stdclass(); $filter->user->ajaxgetmore = new stdclass(); $filter->repo->ajaxsynccommit = new stdclass(); $filter->search->index = new stdclass(); +$filter->gitlab->webhook = new stdclass(); $filter->bug->batchcreate->cookie['preBranch'] = 'int'; $filter->bug->browse->cookie['bugModule'] = 'int'; @@ -308,3 +310,8 @@ $filter->webhook->bind->cookie['selectedDepts'] = 'reg::checked'; $filter->search->index->get['words'] = 'reg::any'; $filter->search->index->get['type'] = 'code'; + +$filter->gitlab->webhook->get['gitlab'] = 'int'; +$filter->gitlab->webhook->get['product'] = 'int'; +$filter->gitlab->webhook->get['project'] = 'int'; +$filter->gitlab->webhook->get['token'] = 'reg::any'; From 898fd11a5895ffb0b2a59207a4f5fc20f1ba690c Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Fri, 25 Jun 2021 17:21:22 +0800 Subject: [PATCH 136/269] * Add gitlab objectTables config. --- module/gitlab/config.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 7a1656ad3b..daeb53eac6 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -82,3 +82,8 @@ $config->gitlab->bugStateMap['active'] = 'reopen'; $config->gitlab->bugStateMap['resolved'] = 'reopen'; $config->gitlab->bugStateMap['closed'] = 'close'; +$config->gitlab->objectTables = new stdclass; +$config->gitlab->objectTables->story = TABLE_STORY; +$config->gitlab->objectTables->task = TABLE_TASK; +$config->gitlab->objectTables->bug = TABLE_BUG; + From 2076a3aadb968c9303c15ca17e38fb3faa578750 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Fri, 25 Jun 2021 17:55:19 +0800 Subject: [PATCH 137/269] * Change markdown description to html. --- module/gitlab/model.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 7f75fad7e3..c91272bf39 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -794,6 +794,9 @@ class gitlabModel extends model $issue->issue->objectType = $object->type; $issue->issue->objectID = $object->id; + /* Parse markdown description to html. */ + $issue->issue->description = $this->app->loadClass('hyperdown')->makeHtml($issue->issue->description); + if(!isset($this->config->gitlab->maps->{$object->type})) return false; $issue->object = $this->issueToZentaoObject($issue->issue, $gitlabID); return $issue; From 3429d54c09ceefb06233be96c95157e816dd0d8c Mon Sep 17 00:00:00 2001 From: lichengjun Date: Mon, 28 Jun 2021 08:38:59 +0800 Subject: [PATCH 138/269] * Add sync bug to issue. --- module/bug/control.php | 7 ++++ module/bug/js/create.js | 20 +++++++++++ module/bug/lang/zh-cn.php | 1 + module/bug/model.php | 6 +++- module/bug/view/create.html.php | 8 +++++ module/common/model.php | 1 - module/gitlab/control.php | 2 +- module/gitlab/model.php | 61 +++++++++++++++++++++++++++++++++ 8 files changed, 103 insertions(+), 3 deletions(-) diff --git a/module/bug/control.php b/module/bug/control.php index 0dabb253a3..84d137d9f0 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -557,6 +557,13 @@ class bug extends control $this->view->customFields = $customFields; $this->view->showFields = $this->config->bug->custom->createFields; + /* Set gitlabProjects. */ + $allGitlabs = $this->loadModel('gitlab')->getPairs(); + $gitlabProjects = $this->loadModel('gitlab')->getProjectsByExecution($executionID); + foreach($allGitlabs as $id => $name) if($id and !isset($gitlabProjects[$id])) unset($allGitlabs[$id]); + $this->view->gitlabList = $allGitlabs; + $this->view->gitlabProjects = $gitlabProjects; + $this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->bug->create; $this->view->position[] = html::a($this->createLink('bug', 'browse', "productID=$productID"), $this->products[$productID]); $this->view->position[] = $this->lang->bug->create; diff --git a/module/bug/js/create.js b/module/bug/js/create.js index b602586a0a..45e46052d7 100644 --- a/module/bug/js/create.js +++ b/module/bug/js/create.js @@ -155,3 +155,23 @@ $(function() $(window).unload(function(){ if(blockID) window.parent.refreshBlock($('#block' + blockID)); }); + +$(document).ready(function() +{ + $('#gitlab').change(function() + { + host = $('#gitlab').val(); + if(host == '') return false; + projects = ''; + $.each(gitlabProjects[host], function(id, obj){projects = projects + ',' + obj.gitlabProject}); + url = createLink('repo', 'ajaxgetgitlabprojects', "host=" + host + "&projects=" + projects); + + $.get(url, function(response) + { + $('#gitlabProject').html('').append(response); + $('#gitlabProject').chosen().trigger("chosen:updated");; + }); + + }); + +}); diff --git a/module/bug/lang/zh-cn.php b/module/bug/lang/zh-cn.php index 7dfd1e848b..82912a0c71 100644 --- a/module/bug/lang/zh-cn.php +++ b/module/bug/lang/zh-cn.php @@ -24,6 +24,7 @@ $lang->bug->storyVersion = "{$lang->SRCommon}版本"; $lang->bug->color = '标题颜色'; $lang->bug->task = '相关任务'; $lang->bug->title = 'Bug标题'; +$lang->bug->sync2gitlab = '同步gitlab'; $lang->bug->severity = '严重程度'; $lang->bug->severityAB = '级别'; $lang->bug->pri = '优先级'; diff --git a/module/bug/model.php b/module/bug/model.php index b9e9f11ef5..c3e2283689 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -84,10 +84,14 @@ class bugModel extends model /* Use classic mode to replace required project. */ if($this->config->systemMode == 'classic' and strpos($this->config->bug->create->requiredFields, 'project') !== false) $this->config->bug->create->requiredFields = str_replace('project', 'execution', $this->config->bug->create->requiredFields); - $this->dao->insert(TABLE_BUG)->data($bug)->autoCheck()->batchCheck($this->config->bug->create->requiredFields, 'notempty')->exec(); + $this->dao->insert(TABLE_BUG)->data($bug, $skip = 'gitlab,gitlabProject')->autoCheck()->batchCheck($this->config->bug->create->requiredFields, 'notempty')->exec(); if(!dao::isError()) { $bugID = $this->dao->lastInsertID(); + + /* Sync this bug to gitlab issue. */ + $this->loadModel('gitlab')->syncBug($bugID, $this->post->gitlab, $this->post->gitlabProject); + $this->file->updateObjectID($this->post->uid, $bugID, 'bug'); $this->file->saveUpload('bug', $bugID); empty($bug->case) ? $this->loadModel('score')->create('bug', 'create', $bugID) : $this->loadModel('score')->create('bug', 'createFormCase', $bug->case); diff --git a/module/bug/view/create.html.php b/module/bug/view/create.html.php index a742898300..951d25b4fb 100644 --- a/module/bug/view/create.html.php +++ b/module/bug/view/create.html.php @@ -26,6 +26,7 @@ js::set('isStepsTemplate', $isStepsTemplate); js::set('oldProjectID', $projectID); js::set('blockID', $blockID); js::set('moduleID', $moduleID); +js::set('gitlabProjects', $gitlabProjects); ?>
@@ -312,6 +313,13 @@ js::set('moduleID', $moduleID);
+ + + + + + + diff --git a/module/common/model.php b/module/common/model.php index 242e393959..03a0fe0b96 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -2230,7 +2230,6 @@ EOD; } if($options) curl_setopt_array($curl, $options); - $response = curl_exec($curl); $errors = curl_error($curl); diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 95120075f8..91e2b57aa6 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -239,7 +239,7 @@ class gitlab extends control public function test($id = 11) { - $gitlabID = 11; $projectID = 36; + $gitlabID = 1; $projectID = 7; $task = $this->loadModel('task')->getByID($id); $issue = $this->gitlab->taskToIssue($gitlabID, $projectID, $task); $issue = $this->gitlab->apiCreateIssue($gitlabID, $projectID, $issue); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 7f75fad7e3..db3d77d6a5 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -580,6 +580,30 @@ class gitlabModel extends model if($issue) $this->saveSyncedIssue('story', $story, $gitlab, $issue); } + /** + * Sync bug to gitlab issue. + * + * @param int $storyID + * @param int $gitlab + * @param int $gitlabProject + * @access public + * @return void + */ + public function syncBug($bugID, $gitlab, $gitlabProject) + { + $bug = $this->loadModel('bug')->getByID($bugID); + + $syncedIssue = $this->getSyncedIssue($objectType = 'bug', $objectID = $bugID, $gitlab); + $issue = $this->bugToIssue($gitlab, $gitlabProject, $bug); + + $this->createZentaoObjectLabel($gitlab, $gitlabProject, 'bug', $bugID); + $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'bug', $storyID); + + if($syncedIssue) $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); + $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); + if($issue) $this->saveSyncedIssue('bug', $story, $gitlab, $issue); + } + /** * Get synced issue from relation table. * @@ -690,6 +714,43 @@ class gitlabModel extends model return $issue; } + /** + * Parse bug to issue. + * + * @param int $gitlabID + * @param int $gitlabProjectID + * @param object $story + * @access public + * @return object + */ + public function bugToIssue($gitlabID, $gitlabProjectID, $bug) + { + $map = $this->config->gitlab->maps->bug; + $issue = new stdclass; + $gitlabUsers = $this->getUserAccountIdPairs($gitlabID); + if(empty($gitlabUsers)) return false; + + foreach($map as $storyField => $config) + { + $value = ''; + list($field, $optionType, $options) = explode('|', $config); + if($optionType == 'field') $value = $bug->$bugField; + if($optionType == 'fields') $value = $bug->$bugField . "\n\n" . $story->$options; + if($optionType == 'userPairs') + { + $value = zget($gitlabUsers, $story->$bugField); + } + if($optionType == 'configItems') + { + $value = zget($this->config->gitlab->$options, $bug->$bugField, ''); + } + if($value) $issue->$field = $value; + } + + var_dump($issue);die; + return $issue; + } + /** * Api create issue. * From 3907ff1ea7fd2c9d2c08317e9e465072edfceb3a Mon Sep 17 00:00:00 2001 From: lichengjun Date: Mon, 28 Jun 2021 11:24:55 +0800 Subject: [PATCH 139/269] * Add bug fix. --- module/gitlab/model.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index db3d77d6a5..e81f82cf6d 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -597,11 +597,11 @@ class gitlabModel extends model $issue = $this->bugToIssue($gitlab, $gitlabProject, $bug); $this->createZentaoObjectLabel($gitlab, $gitlabProject, 'bug', $bugID); - $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'bug', $storyID); + sprintf($this->config->gitlab->zentaoObjectLabel->name, 'bug', $bugID); if($syncedIssue) $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); - if($issue) $this->saveSyncedIssue('bug', $story, $gitlab, $issue); + if($issue) $this->saveSyncedIssue('bug', $bug, $gitlab, $issue); } /** @@ -730,7 +730,7 @@ class gitlabModel extends model $gitlabUsers = $this->getUserAccountIdPairs($gitlabID); if(empty($gitlabUsers)) return false; - foreach($map as $storyField => $config) + foreach($map as $bugField => $config) { $value = ''; list($field, $optionType, $options) = explode('|', $config); @@ -738,7 +738,7 @@ class gitlabModel extends model if($optionType == 'fields') $value = $bug->$bugField . "\n\n" . $story->$options; if($optionType == 'userPairs') { - $value = zget($gitlabUsers, $story->$bugField); + $value = zget($gitlabUsers, $bug->$bugField); } if($optionType == 'configItems') { @@ -747,7 +747,6 @@ class gitlabModel extends model if($value) $issue->$field = $value; } - var_dump($issue);die; return $issue; } From e0e72bf4e3c78cd581a596601645162ab74a4556 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 28 Jun 2021 13:08:33 +0800 Subject: [PATCH 140/269] * Fix parse gitlab user id error. --- module/gitlab/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 89951b3aab..1ec21a890b 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -946,7 +946,7 @@ class gitlabModel extends model if(!isset($this->config->gitlab->maps->{$issue->objectType})) return null; $maps = $this->config->gitlab->maps->{$issue->objectType}; - $gitlabUsers = $this->getUserAccountIdPairs($gitlabID); + $gitlabUsers = $this->getUserIdAccountPairs($gitlabID); $object = new stdclass; $object->id = $issue->objectID; From 6f424a14664450a520726a8bc8e304e53935b4c6 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 28 Jun 2021 13:51:32 +0800 Subject: [PATCH 141/269] * Return object for webhook. --- module/gitlab/control.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 91e2b57aa6..1283e08487 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -216,7 +216,7 @@ class gitlab extends control //$input = file_get_contents('php://input'); $requestBody = json_decode($input); $result = $this->gitlab->webhookParseBody($requestBody, $gitlab); - a($result);exit; + $logFile = $this->app->getLogRoot() . 'webhook.'. date('Ymd') . '.log.php'; if(!file_exists($logFile)) file_put_contents($logFile, ''); @@ -233,7 +233,7 @@ class gitlab extends control $this->view->result = 'success'; $this->view->status = 'ok'; - $this->view->data = 'ougiugjvh'; + $this->view->data = $result->object; $this->display(); } From be619512c460b03c665de18cfc4c2d6c237acea8 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Mon, 28 Jun 2021 14:04:02 +0800 Subject: [PATCH 142/269] * Adj Code. --- module/bug/model.php | 2 +- module/gitlab/config.php | 6 +++--- module/gitlab/model.php | 28 ++++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/module/bug/model.php b/module/bug/model.php index c3e2283689..a7892a8a64 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -90,7 +90,7 @@ class bugModel extends model $bugID = $this->dao->lastInsertID(); /* Sync this bug to gitlab issue. */ - $this->loadModel('gitlab')->syncBug($bugID, $this->post->gitlab, $this->post->gitlabProject); + $this->loadModel('gitlab')->pushToissue($bugID, $this->post->gitlab, $this->post->gitlabProject,'bug'); $this->file->updateObjectID($this->post->uid, $bugID, 'bug'); $this->file->saveUpload('bug', $bugID); diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 7a1656ad3b..17258a2c5d 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -42,14 +42,14 @@ $config->gitlab->maps->story = array(); $config->gitlab->maps->story['title'] = 'title|field|'; $config->gitlab->maps->story['spec'] = 'description|fields|verify'; $config->gitlab->maps->story['openedDate'] = 'created_at|field|'; -$config->gitlab->maps->story['openedBy'] = 'assignee_id|userPairs|'; +$config->gitlab->maps->story['assignedTo'] = 'assignee_id|userPairs|'; $config->gitlab->maps->story['pri'] = 'weight|configItems|storyWeightMap'; $config->gitlab->maps->bug = array(); $config->gitlab->maps->bug['title'] = 'title|field|'; -$config->gitlab->maps->bug['spec'] = 'description|field|'; +$config->gitlab->maps->bug['steps'] = 'description|field|'; $config->gitlab->maps->bug['openedDate'] = 'created_at|field|'; -$config->gitlab->maps->bug['openedBy'] = 'assignee_id|userPairs|'; +$config->gitlab->maps->bug['assignedTo'] = 'assignee_id|userPairs|'; $config->gitlab->maps->bug['pri'] = 'weight|configItems|bugWeightMap'; $config->gitlab->taskWeightMap = array(); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index e81f82cf6d..83f8f1fa85 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -597,13 +597,37 @@ class gitlabModel extends model $issue = $this->bugToIssue($gitlab, $gitlabProject, $bug); $this->createZentaoObjectLabel($gitlab, $gitlabProject, 'bug', $bugID); - sprintf($this->config->gitlab->zentaoObjectLabel->name, 'bug', $bugID); + $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'bug', $bugID); if($syncedIssue) $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); if($issue) $this->saveSyncedIssue('bug', $bug, $gitlab, $issue); } + /** + * Push to gitlab issue. + * + * @param int $storyID + * @param int $gitlab + * @param int $gitlabProject + * @access public + * @return void + */ + public function PushToissue($ID, $gitlabID, $gitlabProject, $type) + { + $data = $this->loadModel($type)->getByID($ID); + + $syncedIssue = $this->getSyncedIssue($objectType = $type, $objectID = $ID, $gitlabID); + $issue = $this->bugToIssue($gitlabID, $gitlabProject, $data); + + $this->createZentaoObjectLabel($gitlabID, $gitlabProject, $type, $ID); + $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, $type, $ID); + + if($syncedIssue) $issue = $this->apiUpdateIssue($gitlabID, $gitlabProject, $syncedIssue, $issue); + $issue = $this->apiCreateIssue($gitlabID, $gitlabProject, $issue); + if($issue) $this->saveSyncedIssue($type, $data, $gitlabID, $issue); + } + /** * Get synced issue from relation table. * @@ -735,7 +759,7 @@ class gitlabModel extends model $value = ''; list($field, $optionType, $options) = explode('|', $config); if($optionType == 'field') $value = $bug->$bugField; - if($optionType == 'fields') $value = $bug->$bugField . "\n\n" . $story->$options; + if($optionType == 'fields') $value = $bug->$bugField . "\n\n" . $bug->$options; if($optionType == 'userPairs') { $value = zget($gitlabUsers, $bug->$bugField); From 9623172398753a02f5f9454cc9115d466dd9d5c4 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 28 Jun 2021 14:39:33 +0800 Subject: [PATCH 143/269] * Ready for pushing story to issue. --- module/gitlab/config.php | 1 + module/gitlab/model.php | 53 +++++++++++++++++++++++++++++++--------- module/story/model.php | 23 ++++++++++++++--- 3 files changed, 61 insertions(+), 16 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 7a1656ad3b..5f802dcc6c 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -43,6 +43,7 @@ $config->gitlab->maps->story['title'] = 'title|field|'; $config->gitlab->maps->story['spec'] = 'description|fields|verify'; $config->gitlab->maps->story['openedDate'] = 'created_at|field|'; $config->gitlab->maps->story['openedBy'] = 'assignee_id|userPairs|'; +$config->gitlab->maps->story['assignedTo'] = 'assignee_id|userPairs|'; $config->gitlab->maps->story['pri'] = 'weight|configItems|storyWeightMap'; $config->gitlab->maps->bug = array(); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index db3d77d6a5..9d03b2bc4d 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -478,6 +478,23 @@ class gitlabModel extends model ->fetchGroup('AID'); } + /** + * Get gitlabID and projectID. + * + * @param string $objectType + * @param int $objectID + * @access public + * @return object + */ + public function getGitlabIDprojectID($objectType, $objectID) + { + return $this->dao->select('extra as gitlabID, BVersion as projectID')->from(TABLE_RELATION) + ->where('relation')->eq('gitlab') + ->andWhere('Atype')->eq($objectType) + ->andWhere('AID')->eq($objectID) + ->fetch(); + } + /** * Create relationship between zentao product and gitlab project. * @@ -558,7 +575,7 @@ class gitlabModel extends model } /** - * Sync story to gitlab issue. + * Push story to gitlab issue. * * @param int $storyID * @param int $gitlab @@ -566,18 +583,30 @@ class gitlabModel extends model * @access public * @return void */ - public function syncStory($storyID, $gitlab, $gitlabProject) + public function pushStory($storyID, $gitlabID, $projectID) { $story = $this->loadModel('story')->getByID($storyID); - $syncedIssue = $this->getSyncedIssue($objectType = 'story', $objectID = $storyID, $gitlab); - $issue = $this->storyToIssue($gitlab, $gitlabProject, $story); - - $this->createZentaoObjectLabel($gitlab, $gitlabProject, 'story', $storyID); - $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'story', $storyID); - - if($syncedIssue) $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); - $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); - if($issue) $this->saveSyncedIssue('story', $story, $gitlab, $issue); + if(!$gitlabID or !$projectID) + { + $result = $this->getGitlabIDprojectID('story', $storyID); + $gitlabID = $result->gitlabID; + $projectID = $result->projectID; + } + + $syncedIssue = $this->getSyncedIssue($objectType = 'story', $objectID = $storyID, $gitlabID); + $issue = $this->storyToIssue($gitlabID, $projectID, $story); + + if($syncedIssue) + { + $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->AID, $issue); + } + else + { + $this->createZentaoObjectLabel($gitlabID, $projectID, 'story', $storyID); + $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'story', $storyID); + $issue = $this->apiCreateIssue($gitlabID, $projectID, $issue); + if($issue) $this->saveSyncedIssue('story', $story, $gitlabID, $issue); + } } /** @@ -710,7 +739,7 @@ class gitlabModel extends model } if($value) $issue->$field = $value; } - + return $issue; } diff --git a/module/story/model.php b/module/story/model.php index 194ab52831..d92b9329d3 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -339,8 +339,8 @@ class storyModel extends model /* Callback the callable method to process the related data for object that is transfered to story. */ if($from && is_callable(array($this, $this->config->story->fromObjects[$from]['callback']))) call_user_func(array($this, $this->config->story->fromObjects[$from]['callback']), $storyID); - /* sync this story to gitlab issue */ - $this->loadModel('gitlab')->syncStory($storyID, $this->post->gitlab, $this->post->gitlabProject); + /* push this story to gitlab issue */ + $this->loadModel('gitlab')->pushStory($storyID, $this->post->gitlab, $this->post->gitlabProject); return array('status' => 'created', 'id' => $storyID); } @@ -830,6 +830,9 @@ class storyModel extends model $this->dao->insert(TABLE_STORYREVIEW)->data($reviewData)->exec(); } + /* Push this story to gitlab issue. */ + $this->loadModel('gitlab')->pushStory($storyID, $this->post->gitlab, $this->post->gitlabProject); + unset($oldStory->parent); unset($story->parent); return common::createChanges($oldStory, $story); @@ -1765,7 +1768,13 @@ class storyModel extends model $story->assignedDate = $now; $this->dao->update(TABLE_STORY)->data($story)->autoCheck()->where('id')->eq((int)$storyID)->exec(); - if(!dao::isError()) return common::createChanges($oldStory, $story); + if(!dao::isError()) + { + /* Push this story to gitlab issue. */ + $this->loadModel('gitlab')->pushStory($storyID, $this->post->gitlab, $this->post->gitlabProject); + + return common::createChanges($oldStory, $story); + } return false; } @@ -1794,7 +1803,13 @@ class storyModel extends model $story->assignedDate = $now; $this->dao->update(TABLE_STORY)->data($story)->autoCheck()->where('id')->eq((int)$storyID)->exec(); - if(!dao::isError()) $allChanges[$storyID] = common::createChanges($oldStory, $story); + if(!dao::isError()) + { + /* Push this story to gitlab issue. */ + $this->loadModel('gitlab')->pushStory($storyID, $this->post->gitlab, $this->post->gitlabProject); + + $allChanges[$storyID] = common::createChanges($oldStory, $story); + } } return $allChanges; } From aebfaa2fbeda416709b6057c25339a568731619d Mon Sep 17 00:00:00 2001 From: lichengjun Date: Mon, 28 Jun 2021 15:02:53 +0800 Subject: [PATCH 144/269] *Adj code. --- module/bug/model.php | 2 +- module/gitlab/model.php | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/module/bug/model.php b/module/bug/model.php index a7892a8a64..a52f200b1e 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -90,7 +90,7 @@ class bugModel extends model $bugID = $this->dao->lastInsertID(); /* Sync this bug to gitlab issue. */ - $this->loadModel('gitlab')->pushToissue($bugID, $this->post->gitlab, $this->post->gitlabProject,'bug'); + $this->loadModel('gitlab')->pushToissue('bug', $bugID, $this->post->gitlab, $this->post->gitlabProject); $this->file->updateObjectID($this->post->uid, $bugID, 'bug'); $this->file->saveUpload('bug', $bugID); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 07ba92caf4..15b5ebde9a 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -607,25 +607,26 @@ class gitlabModel extends model /** * Push to gitlab issue. * - * @param int $storyID - * @param int $gitlab - * @param int $gitlabProject + * @param string $objectType + * @param int $objectID + * @param int $gitlab + * @param int $gitlabProject * @access public * @return void */ - public function PushToissue($ID, $gitlabID, $gitlabProject, $type) + public function pushToissue($objectType, $objectID, $gitlabID, $gitlabProject) { - $data = $this->loadModel($type)->getByID($ID); + $data = $this->loadModel($objectType)->getByID($objectID); - $syncedIssue = $this->getSyncedIssue($objectType = $type, $objectID = $ID, $gitlabID); + $syncedIssue = $this->getSyncedIssue($objectType = $objectType, $objectID = $objectID, $gitlabID); $issue = $this->bugToIssue($gitlabID, $gitlabProject, $data); - $this->createZentaoObjectLabel($gitlabID, $gitlabProject, $type, $ID); - $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, $type, $ID); + $this->createZentaoObjectLabel($gitlabID, $gitlabProject, $objectType, $objectID); + $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); if($syncedIssue) $issue = $this->apiUpdateIssue($gitlabID, $gitlabProject, $syncedIssue, $issue); $issue = $this->apiCreateIssue($gitlabID, $gitlabProject, $issue); - if($issue) $this->saveSyncedIssue($type, $data, $gitlabID, $issue); + if($issue) $this->saveSyncedIssue($objectType, $data, $gitlabID, $issue); } /** From 6a358a0cf8c0862eb3229aa9ff40cd9b7ccc382f Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 28 Jun 2021 16:54:29 +0800 Subject: [PATCH 145/269] * Optimize this function. --- module/gitlab/model.php | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 668c598615..dc57e7351e 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -639,23 +639,36 @@ class gitlabModel extends model * @param string $objectType * @param int $objectID * @param int $gitlab - * @param int $gitlabProject + * @param int $projectID * @access public * @return void */ - public function pushToissue($objectType, $objectID, $gitlabID, $gitlabProject) + public function pushToissue($objectType, $objectID, $gitlabID, $projectID) { - $data = $this->loadModel($objectType)->getByID($objectID); + $object = $this->loadModel($objectType)->getByID($objectID); + if(!$gitlabID or !$projectID) + { + $result = $this->getGitlabIDprojectID($objectType, $objectID); + $gitlabID = $result->gitlabID; + $projectID = $result->projectID; + } $syncedIssue = $this->getSyncedIssue($objectType = $objectType, $objectID = $objectID, $gitlabID); - $issue = $this->bugToIssue($gitlabID, $gitlabProject, $data); + if($objectType == 'story') $issue = $this->storyToIssue($gitlabID, $projectID, $objectID); + if($objectType == 'task') $issue = $this->taskToIssue($gitlabID, $projectID, $objectID); + if($objectType == 'bug') $issue = $this->bugToIssue($gitlabID, $projectID, $objectID); - $this->createZentaoObjectLabel($gitlabID, $gitlabProject, $objectType, $objectID); - $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); - - if($syncedIssue) $issue = $this->apiUpdateIssue($gitlabID, $gitlabProject, $syncedIssue, $issue); - $issue = $this->apiCreateIssue($gitlabID, $gitlabProject, $issue); - if($issue) $this->saveSyncedIssue($objectType, $data, $gitlabID, $issue); + if($syncedIssue) + { + $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue, $issue); + } + else + { + $this->createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID); + $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); + $issue = $this->apiCreateIssue($gitlabID, $projectID, $issue); + if($issue) $this->saveSyncedIssue($objectType, $objectID, $gitlabID, $issue); + } } /** From cc64050647f3235109b195d67277316cc72722f3 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 28 Jun 2021 17:16:52 +0800 Subject: [PATCH 146/269] + Add delete an issue function. --- module/gitlab/model.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index dc57e7351e..c715d09a89 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -858,6 +858,23 @@ class gitlabModel extends model return $response; } + /** + * Delete an issue. + * + * @param int $gitlabID + * @param int $projectID + * @param int $issueID + * @access public + * @return void + */ + public function apiDeleteIssue($gitlabID, $projectID, $issueID) + { + $apiRoot = $this->getApiRoot($gitlabID); + $apiPath = "/projects/{$projectID}/issues/{$issueID}"; + $url = sprintf($apiRoot, $apiPath); + commonModel::http($url, $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE')); + } + public function pushTask($gitlabID, $projectID, $task) { $task->label = $this->config->gitlab->taskLabel->name; From 59f4f344e741e4b7ef2609317d6e3c01ce7e836e Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 28 Jun 2021 17:50:10 +0800 Subject: [PATCH 147/269] + Add the function of deleting an issue. --- module/gitlab/model.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index c715d09a89..db8c3546b1 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -671,6 +671,40 @@ class gitlabModel extends model } } + /** + * Delete ans issue. + * + * @param int $gitlabID + * @param int $projectID + * @param string $objectType + * @param int $objectID + * @access public + * @return void + */ + public function deleteIssue($gitlabID, $projectID, $objectType, $objectID) + { + $object = $this->loadModel($objectType)->getByID($objectID); + $relationID = $this->getRelationID($objectType, $objectID); + if(!empty($relationID)) $this->dao->delete(TABLE_RELATION, $relationID); + } + + /** + * Get relation id. + * + * @param string $objectType + * @param int $objectID + * @access public + * @return void + */ + public function getRelationID($objectType, $objectID) + { + return $this->dao->select('id')->from(TABLE_RELATION) + ->where('AType')->eq($objectType) + ->andWhere('AID')->eq($objectID) + ->andWhere('relation')->eq('gitlab') + ->fetch(); + } + /** * Get synced issue from relation table. * From 627ca95b07b58ab65bf0d5ef3f0b8e7c740833fe Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 28 Jun 2021 17:51:17 +0800 Subject: [PATCH 148/269] + Delete related issue in gitlab when deleting task. --- module/task/control.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/module/task/control.php b/module/task/control.php index 601c8bc479..7cbefe3cbd 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -1280,6 +1280,10 @@ class task extends control } else { + /* Delete related issue in gitlab. */ + $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('task', $taskID); + $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'task', $taskID); + $this->task->delete(TABLE_TASK, $taskID); if($task->parent > 0) { From d15cb6ed42ac7c91d892b94ddf32c086ba5e6f8b Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 28 Jun 2021 18:17:36 +0800 Subject: [PATCH 149/269] * Optimize codes. --- module/gitlab/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index db8c3546b1..f100bd43cb 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -702,7 +702,7 @@ class gitlabModel extends model ->where('AType')->eq($objectType) ->andWhere('AID')->eq($objectID) ->andWhere('relation')->eq('gitlab') - ->fetch(); + ->fetch('id'); } /** From 8189d6070935b890ea1e2b6070298bd46da82f47 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 28 Jun 2021 21:47:12 +0800 Subject: [PATCH 150/269] + Delete related issue in gitlab when deleting bug. --- module/bug/control.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/module/bug/control.php b/module/bug/control.php index 84d137d9f0..f40ca35713 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -1547,6 +1547,10 @@ class bug extends control } else { + /* Delete related issue in gitlab. */ + $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('bug', $bugID); + $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'bug', $bugID); + $this->bug->delete(TABLE_BUG, $bugID); if($bug->toTask != 0) { From bb3bce97db00e07753d52e0e54ff8127cca9660d Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 28 Jun 2021 21:47:26 +0800 Subject: [PATCH 151/269] + Delete related issue in gitlab when deleting story. --- module/story/control.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/module/story/control.php b/module/story/control.php index 869e0c053a..1a43a84db7 100644 --- a/module/story/control.php +++ b/module/story/control.php @@ -987,6 +987,10 @@ class story extends control } else { + /* Delete related issue in gitlab. */ + $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('story', $storyID); + $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'story', $storyID); + $this->story->delete(TABLE_STORY, $storyID); if($story->parent > 0) { From c064d05ab60b99f8a79dbaaa870d8dfa765309c5 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 28 Jun 2021 23:17:50 +0800 Subject: [PATCH 152/269] * Bug fix and format codes. --- module/bug/model.php | 2 +- module/gitlab/model.php | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/module/bug/model.php b/module/bug/model.php index a52f200b1e..ad75ee394e 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -90,7 +90,7 @@ class bugModel extends model $bugID = $this->dao->lastInsertID(); /* Sync this bug to gitlab issue. */ - $this->loadModel('gitlab')->pushToissue('bug', $bugID, $this->post->gitlab, $this->post->gitlabProject); + $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $this->post->gitlab, $this->post->gitlabProject); $this->file->updateObjectID($this->post->uid, $bugID, 'bug'); $this->file->saveUpload('bug', $bugID); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index f100bd43cb..568d05c41f 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -578,14 +578,16 @@ class gitlabModel extends model * Push story to gitlab issue. * * @param int $storyID - * @param int $gitlab - * @param int $gitlabProject + * @param int $gitlabID + * @param int $projectID * @access public * @return void */ public function pushStory($storyID, $gitlabID, $projectID) { $story = $this->loadModel('story')->getByID($storyID); + if(empty($bug)) return false; + if(!$gitlabID or !$projectID) { $result = $this->getGitlabIDprojectID('story', $storyID); @@ -612,7 +614,7 @@ class gitlabModel extends model /** * Sync bug to gitlab issue. * - * @param int $storyID + * @param int $bugID * @param int $gitlab * @param int $gitlabProject * @access public @@ -643,7 +645,7 @@ class gitlabModel extends model * @access public * @return void */ - public function pushToissue($objectType, $objectID, $gitlabID, $projectID) + public function pushToIssue($objectType, $objectID, $gitlabID, $projectID) { $object = $this->loadModel($objectType)->getByID($objectID); if(!$gitlabID or !$projectID) @@ -654,9 +656,9 @@ class gitlabModel extends model } $syncedIssue = $this->getSyncedIssue($objectType = $objectType, $objectID = $objectID, $gitlabID); - if($objectType == 'story') $issue = $this->storyToIssue($gitlabID, $projectID, $objectID); - if($objectType == 'task') $issue = $this->taskToIssue($gitlabID, $projectID, $objectID); - if($objectType == 'bug') $issue = $this->bugToIssue($gitlabID, $projectID, $objectID); + if($objectType == 'story') $issue = $this->storyToIssue($gitlabID, $projectID, $object); + if($objectType == 'task') $issue = $this->taskToIssue($gitlabID, $projectID, $object); + if($objectType == 'bug') $issue = $this->bugToIssue($gitlabID, $projectID, $object); if($syncedIssue) { @@ -667,7 +669,7 @@ class gitlabModel extends model $this->createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID); $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); $issue = $this->apiCreateIssue($gitlabID, $projectID, $issue); - if($issue) $this->saveSyncedIssue($objectType, $objectID, $gitlabID, $issue); + if($issue) $this->saveSyncedIssue($objectType, $object, $gitlabID, $issue); } } @@ -755,7 +757,7 @@ class gitlabModel extends model * * @param int $gitlabID * @param int $gitlabProjectID - * @param object $task + * @param object $task * @access public * @return object */ From 6dba8ad4430b5965d6fca1409c82e8b2bf78fb83 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 28 Jun 2021 23:31:48 +0800 Subject: [PATCH 153/269] + Update issue when assign bug to user. --- module/bug/model.php | 9 +++++++++ module/task/model.php | 1 - 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/module/bug/model.php b/module/bug/model.php index ad75ee394e..fe879e49e8 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -852,6 +852,15 @@ class bugModel extends model ->autoCheck() ->where('id')->eq($bugID)->exec(); + $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('bug', $bugID); + $attribute = new stdclass(); + $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $bug->assignedTo); + if($attribute->assignee_id != '') + { + // TODO(dingguodong) we should alert to operator when can not find the user, and the operator should reconfigure user binding. + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID , $attribute); + } + if(!dao::isError()) return common::createChanges($oldBug, $bug); } diff --git a/module/task/model.php b/module/task/model.php index f465c053d9..246a17f9c0 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -1327,7 +1327,6 @@ class taskModel extends model ->where('id')->eq($taskID)->exec(); $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('task', $taskID); - $attribute = new stdclass(); $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $task->assignedTo); if($attribute->assignee_id != '') From 38a0f4bbfde8a92e43596bfeebb8c143c9b231f5 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Tue, 29 Jun 2021 08:36:51 +0800 Subject: [PATCH 154/269] * Add update story to gitlab issue. --- module/gitlab/model.php | 15 +++++++++++++++ module/story/model.php | 14 +++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index f100bd43cb..7a2c9fd117 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -77,6 +77,21 @@ class gitlabModel extends model ->fetchPairs(); } + /** + * Get gitlab gitlabID and gitlabProjectID. + * + * @param int $gitlab + * @access public + * @return void + */ + public function getGitlabToGitlabProject($storyID) + { + return $this->dao->select('BID,BVersion')->from(TABLE_RELATION) + ->where('relation')->eq('gitlab') + ->andWhere('AID')->eq($storyID) + ->fetchAll(); + } + /** * Get zentao account gitlab user id pairs of one gitlab. * diff --git a/module/story/model.php b/module/story/model.php index d92b9329d3..dfb669f2e0 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -828,10 +828,10 @@ class storyModel extends model $reviewData->version = $oldStory->version; $reviewData->reviewer = $reviewer; $this->dao->insert(TABLE_STORYREVIEW)->data($reviewData)->exec(); - } - - /* Push this story to gitlab issue. */ - $this->loadModel('gitlab')->pushStory($storyID, $this->post->gitlab, $this->post->gitlabProject); + } + /* update story to gitlab issue. */ + $objectID = $this->loadModel('gitlab')->getGitlabToGitlabProject($storyID); + if($objectID) $this->loadModel('gitlab')->pushToissue('story', $storyID, $this->post->gitlab, $this->post->gitlabProject); unset($oldStory->parent); unset($story->parent); @@ -1767,11 +1767,11 @@ class storyModel extends model $story->assignedTo = $assignedTo; $story->assignedDate = $now; - $this->dao->update(TABLE_STORY)->data($story)->autoCheck()->where('id')->eq((int)$storyID)->exec(); if(!dao::isError()) { - /* Push this story to gitlab issue. */ - $this->loadModel('gitlab')->pushStory($storyID, $this->post->gitlab, $this->post->gitlabProject); + /* Update this story to gitlab issue. */ + $objectID = $this->loadModel('gitlab')->getGitlabToGitlabProject($storyID); + if($objectID) $this->loadModel('gitlab')->pushToissue('story', $storyID, $this->post->gitlab, $this->post->gitlabProject); return common::createChanges($oldStory, $story); } From 2e9351bad6bbada6257ad72d1347a257888eb773 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Tue, 29 Jun 2021 09:07:00 +0800 Subject: [PATCH 155/269] * Add fix update story. --- module/gitlab/model.php | 15 --------------- module/story/model.php | 4 ++-- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index f09d022bc6..568d05c41f 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -77,21 +77,6 @@ class gitlabModel extends model ->fetchPairs(); } - /** - * Get gitlab gitlabID and gitlabProjectID. - * - * @param int $gitlab - * @access public - * @return void - */ - public function getGitlabToGitlabProject($storyID) - { - return $this->dao->select('BID,BVersion')->from(TABLE_RELATION) - ->where('relation')->eq('gitlab') - ->andWhere('AID')->eq($storyID) - ->fetchAll(); - } - /** * Get zentao account gitlab user id pairs of one gitlab. * diff --git a/module/story/model.php b/module/story/model.php index dfb669f2e0..05486f3c2c 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -830,7 +830,7 @@ class storyModel extends model $this->dao->insert(TABLE_STORYREVIEW)->data($reviewData)->exec(); } /* update story to gitlab issue. */ - $objectID = $this->loadModel('gitlab')->getGitlabToGitlabProject($storyID); + $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('story',$storyID); if($objectID) $this->loadModel('gitlab')->pushToissue('story', $storyID, $this->post->gitlab, $this->post->gitlabProject); unset($oldStory->parent); @@ -1770,7 +1770,7 @@ class storyModel extends model if(!dao::isError()) { /* Update this story to gitlab issue. */ - $objectID = $this->loadModel('gitlab')->getGitlabToGitlabProject($storyID); + $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('story',$storyID); if($objectID) $this->loadModel('gitlab')->pushToissue('story', $storyID, $this->post->gitlab, $this->post->gitlabProject); return common::createChanges($oldStory, $story); From db68646908a5b28ad0a17751616fd13900cd91b3 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 09:31:29 +0800 Subject: [PATCH 156/269] - Remove old pushObject function. --- module/gitlab/model.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 568d05c41f..d849c5d6d4 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -911,20 +911,6 @@ class gitlabModel extends model commonModel::http($url, $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE')); } - public function pushTask($gitlabID, $projectID, $task) - { - $task->label = $this->config->gitlab->taskLabel->name; - $response = $this->apiCreateIssue($gitlabID, $projectID, $task); - return $response; - } - - public function pushBug($gitlabID, $projectID, $bug) - { - $bug->label = $this->config->gitlab->bugLabel->name; - $response = $this->apiCreateIssue($gitlabID, $projectID, $bug); - return $response; - } - /** * webhook check token. * From 3906982fdb04b25300eabce04faeb2accfd1031b Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 09:36:34 +0800 Subject: [PATCH 157/269] * Rename syncObject to pushObject. --- module/gitlab/model.php | 8 ++++---- module/task/model.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index d849c5d6d4..41b95ddf97 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -550,7 +550,7 @@ class gitlabModel extends model } /** - * Sync task to gitlab issue. + * Push task to gitlab issue. * * @param int $taskID * @param int $gitlab @@ -558,7 +558,7 @@ class gitlabModel extends model * @access public * @return void */ - public function syncTask($taskID, $gitlab, $gitlabProject) + public function pushTask($taskID, $gitlab, $gitlabProject) { $task = $this->loadModel('task')->getByID($taskID); $syncedIssue = $this->getSyncedIssue($objectType = 'task', $objectID = $taskID, $gitlab); @@ -612,7 +612,7 @@ class gitlabModel extends model } /** - * Sync bug to gitlab issue. + * Push bug to gitlab issue. * * @param int $bugID * @param int $gitlab @@ -620,7 +620,7 @@ class gitlabModel extends model * @access public * @return void */ - public function syncBug($bugID, $gitlab, $gitlabProject) + public function pushBug($bugID, $gitlab, $gitlabProject) { $bug = $this->loadModel('bug')->getByID($bugID); diff --git a/module/task/model.php b/module/task/model.php index 246a17f9c0..1b785e095b 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -122,7 +122,7 @@ class taskModel extends model $taskID = $this->dao->lastInsertID(); /* Sync this task to gitlab issue. */ - $this->loadModel('gitlab')->syncTask($taskID, $this->post->gitlab, $this->post->gitlabProject); + $this->loadModel('gitlab')->pushTask($taskID, $this->post->gitlab, $this->post->gitlabProject); /* Mark design version.*/ if(isset($task->design) && !empty($task->design)) From 38ca3cbb9e386ef22adf28752b089f0c2d8eb592 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 09:40:45 +0800 Subject: [PATCH 158/269] * Optimize codes and bug fix. --- module/gitlab/model.php | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 41b95ddf97..dd9e1824ed 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -565,13 +565,17 @@ class gitlabModel extends model $issue = $this->taskToIssue($gitlab, $gitlabProject, $task); - $this->createZentaoObjectLabel($gitlab, $gitlabProject, 'task', $taskID); - $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'task', $taskID); - - if($syncedIssue) $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); - $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); - - $this->saveSyncedIssue('task', $task, $gitlab, $issue); + if($syncedIssue) + { + $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); + } + else + { + $this->createZentaoObjectLabel($gitlab, $gitlabProject, 'task', $taskID); + $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'task', $taskID); + $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); + $this->saveSyncedIssue('task', $task, $gitlab, $issue); + } } /** @@ -627,12 +631,17 @@ class gitlabModel extends model $syncedIssue = $this->getSyncedIssue($objectType = 'bug', $objectID = $bugID, $gitlab); $issue = $this->bugToIssue($gitlab, $gitlabProject, $bug); - $this->createZentaoObjectLabel($gitlab, $gitlabProject, 'bug', $bugID); - $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'bug', $bugID); - - if($syncedIssue) $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); - $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); - if($issue) $this->saveSyncedIssue('bug', $bug, $gitlab, $issue); + if($syncedIssue) + { + $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); + } + else + { + $this->createZentaoObjectLabel($gitlab, $gitlabProject, 'bug', $bugID); + $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'bug', $bugID); + $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); + if($issue) $this->saveSyncedIssue('bug', $bug, $gitlab, $issue); + } } /** From 9d7b8901fce9369728ada8977d2dced1ae06e967 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Tue, 29 Jun 2021 10:00:04 +0800 Subject: [PATCH 159/269] * Fix gitlab issue state. --- module/gitlab/config.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index daeb53eac6..ce4f5d7d79 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -37,6 +37,7 @@ $config->gitlab->maps->task['lastEditedDate'] = 'updated_at|field|'; $config->gitlab->maps->task['deadline'] = 'due_date|field|'; $config->gitlab->maps->task['status'] = 'state|configItems|taskStateMap'; $config->gitlab->maps->task['pri'] = 'weight|configItems|taskWeightMap'; +$config->gitlab->maps->task['lastEditedBy'] = 'updated_by_id|userPairs|'; $config->gitlab->maps->story = array(); $config->gitlab->maps->story['title'] = 'title|field|'; @@ -58,11 +59,11 @@ $config->gitlab->taskWeightMap['2'] = '2'; $config->gitlab->taskWeightMap['3'] = '3'; $config->gitlab->taskStateMap = array(); -$config->gitlab->taskStateMap['doing'] = 'reopen'; -$config->gitlab->taskStateMap['wait'] = 'reopen'; +$config->gitlab->taskStateMap['doing'] = 'opened'; +$config->gitlab->taskStateMap['wait'] = 'opened'; +$config->gitlab->taskStateMap['closed'] = 'close'; $config->gitlab->taskStateMap['done'] = 'close'; $config->gitlab->taskStateMap['cancel'] = 'close'; -$config->gitlab->taskStateMap['closed'] = 'close'; $config->gitlab->taskTypesToSync = 'design,devel,request,discuss,ui,affair,misc'; From 9459443016108bec7e7fd8b4288b6be9827e02f5 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 10:00:45 +0800 Subject: [PATCH 160/269] * Preparing for merge them to pushObject. --- module/gitlab/model.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index dd9e1824ed..8cf41777ce 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -561,6 +561,14 @@ class gitlabModel extends model public function pushTask($taskID, $gitlab, $gitlabProject) { $task = $this->loadModel('task')->getByID($taskID); + + if(!$gitlabID or !$projectID) + { + $result = $this->getGitlabIDprojectID('task', $taskID); + $gitlabID = $result->gitlabID; + $projectID = $result->projectID; + } + $syncedIssue = $this->getSyncedIssue($objectType = 'task', $objectID = $taskID, $gitlab); $issue = $this->taskToIssue($gitlab, $gitlabProject, $task); @@ -628,6 +636,13 @@ class gitlabModel extends model { $bug = $this->loadModel('bug')->getByID($bugID); + if(!$gitlabID or !$projectID) + { + $result = $this->getGitlabIDprojectID('bug', $bugID); + $gitlabID = $result->gitlabID; + $projectID = $result->projectID; + } + $syncedIssue = $this->getSyncedIssue($objectType = 'bug', $objectID = $bugID, $gitlab); $issue = $this->bugToIssue($gitlab, $gitlabProject, $bug); From cb733a018660e584f9b0b6b468ee8f1023290d7c Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Tue, 29 Jun 2021 10:01:34 +0800 Subject: [PATCH 161/269] * Add webhookIssueAssign function. --- module/gitlab/model.php | 53 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 1ec21a890b..1aa7c492e8 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -853,12 +853,12 @@ class gitlabModel extends model $issue->issue->objectType = $object->type; $issue->issue->objectID = $object->id; - + /* Parse markdown description to html. */ $issue->issue->description = $this->app->loadClass('hyperdown')->makeHtml($issue->issue->description); if(!isset($this->config->gitlab->maps->{$object->type})) return false; - $issue->object = $this->issueToZentaoObject($issue->issue, $gitlabID); + $issue->object = $this->issueToZentaoObject($issue->issue, $gitlabID, $body->changes); return $issue; } @@ -905,7 +905,6 @@ class gitlabModel extends model { $tableName = zget($this->config->gitlab->objectTables, $issue->objectType, ''); if($tableName) $this->dao->update($tableName)->data($issue->object)->where('id')->eq($issue->objectID)->exec(); - a($this->dao->get());exit; return !dao::isError(); } @@ -933,6 +932,51 @@ class gitlabModel extends model return $object; } + /** + * Process webhook issue assign option. + * + * @param int $gitlabID + * @param object $issue + * @access public + * @return void + */ + public function webhookIssueAssign($gitlabID, $issue) + { + $gitlabUsers = $this->getUserIdAccountPairs($gitlabID); + if($issue->objectType == 'task') + { + $oldTask = $this->loadModel('task')->getByID($issue->objectID); + $_POST['left'] = $oldTask->left; + $_POST['lastEditedBy'] = $issue->object->lastEditedBy; + $_POST['lastEditedDate'] = $issue->object->lastEditedDate; + $_POST['assignedDate'] = $issue->object->lastEditedDate; + $_POST['assignedBy'] = $issue->object->lastEditedBy; + $this->task->assign($issue->objectID); + } + + if($issue->objectType == 'bug') + { + $oldBug = $this->loadModel('bug')->getByID($issue->objectID); + $_POST['lastEditedBy'] = $issue->object->lastEditedBy; + $_POST['lastEditedDate'] = $issue->object->lastEditedDate; + $_POST['assignedDate'] = $issue->object->lastEditedDate; + $_POST['assignedBy'] = $issue->object->lastEditedBy; + $this->bug->assign($issue->objectID); + } + + if($issue->objectType == 'story') + { + $oldBug = $this->loadModel('story')->getByID($issue->objectID); + $_POST['lastEditedBy'] = $issue->object->lastEditedBy; + $_POST['lastEditedDate'] = $issue->object->lastEditedDate; + $_POST['assignedDate'] = $issue->object->lastEditedDate; + $_POST['assignedBy'] = $issue->object->lastEditedBy; + $this->story->assign($issue->objectID); + } + + + } + /** * Parse issue to zentao object. * @@ -941,7 +985,7 @@ class gitlabModel extends model * @access public * @return object */ - public function issueToZentaoObject($issue, $gitlabID) + public function issueToZentaoObject($issue, $gitlabID, $changes = null) { if(!isset($this->config->gitlab->maps->{$issue->objectType})) return null; @@ -954,6 +998,7 @@ class gitlabModel extends model { $value = ''; list($gitlabField, $optionType, $options) = explode('|', $config); + if(!isset($changes->gitlabField)) continue; if($optionType == 'field') $value = $issue->$gitlabField; if($optionType == 'field') $value = $issue->$gitlabField; if($optionType == 'userPairs') $value = zget($gitlabUsers, $issue->$gitlabField); From 1bad02c282be6ed7d06327f561697ddba9bf7003 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 10:13:26 +0800 Subject: [PATCH 162/269] * Correct issue state. --- module/gitlab/config.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 5b21c8d084..4f3117f015 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -52,6 +52,7 @@ $config->gitlab->maps->bug['title'] = 'title|field|'; $config->gitlab->maps->bug['steps'] = 'description|field|'; $config->gitlab->maps->bug['openedDate'] = 'created_at|field|'; $config->gitlab->maps->bug['assignedTo'] = 'assignee_id|userPairs|'; +$config->gitlab->maps->bug['status'] = 'state|configItems|bugStateMap'; $config->gitlab->maps->bug['pri'] = 'weight|configItems|bugWeightMap'; $config->gitlab->taskWeightMap = array(); @@ -62,9 +63,9 @@ $config->gitlab->taskWeightMap['3'] = '3'; $config->gitlab->taskStateMap = array(); $config->gitlab->taskStateMap['doing'] = 'opened'; $config->gitlab->taskStateMap['wait'] = 'opened'; -$config->gitlab->taskStateMap['closed'] = 'close'; -$config->gitlab->taskStateMap['done'] = 'close'; -$config->gitlab->taskStateMap['cancel'] = 'close'; +$config->gitlab->taskStateMap['closed'] = 'closed'; +$config->gitlab->taskStateMap['done'] = 'closed'; +$config->gitlab->taskStateMap['cancel'] = 'closed'; $config->gitlab->taskTypesToSync = 'design,devel,request,discuss,ui,affair,misc'; @@ -80,9 +81,9 @@ $config->gitlab->bugWeightMap['3'] = '3'; $config->gitlab->bugWeightMap['4'] = '4'; $config->gitlab->bugStateMap = array(); -$config->gitlab->bugStateMap['active'] = 'reopen'; -$config->gitlab->bugStateMap['resolved'] = 'reopen'; -$config->gitlab->bugStateMap['closed'] = 'close'; +$config->gitlab->bugStateMap['active'] = 'opened'; +$config->gitlab->bugStateMap['resolved'] = 'closed'; +$config->gitlab->bugStateMap['closed'] = 'closed'; $config->gitlab->objectTables = new stdclass; $config->gitlab->objectTables->story = TABLE_STORY; From df508bdfec086f9a767c49c5b8736ed1e98ba610 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Tue, 29 Jun 2021 10:43:30 +0800 Subject: [PATCH 163/269] * Add bug,story,task push to issues function. --- module/bug/model.php | 3 +++ module/story/model.php | 9 ++++++--- module/task/model.php | 10 ++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/module/bug/model.php b/module/bug/model.php index fe879e49e8..aef3b6b84a 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -1219,6 +1219,9 @@ class bugModel extends model $this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec(); + $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('bug',$bugID); + if($objectID) $this->loadModel('bug')->pushToissue('bug', $bugID, $objectID->gitlabID, $objectID->projectID); + return common::createChanges($oldBug, $bug); } diff --git a/module/story/model.php b/module/story/model.php index 05486f3c2c..1656103c23 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -831,7 +831,7 @@ class storyModel extends model } /* update story to gitlab issue. */ $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('story',$storyID); - if($objectID) $this->loadModel('gitlab')->pushToissue('story', $storyID, $this->post->gitlab, $this->post->gitlabProject); + if($objectID) $this->loadModel('gitlab')->pushToissue('story', $storyID, $objectID->gitlabID, $objectID->projectID); unset($oldStory->parent); unset($story->parent); @@ -1426,6 +1426,9 @@ class storyModel extends model ->checkIF($story->closedReason == 'duplicate', 'duplicateStory', 'notempty') ->where('id')->eq($storyID)->exec(); + $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('story',$storyID); + if($objectID) $this->loadModel('gitlab')->pushToissue('story', $storyID, $objectID->gitlabID, $objectID->projectID); + /* Update parent story status. */ if($oldStory->parent > 0) $this->updateParentStatus($storyID, $oldStory->parent); $this->setStage($storyID); @@ -1769,9 +1772,9 @@ class storyModel extends model if(!dao::isError()) { - /* Update this story to gitlab issue. */ + /* Update story to gitlab issue. */ $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('story',$storyID); - if($objectID) $this->loadModel('gitlab')->pushToissue('story', $storyID, $this->post->gitlab, $this->post->gitlabProject); + if($objectID) $this->loadModel('gitlab')->pushToissue('story', $storyID, $objectID->gitlabID, $objectID->projectID); return common::createChanges($oldStory, $story); } diff --git a/module/task/model.php b/module/task/model.php index 246a17f9c0..153047c1e0 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -1670,6 +1670,9 @@ class taskModel extends model ->where('id')->eq((int)$taskID) ->exec(); + $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('task',$taskID); + if($objectID) $this->loadModel('gitlab')->pushToissue('task', $taskID, $objectID->gitlabID, $objectID->projectID); + if($oldTask->parent > 0) $this->updateParentStatus($taskID); if($oldTask->story) $this->loadModel('story')->setStage($oldTask->story); if($task->status == 'done' && !dao::isError()) $this->loadModel('score')->create('task', 'finish', $taskID); @@ -1726,6 +1729,9 @@ class taskModel extends model $this->dao->update(TABLE_TASK)->data($task)->autoCheck()->where('id')->eq((int)$taskID)->exec(); + $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('task',$taskID); + if($objectID) $this->loadModel('gitlab')->pushToissue('task', $taskID, $objectID->gitlabID, $objectID->projectID); + if(!dao::isError()) { if($oldTask->parent > 0) $this->updateParentStatus($taskID); @@ -1769,6 +1775,10 @@ class taskModel extends model $this->dao->update(TABLE_TASK)->set('assignedTo=openedBy')->where('parent')->eq((int)$taskID)->exec(); } if($oldTask->story) $this->loadModel('story')->setStage($oldTask->story); + + $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('task',$taskID); + if($objectID) $this->loadModel('gitlab')->pushToissue('task', $taskID, $objectID->gitlabID, $objectID->projectID); + if(!dao::isError()) return common::createChanges($oldTask, $task); } From 54505413910b4de7234a4b4e52926e68983e8ecb Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Tue, 29 Jun 2021 10:56:17 +0800 Subject: [PATCH 164/269] * Add datetime and date option. --- module/gitlab/config.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 5b21c8d084..987a381bd2 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -31,10 +31,10 @@ $config->gitlab->maps = new stdclass; $config->gitlab->maps->task = array(); $config->gitlab->maps->task['name'] = 'title|field|'; $config->gitlab->maps->task['desc'] = 'description|field|'; -$config->gitlab->maps->task['openedDate'] = 'created_at|field|'; +$config->gitlab->maps->task['openedDate'] = 'created_at|field|datetime'; $config->gitlab->maps->task['assignedTo'] = 'assignee_id|userPairs|'; -$config->gitlab->maps->task['lastEditedDate'] = 'updated_at|field|'; -$config->gitlab->maps->task['deadline'] = 'due_date|field|'; +$config->gitlab->maps->task['lastEditedDate'] = 'updated_at|field|datetime'; +$config->gitlab->maps->task['deadline'] = 'due_date|field|date'; $config->gitlab->maps->task['status'] = 'state|configItems|taskStateMap'; $config->gitlab->maps->task['pri'] = 'weight|configItems|taskWeightMap'; $config->gitlab->maps->task['lastEditedBy'] = 'updated_by_id|userPairs|'; @@ -42,15 +42,16 @@ $config->gitlab->maps->task['lastEditedBy'] = 'updated_by_id|userPairs|'; $config->gitlab->maps->story = array(); $config->gitlab->maps->story['title'] = 'title|field|'; $config->gitlab->maps->story['spec'] = 'description|fields|verify'; -$config->gitlab->maps->story['openedDate'] = 'created_at|field|'; +$config->gitlab->maps->story['openedDate'] = 'created_at|field|datetime'; $config->gitlab->maps->story['openedBy'] = 'assignee_id|userPairs|'; $config->gitlab->maps->story['assignedTo'] = 'assignee_id|userPairs|'; +$config->gitlab->maps->story['status'] = 'state|configItems|storyStateMap'; $config->gitlab->maps->story['pri'] = 'weight|configItems|storyWeightMap'; $config->gitlab->maps->bug = array(); $config->gitlab->maps->bug['title'] = 'title|field|'; $config->gitlab->maps->bug['steps'] = 'description|field|'; -$config->gitlab->maps->bug['openedDate'] = 'created_at|field|'; +$config->gitlab->maps->bug['openedDate'] = 'created_at|field|datetime'; $config->gitlab->maps->bug['assignedTo'] = 'assignee_id|userPairs|'; $config->gitlab->maps->bug['pri'] = 'weight|configItems|bugWeightMap'; From e3a5814eecdf80ce2110f1600b665a13bf62c076 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Tue, 29 Jun 2021 10:58:17 +0800 Subject: [PATCH 165/269] * Fix date and datetime field. --- module/gitlab/model.php | 47 +++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 9972ffe503..85b13c0739 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -1057,39 +1057,24 @@ class gitlabModel extends model */ public function webhookIssueAssign($gitlabID, $issue) { + $tableName = zget($this->config->gitlab->objectTables, $issue->objectType, ''); + if(!$tableName) return false; + $gitlabUsers = $this->getUserIdAccountPairs($gitlabID); - if($issue->objectType == 'task') - { - $oldTask = $this->loadModel('task')->getByID($issue->objectID); - $_POST['left'] = $oldTask->left; - $_POST['lastEditedBy'] = $issue->object->lastEditedBy; - $_POST['lastEditedDate'] = $issue->object->lastEditedDate; - $_POST['assignedDate'] = $issue->object->lastEditedDate; - $_POST['assignedBy'] = $issue->object->lastEditedBy; - $this->task->assign($issue->objectID); - } - if($issue->objectType == 'bug') - { - $oldBug = $this->loadModel('bug')->getByID($issue->objectID); - $_POST['lastEditedBy'] = $issue->object->lastEditedBy; - $_POST['lastEditedDate'] = $issue->object->lastEditedDate; - $_POST['assignedDate'] = $issue->object->lastEditedDate; - $_POST['assignedBy'] = $issue->object->lastEditedBy; - $this->bug->assign($issue->objectID); - } - - if($issue->objectType == 'story') - { - $oldBug = $this->loadModel('story')->getByID($issue->objectID); - $_POST['lastEditedBy'] = $issue->object->lastEditedBy; - $_POST['lastEditedDate'] = $issue->object->lastEditedDate; - $_POST['assignedDate'] = $issue->object->lastEditedDate; - $_POST['assignedBy'] = $issue->object->lastEditedBy; - $this->story->assign($issue->objectID); - } + $data = $issue->object; + $data->assignedDate = $issue->object->lastEditedDate; + $data->assignedBy = $issue->object->lastEditedBy; + $data->assignedTo = $issue->object->assignedTo; + $this->dao->update($tableName)->data($data)->where('id')->eq($issue->objectID)->exec(); + if(dao::isError()) return false; + $oldObject = $this->dao->findById($issue->objectID)->from($tableName)->fetch(); + $changes = common::createChanges($oldObject, $data); + $actionID = $this->action->create($issue->objectType, $issue->objectID, 'Assigned', '', $data->assignedTo); + $this->action->logHistory($actionID, $changes); + return true; } /** @@ -1113,9 +1098,11 @@ class gitlabModel extends model { $value = ''; list($gitlabField, $optionType, $options) = explode('|', $config); - if(!isset($changes->gitlabField)) continue; + if(!isset($changes->$gitlabField)) continue; if($optionType == 'field') $value = $issue->$gitlabField; if($optionType == 'field') $value = $issue->$gitlabField; + if($options == 'date') $value = date('Y-m-d', $value); + if($options == 'datetime') $value = date('Y-m-d H:i:s', $value); if($optionType == 'userPairs') $value = zget($gitlabUsers, $issue->$gitlabField); if($optionType == 'configItems' and isset($issue->$gitlabField)) $value = array_search($issue->$gitlabField, $this->config->gitlab->$options); if($value) $object->$zentaoField = $value; From af02efc949357c1ebb2247b7a0ce6299a59f6a42 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Tue, 29 Jun 2021 10:59:42 +0800 Subject: [PATCH 166/269] * Add strtotime. --- module/gitlab/model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 6316c6a63d..e709b7db79 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -1116,8 +1116,8 @@ class gitlabModel extends model if(!isset($changes->$gitlabField)) continue; if($optionType == 'field') $value = $issue->$gitlabField; if($optionType == 'field') $value = $issue->$gitlabField; - if($options == 'date') $value = date('Y-m-d', $value); - if($options == 'datetime') $value = date('Y-m-d H:i:s', $value); + if($options == 'date') $value = date('Y-m-d', strtotime($value)); + if($options == 'datetime') $value = date('Y-m-d H:i:s', strtotime($value)); if($optionType == 'userPairs') $value = zget($gitlabUsers, $issue->$gitlabField); if($optionType == 'configItems' and isset($issue->$gitlabField)) $value = array_search($issue->$gitlabField, $this->config->gitlab->$options); if($value) $object->$zentaoField = $value; From ad05859fadce946c83958a98674653046a802137 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 11:05:48 +0800 Subject: [PATCH 167/269] * Update bugToIssue and meet the gitlab API. --- module/gitlab/model.php | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 1c91b29c8a..020009290a 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -570,12 +570,11 @@ class gitlabModel extends model } $syncedIssue = $this->getSyncedIssue($objectType = 'task', $objectID = $taskID, $gitlab); - $issue = $this->taskToIssue($gitlab, $gitlabProject, $task); if($syncedIssue) { - $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); + $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue->BID, $issue); } else { @@ -612,7 +611,7 @@ class gitlabModel extends model if($syncedIssue) { - $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->AID, $issue); + $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->BID, $issue); } else { @@ -627,12 +626,12 @@ class gitlabModel extends model * Push bug to gitlab issue. * * @param int $bugID - * @param int $gitlab - * @param int $gitlabProject + * @param int $gitlabID + * @param int $projectID * @access public * @return void */ - public function pushBug($bugID, $gitlab, $gitlabProject) + public function pushBug($bugID, $gitlabID, $projectID) { $bug = $this->loadModel('bug')->getByID($bugID); @@ -643,19 +642,19 @@ class gitlabModel extends model $projectID = $result->projectID; } - $syncedIssue = $this->getSyncedIssue($objectType = 'bug', $objectID = $bugID, $gitlab); - $issue = $this->bugToIssue($gitlab, $gitlabProject, $bug); - + $syncedIssue = $this->getSyncedIssue($objectType = 'bug', $objectID = $bugID, $gitlabID); + $issue = $this->bugToIssue($gitlabID, $projectID, $bug); + if($syncedIssue) { - $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); + $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->BID, $issue); } else { - $this->createZentaoObjectLabel($gitlab, $gitlabProject, 'bug', $bugID); + $this->createZentaoObjectLabel($gitlabID, $projectID, 'bug', $bugID); $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'bug', $bugID); - $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); - if($issue) $this->saveSyncedIssue('bug', $bug, $gitlab, $issue); + $issue = $this->apiCreateIssue($gitlabID, $projectID, $issue); + if($issue) $this->saveSyncedIssue('bug', $bug, $gitlabID, $issue); } } @@ -664,7 +663,7 @@ class gitlabModel extends model * * @param string $objectType * @param int $objectID - * @param int $gitlab + * @param int $gitlabID * @param int $projectID * @access public * @return void @@ -686,7 +685,7 @@ class gitlabModel extends model if($syncedIssue) { - $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue, $issue); + $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->BID, $issue); } else { @@ -845,12 +844,12 @@ class gitlabModel extends model * Parse bug to issue. * * @param int $gitlabID - * @param int $gitlabProjectID + * @param int $projectID * @param object $story * @access public * @return object */ - public function bugToIssue($gitlabID, $gitlabProjectID, $bug) + public function bugToIssue($gitlabID, $projectID, $bug) { $map = $this->config->gitlab->maps->bug; $issue = new stdclass; @@ -874,6 +873,9 @@ class gitlabModel extends model if($value) $issue->$field = $value; } + /* issue->state is null when creating it, we should put status_event when updating it. */ + if(isset($issue->state)) $issue->status_event=$issue->state; + return $issue; } From bf9d28ef7f0f9317542dc8e81024c5e482d55d1d Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 11:13:29 +0800 Subject: [PATCH 168/269] + Update issue status when close bug. --- module/bug/control.php | 2 ++ module/gitlab/model.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/module/bug/control.php b/module/bug/control.php index f40ca35713..13714a464b 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -1247,6 +1247,8 @@ class bug extends control $this->executeHooks($bugID); + $this->loadModel('gitlab')->pushBug($bugID, $this->post->gitlab, $this->post->gitlabProject); + if($bug->toTask != 0) { /* If task is not finished, update it's status. */ diff --git a/module/gitlab/model.php b/module/gitlab/model.php index f12dd1ab3f..1fbbaa4647 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -874,7 +874,7 @@ class gitlabModel extends model } /* issue->state is null when creating it, we should put status_event when updating it. */ - if(isset($issue->state)) $issue->status_event=$issue->state; + if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; return $issue; } From d31184ccd3e5d83a6b5444bf2a3784cb95329bcb Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 13:32:01 +0800 Subject: [PATCH 169/269] + Add func to get gitlab and project by productID. --- module/gitlab/model.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 1fbbaa4647..802b544688 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -478,6 +478,16 @@ class gitlabModel extends model ->fetchGroup('AID'); } + public function getProjectsByProduct($productID) + { + return $this->dao->select('AID, BID as gitlabProject')->from(TABLE_RELATION) + ->where('relation')->eq('interrated') + ->andWhere('AType')->eq('gitlab') + ->andWhere('BType')->eq('gitlabProject') + ->andWhere('product')->eq($productID) + ->fetchGroup('AID'); + } + /** * Get gitlabID and projectID. * From b3a5fff35ece8ed37a421da01d97e0c19c081ea9 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 13:32:39 +0800 Subject: [PATCH 170/269] * Push bug when creating bug using productID. --- module/bug/control.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/module/bug/control.php b/module/bug/control.php index 13714a464b..f9ed3666a1 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -559,7 +559,9 @@ class bug extends control /* Set gitlabProjects. */ $allGitlabs = $this->loadModel('gitlab')->getPairs(); - $gitlabProjects = $this->loadModel('gitlab')->getProjectsByExecution($executionID); + if(!empty($executionID)) $gitlabProjects = $this->loadModel('gitlab')->getProjectsByExecution($executionID); + elseif(!empty($productID)) $gitlabProjects = $this->loadModel('gitlab')->getProjectsByProduct($productID); + foreach($allGitlabs as $id => $name) if($id and !isset($gitlabProjects[$id])) unset($allGitlabs[$id]); $this->view->gitlabList = $allGitlabs; $this->view->gitlabProjects = $gitlabProjects; From af524d455b6aa61129b56067c090f36846985974 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 13:43:08 +0800 Subject: [PATCH 171/269] * Resolve hidden error. --- module/bug/model.php | 1 + 1 file changed, 1 insertion(+) diff --git a/module/bug/model.php b/module/bug/model.php index aef3b6b84a..153b944028 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -1185,6 +1185,7 @@ class bugModel extends model foreach($openedBuilds as $openedBuild) { $build = $this->build->getByID($openedBuild); + if(empty($build)) continue; $build->bugs = trim(str_replace(",$bugID,", ',', ",$build->bugs,"), ','); $this->dao->update(TABLE_BUILD)->set('bugs')->eq($build->bugs)->where('id')->eq((int)$openedBuild)->exec(); } From 7f42605c3118d06b6cf1ca3652af7ebd7fbef297 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 13:58:53 +0800 Subject: [PATCH 172/269] * Reactivate issue when reopen the bug. --- module/gitlab/model.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 802b544688..5b4835db21 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -707,7 +707,7 @@ class gitlabModel extends model } /** - * Delete ans issue. + * Delete an issue. * * @param int $gitlabID * @param int $projectID @@ -885,6 +885,7 @@ class gitlabModel extends model /* issue->state is null when creating it, we should put status_event when updating it. */ if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; + if(isset($issue->state) and $issue->state == 'opened') $issue->state_event='reopen'; return $issue; } From 16c4e340e8bc4ee94318582b5d88e02d38ab9bbd Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 14:00:05 +0800 Subject: [PATCH 173/269] * Resolve whoes the bug. --- module/bug/model.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/module/bug/model.php b/module/bug/model.php index 153b944028..f93105c564 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -1178,6 +1178,9 @@ class bugModel extends model $this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec(); $this->dao->update(TABLE_BUG)->set('activatedCount = activatedCount + 1')->where('id')->eq((int)$bugID)->exec(); + $relation = $this->loadModel('gitlab')->getGitlabIDprojectID('bug',$bugID); + if($relation) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $relation->gitlabID, $relation->projectID); + $openedBuilds = $this->post->openedBuild; if($openedBuilds) { @@ -1221,7 +1224,7 @@ class bugModel extends model $this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec(); $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('bug',$bugID); - if($objectID) $this->loadModel('bug')->pushToissue('bug', $bugID, $objectID->gitlabID, $objectID->projectID); + if($objectID) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $objectID->gitlabID, $objectID->projectID); return common::createChanges($oldBug, $bug); } From d863acfdd918057c0349985661a5980f83107062 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 14:10:36 +0800 Subject: [PATCH 174/269] * Update issue when updating the bug. --- module/bug/model.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/module/bug/model.php b/module/bug/model.php index f93105c564..9f44bebf2a 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -646,6 +646,10 @@ class bugModel extends model if(!empty($bug->resolvedBy)) $this->loadModel('score')->create('bug', 'resolve', $bugID); $this->file->updateObjectID($this->post->uid, $bugID, 'bug'); + + $relation = $this->loadModel('gitlab')->getGitlabIDprojectID('bug',$bugID); + if($relation) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $relation->gitlabID, $relation->projectID); + return common::createChanges($oldBug, $bug); } } From 391b57776630a313686566a924c4f92a562b7dfb Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 14:29:35 +0800 Subject: [PATCH 175/269] * Optimize codes for deleting issue when deleting object. --- module/bug/control.php | 2 +- module/gitlab/model.php | 4 +++- module/story/control.php | 2 +- module/task/control.php | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/module/bug/control.php b/module/bug/control.php index f9ed3666a1..fc59536a2f 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -1553,7 +1553,7 @@ class bug extends control { /* Delete related issue in gitlab. */ $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('bug', $bugID); - $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'bug', $bugID); + $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'bug', $bugID, $relation->issueID); $this->bug->delete(TABLE_BUG, $bugID); if($bug->toTask != 0) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 5b4835db21..b4fed35049 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -713,14 +713,16 @@ class gitlabModel extends model * @param int $projectID * @param string $objectType * @param int $objectID + * @param int $issueID * @access public * @return void */ - public function deleteIssue($gitlabID, $projectID, $objectType, $objectID) + public function deleteIssue($gitlabID, $projectID, $objectType, $objectID, $issueID) { $object = $this->loadModel($objectType)->getByID($objectID); $relationID = $this->getRelationID($objectType, $objectID); if(!empty($relationID)) $this->dao->delete(TABLE_RELATION, $relationID); + $this->apiDeleteIssue($gitlabID, $projectID, $issueID); } /** diff --git a/module/story/control.php b/module/story/control.php index 1a43a84db7..e0bad0cb9e 100644 --- a/module/story/control.php +++ b/module/story/control.php @@ -989,7 +989,7 @@ class story extends control { /* Delete related issue in gitlab. */ $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('story', $storyID); - $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'story', $storyID); + $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'story', $storyID, $relation->issueID); $this->story->delete(TABLE_STORY, $storyID); if($story->parent > 0) diff --git a/module/task/control.php b/module/task/control.php index 7cbefe3cbd..869db13dc4 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -1282,7 +1282,7 @@ class task extends control { /* Delete related issue in gitlab. */ $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('task', $taskID); - $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'task', $taskID); + $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'task', $taskID, $relation->issueID); $this->task->delete(TABLE_TASK, $taskID); if($task->parent > 0) From 5f68564d28c280bcd286f1788de4e9b89ac3f854 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 14:52:37 +0800 Subject: [PATCH 176/269] * Optimize codes for deleting issue when deleting object. --- module/bug/control.php | 2 +- module/gitlab/model.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/module/bug/control.php b/module/bug/control.php index fc59536a2f..9b92147752 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -1553,7 +1553,7 @@ class bug extends control { /* Delete related issue in gitlab. */ $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('bug', $bugID); - $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'bug', $bugID, $relation->issueID); + if(!empty($relation)) $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'bug', $bugID, $relation->issueID); $this->bug->delete(TABLE_BUG, $bugID); if($bug->toTask != 0) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index b4fed35049..315b65c466 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -721,7 +721,7 @@ class gitlabModel extends model { $object = $this->loadModel($objectType)->getByID($objectID); $relationID = $this->getRelationID($objectType, $objectID); - if(!empty($relationID)) $this->dao->delete(TABLE_RELATION, $relationID); + if(!empty($relationID)) $this->dao->delete()->from(TABLE_RELATION)->where('id')->eq($relationID)->exec(); $this->apiDeleteIssue($gitlabID, $projectID, $issueID); } From 925a7417eaebf3048080f451e7875613d5edc174 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Tue, 29 Jun 2021 14:52:49 +0800 Subject: [PATCH 177/269] * fix code. --- module/gitlab/model.php | 1 - module/story/model.php | 4 ++-- module/task/model.php | 6 +++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 1fbbaa4647..af1f28317d 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -682,7 +682,6 @@ class gitlabModel extends model if($objectType == 'story') $issue = $this->storyToIssue($gitlabID, $projectID, $object); if($objectType == 'task') $issue = $this->taskToIssue($gitlabID, $projectID, $object); if($objectType == 'bug') $issue = $this->bugToIssue($gitlabID, $projectID, $object); - if($syncedIssue) { $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->BID, $issue); diff --git a/module/story/model.php b/module/story/model.php index 1656103c23..24e9c9b44b 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -830,8 +830,8 @@ class storyModel extends model $this->dao->insert(TABLE_STORYREVIEW)->data($reviewData)->exec(); } /* update story to gitlab issue. */ - $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('story',$storyID); - if($objectID) $this->loadModel('gitlab')->pushToissue('story', $storyID, $objectID->gitlabID, $objectID->projectID); + $objectID = $this->loadModel('gitlab')->getGitlabidProjectID('story',$storyID); + if($objectID) $this->loadModel('gitlab')->pushToIssue('story', $storyID, $objectID->gitlabID, $objectID->projectID); unset($oldStory->parent); unset($story->parent); diff --git a/module/task/model.php b/module/task/model.php index 300d3e3c68..029a9e17b4 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -122,7 +122,7 @@ class taskModel extends model $taskID = $this->dao->lastInsertID(); /* Sync this task to gitlab issue. */ - $this->loadModel('gitlab')->pushTask($taskID, $this->post->gitlab, $this->post->gitlabProject); + $this->loadModel('gitlab')->pushToIssue('task', $taskID, $this->post->gitlab, $this->post->gitlabProject); /* Mark design version.*/ if(isset($task->design) && !empty($task->design)) @@ -941,6 +941,10 @@ class taskModel extends model ->batchCheckIF($task->closedReason == 'cancel', 'finishedBy, finishedDate', 'empty') ->where('id')->eq((int)$taskID)->exec(); + /* update story to gitlab issue. */ + $objectID = $this->loadModel('gitlab')->getGitlabidProjectID('task',$taskID); + if($objectID) $this->loadModel('gitlab')->pushToIssue('task', $taskID, $objectID->gitlabID, $objectID->projectID); + if(!dao::isError()) { /* Mark design version.*/ From e2eabb87712cc8de18665754d2272697eee5b263 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Tue, 29 Jun 2021 15:32:07 +0800 Subject: [PATCH 178/269] * Finish sync assign option. --- module/gitlab/model.php | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index e709b7db79..5755ae8601 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -980,6 +980,7 @@ class gitlabModel extends model $issue->issue = $body->object_attributes; $issue->objectType = $object->type; $issue->objectID = $object->id; + $issue->changes = $body->changes; $issue->issue->objectType = $object->type; $issue->issue->objectID = $object->id; @@ -1070,16 +1071,13 @@ class gitlabModel extends model * @access public * @return void */ - public function webhookIssueAssign($gitlabID, $issue) + public function webhookAssignIssue($issue) { $tableName = zget($this->config->gitlab->objectTables, $issue->objectType, ''); if(!$tableName) return false; - $gitlabUsers = $this->getUserIdAccountPairs($gitlabID); - $data = $issue->object; $data->assignedDate = $issue->object->lastEditedDate; - $data->assignedBy = $issue->object->lastEditedBy; $data->assignedTo = $issue->object->assignedTo; $this->dao->update($tableName)->data($data)->where('id')->eq($issue->objectID)->exec(); @@ -1087,7 +1085,36 @@ class gitlabModel extends model $oldObject = $this->dao->findById($issue->objectID)->from($tableName)->fetch(); $changes = common::createChanges($oldObject, $data); - $actionID = $this->action->create($issue->objectType, $issue->objectID, 'Assigned', '', $data->assignedTo); + $actionID = $this->loadModel('action')->create($issue->objectType, $issue->objectID, 'Assigned', "Assigned by webhook by gitlab issue : {$issue->issue->url}", $data->assignedTo); + $this->action->logHistory($actionID, $changes); + return true; + } + + /** + * Process issue close option. + * + * @param int $gitlabID + * @param object $issue + * @access public + * @return void + */ + public function webhookCloseIssue($issue) + { + $tableName = zget($this->config->gitlab->objectTables, $issue->objectType, ''); + if(!$tableName) return false; + + $data = $issue->object; + $data->assignedTo = 'closed'; + $data->status = 'closed'; + $data->closedBy = $issue->object->lastEditedBy; + $data->closedDate = $issue->object->lastEditedDate; + + $this->dao->update($tableName)->data($data)->where('id')->eq($issue->objectID)->exec(); + if(dao::isError()) return false; + + $oldObject = $this->dao->findById($issue->objectID)->from($tableName)->fetch(); + $changes = common::createChanges($oldObject, $data); + $actionID = $this->loadModel('action')->create($issue->objectType, $issue->objectID, 'Closed', "Closed by gitlab issue: {$issue->issue->url}."); $this->action->logHistory($actionID, $changes); return true; } @@ -1104,6 +1131,7 @@ class gitlabModel extends model { if(!isset($this->config->gitlab->maps->{$issue->objectType})) return null; + if(isset($changes->assignees)) $changes->assignee_id = true; $maps = $this->config->gitlab->maps->{$issue->objectType}; $gitlabUsers = $this->getUserIdAccountPairs($gitlabID); From 3b69fe594d5bd2ab1230519cd5ad26c83de4e2fe Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 15:39:34 +0800 Subject: [PATCH 179/269] * Bug fixed for curl DELETE. --- module/gitlab/model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index d0891c6366..8daaf1a010 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -349,7 +349,7 @@ class gitlabModel extends model $apiRoot = $this->getApiRoot($gitlabID); $url = sprintf($apiRoot, "/projects/{$projectID}/labels/{$labelID}"); - return json_decode(commonModel::http($url, $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE'))); + return json_decode(commonModel::http($url, null, $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE'))); } /** @@ -946,7 +946,7 @@ class gitlabModel extends model $apiRoot = $this->getApiRoot($gitlabID); $apiPath = "/projects/{$projectID}/issues/{$issueID}"; $url = sprintf($apiRoot, $apiPath); - commonModel::http($url, $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE')); + return commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'DELETE')); } /** From e8695963aff6e4319237b0d7dc10221245cd83e8 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Tue, 29 Jun 2021 15:58:38 +0800 Subject: [PATCH 180/269] *Task fixed close issues. --- module/gitlab/model.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index d0891c6366..3fb2c418db 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -800,6 +800,7 @@ class gitlabModel extends model $map = $this->config->gitlab->maps->task; $issue = new stdclass; $gitlabUsers = $this->getUserAccountIdPairs($gitlabID); + foreach($map as $taskField => $config) { $value = ''; @@ -812,6 +813,11 @@ class gitlabModel extends model } if($value) $issue->$field = $value; } + + /* issue->state is null when creating it, we should put status_event when updating it. */ + if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; + if(isset($issue->state) and $issue->state == 'opened') $issue->state_event='reopen'; + return $issue; } @@ -848,6 +854,10 @@ class gitlabModel extends model if($value) $issue->$field = $value; } + /* issue->state is null when creating it, we should put status_event when updating it. */ + if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; + if(isset($issue->state) and $issue->state == 'opened') $issue->state_event='reopen'; + return $issue; } From 701b817946d5b310161248bb3c3ac6be9f40103f Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 16:10:11 +0800 Subject: [PATCH 181/269] * Bug fixed when creating object and syncing to issue. --- module/gitlab/model.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index e27d71c441..64cddda471 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -571,6 +571,7 @@ class gitlabModel extends model public function pushTask($taskID, $gitlab, $gitlabProject) { $task = $this->loadModel('task')->getByID($taskID); + if(empty($task)) return false; if(!$gitlabID or !$projectID) { @@ -607,7 +608,7 @@ class gitlabModel extends model public function pushStory($storyID, $gitlabID, $projectID) { $story = $this->loadModel('story')->getByID($storyID); - if(empty($bug)) return false; + if(empty($story)) return false; if(!$gitlabID or !$projectID) { @@ -644,6 +645,7 @@ class gitlabModel extends model public function pushBug($bugID, $gitlabID, $projectID) { $bug = $this->loadModel('bug')->getByID($bugID); + if(empty($bug)) return false; if(!$gitlabID or !$projectID) { @@ -681,6 +683,7 @@ class gitlabModel extends model public function pushToIssue($objectType, $objectID, $gitlabID, $projectID) { $object = $this->loadModel($objectType)->getByID($objectID); + if(empty($object)) return false; if(!$gitlabID or !$projectID) { $result = $this->getGitlabIDprojectID($objectType, $objectID); From dd8cd2aa5eb93a4204a97a12bb9a2fc37725d8d6 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Tue, 29 Jun 2021 16:15:15 +0800 Subject: [PATCH 182/269] * Check token by X-Gitlab-Token. --- module/gitlab/model.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index ea1541e762..460b1b6cec 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -58,7 +58,7 @@ class gitlabModel extends model { $gitlab = $this->getByID($id); if(!$gitlab) return ""; - $gitlab_url = rtrim($gitlab->url, '/').'/api/v4%s'."?private_token={$gitlab->token}"; + $gitlab_url = rtrim($gitlab->url, '/') . '/api/v4%s'; return $gitlab_url; } @@ -551,7 +551,7 @@ class gitlabModel extends model $webhooks = $this->apiGetHooks($gitlabID, $projectID); foreach($products as $index => $product) { - $url = sprintf($this->config->gitlab->webhookURL, commonModel::getSysURL(), $product, $gitlabID, $gitlab->private); + $url = sprintf($this->config->gitlab->webhookURL, commonModel::getSysURL(), $product, $gitlabID); foreach($webhooks as $webhook) if($webhook->url == $url) continue; $response = $this->apiCreateHook($gitlabID, $projectID, $url); } @@ -958,7 +958,7 @@ class gitlabModel extends model public function webhookCheckToken() { $gitlab = $this->getByID($this->get->gitlab); - if($gitlab->private != $this->get->token) die(); + if($gitlab->private != $_SERVER["HTTP_X_GITLAB_TOKEN"]) die('Token error.'); } /** From 812b048621856ef3ea8c715268257bd54346e9bf Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 16:20:01 +0800 Subject: [PATCH 183/269] + Add story state map(without full qa). --- module/gitlab/config.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 4fcfd175f5..c1017854af 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -75,6 +75,11 @@ $config->gitlab->storyWeightMap['1'] = '1'; $config->gitlab->storyWeightMap['2'] = '2'; $config->gitlab->storyWeightMap['3'] = '3'; +$config->gitlab->storyStateMap = array(); +$config->gitlab->storyStateMap['active'] = 'opened'; +$config->gitlab->storyStateMap['resolved'] = 'closed'; +$config->gitlab->storyStateMap['closed'] = 'closed'; + $config->gitlab->bugWeightMap = array(); $config->gitlab->bugWeightMap['1'] = '1'; $config->gitlab->bugWeightMap['2'] = '2'; From ad41a07d3607b1cd8eab670b905a2083f85409bd Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 16:47:09 +0800 Subject: [PATCH 184/269] + Create webhook with access token; --- module/gitlab/model.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 1eecd4eed3..4e8d1d3f03 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -233,6 +233,10 @@ class gitlabModel extends model { $apiRoot = $this->getApiRoot($gitlabID); + $accessToken = $this->dao->select('private as accessToken')->from(TABLE_PIPELINE) + ->where('id')->eq($gitlabID) + ->fetch('accessToken'); + $postData = new stdclass; $postData->enable_ssl_verification = "false"; $postData->issues_events = "true"; @@ -240,7 +244,8 @@ class gitlabModel extends model $postData->push_events = "true"; $postData->tag_push_events = "true"; $postData->url = $url; - + $postData->token = $accessToken; + $url = sprintf($apiRoot, "/projects/{$projectID}/hooks"); return commonModel::http($url, $postData); } From 6d7bb20eac75a1a5d60ffa8088057e0c81ab1cf6 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 29 Jun 2021 16:56:14 +0800 Subject: [PATCH 185/269] * Remove token from url for security. --- module/gitlab/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index c1017854af..ca3f7babb3 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -21,7 +21,7 @@ $config->gitlab->zentaoObjectLabel->storyColor = '#69D100'; $config->gitlab->zentaoObjectLabel->bugColor = '#D10069'; $config->gitlab->zentaoObjectLabel->priority = "0"; -$config->gitlab->webhookURL = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s&token=%s"; +$config->gitlab->webhookURL = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s"; $config->gitlab->skippedFields = new stdclass; $config->gitlab->skippedFields->issueCreate = array(); From 1c27519ef2b6b65f8293fc66789f9d701e958ba8 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Wed, 30 Jun 2021 16:22:33 +0800 Subject: [PATCH 186/269] * Fix story sync Issuse bug. --- module/bug/model.php | 1 + module/gitlab/config.php | 3 +-- module/gitlab/model.php | 2 -- module/story/model.php | 4 ++-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/module/bug/model.php b/module/bug/model.php index 9f44bebf2a..899a68062b 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -1002,6 +1002,7 @@ class bugModel extends model ->checkIF($bug->resolution == 'fixed', 'resolvedBuild','notempty') ->where('id')->eq((int)$bugID) ->exec(); + if(!dao::isError()) { $this->loadModel('score')->create('bug', 'resolve', $oldBug); diff --git a/module/gitlab/config.php b/module/gitlab/config.php index ca3f7babb3..7a8db397a8 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -43,10 +43,9 @@ $config->gitlab->maps->story = array(); $config->gitlab->maps->story['title'] = 'title|field|'; $config->gitlab->maps->story['spec'] = 'description|fields|verify'; $config->gitlab->maps->story['openedDate'] = 'created_at|field|datetime'; -$config->gitlab->maps->story['openedBy'] = 'assignee_id|userPairs|'; -$config->gitlab->maps->story['assignedTo'] = 'assignee_id|userPairs|'; $config->gitlab->maps->story['status'] = 'state|configItems|storyStateMap'; $config->gitlab->maps->story['pri'] = 'weight|configItems|storyWeightMap'; +$config->gitlab->maps->story['lastEditedBy'] = 'assignee_id|userPairs|'; $config->gitlab->maps->bug = array(); $config->gitlab->maps->bug['title'] = 'title|field|'; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 4e8d1d3f03..cc2422030e 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -861,11 +861,9 @@ class gitlabModel extends model } if($value) $issue->$field = $value; } - /* issue->state is null when creating it, we should put status_event when updating it. */ if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; if(isset($issue->state) and $issue->state == 'opened') $issue->state_event='reopen'; - return $issue; } diff --git a/module/story/model.php b/module/story/model.php index 24e9c9b44b..7a911f027f 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -1407,7 +1407,7 @@ class storyModel extends model $oldStory = $this->dao->findById($storyID)->from(TABLE_STORY)->fetch(); $now = helper::now(); $story = fixer::input('post') - ->add('assignedTo', 'closed') + ->add('assignedTo', 'closed') ->add('status', 'closed') ->add('stage', 'closed') ->setDefault('lastEditedBy', $this->app->user->account) @@ -1427,7 +1427,7 @@ class storyModel extends model ->where('id')->eq($storyID)->exec(); $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('story',$storyID); - if($objectID) $this->loadModel('gitlab')->pushToissue('story', $storyID, $objectID->gitlabID, $objectID->projectID); + if($objectID) $this->loadModel('gitlab')->pushToIssue('story', $storyID, $objectID->gitlabID, $objectID->projectID); /* Update parent story status. */ if($oldStory->parent > 0) $this->updateParentStatus($storyID, $oldStory->parent); From b48df3518a9f6488350d87b4f83e75acb6a82264 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Wed, 30 Jun 2021 18:56:55 +0800 Subject: [PATCH 187/269] * Fix story bug. --- module/gitlab/config.php | 12 ++++++------ module/story/model.php | 12 ++++++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 7a8db397a8..5c09cc37ec 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -40,12 +40,12 @@ $config->gitlab->maps->task['pri'] = 'weight|configItems|taskWeightMa $config->gitlab->maps->task['lastEditedBy'] = 'updated_by_id|userPairs|'; $config->gitlab->maps->story = array(); -$config->gitlab->maps->story['title'] = 'title|field|'; -$config->gitlab->maps->story['spec'] = 'description|fields|verify'; -$config->gitlab->maps->story['openedDate'] = 'created_at|field|datetime'; -$config->gitlab->maps->story['status'] = 'state|configItems|storyStateMap'; -$config->gitlab->maps->story['pri'] = 'weight|configItems|storyWeightMap'; -$config->gitlab->maps->story['lastEditedBy'] = 'assignee_id|userPairs|'; +$config->gitlab->maps->story['title'] = 'title|field|'; +$config->gitlab->maps->story['spec'] = 'description|fields|verify'; +$config->gitlab->maps->story['openedDate'] = 'created_at|field|datetime'; +$config->gitlab->maps->story['assignedTo'] = 'assignee_id|userPairs|'; +$config->gitlab->maps->story['status'] = 'state|configItems|storyStateMap'; +$config->gitlab->maps->story['pri'] = 'weight|configItems|storyWeightMap'; $config->gitlab->maps->bug = array(); $config->gitlab->maps->bug['title'] = 'title|field|'; diff --git a/module/story/model.php b/module/story/model.php index 7a911f027f..2f9513d10e 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -1772,10 +1772,14 @@ class storyModel extends model if(!dao::isError()) { - /* Update story to gitlab issue. */ - $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('story',$storyID); - if($objectID) $this->loadModel('gitlab')->pushToissue('story', $storyID, $objectID->gitlabID, $objectID->projectID); - + $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('story', $storyID); + $attribute = new stdclass(); + $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $story->assignedTo); + if($attribute->assignee_id != '') + { + // TODO(dingguodong) we should alert to operator when can not find the user, and the operator should reconfigure user binding. + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID , $attribute); + } return common::createChanges($oldStory, $story); } return false; From 15149a59556c0c046b0727dbf95822753e219062 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 1 Jul 2021 08:12:43 +0800 Subject: [PATCH 188/269] * Rename pushObject to pushToIssue. --- module/bug/control.php | 2 +- module/gitlab/view/transferissue.html.php | 63 +++++++++++++++++++++++ module/story/model.php | 4 +- 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 module/gitlab/view/transferissue.html.php diff --git a/module/bug/control.php b/module/bug/control.php index 9b92147752..a4921fd7fb 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -1249,7 +1249,7 @@ class bug extends control $this->executeHooks($bugID); - $this->loadModel('gitlab')->pushBug($bugID, $this->post->gitlab, $this->post->gitlabProject); + $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $this->post->gitlab, $this->post->gitlabProject); if($bug->toTask != 0) { diff --git a/module/gitlab/view/transferissue.html.php b/module/gitlab/view/transferissue.html.php new file mode 100644 index 0000000000..90e157f3cd --- /dev/null +++ b/module/gitlab/view/transferissue.html.php @@ -0,0 +1,63 @@ + + * @package story + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +
+
+

gitlab->transferIssue;?>

+
+
+
+
gitlab->name; ?>name, "class='form-control'"); ?>gitlab->gitlabNameTips; ?>name, "class='form-control' placeholder='{$lang->gitlab->placeholder->name}'"); ?>
gitlab->url; ?>url, "class='form-control'"); ?>gitlab->gitlabUrlTips; ?>url, "class='form-control' placeholder='{$lang->gitlab->placeholder->url}'"); ?>
gitlab->token;?>token, "class='form-control'");?>gitlab->gitlabTokenTips; ?>token, "class='form-control' placeholder='{$lang->gitlab->placeholder->token}'");?>
From 0205c86b346c4102befc70b98056c8ff412813df Mon Sep 17 00:00:00 2001 From: lichengjun Date: Mon, 21 Jun 2021 16:34:16 +0800 Subject: [PATCH 079/269] * Add execution task gitlab. --- module/task/lang/zh-cn.php | 4 ++++ module/task/view/create.html.php | 4 ++++ module/user/model.php | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/module/task/lang/zh-cn.php b/module/task/lang/zh-cn.php index ba81bcb2e5..cde88378fe 100644 --- a/module/task/lang/zh-cn.php +++ b/module/task/lang/zh-cn.php @@ -67,6 +67,7 @@ $lang->task->storyVersion = "{$lang->SRCommon}版本"; $lang->task->color = '标题颜色'; $lang->task->name = '任务名称'; $lang->task->type = '任务类型'; +$lang->task->sync = '同步平台'; $lang->task->pri = '优先级'; $lang->task->mailto = '抄送给'; $lang->task->estimate = '最初预计'; @@ -163,6 +164,9 @@ $lang->task->typeList['ui'] = '界面'; $lang->task->typeList['affair'] = '事务'; $lang->task->typeList['misc'] = '其他'; +$lang->task->syncList[''] = ''; +$lang->task->syncList['gitlab'] = 'gitlab'; + $lang->task->priList[0] = ''; $lang->task->priList[1] = '1'; $lang->task->priList[2] = '2'; diff --git a/module/task/view/create.html.php b/module/task/view/create.html.php index 508f3f7087..1bcb421ffe 100644 --- a/module/task/view/create.html.php +++ b/module/task/view/create.html.php @@ -45,6 +45,10 @@
task->sync;?>task->syncList, '', "class='form-control chosen' onchange='setOwners(this.value)'");?>
task->module;?> module, "class='form-control chosen' onchange='setStories(this.value, $execution->id)'");?>
task->sync;?>task->syncList, '', "class='form-control chosen' onchange='setOwners(this.value)'");?>realname, "class='form-control chosen' onchange='setOwners(this.value)'");?>
task->module;?>
task->sync;?>realname, "class='form-control chosen' onchange='setOwners(this.value)'");?>
task->module;?> module, "class='form-control chosen' onchange='setStories(this.value, $execution->id)'");?>
task->sync;?>
task->afterSubmit;?> task->afterChoices, !empty($task->id) ? 'toTaskList' : 'continueAdding');?>
task->sync;?>task->sync2Gitlab;?>
task->afterSubmit;?> task->afterChoices, !empty($task->id) ? 'toTaskList' : 'continueAdding');?>
story->sync2Gitlab;?>
task->sync2Gitlab;?>
bug->status;?>
+ + + + + + + + + zentaoAccount)) continue;?> + + + + + + + + zentaoAccount)) continue;?> + + + + + + + + + + + + +
gitlab->gitlabAccount;?>gitlab->zentaoAccount;?>
avatar, "height=40");?> + realname;?> +
account . " <" . $gitlabUser->email . ">"; ?> +
id]", $userPairs, '', "class='form-control select chosen'" );?>
avatar, "height=40");?> + realname;?> +
account . " <" . $gitlabUser->email . ">";?> +
id]", $userPairs, $gitlabUser->zentaoAccount, "class='form-control select chosen'" );?>
+ save);?> + +
+
+ + + diff --git a/module/story/model.php b/module/story/model.php index 2f9513d10e..6e296eb280 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -340,7 +340,7 @@ class storyModel extends model if($from && is_callable(array($this, $this->config->story->fromObjects[$from]['callback']))) call_user_func(array($this, $this->config->story->fromObjects[$from]['callback']), $storyID); /* push this story to gitlab issue */ - $this->loadModel('gitlab')->pushStory($storyID, $this->post->gitlab, $this->post->gitlabProject); + $this->loadModel('gitlab')->pushToIssue('story', $storyID, $this->post->gitlab, $this->post->gitlabProject); return array('status' => 'created', 'id' => $storyID); } @@ -1813,7 +1813,7 @@ class storyModel extends model if(!dao::isError()) { /* Push this story to gitlab issue. */ - $this->loadModel('gitlab')->pushStory($storyID, $this->post->gitlab, $this->post->gitlabProject); + $this->loadModel('gitlab')->pushToIssue('story', $storyID, $this->post->gitlab, $this->post->gitlabProject); $allChanges[$storyID] = common::createChanges($oldStory, $story); } From ef8948e381190262f46d9d840aabb62922c51869 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 1 Jul 2021 10:05:49 +0800 Subject: [PATCH 189/269] + Append bug link in zentao to gitlab issue description. --- module/gitlab/model.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index cc2422030e..6af2c05e6a 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -904,6 +904,10 @@ class gitlabModel extends model if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; if(isset($issue->state) and $issue->state == 'opened') $issue->state_event='reopen'; + /* Append this object link in zentao to gitlab issue description */ + $zentaoLink = common::getSysURL() . helper::createLink('bug', 'view', "bugID={$bug->id}"); + $issue->description = $issue->description . "\n\n" . $zentaoLink; + return $issue; } From 8d6531c91663f9e8fbbeed3aee5780dce00140e9 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 1 Jul 2021 10:16:35 +0800 Subject: [PATCH 190/269] + Append task link in zentao to gitlab issue description. --- module/gitlab/model.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 6af2c05e6a..1df25723a4 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -826,6 +826,10 @@ class gitlabModel extends model if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; if(isset($issue->state) and $issue->state == 'opened') $issue->state_event='reopen'; + /* Append this object link in zentao to gitlab issue description */ + $zentaoLink = common::getSysURL() . helper::createLink('task', 'view', "taskID={$task->id}"); + $issue->description = $issue->description . "\n\n" . $zentaoLink; + return $issue; } From 493f692a69ac32a6f091ce205a2072f263c585e6 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 1 Jul 2021 10:19:36 +0800 Subject: [PATCH 191/269] + Append story link in zentao to gitlab issue description. --- module/gitlab/model.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 1df25723a4..a28ed01c40 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -868,6 +868,11 @@ class gitlabModel extends model /* issue->state is null when creating it, we should put status_event when updating it. */ if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; if(isset($issue->state) and $issue->state == 'opened') $issue->state_event='reopen'; + + /* Append this object link in zentao to gitlab issue description */ + $zentaoLink = common::getSysURL() . helper::createLink('story', 'view', "storyID={$story->id}"); + $issue->description = $issue->description . "\n\n" . $zentaoLink; + return $issue; } From 5d31216afdd8049fd498422dfdee679b1860cf1b Mon Sep 17 00:00:00 2001 From: lichengjun Date: Thu, 1 Jul 2021 11:21:05 +0800 Subject: [PATCH 192/269] * Fix close to issues bug. --- module/gitlab/model.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index a28ed01c40..e6c23f6ab4 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -865,6 +865,8 @@ class gitlabModel extends model } if($value) $issue->$field = $value; } + + if($issue->assignee_id == 'closed') unset($issue->assignee_id); /* issue->state is null when creating it, we should put status_event when updating it. */ if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; if(isset($issue->state) and $issue->state == 'opened') $issue->state_event='reopen'; From 1b0f48b9e380db5a005216c62958de55e4c2e4d8 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Thu, 1 Jul 2021 14:00:43 +0800 Subject: [PATCH 193/269] * Fix close to issues. --- module/gitlab/model.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index e6c23f6ab4..509517ecbe 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -822,6 +822,7 @@ class gitlabModel extends model if($value) $issue->$field = $value; } + if($issue->assignee_id == 'closed') unset($issue->assignee_id); /* issue->state is null when creating it, we should put status_event when updating it. */ if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; if(isset($issue->state) and $issue->state == 'opened') $issue->state_event='reopen'; @@ -911,6 +912,7 @@ class gitlabModel extends model if($value) $issue->$field = $value; } + if($issue->assignee_id == 'closed') unset($issue->assignee_id); /* issue->state is null when creating it, we should put status_event when updating it. */ if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; if(isset($issue->state) and $issue->state == 'opened') $issue->state_event='reopen'; From 1fa03c1f44cc196ad83c9a4e45f1eb7d05461de2 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Thu, 1 Jul 2021 14:24:05 +0800 Subject: [PATCH 194/269] * Add api get single issue --- module/bug/model.php | 5 +++++ module/gitlab/model.php | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/module/bug/model.php b/module/bug/model.php index 899a68062b..d39b8a3b4d 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -1226,6 +1226,11 @@ class bugModel extends model ->remove('comment') ->get(); + $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('bug', $bugID); + + $singleIssue = new stdclass(); + $singleIssue = $this->loadModel('gitlab')->apiSingleIssue($relation->gitlabID, $relation->issueID); + $this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec(); $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('bug',$bugID); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 509517ecbe..b6e2bc04b8 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -924,6 +924,24 @@ class gitlabModel extends model return $issue; } + /** + * Api get single issue. + * + * @param int $gitlabID + * @param int $projectID + * @param object $issue + * @access public + * @return void + */ + public function apiSingleIssue($gitlabID, $projectID, $issue) + { + $apiRoot = $this->getApiRoot($gitlabID); + $apiPath = "/issues/{$issue}"; + + $url = sprintf($apiRoot, $apiPath); + return json_decode(commonModel::http($url, $issue)); + } + /** * Api create issue. * From ed4d6d4c11655d33a199ff4e4589f72377937f74 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 1 Jul 2021 14:30:59 +0800 Subject: [PATCH 195/269] - Remove unused bindProduct. --- module/gitlab/view/browse.html.php | 1 - 1 file changed, 1 deletion(-) diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php index 19f7e339c4..1fc24f76e0 100644 --- a/module/gitlab/view/browse.html.php +++ b/module/gitlab/view/browse.html.php @@ -36,7 +36,6 @@ url; ?> "); common::printIcon('gitlab', 'edit', "gitlabID=$id", '', 'list', 'edit'); common::printIcon('gitlab', 'binduser', "id=$id", '', 'list', 'group'); if(common::hasPriv('gitlab', 'delete')) echo html::a($this->createLink('gitlab', 'delete', "gitlabID=$id"), '', 'hiddenwin', "title='{$lang->gitlab->delete}' class='btn'"); From e510d5ae6a505e1cd8342b985f28165964f3693b Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 1 Jul 2021 15:39:54 +0800 Subject: [PATCH 196/269] * Review codes and adjust code format. --- module/gitlab/model.php | 1052 ++++++++++++++++----------------------- 1 file changed, 435 insertions(+), 617 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index f1fa6fcafd..d62c11a623 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -48,18 +48,17 @@ class gitlabModel extends model } /** - * Get gitlab api base url with access_token + * Get gitlab api base url by gitlab id. * * @param int $id * @access public - * @return string gitlab api base url with access_token - */ - public function getApiRoot($id) - { + * @return string + */ + public function getApiRoot($id) + { $gitlab = $this->getByID($id); - if(!$gitlab) return ""; - $gitlab_url = rtrim($gitlab->url, '/') . '/api/v4%s'; - return $gitlab_url; + if(!$gitlab) return ''; + return rtrim($gitlab->url, '/').'/api/v4%s'."?private_token={$gitlab->token}"; } /** @@ -67,7 +66,7 @@ class gitlabModel extends model * * @param int $gitlab * @access public - * @return void + * @return array */ public function getUserIdAccountPairs($gitlab) { @@ -82,7 +81,7 @@ class gitlabModel extends model * * @param int $gitlab * @access public - * @return void + * @return array */ public function getUserAccountIdPairs($gitlab) { @@ -92,6 +91,148 @@ class gitlabModel extends model ->fetchPairs(); } + /** + * Get project pairs of one gitlab. + * + * @param int $gitlabID + * @access public + * @return array + */ + public function getProjectPairs($gitlabID) + { + $projects = $this->apiGetProjects($gitlabID); + + $projectPairs = array(); + foreach($projects as $project) $projectPairs[$project->id] = $project->name_with_namespace; + + return $projectPairs; + } + + /** + * Get matched gitlab users. + * + * @param array $gitlabUsers + * @param array $zentaoUsers + * @access public + * @return array + */ + public function getMatchedUsers($gitlabID, $gitlabUsers, $zentaoUsers) + { + $matches = new stdclass; + foreach($gitlabUsers as $gitlabUser) + { + foreach($zentaoUsers as $zentaoUser) + { + if($gitlabUser->account == $zentaoUser->account) $matches->accounts[$gitlabUser->account][] = $zentaoUser->account; + if($gitlabUser->realname == $zentaoUser->realname) $matches->names[$gitlabUser->realname][] = $zentaoUser->account; + if($gitlabUser->email == $zentaoUser->email) $matches->emails[$gitlabUser->email][] = $zentaoUser->account; + } + } + + $bindedUsers = $this->dao->select('openID,account') + ->from(TABLE_OAUTH) + ->where('providerType')->eq('gitlab') + ->andWhere('providerID')->eq($gitlabID) + ->fetchPairs(); + + $matchedUsers = array(); + foreach($gitlabUsers as $gitlabUser) + { + if(isset($bindedUsers[$gitlabUser->id])) + { + $gitlabUser->zentaoAccount = $bindedUsers[$gitlabUser->id]; + $matchedUsers[] = $gitlabUser; + continue; + } + + $matchedZentaoUsers = array(); + if(isset($matches->accounts[$gitlabUser->account])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->accounts[$gitlabUser->account]); + if(isset($matches->emails[$gitlabUser->email])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->emails[$gitlabUser->email]); + if(isset($matches->names[$gitlabUser->realname])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->names[$gitlabUser->realname]); + + $matchedZentaoUsers = array_unique($matchedZentaoUsers); + if(count($matchedZentaoUsers) == 1) + { + $gitlabUser->zentaoAccount = current($matchedZentaoUsers); + $matchedUsers[] = $gitlabUser; + } + } + + return $matchedUsers; + } + + /** + * Get gitlab projects by executionID. + * + * @param int $executionID + * @access public + * @return array + */ + public function getProjectsByExecution($executionID) + { + $products = $this->loadModel('execution')->getProducts($executionID, false); + $productIdList = array_keys($products); + + return $this->dao->select('AID,BID as gitlabProject') + ->from(TABLE_RELATION) + ->where('relation')->eq('interrated') + ->andWhere('AType')->eq('gitlab') + ->andWhere('BType')->eq('gitlabProject') + ->andWhere('product')->in($productIdList) + ->fetchGroup('AID'); + } + + /** + * Get gitlab projects of one Product. + * + * @param int $productID + * @access public + * @return array + */ + public function getProjectsByProduct($productID) + { + return $this->dao->select('AID, BID as gitlabProject')->from(TABLE_RELATION) + ->where('relation')->eq('interrated') + ->andWhere('AType')->eq('gitlab') + ->andWhere('BType')->eq('gitlabProject') + ->andWhere('product')->eq($productID) + ->fetchGroup('AID'); + } + + /** + * Get gitlabID and projectID. + * + * @param string $objectType + * @param int $objectID + * @access public + * @return object + */ + public function getRelationByObject($objectType, $objectID) + { + return $this->dao->select('id,extra as gitlabID, BVersion as projectID, BID as issueID')->from(TABLE_RELATION) + ->where('relation')->eq('gitlab') + ->andWhere('Atype')->eq($objectType) + ->andWhere('AID')->eq($objectID) + ->fetch(); + } + + /** + * Get gitlab userID by account. + * + * @param int $gitlabID + * @param string $account + * @access public + * @return arary + */ + public function getGitlabUserID($gitlabID, $account) + { + return $this->dao->select('openID')->from(TABLE_OAUTH) + ->where('providerType')->eq('gitlab') + ->andWhere('providerID')->eq($gitlabID) + ->andWhere('account')->eq($account) + ->fetch('openID'); + } + /** * Create a gitlab. * @@ -203,13 +344,13 @@ class gitlabModel extends model } /** - * Get specific hook. + * Get specific hook by api. * * @param int $gitlabID * @param int $projectID * @param int $hookID * @access public - * @return void + * @return object */ public function apiGetHook($gitlabID, $projectID, $hookID) { @@ -221,13 +362,13 @@ class gitlabModel extends model } /** - * Create hook. + * Create hook by api. * * @param int $gitlabID * @param int $projectID * @param string $url * @access public - * @return void + * @return object */ public function apiCreateHook($gitlabID, $projectID, $url) { @@ -251,13 +392,13 @@ class gitlabModel extends model } /** - * Delete hook. + * Delete hook by api. * * @param int $gitlabID * @param int $projectID * @param int $hookID * @access public - * @return void + * @return null|object */ public function apiDeleteHook($gitlabID, $projectID, $hookID) { @@ -268,13 +409,13 @@ class gitlabModel extends model } /** - * Update hook. + * Update hook by api. * * @param int $gitlabID * @param int $projectID * @param int $hookID * @access public - * @return void + * @return object */ public function apiUpdateHook($gitlabID, $projectID, $hookID) { @@ -290,10 +431,8 @@ class gitlabModel extends model $postData->url = $url; $postData->token = $token; - $apiPath = "/projects/{$projectID}/hooks/{$hookID}"; - $url = sprintf($apiRoot, $apiPath); - $response = commonModel::http($url, $postData, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT')); - return $response; + $url = sprintf($apiRoot, "/projects/{$projectID}/hooks/{$hookID}"); + return commonModel::http($url, $postData, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT')); } /** @@ -310,18 +449,17 @@ class gitlabModel extends model if(empty($label->name) or empty($label->color)) return false; $apiRoot = $this->getApiRoot($gitlabID); - - $url = sprintf($apiRoot, "/projects/{$projectID}/labels/"); - return commonModel::http($url, $label); + $url = sprintf($apiRoot, "/projects/{$projectID}/labels/"); + return json_decode(commonModel::http($url, $label)); } /** - * Get labels of project. + * Get labels of project by api. * * @param int $gitlabID * @param int $projectID * @access public - * @return void + * @return array */ public function apiGetLabels($gitlabID, $projectID) { @@ -333,13 +471,13 @@ class gitlabModel extends model } /** - * Delete a Label by labelName. + * Delete a Label with labelName by api. * - * @param int $gitlabID - * @param int $projectID - * @param string $labelName + * @param int $gitlabID + * @param int $projectID + * @param string $labelName * @access public - * @return void + * @return object */ public function apiDeleteLabel($gitlabID, $projectID, $labelName) { @@ -357,6 +495,246 @@ class gitlabModel extends model return json_decode(commonModel::http($url, null, $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE'))); } + /** + * Get single issue by api. + * + * @param int $gitlabID + * @param int $projectID + * @param int $issueID + * @access public + * @return object + */ + public function apiGetSingleIssue($gitlabID, $projectID, $issueID) + { + $apiRoot = $this->getApiRoot($gitlabID); + $url = sprintf($apiRoot, "/issues/{$issueID}"); + return json_decode(commonModel::http($url)); + } + + /** + * Create issue by api. + * + * @param int $gitlabID + * @param int $projectID + * @param object $issue + * @access public + * @return object + */ + public function apiCreateIssue($gitlabID, $projectID, $issue) + { + foreach($this->config->gitlab->skippedFields->issueCreate as $field) + { + if(isset($issue->$field)) unset($issue->$field); + } + + $apiRoot = $this->getApiRoot($gitlabID); + $url = sprintf($apiRoot, "/projects/{$projectID}/issues/"); + + return json_decode(commonModel::http($url, $issue)); + } + + /** + * Update issue by gitlab API. + * + * @param int $gitlabID + * @param int $projectID + * @param int $issueID + * @param object $attribute + * @access public + * @return object + */ + public function apiUpdateIssue($gitlabID, $projectID, $issueID, $attribute) + { + $apiRoot = $this->getApiRoot($gitlabID); + $url = sprintf($apiRoot, "/projects/{$projectID}/issues/{$issueID}"); + return json_decode(commonModel::http($url, $attribute, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); + } + + /** + * Delete an issue by api. + * + * @param int $gitlabID + * @param int $projectID + * @param int $issueID + * @access public + * @return object + */ + public function apiDeleteIssue($gitlabID, $projectID, $issueID) + { + $apiRoot = $this->getApiRoot($gitlabID); + $url = sprintf($apiRoot, "/projects/{$projectID}/issues/{$issueID}"); + return json_decode(commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'DELETE'))); + } + + /** + * Check webhook token by HTTP_X_GITLAB_TOKEN. + * + * @access public + * @return void + */ + public function webhookCheckToken() + { + $gitlab = $this->getByID($this->get->gitlab); + if($gitlab->private != $_SERVER["HTTP_X_GITLAB_TOKEN"]) die('Token error.'); + } + + /** + * Parse webhook body function. + * + * @param object $body + * @param int $gitlabID + * @access public + * @return object + */ + public function webhookParseBody($body, $gitlabID) + { + $type = zget($body, 'object_kind', ''); + if(!$type or !is_callable(array($this, "webhookParse{$type}"))) return false; + return call_user_func_array(array($this, "webhookParse{$type}"), array('body' => $body, $gitlabID)); + } + + /** + * Parse Webhook issue. + * + * @param object $body + * @param int $gitlabID + * @access public + * @return object + */ + public function WebhookParseIssue($body, $gitlabID) + { + $object = $this->webhookParseObject($body->labels); + if(empty($object)) return null; + + $issue = new stdclass; + $issue->action = $body->object_attributes->action . $body->object_kind; + $issue->issue = $body->object_attributes; + $issue->changes = $body->changes; + $issue->objectType = $object->type; + $issue->objectID = $object->id; + + $issue->issue->objectType = $object->type; + $issue->issue->objectID = $object->id; + + /* Parse markdown description to html. */ + $issue->issue->description = $this->app->loadClass('hyperdown')->makeHtml($issue->issue->description); + + if(!isset($this->config->gitlab->maps->{$object->type})) return false; + $issue->object = $this->issueToZentaoObject($issue->issue, $gitlabID, $body->changes); + return $issue; + } + + /** + * Webhook parse note. + * + * @param object $body + * @access public + * @return void + */ + public function webhookParseNote($body) + { + //@todo + } + + /** + * Webhook sync issue. + * + * @param object $issue + * @param int $objectType + * @param int $objectID + * @access public + * @return void + */ + public function webhookSyncIssue($gitlabID, $issue) + { + $tableName = zget($this->config->gitlab->objectTables, $issue->objectType, ''); + if($tableName) $this->dao->update($tableName)->data($issue->object)->where('id')->eq($issue->objectID)->exec(); + return !dao::isError(); + } + + /** + * Parse zentao object from labels. + * + * @param array $labels + * @access public + * @return object|false + */ + public function webhookParseObject($labels) + { + $object = null; + foreach($labels as $label) + { + if(preg_match($this->config->gitlab->labelPattern->task, $label->title)) + { + list($prefix, $id) = explode('/', $label->title); + + $object = new stdclass; + $object->type = 'task'; + $object->id = $id; + } + } + + return $object; + } + + /** + * Process webhook issue assign option. + * + * @param int $gitlabID + * @param object $issue + * @access public + * @return bool + */ + public function webhookAssignIssue($issue) + { + $tableName = zget($this->config->gitlab->objectTables, $issue->objectType, ''); + if(!$tableName) return false; + + $data = $issue->object; + $data->assignedDate = $issue->object->lastEditedDate; + $data->assignedTo = $issue->object->assignedTo; + + $this->dao->update($tableName)->data($data)->where('id')->eq($issue->objectID)->exec(); + if(dao::isError()) return false; + + $oldObject = $this->dao->findById($issue->objectID)->from($tableName)->fetch(); + $changes = common::createChanges($oldObject, $data); + $actionID = $this->loadModel('action')->create($issue->objectType, $issue->objectID, 'Assigned', "Assigned by webhook by gitlab issue : {$issue->issue->url}", $data->assignedTo); + $this->action->logHistory($actionID, $changes); + + return true; + } + + /** + * Process issue close option. + * + * @param int $gitlabID + * @param object $issue + * @access public + * @return bool + */ + public function webhookCloseIssue($issue) + { + $tableName = zget($this->config->gitlab->objectTables, $issue->objectType, ''); + if(!$tableName) return false; + + $data = $issue->object; + $data->assignedTo = 'closed'; + $data->status = 'closed'; + $data->closedBy = $issue->object->lastEditedBy; + $data->closedDate = $issue->object->lastEditedDate; + + $this->dao->update($tableName)->data($data)->where('id')->eq($issue->objectID)->exec(); + if(dao::isError()) return false; + + $oldObject = $this->dao->findById($issue->objectID)->from($tableName)->fetch(); + $changes = common::createChanges($oldObject, $data); + $actionID = $this->loadModel('action')->create($issue->objectType, $issue->objectID, 'Closed', "Closed by gitlab issue: {$issue->issue->url}."); + $this->action->logHistory($actionID, $changes); + return true; + } + + /** * Create zentao object label for gitlab project. * @@ -370,21 +748,19 @@ class gitlabModel extends model public function createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID) { $label = new stdclass; + $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); if($objectType == 'task') { - $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); - $label->color = $this->config->gitlab->zentaoObjectLabel->taskColor; - $label->description = common::getSysURL() . helper::createLink('task', 'view', "taskID={$objectID}"); + $label->color = $this->config->gitlab->zentaoObjectLabel->colors->$objectType; + $label->description = common::getSysURL() . helper::createLink($objectType, 'view', "taskID={$objectID}"); } elseif($objectType == 'bug') { - $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); $label->color = $this->config->gitlab->zentaoObjectLabel->taskColor; $label->description = common::getSysURL() . helper::createLink('bug', 'view', "bugID={$objectID}"); } elseif($objectType == 'story') { - $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); $label->color = $this->config->gitlab->zentaoObjectLabel->taskColor; $label->description = common::getSysURL() . helper::createLink('story', 'view', "storyID={$objectID}"); } @@ -392,124 +768,6 @@ class gitlabModel extends model return $this->apiCreateLabel($gitlabID, $projectID, $label); } - /** - * Get project pairs of one gitlab. - * - * @param int $gitlabID - * @access public - * @return array - */ - public function getProjectPairs($gitlabID) - { - $projects = $this->apiGetProjects($gitlabID); - - $projectPairs = array(); - foreach($projects as $project) $projectPairs[$project->id] = $project->name_with_namespace; - - return $projectPairs; - } - - /** - * Get matched gitlab users. - * - * @param array $gitlabUsers - * @param array $zentaoUsers - * @access public - * @return array - */ - public function getMatchedUsers($gitlabID, $gitlabUsers, $zentaoUsers) - { - $matches = new stdclass; - foreach($gitlabUsers as $gitlabUser) - { - foreach($zentaoUsers as $zentaoUser) - { - if($gitlabUser->account == $zentaoUser->account) $matches->accounts[$gitlabUser->account][] = $zentaoUser->account; - if($gitlabUser->realname == $zentaoUser->realname) $matches->names[$gitlabUser->realname][] = $zentaoUser->account; - if($gitlabUser->email == $zentaoUser->email) $matches->emails[$gitlabUser->email][] = $zentaoUser->account; - } - } - - $bindedUsers = $this->dao->select('openID,account') - ->from(TABLE_OAUTH) - ->where('providerType')->eq('gitlab') - ->andWhere('providerID')->eq($gitlabID) - ->fetchPairs(); - - $matchedUsers = array(); - foreach($gitlabUsers as $gitlabUser) - { - if(isset($bindedUsers[$gitlabUser->id])) - { - $gitlabUser->zentaoAccount = $bindedUsers[$gitlabUser->id]; - $matchedUsers[] = $gitlabUser; - continue; - } - - $matchedZentaoUsers = array(); - if(isset($matches->accounts[$gitlabUser->account])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->accounts[$gitlabUser->account]); - if(isset($matches->emails[$gitlabUser->email])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->emails[$gitlabUser->email]); - if(isset($matches->names[$gitlabUser->realname])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->names[$gitlabUser->realname]); - - $matchedZentaoUsers = array_unique($matchedZentaoUsers); - if(count($matchedZentaoUsers) == 1) - { - $gitlabUser->zentaoAccount = current($matchedZentaoUsers); - $matchedUsers[] = $gitlabUser; - } - } - - return $matchedUsers; - } - - /** - * Get projects by executionID. - * - * @param int $executionID - * @access public - * @return array - */ - public function getProjectsByExecution($executionID) - { - $products = $this->loadModel('execution')->getProducts($executionID, false); - $productIdList = array_keys($products); - - return $this->dao->select('AID,BID as gitlabProject') - ->from(TABLE_RELATION) - ->where('relation')->eq('interrated') - ->andWhere('AType')->eq('gitlab') - ->andWhere('BType')->eq('gitlabProject') - ->andWhere('product')->in($productIdList) - ->fetchGroup('AID'); - } - - public function getProjectsByProduct($productID) - { - return $this->dao->select('AID, BID as gitlabProject')->from(TABLE_RELATION) - ->where('relation')->eq('interrated') - ->andWhere('AType')->eq('gitlab') - ->andWhere('BType')->eq('gitlabProject') - ->andWhere('product')->eq($productID) - ->fetchGroup('AID'); - } - - /** - * Get gitlabID and projectID. - * - * @param string $objectType - * @param int $objectID - * @access public - * @return object - */ - public function getGitlabIDprojectID($objectType, $objectID) - { - return $this->dao->select('extra as gitlabID, BVersion as projectID')->from(TABLE_RELATION) - ->where('relation')->eq('gitlab') - ->andWhere('Atype')->eq($objectType) - ->andWhere('AID')->eq($objectID) - ->fetch(); - } - /** * Create relationship between zentao product and gitlab project. * @@ -548,11 +806,11 @@ class gitlabModel extends model * @param int $gitlabID * @param int $projectID * @access public - * @return void + * @return bool */ public function createWebhook($products, $gitlabID, $projectID) { - $gitlab = $this->getByID($gitlabID); + $gitlab = $this->getByID($gitlabID); $webhooks = $this->apiGetHooks($gitlabID, $projectID); foreach($products as $index => $product) { @@ -564,117 +822,6 @@ class gitlabModel extends model return true; } - /** - * Push task to gitlab issue. - * - * @param int $taskID - * @param int $gitlab - * @param int $gitlabProject - * @access public - * @return void - */ - public function pushTask($taskID, $gitlab, $gitlabProject) - { - $task = $this->loadModel('task')->getByID($taskID); - if(empty($task)) return false; - - if(!$gitlabID or !$projectID) - { - $result = $this->getGitlabIDprojectID('task', $taskID); - $gitlabID = $result->gitlabID; - $projectID = $result->projectID; - } - - $syncedIssue = $this->getSyncedIssue($objectType = 'task', $objectID = $taskID, $gitlab); - $issue = $this->taskToIssue($gitlab, $gitlabProject, $task); - - if($syncedIssue) - { - $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue->BID, $issue); - } - else - { - $this->createZentaoObjectLabel($gitlab, $gitlabProject, 'task', $taskID); - $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'task', $taskID); - $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); - $this->saveSyncedIssue('task', $task, $gitlab, $issue); - } - } - - /** - * Push story to gitlab issue. - * - * @param int $storyID - * @param int $gitlabID - * @param int $projectID - * @access public - * @return void - */ - public function pushStory($storyID, $gitlabID, $projectID) - { - $story = $this->loadModel('story')->getByID($storyID); - if(empty($story)) return false; - - if(!$gitlabID or !$projectID) - { - $result = $this->getGitlabIDprojectID('story', $storyID); - $gitlabID = $result->gitlabID; - $projectID = $result->projectID; - } - - $syncedIssue = $this->getSyncedIssue($objectType = 'story', $objectID = $storyID, $gitlabID); - $issue = $this->storyToIssue($gitlabID, $projectID, $story); - - if($syncedIssue) - { - $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->BID, $issue); - } - else - { - $this->createZentaoObjectLabel($gitlabID, $projectID, 'story', $storyID); - $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'story', $storyID); - $issue = $this->apiCreateIssue($gitlabID, $projectID, $issue); - if($issue) $this->saveSyncedIssue('story', $story, $gitlabID, $issue); - } - } - - /** - * Push bug to gitlab issue. - * - * @param int $bugID - * @param int $gitlabID - * @param int $projectID - * @access public - * @return void - */ - public function pushBug($bugID, $gitlabID, $projectID) - { - $bug = $this->loadModel('bug')->getByID($bugID); - if(empty($bug)) return false; - - if(!$gitlabID or !$projectID) - { - $result = $this->getGitlabIDprojectID('bug', $bugID); - $gitlabID = $result->gitlabID; - $projectID = $result->projectID; - } - - $syncedIssue = $this->getSyncedIssue($objectType = 'bug', $objectID = $bugID, $gitlabID); - $issue = $this->bugToIssue($gitlabID, $projectID, $bug); - - if($syncedIssue) - { - $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->BID, $issue); - } - else - { - $this->createZentaoObjectLabel($gitlabID, $projectID, 'bug', $bugID); - $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'bug', $bugID); - $issue = $this->apiCreateIssue($gitlabID, $projectID, $issue); - if($issue) $this->saveSyncedIssue('bug', $bug, $gitlabID, $issue); - } - } - /** * Push to gitlab issue. * @@ -700,27 +847,24 @@ class gitlabModel extends model if($objectType == 'story') $issue = $this->storyToIssue($gitlabID, $projectID, $object); if($objectType == 'task') $issue = $this->taskToIssue($gitlabID, $projectID, $object); if($objectType == 'bug') $issue = $this->bugToIssue($gitlabID, $projectID, $object); - if($syncedIssue) - { - $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->BID, $issue); - } - else - { - $this->createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID); - $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); - $issue = $this->apiCreateIssue($gitlabID, $projectID, $issue); - if($issue) $this->saveSyncedIssue($objectType, $object, $gitlabID, $issue); - } - } - /** - * Delete an issue. - * - * @param int $gitlabID - * @param int $projectID - * @param string $objectType - * @param int $objectID - * @param int $issueID + if($syncedIssue) return $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->BID, $issue); + + $label = $this->createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID); + $issue->labels = $label->name; + + $issue = $this->apiCreateIssue($gitlabID, $projectID, $issue); + if($issue) $this->saveSyncedIssue($objectType, $object, $gitlabID, $issue); + } + + /** + * Delete an issue from zentao and gitlab. + * + * @param int $gitlabID + * @param int $projectID + * @param string $objectType + * @param int $objectID + * @param int $issueID * @access public * @return void */ @@ -732,41 +876,6 @@ class gitlabModel extends model $this->apiDeleteIssue($gitlabID, $projectID, $issueID); } - /** - * Get relation id. - * - * @param string $objectType - * @param int $objectID - * @access public - * @return void - */ - public function getRelationID($objectType, $objectID) - { - return $this->dao->select('id')->from(TABLE_RELATION) - ->where('AType')->eq($objectType) - ->andWhere('AID')->eq($objectID) - ->andWhere('relation')->eq('gitlab') - ->fetch('id'); - } - - /** - * Get synced issue from relation table. - * - * @param string $objectType - * @param int $objectID - * @param int $gitlab - * @access public - * @return object - */ - public function getSyncedIssue($objectType, $objectID, $gitlab) - { - return $this->dao->select('*')->from(TABLE_RELATION) - ->where('AType')->eq($objectType) - ->andWhere('AID')->eq($objectID) - ->andWhere('extra')->eq($gitlab) - ->fetch(); - } - /** * Save synced issue to relation table. * @@ -823,6 +932,7 @@ class gitlabModel extends model } if($issue->assignee_id == 'closed') unset($issue->assignee_id); + /* issue->state is null when creating it, we should put status_event when updating it. */ if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; if(isset($issue->state) and $issue->state == 'opened') $issue->state_event='reopen'; @@ -868,6 +978,7 @@ class gitlabModel extends model } if($issue->assignee_id == 'closed') unset($issue->assignee_id); + /* issue->state is null when creating it, we should put status_event when updating it. */ if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; if(isset($issue->state) and $issue->state == 'opened') $issue->state_event='reopen'; @@ -913,6 +1024,7 @@ class gitlabModel extends model } if($issue->assignee_id == 'closed') unset($issue->assignee_id); + /* issue->state is null when creating it, we should put status_event when updating it. */ if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; if(isset($issue->state) and $issue->state == 'opened') $issue->state_event='reopen'; @@ -924,266 +1036,6 @@ class gitlabModel extends model return $issue; } - /** - * Api get single issue. - * - * @param int $gitlabID - * @param int $projectID - * @param object $issue - * @access public - * @return void - */ - public function apiSingleIssue($gitlabID, $projectID, $issue) - { - $apiRoot = $this->getApiRoot($gitlabID); - $apiPath = "/issues/{$issue}"; - - $url = sprintf($apiRoot, $apiPath); - return json_decode(commonModel::http($url, $issue)); - } - - /** - * Api create issue. - * - * @param int $gitlabID - * @param int $projectID - * @param object $issue - * @access public - * @return void - */ - public function apiCreateIssue($gitlabID, $projectID, $issue) - { - $apiRoot = $this->getApiRoot($gitlabID); - $apiPath = "/projects/{$projectID}/issues/"; - foreach($this->config->gitlab->skippedFields->issueCreate as $field) - { - if(isset($issue->$field)) unset($issue->$field); - } - - $url = sprintf($apiRoot, $apiPath); - return json_decode(commonModel::http($url, $issue)); - } - - /** - * Update issue with new attribute using gitlab API. - * - * @param int $gitlabID - * @param int $projectID - * @param int $issueID - * @param object $attribute - * @access public - * @return object - */ - public function apiUpdateIssue($gitlabID, $projectID, $issueID, $attribute) - { - $apiRoot = $this->getApiRoot($gitlabID); - $apiPath = "/projects/{$projectID}/issues/{$issueID}"; - $url = sprintf($apiRoot, $apiPath); - $response = json_decode(commonModel::http($url, $attribute, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); - return $response; - } - - /** - * Delete an issue. - * - * @param int $gitlabID - * @param int $projectID - * @param int $issueID - * @access public - * @return void - */ - public function apiDeleteIssue($gitlabID, $projectID, $issueID) - { - $apiRoot = $this->getApiRoot($gitlabID); - $apiPath = "/projects/{$projectID}/issues/{$issueID}"; - $url = sprintf($apiRoot, $apiPath); - return commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'DELETE')); - } - - /** - * webhook check token. - * - * @access public - * @return void - */ - public function webhookCheckToken() - { - $gitlab = $this->getByID($this->get->gitlab); - if($gitlab->private != $_SERVER["HTTP_X_GITLAB_TOKEN"]) die('Token error.'); - } - - /** - * Parse webhook body function. - * - * @param object $body - * @param int $gitlabID - * @access public - * @return object - */ - public function webhookParseBody($body, $gitlabID) - { - $type = zget($body, 'object_kind', ''); - if(!$type or !is_callable(array($this, "webhookParse{$type}"))) return false; - return call_user_func_array(array($this, "webhookParse{$type}"), array('body' => $body, $gitlabID)); - } - - /** - * Parse Webhook issue. - * - * @param object $body - * @param int $gitlabID - * @access public - * @return object - */ - public function WebhookParseIssue($body, $gitlabID) - { - $object = $this->webhookParseObject($body->labels); - if(empty($object)) return null; - - $issue = new stdclass; - $issue->action = $body->object_attributes->action . $body->object_kind; - $issue->issue = $body->object_attributes; - $issue->objectType = $object->type; - $issue->objectID = $object->id; - $issue->changes = $body->changes; - - $issue->issue->objectType = $object->type; - $issue->issue->objectID = $object->id; - - /* Parse markdown description to html. */ - $issue->issue->description = $this->app->loadClass('hyperdown')->makeHtml($issue->issue->description); - - if(!isset($this->config->gitlab->maps->{$object->type})) return false; - $issue->object = $this->issueToZentaoObject($issue->issue, $gitlabID, $body->changes); - return $issue; - } - - /** - * Webhook parse note. - * - * @param object $body - * @access public - * @return void - */ - public function webhookParseNote($body) - { - $request = new stdclass; - $request->type = $body->object_kind; - if(isset($body->issue)) $body->issue = $this->parseIssue($body->issue); - - $request->labels = $body->labels; - $request->project = $body->project->id; - $request->labels = $labels; - $request->type = $labelType; - $request->typeID = $labelTypeID; - - $request->project = $body->project->id; - $request->title = $issue->title; - $request->description = $issue->description; - $request->action = $issue->action; - $request->created_at = $issue->created_at; - $request->due_date = $issue->due_date; - - $request->assignees = $issue->assignee_id; - $request->url = $issue->url; - } - - /** - * Webhook sync issue. - * - * @param object $issue - * @param int $objectType - * @param int $objectID - * @access public - * @return void - */ - public function webhookSyncIssue($gitlabID, $issue) - { - $tableName = zget($this->config->gitlab->objectTables, $issue->objectType, ''); - if($tableName) $this->dao->update($tableName)->data($issue->object)->where('id')->eq($issue->objectID)->exec(); - return !dao::isError(); - } - - /** - * Parse zentao object from labels. - * - * @param array $labels - * @access public - * @return object|false - */ - public function webhookParseObject($labels) - { - $object = null; - foreach($labels as $label) - { - if(preg_match($this->config->gitlab->labelPattern->task, $label->title)) - { - list($prefix, $id) = explode('/', $label->title); - - $object = new stdclass; - $object->type = 'task'; - $object->id = $id; - } - } - return $object; - } - - /** - * Process webhook issue assign option. - * - * @param int $gitlabID - * @param object $issue - * @access public - * @return void - */ - public function webhookAssignIssue($issue) - { - $tableName = zget($this->config->gitlab->objectTables, $issue->objectType, ''); - if(!$tableName) return false; - - $data = $issue->object; - $data->assignedDate = $issue->object->lastEditedDate; - $data->assignedTo = $issue->object->assignedTo; - - $this->dao->update($tableName)->data($data)->where('id')->eq($issue->objectID)->exec(); - if(dao::isError()) return false; - - $oldObject = $this->dao->findById($issue->objectID)->from($tableName)->fetch(); - $changes = common::createChanges($oldObject, $data); - $actionID = $this->loadModel('action')->create($issue->objectType, $issue->objectID, 'Assigned', "Assigned by webhook by gitlab issue : {$issue->issue->url}", $data->assignedTo); - $this->action->logHistory($actionID, $changes); - return true; - } - - /** - * Process issue close option. - * - * @param int $gitlabID - * @param object $issue - * @access public - * @return void - */ - public function webhookCloseIssue($issue) - { - $tableName = zget($this->config->gitlab->objectTables, $issue->objectType, ''); - if(!$tableName) return false; - - $data = $issue->object; - $data->assignedTo = 'closed'; - $data->status = 'closed'; - $data->closedBy = $issue->object->lastEditedBy; - $data->closedDate = $issue->object->lastEditedDate; - - $this->dao->update($tableName)->data($data)->where('id')->eq($issue->objectID)->exec(); - if(dao::isError()) return false; - - $oldObject = $this->dao->findById($issue->objectID)->from($tableName)->fetch(); - $changes = common::createChanges($oldObject, $data); - $actionID = $this->loadModel('action')->create($issue->objectType, $issue->objectID, 'Closed', "Closed by gitlab issue: {$issue->issue->url}."); - $this->action->logHistory($actionID, $changes); - return true; - } - /** * Parse issue to zentao object. * @@ -1217,38 +1069,4 @@ class gitlabModel extends model } return $object; } - - /** - * Get gitlab userID by account. - * - * @param int $gitlabID - * @param string $account - * @access public - * @return arary - */ - public function getGitlabUserID($gitlabID, $account) - { - return $this->dao->select('openID')->from(TABLE_OAUTH) - ->where('providerType')->eq('gitlab') - ->andWhere('providerID')->eq($gitlabID) - ->andWhere('account')->eq($account) - ->fetch('openID'); - } - - /** - * Get gitlab issue from relation by object type and id. - * - * @param string $objectType - * @param int $objectID - * @access public - * @return object - */ - public function getGitlabIssueFromRelation($objectType,$objectID) - { - return $this->dao->select('extra as gitlabID,BVersion as projectID,BID as issueID,AType,AID')->from(TABLE_RELATION) - ->where('relation')->eq('gitlab') - ->andWhere('AType')->eq($objectType) - ->andWhere('AID')->eq($objectID) - ->fetch(); - } } From 688890ee8454fd52f08ecd39a9f996d95a1d1a47 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 1 Jul 2021 15:49:19 +0800 Subject: [PATCH 197/269] * Return all fields in getRelationByObject function. --- module/gitlab/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index d62c11a623..142819af06 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -209,7 +209,7 @@ class gitlabModel extends model */ public function getRelationByObject($objectType, $objectID) { - return $this->dao->select('id,extra as gitlabID, BVersion as projectID, BID as issueID')->from(TABLE_RELATION) + return $this->dao->select('*, extra as gitlabID, BVersion as projectID, BID as issueID')->from(TABLE_RELATION) ->where('relation')->eq('gitlab') ->andWhere('Atype')->eq($objectType) ->andWhere('AID')->eq($objectID) From d4d8185131dd3746b930f0f3fd326abdc2baa66c Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 1 Jul 2021 15:55:20 +0800 Subject: [PATCH 198/269] * Rename some functions after code review. --- module/bug/control.php | 2 +- module/bug/model.php | 4 ++-- module/gitlab/model.php | 2 +- module/repo/model.php | 4 ++-- module/story/control.php | 2 +- module/story/model.php | 2 +- module/task/control.php | 2 +- module/task/model.php | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/module/bug/control.php b/module/bug/control.php index a4921fd7fb..e85c479956 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -1552,7 +1552,7 @@ class bug extends control else { /* Delete related issue in gitlab. */ - $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('bug', $bugID); + $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); if(!empty($relation)) $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'bug', $bugID, $relation->issueID); $this->bug->delete(TABLE_BUG, $bugID); diff --git a/module/bug/model.php b/module/bug/model.php index d39b8a3b4d..b227a21d8b 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -856,7 +856,7 @@ class bugModel extends model ->autoCheck() ->where('id')->eq($bugID)->exec(); - $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('bug', $bugID); + $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); $attribute = new stdclass(); $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $bug->assignedTo); if($attribute->assignee_id != '') @@ -1226,7 +1226,7 @@ class bugModel extends model ->remove('comment') ->get(); - $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('bug', $bugID); + $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); $singleIssue = new stdclass(); $singleIssue = $this->loadModel('gitlab')->apiSingleIssue($relation->gitlabID, $relation->issueID); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 142819af06..93183fb81b 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -776,7 +776,7 @@ class gitlabModel extends model * @access public * @return void */ - public function saveRelation($products, $gitlabID, $gitlabProjectID) + public function saveProjectRelation($products, $gitlabID, $gitlabProjectID) { $programs = $this->dao->select('id,program')->from(TABLE_PRODUCT)->where('id')->in($products)->fetchPairs(); diff --git a/module/repo/model.php b/module/repo/model.php index 973bab455a..463dc12510 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -232,7 +232,7 @@ class repoModel extends model if($this->post->SCM == 'Gitlab') { - $this->loadModel("gitlab")->saveRelation($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); + $this->loadModel("gitlab")->saveProjectRelation($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); /* create webhook for zentao */ $this->loadModel("gitlab")->createWebhook($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); @@ -293,7 +293,7 @@ class repoModel extends model $this->rmClientVersionFile(); - if($repo->SCM == 'Gitlab') $this->loadModel("gitlab")->saveRelation($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); + if($repo->SCM == 'Gitlab') $this->loadModel("gitlab")->saveProjectRelation($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); if($repo->path != $data->path) { $this->dao->delete()->from(TABLE_REPOHISTORY)->where('repo')->eq($id)->exec(); diff --git a/module/story/control.php b/module/story/control.php index e0bad0cb9e..03215cfc9b 100644 --- a/module/story/control.php +++ b/module/story/control.php @@ -988,7 +988,7 @@ class story extends control else { /* Delete related issue in gitlab. */ - $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('story', $storyID); + $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'story', $storyID, $relation->issueID); $this->story->delete(TABLE_STORY, $storyID); diff --git a/module/story/model.php b/module/story/model.php index 6e296eb280..7dc44bb7a8 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -1772,7 +1772,7 @@ class storyModel extends model if(!dao::isError()) { - $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('story', $storyID); + $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); $attribute = new stdclass(); $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $story->assignedTo); if($attribute->assignee_id != '') diff --git a/module/task/control.php b/module/task/control.php index 869db13dc4..d3f5f41f40 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -1281,7 +1281,7 @@ class task extends control else { /* Delete related issue in gitlab. */ - $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('task', $taskID); + $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'task', $taskID, $relation->issueID); $this->task->delete(TABLE_TASK, $taskID); diff --git a/module/task/model.php b/module/task/model.php index 029a9e17b4..5408897ed3 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -1330,7 +1330,7 @@ class taskModel extends model ->check('left', 'float') ->where('id')->eq($taskID)->exec(); - $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('task', $taskID); + $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); $attribute = new stdclass(); $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $task->assignedTo); if($attribute->assignee_id != '') From df46ea907bff19967441d186a9e9ffd80140a1bc Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 1 Jul 2021 16:07:29 +0800 Subject: [PATCH 199/269] * Format code. --- module/gitlab/control.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 1283e08487..e71edf298f 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -27,10 +27,10 @@ class gitlab extends control $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->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browse; $this->view->gitlabList = $this->gitlab->getList($orderBy, $pager); $this->view->orderBy = $orderBy; $this->view->pager = $pager; @@ -118,12 +118,8 @@ class gitlab extends control $user->providerID = $gitlabID; $user->providerType = 'gitlab'; - $this->dao->delete() - ->from(TABLE_OAUTH) - ->where('providerType')->eq($user->providerType) - ->andWhere('providerID')->eq($user->providerID) - ->exec(); - + /* Delete binded users and save new relationship.*/ + $this->dao->delete()->from(TABLE_OAUTH)->where('providerType')->eq($user->providerType)->andWhere('providerID')->eq($user->providerID)->exec(); foreach($users as $openID => $account) { if(!$account) continue; @@ -212,8 +208,7 @@ class gitlab extends control $gitlab = $this->get->gitlab; $project = $this->get->project; - $input = '{"object_kind":"issue","event_type":"issue","user":{"id":1,"name":"Administrator","username":"root","avatar_url":"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon","email":"admin@example.com"},"project":{"id":36,"name":"zenops202106dgd","description":"repo for dingguodong dev env","web_url":"http://192.168.1.161:51080/root/zenops202106dgd","avatar_url":null,"git_ssh_url":"ssh://git@192.168.1.161:51022/root/zenops202106dgd.git","git_http_url":"http://192.168.1.161:51080/root/zenops202106dgd.git","namespace":"Administrator","visibility_level":0,"path_with_namespace":"root/zenops202106dgd","default_branch":"master","ci_config_path":null,"homepage":"http://192.168.1.161:51080/root/zenops202106dgd","url":"ssh://git@192.168.1.161:51022/root/zenops202106dgd.git","ssh_url":"ssh://git@192.168.1.161:51022/root/zenops202106dgd.git","http_url":"http://192.168.1.161:51080/root/zenops202106dgd.git"},"object_attributes":{"author_id":1,"closed_at":null,"confidential":false,"created_at":"2021-06-22 02:38:01 UTC","description":"扩展动作的公式保存之后再点设置按钮报js错误\nnew issue 0622 desc ee\n![elephant](http://192.168.1.161:51080/root/zenops202106dgd/uploads/9b85fd397a602b628a271ce02264f502/elephant.jpg)","discussion_locked":null,"due_date":"2021-06-25","id":33,"iid":3,"last_edited_at":"2021-06-24 02:53:52 UTC","last_edited_by_id":1,"milestone_id":null,"moved_to_id":null,"duplicated_to_id":null,"project_id":36,"relative_position":1539,"state_id":1,"time_estimate":0,"title":"new issue 0622","updated_at":"2021-06-24 02:53:52 UTC","updated_by_id":1,"url":"http://192.168.1.161:51080/root/zenops202106dgd/-/issues/3","total_time_spent":0,"human_total_time_spent":null,"human_time_estimate":null,"assignee_ids":[8],"assignee_id":8,"labels":[{"id":38,"title":"zentao_objectType","color":"#0033CC","project_id":36,"created_at":"2021-06-16 12:04:23 UTC","updated_at":"2021-06-22 05:17:29 UTC","template":false,"description":"task","type":"ProjectLabel","group_id":null},{"id":40,"title":"zentao_task/12738","color":"#428BCA","project_id":36,"created_at":"2021-06-21 08:58:17 UTC","updated_at":"2021-06-24 02:46:14 UTC","template":false,"description":"type:bug,id:1234,url:https://back.zcorp.cc/pms/project-browse-1291-all.html","type":"ProjectLabel","group_id":null}],"state":"opened","action":"update"},"labels":[{"id":38,"title":"zentao_objectType","color":"#0033CC","project_id":36,"created_at":"2021-06-16 12:04:23 UTC","updated_at":"2021-06-22 05:17:29 UTC","template":false,"description":"task","type":"ProjectLabel","group_id":null},{"id":40,"title":"zentao_task/12738","color":"#428BCA","project_id":36,"created_at":"2021-06-21 08:58:17 UTC","updated_at":"2021-06-24 02:46:14 UTC","template":false,"description":"type:bug,id:1234,url:https://back.zcorp.cc/pms/project-browse-1291-all.html","type":"ProjectLabel","group_id":null}],"changes":{},"repository":{"name":"zenops202106dgd","url":"ssh://git@192.168.1.161:51022/root/zenops202106dgd.git","description":"repo for dingguodong dev env","homepage":"http://192.168.1.161:51080/root/zenops202106dgd"},"assignees":[{"id":8,"name":"dingguodong","username":"dingguodong","avatar_url":"https://www.gravatar.com/avatar/11302c6dd9e26e9f8e4517538f51e4a2?s=80\u0026d=identicon","email":"dingguodong@easycorp.ltd"}]}'; - //$input = file_get_contents('php://input'); + $input = file_get_contents('php://input'); $requestBody = json_decode($input); $result = $this->gitlab->webhookParseBody($requestBody, $gitlab); @@ -225,11 +220,17 @@ class gitlab extends control { fwrite($fh, date('Ymd H:i:s') . ": " . $this->app->getURI() . "\n"); fwrite($fh, "JSON: \n " . $input . "\n"); - fwrite($fh, "Parsed object: {$result->objectType} :\n " . print_r($result->object, true) . "\n"); + fwrite($fh, "Parsed object: {$result->issue->objectType} :\n " . print_r($result->object, true) . "\n"); fclose($fh); } - if($result->action = 'updateissue') $this->gitlab->webhookSyncIssue($gitlab, $result); + if($result->action == 'updateissue' and isset($result->changes->assignees)) $this->gitlab->webhookAssignIssue($result); + + //if($result->action = 'reopenissue') $this->gitlab->webhookIssueReopen($gitlab, $result); + + if($result->action == 'closeissue') $this->gitlab->webhookCloseIssue($result); + + if($result->action == 'updateissue') $this->gitlab->webhookSyncIssue($gitlab, $result); $this->view->result = 'success'; $this->view->status = 'ok'; @@ -241,6 +242,9 @@ class gitlab extends control { $gitlabID = 1; $projectID = 7; $task = $this->loadModel('task')->getByID($id); + $relations = $this->gitlab->getRelationByObject('task', $task->id); + + a($relations);exit; $issue = $this->gitlab->taskToIssue($gitlabID, $projectID, $task); $issue = $this->gitlab->apiCreateIssue($gitlabID, $projectID, $issue); $this->gitlab->saveSyncedIssue('task', $task, $gitlabID, $issue); From 56e66eb40ad12cc0c44e5f353df8f0cfe7e668e8 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 1 Jul 2021 16:15:19 +0800 Subject: [PATCH 200/269] * Simplify function for createZentaoObjectLabel. --- module/gitlab/config.php | 12 ++++++------ module/gitlab/model.php | 17 ++--------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 5c09cc37ec..ad49373fb8 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -14,12 +14,12 @@ $config->gitlab->actions = array(); $config->gitlab->actions['issue'] = array(); $config->gitlab->zentaoObjectLabel = new stdclass(); -$config->gitlab->zentaoObjectLabel->name = "zentao_%s/%s"; -$config->gitlab->zentaoObjectLabel->description = "%s"; -$config->gitlab->zentaoObjectLabel->taskColor = '#0033CC'; -$config->gitlab->zentaoObjectLabel->storyColor = '#69D100'; -$config->gitlab->zentaoObjectLabel->bugColor = '#D10069'; -$config->gitlab->zentaoObjectLabel->priority = "0"; +$config->gitlab->zentaoObjectLabel->name = "zentao_%s/%s"; +$config->gitlab->zentaoObjectLabel->description = "%s"; +$config->gitlab->zentaoObjectLabel->color->task = '#0033CC'; +$config->gitlab->zentaoObjectLabel->color->story = '#69D100'; +$config->gitlab->zentaoObjectLabel->color->bug = '#D10069'; +$config->gitlab->zentaoObjectLabel->priority = "0"; $config->gitlab->webhookURL = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s"; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 93183fb81b..58df89a72d 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -749,21 +749,8 @@ class gitlabModel extends model { $label = new stdclass; $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); - if($objectType == 'task') - { - $label->color = $this->config->gitlab->zentaoObjectLabel->colors->$objectType; - $label->description = common::getSysURL() . helper::createLink($objectType, 'view', "taskID={$objectID}"); - } - elseif($objectType == 'bug') - { - $label->color = $this->config->gitlab->zentaoObjectLabel->taskColor; - $label->description = common::getSysURL() . helper::createLink('bug', 'view', "bugID={$objectID}"); - } - elseif($objectType == 'story') - { - $label->color = $this->config->gitlab->zentaoObjectLabel->taskColor; - $label->description = common::getSysURL() . helper::createLink('story', 'view', "storyID={$objectID}"); - } + $label->color = $this->config->gitlab->zentaoObjectLabel->colors->$objectType; + $label->description = common::getSysURL() . helper::createLink($objectType, 'view', "id={$objectID}"); return $this->apiCreateLabel($gitlabID, $projectID, $label); } From 2341965ff4a71d477eb4cd05db49e7ae357c69b6 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Thu, 1 Jul 2021 16:18:22 +0800 Subject: [PATCH 201/269] * Fix format code. --- module/bug/model.php | 2 +- module/gitlab/model.php | 9 ++++----- module/task/model.php | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/module/bug/model.php b/module/bug/model.php index d39b8a3b4d..24e04ac9ae 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -647,7 +647,7 @@ class bugModel extends model if(!empty($bug->resolvedBy)) $this->loadModel('score')->create('bug', 'resolve', $bugID); $this->file->updateObjectID($this->post->uid, $bugID, 'bug'); - $relation = $this->loadModel('gitlab')->getGitlabIDprojectID('bug',$bugID); + $relation = $this->loadModel('gitlab')->getRelationByObject('bug',$bugID); if($relation) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $relation->gitlabID, $relation->projectID); return common::createChanges($oldBug, $bug); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index d62c11a623..7a2a741bcc 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -209,7 +209,7 @@ class gitlabModel extends model */ public function getRelationByObject($objectType, $objectID) { - return $this->dao->select('id,extra as gitlabID, BVersion as projectID, BID as issueID')->from(TABLE_RELATION) + return $this->dao->select('*, id, extra as gitlabID, BVersion as projectID, BID as issueID')->from(TABLE_RELATION) ->where('relation')->eq('gitlab') ->andWhere('Atype')->eq($objectType) ->andWhere('AID')->eq($objectID) @@ -506,8 +506,7 @@ class gitlabModel extends model */ public function apiGetSingleIssue($gitlabID, $projectID, $issueID) { - $apiRoot = $this->getApiRoot($gitlabID); - $url = sprintf($apiRoot, "/issues/{$issueID}"); + $url = sprintf($this->getApiRoot($gitlabID), "/issues/{$issueID}"); return json_decode(commonModel::http($url)); } @@ -838,7 +837,7 @@ class gitlabModel extends model if(empty($object)) return false; if(!$gitlabID or !$projectID) { - $result = $this->getGitlabIDprojectID($objectType, $objectID); + $result = $this->getRelationByObject($objectType, $objectID); $gitlabID = $result->gitlabID; $projectID = $result->projectID; } @@ -871,7 +870,7 @@ class gitlabModel extends model public function deleteIssue($gitlabID, $projectID, $objectType, $objectID, $issueID) { $object = $this->loadModel($objectType)->getByID($objectID); - $relationID = $this->getRelationID($objectType, $objectID); + $relationID = $this->getRelationByObject($objectType, $objectID); if(!empty($relationID)) $this->dao->delete()->from(TABLE_RELATION)->where('id')->eq($relationID)->exec(); $this->apiDeleteIssue($gitlabID, $projectID, $issueID); } diff --git a/module/task/model.php b/module/task/model.php index 029a9e17b4..a9ce439135 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -1674,7 +1674,7 @@ class taskModel extends model ->where('id')->eq((int)$taskID) ->exec(); - $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('task',$taskID); + $objectID = $this->loadModel('gitlab')->getRelationByObject('task',$taskID); if($objectID) $this->loadModel('gitlab')->pushToissue('task', $taskID, $objectID->gitlabID, $objectID->projectID); if($oldTask->parent > 0) $this->updateParentStatus($taskID); From 84674f2d5c6d11b453aca03e2fd9450463ab082b Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 1 Jul 2021 16:18:57 +0800 Subject: [PATCH 202/269] + Add unfinished transferIssue function for optimizing after code review. --- module/gitlab/control.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 1283e08487..6b35a6cf3b 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -246,4 +246,29 @@ class gitlab extends control $this->gitlab->saveSyncedIssue('task', $task, $gitlabID, $issue); exit; } + + public function transferIssue() + { + //TODO(dingguodong) todo next. + if(!empty($this->post)) + { + $project; + $product; + $execution; + $objetcType; + $gitlab; + $gitlabProject; + $gitlabIssue; + } + + $this->view->programs = array('') + $this->loadModel('program')->getTopPairs('', 'noclosed'); + + $this->view->products = '$projects'; + $this->view->execution = '$projects'; + $this->view->objectTypes = '$projects'; + $this->view->gitlabs = '$projects'; + $this->view->gitlabProjects = '$projects'; + $this->view->gitlabIssues = '$projects'; + $this->display(); + } } From 1a5824ea8bf69e87036c4994783ed6a01e2f7f2e Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 1 Jul 2021 16:33:13 +0800 Subject: [PATCH 203/269] * Simplify function for deleteIssue. --- module/bug/control.php | 2 +- module/gitlab/model.php | 10 +++++----- module/story/control.php | 2 +- module/task/control.php | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/module/bug/control.php b/module/bug/control.php index e85c479956..fc7f8a98b1 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -1553,7 +1553,7 @@ class bug extends control { /* Delete related issue in gitlab. */ $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); - if(!empty($relation)) $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'bug', $bugID, $relation->issueID); + if(!empty($relation)) $this->loadModel('gitlab')->deleteIssue('bug', $bugID, $relation->issueID); $this->bug->delete(TABLE_BUG, $bugID); if($bug->toTask != 0) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 31a595c14d..e249f48aea 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -854,12 +854,12 @@ class gitlabModel extends model * @access public * @return void */ - public function deleteIssue($gitlabID, $projectID, $objectType, $objectID, $issueID) + public function deleteIssue($objectType, $objectID, $issueID) { - $object = $this->loadModel($objectType)->getByID($objectID); - $relationID = $this->getRelationByObject($objectType, $objectID); - if(!empty($relationID)) $this->dao->delete()->from(TABLE_RELATION)->where('id')->eq($relationID)->exec(); - $this->apiDeleteIssue($gitlabID, $projectID, $issueID); + $object = $this->loadModel($objectType)->getByID($objectID); + $relation = $this->getRelationByObject($objectType, $objectID); + if(!empty($relation)) $this->dao->delete()->from(TABLE_RELATION)->where('id')->eq($relation->id)->exec(); + $this->apiDeleteIssue($relation->gitlabID, $relation->projectID, $issueID); } /** diff --git a/module/story/control.php b/module/story/control.php index 03215cfc9b..6370776923 100644 --- a/module/story/control.php +++ b/module/story/control.php @@ -989,7 +989,7 @@ class story extends control { /* Delete related issue in gitlab. */ $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); - $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'story', $storyID, $relation->issueID); + if(!empty($relation)) $this->loadModel('gitlab')->deleteIssue('story', $storyID, $relation->issueID); $this->story->delete(TABLE_STORY, $storyID); if($story->parent > 0) diff --git a/module/task/control.php b/module/task/control.php index d3f5f41f40..f8b75ec28d 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -1282,7 +1282,7 @@ class task extends control { /* Delete related issue in gitlab. */ $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); - $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'task', $taskID, $relation->issueID); + if(!empty($relation)) $this->loadModel('gitlab')->deleteIssue('task', $taskID, $relation->issueID); $this->task->delete(TABLE_TASK, $taskID); if($task->parent > 0) From 3af2cbffbffba828c2e5af90f174158d0d0f5b8b Mon Sep 17 00:00:00 2001 From: lichengjun Date: Thu, 1 Jul 2021 16:39:15 +0800 Subject: [PATCH 204/269] * Misjudgment story issues status; --- module/bug/model.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/module/bug/model.php b/module/bug/model.php index cb54e5fa47..e62af700f8 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -1228,14 +1228,17 @@ class bugModel extends model $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); - $singleIssue = new stdclass(); - $singleIssue = $this->loadModel('gitlab')->apiSingleIssue($relation->gitlabID, $relation->issueID); - $this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec(); - $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('bug',$bugID); - if($objectID) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $objectID->gitlabID, $objectID->projectID); + $singleIssue = new stdclass(); + $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); + if($singleIssue->state != 'closed') + { + $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('bug',$bugID); + if($objectID) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $objectID->gitlabID, $objectID->projectID); + } + return common::createChanges($oldBug, $bug); } From 7015721af5afb92425424661b15e12aa783010fb Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 1 Jul 2021 17:03:34 +0800 Subject: [PATCH 205/269] + Add function for parsing zentao object to issue. --- module/gitlab/model.php | 56 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index e249f48aea..0294ec1668 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -830,13 +830,10 @@ class gitlabModel extends model } $syncedIssue = $this->getSyncedIssue($objectType = $objectType, $objectID = $objectID, $gitlabID); - if($objectType == 'story') $issue = $this->storyToIssue($gitlabID, $projectID, $object); - if($objectType == 'task') $issue = $this->taskToIssue($gitlabID, $projectID, $object); - if($objectType == 'bug') $issue = $this->bugToIssue($gitlabID, $projectID, $object); - + $issue = $this->parseObjectToIssue($gitlabID, $projectID, $object, $objectType); if($syncedIssue) return $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->BID, $issue); - - $label = $this->createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID); + + $label = $this->createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID); $issue->labels = $label->name; $issue = $this->apiCreateIssue($gitlabID, $projectID, $issue); @@ -1022,6 +1019,53 @@ class gitlabModel extends model return $issue; } + /** + * Parse zentao object to issue. object can be task, bug and story. + * + * @param int $gitlabID + * @param int $projectID + * @param object $object + * @param string $objectType + * @access public + * @return object + */ + public function parseObjectToIssue($gitlabID, $projectID, $object, $objectType) + { + $map = $this->config->gitlab->maps->$objectType; + $issue = new stdclass; + $gitlabUsers = $this->getUserAccountIdPairs($gitlabID); + if(empty($gitlabUsers)) return false; + + foreach($map as $objectField => $config) + { + $value = ''; + list($field, $optionType, $options) = explode('|', $config); + if($optionType == 'field') $value = $object->$bugField; + if($optionType == 'fields') $value = $object->$bugField . "\n\n" . $object->$options; + if($optionType == 'userPairs') + { + $value = zget($gitlabUsers, $object->$objectField); + } + if($optionType == 'configItems') + { + $value = zget($this->config->gitlab->$options, $object->$objectField, ''); + } + if($value) $issue->$field = $value; + } + + if($issue->assignee_id == 'closed') unset($issue->assignee_id); + + /* issue->state is null when creating it, we should put status_event when updating it. */ + if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; + if(isset($issue->state) and $issue->state == 'opened') $issue->state_event='reopen'; + + /* Append this object link in zentao to gitlab issue description */ + $zentaoLink = common::getSysURL() . helper::createLink($objectType, 'view', "id={$object->id}"); + $issue->description = $issue->description . "\n\n" . $zentaoLink; + + return $issue; + } + /** * Parse issue to zentao object. * From b8ae511b5bba16e80f1d33e32f1ce132f5f419c3 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 1 Jul 2021 17:12:00 +0800 Subject: [PATCH 206/269] * Transform tab to 4 spaces. --- module/gitlab/model.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 0294ec1668..49d8071f88 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -53,8 +53,8 @@ class gitlabModel extends model * @param int $id * @access public * @return string - */ - public function getApiRoot($id) + */ + public function getApiRoot($id) { $gitlab = $this->getByID($id); if(!$gitlab) return ''; @@ -632,7 +632,7 @@ class gitlabModel extends model */ public function webhookParseNote($body) { - //@todo + //@todo } /** @@ -747,7 +747,7 @@ class gitlabModel extends model public function createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID) { $label = new stdclass; - $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); + $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); $label->color = $this->config->gitlab->zentaoObjectLabel->colors->$objectType; $label->description = common::getSysURL() . helper::createLink($objectType, 'view', "id={$objectID}"); @@ -834,20 +834,20 @@ class gitlabModel extends model if($syncedIssue) return $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->BID, $issue); $label = $this->createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID); - $issue->labels = $label->name; + $issue->labels = $label->name; - $issue = $this->apiCreateIssue($gitlabID, $projectID, $issue); - if($issue) $this->saveSyncedIssue($objectType, $object, $gitlabID, $issue); - } + $issue = $this->apiCreateIssue($gitlabID, $projectID, $issue); + if($issue) $this->saveSyncedIssue($objectType, $object, $gitlabID, $issue); + } - /** - * Delete an issue from zentao and gitlab. - * - * @param int $gitlabID - * @param int $projectID - * @param string $objectType - * @param int $objectID - * @param int $issueID + /** + * Delete an issue from zentao and gitlab. + * + * @param int $gitlabID + * @param int $projectID + * @param string $objectType + * @param int $objectID + * @param int $issueID * @access public * @return void */ @@ -1078,7 +1078,7 @@ class gitlabModel extends model { if(!isset($this->config->gitlab->maps->{$issue->objectType})) return null; - if(isset($changes->assignees)) $changes->assignee_id = true; + if(isset($changes->assignees)) $changes->assignee_id = true; $maps = $this->config->gitlab->maps->{$issue->objectType}; $gitlabUsers = $this->getUserIdAccountPairs($gitlabID); From 7c240783aff4fcaf5d1b2c73a2f0510d25e5a3ea Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 1 Jul 2021 17:14:23 +0800 Subject: [PATCH 207/269] * Remove needless bracket and bug fix for stdclass. --- module/gitlab/config.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index ad49373fb8..5f699712cf 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -1,8 +1,8 @@ gitlab->create = new stdclass(); +$config->gitlab->create = new stdclass; $config->gitlab->create->requiredFields = 'name,url,token'; -$config->gitlab->edit = new stdclass(); +$config->gitlab->edit = new stdclass; $config->gitlab->edit->requiredFields = 'name,url,token'; $config->gitlab->labelPattern = new stdclass; @@ -13,9 +13,10 @@ $config->gitlab->labelPattern->story = '/^zentao_story\/\d+$/'; $config->gitlab->actions = array(); $config->gitlab->actions['issue'] = array(); -$config->gitlab->zentaoObjectLabel = new stdclass(); +$config->gitlab->zentaoObjectLabel = new stdclass; $config->gitlab->zentaoObjectLabel->name = "zentao_%s/%s"; $config->gitlab->zentaoObjectLabel->description = "%s"; +$config->gitlab->zentaoObjectLabel->color = new stdclass; $config->gitlab->zentaoObjectLabel->color->task = '#0033CC'; $config->gitlab->zentaoObjectLabel->color->story = '#69D100'; $config->gitlab->zentaoObjectLabel->color->bug = '#D10069'; From cebe56a593ec0a8ae7c185b8ede1fb816693949c Mon Sep 17 00:00:00 2001 From: lichengjun Date: Thu, 1 Jul 2021 18:34:24 +0800 Subject: [PATCH 208/269] * Fix Replace with getRationByObject. --- module/bug/model.php | 23 ++++++++++++----------- module/gitlab/model.php | 4 ++-- module/story/model.php | 17 ++++++++++++++--- module/task/model.php | 17 ++++++++++++++--- 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/module/bug/model.php b/module/bug/model.php index e62af700f8..df0578d44a 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -647,7 +647,7 @@ class bugModel extends model if(!empty($bug->resolvedBy)) $this->loadModel('score')->create('bug', 'resolve', $bugID); $this->file->updateObjectID($this->post->uid, $bugID, 'bug'); - $relation = $this->loadModel('gitlab')->getRelationByObject('bug',$bugID); + $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); if($relation) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $relation->gitlabID, $relation->projectID); return common::createChanges($oldBug, $bug); @@ -1183,7 +1183,7 @@ class bugModel extends model $this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec(); $this->dao->update(TABLE_BUG)->set('activatedCount = activatedCount + 1')->where('id')->eq((int)$bugID)->exec(); - $relation = $this->loadModel('gitlab')->getGitlabIDprojectID('bug',$bugID); + $relation = $this->loadModel('gitlab')->getRelationByObject('bug',$bugID); if($relation) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $relation->gitlabID, $relation->projectID); $openedBuilds = $this->post->openedBuild; @@ -1226,19 +1226,20 @@ class bugModel extends model ->remove('comment') ->get(); - $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); - $this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec(); - $singleIssue = new stdclass(); - $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); + $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); + if(!empty($relation)) + { + $singleIssue = new stdclass(); + $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); - if($singleIssue->state != 'closed') - { - $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('bug',$bugID); - if($objectID) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $objectID->gitlabID, $objectID->projectID); + if($singleIssue->state != 'closed') + { + $objectID = $this->loadModel('gitlab')->getRelationByObject('bug',$bugID); + if($objectID) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $objectID->gitlabID, $objectID->projectID); + } } - return common::createChanges($oldBug, $bug); } diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 49d8071f88..d895df3e20 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -829,9 +829,9 @@ class gitlabModel extends model $projectID = $result->projectID; } - $syncedIssue = $this->getSyncedIssue($objectType = $objectType, $objectID = $objectID, $gitlabID); + $syncedIssue = $this->getRelationByObject($objectType, $objectID); $issue = $this->parseObjectToIssue($gitlabID, $projectID, $object, $objectType); - if($syncedIssue) return $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->BID, $issue); + if($syncedIssue) return $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->issueID, $issue); $label = $this->createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID); $issue->labels = $label->name; diff --git a/module/story/model.php b/module/story/model.php index 7dc44bb7a8..153d6473db 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -830,7 +830,7 @@ class storyModel extends model $this->dao->insert(TABLE_STORYREVIEW)->data($reviewData)->exec(); } /* update story to gitlab issue. */ - $objectID = $this->loadModel('gitlab')->getGitlabidProjectID('story',$storyID); + $objectID = $this->loadModel('gitlab')->getRelationByObject('story',$storyID); if($objectID) $this->loadModel('gitlab')->pushToIssue('story', $storyID, $objectID->gitlabID, $objectID->projectID); unset($oldStory->parent); @@ -1426,8 +1426,19 @@ class storyModel extends model ->checkIF($story->closedReason == 'duplicate', 'duplicateStory', 'notempty') ->where('id')->eq($storyID)->exec(); - $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('story',$storyID); - if($objectID) $this->loadModel('gitlab')->pushToIssue('story', $storyID, $objectID->gitlabID, $objectID->projectID); + $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); + + if(!empty($relation)) + { + $singleIssue = new stdclass(); + $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); + + if($singleIssue->state != 'closed') + { + $objectID = $this->loadModel('gitlab')->getRelationByObject('story',$storyID); + if($objectID) $this->loadModel('gitlab')->pushToIssue('story', $storyID, $objectID->gitlabID, $objectID->projectID); + } + } /* Update parent story status. */ if($oldStory->parent > 0) $this->updateParentStatus($storyID, $oldStory->parent); diff --git a/module/task/model.php b/module/task/model.php index 649e41c6d0..ddf4aea17e 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -942,7 +942,7 @@ class taskModel extends model ->where('id')->eq((int)$taskID)->exec(); /* update story to gitlab issue. */ - $objectID = $this->loadModel('gitlab')->getGitlabidProjectID('task',$taskID); + $objectID = $this->loadModel('gitlab')->getRelationByObject('task',$taskID); if($objectID) $this->loadModel('gitlab')->pushToIssue('task', $taskID, $objectID->gitlabID, $objectID->projectID); if(!dao::isError()) @@ -1733,8 +1733,19 @@ class taskModel extends model $this->dao->update(TABLE_TASK)->data($task)->autoCheck()->where('id')->eq((int)$taskID)->exec(); - $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('task',$taskID); - if($objectID) $this->loadModel('gitlab')->pushToissue('task', $taskID, $objectID->gitlabID, $objectID->projectID); + $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); + + if(!empty($relation)) + { + $singleIssue = new stdclass(); + $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); + + if($singleIssue->state != 'closed') + { + $objectID = $this->loadModel('gitlab')->getRelationByObject('task',$taskID); + if($objectID) $this->loadModel('gitlab')->pushToIssue('task', $taskID, $objectID->gitlabID, $objectID->projectID); + } + } if(!dao::isError()) { From 7b52b61439cfa9c179380c3d05f51da3864db0fc Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 1 Jul 2021 21:15:31 +0800 Subject: [PATCH 209/269] * Optimize function parseObjectToIssue. --- module/gitlab/model.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index d895df3e20..26b568df36 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -1031,17 +1031,17 @@ class gitlabModel extends model */ public function parseObjectToIssue($gitlabID, $projectID, $object, $objectType) { - $map = $this->config->gitlab->maps->$objectType; - $issue = new stdclass; $gitlabUsers = $this->getUserAccountIdPairs($gitlabID); if(empty($gitlabUsers)) return false; + $issue = new stdclass; + $map = $this->config->gitlab->maps->$objectType; foreach($map as $objectField => $config) { $value = ''; list($field, $optionType, $options) = explode('|', $config); - if($optionType == 'field') $value = $object->$bugField; - if($optionType == 'fields') $value = $object->$bugField . "\n\n" . $object->$options; + if($optionType == 'field') $value = $object->$objectField; + if($optionType == 'fields') $value = $object->$objectField . "\n\n" . $object->$options; if($optionType == 'userPairs') { $value = zget($gitlabUsers, $object->$objectField); From a951e67f59ff2de695b763e220358f123f6a2acf Mon Sep 17 00:00:00 2001 From: lichengjun Date: Fri, 2 Jul 2021 11:04:50 +0800 Subject: [PATCH 210/269] * Fix issues bugs. --- module/gitlab/config.php | 3 ++- module/gitlab/model.php | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 5f699712cf..1528859692 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -16,7 +16,8 @@ $config->gitlab->actions['issue'] = array(); $config->gitlab->zentaoObjectLabel = new stdclass; $config->gitlab->zentaoObjectLabel->name = "zentao_%s/%s"; $config->gitlab->zentaoObjectLabel->description = "%s"; -$config->gitlab->zentaoObjectLabel->color = new stdclass; + +$config->gitlab->zentaoObjectLabel->color = new stdclass; $config->gitlab->zentaoObjectLabel->color->task = '#0033CC'; $config->gitlab->zentaoObjectLabel->color->story = '#69D100'; $config->gitlab->zentaoObjectLabel->color->bug = '#D10069'; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 26b568df36..3e051e58ad 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -748,7 +748,7 @@ class gitlabModel extends model { $label = new stdclass; $label->name = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); - $label->color = $this->config->gitlab->zentaoObjectLabel->colors->$objectType; + $label->color = $this->config->gitlab->zentaoObjectLabel->color->$objectType; $label->description = common::getSysURL() . helper::createLink($objectType, 'view', "id={$objectID}"); return $this->apiCreateLabel($gitlabID, $projectID, $label); @@ -834,7 +834,7 @@ class gitlabModel extends model if($syncedIssue) return $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->issueID, $issue); $label = $this->createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID); - $issue->labels = $label->name; + $issue->labels = isset($label->name) ? $label->name : ''; $issue = $this->apiCreateIssue($gitlabID, $projectID, $issue); if($issue) $this->saveSyncedIssue($objectType, $object, $gitlabID, $issue); @@ -914,7 +914,7 @@ class gitlabModel extends model if($value) $issue->$field = $value; } - if($issue->assignee_id == 'closed') unset($issue->assignee_id); + if($isset($issue->assignee_id) and $issue->assignee_id == 'closed') unset($issue->assignee_id); /* issue->state is null when creating it, we should put status_event when updating it. */ if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; @@ -1053,7 +1053,7 @@ class gitlabModel extends model if($value) $issue->$field = $value; } - if($issue->assignee_id == 'closed') unset($issue->assignee_id); + if(isset($issue->assignee_id) and $issue->assignee_id == 'closed') unset($issue->assignee_id); /* issue->state is null when creating it, we should put status_event when updating it. */ if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; From 745957f6e3bcfb22a1eb03e59a529e99d37fe4f8 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Fri, 2 Jul 2021 14:19:17 +0800 Subject: [PATCH 211/269] * Fix gitlab to issues bug. --- module/gitlab/model.php | 2 +- module/story/model.php | 1 - module/task/model.php | 6 +++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 3e051e58ad..8d9d9b7b48 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -834,7 +834,7 @@ class gitlabModel extends model if($syncedIssue) return $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->issueID, $issue); $label = $this->createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID); - $issue->labels = isset($label->name) ? $label->name : ''; + $issue->labels = isset($label->name) ? '' :$label->name; $issue = $this->apiCreateIssue($gitlabID, $projectID, $issue); if($issue) $this->saveSyncedIssue($objectType, $object, $gitlabID, $issue); diff --git a/module/story/model.php b/module/story/model.php index 153d6473db..dc9b65c26f 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -441,7 +441,6 @@ class storyModel extends model dao::$errors['message'][] = sprintf($this->lang->error->notempty, $this->lang->story->$field); return false; } - $data[$i] = $story; } diff --git a/module/task/model.php b/module/task/model.php index ddf4aea17e..ae519d1816 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -380,6 +380,10 @@ class taskModel extends model if(dao::isError()) return false; $taskID = $this->dao->lastInsertID(); + + /* Sync this task to gitlab issue. */ + $this->loadModel('gitlab')->pushToIssue('task', $taskID, $this->post->gitlab, $this->post->gitlabProject); + $taskSpec = new stdClass(); $taskSpec->task = $taskID; $taskSpec->version = $task->version; @@ -1791,7 +1795,7 @@ class taskModel extends model } if($oldTask->story) $this->loadModel('story')->setStage($oldTask->story); - $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('task',$taskID); + $objectID = $this->loadModel('gitlab')->getRelationByObject('task',$taskID); if($objectID) $this->loadModel('gitlab')->pushToissue('task', $taskID, $objectID->gitlabID, $objectID->projectID); if(!dao::isError()) return common::createChanges($oldTask, $task); From a4f4cfd8a9416c3a167495728d9d97f7b1d420bf Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Fri, 2 Jul 2021 17:16:56 +0800 Subject: [PATCH 212/269] * Rename gitlabModel::createWebhook to initWebhooks. --- module/gitlab/model.php | 11 +++-------- module/repo/model.php | 4 ++-- module/upgrade/model.php | 26 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 0294ec1668..21d832df8b 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -794,7 +794,7 @@ class gitlabModel extends model * @access public * @return bool */ - public function createWebhook($products, $gitlabID, $projectID) + public function initWebhooks($products, $gitlabID, $projectID) { $gitlab = $this->getByID($gitlabID); $webhooks = $this->apiGetHooks($gitlabID, $projectID); @@ -822,14 +822,9 @@ class gitlabModel extends model { $object = $this->loadModel($objectType)->getByID($objectID); if(empty($object)) return false; - if(!$gitlabID or !$projectID) - { - $result = $this->getRelationByObject($objectType, $objectID); - $gitlabID = $result->gitlabID; - $projectID = $result->projectID; - } + if(!$gitlabID or !$projectID) return false; - $syncedIssue = $this->getSyncedIssue($objectType = $objectType, $objectID = $objectID, $gitlabID); + $syncedIssue = $this->getRelationByObject($objectType, $objectID); $issue = $this->parseObjectToIssue($gitlabID, $projectID, $object, $objectType); if($syncedIssue) return $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->BID, $issue); diff --git a/module/repo/model.php b/module/repo/model.php index 463dc12510..bccba49194 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -235,7 +235,7 @@ class repoModel extends model $this->loadModel("gitlab")->saveProjectRelation($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); /* create webhook for zentao */ - $this->loadModel("gitlab")->createWebhook($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); + $this->loadModel("gitlab")->initWebhooks($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); } return $this->dao->lastInsertID(); } @@ -298,7 +298,7 @@ class repoModel extends model { $this->dao->delete()->from(TABLE_REPOHISTORY)->where('repo')->eq($id)->exec(); $this->dao->delete()->from(TABLE_REPOFILES)->where('repo')->eq($id)->exec(); - if($repo->SCM == 'Gitlab') $this->loadModel("gitlab")->createWebhook($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); + if($repo->SCM == 'Gitlab') $this->loadModel("gitlab")->initWebhooks($this->post->product, $this->post->gitlabHost, $this->post->gitlabProject); return false; } diff --git a/module/upgrade/model.php b/module/upgrade/model.php index 53b185d58a..7dd700b77c 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -4991,4 +4991,30 @@ class upgradeModel extends model $this->dao->update(TABLE_PRODUCT)->set('createdVersion')->eq($this->config->version)->where('createdVersion')->eq('')->exec(); return true; } + + public function processGitlabRepo() + { + $repoList = $this->dao->select('*')->from(TABLE_REPO)->where('SCM')->eq('Gitlab')->fetchAll(); + foreach($repoList as $repo) + { + /* Create gitlab from repo. */ + $gitlab = new stdclass; + $gitlab->type = 'gitlab'; + $gitlab->name = $repo->client; + $gitlab->token = base64_decode($repo->password); + $gitlab->private = md5(uniqid()); + $this->dao->insert(TABLE_PIPELINE)->data($gitlab)->exec(); + + $gitlabID = $this->dao->lastInsertID(); + + preg_match('/projects\/(\d+)\/repository/', $repo->path, $matches); + $gitlabProject = $matches[1]; + $products = explode(',', $repo->product); + $this->loadModel('gitlab')->saveProjectRelation($products, $gitlabID, $gitlabProject); + + $this->dao->update(TABLE_REPO)->set('client')->eq($gitlabID)->set('path')->eq($gitlabProject)->where('id')->eq($repo->id)->exec(); + + $this->loadModel("gitlab")->initWebhooks($products, $gitlabID, $gitlabProject); + } + } } From 7d31a09810b9c6e46fd2c78ff0591ac72a915f07 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 2 Jul 2021 17:21:40 +0800 Subject: [PATCH 213/269] * commit unfinished job for task #38934. --- config/filter.php | 6 +++ module/gitlab/config.php | 2 + module/gitlab/control.php | 42 ++++++++------- module/gitlab/js/mapissue.js | 19 +++++++ module/gitlab/lang/zh-cn.php | 7 ++- module/gitlab/model.php | 24 ++++++++- module/gitlab/view/importissue.html.php | 52 +++++++++++++++++++ module/gitlab/view/transferissue.html.php | 63 ----------------------- module/repo/view/maintain.html.php | 1 + 9 files changed, 131 insertions(+), 85 deletions(-) create mode 100644 module/gitlab/js/mapissue.js create mode 100644 module/gitlab/view/importissue.html.php delete mode 100644 module/gitlab/view/transferissue.html.php diff --git a/config/filter.php b/config/filter.php index 680245f08b..a4125b9da5 100644 --- a/config/filter.php +++ b/config/filter.php @@ -132,6 +132,7 @@ $filter->user->ajaxgetmore = new stdclass(); $filter->repo->ajaxsynccommit = new stdclass(); $filter->search->index = new stdclass(); $filter->gitlab->webhook = new stdclass(); +$filter->gitlab->importissue = new stdclass(); $filter->bug->batchcreate->cookie['preBranch'] = 'int'; $filter->bug->browse->cookie['bugModule'] = 'int'; @@ -315,3 +316,8 @@ $filter->gitlab->webhook->get['gitlab'] = 'int'; $filter->gitlab->webhook->get['product'] = 'int'; $filter->gitlab->webhook->get['project'] = 'int'; $filter->gitlab->webhook->get['token'] = 'reg::any'; + +$filter->gitlab->importissue->get['gitlab'] = 'int'; +$filter->gitlab->importissue->get['product'] = 'int'; +$filter->gitlab->importissue->get['project'] = 'int'; + diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 5f699712cf..d4dfc228f9 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -96,3 +96,5 @@ $config->gitlab->objectTables->story = TABLE_STORY; $config->gitlab->objectTables->task = TABLE_TASK; $config->gitlab->objectTables->bug = TABLE_BUG; +$config->gitlab->objectTypes = array('', 'task', 'bug', 'story'); + diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 7de7b907d2..4ef8d58d8a 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -251,28 +251,32 @@ class gitlab extends control exit; } - public function transferIssue() + public function importIssue() { - //TODO(dingguodong) todo next. - if(!empty($this->post)) + if($_POST) { - $project; - $product; - $execution; - $objetcType; - $gitlab; - $gitlabProject; - $gitlabIssue; + $this->post->a(); } - - $this->view->programs = array('') + $this->loadModel('program')->getTopPairs('', 'noclosed'); - - $this->view->products = '$projects'; - $this->view->execution = '$projects'; - $this->view->objectTypes = '$projects'; - $this->view->gitlabs = '$projects'; - $this->view->gitlabProjects = '$projects'; - $this->view->gitlabIssues = '$projects'; + + $productID = $this->get->product; + $gitlabID = $this->get->gitlab; + $projectID = $this->get->project; + $relations = $this->gitlab->getExecutionsByProduct($productID); + + $executions = array(); + foreach($relations as $relation) + { + if($relation->execution) $executions[] = $this->loadModel("execution")->getByID($relation->execution)->name; + } + + $this->view->productName = $this->loadModel("product")->getByID($productID)->name; + $this->view->productID = $productID; + $this->view->gitlabID = $gitlabID; + $this->view->gitlabProjectID = $projectID; + $this->view->executions = $executions; + $this->view->objectTypes = $this->config->gitlab->objectTypes; + + $this->view->gitlabIssues = $this->gitlab->apiGetIssues($gitlabID, $projectID); $this->display(); } } diff --git a/module/gitlab/js/mapissue.js b/module/gitlab/js/mapissue.js new file mode 100644 index 0000000000..a8be522002 --- /dev/null +++ b/module/gitlab/js/mapissue.js @@ -0,0 +1,19 @@ +$(document).ready(function() +{ + $('[name^=gitlabID').change(function() + { + var gitlab = $(this); + host = gitlab.val(); + if(host == '') return false; + projects = ''; + url = createLink('repo', 'ajaxgetgitlabprojects', "host=" + host); + + $.get(url, function(response) + { + project = gitlab.parent().next().find('select'); + project.html('').append(response); + project.chosen().trigger("chosen:updated"); + }); + + }); +}); diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index 24226ad028..abe00b1b5e 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -6,6 +6,7 @@ $lang->gitlab->create = '添加gitlab'; $lang->gitlab->edit = '编辑gitlab'; $lang->gitlab->bindUser = '绑定用户'; $lang->gitlab->bindProduct = '关联产品'; +$lang->gitlab->importIssue = '关联议题'; $lang->gitlab->delete = '删除'; $lang->gitlab->confirmDelete = '确认删除该gitlab吗?'; $lang->gitlab->gitlabAccount = 'gitlab用户'; @@ -13,11 +14,13 @@ $lang->gitlab->zentaoAccount = '禅道用户'; $lang->gitlab->browseAction = 'gitlab列表'; $lang->gitlab->deleteAction = '删除gitlab'; -$lang->gitlab->gitlabProject = 'gitlab项目'; +$lang->gitlab->gitlabProject = "{$lang->gitlab->common}项目"; +$lang->gitlab->gitlabIssue = "{$lang->gitlab->common}议题"; $lang->gitlab->zentaoProduct = '禅道产品'; +$lang->gitlab->objectType = '类型'; // task, bug, story $lang->gitlab->id = 'ID'; -$lang->gitlab->name = '名称'; +$lang->gitlab->name = "{$lang->gitlab->common}名称"; $lang->gitlab->url = '服务地址'; $lang->gitlab->token = 'Token'; $lang->gitlab->defaultProject = '默认项目'; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 26b568df36..0d1e7f9ccc 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -198,7 +198,24 @@ class gitlabModel extends model ->andWhere('product')->eq($productID) ->fetchGroup('AID'); } - + + /** + * Get executions by one product for gitlab module. + * + * @param int $productID + * @access public + * @return array + */ + public function getExecutionsByProduct($productID) + { + return $this->dao->select('distinct execution')->from(TABLE_RELATION) + ->where('relation')->eq('interrated') + ->andWhere('AType')->eq('gitlab') + ->andWhere('BType')->eq('gitlabProject') + ->andWhere('product')->eq($productID) + ->fetchAll('execution'); + } + /** * Get gitlabID and projectID. * @@ -326,6 +343,11 @@ class gitlabModel extends model return $allResults; } + public function apiGetIssues($gitlabID, $projectID) + { + + } + /** * Get hooks. * diff --git a/module/gitlab/view/importissue.html.php b/module/gitlab/view/importissue.html.php new file mode 100644 index 0000000000..16b8879841 --- /dev/null +++ b/module/gitlab/view/importissue.html.php @@ -0,0 +1,52 @@ + + * @package story + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +
+
+

gitlab->importIssue;?>

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
product->common;?>execution->common;?>gitlab->gitlabIssue;?>gitlab->objectType;?>
+ save);?> + +
+
+
+
+ diff --git a/module/gitlab/view/transferissue.html.php b/module/gitlab/view/transferissue.html.php deleted file mode 100644 index 90e157f3cd..0000000000 --- a/module/gitlab/view/transferissue.html.php +++ /dev/null @@ -1,63 +0,0 @@ - - * @package story - * @version $Id$ - * @link http://www.zentao.net - */ -?> - -
-
-

gitlab->transferIssue;?>

-
-
-
- - - - - - - - - - zentaoAccount)) continue;?> - - - - - - - - zentaoAccount)) continue;?> - - - - - - - - - - - - -
gitlab->gitlabAccount;?>gitlab->zentaoAccount;?>
avatar, "height=40");?> - realname;?> -
account . " <" . $gitlabUser->email . ">"; ?> -
id]", $userPairs, '', "class='form-control select chosen'" );?>
avatar, "height=40");?> - realname;?> -
account . " <" . $gitlabUser->email . ">";?> -
id]", $userPairs, $gitlabUser->zentaoAccount, "class='form-control select chosen'" );?>
- save);?> - -
-
-
-
- diff --git a/module/repo/view/maintain.html.php b/module/repo/view/maintain.html.php index e7a0e9391d..2c2da5b64a 100644 --- a/module/repo/view/maintain.html.php +++ b/module/repo/view/maintain.html.php @@ -49,6 +49,7 @@ id&objectID=$objectID", '', 'list', 'edit'); + common::printIcon('gitlab', 'importissue', "product={$repo->product}&gitlab={$repo->gitlab}&project={$repo->project}", '', 'list', 'link'); if(common::hasPriv('repo', 'delete')) echo html::a($this->createLink('repo', 'delete', "repoID=$repo->id&objectID=$objectID"), '', 'hiddenwin', "title='{$lang->repo->delete}' class='btn'"); ?> From 82f854f3f101e865a3448e5b38ba866cac0438d2 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 2 Jul 2021 17:32:24 +0800 Subject: [PATCH 214/269] - Remove unneeded function. --- module/gitlab/control.php | 2 +- module/gitlab/model.php | 17 ----------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 4ef8d58d8a..213828f266 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -261,7 +261,7 @@ class gitlab extends control $productID = $this->get->product; $gitlabID = $this->get->gitlab; $projectID = $this->get->project; - $relations = $this->gitlab->getExecutionsByProduct($productID); + // todo next: get execution from product and execution module. $executions = array(); foreach($relations as $relation) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index f55fcb0c37..74c4bcb7a7 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -182,23 +182,6 @@ class gitlabModel extends model ->fetchGroup('AID'); } - /** - * Get gitlab projects of one Product. - * - * @param int $productID - * @access public - * @return array - */ - public function getProjectsByProduct($productID) - { - return $this->dao->select('AID, BID as gitlabProject')->from(TABLE_RELATION) - ->where('relation')->eq('interrated') - ->andWhere('AType')->eq('gitlab') - ->andWhere('BType')->eq('gitlabProject') - ->andWhere('product')->eq($productID) - ->fetchGroup('AID'); - } - /** * Get executions by one product for gitlab module. * From 4485dbe009ba0f4c05bd4d5fc043f8dc5c0e66f3 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 2 Jul 2021 17:36:18 +0800 Subject: [PATCH 215/269] + Create apiGetIssues function. --- module/gitlab/model.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 74c4bcb7a7..ca76597396 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -326,11 +326,6 @@ class gitlabModel extends model return $allResults; } - public function apiGetIssues($gitlabID, $projectID) - { - - } - /** * Get hooks. * @@ -515,6 +510,13 @@ class gitlabModel extends model return json_decode(commonModel::http($url)); } + public function apiGetIssues($gitlabID, $projectID) + { + // TODO(dingguodong) not pagination yet. + $url = sprintf($this->getApiRoot($gitlabID), "/projects/{$projectID}/issues/{$issueID}"); + return json_decode(commonModel::http($url)); + } + /** * Create issue by api. * From c64b3580c888835fba7b34e14f24b9704e5f1a36 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Sat, 3 Jul 2021 09:58:23 +0800 Subject: [PATCH 216/269] * Fix bug,task,story code format. --- module/bug/control.php | 2 -- module/bug/model.php | 40 +++++++++++++++++++------- module/gitlab/model.php | 49 +++++++------------------------- module/story/model.php | 38 ++++++++++++++++++------- module/task/model.php | 63 ++++++++++++++++++++++++++++++++--------- 5 files changed, 116 insertions(+), 76 deletions(-) diff --git a/module/bug/control.php b/module/bug/control.php index fc7f8a98b1..834205c6e4 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -1249,8 +1249,6 @@ class bug extends control $this->executeHooks($bugID); - $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $this->post->gitlab, $this->post->gitlabProject); - if($bug->toTask != 0) { /* If task is not finished, update it's status. */ diff --git a/module/bug/model.php b/module/bug/model.php index df0578d44a..eb26511faf 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -89,9 +89,10 @@ class bugModel extends model { $bugID = $this->dao->lastInsertID(); - /* Sync this bug to gitlab issue. */ - $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $this->post->gitlab, $this->post->gitlabProject); - + $object = $this->getByID($bugID); + $issue = $this->loadModel('gitlab')->parseObjectToIssue($this->post->gitlab, $this->post->gitlabProject, 'bug', $object); + $this->loadModel('gitlab')->apiCreateIssue($this->post->gitlab, $this->post->gitlabProject, $issue, 'bug', $bugID, $object); + $this->file->updateObjectID($this->post->uid, $bugID, 'bug'); $this->file->saveUpload('bug', $bugID); empty($bug->case) ? $this->loadModel('score')->create('bug', 'create', $bugID) : $this->loadModel('score')->create('bug', 'createFormCase', $bug->case); @@ -647,9 +648,16 @@ class bugModel extends model if(!empty($bug->resolvedBy)) $this->loadModel('score')->create('bug', 'resolve', $bugID); $this->file->updateObjectID($this->post->uid, $bugID, 'bug'); - $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); - if($relation) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $relation->gitlabID, $relation->projectID); + $object = $this->getByID($bugID); + if(!empty($object)) + { + + $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); + $issue = $this->parseObjectToIssue($relation->gitlabID, $relation->projectID, $object, 'bug'); + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $issueID, 'bug', $object); + + } return common::createChanges($oldBug, $bug); } } @@ -861,8 +869,9 @@ class bugModel extends model $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $bug->assignedTo); if($attribute->assignee_id != '') { + $attribute = $this->getByID($bugID); // TODO(dingguodong) we should alert to operator when can not find the user, and the operator should reconfigure user binding. - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID , $attribute); + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $attribute); } if(!dao::isError()) return common::createChanges($oldBug, $bug); @@ -1010,6 +1019,17 @@ class bugModel extends model /* Link bug to build and release. */ $this->linkBugToBuild($bugID, $bug->resolvedBuild); + $object = $this->getByID($bugID); + + if(!empty($object)) + { + $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); + if($relation) + { + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $object); + } + + } return common::createChanges($oldBug, $bug); } @@ -1183,9 +1203,6 @@ class bugModel extends model $this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec(); $this->dao->update(TABLE_BUG)->set('activatedCount = activatedCount + 1')->where('id')->eq((int)$bugID)->exec(); - $relation = $this->loadModel('gitlab')->getRelationByObject('bug',$bugID); - if($relation) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $relation->gitlabID, $relation->projectID); - $openedBuilds = $this->post->openedBuild; if($openedBuilds) { @@ -1228,6 +1245,8 @@ class bugModel extends model $this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec(); + $object = $this->getByID($bugID); + $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); if(!empty($relation)) { @@ -1236,8 +1255,7 @@ class bugModel extends model if($singleIssue->state != 'closed') { - $objectID = $this->loadModel('gitlab')->getRelationByObject('bug',$bugID); - if($objectID) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $objectID->gitlabID, $objectID->projectID); + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $object); } } return common::createChanges($oldBug, $bug); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 8d9d9b7b48..45fc1bfbc0 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -519,8 +519,11 @@ class gitlabModel extends model * @access public * @return object */ - public function apiCreateIssue($gitlabID, $projectID, $issue) + public function apiCreateIssue($gitlabID, $projectID, $issue, $objectType, $objectID, $object) { + $label = $this->createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID); + $issue->labels = isset($label->name) ? $label->name : ''; + foreach($this->config->gitlab->skippedFields->issueCreate as $field) { if(isset($issue->$field)) unset($issue->$field); @@ -529,7 +532,8 @@ class gitlabModel extends model $apiRoot = $this->getApiRoot($gitlabID); $url = sprintf($apiRoot, "/projects/{$projectID}/issues/"); - return json_decode(commonModel::http($url, $issue)); + $response = json_decode(commonModel::http($url, $issue)); + $this->saveSyncedIssue($objectType, $object, $gitlabID, $response); } /** @@ -542,8 +546,9 @@ class gitlabModel extends model * @access public * @return object */ - public function apiUpdateIssue($gitlabID, $projectID, $issueID, $attribute) + public function apiUpdateIssue($gitlabID, $projectID, $issueID, $objectType, $object) { + $attribute = $this->parseObjectToIssue($gitlabID, $projectID, $objectType, $object); $apiRoot = $this->getApiRoot($gitlabID); $url = sprintf($apiRoot, "/projects/{$projectID}/issues/{$issueID}"); return json_decode(commonModel::http($url, $attribute, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); @@ -808,38 +813,6 @@ class gitlabModel extends model return true; } - /** - * Push to gitlab issue. - * - * @param string $objectType - * @param int $objectID - * @param int $gitlabID - * @param int $projectID - * @access public - * @return void - */ - public function pushToIssue($objectType, $objectID, $gitlabID, $projectID) - { - $object = $this->loadModel($objectType)->getByID($objectID); - if(empty($object)) return false; - if(!$gitlabID or !$projectID) - { - $result = $this->getRelationByObject($objectType, $objectID); - $gitlabID = $result->gitlabID; - $projectID = $result->projectID; - } - - $syncedIssue = $this->getRelationByObject($objectType, $objectID); - $issue = $this->parseObjectToIssue($gitlabID, $projectID, $object, $objectType); - if($syncedIssue) return $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->issueID, $issue); - - $label = $this->createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID); - $issue->labels = isset($label->name) ? '' :$label->name; - - $issue = $this->apiCreateIssue($gitlabID, $projectID, $issue); - if($issue) $this->saveSyncedIssue($objectType, $object, $gitlabID, $issue); - } - /** * Delete an issue from zentao and gitlab. * @@ -1029,11 +1002,10 @@ class gitlabModel extends model * @access public * @return object */ - public function parseObjectToIssue($gitlabID, $projectID, $object, $objectType) + public function parseObjectToIssue($gitlabID, $projectID, $objectType, $object) { $gitlabUsers = $this->getUserAccountIdPairs($gitlabID); if(empty($gitlabUsers)) return false; - $issue = new stdclass; $map = $this->config->gitlab->maps->$objectType; foreach($map as $objectField => $config) @@ -1052,7 +1024,6 @@ class gitlabModel extends model } if($value) $issue->$field = $value; } - if(isset($issue->assignee_id) and $issue->assignee_id == 'closed') unset($issue->assignee_id); /* issue->state is null when creating it, we should put status_event when updating it. */ @@ -1062,7 +1033,7 @@ class gitlabModel extends model /* Append this object link in zentao to gitlab issue description */ $zentaoLink = common::getSysURL() . helper::createLink($objectType, 'view', "id={$object->id}"); $issue->description = $issue->description . "\n\n" . $zentaoLink; - + return $issue; } diff --git a/module/story/model.php b/module/story/model.php index dc9b65c26f..cd371d2727 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -340,8 +340,10 @@ class storyModel extends model if($from && is_callable(array($this, $this->config->story->fromObjects[$from]['callback']))) call_user_func(array($this, $this->config->story->fromObjects[$from]['callback']), $storyID); /* push this story to gitlab issue */ - $this->loadModel('gitlab')->pushToIssue('story', $storyID, $this->post->gitlab, $this->post->gitlabProject); - + $object = $this->getByID($storyID); + $issue = $this->loadModel('gitlab')->parseObjectToIssue($this->post->gitlab, $this->post->gitlabProject, 'story', $object); + $this->loadModel('gitlab')->apiCreateIssue($this->post->gitlab, $this->post->gitlabProject, $issue, 'story', $storyID, $object); + return array('status' => 'created', 'id' => $storyID); } return false; @@ -829,8 +831,16 @@ class storyModel extends model $this->dao->insert(TABLE_STORYREVIEW)->data($reviewData)->exec(); } /* update story to gitlab issue. */ - $objectID = $this->loadModel('gitlab')->getRelationByObject('story',$storyID); - if($objectID) $this->loadModel('gitlab')->pushToIssue('story', $storyID, $objectID->gitlabID, $objectID->projectID); + $object = $this->getByID($storyID); + + if(!empty($object)) + { + $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); + if($relation) + { + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); + } + } unset($oldStory->parent); unset($story->parent); @@ -1434,10 +1444,11 @@ class storyModel extends model if($singleIssue->state != 'closed') { - $objectID = $this->loadModel('gitlab')->getRelationByObject('story',$storyID); - if($objectID) $this->loadModel('gitlab')->pushToIssue('story', $storyID, $objectID->gitlabID, $objectID->projectID); + $object = $this->getByID($storyID); + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); } } + /* Update parent story status. */ if($oldStory->parent > 0) $this->updateParentStatus($storyID, $oldStory->parent); @@ -1787,8 +1798,9 @@ class storyModel extends model $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $story->assignedTo); if($attribute->assignee_id != '') { + $object = $this->getByID($storyID); // TODO(dingguodong) we should alert to operator when can not find the user, and the operator should reconfigure user binding. - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID , $attribute); + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story' $attribute); } return common::createChanges($oldStory, $story); } @@ -1823,9 +1835,15 @@ class storyModel extends model if(!dao::isError()) { /* Push this story to gitlab issue. */ - $this->loadModel('gitlab')->pushToIssue('story', $storyID, $this->post->gitlab, $this->post->gitlabProject); - - $allChanges[$storyID] = common::createChanges($oldStory, $story); + $object = $this->getByID($storyID); + if(!empty($object)) + { + $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); + if($relation) + { + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); + } + } } } return $allChanges; diff --git a/module/task/model.php b/module/task/model.php index ae519d1816..78512624d1 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -122,8 +122,11 @@ class taskModel extends model $taskID = $this->dao->lastInsertID(); /* Sync this task to gitlab issue. */ - $this->loadModel('gitlab')->pushToIssue('task', $taskID, $this->post->gitlab, $this->post->gitlabProject); - + + $object = $this->getByID($taskID); + $issue = $this->loadModel('gitlab')->parseObjectToIssue($this->post->gitlab, $this->post->gitlabProject, 'task', $object); + $this->loadModel('gitlab')->apiCreateIssue($this->post->gitlab, $this->post->gitlabProject, $issue, 'task', $taskID, $object); + /* Mark design version.*/ if(isset($task->design) && !empty($task->design)) { @@ -382,7 +385,9 @@ class taskModel extends model $taskID = $this->dao->lastInsertID(); /* Sync this task to gitlab issue. */ - $this->loadModel('gitlab')->pushToIssue('task', $taskID, $this->post->gitlab, $this->post->gitlabProject); + $object = $this->getByID($taskID); + $issue = $this->loadModel('gitlab')->parseObjectToIssue($this->post->gitlab, $this->post->gitlabProject, 'task', $object); + $this->loadModel('gitlab')->apiCreateIssue($this->post->gitlab, $this->post->gitlabProject, $issue, 'task', $taskID, $object); $taskSpec = new stdClass(); $taskSpec->task = $taskID; @@ -946,9 +951,19 @@ class taskModel extends model ->where('id')->eq((int)$taskID)->exec(); /* update story to gitlab issue. */ - $objectID = $this->loadModel('gitlab')->getRelationByObject('task',$taskID); - if($objectID) $this->loadModel('gitlab')->pushToIssue('task', $taskID, $objectID->gitlabID, $objectID->projectID); - + $object = $this->getByID($taskID); + + if(!empty($object)) + { + $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); + if($relation) + { + $object = $this->getByID($taskID); + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $object); + } + + } + if(!dao::isError()) { /* Mark design version.*/ @@ -1339,8 +1354,9 @@ class taskModel extends model $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $task->assignedTo); if($attribute->assignee_id != '') { + $attribute = $this->getByID($taskID); // TODO(dingguodong) we should alert to operator when can not find the user, and the operator should reconfigure user binding. - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID , $attribute); + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, $attribute); } if(!dao::isError()) return common::createChanges($oldTask, $task); @@ -1678,8 +1694,18 @@ class taskModel extends model ->where('id')->eq((int)$taskID) ->exec(); - $objectID = $this->loadModel('gitlab')->getRelationByObject('task',$taskID); - if($objectID) $this->loadModel('gitlab')->pushToissue('task', $taskID, $objectID->gitlabID, $objectID->projectID); + $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); + if(!empty($relation)) + { + $singleIssue = new stdclass(); + $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); + + if($singleIssue->state != 'closed') + { + $object = $this->getByID($taskID); + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $object); + } + } if($oldTask->parent > 0) $this->updateParentStatus($taskID); if($oldTask->story) $this->loadModel('story')->setStage($oldTask->story); @@ -1738,7 +1764,6 @@ class taskModel extends model $this->dao->update(TABLE_TASK)->data($task)->autoCheck()->where('id')->eq((int)$taskID)->exec(); $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); - if(!empty($relation)) { $singleIssue = new stdclass(); @@ -1746,8 +1771,8 @@ class taskModel extends model if($singleIssue->state != 'closed') { - $objectID = $this->loadModel('gitlab')->getRelationByObject('task',$taskID); - if($objectID) $this->loadModel('gitlab')->pushToIssue('task', $taskID, $objectID->gitlabID, $objectID->projectID); + $object = $this->getByID($bugID); + if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $object); } } @@ -1795,8 +1820,18 @@ class taskModel extends model } if($oldTask->story) $this->loadModel('story')->setStage($oldTask->story); - $objectID = $this->loadModel('gitlab')->getRelationByObject('task',$taskID); - if($objectID) $this->loadModel('gitlab')->pushToissue('task', $taskID, $objectID->gitlabID, $objectID->projectID); + $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); + if(!empty($relation)) + { + $singleIssue = new stdclass(); + $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); + + if($singleIssue->state != 'closed') + { + $object = $this->getByID($taskID); + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $object); + } + } if(!dao::isError()) return common::createChanges($oldTask, $task); } From 1c5aed2d76b02e62a829580d0b2b3e0849313491 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Sat, 3 Jul 2021 10:25:58 +0800 Subject: [PATCH 217/269] * Fix bug,story,task code format. --- module/bug/model.php | 5 ++--- module/story/model.php | 12 +++++------- module/task/model.php | 12 +++++------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/module/bug/model.php b/module/bug/model.php index eb26511faf..6d44b10346 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -865,11 +865,10 @@ class bugModel extends model ->where('id')->eq($bugID)->exec(); $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); - $attribute = new stdclass(); + $attribute = $this->getByID($bugID); $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $bug->assignedTo); if($attribute->assignee_id != '') { - $attribute = $this->getByID($bugID); // TODO(dingguodong) we should alert to operator when can not find the user, and the operator should reconfigure user binding. $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $attribute); } @@ -1255,7 +1254,7 @@ class bugModel extends model if($singleIssue->state != 'closed') { - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $object); + if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $object); } } return common::createChanges($oldBug, $bug); diff --git a/module/story/model.php b/module/story/model.php index cd371d2727..74b94499f3 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -838,7 +838,7 @@ class storyModel extends model $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); if($relation) { - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); + $if(!empty($object)) this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); } } @@ -1435,6 +1435,7 @@ class storyModel extends model ->checkIF($story->closedReason == 'duplicate', 'duplicateStory', 'notempty') ->where('id')->eq($storyID)->exec(); + $object = $this->getByID($storyID); $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); if(!empty($relation)) @@ -1444,11 +1445,9 @@ class storyModel extends model if($singleIssue->state != 'closed') { - $object = $this->getByID($storyID); - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); + $if(!empty($object)) this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); } } - /* Update parent story status. */ if($oldStory->parent > 0) $this->updateParentStatus($storyID, $oldStory->parent); @@ -1794,11 +1793,10 @@ class storyModel extends model if(!dao::isError()) { $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); - $attribute = new stdclass(); + $attribute = $this->getByID($storyID); $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $story->assignedTo); if($attribute->assignee_id != '') { - $object = $this->getByID($storyID); // TODO(dingguodong) we should alert to operator when can not find the user, and the operator should reconfigure user binding. $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story' $attribute); } @@ -1841,7 +1839,7 @@ class storyModel extends model $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); if($relation) { - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); + $if(!empty($object)) this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); } } } diff --git a/module/task/model.php b/module/task/model.php index 78512624d1..e3c19189d7 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -958,8 +958,7 @@ class taskModel extends model $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); if($relation) { - $object = $this->getByID($taskID); - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $object); + if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $object); } } @@ -1350,11 +1349,10 @@ class taskModel extends model ->where('id')->eq($taskID)->exec(); $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); - $attribute = new stdclass(); + $attribute = $this->getByID($taskID); $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $task->assignedTo); if($attribute->assignee_id != '') { - $attribute = $this->getByID($taskID); // TODO(dingguodong) we should alert to operator when can not find the user, and the operator should reconfigure user binding. $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, $attribute); } @@ -1763,6 +1761,7 @@ class taskModel extends model $this->dao->update(TABLE_TASK)->data($task)->autoCheck()->where('id')->eq((int)$taskID)->exec(); + $object = $this->getByID($bugID); $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); if(!empty($relation)) { @@ -1771,7 +1770,6 @@ class taskModel extends model if($singleIssue->state != 'closed') { - $object = $this->getByID($bugID); if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $object); } } @@ -1820,6 +1818,7 @@ class taskModel extends model } if($oldTask->story) $this->loadModel('story')->setStage($oldTask->story); + $object = $this->getByID($taskID); $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); if(!empty($relation)) { @@ -1828,8 +1827,7 @@ class taskModel extends model if($singleIssue->state != 'closed') { - $object = $this->getByID($taskID); - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $object); + $if(!empty($object)) this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $object); } } From 38df84e8ede26f65f11adc666ba40372d838b293 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Mon, 5 Jul 2021 05:40:10 +0800 Subject: [PATCH 218/269] * Fix story, task bug. --- module/story/model.php | 8 ++++---- module/task/model.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/module/story/model.php b/module/story/model.php index 74b94499f3..e5fcd0e657 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -838,7 +838,7 @@ class storyModel extends model $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); if($relation) { - $if(!empty($object)) this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); + if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); } } @@ -1445,7 +1445,7 @@ class storyModel extends model if($singleIssue->state != 'closed') { - $if(!empty($object)) this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); + if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); } } @@ -1798,7 +1798,7 @@ class storyModel extends model if($attribute->assignee_id != '') { // TODO(dingguodong) we should alert to operator when can not find the user, and the operator should reconfigure user binding. - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story' $attribute); + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $attribute); } return common::createChanges($oldStory, $story); } @@ -1839,7 +1839,7 @@ class storyModel extends model $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); if($relation) { - $if(!empty($object)) this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); + if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); } } } diff --git a/module/task/model.php b/module/task/model.php index e3c19189d7..8d742c3780 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -1827,7 +1827,7 @@ class taskModel extends model if($singleIssue->state != 'closed') { - $if(!empty($object)) this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $object); + if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $object); } } From 2650aab901f4dc0f8d9bd761699fb251f672e74f Mon Sep 17 00:00:00 2001 From: lichengjun Date: Mon, 5 Jul 2021 09:03:42 +0800 Subject: [PATCH 219/269] * Fix gitlab model apiCreateIssues function code format. --- module/gitlab/model.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 41a9eb56f3..cac21b1754 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -520,9 +520,12 @@ class gitlabModel extends model /** * Create issue by api. * - * @param int $gitlabID - * @param int $projectID - * @param object $issue + * @param int $gitlabID + * @param int $projectID + * @param object $issue + * @param string $objectType + * @param int $objectID + * @param object $object * @access public * @return object */ @@ -540,7 +543,12 @@ class gitlabModel extends model $url = sprintf($apiRoot, "/projects/{$projectID}/issues/"); $response = json_decode(commonModel::http($url, $issue)); - $this->saveSyncedIssue($objectType, $object, $gitlabID, $response); + if($response) + { + $this->saveSyncedIssue($objectType, $object, $gitlabID, $response); + }else{ + return $issue; + } } /** @@ -1004,8 +1012,8 @@ class gitlabModel extends model * * @param int $gitlabID * @param int $projectID - * @param object $object * @param string $objectType + * @param object $object * @access public * @return object */ From b8408954785358d7634d4db61a02f5da6abaa749 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Mon, 5 Jul 2021 09:57:10 +0800 Subject: [PATCH 220/269] * Remove issue param from apiCreateIssue function. --- module/gitlab/model.php | 68 ++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index cac21b1754..63b0c424bc 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -256,6 +256,44 @@ class gitlabModel extends model return $this->loadModel('pipeline')->update($id); } + /** + * Send an api get request. + * + * @param int|string $host gitlab server ID | gitlab host url. + * @param int $api + * @param int $data + * @param int $options + * @access public + * @return object + */ + public function apiGet($host, $api, $data = array(), $options = array()) + { + if(is_numeric($host)) $host = $this->getApiRoot($host); + if(strpos($host, 'http://') !== 0 and strpos($host, 'https://') !== 0) return false; + + $url = sprintf($apiRoot, $api); + return json_decode(commonModel::http($url, $data, $options)); + } + + /** + * Send an api post request. + * + * @param int|string $host gitlab server ID | gitlab host url. + * @param int $api + * @param int $data + * @param int $options + * @access public + * @return object + */ + public function apiGet($host, $api, $data = array(), $options = array()) + { + if(is_numeric($host)) $host = $this->getApiRoot($host); + if(strpos($host, 'http://') !== 0 and strpos($host, 'https://') !== 0) return false; + + $url = sprintf($apiRoot, $api); + return json_decode(commonModel::http($url, $data, $options)); + } + /** * Get current user. * @@ -266,8 +304,8 @@ class gitlabModel extends model */ public function apiGetCurrentUser($host, $token) { - $api = rtrim($host, '/') . "/api/v4/user?private_token=$token"; - return json_decode(commonModel::http($api)); + $host = rtrim($host, '/') . "/api/v4%s?private_token=$token"; + return $this->apiGet($host, '/user'); } /** @@ -280,9 +318,7 @@ class gitlabModel extends model */ public function apiGetUsers($gitlab) { - $apiRoot = $this->getApiRoot($gitlab->id); - $url = sprintf($apiRoot, '/users'); - $response = json_decode(commonModel::http($url)); + $response = $this->apiGet($gitlab->id, '/users'); if (!$response) return array(); @@ -522,19 +558,20 @@ class gitlabModel extends model * * @param int $gitlabID * @param int $projectID - * @param object $issue * @param string $objectType * @param int $objectID * @param object $object * @access public * @return object */ - public function apiCreateIssue($gitlabID, $projectID, $issue, $objectType, $objectID, $object) + public function apiCreateIssue($gitlabID, $projectID, $objectType, $objectID, $object) { $label = $this->createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID); - $issue->labels = isset($label->name) ? $label->name : ''; - foreach($this->config->gitlab->skippedFields->issueCreate as $field) + $issue = $this->loadModel('gitlab')->parseObjectToIssue($gitlabID, $projectID, $objectType, $object); + if(isset($label->name)) $issue->labels = $label->name; + + foreach($this->config->gitlab->skippedFields->issueCreate[$objectType] as $field) { if(isset($issue->$field)) unset($issue->$field); } @@ -543,12 +580,9 @@ class gitlabModel extends model $url = sprintf($apiRoot, "/projects/{$projectID}/issues/"); $response = json_decode(commonModel::http($url, $issue)); - if($response) - { - $this->saveSyncedIssue($objectType, $object, $gitlabID, $response); - }else{ - return $issue; - } + if(!$response) return false; + + return $this->saveSyncedIssue($objectType, $object, $gitlabID, $response); } /** @@ -563,10 +597,10 @@ class gitlabModel extends model */ public function apiUpdateIssue($gitlabID, $projectID, $issueID, $objectType, $object) { - $attribute = $this->parseObjectToIssue($gitlabID, $projectID, $objectType, $object); + $issue = $this->parseObjectToIssue($gitlabID, $projectID, $objectType, $object); $apiRoot = $this->getApiRoot($gitlabID); $url = sprintf($apiRoot, "/projects/{$projectID}/issues/{$issueID}"); - return json_decode(commonModel::http($url, $attribute, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); + return json_decode(commonModel::http($url, $issue, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); } /** From eca1930586bbdcb01641be85abba432c911f8d42 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 5 Jul 2021 10:26:54 +0800 Subject: [PATCH 221/269] * Remove useless variables for apiGetIssues. --- module/gitlab/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 41a9eb56f3..6fb3ddf0e2 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -513,7 +513,7 @@ class gitlabModel extends model public function apiGetIssues($gitlabID, $projectID) { // TODO(dingguodong) not pagination yet. - $url = sprintf($this->getApiRoot($gitlabID), "/projects/{$projectID}/issues/{$issueID}"); + $url = sprintf($this->getApiRoot($gitlabID), "/projects/{$projectID}/issues"); return json_decode(commonModel::http($url)); } From 388f6365c925b48fc5fe9db65977f00ad4bda236 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 5 Jul 2021 10:50:24 +0800 Subject: [PATCH 222/269] * The GET form for importIssue is completed, post not. --- module/gitlab/control.php | 21 +++++++++------------ module/gitlab/model.php | 2 +- module/gitlab/view/importissue.html.php | 8 +++++--- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 213828f266..c39a7729ce 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -253,22 +253,19 @@ class gitlab extends control public function importIssue() { + $productID = $this->get->product; + $gitlabID = $this->get->gitlab; + $projectID = $this->get->project; + + $executions = $this->loadModel('product')->getAllExecutionPairsByProduct($productID); + if($_POST) { $this->post->a(); } - $productID = $this->get->product; - $gitlabID = $this->get->gitlab; - $projectID = $this->get->project; - // todo next: get execution from product and execution module. - - $executions = array(); - foreach($relations as $relation) - { - if($relation->execution) $executions[] = $this->loadModel("execution")->getByID($relation->execution)->name; - } - + $gitlabIssues = $this->gitlab->apiGetIssues($gitlabID, $projectID); + $this->view->productName = $this->loadModel("product")->getByID($productID)->name; $this->view->productID = $productID; $this->view->gitlabID = $gitlabID; @@ -276,7 +273,7 @@ class gitlab extends control $this->view->executions = $executions; $this->view->objectTypes = $this->config->gitlab->objectTypes; - $this->view->gitlabIssues = $this->gitlab->apiGetIssues($gitlabID, $projectID); + $this->view->gitlabIssues = $gitlabIssues; $this->display(); } } diff --git a/module/gitlab/model.php b/module/gitlab/model.php index ed7ba695cb..16a3f5e1d9 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -285,7 +285,7 @@ class gitlabModel extends model * @access public * @return object */ - public function apiGet($host, $api, $data = array(), $options = array()) + public function apiPost($host, $api, $data = array(), $options = array()) { if(is_numeric($host)) $host = $this->getApiRoot($host); if(strpos($host, 'http://') !== 0 and strpos($host, 'https://') !== 0) return false; diff --git a/module/gitlab/view/importissue.html.php b/module/gitlab/view/importissue.html.php index 16b8879841..e1a53be93c 100644 --- a/module/gitlab/view/importissue.html.php +++ b/module/gitlab/view/importissue.html.php @@ -20,22 +20,24 @@ + - + + - - + + From 30f8f51e3b016606ee66780fcc74b0486d44c0a7 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Mon, 5 Jul 2021 13:26:49 +0800 Subject: [PATCH 223/269] *Add batch update, assign, function in the story model. --- module/bug/model.php | 3 +-- module/gitlab/config.php | 4 +++- module/gitlab/model.php | 20 -------------------- module/story/model.php | 29 ++++++++++++++++++++++++++--- module/task/model.php | 6 ++---- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/module/bug/model.php b/module/bug/model.php index 6d44b10346..2e16e2f32f 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -90,8 +90,7 @@ class bugModel extends model $bugID = $this->dao->lastInsertID(); $object = $this->getByID($bugID); - $issue = $this->loadModel('gitlab')->parseObjectToIssue($this->post->gitlab, $this->post->gitlabProject, 'bug', $object); - $this->loadModel('gitlab')->apiCreateIssue($this->post->gitlab, $this->post->gitlabProject, $issue, 'bug', $bugID, $object); + $this->loadModel('gitlab')->apiCreateIssue($this->post->gitlab, $this->post->gitlabProject, 'bug', $bugID, $object); $this->file->updateObjectID($this->post->uid, $bugID, 'bug'); $this->file->saveUpload('bug', $bugID); diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 9cd8d1da48..f3fff35b4d 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -27,7 +27,9 @@ $config->gitlab->webhookURL = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=% $config->gitlab->skippedFields = new stdclass; $config->gitlab->skippedFields->issueCreate = array(); -$config->gitlab->skippedFields->issueCreate[] = ''; +$config->gitlab->skippedFields->issueCreate['story'] = array(); +$config->gitlab->skippedFields->issueCreate['task'] = array(); +$config->gitlab->skippedFields->issueCreate['bug'] = array(); $config->gitlab->maps = new stdclass; $config->gitlab->maps->task = array(); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 63b0c424bc..b2a9d0fe64 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -275,25 +275,6 @@ class gitlabModel extends model return json_decode(commonModel::http($url, $data, $options)); } - /** - * Send an api post request. - * - * @param int|string $host gitlab server ID | gitlab host url. - * @param int $api - * @param int $data - * @param int $options - * @access public - * @return object - */ - public function apiGet($host, $api, $data = array(), $options = array()) - { - if(is_numeric($host)) $host = $this->getApiRoot($host); - if(strpos($host, 'http://') !== 0 and strpos($host, 'https://') !== 0) return false; - - $url = sprintf($apiRoot, $api); - return json_decode(commonModel::http($url, $data, $options)); - } - /** * Get current user. * @@ -570,7 +551,6 @@ class gitlabModel extends model $issue = $this->loadModel('gitlab')->parseObjectToIssue($gitlabID, $projectID, $objectType, $object); if(isset($label->name)) $issue->labels = $label->name; - foreach($this->config->gitlab->skippedFields->issueCreate[$objectType] as $field) { if(isset($issue->$field)) unset($issue->$field); diff --git a/module/story/model.php b/module/story/model.php index e5fcd0e657..e0595205c3 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -341,8 +341,7 @@ class storyModel extends model /* push this story to gitlab issue */ $object = $this->getByID($storyID); - $issue = $this->loadModel('gitlab')->parseObjectToIssue($this->post->gitlab, $this->post->gitlabProject, 'story', $object); - $this->loadModel('gitlab')->apiCreateIssue($this->post->gitlab, $this->post->gitlabProject, $issue, 'story', $storyID, $object); + $this->loadModel('gitlab')->apiCreateIssue($this->post->gitlab, $this->post->gitlabProject, 'story', $storyID, $object); return array('status' => 'created', 'id' => $storyID); } @@ -1168,6 +1167,18 @@ class storyModel extends model /* Update story sort of plan when story plan has changed. */ if($oldStory->plan != $story->plan) $this->updateStoryOrderOfPlan($storyID, $story->plan, $oldStory->plan); + /* update story to gitlab issue. */ + $object = $this->getByID($storyID); + + if(!empty($object)) + { + $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); + if($relation) + { + if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); + } + } + $this->executeHooks($storyID); if($story->type == 'story') $this->batchChangeStage(array($storyID), $story->stage); if($story->closedReason == 'done') $this->loadModel('score')->create('story', 'close'); @@ -1440,7 +1451,6 @@ class storyModel extends model if(!empty($relation)) { - $singleIssue = new stdclass(); $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); if($singleIssue->state != 'closed') @@ -1515,6 +1525,19 @@ class storyModel extends model if($oldStory->parent > 0) $this->updateParentStatus($storyID, $oldStory->parent); $this->setStage($storyID); $allChanges[$storyID] = common::createChanges($oldStory, $story); + + $object = $this->getByID($storyID); + $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); + + if(!empty($relation)) + { + $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); + + if($singleIssue->state != 'closed') + { + if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); + } + } } else { diff --git a/module/task/model.php b/module/task/model.php index 8d742c3780..55dd236b04 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -124,8 +124,7 @@ class taskModel extends model /* Sync this task to gitlab issue. */ $object = $this->getByID($taskID); - $issue = $this->loadModel('gitlab')->parseObjectToIssue($this->post->gitlab, $this->post->gitlabProject, 'task', $object); - $this->loadModel('gitlab')->apiCreateIssue($this->post->gitlab, $this->post->gitlabProject, $issue, 'task', $taskID, $object); + $this->loadModel('gitlab')->apiCreateIssue($this->post->gitlab, $this->post->gitlabProject, 'task', $taskID, $object); /* Mark design version.*/ if(isset($task->design) && !empty($task->design)) @@ -386,8 +385,7 @@ class taskModel extends model /* Sync this task to gitlab issue. */ $object = $this->getByID($taskID); - $issue = $this->loadModel('gitlab')->parseObjectToIssue($this->post->gitlab, $this->post->gitlabProject, 'task', $object); - $this->loadModel('gitlab')->apiCreateIssue($this->post->gitlab, $this->post->gitlabProject, $issue, 'task', $taskID, $object); + $this->loadModel('gitlab')->apiCreateIssue($this->post->gitlab, $this->post->gitlabProject,'task', $taskID, $object); $taskSpec = new stdClass(); $taskSpec->task = $taskID; From 57c807dd721b9c7be2ef22b1578e4de23e1a464f Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 5 Jul 2021 15:01:54 +0800 Subject: [PATCH 224/269] * Fix bug for sql datetime lt empty string. --- module/repo/model.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/module/repo/model.php b/module/repo/model.php index bccba49194..da7e060501 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -459,7 +459,9 @@ class repoModel extends model ->leftJoin(TABLE_REPOBRANCH)->alias('t3')->on('t2.id=t3.revision') ->where('1=1') ->andWhere('t1.repo')->eq($repo->id) + ->beginIF($revisionTime) ->andWhere('t2.`time`')->le($revisionTime) + ->fi() ->andWhere('left(t2.comment, 12)')->ne('Merge branch') ->beginIF($repo->SCM != 'Subversion' and $this->cookie->repoBranch)->andWhere('t3.branch')->eq($this->cookie->repoBranch)->fi() ->beginIF($type == 'dir') @@ -476,7 +478,9 @@ class repoModel extends model $comments = $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($revisionTime) ->andWhere('t1.`time`')->le($revisionTime) + ->fi() ->andWhere('left(t1.comment, 12)')->ne('Merge branch') ->beginIF($repo->SCM != 'Subversion' and $this->cookie->repoBranch)->andWhere('t2.branch')->eq($this->cookie->repoBranch)->fi() ->beginIF($entry != '/' and !empty($entry))->andWhere('t1.id')->in($historyIdList)->fi() From 94a297d341f41bdc3a1c6b66778108de3febc243 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 5 Jul 2021 15:03:55 +0800 Subject: [PATCH 225/269] * set page to 100 temp. --- module/gitlab/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 16a3f5e1d9..5db702a8c1 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -549,7 +549,7 @@ class gitlabModel extends model public function apiGetIssues($gitlabID, $projectID) { // TODO(dingguodong) not pagination yet. - $url = sprintf($this->getApiRoot($gitlabID), "/projects/{$projectID}/issues"); + $url = sprintf($this->getApiRoot($gitlabID), "/projects/{$projectID}/issues") . '&per_page=100'; return json_decode(commonModel::http($url)); } From ec86c142ef6f84d404528d33ba4077872668947d Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 5 Jul 2021 15:10:34 +0800 Subject: [PATCH 226/269] * set product column table width to 400. --- module/repo/view/maintain.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/repo/view/maintain.html.php b/module/repo/view/maintain.html.php index 2c2da5b64a..d59a9a4186 100644 --- a/module/repo/view/maintain.html.php +++ b/module/repo/view/maintain.html.php @@ -25,7 +25,7 @@ - + From 7db7bd4635838f17508f4438ea65eb5f5ad8be6e Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Tue, 6 Jul 2021 10:18:28 +0800 Subject: [PATCH 227/269] * Fix parse bug and story object from webhook issue function. --- module/gitlab/model.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 7eea1cc937..11bd3bcabd 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -712,20 +712,24 @@ class gitlabModel extends model * * @param array $labels * @access public - * @return object|false + * @return object */ public function webhookParseObject($labels) { - $object = null; + $object = null; + $objectType = ''; foreach($labels as $label) { - if(preg_match($this->config->gitlab->labelPattern->task, $label->title)) + if(preg_match($this->config->gitlab->labelPattern->story, $label->title)) $objectType = 'story'; + if(preg_match($this->config->gitlab->labelPattern->task, $label->title)) $objectType = 'task'; + if(preg_match($this->config->gitlab->labelPattern->bug, $label->title)) $objectType = 'bug'; + + if($objectType) { list($prefix, $id) = explode('/', $label->title); - $object = new stdclass; - $object->type = 'task'; $object->id = $id; + $object->type = $objectType; } } From e5d78d015ba87fa817acc310eea96a76659d36ee Mon Sep 17 00:00:00 2001 From: lichengjun Date: Tue, 6 Jul 2021 11:21:12 +0800 Subject: [PATCH 228/269] *Fix bug model code format. --- module/bug/control.php | 4 +--- module/bug/model.php | 32 ++++++++------------------------ 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/module/bug/control.php b/module/bug/control.php index 834205c6e4..9594fcfbce 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -559,9 +559,7 @@ class bug extends control /* Set gitlabProjects. */ $allGitlabs = $this->loadModel('gitlab')->getPairs(); - if(!empty($executionID)) $gitlabProjects = $this->loadModel('gitlab')->getProjectsByExecution($executionID); - elseif(!empty($productID)) $gitlabProjects = $this->loadModel('gitlab')->getProjectsByProduct($productID); - + $gitlabProjects = $this->loadModel('gitlab')->getProjectsByExecution($executionID); foreach($allGitlabs as $id => $name) if($id and !isset($gitlabProjects[$id])) unset($allGitlabs[$id]); $this->view->gitlabList = $allGitlabs; $this->view->gitlabProjects = $gitlabProjects; diff --git a/module/bug/model.php b/module/bug/model.php index 2e16e2f32f..41a888416e 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -646,16 +646,11 @@ class bugModel extends model if(!empty($bug->resolvedBy)) $this->loadModel('score')->create('bug', 'resolve', $bugID); $this->file->updateObjectID($this->post->uid, $bugID, 'bug'); - - $object = $this->getByID($bugID); - if(!empty($object)) + if(!empty($bug)) { - $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); - $issue = $this->parseObjectToIssue($relation->gitlabID, $relation->projectID, $object, 'bug'); - if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $issueID, 'bug', $object); - + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); } return common::createChanges($oldBug, $bug); } @@ -864,12 +859,11 @@ class bugModel extends model ->where('id')->eq($bugID)->exec(); $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); - $attribute = $this->getByID($bugID); - $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $bug->assignedTo); - if($attribute->assignee_id != '') + $bug->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $bug->assignedTo); + if($bug->assignee_id != '') { // TODO(dingguodong) we should alert to operator when can not find the user, and the operator should reconfigure user binding. - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $attribute); + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); } if(!dao::isError()) return common::createChanges($oldBug, $bug); @@ -1017,17 +1011,9 @@ class bugModel extends model /* Link bug to build and release. */ $this->linkBugToBuild($bugID, $bug->resolvedBuild); - $object = $this->getByID($bugID); + $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); - if(!empty($object)) - { - $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); - if($relation) - { - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $object); - } - - } return common::createChanges($oldBug, $bug); } @@ -1243,8 +1229,6 @@ class bugModel extends model $this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec(); - $object = $this->getByID($bugID); - $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); if(!empty($relation)) { @@ -1253,7 +1237,7 @@ class bugModel extends model if($singleIssue->state != 'closed') { - if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $object); + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); } } return common::createChanges($oldBug, $bug); From 9ab1e4541f59b94d33ee8ed526cd320deba8e71f Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 6 Jul 2021 16:31:43 +0800 Subject: [PATCH 229/269] * Import gitlab issue to task(staging). --- config/filter.php | 1 + module/gitlab/control.php | 92 ++++++++++++++++++++++--- module/gitlab/js/importissue.js | 18 +++++ module/gitlab/js/mapissue.js | 19 ----- module/gitlab/model.php | 46 ++++++++++--- module/gitlab/view/importissue.html.php | 11 ++- module/task/model.php | 53 +++++++++++++- 7 files changed, 195 insertions(+), 45 deletions(-) create mode 100644 module/gitlab/js/importissue.js delete mode 100644 module/gitlab/js/mapissue.js diff --git a/config/filter.php b/config/filter.php index a4125b9da5..7460c2a0da 100644 --- a/config/filter.php +++ b/config/filter.php @@ -319,5 +319,6 @@ $filter->gitlab->webhook->get['token'] = 'reg::any'; $filter->gitlab->importissue->get['gitlab'] = 'int'; $filter->gitlab->importissue->get['product'] = 'int'; +$filter->gitlab->importissue->get['product'] = 'string'; $filter->gitlab->importissue->get['project'] = 'int'; diff --git a/module/gitlab/control.php b/module/gitlab/control.php index c39a7729ce..744927264d 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -251,29 +251,101 @@ class gitlab extends control exit; } + /** + * Import gitlab issue to zentaopms. + * + * @access public + * @return void + */ public function importIssue() { - $productID = $this->get->product; - $gitlabID = $this->get->gitlab; - $projectID = $this->get->project; + $productIDList = explode(',', $this->get->product); + $gitlabID = $this->get->gitlab; + $projectID = $this->get->project; - $executions = $this->loadModel('product')->getAllExecutionPairsByProduct($productID); if($_POST) { - $this->post->a(); + $executionList = $this->post->executionList; + $objectTypeList = $this->post->objectTypeList; + $productList = $this->post->productList; + foreach($executionList as $issueID => $executionID) + { + if($executionID) + { + $objectType = $this->config->gitlab->objectTypes[$objectTypeList[$issueID]]; + + $issue = $this->gitlab->apiGetSingleIssue($gitlabID, $projectID, $issueID); + $originalIssue = $issue; + $issue->objectType = $objectType; + $issue->objectID = 0; // meet the required parameters for issueToZentaoObject. + if(isset($issue->assignee)) $issue->assignee_id = $issue->assignee->id; + $issue->updated_by_id = $issue->author->id; // here can be replaced by current zentao user. + + $object = $this->gitlab->issueToZentaoObject($issue, $gitlabID); + if($objectType == 'task') + { + $objectID = $this->loadModel('task')->createTaskFromGitlabIssue($object, $executionID); + } + + if($objectType == 'bug') + { + } + + if($objectType == 'story') + { + } + + $object->id = $objectID; + $this->gitlab->saveImportedIssue($gitlabID, $projectID, $objectType, $objectID, $originalIssue, $object); + + } + } + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->server->http_referer)); } - $gitlabIssues = $this->gitlab->apiGetIssues($gitlabID, $projectID); - - $this->view->productName = $this->loadModel("product")->getByID($productID)->name; - $this->view->productID = $productID; + $savedIssueIDList = $this->dao->select('BID as issueID')->from(TABLE_RELATION) + ->where('relation')->eq('gitlab') + ->fetchAll('issueID'); + $iids = ''; + foreach($savedIssueIDList as $savedIssueID) $iids = $iids . $savedIssueID->issueID . ','; + $options = '¬[iids]=' . trim($iids, ','); + $gitlabIssues = $this->gitlab->apiGetIssues($gitlabID, $projectID, $options); //TODO(dingguodong) when no issues here? + + $products = array(); + $products[] = ''; + foreach($productIDList as $productID) + { + $products[$productID] = $this->loadModel("product")->getByID($productID)->name; + } + + $this->view->products = $products; $this->view->gitlabID = $gitlabID; $this->view->gitlabProjectID = $projectID; - $this->view->executions = $executions; $this->view->objectTypes = $this->config->gitlab->objectTypes; $this->view->gitlabIssues = $gitlabIssues; $this->display(); } + + /** + * Ajax get executions by productID. + * + * @param int $productID + * @access public + * @return string + */ + public function ajaxGetExecutionsByProduct($productID) + { + if(!$productID) $this->send(array('message' => array())); + + $executions = $this->loadModel('product')->getAllExecutionPairsByProduct($productID); + $options = ""; + foreach($executions as $index =>$execution) + { + $options .= ""; + } + die($options); + } + } diff --git a/module/gitlab/js/importissue.js b/module/gitlab/js/importissue.js new file mode 100644 index 0000000000..d48d5a6028 --- /dev/null +++ b/module/gitlab/js/importissue.js @@ -0,0 +1,18 @@ +$(document).ready(function() +{ + $('[name^=productList').change(function() + { + var execution = $(this); + host = execution.val(); + if(host == '') return false; + executions = ''; + url = createLink('gitlab', 'ajaxGetExecutionsByProduct', "host=" + host); + + $.get(url, function(response) + { + execution = execution.parent().next().find('select'); + execution.html('').append(response); + execution.chosen().trigger("chosen:updated"); + }); + }); +}); diff --git a/module/gitlab/js/mapissue.js b/module/gitlab/js/mapissue.js deleted file mode 100644 index a8be522002..0000000000 --- a/module/gitlab/js/mapissue.js +++ /dev/null @@ -1,19 +0,0 @@ -$(document).ready(function() -{ - $('[name^=gitlabID').change(function() - { - var gitlab = $(this); - host = gitlab.val(); - if(host == '') return false; - projects = ''; - url = createLink('repo', 'ajaxgetgitlabprojects', "host=" + host); - - $.get(url, function(response) - { - project = gitlab.parent().next().find('select'); - project.html('').append(response); - project.chosen().trigger("chosen:updated"); - }); - - }); -}); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 7eea1cc937..d972f2ffaa 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -271,13 +271,11 @@ class gitlabModel extends model if(is_numeric($host)) $host = $this->getApiRoot($host); if(strpos($host, 'http://') !== 0 and strpos($host, 'https://') !== 0) return false; - $url = sprintf($apiRoot, $api); + $url = sprintf($host, $api); return json_decode(commonModel::http($url, $data, $options)); } /** -<<<<<<< HEAD -======= * Send an api post request. * * @param int|string $host gitlab server ID | gitlab host url. @@ -549,10 +547,17 @@ class gitlabModel extends model return json_decode(commonModel::http($url)); } - public function apiGetIssues($gitlabID, $projectID) + public function apiGetIssues($gitlabID, $projectID, $options = null) { // TODO(dingguodong) not pagination yet. - $url = sprintf($this->getApiRoot($gitlabID), "/projects/{$projectID}/issues") . '&per_page=100'; + if($options) + { + $url = sprintf($this->getApiRoot($gitlabID), "/projects/{$projectID}/issues") . '&per_page=100' . $options; + } + else + { + $url = sprintf($this->getApiRoot($gitlabID), "/projects/{$projectID}/issues") . '&per_page=100'; + } return json_decode(commonModel::http($url)); } @@ -893,7 +898,7 @@ class gitlabModel extends model * @access public * @return void */ - public function saveSyncedIssue($objectType, $object, $gitlab, $issue) + public function saveSyncedIssue($objectType, $object, $gitlabID, $issue) { if(empty($issue->iid) or empty($issue->project_id)) return false; @@ -906,10 +911,33 @@ class gitlabModel extends model $relation->BType = 'issue'; $relation->BID = $issue->iid; $relation->BVersion = $issue->project_id; - $relation->extra = $gitlab; + $relation->extra = $gitlabID; $this->dao->replace(TABLE_RELATION)->data($relation)->exec(); } + /** + * Save imported issue. + * + * @param int $gitlabID + * @param int $projectID + * @param string $objectType + * @param int $objectID + * @param object $issue + * @access public + * @return void + */ + public function saveImportedIssue($gitlabID, $projectID, $objectType, $objectID, $issue, $object) + { + $label = $this->createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID); + $data = new stdclass; + if(isset($label->name)) $data->labels = $label->name; + + $apiRoot = $this->getApiRoot($gitlabID); + $url = sprintf($apiRoot, "/projects/{$projectID}/issues/{$issue->iid}"); + commonModel::http($url, $data, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT')); + $this->saveSyncedIssue($objectType, $object, $gitlabID, $issue); + } + /** * Parse task to issue. * @@ -1110,12 +1138,12 @@ class gitlabModel extends model { $value = ''; list($gitlabField, $optionType, $options) = explode('|', $config); - if(!isset($changes->$gitlabField)) continue; + if(!isset($changes->$gitlabField) and $object->id != 0) continue; if($optionType == 'field') $value = $issue->$gitlabField; if($optionType == 'field') $value = $issue->$gitlabField; if($options == 'date') $value = date('Y-m-d', strtotime($value)); if($options == 'datetime') $value = date('Y-m-d H:i:s', strtotime($value)); - if($optionType == 'userPairs') $value = zget($gitlabUsers, $issue->$gitlabField); + if($optionType == 'userPairs' and isset($issue->$gitlabField)) $value = zget($gitlabUsers, $issue->$gitlabField); if($optionType == 'configItems' and isset($issue->$gitlabField)) $value = array_search($issue->$gitlabField, $this->config->gitlab->$options); if($value) $object->$zentaoField = $value; } diff --git a/module/gitlab/view/importissue.html.php b/module/gitlab/view/importissue.html.php index e1a53be93c..c43fcc2e24 100644 --- a/module/gitlab/view/importissue.html.php +++ b/module/gitlab/view/importissue.html.php @@ -21,21 +21,20 @@ + - - - - + + + + - - diff --git a/module/task/model.php b/module/task/model.php index 55dd236b04..a4032ee589 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -122,7 +122,6 @@ class taskModel extends model $taskID = $this->dao->lastInsertID(); /* Sync this task to gitlab issue. */ - $object = $this->getByID($taskID); $this->loadModel('gitlab')->apiCreateIssue($this->post->gitlab, $this->post->gitlabProject, 'task', $taskID, $object); @@ -455,6 +454,58 @@ class taskModel extends model return $mails; } + /** + * Create task from gitlab issue. + * + * @param object $task + * @param int $executionID + * @access public + * @return int + */ + public function createTaskFromGitlabIssue($task, $executionID) + { + foreach($task as $feild => $value) $_POST[$feild] = $value; + $requiredFields = ',' . $this->config->task->create->requiredFields . ','; + $requiredFields = trim($requiredFields, ','); + $task = fixer::input('post') + ->setDefault('execution', $executionID) + ->setDefault('estimate,left,story', 0) + ->setDefault('status', 'wait') + ->setIF($this->config->systemMode == 'new', 'project', $this->getProjectID($executionID)) + ->setIF($this->post->estimate != false, 'left', $this->post->estimate) + ->setIF($this->post->story != false, 'storyVersion', $this->loadModel('story')->getVersion($this->post->story)) + ->setDefault('estStarted', '0000-00-00') + ->setDefault('deadline', '0000-00-00') + ->setIF(strpos($requiredFields, 'estStarted') !== false, 'estStarted', helper::isZeroDate($this->post->estStarted) ? '' : $this->post->estStarted) + ->setIF(strpos($requiredFields, 'deadline') !== false, 'deadline', helper::isZeroDate($this->post->deadline) ? '' : $this->post->deadline) + ->setIF(strpos($requiredFields, 'estimate') !== false, 'estimate', $this->post->estimate) + ->setIF(strpos($requiredFields, 'left') !== false, 'left', $this->post->left) + ->setIF(strpos($requiredFields, 'story') !== false, 'story', $this->post->story) + ->setIF(is_numeric($this->post->estimate), 'estimate', (float)$this->post->estimate) + ->setIF(is_numeric($this->post->consumed), 'consumed', (float)$this->post->consumed) + ->setIF(is_numeric($this->post->left), 'left', (float)$this->post->left) + ->setDefault('openedBy', $this->app->user->account) + ->setDefault('openedDate', helper::now()) + ->cleanINT('execution,story,module') + ->stripTags($this->config->task->editor->create['id'], $this->config->allowedTags) + ->join('mailto', ',') + ->remove('objectTypeList,productList,executionList,gitlabID,gitlabProjectID,after,files,labels,assignedTo,uid,storyEstimate,storyDesc,storyPri,team,teamEstimate,teamMember,multiple,teams,contactListMenu,selectTestStory,testStory,testPri,testEstStarted,testDeadline,testAssignedTo,testEstimate,sync') + ->add('version', 1) + ->get(); + + $this->dao->insert(TABLE_TASK)->data($task, $skip = 'id') + ->autoCheck() + ->batchCheck($requiredFields, 'notempty') + ->checkIF($task->estimate != '', 'estimate', 'float') + ->checkIF(!helper::isZeroDate($task->deadline), 'deadline', 'ge', $task->estStarted) + ->exec(); + + if(dao::isError()) return false; + + $taskID = $this->dao->lastInsertID(); + return $taskID; + } + /** * Compute parent task working hours. * From f04514f65d267628ebe94132753bd783b401e8e8 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Tue, 6 Jul 2021 16:43:04 +0800 Subject: [PATCH 230/269] * Fix code format. --- module/execution/control.php | 4 +++ module/gitlab/model.php | 3 -- module/story/model.php | 62 ++++++++---------------------------- module/task/model.php | 47 +++++++-------------------- 4 files changed, 30 insertions(+), 86 deletions(-) diff --git a/module/execution/control.php b/module/execution/control.php index 410a91ba47..ba0baa3771 100644 --- a/module/execution/control.php +++ b/module/execution/control.php @@ -2449,6 +2449,10 @@ class execution extends control $_POST = array(); foreach($storyIdList as $storyID) { + /* Delete related issue in gitlab. */ + $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); + if(!empty($relation)) $this->loadModel('gitlab')->deleteIssue('story', $storyID, $relation->issueID); + $this->execution->unlinkStory($executionID, $storyID); } } diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 11bd3bcabd..b1f7ed9aca 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -276,8 +276,6 @@ class gitlabModel extends model } /** -<<<<<<< HEAD -======= * Send an api post request. * * @param int|string $host gitlab server ID | gitlab host url. @@ -297,7 +295,6 @@ class gitlabModel extends model } /** ->>>>>>> 388f6365c925b48fc5fe9db65977f00ad4bda236 * Get current user. * * @param string $host diff --git a/module/story/model.php b/module/story/model.php index e0595205c3..4de8a83290 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -830,16 +830,8 @@ class storyModel extends model $this->dao->insert(TABLE_STORYREVIEW)->data($reviewData)->exec(); } /* update story to gitlab issue. */ - $object = $this->getByID($storyID); - - if(!empty($object)) - { - $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); - if($relation) - { - if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); - } - } + $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); unset($oldStory->parent); unset($story->parent); @@ -1168,16 +1160,8 @@ class storyModel extends model if($oldStory->plan != $story->plan) $this->updateStoryOrderOfPlan($storyID, $story->plan, $oldStory->plan); /* update story to gitlab issue. */ - $object = $this->getByID($storyID); - - if(!empty($object)) - { - $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); - if($relation) - { - if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); - } - } + $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); + if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); $this->executeHooks($storyID); if($story->type == 'story') $this->batchChangeStage(array($storyID), $story->stage); @@ -1446,17 +1430,13 @@ class storyModel extends model ->checkIF($story->closedReason == 'duplicate', 'duplicateStory', 'notempty') ->where('id')->eq($storyID)->exec(); - $object = $this->getByID($storyID); $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); if(!empty($relation)) { $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); - if($singleIssue->state != 'closed') - { - if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); - } + if($singleIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); } /* Update parent story status. */ @@ -1526,17 +1506,11 @@ class storyModel extends model $this->setStage($storyID); $allChanges[$storyID] = common::createChanges($oldStory, $story); - $object = $this->getByID($storyID); $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); - if(!empty($relation)) { $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); - - if($singleIssue->state != 'closed') - { - if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); - } + if($singleIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); } } else @@ -1816,13 +1790,8 @@ class storyModel extends model if(!dao::isError()) { $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); - $attribute = $this->getByID($storyID); - $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $story->assignedTo); - if($attribute->assignee_id != '') - { - // TODO(dingguodong) we should alert to operator when can not find the user, and the operator should reconfigure user binding. - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $attribute); - } + $story->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $story->assignedTo); + if($story->assignee_id != '') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); return common::createChanges($oldStory, $story); } return false; @@ -1856,15 +1825,8 @@ class storyModel extends model if(!dao::isError()) { /* Push this story to gitlab issue. */ - $object = $this->getByID($storyID); - if(!empty($object)) - { - $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); - if($relation) - { - if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $object); - } - } + $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); + if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); } } return $allChanges; @@ -1900,6 +1862,10 @@ class storyModel extends model /* Update parent story status. */ if($oldStory->parent > 0) $this->updateParentStatus($storyID, $oldStory->parent); + /* Push this story to gitlab issue. */ + $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); + if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); + return common::createChanges($oldStory, $story); } diff --git a/module/task/model.php b/module/task/model.php index 55dd236b04..6692a859c7 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -948,18 +948,9 @@ class taskModel extends model ->batchCheckIF($task->closedReason == 'cancel', 'finishedBy, finishedDate', 'empty') ->where('id')->eq((int)$taskID)->exec(); - /* update story to gitlab issue. */ - $object = $this->getByID($taskID); - - if(!empty($object)) - { - $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); - if($relation) - { - if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $object); - } - - } + /* update story to gitlab issue. */ + $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); + if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); if(!dao::isError()) { @@ -1347,13 +1338,8 @@ class taskModel extends model ->where('id')->eq($taskID)->exec(); $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); - $attribute = $this->getByID($taskID); - $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $task->assignedTo); - if($attribute->assignee_id != '') - { - // TODO(dingguodong) we should alert to operator when can not find the user, and the operator should reconfigure user binding. - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, $attribute); - } + $task->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $task->assignedTo); + if($task->assignee_id != '') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, $task); if(!dao::isError()) return common::createChanges($oldTask, $task); } @@ -1695,12 +1681,7 @@ class taskModel extends model { $singleIssue = new stdclass(); $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); - - if($singleIssue->state != 'closed') - { - $object = $this->getByID($taskID); - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $object); - } + if($singleIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); } if($oldTask->parent > 0) $this->updateParentStatus($taskID); @@ -1759,17 +1740,13 @@ class taskModel extends model $this->dao->update(TABLE_TASK)->data($task)->autoCheck()->where('id')->eq((int)$taskID)->exec(); - $object = $this->getByID($bugID); $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); if(!empty($relation)) { $singleIssue = new stdclass(); $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); - if($singleIssue->state != 'closed') - { - if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $object); - } + if($singleIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $task); } if(!dao::isError()) @@ -1816,17 +1793,13 @@ class taskModel extends model } if($oldTask->story) $this->loadModel('story')->setStage($oldTask->story); - $object = $this->getByID($taskID); $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); if(!empty($relation)) { $singleIssue = new stdclass(); $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); - if($singleIssue->state != 'closed') - { - if(!empty($object)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $object); - } + if($singleIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); } if(!dao::isError()) return common::createChanges($oldTask, $task); @@ -1893,6 +1866,10 @@ class taskModel extends model $this->computeWorkingHours($taskID); } if($oldTask->story) $this->loadModel('story')->setStage($oldTask->story); + + $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); + if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); + if(!dao::isError()) return common::createChanges($oldTask, $task); } From d241e218ce54cc1c696d58eb4cb8accf47a79457 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 6 Jul 2021 17:35:02 +0800 Subject: [PATCH 231/269] * Finished import gitlab issue to task. --- module/gitlab/control.php | 19 ++++++++++++------- module/gitlab/lang/zh-cn.php | 7 ++++--- module/gitlab/model.php | 3 ++- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 744927264d..5dfc931326 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -274,9 +274,7 @@ class gitlab extends control if($executionID) { $objectType = $this->config->gitlab->objectTypes[$objectTypeList[$issueID]]; - $issue = $this->gitlab->apiGetSingleIssue($gitlabID, $projectID, $issueID); - $originalIssue = $issue; $issue->objectType = $objectType; $issue->objectID = 0; // meet the required parameters for issueToZentaoObject. if(isset($issue->assignee)) $issue->assignee_id = $issue->assignee->id; @@ -296,17 +294,24 @@ class gitlab extends control { } - $object->id = $objectID; - $this->gitlab->saveImportedIssue($gitlabID, $projectID, $objectType, $objectID, $originalIssue, $object); + $object->id = $objectID; + $object->product = $productList[$issueID]; + $object->execution = $executionID; + $this->gitlab->saveImportedIssue($gitlabID, $projectID, $objectType, $objectID, $issue, $object); - } + } + else + { + if($productList[$issueID] != 0) $this->send(array('result' => 'fail', 'message' => $this->lang->gitlab->importIssueError, 'locate' => $this->server->http_referer)); + } } $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->server->http_referer)); } $savedIssueIDList = $this->dao->select('BID as issueID')->from(TABLE_RELATION) - ->where('relation')->eq('gitlab') - ->fetchAll('issueID'); + ->where('relation')->eq('gitlab') + ->andWhere('product')->in($productIDList) + ->fetchAll('issueID'); $iids = ''; foreach($savedIssueIDList as $savedIssueID) $iids = $iids . $savedIssueID->issueID . ','; $options = '¬[iids]=' . trim($iids, ','); diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index abe00b1b5e..6c5e6ad25d 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -36,6 +36,7 @@ $lang->gitlab->placeholder->name = ''; $lang->gitlab->placeholder->url = "请填写Gitlab Server首页的访问地址,如:https://gitlab.zentao.net。"; $lang->gitlab->placeholder->token = "请填写具有admin权限账户的access token"; -$lang->gitlab->tokenError = "当前token非管理员权限。"; -$lang->gitlab->hostError = "无效的gitlab服务地址。"; -$lang->gitlab->bindUserError = "不能重复绑定用户 %s"; +$lang->gitlab->tokenError = "当前token非管理员权限。"; +$lang->gitlab->hostError = "无效的gitlab服务地址。"; +$lang->gitlab->bindUserError = "不能重复绑定用户 %s"; +$lang->gitlab->importIssueError = "未选择该议题所属的执行。"; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index b0e9a61cd1..4d2ebd3370 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -543,7 +543,7 @@ class gitlabModel extends model */ public function apiGetSingleIssue($gitlabID, $projectID, $issueID) { - $url = sprintf($this->getApiRoot($gitlabID), "/issues/{$issueID}"); + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/issues/{$issueID}"); return json_decode(commonModel::http($url)); } @@ -907,6 +907,7 @@ class gitlabModel extends model if(empty($issue->iid) or empty($issue->project_id)) return false; $relation = new stdclass; + $relation->product = zget($object, 'product', 0); $relation->execution = zget($object, 'execution', 0); $relation->AType = $objectType; $relation->AID = $object->id; From 83d23a312c1162dee68e06d2e6e509adafaaf4f0 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Wed, 7 Jul 2021 09:44:16 +0800 Subject: [PATCH 232/269] * Add getIssueListByObjects function. --- module/gitlab/model.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 11bd3bcabd..639b7cceb6 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -216,6 +216,24 @@ class gitlabModel extends model ->fetch(); } + /** + * Get issue id list group by obejct. + * + * @param string $objectType + * @param int $objectID + * @access public + * @return object + */ + public function getIssueListByObjects($objectType, $objects) + { + return $this->dao->select('*, extra as gitlabID, BVersion as projectID, BID as issueID')->from(TABLE_RELATION) + ->where('relation')->eq('gitlab') + ->andWhere('Atype')->eq($objectType) + ->andWhere('AID')->in($objects) + ->fetchAll('AID'); + } + + /** * Get gitlab userID by account. * From e5df582bd7853e57588515ec149cb765c201460e Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Wed, 7 Jul 2021 09:46:16 +0800 Subject: [PATCH 233/269] * Fix sync task changes to issue function. --- module/task/model.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/module/task/model.php b/module/task/model.php index 55dd236b04..1eb25b0580 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -1191,6 +1191,14 @@ class taskModel extends model $tasks[$taskID] = $task; } + $issues = $this->loadModel('gitlab')->getIssueListByObjects('task', $taskID); + foreach($tasks as $taskID => $task) + { + $issue = zget($issues, $taskID, 0); + if(!$issue) continue; + $this->loadModel('gitlab')->apiUpdateIssue($issue->gitlabID, $issue->projectID, $issue->issueID, $task); + } + /* Check field not empty. */ foreach($tasks as $taskID => $task) { @@ -1347,13 +1355,9 @@ class taskModel extends model ->where('id')->eq($taskID)->exec(); $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); - $attribute = $this->getByID($taskID); - $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $task->assignedTo); - if($attribute->assignee_id != '') - { - // TODO(dingguodong) we should alert to operator when can not find the user, and the operator should reconfigure user binding. - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, $attribute); - } + $task = $this->getByID($taskID); + // TODO(dingguodong) we should alert to operator when can not find the user, and the operator should reconfigure user binding. + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); if(!dao::isError()) return common::createChanges($oldTask, $task); } From b6192eb928eecd012e974aa4c1d212686220f36e Mon Sep 17 00:00:00 2001 From: lichengjun Date: Wed, 7 Jul 2021 16:35:21 +0800 Subject: [PATCH 234/269] * Add bug,task,story,model. --- module/bug/control.php | 9 +++++++++ module/bug/model.php | 25 +++++++++++++++++++++++-- module/story/model.php | 4 ++++ module/task/control.php | 6 ++++++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/module/bug/control.php b/module/bug/control.php index 9594fcfbce..27feba41db 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -1464,6 +1464,15 @@ class bug extends control $bugs = $this->bug->getByList($bugIDList); foreach($bugs as $bugID => $bug) { + $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); + if(!empty($relation)) + { + $singleIssue = new stdclass(); + $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); + + if($singleIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); + } + if($bug->status != 'resolved') { if($bug->status != 'closed') $skipBugs[$bugID] = $bugID; diff --git a/module/bug/model.php b/module/bug/model.php index 41a888416e..e5ff470a36 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -89,8 +89,7 @@ class bugModel extends model { $bugID = $this->dao->lastInsertID(); - $object = $this->getByID($bugID); - $this->loadModel('gitlab')->apiCreateIssue($this->post->gitlab, $this->post->gitlabProject, 'bug', $bugID, $object); + $this->loadModel('gitlab')->apiCreateIssue($this->post->gitlab, $this->post->gitlabProject, 'bug', $bugID, $bug); $this->file->updateObjectID($this->post->uid, $bugID, 'bug'); $this->file->saveUpload('bug', $bugID); @@ -824,6 +823,12 @@ class bugModel extends model /* Update bugs. */ foreach($activateBugs as $bugID => $bug) { + if(!empty($bug)) + { + $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', (Object)$bug); + } + $oldBug = $bugs[$bugID]; $this->dao->update(TABLE_BUG)->data($bug, $skipFields = 'comment')->autoCheck()->where('id')->eq((int)$bugID)->exec(); if(dao::isError()) die(js::error('bug#' . $bugID . dao::getError(true))); @@ -920,6 +925,12 @@ class bugModel extends model $bug->lastEditedDate = $now; $bug->confirmed = 1; + if(!empty($bug)) + { + $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); + } + $this->dao->update(TABLE_BUG)->data($bug)->where('id')->eq($bugID)->exec(); $this->executeHooks($bugID); } @@ -1143,6 +1154,10 @@ class bugModel extends model $this->dao->update(TABLE_BUG)->data($bug)->where('id')->eq($bugID)->exec(); $this->executeHooks($bugID); + /* batch resolve issure bugs.*/ + $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); + $changes[$bugID] = common::createChanges($oldBug, $bug); } @@ -1200,6 +1215,12 @@ class bugModel extends model } } + if(!empty($bug)) + { + $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); + } + $bug->activatedCount += 1; return common::createChanges($oldBug, $bug); } diff --git a/module/story/model.php b/module/story/model.php index 4de8a83290..a5ed11130f 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -1824,6 +1824,10 @@ class storyModel extends model $this->dao->update(TABLE_STORY)->data($story)->autoCheck()->where('id')->eq((int)$storyID)->exec(); if(!dao::isError()) { + $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); + $story->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $story->assignedTo); + if($story->assignee_id != '') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); + /* Push this story to gitlab issue. */ $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); diff --git a/module/task/control.php b/module/task/control.php index f8b75ec28d..fa9dc689ac 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -572,6 +572,9 @@ class task extends control $task = $this->task->getByID($taskID); + $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); + $members = $this->loadModel('user')->getTeamMemberPairs($executionID, 'execution', 'nodeleted'); /* Compute next assignedTo. */ @@ -645,6 +648,9 @@ class task extends control if(isset($muletipleTasks[$taskID]) and $task->assignedTo != $this->app->user->account) continue; if(isset($muletipleTasks[$taskID]) and !isset($muletipleTasks[$taskID][$this->post->assignedTo])) continue; + $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); + $changes = $this->task->assign($taskID); if(dao::isError()) die(js::error(dao::getError())); $actionID = $this->action->create('task', $taskID, 'Assigned', $this->post->comment, $this->post->assignedTo); From e9bcb88d9edb3949c3b0f98a0d9f7eb47193c5c6 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 7 Jul 2021 17:09:04 +0800 Subject: [PATCH 235/269] * Rename saveSyncedIssue to saveIssueRelation, add func doc. --- module/gitlab/control.php | 2 +- module/gitlab/model.php | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 5dfc931326..0a1b249532 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -247,7 +247,7 @@ class gitlab extends control a($relations);exit; $issue = $this->gitlab->taskToIssue($gitlabID, $projectID, $task); $issue = $this->gitlab->apiCreateIssue($gitlabID, $projectID, $issue); - $this->gitlab->saveSyncedIssue('task', $task, $gitlabID, $issue); + $this->gitlab->saveIssueRelation('task', $task, $gitlabID, $issue); exit; } diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 85dce8be52..dc541da4eb 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -546,6 +546,15 @@ class gitlabModel extends model return json_decode(commonModel::http($url)); } + /** + * Get gitlab issues by api. + * + * @param int $gitlabID + * @param int $projectID + * @param string $options + * @access public + * @return object + */ public function apiGetIssues($gitlabID, $projectID, $options = null) { // TODO(dingguodong) not pagination yet. @@ -588,7 +597,7 @@ class gitlabModel extends model $response = json_decode(commonModel::http($url, $issue)); if(!$response) return false; - return $this->saveSyncedIssue($objectType, $object, $gitlabID, $response); + return $this->saveIssueRelation($objectType, $object, $gitlabID, $response); } /** @@ -901,7 +910,7 @@ class gitlabModel extends model * @access public * @return void */ - public function saveSyncedIssue($objectType, $object, $gitlabID, $issue) + public function saveIssueRelation($objectType, $object, $gitlabID, $issue) { if(empty($issue->iid) or empty($issue->project_id)) return false; @@ -939,7 +948,7 @@ class gitlabModel extends model $apiRoot = $this->getApiRoot($gitlabID); $url = sprintf($apiRoot, "/projects/{$projectID}/issues/{$issue->iid}"); commonModel::http($url, $data, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT')); - $this->saveSyncedIssue($objectType, $object, $gitlabID, $issue); + $this->saveIssueRelation($objectType, $object, $gitlabID, $issue); } /** From 47e3c473a1d6c084e3cf146947499954b3eb963e Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 7 Jul 2021 17:16:06 +0800 Subject: [PATCH 236/269] * Put strings in long line to config file. --- module/task/config.php | 1 + module/task/model.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/module/task/config.php b/module/task/config.php index 5db5eb88ae..ab950c3b2e 100644 --- a/module/task/config.php +++ b/module/task/config.php @@ -26,6 +26,7 @@ $config->task->editor->activate = array('id' => 'comment', 'tools' => 'simpleToo $config->task->editor->cancel = array('id' => 'comment', 'tools' => 'simpleTools'); $config->task->editor->pause = array('id' => 'comment', 'tools' => 'simpleTools'); +$config->task->removeFields = 'objectTypeList,productList,executionList,gitlabID,gitlabProjectID,after,files,labels,assignedTo,uid,storyEstimate,storyDesc,storyPri,team,teamEstimate,teamMember,multiple,teams,contactListMenu,selectTestStory,testStory,testPri,testEstStarted,testDeadline,testAssignedTo,testEstimate,sync'; $config->task->exportFields = ' id, execution, module, story, name, desc, diff --git a/module/task/model.php b/module/task/model.php index 62890a2386..770e973774 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -489,7 +489,7 @@ class taskModel extends model ->cleanINT('execution,story,module') ->stripTags($this->config->task->editor->create['id'], $this->config->allowedTags) ->join('mailto', ',') - ->remove('objectTypeList,productList,executionList,gitlabID,gitlabProjectID,after,files,labels,assignedTo,uid,storyEstimate,storyDesc,storyPri,team,teamEstimate,teamMember,multiple,teams,contactListMenu,selectTestStory,testStory,testPri,testEstStarted,testDeadline,testAssignedTo,testEstimate,sync') + ->remove($this->config->task->removeFields) ->add('version', 1) ->get(); From b42bc4afc977e6e4dbd99b61ac60f3dfed640392 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 7 Jul 2021 17:29:53 +0800 Subject: [PATCH 237/269] * Optimize url parameter. --- config/filter.php | 1 + module/gitlab/control.php | 8 ++++---- module/repo/view/maintain.html.php | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/config/filter.php b/config/filter.php index 7460c2a0da..42bd625242 100644 --- a/config/filter.php +++ b/config/filter.php @@ -321,4 +321,5 @@ $filter->gitlab->importissue->get['gitlab'] = 'int'; $filter->gitlab->importissue->get['product'] = 'int'; $filter->gitlab->importissue->get['product'] = 'string'; $filter->gitlab->importissue->get['project'] = 'int'; +$filter->gitlab->importissue->get['repo'] = 'int'; diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 0a1b249532..0fa6a04612 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -259,10 +259,10 @@ class gitlab extends control */ public function importIssue() { - $productIDList = explode(',', $this->get->product); - $gitlabID = $this->get->gitlab; - $projectID = $this->get->project; - + $repo = $this->loadModel('repo')->getRepoByID($this->get->repo); + $productIDList = explode(',', $repo->product); + $gitlabID = $repo->gitlab; + $projectID = $repo->project; if($_POST) { diff --git a/module/repo/view/maintain.html.php b/module/repo/view/maintain.html.php index d59a9a4186..4f754db09f 100644 --- a/module/repo/view/maintain.html.php +++ b/module/repo/view/maintain.html.php @@ -49,7 +49,7 @@ From 90d5f86b612bc13799262ef5389a9694201639f1 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Wed, 7 Jul 2021 17:41:07 +0800 Subject: [PATCH 238/269] * Fix close funciton code. --- module/bug/control.php | 6 ++---- module/bug/model.php | 9 ++------- module/gitlab/model.php | 2 +- module/story/model.php | 9 ++++----- module/task/model.php | 17 ++++++----------- 5 files changed, 15 insertions(+), 28 deletions(-) diff --git a/module/bug/control.php b/module/bug/control.php index 27feba41db..3f87585bcb 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -1467,10 +1467,8 @@ class bug extends control $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); if(!empty($relation)) { - $singleIssue = new stdclass(); - $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); - - if($singleIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); + $currentIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->projectID, $relation->issueID); + if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); } if($bug->status != 'resolved') diff --git a/module/bug/model.php b/module/bug/model.php index e5ff470a36..d9e90aff41 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -1253,13 +1253,8 @@ class bugModel extends model $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); if(!empty($relation)) { - $singleIssue = new stdclass(); - $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); - - if($singleIssue->state != 'closed') - { - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); - } + $currentIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->projectID, $relation->issueID); + if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); } return common::createChanges($oldBug, $bug); } diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 85dce8be52..2a5808df8a 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -543,7 +543,7 @@ class gitlabModel extends model public function apiGetSingleIssue($gitlabID, $projectID, $issueID) { $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/issues/{$issueID}"); - return json_decode(commonModel::http($url)); + $aaa = json_decode(commonModel::http($url)); } public function apiGetIssues($gitlabID, $projectID, $options = null) diff --git a/module/story/model.php b/module/story/model.php index a5ed11130f..9e998cb7b8 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -1434,9 +1434,8 @@ class storyModel extends model if(!empty($relation)) { - $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); - - if($singleIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); + $currentIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->projectID, $relation->issueID); + if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); } /* Update parent story status. */ @@ -1509,8 +1508,8 @@ class storyModel extends model $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); if(!empty($relation)) { - $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); - if($singleIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); + $currentIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->projectID, $relation->issueID); + if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); } } else diff --git a/module/task/model.php b/module/task/model.php index 62890a2386..8b2c30ba8f 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -1730,9 +1730,8 @@ class taskModel extends model $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); if(!empty($relation)) { - $singleIssue = new stdclass(); - $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); - if($singleIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); + $currentIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->projectID, $relation->issueID); + if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); } if($oldTask->parent > 0) $this->updateParentStatus($taskID); @@ -1794,10 +1793,8 @@ class taskModel extends model $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); if(!empty($relation)) { - $singleIssue = new stdclass(); - $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); - - if($singleIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $task); + $currentIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->projectID, $relation->issueID); + if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $task); } if(!dao::isError()) @@ -1847,10 +1844,8 @@ class taskModel extends model $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); if(!empty($relation)) { - $singleIssue = new stdclass(); - $singleIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->issueID); - - if($singleIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); + $currentIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->projectID, $relation->issueID); + if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); } if(!dao::isError()) return common::createChanges($oldTask, $task); From de848b9faf23f0ffb68b44f0e17368ac7f52fd44 Mon Sep 17 00:00:00 2001 From: lichengjun Date: Thu, 8 Jul 2021 09:29:29 +0800 Subject: [PATCH 239/269] * Fix code format. --- module/gitlab/model.php | 4 ++-- module/task/control.php | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 1108b86548..85dc58983d 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -543,7 +543,7 @@ class gitlabModel extends model public function apiGetSingleIssue($gitlabID, $projectID, $issueID) { $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/issues/{$issueID}"); - $aaa = json_decode(commonModel::http($url)); + return json_decode(commonModel::http($url)); } /** @@ -583,7 +583,7 @@ class gitlabModel extends model public function apiCreateIssue($gitlabID, $projectID, $objectType, $objectID, $object) { $label = $this->createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID); - + if(!isset($object->id)) $object->id = $objectID; $issue = $this->loadModel('gitlab')->parseObjectToIssue($gitlabID, $projectID, $objectType, $object); if(isset($label->name)) $issue->labels = $label->name; foreach($this->config->gitlab->skippedFields->issueCreate[$objectType] as $field) diff --git a/module/task/control.php b/module/task/control.php index fa9dc689ac..5ec982cb8d 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -649,8 +649,7 @@ class task extends control if(isset($muletipleTasks[$taskID]) and !isset($muletipleTasks[$taskID][$this->post->assignedTo])) continue; $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); - + if(!empty($task))$this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); $changes = $this->task->assign($taskID); if(dao::isError()) die(js::error(dao::getError())); $actionID = $this->action->create('task', $taskID, 'Assigned', $this->post->comment, $this->post->assignedTo); From 882f7195fdde44e7dd64aaaaaa13d93a786d677f Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 8 Jul 2021 10:54:23 +0800 Subject: [PATCH 240/269] * Keep uniformed style for fixer removal action. --- module/task/config.php | 2 +- module/task/model.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/module/task/config.php b/module/task/config.php index ab950c3b2e..cb5c12a616 100644 --- a/module/task/config.php +++ b/module/task/config.php @@ -26,7 +26,7 @@ $config->task->editor->activate = array('id' => 'comment', 'tools' => 'simpleToo $config->task->editor->cancel = array('id' => 'comment', 'tools' => 'simpleTools'); $config->task->editor->pause = array('id' => 'comment', 'tools' => 'simpleTools'); -$config->task->removeFields = 'objectTypeList,productList,executionList,gitlabID,gitlabProjectID,after,files,labels,assignedTo,uid,storyEstimate,storyDesc,storyPri,team,teamEstimate,teamMember,multiple,teams,contactListMenu,selectTestStory,testStory,testPri,testEstStarted,testDeadline,testAssignedTo,testEstimate,sync'; +$config->task->removeFields = 'objectTypeList,productList,executionList,gitlabID,gitlabProjectID'; $config->task->exportFields = ' id, execution, module, story, name, desc, diff --git a/module/task/model.php b/module/task/model.php index b83c8b74f7..a9615b9f59 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -489,6 +489,7 @@ class taskModel extends model ->cleanINT('execution,story,module') ->stripTags($this->config->task->editor->create['id'], $this->config->allowedTags) ->join('mailto', ',') + ->remove('after,files,labels,assignedTo,uid,storyEstimate,storyDesc,storyPri,team,teamEstimate,teamMember,multiple,teams,contactListMenu,selectTestStory,testStory,testPri,testEstStarted,testDeadline,testAssignedTo,testEstimate,sync') ->remove($this->config->task->removeFields) ->add('version', 1) ->get(); From 832e9b1cf1fc256fdf770a36b67d383bd60b0e0e Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 8 Jul 2021 11:25:14 +0800 Subject: [PATCH 241/269] * Optimize code when value is null. --- module/gitlab/model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 85dc58983d..f4cba5b9c2 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -1154,8 +1154,8 @@ class gitlabModel extends model if(!isset($changes->$gitlabField) and $object->id != 0) continue; if($optionType == 'field') $value = $issue->$gitlabField; if($optionType == 'field') $value = $issue->$gitlabField; - if($options == 'date') $value = date('Y-m-d', strtotime($value)); - if($options == 'datetime') $value = date('Y-m-d H:i:s', strtotime($value)); + if($options == 'date') $value = $value ? date('Y-m-d', strtotime($value)) : '0000-00-00'; + if($options == 'datetime') $value = $value ? date('Y-m-d H:i:s', strtotime($value)) : '0000-00-00 00:00:00'; if($optionType == 'userPairs' and isset($issue->$gitlabField)) $value = zget($gitlabUsers, $issue->$gitlabField); if($optionType == 'configItems' and isset($issue->$gitlabField)) $value = array_search($issue->$gitlabField, $this->config->gitlab->$options); if($value) $object->$zentaoField = $value; From 129e14bf30be90d86d2bf04782b210fa5ed97db7 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 8 Jul 2021 14:30:28 +0800 Subject: [PATCH 242/269] * Finish importing issue to zentao bug(staging). --- module/bug/config.php | 1 + module/bug/model.php | 45 ++++++++++++++++++++++++++++++++++++ module/gitlab/config.php | 1 + module/gitlab/control.php | 22 ++++++++++++++---- module/gitlab/lang/zh-cn.php | 1 + 5 files changed, 65 insertions(+), 5 deletions(-) diff --git a/module/bug/config.php b/module/bug/config.php index ab1efb6707..bc508859ab 100644 --- a/module/bug/config.php +++ b/module/bug/config.php @@ -2,6 +2,7 @@ $config->bug = new stdClass(); $config->bug->batchCreate = 10; $config->bug->longlife = 7; +$config->bug->removeFields= 'objectTypeList,productList,executionList,gitlabID,gitlabProjectID'; $config->bug->create = new stdclass(); $config->bug->edit = new stdclass(); diff --git a/module/bug/model.php b/module/bug/model.php index d9e90aff41..d481824988 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -273,6 +273,51 @@ class bugModel extends model return $actions; } + /** + * Create bug from gitlab issue. + * + * @param object $bug + * @param int $executionID + * @access public + * @return int + */ + public function createBugFromGitlabIssue($bug, $executionID) + { + foreach($bug as $feild => $value) $_POST[$feild] = $value; + $now = helper::now(); + $bug = fixer::input('post') + ->setDefault('openedBy', $this->app->user->account) + ->setDefault('openedDate', $now) + ->setDefault('project,execution,story,task', 0) + ->setDefault('openedBuild', '1') // todo(dingguodong) openedBuild is hard-coded. + ->setDefault('deadline', '0000-00-00') + ->setIF($this->config->systemMode == 'new' && $this->lang->navGroup->bug != 'qa', 'project', $this->session->project) + ->setIF(strpos($this->config->bug->create->requiredFields, 'deadline') !== false, 'deadline', $bug->deadline) + ->setIF(isset($bug->assignedTo) and $bug->assignedTo != '', 'assignedDate', $now) + ->stripTags($this->config->bug->editor->create['id'], $this->config->allowedTags) + ->cleanInt('product,execution,module,severity') + ->join('openedBuild', ',') + ->join('mailto', ',') + ->remove('files, labels,uid,oldTaskID,contactListMenu') + ->remove($this->config->bug->removeFields) + ->get(); + + if($executionID != 0) + { + $bug->project = $this->dao->select('parent')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch('parent'); + $bug->execution = $executionID; + } + + $this->dao->insert(TABLE_BUG)->data($bug, $skip = 'gitlab,gitlabProject')->autoCheck()->batchCheck($this->config->bug->create->requiredFields, 'notempty')->exec(); + if(!dao::isError()) + { + $bugID = $this->dao->lastInsertID(); + return $bugID; + } + + return false; + } + /** * Get bugs. * diff --git a/module/gitlab/config.php b/module/gitlab/config.php index f3fff35b4d..84ee284a8d 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -55,6 +55,7 @@ $config->gitlab->maps->bug = array(); $config->gitlab->maps->bug['title'] = 'title|field|'; $config->gitlab->maps->bug['steps'] = 'description|field|'; $config->gitlab->maps->bug['openedDate'] = 'created_at|field|datetime'; +$config->gitlab->maps->bug['deadline'] = 'due_date|field|date'; $config->gitlab->maps->bug['assignedTo'] = 'assignee_id|userPairs|'; $config->gitlab->maps->bug['status'] = 'state|configItems|bugStateMap'; $config->gitlab->maps->bug['pri'] = 'weight|configItems|bugWeightMap'; diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 0fa6a04612..11a3aed968 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -269,6 +269,8 @@ class gitlab extends control $executionList = $this->post->executionList; $objectTypeList = $this->post->objectTypeList; $productList = $this->post->productList; + + $failedIssues = array(); foreach($executionList as $issueID => $executionID) { if($executionID) @@ -281,6 +283,8 @@ class gitlab extends control $issue->updated_by_id = $issue->author->id; // here can be replaced by current zentao user. $object = $this->gitlab->issueToZentaoObject($issue, $gitlabID); + $object->product = $productList[$issueID]; + $object->execution = $executionID; if($objectType == 'task') { $objectID = $this->loadModel('task')->createTaskFromGitlabIssue($object, $executionID); @@ -288,23 +292,31 @@ class gitlab extends control if($objectType == 'bug') { + $objectID = $this->loadModel('bug')->createBugFromGitlabIssue($object, $executionID); } if($objectType == 'story') { + $objectID = $this->loadModel('story')->createStoryFromGitlabIssue($object, $executionID); } - - $object->id = $objectID; - $object->product = $productList[$issueID]; - $object->execution = $executionID; - $this->gitlab->saveImportedIssue($gitlabID, $projectID, $objectType, $objectID, $issue, $object); + if($objectID) + { + $object->id = $objectID; + $this->gitlab->saveImportedIssue($gitlabID, $projectID, $objectType, $objectID, $issue, $object); + } + else + { + $failedIssues[] = $issue->iid; + } } else { if($productList[$issueID] != 0) $this->send(array('result' => 'fail', 'message' => $this->lang->gitlab->importIssueError, 'locate' => $this->server->http_referer)); } } + + if($failedIssues) $this->send(array('result' => 'success', 'message' => $this->lang->gitlab->importIssueWarn, 'locate' => $this->server->http_referer)); $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->server->http_referer)); } diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index 6c5e6ad25d..e2df334a72 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -40,3 +40,4 @@ $lang->gitlab->tokenError = "当前token非管理员权限。"; $lang->gitlab->hostError = "无效的gitlab服务地址。"; $lang->gitlab->bindUserError = "不能重复绑定用户 %s"; $lang->gitlab->importIssueError = "未选择该议题所属的执行。"; +$lang->gitlab->importIssueWarn = "存在导入失败的议题,可再次尝试导入。"; From 5c25aba4c664ecf74266de1f190942791352289e Mon Sep 17 00:00:00 2001 From: lichengjun Date: Thu, 8 Jul 2021 14:46:27 +0800 Subject: [PATCH 243/269] * Fix task code bug. --- module/task/control.php | 4 +--- module/task/model.php | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/module/task/control.php b/module/task/control.php index 5ec982cb8d..64da0f0f6a 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -647,9 +647,7 @@ class task extends control { if(isset($muletipleTasks[$taskID]) and $task->assignedTo != $this->app->user->account) continue; if(isset($muletipleTasks[$taskID]) and !isset($muletipleTasks[$taskID][$this->post->assignedTo])) continue; - - $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); - if(!empty($task))$this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); + $changes = $this->task->assign($taskID); if(dao::isError()) die(js::error(dao::getError())); $actionID = $this->action->create('task', $taskID, 'Assigned', $this->post->comment, $this->post->assignedTo); diff --git a/module/task/model.php b/module/task/model.php index b83c8b74f7..a17ae4b1a9 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -1389,8 +1389,7 @@ class taskModel extends model ->where('id')->eq($taskID)->exec(); $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); - $task->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $task->assignedTo); - if($task->assignee_id != '') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, $task); + if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $oldTask); if(!dao::isError()) return common::createChanges($oldTask, $task); } From 9e76157a0c228c9e248ab668ecdaab8db359fb5e Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 8 Jul 2021 14:54:18 +0800 Subject: [PATCH 244/269] * Put product into removal field and bug fix. --- module/task/config.php | 2 +- module/task/model.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/module/task/config.php b/module/task/config.php index cb5c12a616..67fe4ffabc 100644 --- a/module/task/config.php +++ b/module/task/config.php @@ -26,7 +26,7 @@ $config->task->editor->activate = array('id' => 'comment', 'tools' => 'simpleToo $config->task->editor->cancel = array('id' => 'comment', 'tools' => 'simpleTools'); $config->task->editor->pause = array('id' => 'comment', 'tools' => 'simpleTools'); -$config->task->removeFields = 'objectTypeList,productList,executionList,gitlabID,gitlabProjectID'; +$config->task->removeFields = 'objectTypeList,productList,executionList,gitlabID,gitlabProjectID,product'; $config->task->exportFields = ' id, execution, module, story, name, desc, diff --git a/module/task/model.php b/module/task/model.php index a9615b9f59..fc82302bc5 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -1391,7 +1391,7 @@ class taskModel extends model $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); $task->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $task->assignedTo); - if($task->assignee_id != '') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, $task); + if($task->assignee_id != '') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); if(!dao::isError()) return common::createChanges($oldTask, $task); } From 6af64c8c1273e7b08c84a3c2d634c92abbcf4bc3 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 8 Jul 2021 15:51:50 +0800 Subject: [PATCH 245/269] * Change variable name and add a todo for issueToZentaoObject. --- module/gitlab/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index f4cba5b9c2..991f7621cc 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -1153,7 +1153,7 @@ class gitlabModel extends model list($gitlabField, $optionType, $options) = explode('|', $config); if(!isset($changes->$gitlabField) and $object->id != 0) continue; if($optionType == 'field') $value = $issue->$gitlabField; - if($optionType == 'field') $value = $issue->$gitlabField; + if($optionType == 'fields') $value = $issue->$gitlabField; // TODO(dingguodong) not implemented. if($options == 'date') $value = $value ? date('Y-m-d', strtotime($value)) : '0000-00-00'; if($options == 'datetime') $value = $value ? date('Y-m-d H:i:s', strtotime($value)) : '0000-00-00 00:00:00'; if($optionType == 'userPairs' and isset($issue->$gitlabField)) $value = zget($gitlabUsers, $issue->$gitlabField); From 47102c509e47f9dd36003f47f55a1bb376bf9e7e Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 8 Jul 2021 15:55:11 +0800 Subject: [PATCH 246/269] + Finished importing issue to story. --- module/gitlab/control.php | 3 ++- module/story/config.php | 2 +- module/story/model.php | 52 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 11a3aed968..076f7e86e8 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -285,6 +285,7 @@ class gitlab extends control $object = $this->gitlab->issueToZentaoObject($issue, $gitlabID); $object->product = $productList[$issueID]; $object->execution = $executionID; + if($objectType == 'task') { $objectID = $this->loadModel('task')->createTaskFromGitlabIssue($object, $executionID); @@ -302,7 +303,7 @@ class gitlab extends control if($objectID) { - $object->id = $objectID; + $object->id = $objectID; $this->gitlab->saveImportedIssue($gitlabID, $projectID, $objectType, $objectID, $issue, $object); } else diff --git a/module/story/config.php b/module/story/config.php index 5db4554810..985210da95 100644 --- a/module/story/config.php +++ b/module/story/config.php @@ -4,10 +4,10 @@ $config->story = new stdclass(); $config->story->batchCreate = 10; $config->story->affectedFixedNum = 7; $config->story->needReview = 1; +$config->story->removeFields = 'objectTypeList,productList,executionList,gitlabID,gitlabProjectID,execution'; $config->story->batchClose = new stdclass(); $config->story->batchClose->columns = 10; - $config->story->create = new stdclass(); $config->story->edit = new stdclass(); $config->story->change = new stdclass(); diff --git a/module/story/model.php b/module/story/model.php index 9e998cb7b8..5b69837f8f 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -216,7 +216,7 @@ class storyModel extends model /* Check repeat story. */ $result = $this->loadModel('common')->removeDuplicate('story', $story, "product={$story->product}"); - if($result['stop']) return array('status' => 'exists', 'id' => $result['duplicate']); + if(isset($result['stop']) and $result['stop']) return array('status' => 'exists', 'id' => $result['duplicate']); if($this->checkForceReview()) $story->status = 'draft'; if($story->status == 'draft') $story->stage = $this->post->plan > 0 ? 'planned' : 'wait'; @@ -348,6 +348,56 @@ class storyModel extends model return false; } + /** + * Create story from gitlab issue. + * + * @param object $story + * @param int $executionID + * @access public + * @return int + */ + public function createStoryFromGitlabIssue($story, $executionID) + { + foreach($story as $feild => $value) $_POST[$feild] = $value; + $now = helper::now(); + $story = fixer::input('post') + ->cleanInt('product,module,pri,plan') + ->callFunc('title', 'trim') + ->add('assignedDate', 0) + ->add('version', 1) + ->add('status', 'draft') + ->setDefault('plan,verify', '') + ->setDefault('openedBy', $this->app->user->account) + ->setDefault('openedDate', $now) + ->setIF($story->assignedTo != '', 'assignedDate', $now) + ->setIF($executionID > 0, 'status', 'active') + ->setIF($executionID > 0, 'stage', 'projected') + ->join('mailto', ',') + ->stripTags($this->config->story->editor->create['id'], $this->config->allowedTags) + ->remove('files,labels,reviewer,needNotReview,newStory,uid,contactListMenu,URS') + ->remove($this->config->story->removeFields) + ->get(); + + $requiredFields = $this->config->story->create->requiredFields; + $this->dao->insert(TABLE_STORY)->data($story, 'spec,verify,gitlab,gitlabProject')->autoCheck()->batchCheck($requiredFields, 'notempty')->exec(); + if(!dao::isError()) + { + $storyID = $this->dao->lastInsertID(); + + $data = new stdclass(); + $data->story = $storyID; + $data->version = 1; + $data->title = $story->title; + $data->spec = $story->spec; + $data->verify = $story->spec; + $this->dao->insert(TABLE_STORYSPEC)->data($data)->exec(); + + return $storyID; + } + + return false; + } + /** * Batch create stories. * From 22eeab384a4fd65609dfc496b71e67105baf7044 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 8 Jul 2021 16:07:58 +0800 Subject: [PATCH 247/269] * Change per_page value to 20. --- module/gitlab/model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 991f7621cc..d7fa2b393e 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -560,11 +560,11 @@ class gitlabModel extends model // TODO(dingguodong) not pagination yet. if($options) { - $url = sprintf($this->getApiRoot($gitlabID), "/projects/{$projectID}/issues") . '&per_page=100' . $options; + $url = sprintf($this->getApiRoot($gitlabID), "/projects/{$projectID}/issues") . '&per_page=20' . $options; } else { - $url = sprintf($this->getApiRoot($gitlabID), "/projects/{$projectID}/issues") . '&per_page=100'; + $url = sprintf($this->getApiRoot($gitlabID), "/projects/{$projectID}/issues") . '&per_page=20'; } return json_decode(commonModel::http($url)); } From 7bf0789e54ba969ad1aa1e83c6b7b2b680e2f150 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 8 Jul 2021 17:35:55 +0800 Subject: [PATCH 248/269] * Rename zt_jenkins to zt_pipeline. --- db/standard/zentao15.0.rc3.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/standard/zentao15.0.rc3.sql b/db/standard/zentao15.0.rc3.sql index d59660d05a..68b0271093 100644 --- a/db/standard/zentao15.0.rc3.sql +++ b/db/standard/zentao15.0.rc3.sql @@ -447,7 +447,7 @@ CREATE TABLE `zt_history` ( PRIMARY KEY (`id`), KEY `action` (`action`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -CREATE TABLE `zt_jenkins` ( +CREATE TABLE `zt_pipeline` ( `id` smallint(8) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, `url` varchar(255) DEFAULT NULL, From 14d78cca44f711485dcb638ccfbe46f47114ef51 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 9 Jul 2021 10:15:04 +0800 Subject: [PATCH 249/269] * Construct object manually instead of using fixer. --- module/bug/model.php | 29 +++++------------------------ module/story/model.php | 25 ++++++------------------- module/task/model.php | 40 +++++++++------------------------------- 3 files changed, 20 insertions(+), 74 deletions(-) diff --git a/module/bug/model.php b/module/bug/model.php index d481824988..d5f0bf787b 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -283,30 +283,11 @@ class bugModel extends model */ public function createBugFromGitlabIssue($bug, $executionID) { - foreach($bug as $feild => $value) $_POST[$feild] = $value; - $now = helper::now(); - $bug = fixer::input('post') - ->setDefault('openedBy', $this->app->user->account) - ->setDefault('openedDate', $now) - ->setDefault('project,execution,story,task', 0) - ->setDefault('openedBuild', '1') // todo(dingguodong) openedBuild is hard-coded. - ->setDefault('deadline', '0000-00-00') - ->setIF($this->config->systemMode == 'new' && $this->lang->navGroup->bug != 'qa', 'project', $this->session->project) - ->setIF(strpos($this->config->bug->create->requiredFields, 'deadline') !== false, 'deadline', $bug->deadline) - ->setIF(isset($bug->assignedTo) and $bug->assignedTo != '', 'assignedDate', $now) - ->stripTags($this->config->bug->editor->create['id'], $this->config->allowedTags) - ->cleanInt('product,execution,module,severity') - ->join('openedBuild', ',') - ->join('mailto', ',') - ->remove('files, labels,uid,oldTaskID,contactListMenu') - ->remove($this->config->bug->removeFields) - ->get(); - - if($executionID != 0) - { - $bug->project = $this->dao->select('parent')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch('parent'); - $bug->execution = $executionID; - } + $bug->openedBy = $this->app->user->account; + $bug->openedBuild = 0; + $bug->story = 0; + $bug->task = 0; + $bug->project = $this->dao->select('parent')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch('parent'); $this->dao->insert(TABLE_BUG)->data($bug, $skip = 'gitlab,gitlabProject')->autoCheck()->batchCheck($this->config->bug->create->requiredFields, 'notempty')->exec(); if(!dao::isError()) diff --git a/module/story/model.php b/module/story/model.php index 5b69837f8f..ddba566108 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -358,25 +358,12 @@ class storyModel extends model */ public function createStoryFromGitlabIssue($story, $executionID) { - foreach($story as $feild => $value) $_POST[$feild] = $value; - $now = helper::now(); - $story = fixer::input('post') - ->cleanInt('product,module,pri,plan') - ->callFunc('title', 'trim') - ->add('assignedDate', 0) - ->add('version', 1) - ->add('status', 'draft') - ->setDefault('plan,verify', '') - ->setDefault('openedBy', $this->app->user->account) - ->setDefault('openedDate', $now) - ->setIF($story->assignedTo != '', 'assignedDate', $now) - ->setIF($executionID > 0, 'status', 'active') - ->setIF($executionID > 0, 'stage', 'projected') - ->join('mailto', ',') - ->stripTags($this->config->story->editor->create['id'], $this->config->allowedTags) - ->remove('files,labels,reviewer,needNotReview,newStory,uid,contactListMenu,URS') - ->remove($this->config->story->removeFields) - ->get(); + $story->status = 'active'; + $story->stage = 'projected'; + $story->openedBy = 'openedBy'; + $story->version = '1'; + + if(isset($story->execution)) unset($story->execution); $requiredFields = $this->config->story->create->requiredFields; $this->dao->insert(TABLE_STORY)->data($story, 'spec,verify,gitlab,gitlabProject')->autoCheck()->batchCheck($requiredFields, 'notempty')->exec(); diff --git a/module/task/model.php b/module/task/model.php index f01fba6664..6011759459 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -464,40 +464,18 @@ class taskModel extends model */ public function createTaskFromGitlabIssue($task, $executionID) { - foreach($task as $feild => $value) $_POST[$feild] = $value; - $requiredFields = ',' . $this->config->task->create->requiredFields . ','; - $requiredFields = trim($requiredFields, ','); - $task = fixer::input('post') - ->setDefault('execution', $executionID) - ->setDefault('estimate,left,story', 0) - ->setDefault('status', 'wait') - ->setIF($this->config->systemMode == 'new', 'project', $this->getProjectID($executionID)) - ->setIF($this->post->estimate != false, 'left', $this->post->estimate) - ->setIF($this->post->story != false, 'storyVersion', $this->loadModel('story')->getVersion($this->post->story)) - ->setDefault('estStarted', '0000-00-00') - ->setDefault('deadline', '0000-00-00') - ->setIF(strpos($requiredFields, 'estStarted') !== false, 'estStarted', helper::isZeroDate($this->post->estStarted) ? '' : $this->post->estStarted) - ->setIF(strpos($requiredFields, 'deadline') !== false, 'deadline', helper::isZeroDate($this->post->deadline) ? '' : $this->post->deadline) - ->setIF(strpos($requiredFields, 'estimate') !== false, 'estimate', $this->post->estimate) - ->setIF(strpos($requiredFields, 'left') !== false, 'left', $this->post->left) - ->setIF(strpos($requiredFields, 'story') !== false, 'story', $this->post->story) - ->setIF(is_numeric($this->post->estimate), 'estimate', (float)$this->post->estimate) - ->setIF(is_numeric($this->post->consumed), 'consumed', (float)$this->post->consumed) - ->setIF(is_numeric($this->post->left), 'left', (float)$this->post->left) - ->setDefault('openedBy', $this->app->user->account) - ->setDefault('openedDate', helper::now()) - ->cleanINT('execution,story,module') - ->stripTags($this->config->task->editor->create['id'], $this->config->allowedTags) - ->join('mailto', ',') - ->remove('after,files,labels,assignedTo,uid,storyEstimate,storyDesc,storyPri,team,teamEstimate,teamMember,multiple,teams,contactListMenu,selectTestStory,testStory,testPri,testEstStarted,testDeadline,testAssignedTo,testEstimate,sync') - ->remove($this->config->task->removeFields) - ->add('version', 1) - ->get(); + $task->version = 1; + $task->openedBy = $this->app->user->account; + $task->story = 0; + $task->module = 0; + $task->estimate = 0; + $task->estStarted = '0000-00-00'; + + if(isset($task->product)) unset($task->product); $this->dao->insert(TABLE_TASK)->data($task, $skip = 'id') ->autoCheck() - ->batchCheck($requiredFields, 'notempty') - ->checkIF($task->estimate != '', 'estimate', 'float') + ->batchCheck($this->config->task->create->requiredFields, 'notempty') ->checkIF(!helper::isZeroDate($task->deadline), 'deadline', 'ge', $task->estStarted) ->exec(); From b062fe0a8e738d9cea78eb647744983ef20f23f4 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 9 Jul 2021 10:16:12 +0800 Subject: [PATCH 250/269] * Optimize codes when importing issues. --- module/gitlab/control.php | 3 ++- module/gitlab/lang/zh-cn.php | 11 ++++++----- module/gitlab/view/importissue.html.php | 8 ++++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 076f7e86e8..bde28ba333 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -327,7 +327,7 @@ class gitlab extends control ->fetchAll('issueID'); $iids = ''; foreach($savedIssueIDList as $savedIssueID) $iids = $iids . $savedIssueID->issueID . ','; - $options = '¬[iids]=' . trim($iids, ','); + $options = '&state=opened¬[iids]=' . trim($iids, ','); $gitlabIssues = $this->gitlab->apiGetIssues($gitlabID, $projectID, $options); //TODO(dingguodong) when no issues here? $products = array(); @@ -337,6 +337,7 @@ class gitlab extends control $products[$productID] = $this->loadModel("product")->getByID($productID)->name; } + $this->view->importable = empty($gitlabIssues) ? false : true; $this->view->products = $products; $this->view->gitlabID = $gitlabID; $this->view->gitlabProjectID = $projectID; diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index e2df334a72..09ac42e021 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -36,8 +36,9 @@ $lang->gitlab->placeholder->name = ''; $lang->gitlab->placeholder->url = "请填写Gitlab Server首页的访问地址,如:https://gitlab.zentao.net。"; $lang->gitlab->placeholder->token = "请填写具有admin权限账户的access token"; -$lang->gitlab->tokenError = "当前token非管理员权限。"; -$lang->gitlab->hostError = "无效的gitlab服务地址。"; -$lang->gitlab->bindUserError = "不能重复绑定用户 %s"; -$lang->gitlab->importIssueError = "未选择该议题所属的执行。"; -$lang->gitlab->importIssueWarn = "存在导入失败的议题,可再次尝试导入。"; +$lang->gitlab->noImportableIssues = "目前没有可供导入的议题。"; +$lang->gitlab->tokenError = "当前token非管理员权限。"; +$lang->gitlab->hostError = "无效的gitlab服务地址。"; +$lang->gitlab->bindUserError = "不能重复绑定用户 %s"; +$lang->gitlab->importIssueError = "未选择该议题所属的执行。"; +$lang->gitlab->importIssueWarn = "存在导入失败的议题,可再次尝试导入。"; diff --git a/module/gitlab/view/importissue.html.php b/module/gitlab/view/importissue.html.php index c43fcc2e24..98ca018d8f 100644 --- a/module/gitlab/view/importissue.html.php +++ b/module/gitlab/view/importissue.html.php @@ -15,6 +15,7 @@

gitlab->importIssue;?>

+
gitlab->gitlabIssue;?> product->common;?> execution->common;?>gitlab->gitlabIssue;?> gitlab->objectType;?>
title; ?>
repo->id); ?> repo->type); ?> repo->name); ?>repo->product); ?>repo->product); ?> repo->path; ?> actions; ?>
gitlab->gitlabIssue;?>gitlab->objectType;?> product->common;?> execution->common;?>gitlab->objectType;?>
title; ?>web_url}' target='_blank'>$issue->title"; ?>iid}]", $objectTypes, '', "class='form-control select chosen'" );?>iid}]", $products, '', "class='form-control select chosen'" );?>iid}]", '', '', "class='form-control select chosen'" );?>
id&objectID=$objectID", '', 'list', 'edit'); - common::printIcon('gitlab', 'importissue', "product={$repo->product}&gitlab={$repo->gitlab}&project={$repo->project}", '', 'list', 'link'); + common::printIcon('gitlab', 'importissue', "repo={$repo->id}", '', 'list', 'link'); if(common::hasPriv('repo', 'delete')) echo html::a($this->createLink('repo', 'delete', "repoID=$repo->id&objectID=$objectID"), '', 'hiddenwin', "title='{$lang->repo->delete}' class='btn'"); ?>
@@ -46,8 +47,11 @@ -
+ - + + + gitlab->noImportableIssues; ?> + From ab2e2191e3083c85a27baf51ef09bf81b77f243c Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 9 Jul 2021 13:48:23 +0800 Subject: [PATCH 251/269] * Bug fix and optimize for import issue. --- module/bug/model.php | 19 +++++++++---------- module/gitlab/control.php | 18 ++++-------------- module/gitlab/model.php | 2 ++ module/story/model.php | 9 +++++---- module/task/model.php | 24 ++++++++++++------------ 5 files changed, 32 insertions(+), 40 deletions(-) diff --git a/module/bug/model.php b/module/bug/model.php index d5f0bf787b..d51e28ce18 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -283,18 +283,16 @@ class bugModel extends model */ public function createBugFromGitlabIssue($bug, $executionID) { - $bug->openedBy = $this->app->user->account; - $bug->openedBuild = 0; - $bug->story = 0; - $bug->task = 0; - $bug->project = $this->dao->select('parent')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch('parent'); + $bug->openedBy = $this->app->user->account; + $bug->openedDate = helper::now(); // TODO(dingguodong) use from issue->created_at ? + $bug->assignedDate = isset($bug->assignedTo) ? helper::now() : 0; + $bug->openedBuild = 1; + $bug->story = 0; + $bug->task = 0; + $bug->project = $this->dao->select('parent')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch('parent'); $this->dao->insert(TABLE_BUG)->data($bug, $skip = 'gitlab,gitlabProject')->autoCheck()->batchCheck($this->config->bug->create->requiredFields, 'notempty')->exec(); - if(!dao::isError()) - { - $bugID = $this->dao->lastInsertID(); - return $bugID; - } + if(!dao::isError()) return $this->dao->lastInsertID(); return false; } @@ -675,6 +673,7 @@ class bugModel extends model if(!empty($bug)) { $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); + $bug->id = $bugID; if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); } return common::createChanges($oldBug, $bug); diff --git a/module/gitlab/control.php b/module/gitlab/control.php index bde28ba333..451a29d527 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -285,21 +285,11 @@ class gitlab extends control $object = $this->gitlab->issueToZentaoObject($issue, $gitlabID); $object->product = $productList[$issueID]; $object->execution = $executionID; + $clonedObject = clone $object; - if($objectType == 'task') - { - $objectID = $this->loadModel('task')->createTaskFromGitlabIssue($object, $executionID); - } - - if($objectType == 'bug') - { - $objectID = $this->loadModel('bug')->createBugFromGitlabIssue($object, $executionID); - } - - if($objectType == 'story') - { - $objectID = $this->loadModel('story')->createStoryFromGitlabIssue($object, $executionID); - } + if($objectType == 'task') $objectID = $this->loadModel('task')->createTaskFromGitlabIssue($clonedObject, $executionID); + if($objectType == 'bug') $objectID = $this->loadModel('bug')->createBugFromGitlabIssue($clonedObject, $executionID); + if($objectType == 'story') $objectID = $this->loadModel('story')->createStoryFromGitlabIssue($clonedObject, $executionID); if($objectID) { diff --git a/module/gitlab/model.php b/module/gitlab/model.php index d7fa2b393e..afa99f789e 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -1159,6 +1159,8 @@ class gitlabModel extends model if($optionType == 'userPairs' and isset($issue->$gitlabField)) $value = zget($gitlabUsers, $issue->$gitlabField); if($optionType == 'configItems' and isset($issue->$gitlabField)) $value = array_search($issue->$gitlabField, $this->config->gitlab->$options); if($value) $object->$zentaoField = $value; + + if($gitlabField == "description") $object->$zentaoField .= "
" . $issue->web_url; } return $object; } diff --git a/module/story/model.php b/module/story/model.php index ddba566108..f436d57f62 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -358,10 +358,11 @@ class storyModel extends model */ public function createStoryFromGitlabIssue($story, $executionID) { - $story->status = 'active'; - $story->stage = 'projected'; - $story->openedBy = 'openedBy'; - $story->version = '1'; + $story->status = 'active'; + $story->stage = 'projected'; + $story->openedBy = $this->app->user->account; + $story->version = 1; + $story->assignedDate = isset($story->assignedTo) ? helper::now() : 0; if(isset($story->execution)) unset($story->execution); diff --git a/module/task/model.php b/module/task/model.php index 6011759459..6fe25f81fa 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -464,25 +464,25 @@ class taskModel extends model */ public function createTaskFromGitlabIssue($task, $executionID) { - $task->version = 1; - $task->openedBy = $this->app->user->account; - $task->story = 0; - $task->module = 0; - $task->estimate = 0; - $task->estStarted = '0000-00-00'; + $task->version = 1; + $task->openedBy = $this->app->user->account; + $task->assignedDate = isset($task->assignedTo) ? helper::now() : 0; + $task->story = 0; + $task->module = 0; + $task->estimate = 0; + $task->estStarted = '0000-00-00'; + $task->left = 1; + $task->type = 'devel'; - if(isset($task->product)) unset($task->product); - - $this->dao->insert(TABLE_TASK)->data($task, $skip = 'id') + $this->dao->insert(TABLE_TASK)->data($task, $skip = 'id,product') ->autoCheck() ->batchCheck($this->config->task->create->requiredFields, 'notempty') ->checkIF(!helper::isZeroDate($task->deadline), 'deadline', 'ge', $task->estStarted) ->exec(); if(dao::isError()) return false; - - $taskID = $this->dao->lastInsertID(); - return $taskID; + + return $this->dao->lastInsertID(); } /** From d2a5588e9de35b41aa09ed29e1f8113d1501bfc4 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 9 Jul 2021 14:00:36 +0800 Subject: [PATCH 252/269] * Link story to execution. --- module/story/model.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/module/story/model.php b/module/story/model.php index f436d57f62..e987324b9b 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -379,6 +379,9 @@ class storyModel extends model $data->spec = $story->spec; $data->verify = $story->spec; $this->dao->insert(TABLE_STORYSPEC)->data($data)->exec(); + + /* Link story to execution. */ + $this->linkStory($executionID, $story->product, $storyID); return $storyID; } From 9e6b4db720a6dd50965cc7e8e92413ba9825a5d7 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 9 Jul 2021 14:33:49 +0800 Subject: [PATCH 253/269] * Fix bug when batch edit task,bug,story. --- module/bug/model.php | 7 +++++++ module/story/model.php | 5 +++++ module/task/model.php | 6 +++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/module/bug/model.php b/module/bug/model.php index d51e28ce18..b12997f76f 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -289,6 +289,8 @@ class bugModel extends model $bug->openedBuild = 1; $bug->story = 0; $bug->task = 0; + $bug->pri = 3; + $bug->severity = 3; $bug->project = $this->dao->select('parent')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch('parent'); $this->dao->insert(TABLE_BUG)->data($bug, $skip = 'gitlab,gitlabProject')->autoCheck()->batchCheck($this->config->bug->create->requiredFields, 'notempty')->exec(); @@ -794,6 +796,11 @@ class bugModel extends model $this->executeHooks($bugID); $allChanges[$bugID] = common::createChanges($oldBug, $bug); + + /* update bug to gitlab issue. */ + $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); + $bug->id = $bugID; + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); } else { diff --git a/module/story/model.php b/module/story/model.php index e987324b9b..a7a37c404a 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -694,6 +694,11 @@ class storyModel extends model } $this->file->updateObjectID($this->post->uid, $storyID, 'story'); + + /* update story to gitlab issue. */ + $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); + return common::createChanges($oldStory, $story); } } diff --git a/module/task/model.php b/module/task/model.php index 6fe25f81fa..5d1eb2917f 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -978,7 +978,7 @@ class taskModel extends model ->batchCheckIF($task->closedReason == 'cancel', 'finishedBy, finishedDate', 'empty') ->where('id')->eq((int)$taskID)->exec(); - /* update story to gitlab issue. */ + /* update task to gitlab issue. */ $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); @@ -1281,6 +1281,10 @@ class taskModel extends model if($task->status == 'done') $this->loadModel('score')->create('task', 'finish', $taskID); if($task->status == 'closed') $this->loadModel('score')->create('task', 'close', $taskID); $allChanges[$taskID] = common::createChanges($oldTask, $task); + + /* update task to gitlab issue. */ + $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); + if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); } else { From 5de789ad8d383bc7882323142ec7b877a566d3b6 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 9 Jul 2021 15:03:18 +0800 Subject: [PATCH 254/269] * Fix bug when batch assign on task. --- module/task/model.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/module/task/model.php b/module/task/model.php index 5d1eb2917f..57b57da9f0 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -1371,8 +1371,10 @@ class taskModel extends model ->check('left', 'float') ->where('id')->eq($taskID)->exec(); + $task = $this->getById($taskID); + $task->id = $taskID; $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); - if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $oldTask); + if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); if(!dao::isError()) return common::createChanges($oldTask, $task); } From 677a3b00525d68362d08933806b369b6afbcb0f9 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 9 Jul 2021 17:22:27 +0800 Subject: [PATCH 255/269] * Add objectID to object for apiUpdateIssue(bug fix). --- module/gitlab/model.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index afa99f789e..ff4437dab1 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -610,8 +610,9 @@ class gitlabModel extends model * @access public * @return object */ - public function apiUpdateIssue($gitlabID, $projectID, $issueID, $objectType, $object) + public function apiUpdateIssue($gitlabID, $projectID, $issueID, $objectType, $object, $objectID = null) { + if(!isset($object->id) && !empty($objectID)) $object->id = $objectID; $issue = $this->parseObjectToIssue($gitlabID, $projectID, $objectType, $object); $apiRoot = $this->getApiRoot($gitlabID); $url = sprintf($apiRoot, "/projects/{$projectID}/issues/{$issueID}"); @@ -1124,7 +1125,7 @@ class gitlabModel extends model /* Append this object link in zentao to gitlab issue description */ $zentaoLink = common::getSysURL() . helper::createLink($objectType, 'view', "id={$object->id}"); - $issue->description = $issue->description . "\n\n" . $zentaoLink; + if(strpos($issue->description, $zentaoLink) == false) $issue->description = $issue->description . "\n\n" . $zentaoLink; return $issue; } From fdb69a81b14d0ef6e328e80f0fb1bfa5a1c1d333 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 9 Jul 2021 17:23:16 +0800 Subject: [PATCH 256/269] * Change all lines about apiUpdateIssue func. --- module/bug/model.php | 21 ++++++++++----------- module/story/model.php | 18 +++++++++--------- module/task/control.php | 2 +- module/task/model.php | 15 +++++++-------- 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/module/bug/model.php b/module/bug/model.php index b12997f76f..b342d0eae7 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -675,8 +675,7 @@ class bugModel extends model if(!empty($bug)) { $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); - $bug->id = $bugID; - if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug, $bugID); } return common::createChanges($oldBug, $bug); } @@ -799,8 +798,7 @@ class bugModel extends model /* update bug to gitlab issue. */ $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); - $bug->id = $bugID; - if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug, $bugID); } else { @@ -858,7 +856,7 @@ class bugModel extends model if(!empty($bug)) { $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); - if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', (Object)$bug); + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', (Object)$bug, $bugID); } $oldBug = $bugs[$bugID]; @@ -896,11 +894,12 @@ class bugModel extends model ->where('id')->eq($bugID)->exec(); $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); + $bug = $this->getById($bugID); // get full bug object to update issue. $bug->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $bug->assignedTo); if($bug->assignee_id != '') { // TODO(dingguodong) we should alert to operator when can not find the user, and the operator should reconfigure user binding. - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug, $bugID); } if(!dao::isError()) return common::createChanges($oldBug, $bug); @@ -960,7 +959,7 @@ class bugModel extends model if(!empty($bug)) { $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); - if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug, $bugID); } $this->dao->update(TABLE_BUG)->data($bug)->where('id')->eq($bugID)->exec(); @@ -1055,7 +1054,7 @@ class bugModel extends model $this->linkBugToBuild($bugID, $bug->resolvedBuild); $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); - if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug, $bugID); return common::createChanges($oldBug, $bug); } @@ -1188,7 +1187,7 @@ class bugModel extends model /* batch resolve issure bugs.*/ $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); - if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug, $bugID); $changes[$bugID] = common::createChanges($oldBug, $bug); } @@ -1250,7 +1249,7 @@ class bugModel extends model if(!empty($bug)) { $relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID); - if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug, $bugID); } $bug->activatedCount += 1; @@ -1286,7 +1285,7 @@ class bugModel extends model if(!empty($relation)) { $currentIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->projectID, $relation->issueID); - if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug); + if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug, $bugID); } return common::createChanges($oldBug, $bug); } diff --git a/module/story/model.php b/module/story/model.php index a7a37c404a..e633e88daf 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -697,7 +697,7 @@ class storyModel extends model /* update story to gitlab issue. */ $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); - if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story, $storyID); return common::createChanges($oldStory, $story); } @@ -877,7 +877,7 @@ class storyModel extends model } /* update story to gitlab issue. */ $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); - if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); + if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story, $storyID); unset($oldStory->parent); unset($story->parent); @@ -1207,7 +1207,7 @@ class storyModel extends model /* update story to gitlab issue. */ $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); - if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); + if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story, $storyID); $this->executeHooks($storyID); if($story->type == 'story') $this->batchChangeStage(array($storyID), $story->stage); @@ -1481,7 +1481,7 @@ class storyModel extends model if(!empty($relation)) { $currentIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->projectID, $relation->issueID); - if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); + if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story, $storyID); } /* Update parent story status. */ @@ -1555,7 +1555,7 @@ class storyModel extends model if(!empty($relation)) { $currentIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->projectID, $relation->issueID); - if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); + if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story, $storyID); } } else @@ -1836,7 +1836,7 @@ class storyModel extends model { $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); $story->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $story->assignedTo); - if($story->assignee_id != '') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); + if($story->assignee_id != '') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story, $storyID); return common::createChanges($oldStory, $story); } return false; @@ -1871,11 +1871,11 @@ class storyModel extends model { $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); $story->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $story->assignedTo); - if($story->assignee_id != '') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); + if($story->assignee_id != '') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story, $storyID); /* Push this story to gitlab issue. */ $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); - if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); + if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story, $storyID); } } return $allChanges; @@ -1913,7 +1913,7 @@ class storyModel extends model /* Push this story to gitlab issue. */ $relation = $this->loadModel('gitlab')->getRelationByObject('story', $storyID); - if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story); + if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'story', $story, $storyID); return common::createChanges($oldStory, $story); } diff --git a/module/task/control.php b/module/task/control.php index 64da0f0f6a..0c6540bbea 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -573,7 +573,7 @@ class task extends control $task = $this->task->getByID($taskID); $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); - $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task, $taskID); $members = $this->loadModel('user')->getTeamMemberPairs($executionID, 'execution', 'nodeleted'); diff --git a/module/task/model.php b/module/task/model.php index 57b57da9f0..c01d508acd 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -980,7 +980,7 @@ class taskModel extends model /* update task to gitlab issue. */ $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); - if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); + if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task, $taskID); if(!dao::isError()) { @@ -1284,7 +1284,7 @@ class taskModel extends model /* update task to gitlab issue. */ $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); - if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); + if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task, $taskID); } else { @@ -1372,9 +1372,8 @@ class taskModel extends model ->where('id')->eq($taskID)->exec(); $task = $this->getById($taskID); - $task->id = $taskID; $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); - if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); + if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task, $taskID); if(!dao::isError()) return common::createChanges($oldTask, $task); } @@ -1715,7 +1714,7 @@ class taskModel extends model if(!empty($relation)) { $currentIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->projectID, $relation->issueID); - if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); + if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task, $taskID); } if($oldTask->parent > 0) $this->updateParentStatus($taskID); @@ -1778,7 +1777,7 @@ class taskModel extends model if(!empty($relation)) { $currentIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->projectID, $relation->issueID); - if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $task); + if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $task, $taskID); } if(!dao::isError()) @@ -1829,7 +1828,7 @@ class taskModel extends model if(!empty($relation)) { $currentIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->projectID, $relation->issueID); - if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); + if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task, $taskID); } if(!dao::isError()) return common::createChanges($oldTask, $task); @@ -1898,7 +1897,7 @@ class taskModel extends model if($oldTask->story) $this->loadModel('story')->setStage($oldTask->story); $relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID); - if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task); + if(!empty($relation)) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task, $taskID); if(!dao::isError()) return common::createChanges($oldTask, $task); } From d27efcb9eaec1e8a0f718169ea681139e9863306 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 9 Jul 2021 18:02:28 +0800 Subject: [PATCH 257/269] * Get full object when desc is empty. --- module/gitlab/model.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index ff4437dab1..46415d56b0 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -612,6 +612,9 @@ class gitlabModel extends model */ public function apiUpdateIssue($gitlabID, $projectID, $issueID, $objectType, $object, $objectID = null) { + /* Get full object when desc is empty. */ + if(!isset($object->description) || (isset($object->description) && $object->description == '')) $object = $this->loadModel($objectType)->getByID($objectID); + if(!isset($object->id) && !empty($objectID)) $object->id = $objectID; $issue = $this->parseObjectToIssue($gitlabID, $projectID, $objectType, $object); $apiRoot = $this->getApiRoot($gitlabID); From 2fce8df996694fee18156b3983120ff8000ad899 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 12 Jul 2021 14:06:18 +0800 Subject: [PATCH 258/269] * Remove link when scm is not gitlab. --- module/repo/view/maintain.html.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/repo/view/maintain.html.php b/module/repo/view/maintain.html.php index 4f754db09f..8c66203273 100644 --- a/module/repo/view/maintain.html.php +++ b/module/repo/view/maintain.html.php @@ -48,8 +48,8 @@ path; ?> id&objectID=$objectID", '', 'list', 'edit'); - common::printIcon('gitlab', 'importissue', "repo={$repo->id}", '', 'list', 'link'); + common::printIcon('repo', 'edit', "repoID=$repo->id&objectID=$objectID", '', 'list', 'edit'); + if(strtolower($repo->SCM) == "gitlab") common::printIcon('gitlab', 'importissue', "repo={$repo->id}", '', 'list', 'link'); // disable button instead of hiding it. if(common::hasPriv('repo', 'delete')) echo html::a($this->createLink('repo', 'delete', "repoID=$repo->id&objectID=$objectID"), '', 'hiddenwin', "title='{$lang->repo->delete}' class='btn'"); ?> From cc60268ee4721096d6d7ac35ee5688f18fd5dbff Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 12 Jul 2021 14:32:48 +0800 Subject: [PATCH 259/269] * Filter issue in gitlab using alternative way. --- module/gitlab/control.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 451a29d527..c0af485b49 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -315,10 +315,20 @@ class gitlab extends control ->where('relation')->eq('gitlab') ->andWhere('product')->in($productIDList) ->fetchAll('issueID'); - $iids = ''; - foreach($savedIssueIDList as $savedIssueID) $iids = $iids . $savedIssueID->issueID . ','; - $options = '&state=opened¬[iids]=' . trim($iids, ','); - $gitlabIssues = $this->gitlab->apiGetIssues($gitlabID, $projectID, $options); //TODO(dingguodong) when no issues here? + + /* 'not[iids]' option in gitlab API has a issue when iids is too long. */ + $gitlabIssues = $this->gitlab->apiGetIssues($gitlabID, $projectID, '&state=opened'); + foreach($gitlabIssues as $index => $issue) + { + foreach($savedIssueIDList as $savedIssueID) + { + if($issue->iid == $savedIssueID->issueID) + { + unset($gitlabIssues[$index]); + break; + } + } + } $products = array(); $products[] = ''; From 9ae5f3e8fe5727979426a68a77111c543afcf27f Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 13 Jul 2021 10:02:06 +0800 Subject: [PATCH 260/269] * Change getting repoID from _GET to getting from para. --- module/gitlab/control.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index c0af485b49..28540a6fe2 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -254,12 +254,13 @@ class gitlab extends control /** * Import gitlab issue to zentaopms. * + * @param int $repoID * @access public * @return void */ - public function importIssue() + public function importIssue($repoID) { - $repo = $this->loadModel('repo')->getRepoByID($this->get->repo); + $repo = $this->loadModel('repo')->getRepoByID($repoID); $productIDList = explode(',', $repo->product); $gitlabID = $repo->gitlab; $projectID = $repo->project; From 1d0f19caaa128b6225b470a0bc2feca30a513592 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 13 Jul 2021 11:06:13 +0800 Subject: [PATCH 261/269] + Delete project relation when user deleting a repo. --- module/gitlab/model.php | 31 +++++++++++++++++++++++++++++++ module/repo/control.php | 3 +++ 2 files changed, 34 insertions(+) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 46415d56b0..0a22c5f143 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -863,6 +863,37 @@ class gitlabModel extends model return true; } + /** + * Delete project relation. + * + * condition: when user deleting a repo. + * + * @param int $repoID + * @access public + * @return void + */ + public function deleteProjectRelation($repoID) + { + $repo = $this->dao->select('product,path as gitlabProjectID,client as gitlabID')->from(TABLE_REPO) + ->where('id')->eq($repoID) + ->andWhere('deleted')->eq(0) + ->fetch(); + if(empty($repo)) return false; + + $productIDList = explode(',', $repo->product); + foreach($productIDList as $product) + { + $this->dao->delete()->from(TABLE_RELATION) + ->where('product')->eq($product) + ->andWhere('AType')->eq('gitlab') + ->andWhere('BType')->eq('gitlabProject') + ->andWhere('relation')->eq('interrated') + ->andWhere('AID')->eq($repo->gitlabID) + ->andWhere('BID')->eq($repo->gitlabProjectID) + ->exec(); + } + } + /** * Create webhook for zentao. * diff --git a/module/repo/control.php b/module/repo/control.php index c16b3c61cb..c12c786b4e 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -209,6 +209,9 @@ class repo extends control die(js::confirm($this->lang->repo->notice->delete, $this->repo->createLink('delete', "repoID=$repoID&objectID=$objectID&confirm=yes"))); } + /* Delete project relation for gitlab type. */ + $this->loadModel('gitlab')->deleteProjectRelation($repoID); + $relationID = $this->dao->select('id')->from(TABLE_RELATION)->where('extra')->eq($repoID)->fetch(); if($relationID) { From fef177344ed5d6863e10b72a420d435dd3786e05 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 13 Jul 2021 11:08:24 +0800 Subject: [PATCH 262/269] * Rename gitlab issue name to en lang. --- module/gitlab/lang/zh-cn.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index 09ac42e021..923bcf7baf 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -6,7 +6,7 @@ $lang->gitlab->create = '添加gitlab'; $lang->gitlab->edit = '编辑gitlab'; $lang->gitlab->bindUser = '绑定用户'; $lang->gitlab->bindProduct = '关联产品'; -$lang->gitlab->importIssue = '关联议题'; +$lang->gitlab->importIssue = '关联issue'; $lang->gitlab->delete = '删除'; $lang->gitlab->confirmDelete = '确认删除该gitlab吗?'; $lang->gitlab->gitlabAccount = 'gitlab用户'; @@ -15,7 +15,7 @@ $lang->gitlab->zentaoAccount = '禅道用户'; $lang->gitlab->browseAction = 'gitlab列表'; $lang->gitlab->deleteAction = '删除gitlab'; $lang->gitlab->gitlabProject = "{$lang->gitlab->common}项目"; -$lang->gitlab->gitlabIssue = "{$lang->gitlab->common}议题"; +$lang->gitlab->gitlabIssue = "{$lang->gitlab->common}issue"; $lang->gitlab->zentaoProduct = '禅道产品'; $lang->gitlab->objectType = '类型'; // task, bug, story @@ -36,9 +36,9 @@ $lang->gitlab->placeholder->name = ''; $lang->gitlab->placeholder->url = "请填写Gitlab Server首页的访问地址,如:https://gitlab.zentao.net。"; $lang->gitlab->placeholder->token = "请填写具有admin权限账户的access token"; -$lang->gitlab->noImportableIssues = "目前没有可供导入的议题。"; +$lang->gitlab->noImportableIssues = "目前没有可供导入的issue。"; $lang->gitlab->tokenError = "当前token非管理员权限。"; $lang->gitlab->hostError = "无效的gitlab服务地址。"; $lang->gitlab->bindUserError = "不能重复绑定用户 %s"; -$lang->gitlab->importIssueError = "未选择该议题所属的执行。"; -$lang->gitlab->importIssueWarn = "存在导入失败的议题,可再次尝试导入。"; +$lang->gitlab->importIssueError = "未选择该issue所属的执行。"; +$lang->gitlab->importIssueWarn = "存在导入失败的issue,可再次尝试导入。"; From b3641df7b20438e11bbe1c3f3e799f90199d9b3a Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 13 Jul 2021 14:36:01 +0800 Subject: [PATCH 263/269] * Display icon name in lang setting. --- module/gitlab/view/browse.html.php | 2 +- module/repo/view/maintain.html.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php index 1fc24f76e0..dd3311b1dd 100644 --- a/module/gitlab/view/browse.html.php +++ b/module/gitlab/view/browse.html.php @@ -37,7 +37,7 @@ createLink('gitlab', 'delete', "gitlabID=$id"), '', 'hiddenwin', "title='{$lang->gitlab->delete}' class='btn'"); ?> diff --git a/module/repo/view/maintain.html.php b/module/repo/view/maintain.html.php index 8c66203273..cd358fb3ce 100644 --- a/module/repo/view/maintain.html.php +++ b/module/repo/view/maintain.html.php @@ -49,7 +49,7 @@ id&objectID=$objectID", '', 'list', 'edit'); - if(strtolower($repo->SCM) == "gitlab") common::printIcon('gitlab', 'importissue', "repo={$repo->id}", '', 'list', 'link'); // disable button instead of hiding it. + if(strtolower($repo->SCM) == "gitlab") common::printIcon('gitlab', 'importIssue', "repo={$repo->id}", '', 'list', 'link'); // disable button instead of hiding it. if(common::hasPriv('repo', 'delete')) echo html::a($this->createLink('repo', 'delete', "repoID=$repo->id&objectID=$objectID"), '', 'hiddenwin', "title='{$lang->repo->delete}' class='btn'"); ?> From c8b3045fc9768ba8808358e5cf591258735c82f6 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 13 Jul 2021 14:39:20 +0800 Subject: [PATCH 264/269] * Rename pipline to pipeline. --- db/zentao.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/zentao.sql b/db/zentao.sql index 7146cad404..d0e6ffda1e 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -471,8 +471,8 @@ CREATE TABLE IF NOT EXISTS `zt_history` ( PRIMARY KEY (`id`), KEY `action` (`action`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- DROP TABLE IF EXISTS `zt_pipline`; -CREATE TABLE IF NOT EXISTS `zt_pipline` ( +-- DROP TABLE IF EXISTS `zt_pipeline`; +CREATE TABLE IF NOT EXISTS `zt_pipeline` ( `id` smallint(8) unsigned NOT NULL AUTO_INCREMENT, `type` char(30) NOT NULL, `name` varchar(50) NOT NULL, From dd7d97fc044d2c97f6ae3068677024b4f52aaf6f Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 13 Jul 2021 15:00:58 +0800 Subject: [PATCH 265/269] * Add private column to sql file. --- db/zentao.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/zentao.sql b/db/zentao.sql index d0e6ffda1e..c62ac037f9 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -480,6 +480,7 @@ CREATE TABLE IF NOT EXISTS `zt_pipeline` ( `account` varchar(30) DEFAULT NULL, `password` varchar(255) NOT NULL, `token` varchar(255) DEFAULT NULL, + `private` char(32) DEFAULT NULL, `createdBy` varchar(30) NOT NULL, `createdDate` datetime NOT NULL, `editedBy` varchar(30) NOT NULL, From fee5d53f946957c81b887d128959d449ab988c43 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 13 Jul 2021 16:50:46 +0800 Subject: [PATCH 266/269] * Optimize import issue and bug fix. --- module/gitlab/control.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 28540a6fe2..b8b72c1201 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -314,7 +314,9 @@ class gitlab extends control $savedIssueIDList = $this->dao->select('BID as issueID')->from(TABLE_RELATION) ->where('relation')->eq('gitlab') - ->andWhere('product')->in($productIDList) + ->andWhere('BType')->eq('issue') + ->andWhere('BVersion')->eq($projectID) + ->andWhere('extra')->eq($gitlabID) ->fetchAll('issueID'); /* 'not[iids]' option in gitlab API has a issue when iids is too long. */ From a519be7fb673f3f8e3f70447ffc2313a3ea2a1a7 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 13 Jul 2021 17:43:59 +0800 Subject: [PATCH 267/269] * Bug fix when assign user on story in execution. --- module/gitlab/model.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 0a22c5f143..a153b99b58 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -612,9 +612,14 @@ class gitlabModel extends model */ public function apiUpdateIssue($gitlabID, $projectID, $issueID, $objectType, $object, $objectID = null) { + $oldObject = clone $object; /* Get full object when desc is empty. */ if(!isset($object->description) || (isset($object->description) && $object->description == '')) $object = $this->loadModel($objectType)->getByID($objectID); - + foreach($oldObject as $index => $attribute) + { + if($index != 'description') $object->$index = $attribute; + } + if(!isset($object->id) && !empty($objectID)) $object->id = $objectID; $issue = $this->parseObjectToIssue($gitlabID, $projectID, $objectType, $object); $apiRoot = $this->getApiRoot($gitlabID); From e8c9118515d1239ad5f0d1ddb3cb2e63c0260baf Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 14 Jul 2021 09:08:57 +0800 Subject: [PATCH 268/269] * Correct function comment, and keep func code stay. --- module/gitlab/model.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index a153b99b58..578640cb90 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -606,7 +606,9 @@ class gitlabModel extends model * @param int $gitlabID * @param int $projectID * @param int $issueID - * @param object $attribute + * @param string $objectType + * @param object $object + * @param int $objectID * @access public * @return object */ From 6f2ae70f06c1756f21c0d35340d8af5e04f5d2e7 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Wed, 14 Jul 2021 09:28:34 +0800 Subject: [PATCH 269/269] * Merge from mapi branch. --- api/v1/entries/error.php | 15 ++ api/v1/entries/product.php | 0 api/v1/entries/productline.php | 0 api/v1/entries/productlines.php | 0 api/v1/entries/products.php | 0 api/v1/entries/program.php | 0 api/v1/entries/programs.php | 9 + api/v1/entries/project.php | 0 api/v1/entries/projects.php | 0 api/v1/entries/task.php | 44 ++++ api/v1/entries/taskassignto.php | 30 +++ api/v1/entries/taskfinish.php | 35 +++ api/v1/entries/tasks.php | 32 +++ api/v1/entries/taskstart.php | 29 +++ api/v1/entries/tokens.php | 26 +++ config/config.php | 4 + config/routes.php | 26 +++ framework/api/entry.class.php | 369 +++++++++++++++++++++++++++++++ framework/api/router.class.php | 230 +++++++++++++++++++ framework/base/control.class.php | 10 +- framework/base/router.class.php | 6 +- module/task/control.php | 89 ++++---- www/api.php | 20 +- 23 files changed, 918 insertions(+), 56 deletions(-) create mode 100644 api/v1/entries/error.php create mode 100644 api/v1/entries/product.php create mode 100644 api/v1/entries/productline.php create mode 100644 api/v1/entries/productlines.php create mode 100644 api/v1/entries/products.php create mode 100644 api/v1/entries/program.php create mode 100644 api/v1/entries/programs.php create mode 100644 api/v1/entries/project.php create mode 100644 api/v1/entries/projects.php create mode 100644 api/v1/entries/task.php create mode 100644 api/v1/entries/taskassignto.php create mode 100644 api/v1/entries/taskfinish.php create mode 100644 api/v1/entries/tasks.php create mode 100644 api/v1/entries/taskstart.php create mode 100644 api/v1/entries/tokens.php create mode 100644 config/routes.php create mode 100644 framework/api/entry.class.php create mode 100644 framework/api/router.class.php diff --git a/api/v1/entries/error.php b/api/v1/entries/error.php new file mode 100644 index 0000000000..c2b5eece56 --- /dev/null +++ b/api/v1/entries/error.php @@ -0,0 +1,15 @@ +send(404, array('error' => 'not found')); + } +} diff --git a/api/v1/entries/product.php b/api/v1/entries/product.php new file mode 100644 index 0000000000..e69de29bb2 diff --git a/api/v1/entries/productline.php b/api/v1/entries/productline.php new file mode 100644 index 0000000000..e69de29bb2 diff --git a/api/v1/entries/productlines.php b/api/v1/entries/productlines.php new file mode 100644 index 0000000000..e69de29bb2 diff --git a/api/v1/entries/products.php b/api/v1/entries/products.php new file mode 100644 index 0000000000..e69de29bb2 diff --git a/api/v1/entries/program.php b/api/v1/entries/program.php new file mode 100644 index 0000000000..e69de29bb2 diff --git a/api/v1/entries/programs.php b/api/v1/entries/programs.php new file mode 100644 index 0000000000..0c94910361 --- /dev/null +++ b/api/v1/entries/programs.php @@ -0,0 +1,9 @@ +loadController('program', 'browse'); + $program->browse(); + } +} diff --git a/api/v1/entries/project.php b/api/v1/entries/project.php new file mode 100644 index 0000000000..e69de29bb2 diff --git a/api/v1/entries/projects.php b/api/v1/entries/projects.php new file mode 100644 index 0000000000..e69de29bb2 diff --git a/api/v1/entries/task.php b/api/v1/entries/task.php new file mode 100644 index 0000000000..00496ea8ef --- /dev/null +++ b/api/v1/entries/task.php @@ -0,0 +1,44 @@ +loadController('task', 'view'); + $control->view($taskID); + + $data = $this->getData(); + $task = $data->data->task; + $this->send(200, $task); + } + + public function put($taskID) + { + $oldTask = $this->loadModel('task')->getByID($taskID); + + /* Set $_POST variables. */ + $fields = 'name,type,assignedTo,estimate,left,consumed,story,parent,execution,module,closedReason,status'; + $this->batchSetPost($fields, $oldTask); + + $control = $this->loadController('task', 'edit'); + $control->edit($taskID); + + $this->getData(); + $this->sendSuccess(200, 'success'); + } + + public function delete($taskID) + { + $control = $this->loadController('task', 'delete'); + $control->delete(0, $taskID, 'true'); + + $this->getData(); + $this->sendSuccess(200, 'success'); + } +} diff --git a/api/v1/entries/taskassignto.php b/api/v1/entries/taskassignto.php new file mode 100644 index 0000000000..77feefa35c --- /dev/null +++ b/api/v1/entries/taskassignto.php @@ -0,0 +1,30 @@ +loadModel('task')->getByID($taskID); + + $fields = 'assignedTo,comment,left'; + $this->batchSetPost($fields); + + $control = $this->loadController('task', 'assignTo'); + $this->requireFields('assignedTo'); + + $control->assignTo($task->execution, $taskID); + + $data = $this->getData(); + if($data->result == 'fail') return $this->sendError(400, $data->message); + + $task = $this->loadModel('task')->getByID($dataID); + + $this->send(200, $task); + } +} diff --git a/api/v1/entries/taskfinish.php b/api/v1/entries/taskfinish.php new file mode 100644 index 0000000000..5f23f8e70a --- /dev/null +++ b/api/v1/entries/taskfinish.php @@ -0,0 +1,35 @@ +loadModel('task')->getByID($taskID); + + $fields = 'assignedTo,realStarted'; + $this->batchSetPost($fields, $task); + + $fields = 'finishedDate,comment'; + $this->batchSetPost($fields); + + $this->setPost('currentConsumed', $this->request('currentConsumed', 0)); + $this->setPost('consumed', $this->request('currentConsumed', 0) + $task->consumed); + + $control = $this->loadController('task', 'finish'); + $this->requireFields('assignedTo,currentConsumed,realStarted,finishedDate'); + $control->finish($taskID); + + $data = $this->getData(); + if($data->result == 'fail') return $this->sendError(400, $data->message); + + $task = $this->loadModel('task')->getByID($taskID); + + $this->send(200, $task); + } +} diff --git a/api/v1/entries/tasks.php b/api/v1/entries/tasks.php new file mode 100644 index 0000000000..a1df8a596f --- /dev/null +++ b/api/v1/entries/tasks.php @@ -0,0 +1,32 @@ +batchSetPost($fields); + + $control = $this->loadController('task', 'create'); + $this->requireFields('name,assignedTo,type'); + + $control->create($executionID, $this->request('storyID', 0), $this->request('moduleID', 0), $this->request('copyTaskID', 0), $this->request('copyTodoID', 0)); + + $data = $this->getData(); + if(!isset($data->id)) return $this->sendError(400, $data->message); + + $task = $this->loadModel('task')->getByID($data->id); + + $this->send(200, $task); + } +} diff --git a/api/v1/entries/taskstart.php b/api/v1/entries/taskstart.php new file mode 100644 index 0000000000..d81e69874e --- /dev/null +++ b/api/v1/entries/taskstart.php @@ -0,0 +1,29 @@ +loadModel('task')->getByID($taskID); + + $fields = 'assignedTo,realStarted,comment,left'; + $this->batchSetPost($fields); + + $control = $this->loadController('task', 'start'); + $this->requireFields('left'); + $control->start($taskID); + + $data = $this->getData(); + if($data->result == 'fail') return $this->sendError(400, $data->message); + + $task = $this->loadModel('task')->getByID($dataID); + + $this->send(200, $task); + } +} diff --git a/api/v1/entries/tokens.php b/api/v1/entries/tokens.php new file mode 100644 index 0000000000..b4d7732643 --- /dev/null +++ b/api/v1/entries/tokens.php @@ -0,0 +1,26 @@ +request('account'); + $password = $this->request('password'); + + $user = $this->loadModel('user')->identify($account, $password); + + if($user) + { + $this->user->login($user); + $this->send(200, array('token' => session_id())); + } + + $this->sendError(400, $this->app->lang->user->loginFailed); + } +} diff --git a/config/config.php b/config/config.php index fad76cba64..27443da8a9 100644 --- a/config/config.php +++ b/config/config.php @@ -170,6 +170,10 @@ if(file_exists($myConfig)) include $myConfig; $zentaopmsConfig = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'zentaopms.php'; if(file_exists($zentaopmsConfig)) include $zentaopmsConfig; +/* API路由配置。API route settings. */ +$routesConfig = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'routes.php'; +if(file_exists($routesConfig)) include $routesConfig; + /* Include extension config files. */ $extConfigFiles = glob(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'ext/*.php'); if($extConfigFiles) foreach($extConfigFiles as $extConfigFile) include $extConfigFile; diff --git a/config/routes.php b/config/routes.php new file mode 100644 index 0000000000..9d76ff8beb --- /dev/null +++ b/config/routes.php @@ -0,0 +1,26 @@ +routes = $routes; diff --git a/framework/api/entry.class.php b/framework/api/entry.class.php new file mode 100644 index 0000000000..03aac91b8f --- /dev/null +++ b/framework/api/entry.class.php @@ -0,0 +1,369 @@ +app->user)) $this->sendError(401, 'Unauthorized'); + } +} + +/** + * 禅道API的baseEntry类。 + * The baseEntry class file of ZenTao API. + * + */ +class baseEntry +{ + /** + * 全局对象 $app。 + * The global $app object. + * + * @var object + * @access public + */ + public $app; + + /** + * 提交的POST数据 + * The decoded request body. + * + * @var object + * @access public + */ + public $requestBody; + + /** + * 构造方法。 + * The construct function. + * + * @access public + * @return void + */ + public function __construct() + { + global $app; + $this->app = $app; + + $this->parseRequestBody(); + } + + /** + * 获取请求数据(POST PUT) + * Get request data(POST or PUT). + * + * @param string $key + * @param mixed $defaultValue + * @access public + * @return mixed + */ + public function request($key, $defaultValue = '') + { + if(isset($this->requestBody->$key)) return $this->requestBody->$key; + return $defaultValue; + } + + /** + * 解析请求数据 + * Parse body of request data. + * + * @access public + * @return void + */ + private function parseRequestBody() + { + $this->requestBody = new stdClass(); + + if($this->app->action == 'post' or $this->app->action == 'put') + { + $requestBody = file_get_contents("php://input"); + if($requestBody) $this->requestBody = json_decode($requestBody); + } + } + + /** + * HTTP状态码 + * HTTP status code + * + * @access public + */ + public $statusCode = array( + 100 => "100 Continue", + 101 => "101 Switching Protocols", + 102 => "102 Processing", + + 200 => "200 OK", + 201 => "201 Created", + 202 => "202 Accepted", + 203 => "203 Non-Authoritative Information", + 204 => "204 No Content", + 205 => "205 Reset Content", + 206 => "206 Partial Content", + 207 => "207 Multi-Status", + + 300 => "300 Multiple Choices", + 301 => "301 Moved Permanently", + 302 => "302 Found", + 303 => "303 See Other", + 304 => "304 Not Modified", + 305 => "305 Use Proxy", + 307 => "307 Temporary Redirect", + + 400 => "400 Bad Request", + 401 => "401 Authorization Required", + 402 => "402 Payment Required", + 403 => "403 Forbidden", + 404 => "404 Not Found", + 405 => "405 Method Not Allowed", + 406 => "406 Not Acceptable", + 407 => "407 Proxy Authentication Required", + 408 => "408 Request Time-out", + 409 => "409 Conflict", + 410 => "410 Gone", + 411 => "411 Length Required", + 412 => "412 Precondition Failed", + 413 => "413 Request Entity Too Large", + 414 => "414 Request-URI Too Large", + 415 => "415 Unsupported Media Type", + 416 => "416 Requested Range Not Satisfiable", + 417 => "417 Expectation Failed", + 422 => "422 Unprocessable Entity", + 423 => "423 Locked", + 424 => "424 Failed Dependency", + 426 => "426 Upgrade Required", + ); + + /** + * 发送请求的响应数据 + * Send response data + * + * @access public + * @return void + */ + public function send($code, $data) + { + header("Content-type: application/json"); + header("HTTP/1.1 {$this->statusCode[$code]}"); + echo json_encode($data); + exit; + } + + /** + * 发送错误信息 + * Send error response + * + * @param int $code + * @param string $msg + * @access public + * @return void + */ + public function sendError($code, $msg) + { + $response = new stdclass(); + $response->error = $msg; + + $this->send($code, $response); + } + + /** + * 发送成功提示 + * Send success response + * + * @param int $code + * @param string $msg + * @access public + * @return void + */ + public function sendSuccess($code, $msg) + { + $response = new stdclass(); + $response->message = $msg; + + $this->send($code, $response); + } + + /** + * 加载禅道的控制器类 + * Load controller of zentaopms + * + * @param string $moduleName + * @param string $methodName + * @access public + * @return object + */ + public function loadController($moduleName, $methodName) + { + global $app; + $app->setModuleName($moduleName); + $app->setMethodName($methodName); + $app->setControlFile(); + + /* + * 引入该模块的control文件。 + * Include the control file of the module. + **/ + $file2Included = $app->setActionExtFile() ? $app->extActionFile : $app->controlFile; + chdir(dirname($file2Included)); + helper::import($file2Included); + + /* + * 设置control的类名。 + * Set the class name of the control. + **/ + $className = class_exists("my$moduleName") ? "my$moduleName" : $moduleName; + if(!class_exists($className)) $app->triggerError("the control $className not found", __FILE__, __LINE__, $exit = true); + + $controller = new $className(); + $controller->viewType = 'json'; + return $controller; + } + + /** + * 加载指定模块的model文件。 + * Load the model file of one module. + * + * @param string $moduleName 模块名,如果为空,使用当前模块。The module name, if empty, use current module's name. + * @param string $appName The app name, if empty, use current app's name. + * @access public + * @return object|bool 如果没有model文件,返回false,否则返回model对象。If no model file, return false, else return the model object. + */ + public function loadModel($moduleName = '', $appName = '') + { + if(empty($moduleName)) $moduleName = $this->moduleName; + if(empty($appName)) $appName = $this->app->appName; + + global $loadedModels; + if(isset($loadedModels[$appName][$moduleName])) + { + $this->$moduleName = $loadedModels[$appName][$moduleName]; + $this->dao = $this->$moduleName->dao; + return $this->$moduleName; + } + + $modelFile = $this->app->setModelFile($moduleName, $appName); + + /** + * 如果没有model文件,尝试加载config配置信息。 + * If no model file, try load config. + */ + if(!helper::import($modelFile)) + { + $this->app->loadModuleConfig($moduleName, $appName); + $this->app->loadLang($moduleName, $appName); + $this->dao = new dao(); + return false; + } + + /** + * 如果没有扩展文件,model类名是$moduleName + 'model',如果有扩展,还需要增加ext前缀。 + * If no extension file, model class name is $moduleName + 'model', else with 'ext' as the prefix. + */ + $modelClass = class_exists('ext' . $appName . $moduleName. 'model') ? 'ext' . $appName . $moduleName . 'model' : $appName . $moduleName . 'model'; + if(!class_exists($modelClass)) + { + $modelClass = class_exists('ext' . $moduleName. 'model') ? 'ext' . $moduleName . 'model' : $moduleName . 'model'; + if(!class_exists($modelClass)) $this->app->triggerError(" The model $modelClass not found", __FILE__, __LINE__, $exit = true); + } + + /** + * 初始化model对象,在control对象中可以通过$this->$moduleName来引用。同时将dao对象赋为control对象的成员变量,方便引用。 + * Init the model object thus you can try $this->$moduleName to access it. Also assign the $dao object as a member of control object. + */ + $loadedModels[$appName][$moduleName] = new $modelClass($appName); + $this->$moduleName = $loadedModels[$appName][$moduleName]; + $this->dao = $this->$moduleName->dao; + + return $this->$moduleName; + } + + /** + * 获取控制器执行返回的数据,在output缓存中. + * Get controller data from output. + * + * @access public + * @return object. + */ + public function getData() + { + $output = ob_get_clean(); + $output = json_decode($output); + + if(isset($output->data)) $output->data = json_decode($output->data); + + return $output; + } + + /** + * 添加$_POST全局变量. + * Add data to $_POST. + * + * @param string $key + * @param mixed $value + * @access public + * @return void + */ + public function setPost($key, $value) + { + $_POST[$key] = $value; + } + + /** + * 批量添加$_POST全局变量. + * Batch set data to $_POST. + * + * @param string $fields + * @param mixed $object + * @access public + * @return void + */ + public function batchSetPost($fields, $object = '') + { + $fields = explode(',', $fields); + foreach($fields as $field) + { + /* + * If the field exists in request body, use it. + * Otherwise set default value from $object. + */ + if(isset($this->requestBody->$field)) + { + $value = $this->requestBody->$field; + } + else + { + if(!$object or !isset($object->$field)) continue; + $value = $object->$field; + } + + $this->setPost($field, $value); + } + } + + /** + * 确保字段不能为空. + * Make sure the fields is not empty. + * + * @param string $fields + * @param mixed $object + * @access public + * @return void + */ + public function requireFields($fields) + { + $fields = explode(',', $fields); + foreach($fields as $field) + { + if(!isset($_POST[$field])) + { + $module = $this->app->moduleName; + $name = isset($this->app->lang->$module->$field) ? $this->app->lang->$module->$field : $field; + $this->sendError(400, sprintf($this->app->lang->error->notempty, $name)); + } + } + } +} diff --git a/framework/api/router.class.php b/framework/api/router.class.php new file mode 100644 index 0000000000..9c6f96d773 --- /dev/null +++ b/framework/api/router.class.php @@ -0,0 +1,230 @@ +httpMethod = strtolower($_SERVER['REQUEST_METHOD']); + + if(!empty($_SERVER['PATH_INFO'])) + { + $this->path = rtrim($_SERVER['PATH_INFO'], '/'); + } + else + { + $this->path = rtrim((strpos($_SERVER['REQUEST_URI'], '?') > 0 ? strstr($_SERVER['REQUEST_URI'], '?', true) : $_SERVER['REQUEST_URI']), '/'); + } + + $dir = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/'); + if($dir != '') $this->path = substr($this->path, strlen($dir)); + + $subPos = strpos($this->path, '/', 1); + + $this->version = substr($this->path, 1, $subPos-1); + $this->path = substr($this->path, $subPos); + } + + /** + * 解析请求路径,找到处理方法 + * + * Parse request path, find entry and action. + * + * @param array $routes + * @access private + * @return void + */ + public function route($routes) + { + foreach($routes as $route => $target) + { + $patternAsRegex = preg_replace_callback( + '#:([\w]+)\+?#', + array($this, 'matchesCallback'), + str_replace(')', ')?', $route) + ); + if(substr($route, -1) === '/') $patternAsRegex .= '?'; + + /* Cache URL params' names and values if this route matches the current HTTP request. */ + if(!preg_match('#^' . $patternAsRegex . '$#', $this->path, $paramValues)) continue; + + /* Set module and action */ + $this->entry = $target; + $this->action = strtolower($_SERVER['REQUEST_METHOD']); + + /* Set params */ + foreach($this->paramNames as $name) + { + if(!isset($paramValues[$name])) continue; + + if(isset($this->paramNamesPath[$name])) + { + $this->params[$name] = explode('/', urldecode($paramValues[$name])); + } + else + { + $this->params[$name] = urldecode($paramValues[$name]); + } + } + return; + } + + $this->entry = 'error'; + $this->action = 'notFound'; + } + + /** + * 将路由路径参数转化为正则 + * + * Parse params of route to regular expression. + * + * @param string $param + * @access protected + * @return string + */ + protected function matchesCallback($m) + { + $this->paramNames[] = $m[1]; + return '(?P<' . $m[1] . '>[^/]+)'; + } + + /** + * 解析访问请求 + * + * Parse request. + * + * @access public + * @return void + */ + public function parseRequest() + { + /* If version of api don't exists, call parent method. */ + if(!$this->version) return parent::parseRequest(); + + $this->route($this->config->routes); + } + + /** + * 执行对应模块 + * + * Load the running module. + * + * @access public + * @return void + */ + public function loadModule() + { + /* If the version of api don't exists, call parent method. */ + if(!$this->version) return parent::loadModule(); + + $entry = strtolower($this->entry); + include($this->appRoot . "api/$this->version/entries/$entry.php"); + + $entryName = $this->entry . 'Entry'; + $entry = new $entryName(); + call_user_func_array(array($entry, $this->action), $this->params); + } + + /** + * 格式化旧版本API响应数据 + * + * Format old version data. + * + * @param string + * @access public + * @return string + */ + public function formatData($output) + { + /* If the version exists, return output directly. */ + if($this->version) return $output; + + $output = json_decode($output); + + $data = new stdClass(); + $data->status = isset($output->status) ? $output->status : $output->result; + if(isset($output->message)) $data->message = $output->message; + if(isset($output->data)) $data->data = json_decode($output->data); + $output = json_encode($data); + + unset($_SESSION['ENTRY_CODE']); + unset($_SESSION['VALID_ENTRY']); + + return $output; + } +} diff --git a/framework/base/control.class.php b/framework/base/control.class.php index 1778c5c804..f0d4a82df5 100644 --- a/framework/base/control.class.php +++ b/framework/base/control.class.php @@ -1,4 +1,5 @@ -viewType == 'json') { print(json_encode($data)); - die(helper::removeUTF8Bom(ob_get_clean())); + $response = helper::removeUTF8Bom(ob_get_clean()); + + if(defined('RUN_MODE') and RUN_MODE == 'api') return print($response); + + die($response); } /** @@ -927,6 +932,7 @@ class baseControl * @param string $methodName method name * @param string|array $vars the params passed, can be array(key=>value) or key1=value1&key2=value2 * @param string $viewType the view type + * @param string $onlybody remove header and footer or not in iframe * @access public * @return string the link string. */ diff --git a/framework/base/router.class.php b/framework/base/router.class.php index ad4e48f97d..b79e0f036b 100644 --- a/framework/base/router.class.php +++ b/framework/base/router.class.php @@ -851,15 +851,15 @@ class baseRouter { if(!defined('SESSION_STARTED')) { + /* If request header has token, use it as session for authentication. */ + $this->sessionID = isset($_SERVER['HTTP_TOKEN']) ? session_id($_SERVER['HTTP_TOKEN']) : session_id(); + $sessionName = $this->config->sessionVar; session_name($sessionName); session_set_cookie_params(0, $this->config->webRoot, '', $this->config->cookieSecure, true); if($this->config->customSession) session_save_path($this->getTmpRoot() . 'session'); session_start(); - /* If request header has token, use it as session for authentication. */ - $this->sessionID = isset($_SERVER['HTTP_TOKEN']) ? session_id($_SERVER['HTTP_TOKEN']) : session_id(); - if(isset($_GET[$this->config->sessionVar])) helper::restartSession($_GET[$this->config->sessionVar]); define('SESSION_STARTED', true); diff --git a/module/task/control.php b/module/task/control.php index 0c6540bbea..283a792918 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -99,7 +99,7 @@ class task extends control { $response['result'] = 'fail'; $response['message'] = dao::getError(); - $this->send($response); + return $this->send($response); } /* if the count of tasksID is 1 then check exists. */ @@ -110,7 +110,7 @@ class task extends control { $response['locate'] = $this->createLink('task', 'view', "taskID={$taskID['id']}"); $response['message'] = sprintf($this->lang->duplicate, $this->lang->task->common); - $this->send($response); + return $this->send($response); } } @@ -134,48 +134,48 @@ class task extends control $this->executeHooks($taskID); /* Return task id when call the API. */ - if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $taskID)); + if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $taskID)); /* If link from no head then reload. */ - if(isonlybody()) $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => 'parent')); + if(isonlybody()) return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => 'parent')); /* Locate the browser. */ if($this->app->getViewType() == 'xhtml') { $taskLink = $this->createLink('task', 'view', "taskID=$taskID"); $response['locate'] = $taskLink; - $this->send($response); + return $this->send($response); } if($this->post->after == 'continueAdding') { $response['message'] = $this->lang->task->successSaved . $this->lang->task->afterChoices['continueAdding']; $response['locate'] = $this->createLink('task', 'create', "executionID=$executionID&storyID={$this->post->story}&moduleID=$moduleID"); - $this->send($response); + return $this->send($response); } elseif($this->post->after == 'toTaskList') { setcookie('moduleBrowseParam', 0, 0, $this->config->webRoot, '', $this->config->cookieSecure, false); $taskLink = $this->createLink('execution', 'task', "executionID=$executionID&status=unclosed¶m=0&orderBy=id_desc"); $response['locate'] = $taskLink; - $this->send($response); + return $this->send($response); } elseif($this->post->after == 'toStoryList') { $response['locate'] = $storyLink; - $this->send($response); + return $this->send($response); } else { $response['locate'] = $taskLink; - $this->send($response); + return $this->send($response); } } - $users = $this->loadModel('user')->getPairs('noclosed|nodeleted'); - $members = $this->loadModel('user')->getTeamMemberPairs($executionID, 'execution', 'nodeleted'); - $showAllModule = isset($this->config->execution->task->allModule) ? $this->config->execution->task->allModule : ''; - $moduleOptionMenu = $this->tree->getTaskOptionMenu($executionID, 0, 0, $showAllModule ? 'allModule' : ''); + $users = $this->loadModel('user')->getPairs('noclosed|nodeleted'); + $members = $this->loadModel('user')->getTeamMemberPairs($executionID, 'execution', 'nodeleted'); + $showAllModule = isset($this->config->execution->task->allModule) ? $this->config->execution->task->allModule : ''; + $moduleOptionMenu = $this->tree->getTaskOptionMenu($executionID, 0, 0, $showAllModule ? 'allModule' : ''); /* Fix bug #3381. When the story module is the root module. */ if($storyID) @@ -212,7 +212,7 @@ class task extends control $position[] = html::a($taskLink, $execution->name); $position[] = $this->lang->task->common; $position[] = $this->lang->task->create; - + /* Set Custom*/ foreach(explode(',', $this->config->task->customCreateFields) as $field) $customFields[$field] = $this->lang->task->$field; if($execution->type == 'ops') unset($customFields['story']); @@ -227,17 +227,17 @@ class task extends control $this->view->showFields = $this->config->task->custom->createFields; $this->view->showAllModule = $showAllModule; - $this->view->title = $title; - $this->view->position = $position; - $this->view->execution = $execution; - $this->view->executions = $this->config->systemMode == 'classic' ? $executions : $this->execution->getByProject(0, 'all', 0, true); - $this->view->task = $task; - $this->view->users = $users; - $this->view->stories = $stories; - $this->view->testStoryIdList = $this->loadModel('story')->getTestStories(array_keys($stories), $execution->id); - $this->view->members = $members; - $this->view->blockID = $blockID; - $this->view->moduleOptionMenu = $moduleOptionMenu; + $this->view->title = $title; + $this->view->position = $position; + $this->view->execution = $execution; + $this->view->executions = $this->config->systemMode == 'classic' ? $executions : $this->execution->getByProject(0, 'all', 0, true); + $this->view->task = $task; + $this->view->users = $users; + $this->view->stories = $stories; + $this->view->testStoryIdList = $this->loadModel('story')->getTestStories(array_keys($stories), $execution->id); + $this->view->members = $members; + $this->view->blockID = $blockID; + $this->view->moduleOptionMenu = $moduleOptionMenu; $this->display(); } @@ -294,17 +294,17 @@ class task extends control if(!empty($_POST)) { $mails = $this->task->batchCreate($executionID); - if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); $taskIDList = array(); foreach($mails as $mail) $taskIDList[] = $mail->taskID; /* Return task id list when call the API. */ - if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'idList' => $taskIDList)); + if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'idList' => $taskIDList)); /* Locate the browser. */ - if(!empty($iframe)) $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => 'parent')); - $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $taskLink)); + if(!empty($iframe)) return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => 'parent')); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $taskLink)); } /* Set Custom*/ @@ -380,7 +380,7 @@ class task extends control if($comment == false) { $changes = $this->task->update($taskID); - if(dao::isError()) die(js::error(dao::getError())); + if(dao::isError()) return print(js::error(dao::getError())); $files = $this->loadModel('file')->saveUpload('task', $taskID); } @@ -407,9 +407,10 @@ class task extends control } } } + if(defined('RUN_MODE') && RUN_MODE == 'api') { - die(array('status' => 'success', 'data' => $taskID)); + return $this->send(array('status' => 'success', 'data' => $taskID)); } else { @@ -560,7 +561,10 @@ class task extends control { $this->loadModel('action'); $changes = $this->task->assign($taskID); + + if($this->viewType == 'json') return $this->send(array('result' => 'fail', 'message' => dao::getError())); if(dao::isError()) die(js::error(dao::getError())); + $actionID = $this->action->create('task', $taskID, 'Assigned', $this->post->comment, $this->post->assignedTo); $this->action->logHistory($actionID, $changes); @@ -647,7 +651,7 @@ class task extends control { if(isset($muletipleTasks[$taskID]) and $task->assignedTo != $this->app->user->account) continue; if(isset($muletipleTasks[$taskID]) and !isset($muletipleTasks[$taskID][$this->post->assignedTo])) continue; - + $changes = $this->task->assign($taskID); if(dao::isError()) die(js::error(dao::getError())); $actionID = $this->action->create('task', $taskID, 'Assigned', $this->post->comment, $this->post->assignedTo); @@ -754,7 +758,12 @@ class task extends control { $this->loadModel('action'); $changes = $this->task->start($taskID); - if(dao::isError()) die(js::error(dao::getError())); + + if(dao::isError()) + { + if($this->viewType == 'json') return $this->send(array('result' => 'fail', 'message' => dao::getError())); + die(js::error(dao::getError())); + } if($this->post->comment != '' or !empty($changes)) { @@ -909,7 +918,11 @@ class task extends control { $this->loadModel('action'); $changes = $this->task->finish($taskID); - if(dao::isError()) die(js::error(dao::getError())); + if(dao::isError()) + { + if($this->viewType == 'json') return $this->send(array('result' => 'fail', 'message' => dao::getError())); + die(js::error(dao::getError())); + } $files = $this->loadModel('file')->saveUpload('task', $taskID); $task = $this->task->getById($taskID); @@ -938,7 +951,7 @@ class task extends control if(isonlybody()) die(js::closeModal('parent.parent', 'this')); if(defined('RUN_MODE') && RUN_MODE == 'api') { - die(array('status' => 'success', 'data' => $taskID)); + return $this->send(array('result' => 'success', 'data' => $taskID)); } else { @@ -1275,11 +1288,11 @@ class task extends control public function delete($executionID, $taskID, $confirm = 'no') { $task = $this->task->getById($taskID); - if($task->parent < 0) die(js::alert($this->lang->task->cannotDeleteParent)); + if($task->parent < 0) return print(js::alert($this->lang->task->cannotDeleteParent)); if($confirm == 'no') { - die(js::confirm($this->lang->task->confirmDelete, inlink('delete', "executionID=$executionID&taskID=$taskID&confirm=yes"))); + return print(js::confirm($this->lang->task->confirmDelete, inlink('delete', "executionID=$executionID&taskID=$taskID&confirm=yes"))); } else { @@ -1298,7 +1311,7 @@ class task extends control $this->executeHooks($taskID); - die(js::locate($this->session->taskList, 'parent')); + return print(js::locate($this->session->taskList, 'parent')); } } diff --git a/www/api.php b/www/api.php index 1b6cd85a47..a216380cfb 100644 --- a/www/api.php +++ b/www/api.php @@ -18,7 +18,8 @@ define('RUN_MODE', 'api'); ob_start(); /* Load the framework. */ -include '../framework/router.class.php'; +include '../framework/api/router.class.php'; +include '../framework/api/entry.class.php'; include '../framework/control.class.php'; include '../framework/model.class.php'; include '../framework/helper.class.php'; @@ -27,30 +28,23 @@ include '../framework/helper.class.php'; $startTime = getTime(); /* Instance the app. */ -$app = router::createApp('pms', dirname(dirname(__FILE__)), 'router'); +$app = router::createApp('pms', dirname(dirname(__FILE__)), 'api'); /* Run the app. */ $common = $app->loadCommon(); /* Check entry. */ -$common->checkEntry(); +if(!$app->version) $common->checkEntry(); /* Set default params. */ $config->requestType = 'GET'; $config->default->view = 'json'; $app->parseRequest(); -$common->checkPriv(); +if(!$app->version) $common->checkPriv(); $app->loadModule(); -$output = json_decode(helper::removeUTF8Bom(ob_get_clean())); -$data = new stdClass(); -$data->status = isset($output->status) ? $output->status : $output->result; -if(isset($output->message)) $data->message = $output->message; -if(isset($output->data)) $data->data = json_decode($output->data); -$output = json_encode($data); -unset($_SESSION['ENTRY_CODE']); -unset($_SESSION['VALID_ENTRY']); +$output = ob_get_clean(); /* Flush the buffer. */ -echo helper::removeUTF8Bom($output); +echo helper::removeUTF8Bom($app->formatData($output));