to support muti-line and more than one commands in one commit

This commit is contained in:
aaronchen2k
2020-01-16 17:11:45 +08:00
parent 341171bf1a
commit 74e29ce8be
3 changed files with 14 additions and 19 deletions
+1 -1
View File
@@ -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+((?:build)|(?:story)|(?:task)|(?:bug))\s+#((\d|,)+)\s*/i' );
$config->repo->commitCommands = array( entity => '/\s*([a-z]+)\s+((?:build)|(?:story)|(?:task)|(?:bug))\s+#((?:\d|,)+)\s*/i' );
+2 -2
View File
@@ -222,9 +222,9 @@ class cron extends control
$log = '';
$time = $now->format('G:i:s');
if (empty($output)) {
$output = '\n';
$output = "\n";
}
if (count($output) > 100) { // return if output a lot of info
if (strlen($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";
+11 -16
View File
@@ -102,6 +102,8 @@ class gitModel extends model
$this->printLog("get " . count($logs) . " logs");
$this->printLog('begin parsing logs');
$latestRevision = $logs[0]->revision;
$allCommands = new stdClass();
foreach($logs as $log)
{
$this->printLog("parsing log {$log->revision}");
@@ -112,10 +114,7 @@ class gitModel extends model
}
$this->printLog("comment is\n----------\n" . trim($log->msg) . "\n----------");
$objects = $this->parseComment($log->msg);
if($objects) {
$this->printLog('extract ' . json_encode($objects));
}
$this->parseComment($log->msg, $allCommands);
}
$this->saveLastRevision($latestRevision);
@@ -123,11 +122,7 @@ class gitModel extends model
$this->deleteRestartFile();
$this->printLog("\n\nrepo ' . $repo->id . ': ' . $repo->path . ' finished");
// check ci commands in logs
$pattern = $this->config->repo->commitCommands['entity'];
$matches = array();
preg_match($pattern, 'fix bug #123',$matches);
$this->printLog('extract ' . json_encode($allCommands));
}
}
@@ -388,14 +383,13 @@ class gitModel extends model
/**
* Parse the comment of git, extract object id list from it.
*
* @param string $comment
* @param string $comment
* @param array $allCommands
* @access public
* @return array
*/
public function parseComment($comment)
public function parseComment($comment, &$allCommands)
{
$ret = array();
$pattern = $this->config->repo->commitCommands['entity'];
$matches = array();
preg_match($pattern, $comment,$matches);
@@ -405,10 +399,11 @@ class gitModel extends model
$entityType = $matches[2];
$entityIds = $matches[3];
$ret[$entityType] = array('action'=>$action, 'entities'=> explode(",", $entityIds));
}
$currArr = $allCommands[$entityType][$action];
$newArr = explode(",", $entityIds);
return $ret;
$allCommands[$entityType][$action] = array_keys(array_flip($currArr) + array_flip($newArr));
}
}
/**