From f3b6a384034402fa3b009f18de8cd6774bfdd031 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 29 Oct 2021 10:06:50 +0800 Subject: [PATCH 1/2] * Adjust and correct codes for gitlab module. --- module/gitlab/lang/en.php | 2 +- module/gitlab/model.php | 15 +++++++-------- module/gitlab/view/view.html.php | 1 - 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/module/gitlab/lang/en.php b/module/gitlab/lang/en.php index 7bbf2594fd..10feba0f39 100644 --- a/module/gitlab/lang/en.php +++ b/module/gitlab/lang/en.php @@ -13,7 +13,7 @@ $lang->gitlab->delete = 'Delete GitLab'; $lang->gitlab->confirmDelete = 'Do you want to delete this GitLab server?'; $lang->gitlab->gitlabAccount = 'GitLab Account'; $lang->gitlab->zentaoAccount = 'Zentao Account'; -$lang->gitlab->serverFail = 'Conntect to GitLab server failed, please check the GitLab server.'; +$lang->gitlab->serverFail = 'Connect to GitLab server failed, please check the GitLab server.'; $lang->gitlab->browseAction = 'GitLab List'; $lang->gitlab->deleteAction = 'Delete GitLab'; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index b1d2f34ee0..e47013c2e2 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -386,7 +386,7 @@ 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)); } @@ -456,7 +456,7 @@ class gitlabModel extends model * * @param int $gitlabID * @access public - * @return void + * @return array */ public function apiGetProjects($gitlabID) { @@ -673,6 +673,7 @@ class gitlabModel extends model public function apiUpdateHook($gitlabID, $projectID, $hookID) { $apiRoot = $this->getApiRoot($gitlabID); + $url = sprintf($apiRoot, "/projects/{$projectID}/hooks/{$hookID}"); $postData = new stdclass; $postData->enable_ssl_verification = "false"; @@ -681,8 +682,6 @@ class gitlabModel extends model $postData->push_events = "true"; $postData->tag_push_events = "true"; $postData->note_events = "true"; - $postData->url = $url; - $postData->token = $token; $url = sprintf($apiRoot, "/projects/{$projectID}/hooks/{$hookID}"); return commonModel::http($url, $postData, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT')); @@ -1231,9 +1230,9 @@ class gitlabModel extends model /** * Create webhook for zentao. * - * @param int $products - * @param int $gitlabID - * @param int $projectID + * @param array $products + * @param int $gitlabID + * @param int $projectID * @access public * @return bool */ @@ -1346,7 +1345,7 @@ class gitlabModel extends model if($value) $issue->$field = $value; } - if($isset($issue->assignee_id) and $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'; diff --git a/module/gitlab/view/view.html.php b/module/gitlab/view/view.html.php index 30fc445968..b1cb6b07d3 100644 --- a/module/gitlab/view/view.html.php +++ b/module/gitlab/view/view.html.php @@ -27,4 +27,3 @@ - From ff55234a7b72d974d883fdaaffc044bfe781f441 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Fri, 29 Oct 2021 17:33:13 +0800 Subject: [PATCH 2/2] * Correct codes in job and compile module. --- module/compile/model.php | 2 +- module/job/control.php | 2 +- module/job/model.php | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/module/compile/model.php b/module/compile/model.php index 3da3233e36..ce3a4b538b 100644 --- a/module/compile/model.php +++ b/module/compile/model.php @@ -134,7 +134,7 @@ class compileModel extends model if($job->triggerType == 'tag') { - $lastTag = $this->getLastTagByRepo($repo); + $lastTag = $this->loadModel('job')->getLastTagByRepo($repo); if($lastTag) { $job->lastTag = $lastTag; diff --git a/module/job/control.php b/module/job/control.php index 383fe16b1c..b17d81e552 100644 --- a/module/job/control.php +++ b/module/job/control.php @@ -352,7 +352,7 @@ class job extends control if($productLeft == $productRight) $matchedProducts[$productName] = $productRight; } } - die(json_encode($matchedProduct)); + die(json_encode($matchedProducts)); } $productName = $this->loadModel('product')->getByID($repo->product)->name; diff --git a/module/job/model.php b/module/job/model.php index c9344e89a4..ecd520b333 100644 --- a/module/job/model.php +++ b/module/job/model.php @@ -364,7 +364,7 @@ class jobModel extends model if($job->triggerType == 'tag') { - $lastTag = $this->getLastTagByRepo($repo); + $lastTag = $this->getLastTagByRepo($repo, $job); if($lastTag) { $build->tag = $lastTag; @@ -430,7 +430,7 @@ class jobModel extends model /** * Exec gitlab pipeline. * - * @param int $job + * @param object $job * @access public * @return void */ @@ -473,10 +473,11 @@ class jobModel extends model * Get last tag of one repo. * * @param object $repo + * @param object $job * @access public * @return void */ - public function getLastTagByRepo($repo) + public function getLastTagByRepo($repo, $job) { if($repo->SCM == 'Subversion') {