From 9c3c8022c9d6e7a82f98531aff677a21c766cf5c Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 16 Jun 2021 20:04:47 +0800 Subject: [PATCH] * 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)