From 012f334c2e5bead13764b582976734de8c2f32b0 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 17 Jun 2021 14:51:39 +0800 Subject: [PATCH 1/3] * 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 2/3] * 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 3/3] * 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]: ""; }