From 341171bf1ae27610fe4b90f009e5cf5f2b645d64 Mon Sep 17 00:00:00 2001 From: aaronchen2k <462826@qq.com> Date: Thu, 16 Jan 2020 15:23:50 +0800 Subject: [PATCH] updte cron log format when output is empty or big --- module/ci/config.php | 2 +- module/ci/control.php | 4 ++-- module/ci/lang/zh-cn.php | 8 ++++---- module/cron/control.php | 6 ++++++ module/git/model.php | 20 +++++--------------- 5 files changed, 18 insertions(+), 22 deletions(-) diff --git a/module/ci/config.php b/module/ci/config.php index 36fbc9edf0..2717c30d7f 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*([a-z]+)\s+((?:story)|(?:task)|(?:bug))\s+#((\d|,)+)\s*/i' ); \ No newline at end of file +$config->repo->commitCommands = array( entity => '/\s*([a-z]+)\s+((?:build)|(?: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 260ae5f84f..45429a366f 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -293,8 +293,8 @@ 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); + $pattern = '/\s*([a-z]+)\s+((?:story)|(?:task)|(?:bug))\s+#((\d|,)+)\s*/i'; + preg_match($pattern, 'update fix bug #567,666 README.',$matches); $citask = $this->ci->getCitaskByID($id); if($_POST) diff --git a/module/ci/lang/zh-cn.php b/module/ci/lang/zh-cn.php index 9518b1a999..fc0ad9ed3b 100644 --- a/module/ci/lang/zh-cn.php +++ b/module/ci/lang/zh-cn.php @@ -87,10 +87,10 @@ $lang->citask->day = '天'; $lang->citask->lastExe = '最后执行'; $lang->citask->scheduleTime = '时间'; -$lang->citask->dayTypeList = array(workDay=>'工作日', everyDay=>'每天'); -$lang->citask->buildTypeList = array(build=>'仅构建', buildAndDeploy=>'构建部署', buildAndTest=>'构建测试'); -$lang->citask->triggerTypeList = array(tag=>'打标签', commit=>'代码提交注释', schedule=>'定时计划'); -$lang->citask->scheduleTypeList = array(corn=>'Corn表达式', custom=>'自定义'); +$lang->citask->dayTypeList = array('workDay'=>'工作日', 'everyDay'=>'每天'); +$lang->citask->buildTypeList = array('build'=>'仅构建', 'buildAndDeploy'=>'构建部署', 'buildAndTest'=>'构建测试'); +$lang->citask->triggerTypeList = array('tag'=>'打标签', 'commit'=>'代码提交注释', 'schedule'=>'定时计划'); +$lang->citask->scheduleTypeList = array('corn'=>'Corn表达式', 'custom'=>'自定义'); // repo $lang->repo->common = '代码库'; diff --git a/module/cron/control.php b/module/cron/control.php index d8036a4df0..5b5faef8c2 100644 --- a/module/cron/control.php +++ b/module/cron/control.php @@ -221,6 +221,12 @@ class cron extends control /* Save log. */ $log = ''; $time = $now->format('G:i:s'); + if (empty($output)) { + $output = '\n'; + } + if (count($output) > 100) { // return if output a lot of info + $output = "\n" . $output; + } $log = "$time task " . $id . " executed,\ncommand: $cron[command].\nreturn : $return.\noutput : $output\n"; $this->cron->logCron($log); unset($log); diff --git a/module/git/model.php b/module/git/model.php index 404b43d082..d870a8b32f 100644 --- a/module/git/model.php +++ b/module/git/model.php @@ -113,25 +113,15 @@ class gitModel extends model $this->printLog("comment is\n----------\n" . trim($log->msg) . "\n----------"); $objects = $this->parseComment($log->msg); - if($objects) - { - $this->printLog('extract' . - ' story:' . join(' ', $objects['stories']) . - ' task:' . join(' ', $objects['tasks']) . - ' bug:' . join(',', $objects['bugs'])); - - $this->saveAction2PMS($objects, $log); - } - else - { - $this->printLog('no objects found' . "\n"); + if($objects) { + $this->printLog('extract ' . json_encode($objects)); } } $this->saveLastRevision($latestRevision); $this->printLog("save revision $latestRevision"); $this->deleteRestartFile(); - $this->printLog("\n\nrepo $name finished"); + $this->printLog("\n\nrepo ' . $repo->id . ': ' . $repo->path . ' finished"); // check ci commands in logs $pattern = $this->config->repo->commitCommands['entity']; @@ -213,7 +203,7 @@ class gitModel extends model foreach($repoObjs as $repoInDb) { if(strtolower($repoInDb->SCM) === 'git' && !in_array($repoInDb->path, $gitRepos)) { - $gitRepos[] = (object)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; } } @@ -415,7 +405,7 @@ class gitModel extends model $entityType = $matches[2]; $entityIds = $matches[3]; - $ret[$entityType] = array(action=>$action, entities=> explode(",", $entityIds)); + $ret[$entityType] = array('action'=>$action, 'entities'=> explode(",", $entityIds)); } return $ret;