* Add unit test.
This commit is contained in:
+1
-33
@@ -1006,7 +1006,7 @@ class repoModel extends model
|
||||
$logs = array_reverse($logs, true);
|
||||
foreach($logs as $i => $log)
|
||||
{
|
||||
if($lastInDB->revision == $log->revision)
|
||||
if(isset($lastInDB->revision) and $lastInDB->revision == $log->revision)
|
||||
{
|
||||
unset($logs[$i]);
|
||||
continue;
|
||||
@@ -2107,38 +2107,6 @@ class repoModel extends model
|
||||
->fetchPairs('path', 'product');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync the latest commit.
|
||||
*
|
||||
* @param int $repoID
|
||||
* @param string $branchID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function syncCommit($repoID, $branchID)
|
||||
{
|
||||
$repo = $this->getRepoByID($repoID);
|
||||
$this->scm = $this->app->loadClass('scm');
|
||||
$this->scm->setEngine($repo);
|
||||
|
||||
$latestInDB = $this->dao->select('DISTINCT t1.*')->from(TABLE_REPOHISTORY)->alias('t1')
|
||||
->leftJoin(TABLE_REPOBRANCH)->alias('t2')->on('t1.id=t2.revision')
|
||||
->where('t1.repo')->eq($repoID)
|
||||
->beginIF($repo->SCM == 'Git' and $branchID)->andWhere('t2.branch')->eq($branchID)->fi()
|
||||
->beginIF($repo->SCM == 'Gitlab' and $branchID)->andWhere('t2.branch')->eq($branchID)->fi()
|
||||
->orderBy('t1.time desc')
|
||||
->limit(1)
|
||||
->fetch();
|
||||
$version = empty($latestInDB) ? 1 : $latestInDB->commit + 1;
|
||||
$revision = $version == 1 ? 'HEAD' : ($repo->SCM == 'Git' ? $latestInDB->commit : $latestInDB->revision);
|
||||
|
||||
$logs = $this->scm->getCommits('since' . $revision, $this->config->repo->batchNum, $branchID);
|
||||
$commitCount = $this->saveCommit($repoID, $logs, $version, $branchID);
|
||||
$this->dao->update(TABLE_REPO)->set('commits=commits + ' . $commitCount)->where('id')->eq($repoID)->exec();
|
||||
|
||||
$this->fixCommit($repoID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get execution pairs.
|
||||
*
|
||||
|
||||
@@ -194,7 +194,7 @@ class repoTest
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
return !empty($objects) ? array_keys($objects) : 'empty';
|
||||
}
|
||||
|
||||
public function getGitRevisionNameTest($revision, $commit)
|
||||
@@ -386,13 +386,17 @@ class repoTest
|
||||
return $objects;
|
||||
}
|
||||
|
||||
public function addLinkTest($matches, $method)
|
||||
public function addLinkTest($comment, $type)
|
||||
{
|
||||
$objects = $this->objectModel->addLink($matches, $method);
|
||||
$rules = $this->objectModel->processRules();
|
||||
$objectReg = '/' . $rules[$type . 'Reg'] . '/i';
|
||||
if(preg_match_all($objectReg, $comment, $result))
|
||||
{
|
||||
$links = $this->objectModel->addLink($result, $type);
|
||||
foreach($links as $link) return $link;
|
||||
}
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
return 'empty';
|
||||
}
|
||||
|
||||
public function parseCommentTest($comment)
|
||||
|
||||
@@ -14,4 +14,11 @@ pid=1
|
||||
|
||||
$repo = new repoTest();
|
||||
|
||||
r($repo->addLinkTest()) && p() && e();
|
||||
$commentTask = 'Finish task #1.';
|
||||
$commentStory = 'Effort story #1 Cost 1h.';
|
||||
$commentBug = 'Fix bug #1.';
|
||||
$commentElse = 'Anything else.';
|
||||
r($repo->addLinkTest($commentTask, 'task')) && p('') && e("task #<a href='atask-view-1.' >1</a>"); //任务链接
|
||||
r($repo->addLinkTest($commentStory, 'story')) && p('') && e("story #<a href='astory-view-1.' >1</a>"); //需求链接
|
||||
r($repo->addLinkTest($commentBug, 'bug')) && p('') && e("bug #<a href='abug-view-1.' >1</a>"); //Bug链接
|
||||
r($repo->addLinkTest($commentElse, 'task')) && p('') && e("empty"); //无链接
|
||||
|
||||
@@ -12,6 +12,22 @@ pid=1
|
||||
|
||||
*/
|
||||
|
||||
$repo = new repoTest();
|
||||
global $tester, $dao;
|
||||
$repo = $tester->loadModel('repo')->getRepoByID(1);
|
||||
$logs = $tester->repo->getUnsyncedCommits($repo);
|
||||
$revision = 1;
|
||||
$revisions = array();
|
||||
foreach($logs as $log)
|
||||
{
|
||||
$tester->repo->saveOneCommit($repo->id, $log, $revision);
|
||||
$revisions[] = $log->revision;
|
||||
$revision ++;
|
||||
}
|
||||
|
||||
r($repo->getHistoryTest()) && p() && e();
|
||||
$repoTest = new repoTest();
|
||||
|
||||
r($repoTest->getHistoryTest(1, $revisions)) && p('1') && e('d5789b703dc09c44be1e89a991c3506de1f678e3');
|
||||
r($repoTest->getHistoryTest(1, array())) && p('') && e('empty');
|
||||
|
||||
$dao->exec('truncate table zt_repohistory');
|
||||
$dao->exec('truncate table zt_repobranch');
|
||||
|
||||
Reference in New Issue
Block a user