From fb7a45efe38da108df74a3cae002e8915661a121 Mon Sep 17 00:00:00 2001 From: aaronchen2k <462826@qq.com> Date: Thu, 16 Jan 2020 14:29:05 +0800 Subject: [PATCH] retrive commands from code ci comments --- module/ci/config.php | 2 +- module/ci/control.php | 3 +++ module/git/model.php | 41 +++++++++++++++++++++-------------------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/module/ci/config.php b/module/ci/config.php index 3c2019b01d..36fbc9edf0 100644 --- a/module/ci/config.php +++ b/module/ci/config.php @@ -15,4 +15,4 @@ $config->repo->binary = '|pdf|'; $config->repo->requiredFields = 'name,repo,buildType,jenkins,jenkinsTask,triggerType'; -$config->repo->commitCommands = array(entity=>'/(.*)\s(?:(?:requirement)|(?:task)|(?:Bug))\s?#(.*)/Ui'); \ No newline at end of file +$config->repo->commitCommands = array( entity => '/\s*([a-z]+)\s+((?:story)|(?:task)|(?:bug))\s+#((\d|,)+)\s*/i' ); \ No newline at end of file diff --git a/module/ci/control.php b/module/ci/control.php index 900a18ee8e..260ae5f84f 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -293,6 +293,9 @@ class ci extends control */ public function editCitask($id) { + $pattern = '/\s*([a-z]+)\s+((?:story)|(?:task)|(?:bug))\s+#((?\d|,)+)\s*/i'; + preg_match($pattern, ' update README. fix bug #123,456',$matches); + $citask = $this->ci->getCitaskByID($id); if($_POST) { diff --git a/module/git/model.php b/module/git/model.php index 9f710fc306..404b43d082 100644 --- a/module/git/model.php +++ b/module/git/model.php @@ -132,6 +132,12 @@ class gitModel extends model $this->printLog("save revision $latestRevision"); $this->deleteRestartFile(); $this->printLog("\n\nrepo $name finished"); + + // check ci commands in logs + $pattern = $this->config->repo->commitCommands['entity']; + $matches = array(); + preg_match($pattern, 'fix bug #123',$matches); + } } @@ -207,7 +213,7 @@ class gitModel extends model foreach($repoObjs as $repoInDb) { if(strtolower($repoInDb->SCM) === 'git' && !in_array($repoInDb->path, $gitRepos)) { - $gitRepos[] = array(id=>$repoInDb->id, path => $repoInDb->path, encoding => 'utf-8'); + $gitRepos[] = (object)array(id=>$repoInDb->id, path => $repoInDb->path, encoding => 'utf-8'); $paths[] = $repoInDb->path; } } @@ -398,27 +404,21 @@ class gitModel extends model */ public function parseComment($comment) { - $stories = array(); - $tasks = array(); - $bugs = array(); + $ret = array(); - // bug|story|task(case insensitive) + some space + #|:|:(Chinese) + id lists(maybe join with space or ,) - // $comment = "bug # 1,2,3,4 Bug:1 2 3 4 5 story:9999,1234566 story:456,1234566"; - $commonReg = "(?:\s){0,}(?:#|:|:){0,}([0-9, ]{1,})"; - $taskReg = '/task' . $commonReg . '/i'; - $storyReg = '/story' . $commonReg . '/i'; - $bugReg = '/bug' . $commonReg . '/i'; + $pattern = $this->config->repo->commitCommands['entity']; + $matches = array(); + preg_match($pattern, $comment,$matches); + if(count($matches) > 1) + { + $action = $matches[1]; + $entityType = $matches[2]; + $entityIds = $matches[3]; - if(preg_match_all($storyReg, $comment, $result)) $stories = join(' ', $result[1]); - if(preg_match_all($taskReg, $comment, $result)) $tasks = join(' ', $result[1]); - if(preg_match_all($bugReg, $comment, $result)) $bugs = join(' ', $result[1]); + $ret[$entityType] = array(action=>$action, entities=> explode(",", $entityIds)); + } - if($stories) $stories = array_unique(explode(' ', str_replace(',', ' ', $stories))); - if($tasks) $tasks = array_unique(explode(' ', str_replace(',', ' ', $tasks))); - if($bugs) $bugs = array_unique(explode(' ', str_replace(',', ' ', $bugs))); - - if(!$stories and !$tasks and !$bugs) return array(); - return array('stories' => $stories, 'tasks' => $tasks, 'bugs' => $bugs); + return $ret; } /** @@ -773,7 +773,7 @@ class gitModel extends model */ public function saveLastRevision($revision) { - file_put_contents($this->logFile, $revision); + $ret = file_put_contents($this->logFile, $revision); } /** @@ -788,6 +788,7 @@ class gitModel extends model echo helper::now() . " $log\n"; } + /** * Build URL. *