From 6c84ee47b7bab1c3ebe2bc02be1b7d342eac5c29 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Tue, 9 Apr 2024 16:12:49 +0800 Subject: [PATCH] * Adjust task check repo logic. --- module/task/control.php | 1 + module/task/ui/view.html.php | 6 +----- module/task/zen.php | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/module/task/control.php b/module/task/control.php index 01f07d2af3..cd4b754d8f 100755 --- a/module/task/control.php +++ b/module/task/control.php @@ -390,6 +390,7 @@ class task extends control $this->view->modulePath = $this->tree->getParents($task->module); $this->view->linkMRTitles = $this->loadModel('mr')->getLinkedMRPairs($taskID, 'task'); $this->view->linkCommits = $this->loadModel('repo')->getCommitsByObject($taskID, 'task'); + $this->view->hasGitRepo = $this->taskZen->checkGitRepo($execution->id); $this->display(); } diff --git a/module/task/ui/view.html.php b/module/task/ui/view.html.php index 0117027d9a..6716e0a9f5 100644 --- a/module/task/ui/view.html.php +++ b/module/task/ui/view.html.php @@ -35,11 +35,7 @@ if(!empty($actions)) $actions = array_merge($actions['mainActions'], array('type if(!$hasDivider) unset($actions['type']); foreach($actions as $key => $action) { - if(isset($action['url']) && strpos($action['url'], 'createBranch') !== false) - { - $hasRepo = $this->loadModel('repo')->getRepoPairs('execution', $task->execution, false); - if(empty($hasRepo)) unset($actions[$key]); - } + if(isset($action['url']) && strpos($action['url'], 'createBranch') !== false && empty($hasGitRepo)) unset($actions[$key]); if(isset($action['url']) && strpos($action['url'], 'view') !== false && $task->parent == 0) unset($actions[$key]); if(isset($actions[$key]['url'])) { diff --git a/module/task/zen.php b/module/task/zen.php index b31a568e34..b94c1d8bbf 100644 --- a/module/task/zen.php +++ b/module/task/zen.php @@ -1909,4 +1909,29 @@ class taskZen extends task return $executionID; } + + /** + * 检查是否有gitlab, gitea, gogs, gitfox 代码库。 + * Check gitlab, gitea, gogs, gitfox repo for execution. + * + * @param int $executionID + * @access protected + * @return bool + */ + protected function checkGitRepo(int $executionID): bool + { + $this->loadModel('repo'); + $repoList = $this->repo->getListBySCM(implode(',', $this->config->repo->gitServiceTypeList), 'haspriv'); + $productIds = $this->loadModel('product')->getProductIDByProject($executionID, false); + foreach($repoList as $repo) + { + $linkedProducts = explode(',', $repo->product); + foreach($productIds as $productID) + { + if(in_array($productID, $linkedProducts)) return true; + } + } + + return false; + } }