* finish task #6893.
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
<?php
|
||||
class scm
|
||||
{
|
||||
public $commitCommandRegx = '/\s*([a-z]+)\s+((?:build)|(?:story)|(?:task)|(?:bug))\s+#((?:\d|,)+)\s*/i';
|
||||
public $tagCommandRegx = '/build[\-_]#((?:\d|,)+)/i';
|
||||
|
||||
public $engine;
|
||||
|
||||
public function setEngine($repo)
|
||||
@@ -80,98 +77,6 @@ class scm
|
||||
{
|
||||
return $this->engine->getCommits($version, $count, $branch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the comment of git, extract object id list from it.
|
||||
*
|
||||
* @param string $comment
|
||||
* @param array $allCommands
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function parseComment($comment, &$allCommands)
|
||||
{
|
||||
$pattern = $this->commitCommandRegx;
|
||||
$matches = array();
|
||||
preg_match_all($pattern, $comment,$matches);
|
||||
|
||||
$stories = array();
|
||||
$tasks = array();
|
||||
$bugs = array();
|
||||
|
||||
if(count($matches) > 1 && count($matches[1]) > 0)
|
||||
{
|
||||
$i = 0;
|
||||
foreach($matches[1] as $action)
|
||||
{
|
||||
$action = $matches[1][$i];
|
||||
$entityType = $matches[2][$i];
|
||||
$entityIds = $matches[3][$i];
|
||||
|
||||
$currArr = $allCommands[$entityType][$action];
|
||||
if (empty($currArr)) $currArr = [];
|
||||
|
||||
$newArr = explode(",", $entityIds);
|
||||
$allCommands[$entityType][$action] = array_keys(array_flip($currArr) + array_flip($newArr));
|
||||
|
||||
if ($entityType === 'story')
|
||||
{
|
||||
$stories = array_merge($stories, $newArr);
|
||||
} else if ($entityType === 'task')
|
||||
{
|
||||
$tasks = array_merge($tasks, $newArr);
|
||||
} else if ($entityType === 'bug')
|
||||
{
|
||||
$bugs = array_merge($bugs, $newArr);
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
return array('stories' => $stories, 'tasks' => $tasks, 'bugs' => $bugs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the tag, extract task list from it.
|
||||
*
|
||||
* @param string $comment
|
||||
* @param array $jobToBuild
|
||||
* @access public
|
||||
*/
|
||||
public function parseTag($comment, &$jobToBuild)
|
||||
{
|
||||
$pattern = $this->tagCommandRegx;
|
||||
$matches = array();
|
||||
preg_match($pattern, $comment,$matches);
|
||||
|
||||
if(count($matches) > 0)
|
||||
{
|
||||
$entityIds = $matches[1];
|
||||
|
||||
if (empty($taskToBuild)) $taskToBuild = [];
|
||||
|
||||
$newArr = explode(",", $entityIds);
|
||||
$jobToBuild = array_keys(array_flip($taskToBuild) + array_flip($newArr));
|
||||
}
|
||||
}
|
||||
|
||||
public function iconvComment($comment, $encodings)
|
||||
{
|
||||
/* Get encodings. */
|
||||
if($encodings == '') return $comment;
|
||||
$encodings = explode(',', $encodings);
|
||||
|
||||
/* Try convert. */
|
||||
foreach($encodings as $encoding)
|
||||
{
|
||||
if($encoding == 'utf-8') continue;
|
||||
$result = helper::convertEncoding($comment, $encoding);
|
||||
if($result) return $result;
|
||||
}
|
||||
|
||||
return $comment;
|
||||
}
|
||||
}
|
||||
|
||||
function escapeCmd($cmd)
|
||||
|
||||
@@ -72,7 +72,7 @@ class git extends control
|
||||
$path = helper::safe64Decode($path);
|
||||
if(common::hasPriv('repo', 'view'))
|
||||
{
|
||||
$repos = $this->loadModel('repo')->listAll();
|
||||
$repos = $this->loadModel('repo')->getList();
|
||||
foreach($repos as $repo)
|
||||
{
|
||||
if($repo->SCM != 'Git') continue;
|
||||
@@ -121,11 +121,10 @@ class git extends control
|
||||
}
|
||||
|
||||
$parsedObjects = array('stories' => array(), 'tasks' => array(), 'bugs' => array());
|
||||
$this->loadModel('repo');
|
||||
foreach($parsedLogs as $log)
|
||||
{
|
||||
$allCommands = [];
|
||||
$scm = $this->app->loadClass('scm');
|
||||
$objects = $scm->parseComment($log->msg, $allCommands);
|
||||
$objects = $this->repo->parseComment($log->msg);
|
||||
|
||||
if($objects)
|
||||
{
|
||||
@@ -184,9 +183,7 @@ class git extends control
|
||||
$parsedFiles[$action][] = ltrim($path, '/');
|
||||
}
|
||||
|
||||
$allCommands = [];
|
||||
$scm = $this->app->loadClass('scm');
|
||||
$objects = $scm->parseComment($message, $allCommands);
|
||||
$objects = $this->loadModel('repo')->parseComment($message);
|
||||
|
||||
if($objects)
|
||||
{
|
||||
|
||||
+22
-29
@@ -71,6 +71,7 @@ class gitModel extends model
|
||||
{
|
||||
parent::__construct();
|
||||
$this->loadModel('action');
|
||||
$this->loadModel('repo');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,16 +95,18 @@ class gitModel extends model
|
||||
|
||||
$savedRevision = $this->getSavedRevision();
|
||||
$this->printLog("start from revision $savedRevision");
|
||||
$logs = $this->getRepoLogs($repo, $savedRevision);
|
||||
if(!empty($logs)) {
|
||||
$logs = $this->getRepoLogs($repo, $savedRevision);
|
||||
$objects = array();
|
||||
if(!empty($logs))
|
||||
{
|
||||
$this->printLog("get " . count($logs) . " logs");
|
||||
$this->printLog('begin parsing logs');
|
||||
$latestRevision = $logs[0]->revision;
|
||||
|
||||
$allCommands = [];
|
||||
foreach ($logs as $log) {
|
||||
foreach($logs as $log)
|
||||
{
|
||||
$this->printLog("parsing log {$log->revision}");
|
||||
if ($log->revision == $savedRevision)
|
||||
if($log->revision == $savedRevision)
|
||||
{
|
||||
$this->printLog("{$log->revision} alread parsed, commit it");
|
||||
continue;
|
||||
@@ -111,8 +114,7 @@ class gitModel extends model
|
||||
|
||||
$this->printLog("comment is\n----------\n" . trim($log->msg) . "\n----------");
|
||||
|
||||
$scm = $this->app->loadClass('scm');
|
||||
$objects = $scm->parseComment($log->msg, $allCommands);
|
||||
$objects = $this->repo->parseComment($log->msg);
|
||||
|
||||
if($objects)
|
||||
{
|
||||
@@ -133,48 +135,40 @@ class gitModel extends model
|
||||
$this->printLog("save revision $latestRevision");
|
||||
$this->deleteRestartFile();
|
||||
$this->printLog("\n\nrepo ' . $repo->id . ': ' . $repo->path . ' finished");
|
||||
|
||||
$this->printLog('extract commands from logs' . json_encode($allCommands));
|
||||
}
|
||||
|
||||
// exe ci task from logs
|
||||
$cijobIDs = $allCommands['build']['start'];
|
||||
foreach($cijobIDs as $id)
|
||||
{
|
||||
$this->loadModel('ci')->exeJob($id);
|
||||
}
|
||||
$cijobIdList = zget($objects, 'testtasks', array());
|
||||
$this->loadModel('integration');
|
||||
foreach($cijobIdList as $id) $this->integration->exec($id);
|
||||
|
||||
// dealwith tag commands
|
||||
$this->printLog("dealwith tag commands");
|
||||
$savedTag = $this->getSavedTag();
|
||||
|
||||
$tags = $this->getRepoTags($repo);
|
||||
if(!empty($tags)) {
|
||||
if(!empty($tags))
|
||||
{
|
||||
$arriveLastTag = false;
|
||||
$jobToBuild = [];
|
||||
foreach ($tags as $tag) {
|
||||
if (!empty($savedTag) && $tag === $savedTag) // get the last build tag position
|
||||
$jobToBuild = array();
|
||||
foreach($tags as $tag)
|
||||
{
|
||||
if(!empty($savedTag) && $tag === $savedTag) // get the last build tag position
|
||||
{
|
||||
$arriveLastTag = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($savedTag) && !$arriveLastTag) // not get
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(!empty($savedTag) && !$arriveLastTag) continue;
|
||||
|
||||
$scm = $this->app->loadClass('scm');
|
||||
$scm->parseTag($tag, $jobToBuild);
|
||||
$jobToBuild += $this->repo->parseTag($tag);
|
||||
}
|
||||
|
||||
$this->saveLastTag($tags[count($tags) - 1]);
|
||||
|
||||
$this->printLog('extract tasks to build: ' . json_encode($jobToBuild));
|
||||
|
||||
foreach ($jobToBuild as $id) {
|
||||
$this->loadModel('ci')->exeJob($id);
|
||||
}
|
||||
foreach($jobToBuild as $id) $this->integration->exec($id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -563,8 +557,7 @@ class gitModel extends model
|
||||
$action->action = 'gitcommited';
|
||||
$action->date = $log->date;
|
||||
|
||||
$scm = $this->app->loadClass('scm');
|
||||
$action->comment = htmlspecialchars($scm->iconvComment($log->msg, $encodings));
|
||||
$action->comment = htmlspecialchars($this->repo->iconvComment($log->msg, $encodings));
|
||||
$action->extra = substr($log->revision, 0, 10);
|
||||
|
||||
$changes = $this->createActionChanges($log, $repoRoot);
|
||||
|
||||
@@ -39,3 +39,21 @@ $config->repo->edit = new stdclass();
|
||||
$config->repo->edit->requiredFields = 'SCM,name,path,encoding,client';
|
||||
$config->repo->svn = new stdclass();
|
||||
$config->repo->svn->requiredFields = 'account,password';
|
||||
|
||||
$config->repo->matchComment['module']['story'] = 'Story';
|
||||
$config->repo->matchComment['module']['task'] = 'Task';
|
||||
$config->repo->matchComment['module']['bug'] = 'Bug';
|
||||
$config->repo->matchComment['module']['testtask'] = 'Build';
|
||||
$config->repo->matchComment['task']['start'] = 'Start';
|
||||
$config->repo->matchComment['task']['finish'] = 'Finish';
|
||||
$config->repo->matchComment['task']['cancel'] = 'Cancel';
|
||||
$config->repo->matchComment['task']['consumed'] = 'Cost';
|
||||
$config->repo->matchComment['task']['left'] = 'Left';
|
||||
$config->repo->matchComment['bug']['resolve'] = 'Resolve';
|
||||
$config->repo->matchComment['bug']['resolvedBuild'] = 'Build';
|
||||
$config->repo->matchComment['testtask']['start'] = 'Start';
|
||||
$config->repo->matchComment['id']['mark'] = '#';
|
||||
$config->repo->matchComment['id']['split'] = ',';
|
||||
$config->repo->matchComment['mark']['consumed'] = ':';
|
||||
$config->repo->matchComment['mark']['left'] = ':';
|
||||
$config->repo->matchComment['mark']['resolvedBuild'] = '#';
|
||||
|
||||
+38
-1
@@ -54,7 +54,7 @@ class repo extends control
|
||||
$this->app->loadClass('pager', $static = true);
|
||||
$pager = new pager($recTotal, $recPerPage, $pageID);
|
||||
|
||||
$this->view->repoList = $this->repo->listAll($orderBy, $pager);
|
||||
$this->view->repoList = $this->repo->getList($orderBy, $pager);
|
||||
|
||||
$this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->browse;
|
||||
$this->view->position[] = $this->lang->repo->common;
|
||||
@@ -571,6 +571,34 @@ class repo extends control
|
||||
$this->fetch('file', 'sendDownHeader', array("fileName" => $fileName, "fileType" => $extension, "content" => $content));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set matchComment.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function setMatchComment()
|
||||
{
|
||||
if($_POST)
|
||||
{
|
||||
$this->loadModel('setting')->setItem('system.repo.matchComment', json_encode($this->post->matchComment));
|
||||
$this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('setMatchComment')));
|
||||
}
|
||||
|
||||
$this->repo->setMenu($this->repos, $this->session->repoID, false);
|
||||
|
||||
$this->app->loadLang('task');
|
||||
$this->app->loadLang('bug');
|
||||
$this->app->loadLang('story');
|
||||
$this->app->loadLang('testtask');
|
||||
if(is_string($this->config->repo->matchComment)) $this->config->repo->matchComment = json_decode($this->config->repo->matchComment, true);
|
||||
|
||||
$this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->setMatchComment;
|
||||
$this->view->position[] = $this->lang->repo->setMatchComment;
|
||||
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show sync comment.
|
||||
*
|
||||
@@ -732,6 +760,15 @@ class repo extends control
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax get svn tags
|
||||
*
|
||||
* @param int $repoID
|
||||
* @param string $path
|
||||
* @param string $revision
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxGetSVNTags($repoID, $path = '', $revision = 'HEAD')
|
||||
{
|
||||
if($this->get->path) $entry = $this->get->path;
|
||||
|
||||
+11
-3
@@ -9,6 +9,7 @@ $lang->repo->editAction = 'Edit Repo';
|
||||
$lang->repo->delete = 'Delete Repo';
|
||||
$lang->repo->showSyncComment = 'Display Synchronization';
|
||||
$lang->repo->ajaxSyncComment = 'Interface: Ajax Sync Note';
|
||||
$lang->repo->setMatchComment = 'Set match comment';
|
||||
$lang->repo->download = 'Download File';
|
||||
$lang->repo->downloadDiff = 'Download Diff';
|
||||
$lang->repo->diffAction = 'Revision Diff';
|
||||
@@ -94,6 +95,8 @@ $lang->repo->commentEdit = '<i class="icon-pencil"></i>';
|
||||
$lang->repo->commentDelete = '<i class="icon-remove"></i>';
|
||||
$lang->repo->allChanges = "Other Changes";
|
||||
$lang->repo->commitTitle = "The %sth Commit";
|
||||
$lang->repo->mark = "Mark Tag";
|
||||
$lang->repo->split = "Split Mark";
|
||||
|
||||
$lang->repo->viewDiffList['inline'] = 'Inline';
|
||||
$lang->repo->viewDiffList['appose'] = 'Parallel';
|
||||
@@ -122,6 +125,12 @@ $lang->repo->notice->deleteBug = 'Are you sure to delete this bug?';
|
||||
$lang->repo->notice->deleteComment = 'Are you sure to delete this comment?';
|
||||
$lang->repo->notice->lastSyncTime = 'Last Sync:';
|
||||
|
||||
$lang->repo->matchComment = new stdclass();
|
||||
$lang->repo->matchComment->exampleLabel = "Comment Example";
|
||||
$lang->repo->matchComment->example['task']['start'] = "%start% %task% %id%1%split%2 %cost%%consumedmark%1 %left%%leftmark%3";
|
||||
$lang->repo->matchComment->example['task']['finish'] = "%finish% %task% %id%1%split%2 %cost%%consumedmark%10";
|
||||
$lang->repo->matchComment->example['bug']['resolve'] = "%resolve% %bug% %id%1%split%2 %resolvedBuild% %buildmark%10";
|
||||
|
||||
$lang->repo->error = new stdclass();
|
||||
$lang->repo->error->useless = 'Your server disabled exec and shell_exec, so it cannot be applied.';
|
||||
$lang->repo->error->connect = 'Connection to the repo failed. Please enter username, password and repo address correctly!';
|
||||
@@ -151,9 +160,8 @@ $lang->repo->example->client->git = "e.g. /usr/bin/git";
|
||||
$lang->repo->example->client->svn = "e.g. /usr/bin/svn";
|
||||
$lang->repo->example->path->git = "e.g. /homt/user/myproject";
|
||||
$lang->repo->example->path->svn = "e.g. http://example.googlecode.com/svn/trunk/myproject";
|
||||
|
||||
$lang->repo->example->config = "Config directory is required in https. Use '--config-dir' to generate config dir.";
|
||||
$lang->repo->example->encoding = "input encoding of files";
|
||||
$lang->repo->example->config = "Config directory is required in https. Use '--config-dir' to generate config dir.";
|
||||
$lang->repo->example->encoding = "input encoding of files";
|
||||
|
||||
$lang->repo->typeList['standard'] = 'Standard';
|
||||
$lang->repo->typeList['performance'] = 'Performance';
|
||||
|
||||
@@ -9,6 +9,7 @@ $lang->repo->editAction = '编辑版本库';
|
||||
$lang->repo->delete = '删除版本库';
|
||||
$lang->repo->showSyncComment = '显示同步进度';
|
||||
$lang->repo->ajaxSyncComment = '接口:AJAX同步注释';
|
||||
$lang->repo->setMatchComment = '注释指令配置';
|
||||
$lang->repo->download = '下载';
|
||||
$lang->repo->downloadDiff = '下载Diff';
|
||||
$lang->repo->diffAction = '版本对比';
|
||||
@@ -94,6 +95,8 @@ $lang->repo->commentEdit = '<i class="icon-pencil"></i>';
|
||||
$lang->repo->commentDelete = '<i class="icon-remove"></i>';
|
||||
$lang->repo->allChanges = "其他改动";
|
||||
$lang->repo->commitTitle = "第%s次提交";
|
||||
$lang->repo->mark = "匹配标记";
|
||||
$lang->repo->split = "分割匹配";
|
||||
|
||||
$lang->repo->viewDiffList['inline'] = '直列';
|
||||
$lang->repo->viewDiffList['appose'] = '并排';
|
||||
@@ -122,6 +125,12 @@ $lang->repo->notice->deleteBug = '确认删除该Bug?';
|
||||
$lang->repo->notice->deleteComment = '确认删除该回复?';
|
||||
$lang->repo->notice->lastSyncTime = '最后更新于:';
|
||||
|
||||
$lang->repo->matchComment = new stdclass();
|
||||
$lang->repo->matchComment->exampleLabel = "注释示例";
|
||||
$lang->repo->matchComment->example['task']['start'] = "%start% %task% %id%1%split%2 %cost%%consumedmark%1 %left%%leftmark%3";
|
||||
$lang->repo->matchComment->example['task']['finish'] = "%finish% %task% %id%1%split%2 %cost%%consumedmark%10";
|
||||
$lang->repo->matchComment->example['bug']['resolve'] = "%resolve% %bug% %id%1%split%2 %resolvedBuild% %buildmark%10";
|
||||
|
||||
$lang->repo->error = new stdclass();
|
||||
$lang->repo->error->useless = '你的服务器禁用了exec,shell_exec方法,无法使用该功能';
|
||||
$lang->repo->error->connect = '连接版本库失败,请填写正确的用户名、密码和版本库地址!';
|
||||
|
||||
+162
-1
@@ -139,7 +139,7 @@ class repoModel extends model
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function listAll($orderBy = 'id_desc', $pager = null, $decode = true)
|
||||
public function getList($orderBy = 'id_desc', $pager = null, $decode = true)
|
||||
{
|
||||
$repos = $this->dao->select('*')->from(TABLE_REPO)
|
||||
->where('deleted')->eq('0')
|
||||
@@ -936,4 +936,165 @@ class repoModel extends model
|
||||
|
||||
return $repos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the comment of git, extract object id list from it.
|
||||
*
|
||||
* @param string $comment
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function parseComment($comment)
|
||||
{
|
||||
if(is_string($this->config->repo->matchComment)) $this->config->repo->matchComment = json_decode($this->config->repo->matchComment, true);
|
||||
$matchComment = $this->config->repo->matchComment;
|
||||
|
||||
$matches = array();
|
||||
$stories = array();
|
||||
$tasks = array();
|
||||
$bugs = array();
|
||||
$testtasks = array();
|
||||
$actions = array();
|
||||
while(true)
|
||||
{
|
||||
$found = preg_match("/{$matchComment['id']['mark']}[0-9]+({$matchComment['id']['split']}[0-9]+)*/", $comment, $matches);
|
||||
if(empty($found)) break;
|
||||
if($found)
|
||||
{
|
||||
$position = strpos($comment, $matches[0]);
|
||||
$subComment = substr($comment, 0, $position + strlen($matches[0]));
|
||||
$comment = substr($comment, $position + strlen($matches[0]) + 1);
|
||||
|
||||
$idList = explode($matchComment['id']['mark'], str_replace($matchComment['id']['split'], '', $matches[0]));
|
||||
foreach($matchComment['module'] as $module => $moduleMatch)
|
||||
{
|
||||
if(stripos($subComment, $moduleMatch) !== false)
|
||||
{
|
||||
if($module == 'story')
|
||||
{
|
||||
foreach($idList as $id) $stories[$id] = $id;
|
||||
}
|
||||
elseif($module == 'task')
|
||||
{
|
||||
foreach($idList as $id) $tasks[$id] = $id;
|
||||
foreach($matchComment['task'] as $method => $match)
|
||||
{
|
||||
if(strpos($subComment, $match) !== false)
|
||||
{
|
||||
$consumed = 0;
|
||||
preg_match("/{$matchComment['task']['consumed']}{$matchComment['mark']['consumed']}([0-9]+)/", $comment, $costMatch);
|
||||
if($costMatch) $consumed = $costMatch[1];
|
||||
|
||||
$left = 0;
|
||||
preg_match("/{$matchComment['task']['left']}{$matchComment['mark']['left']}([0-9]+)/", $comment, $leftMatch);
|
||||
if($leftMatch) $left = $leftMatch[1];
|
||||
|
||||
foreach($idList as $id)
|
||||
{
|
||||
$actions['task'][$id]['action'] = $method;
|
||||
$actions['task'][$id]['consumed'] = $consumed;
|
||||
$actions['task'][$id]['left'] = $left;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($module == 'bug')
|
||||
{
|
||||
foreach($idList as $id) $bugs[$id] = $id;
|
||||
foreach($matchComment['bug'] as $method => $match)
|
||||
{
|
||||
if(strpos($subComment, $match) !== false)
|
||||
{
|
||||
$buildID = 0;
|
||||
preg_match("/{$matchComment['bug']['resolvedBuild']}{$matchComment['mark']['resolvedBuild']}([0-9]+)/", $comment, $buildMatch);
|
||||
if($buildMatch) $buildID = $buildMatch[1];
|
||||
|
||||
foreach($idList as $id)
|
||||
{
|
||||
$actions['bug'][$id]['action'] = $method;
|
||||
$actions['bug'][$id]['resolvedBuild'] = $buildID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($module == 'testtask')
|
||||
{
|
||||
foreach($idList as $id) $testtasks[$id] = $id;
|
||||
foreach($matchComment['testtask'] as $method => $match)
|
||||
{
|
||||
if(strpos($subComment, $match) !== false)
|
||||
{
|
||||
foreach($idList as $id) $actions['testtask'][$id]['action'] = $method;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array('stories' => $stories, 'tasks' => $tasks, 'bugs' => $bugs, 'testtasks' => $testtasks, 'actions' => $actions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the tag, extract task list from it.
|
||||
*
|
||||
* @param string $comment
|
||||
* @access public
|
||||
*/
|
||||
public function parseTag($comment)
|
||||
{
|
||||
global $config;
|
||||
if(is_string($config->repo->matchComment)) $config->repo->matchComment = json_decode($config->repo->matchComment, true);
|
||||
$matchComment = $config->repo->matchComment;
|
||||
|
||||
$testtasks = array();
|
||||
while(true)
|
||||
{
|
||||
$found = preg_match("/{$matchComment['id']['mark']}[0-9]+({$matchComment['id']['split']}[0-9]+)*/", $comment, $matches);
|
||||
if(empty($found)) break;
|
||||
if($found)
|
||||
{
|
||||
$position = strpos($comment, $matches[0]);
|
||||
$subComment = substr($comment, 0, $position + strlen($matches[0]));
|
||||
$comment = substr($comment, $position + strlen($matches[0]) + 1);
|
||||
|
||||
$idList = explode($matchComment['id']['mark'], str_replace($matchComment['id']['split'], '', $matches[0]));
|
||||
foreach($matchComment['module'] as $module => $moduleMatch)
|
||||
{
|
||||
if($module != 'testtask') continue;
|
||||
if(stripos($subComment, $moduleMatch) !== false)
|
||||
{
|
||||
foreach($idList as $id) $testtasks[$id] = $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $testtasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iconv Comment.
|
||||
*
|
||||
* @param string $comment
|
||||
* @param string $encodings
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function iconvComment($comment, $encodings)
|
||||
{
|
||||
/* Get encodings. */
|
||||
if($encodings == '') return $comment;
|
||||
$encodings = explode(',', $encodings);
|
||||
|
||||
/* Try convert. */
|
||||
foreach($encodings as $encoding)
|
||||
{
|
||||
if($encoding == 'utf-8') continue;
|
||||
$result = helper::convertEncoding($comment, $encoding);
|
||||
if($result) return $result;
|
||||
}
|
||||
|
||||
return $comment;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/**
|
||||
* The setMatchComment view file of repo module of ZenTaoPMS.
|
||||
*
|
||||
* @copyright Copyright 2009-2015 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
|
||||
* @license ZPL (http://zpl.pub/page/zplv12.html)
|
||||
* @author Yidong Wang <yidong@cnezsoft.com>
|
||||
* @package repo
|
||||
* @version $Id$
|
||||
* @link http://www.zentao.net
|
||||
*/
|
||||
?>
|
||||
<?php include '../../common/view/header.html.php';?>
|
||||
<div id='mainContent' class='main-content'>
|
||||
<form class='main-form form-ajax' method='post'>
|
||||
<table class='table table-form'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class='w-90px'><?php echo $lang->repo->module;?></th>
|
||||
<th><?php echo $lang->repo->setMatchComment;?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th><?php echo $lang->repo->module;?></th>
|
||||
<td>
|
||||
<div class='input-group'>
|
||||
<?php foreach($config->repo->matchComment['module'] as $module => $match):?>
|
||||
<span class='input-group-addon'><?php echo $lang->{$module}->common;?></span>
|
||||
<?php echo html::input("matchComment[module][{$module}]", $match, "class='form-control'");?>
|
||||
<?php endforeach;?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php echo $lang->task->common;?></th>
|
||||
<td>
|
||||
<div class='input-group'>
|
||||
<?php foreach($config->repo->matchComment['task'] as $method => $match):?>
|
||||
<span class='input-group-addon'><?php echo $lang->task->$method;?></span>
|
||||
<?php echo html::input("matchComment[task][{$method}]", $match, "class='form-control'");?>
|
||||
<?php endforeach;?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php echo $lang->bug->common;?></th>
|
||||
<td>
|
||||
<div class='input-group'>
|
||||
<?php foreach($config->repo->matchComment['bug'] as $method => $match):?>
|
||||
<span class='input-group-addon'><?php echo $lang->bug->$method;?></span>
|
||||
<?php echo html::input("matchComment[bug][{$method}]", $match, "class='form-control'");?>
|
||||
<?php endforeach;?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php echo $lang->testtask->common;?></th>
|
||||
<td>
|
||||
<div class='input-group'>
|
||||
<?php foreach($config->repo->matchComment['testtask'] as $method => $match):?>
|
||||
<span class='input-group-addon'><?php echo $lang->testtask->$method;?></span>
|
||||
<?php echo html::input("matchComment[testtask][{$method}]", $match, "class='form-control'");?>
|
||||
<?php endforeach;?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php echo $lang->idAB;?></th>
|
||||
<td>
|
||||
<div class='input-group'>
|
||||
<?php foreach($config->repo->matchComment['id'] as $method => $match):?>
|
||||
<span class='input-group-addon'><?php echo $lang->repo->$method;?></span>
|
||||
<?php echo html::input("matchComment[id][{$method}]", $match, "class='form-control'");?>
|
||||
<?php endforeach;?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php echo $lang->repo->mark;?></th>
|
||||
<td>
|
||||
<div class='input-group'>
|
||||
<?php foreach($config->repo->matchComment['mark'] as $method => $match):?>
|
||||
<span class='input-group-addon'><?php echo isset($lang->task->$method) ? $lang->task->$method : $lang->bug->$method;?></span>
|
||||
<?php echo html::input("matchComment[mark][{$method}]", $match, "class='form-control'");?>
|
||||
<?php endforeach;?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php echo $lang->repo->matchComment->exampleLabel;?></th>
|
||||
<td id='example'></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan='2' class='text-center'>
|
||||
<?php echo html::submitButton();?>
|
||||
<?php echo html::backButton();?>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<?php js::set('matchCommentExample', $lang->repo->matchComment->example);?>
|
||||
<script>
|
||||
$(function()
|
||||
{
|
||||
replaceExample();
|
||||
$('input').keyup(function(){replaceExample()});
|
||||
})
|
||||
|
||||
function replaceExample()
|
||||
{
|
||||
exampleTaskStart = matchCommentExample['task']['start'].replace('%start%', $('[id*=start').val())
|
||||
.replace('%task%', $('[id*=module][id*=task]').val())
|
||||
.replace('%id%', $('[id*=id][id*=mark]').val())
|
||||
.replace('%split%', $('[id*=id][id*=split]').val())
|
||||
.replace('%cost%', $('[id*=task][id*=consumed]').val())
|
||||
.replace('%consumedmark%', $('[id*=mark][id*=consumed]').val())
|
||||
.replace('%left%', $('[id*=task][id*=left]').val())
|
||||
.replace('%leftmark%', $('[id*=mark][id*=left]').val());
|
||||
exampleTaskFinish = matchCommentExample['task']['finish'].replace('%finish%', $('[id*=finish]').val())
|
||||
.replace('%task%', $('[id*=module][id*=task]').val())
|
||||
.replace('%id%', $('[id*=id][id*=mark]').val())
|
||||
.replace('%split%', $('[id*=id][id*=split]').val())
|
||||
.replace('%cost%', $('[id*=task][id*=consumed]').val())
|
||||
.replace('%consumedmark%', $('[id*=mark][id*=consumed]').val());
|
||||
exampleBugResolve = matchCommentExample['bug']['resolve'].replace('%resolve%', $('[id*=bug][id*="resolve\]"]').val())
|
||||
.replace('%bug%', $('[id*=module][id*=bug]').val())
|
||||
.replace('%id%', $('[id*=id][id*=mark]').val())
|
||||
.replace('%split%', $('[id*=id][id*=split]').val())
|
||||
.replace('%resolvedBuild%', $('[id*=bug][id*=resolvedBuild]').val())
|
||||
.replace('%buildmark%', $('[id*=mark][id*=resolvedBuild]').val());
|
||||
|
||||
html = exampleTaskStart;
|
||||
html += '<br />' + exampleTaskFinish;
|
||||
html += '<br />' + exampleBugResolve;
|
||||
$('#example').html(html);
|
||||
}
|
||||
</script>
|
||||
<?php include '../../common/view/footer.html.php';?>
|
||||
@@ -72,7 +72,7 @@ class svn extends control
|
||||
$url = helper::safe64Decode($url);
|
||||
if(common::hasPriv('repo', 'view'))
|
||||
{
|
||||
$repos = $this->loadModel('repo')->listAll();
|
||||
$repos = $this->loadModel('repo')->getList();
|
||||
foreach($repos as $repo)
|
||||
{
|
||||
if($repo->SCM != 'Subversion') continue;
|
||||
@@ -109,11 +109,10 @@ class svn extends control
|
||||
$parsedLogs[] = $this->svn->convertLog($entry);
|
||||
}
|
||||
$parsedObjects = array('stories' => array(), 'tasks' => array(), 'bugs' => array());
|
||||
$this->loadModel('repo');
|
||||
foreach($parsedLogs as $log)
|
||||
{
|
||||
$allCommands = [];
|
||||
$scm = $this->app->loadClass('scm');
|
||||
$objects = $scm->parseComment($log->msg, $allCommands);
|
||||
$objects = $this->repo->parseComment($log->msg);
|
||||
|
||||
if($objects)
|
||||
{
|
||||
@@ -173,9 +172,7 @@ class svn extends control
|
||||
$parsedFiles[$action][] = $path;
|
||||
}
|
||||
|
||||
$allCommands = [];
|
||||
$scm = $this->app->loadClass('scm');
|
||||
$objects = $scm->parseComment($message, $allCommands);
|
||||
$objects = $this->loadModel('repo')->parseComment($message);
|
||||
|
||||
if($objects)
|
||||
{
|
||||
|
||||
+21
-28
@@ -71,6 +71,7 @@ class svnModel extends model
|
||||
{
|
||||
parent::__construct();
|
||||
$this->loadModel('action');
|
||||
$this->loadModel('repo');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,16 +95,18 @@ class svnModel extends model
|
||||
|
||||
$savedRevision = $this->getSavedRevision();
|
||||
$this->printLog("start from revision $savedRevision");
|
||||
$logs = $this->getRepoLogs($repo, $savedRevision);
|
||||
|
||||
if(!empty($logs)) {
|
||||
$logs = $this->getRepoLogs($repo, $savedRevision);
|
||||
$objects = array();
|
||||
if(!empty($logs))
|
||||
{
|
||||
$this->printLog("get " . count($logs) . " logs");
|
||||
$this->printLog('begin parsing logs');
|
||||
|
||||
$allCommands = [];
|
||||
foreach ($logs as $log) {
|
||||
foreach($logs as $log)
|
||||
{
|
||||
$this->printLog("parsing log {$log->revision}");
|
||||
if ($log->revision == $savedRevision)
|
||||
if($log->revision == $savedRevision)
|
||||
{
|
||||
$this->printLog("{$log->revision} alread parsed, commit it");
|
||||
continue;
|
||||
@@ -111,8 +114,7 @@ class svnModel extends model
|
||||
|
||||
$this->printLog("comment is\n----------\n" . trim($log->msg) . "\n----------");
|
||||
|
||||
$scm = $this->app->loadClass('scm');
|
||||
$objects = $scm->parseComment($log->msg, $allCommands);
|
||||
$objects = $this->repo->parseComment($log->msg);
|
||||
if($objects)
|
||||
{
|
||||
$this->printLog('extract' .
|
||||
@@ -134,41 +136,33 @@ class svnModel extends model
|
||||
$this->printLog("save revision $savedRevision");
|
||||
$this->deleteRestartFile();
|
||||
$this->printLog("\n\nrepo ' . $repo->id . ': ' . $repo->path . ' finished");
|
||||
|
||||
$this->printLog('extract commands from logs' . json_encode($allCommands));
|
||||
}
|
||||
|
||||
// exe ci jobs in log
|
||||
$cijobIDs = $allCommands['build']['start'];
|
||||
foreach($cijobIDs as $id)
|
||||
{
|
||||
$this->loadModel('ci')->exeJob($id);
|
||||
}
|
||||
$cijobIdList = zget($objects, 'testtasks', array());
|
||||
$this->loadModel('integration');
|
||||
foreach($cijobIdList as $id) $this->integration->exec($id);
|
||||
|
||||
// dealwith tag commands
|
||||
$this->printLog("dealwith tag commands");
|
||||
$savedTags = $this->getSavedTags($repo->id);
|
||||
|
||||
$tags = $this->getRepoTags($repo);
|
||||
if(!empty($tags)) {
|
||||
$jobToBuild = [];
|
||||
foreach ($tags as $tag) {
|
||||
if ($savedTags[$tag]) // old
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(!empty($tags))
|
||||
{
|
||||
$jobToBuild = array();
|
||||
foreach($tags as $tag)
|
||||
{
|
||||
if($savedTags[$tag]) continue;
|
||||
|
||||
$scm = $this->app->loadClass('scm');
|
||||
$scm->parseTag($tag, $jobToBuild);
|
||||
$jobToBuild += $this->repo->parseTag($tag);
|
||||
|
||||
$this->saveLastTag($tag, $repo->id);
|
||||
}
|
||||
$this->printLog('extract tasks to build: ' . json_encode($jobToBuild));
|
||||
|
||||
// exe ci jobs in tag
|
||||
foreach ($jobToBuild as $id) {
|
||||
$this->loadModel('ci')->exeJob($id);
|
||||
}
|
||||
foreach($jobToBuild as $id) $this->integration->exec($id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -522,8 +516,7 @@ class svnModel extends model
|
||||
$action->action = 'svncommited';
|
||||
$action->date = $log->date;
|
||||
|
||||
$scm = $this->app->loadClass('scm');
|
||||
$action->comment = htmlspecialchars($scm->iconvComment($log->msg, $encodings));
|
||||
$action->comment = htmlspecialchars($this->repo->iconvComment($log->msg, $encodings));
|
||||
$action->extra = $log->revision;
|
||||
|
||||
$changes = $this->createActionChanges($log, $repoRoot);
|
||||
|
||||
Reference in New Issue
Block a user