From a6169ffec55532503199c532102913c80947fa1e Mon Sep 17 00:00:00 2001 From: wangyidong Date: Wed, 4 Mar 2020 16:05:08 +0800 Subject: [PATCH] * finish task #6913. --- module/git/model.php | 32 ++++++++++++++++++++++++-------- module/integration/model.php | 3 ++- module/svn/model.php | 36 ++++++++++++++++++++++++++---------- 3 files changed, 52 insertions(+), 19 deletions(-) diff --git a/module/git/model.php b/module/git/model.php index f5f5af5ccc..771aadf31d 100644 --- a/module/git/model.php +++ b/module/git/model.php @@ -88,6 +88,17 @@ class gitModel extends model $this->setLogRoot(); $this->setRestartFile(); + $this->loadModel('compile'); + /* Get commit triggerType integrations by repoIdList. */ + $commitPlans = $this->loadModel('integration')->getListByTriggerType('commit', array_keys($this->repos)); + $commitGroup = array(); + foreach($commitPlans as $integration) $commitGroup[$integration->repo][$integration->id] = $integration; + + /* Get tag triggerType integrations by repoIdList. */ + $tagPlans = $this->integration->getListByTriggerType('tag', array_keys($this->repos)); + $tagGroup = array(); + foreach($tagPlans as $integration) $tagGroup[$integration->repo][$integration->id] = $integration; + foreach($this->repos as $repo) { $this->printLog("begin repo $repo->id"); @@ -129,6 +140,16 @@ class gitModel extends model { $this->printLog('no objects found' . "\n"); } + + /* Create compile by comment. */ + $integrations = zget($commitGroup, $repoID, array()); + foreach($integrations as $integration) + { + foreach(explode(',', $integration->comment) as $comment) + { + if(strpos($log->msg, $comment) !== false) $this->compile->createByIntegration($integration->id); + } + } } $this->saveLastRevision($latestRevision); @@ -137,13 +158,8 @@ class gitModel extends model $this->printLog("\n\nrepo #" . $repo->id . ': ' . $repo->path . " finished"); } - // Create compile by integration. - $integrations = zget($objects, 'integrations', array()); - $this->loadModel('compile'); - foreach($integrations as $id) $this->compile->createByIntegration($id); - // Create compile by tag. - $integrations = $this->dao->select('*')->from(TABLE_INTEGRATION)->where('triggerType')->eq('tag')->andWhere('repo')->eq($repo->id)->fetchAll('id'); + $integrations = zget($tagGroup, $repoID, array()); foreach($integrations as $integration) { $dirs = $this->getRepoTags($repo); @@ -209,8 +225,8 @@ class gitModel extends model { unset($repo->acl); unset($repo->desc); - $gitRepos[] = $repo; - $paths[$repo->path] = $repo->path; + $gitRepos[$repo->id] = $repo; + $paths[$repo->path] = $repo->path; } } diff --git a/module/integration/model.php b/module/integration/model.php index 1682f52fec..fb7855233f 100644 --- a/module/integration/model.php +++ b/module/integration/model.php @@ -49,11 +49,12 @@ class integrationModel extends model * @access public * @return array */ - public function getListByTriggerType($triggerType) + public function getListByTriggerType($triggerType, $repoIdList = array()) { return $this->dao->select('*')->from(TABLE_INTEGRATION) ->where('deleted')->eq('0') ->andWhere('triggerType')->eq($triggerType) + ->beginIF($repoIdList)->andWhere('repo')->in($repoIdList)->fi() ->fetchAll('id'); } diff --git a/module/svn/model.php b/module/svn/model.php index 13d5d790f3..258113004a 100644 --- a/module/svn/model.php +++ b/module/svn/model.php @@ -88,9 +88,20 @@ class svnModel extends model $this->setLogRoot(); $this->setRestartFile(); - foreach($this->repos as $name => $repo) + $this->loadModel('compile'); + /* Get commit triggerType integrations by repoIdList */ + $commitPlans = $this->loadModel('integration')->getListByTriggerType('commit', array_keys($this->repos)); + $commitGroup = array(); + foreach($commitPlans as $integration) $commitGroup[$integration->repo][$integration->id] = $integration; + + /* Get tag triggerType integrations by repoIdList */ + $tagPlans = $this->integration->getListByTriggerType('tag', array_keys($this->repos)); + $tagGroup = array(); + foreach($tagPlans as $integration) $tagGroup[$integration->repo][$integration->id] = $integration; + + foreach($this->repos as $repoID => $repo) { - $this->printLog("begin repo $name"); + $this->printLog("begin repo {$repo->name}"); if(!$this->setRepo($repo)) return false; $savedRevision = $this->getSavedRevision(); @@ -129,6 +140,16 @@ class svnModel extends model $this->printLog('no objects found' . "\n"); } + /* Create compile by comment. */ + $integrations = zget($commitGroup, $repoID, array()); + foreach($integrations as $integration) + { + foreach(explode(',', $integration->comment) as $comment) + { + if(strpos($log->msg, $comment) !== false) $this->compile->createByIntegration($integration->id); + } + } + if($log->revision > $savedRevision) $savedRevision = $log->revision; } @@ -138,13 +159,8 @@ class svnModel extends model $this->printLog("\n\nrepo #" . $repo->id . ': ' . $repo->path . " finished"); } - // Create compile by integration. - $integrations = zget($objects, 'integrations', array()); - $this->loadModel('compile'); - foreach($integrations as $id) $this->compile->createByIntegration($id); - /* Create compile by tag. */ - $integrations = $this->dao->select('*')->from(TABLE_INTEGRATION)->where('triggerType')->eq('tag')->andWhere('repo')->eq($repo->id)->fetchAll('id'); + $integrations = zget($tagGroup, $repoID, array()); foreach($integrations as $integration) { $dirs = $this->getRepoTags($repo, $integration->svnDir); @@ -213,8 +229,8 @@ class svnModel extends model unset($repo->acl); unset($repo->desc); - $svnRepos[] = $repo; - $paths[$repo->path] = $repo->path; + $svnRepos[$repo->id] = $repo; + $paths[$repo->path] = $repo->path; } if(empty($svnRepos)) echo "You must set one svn repo.\n";