* finish task #6939.
This commit is contained in:
@@ -27,7 +27,7 @@ class ciModel extends model
|
||||
* Send a request to jenkins to check build status.
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
* @return void
|
||||
*/
|
||||
public function checkBuildStatus()
|
||||
{
|
||||
@@ -106,7 +106,7 @@ class ciModel extends model
|
||||
* @param object $build
|
||||
* @param string $status
|
||||
* @access public
|
||||
* @return bool
|
||||
* @return void
|
||||
*/
|
||||
public function updateBuildStatus($build, $status)
|
||||
{
|
||||
@@ -115,8 +115,12 @@ class ciModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @return false|mixed|string
|
||||
* Send request.
|
||||
*
|
||||
* @param string $url
|
||||
* @param object $data
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function sendRequest($url, $data)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,18 @@
|
||||
*/
|
||||
class compileModel extends model
|
||||
{
|
||||
/**
|
||||
* Get by id
|
||||
*
|
||||
* @param int $buildID
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getByID($buildID)
|
||||
{
|
||||
return $this->dao->select('*')->from(TABLE_COMPILE)->where('id')->eq($buildID)->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get build list.
|
||||
*
|
||||
@@ -34,18 +46,6 @@ class compileModel extends model
|
||||
->fetchAll('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get by id
|
||||
*
|
||||
* @param int $buildID
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getByID($buildID)
|
||||
{
|
||||
return $this->dao->select('*')->from(TABLE_COMPILE)->where('id')->eq($buildID)->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unexecuted list.
|
||||
*
|
||||
@@ -57,6 +57,25 @@ class compileModel extends model
|
||||
return $this->dao->select('*')->from(TABLE_COMPILE)->where('status')->eq('')->andWhere('deleted')->eq('0')->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get build url.
|
||||
*
|
||||
* @param object $jenkins
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getBuildUrl($jenkins)
|
||||
{
|
||||
$jenkinsServer = $jenkins->url;
|
||||
$jenkinsUser = $jenkins->account;
|
||||
$jenkinsPassword = $jenkins->token ? $jenkins->token : base64_decode($jenkins->password);
|
||||
|
||||
$jenkinsAuth = '://' . $jenkinsUser . ':' . $jenkinsPassword . '@';
|
||||
$jenkinsServer = str_replace('://', $jenkinsAuth, $jenkinsServer);
|
||||
$buildUrl = sprintf('%s/job/%s/buildWithParameters/api/json', $jenkinsServer, $jenkins->jkJob);
|
||||
return $buildUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save build by integration
|
||||
*
|
||||
@@ -112,23 +131,4 @@ class compileModel extends model
|
||||
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get build url.
|
||||
*
|
||||
* @param object $jenkins
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getBuildUrl($jenkins)
|
||||
{
|
||||
$jenkinsServer = $jenkins->url;
|
||||
$jenkinsUser = $jenkins->account;
|
||||
$jenkinsPassword = $jenkins->token ? $jenkins->token : base64_decode($jenkins->password);
|
||||
|
||||
$jenkinsAuth = '://' . $jenkinsUser . ':' . $jenkinsPassword . '@';
|
||||
$jenkinsServer = str_replace('://', $jenkinsAuth, $jenkinsServer);
|
||||
$buildUrl = sprintf('%s/job/%s/buildWithParameters/api/json', $jenkinsServer, $jenkins->jkJob);
|
||||
return $buildUrl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,56 +104,65 @@ class gitModel extends model
|
||||
$this->printLog("begin repo $repo->id");
|
||||
if(!$this->setRepo($repo)) return false;
|
||||
|
||||
$savedRevision = $this->getSavedRevision();
|
||||
$this->printLog("start from revision $savedRevision");
|
||||
$logs = $this->getRepoLogs($repo, $savedRevision);
|
||||
$objects = array();
|
||||
if(!empty($logs))
|
||||
$branches = $this->repo->getBranches($repo);
|
||||
foreach($branches as $branch)
|
||||
{
|
||||
$this->printLog("get " . count($logs) . " logs");
|
||||
$this->printLog('begin parsing logs');
|
||||
$latestRevision = $logs[0]->revision;
|
||||
$this->printLog("sync branch $branch logs.");
|
||||
$_COOKIE['repoBranch'] = $branch;
|
||||
|
||||
foreach($logs as $log)
|
||||
$this->printLog("get this repo logs.");
|
||||
|
||||
$lastInDB = $this->getLatestComment($repoID);
|
||||
/* Ignore unsynced branch. */
|
||||
if(empty($lastInDB)) continue;
|
||||
|
||||
$commits = $repo->commits;
|
||||
$version = $lastInDB->commit;
|
||||
$logs = $this->repo->getUnsyncLogs($repo);
|
||||
$objects = array();
|
||||
if(!empty($logs))
|
||||
{
|
||||
$this->printLog("parsing log {$log->revision}");
|
||||
if($log->revision == $savedRevision)
|
||||
$this->printLog("get " . count($logs) . " logs");
|
||||
$this->printLog('begin parsing logs');
|
||||
|
||||
foreach($logs as $log)
|
||||
{
|
||||
$this->printLog("{$log->revision} alread parsed, commit it");
|
||||
continue;
|
||||
}
|
||||
$this->printLog("parsing log {$log->revision}");
|
||||
|
||||
$this->printLog("comment is\n----------\n" . trim($log->msg) . "\n----------");
|
||||
$this->printLog("comment is\n----------\n" . trim($log->msg) . "\n----------");
|
||||
|
||||
$objects = $this->repo->parseComment($log->msg);
|
||||
$objects = $this->repo->parseComment($log->msg);
|
||||
|
||||
if($objects)
|
||||
{
|
||||
$this->printLog('extract' .
|
||||
' story:' . join(' ', $objects['stories']) .
|
||||
' task:' . join(' ', $objects['tasks']) .
|
||||
' bug:' . join(',', $objects['bugs']));
|
||||
|
||||
$this->saveAction2PMS($objects, $log, $repo->encoding);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->printLog('no objects found' . "\n");
|
||||
}
|
||||
|
||||
/* Create compile by comment. */
|
||||
$integrations = zget($commitGroup, $repoID, array());
|
||||
foreach($integrations as $integration)
|
||||
{
|
||||
foreach(explode(',', $integration->comment) as $comment)
|
||||
if($objects)
|
||||
{
|
||||
if(strpos($log->msg, $comment) !== false) $this->compile->createByIntegration($integration->id);
|
||||
$this->printLog('extract' .
|
||||
' story:' . join(' ', $objects['stories']) .
|
||||
' task:' . join(' ', $objects['tasks']) .
|
||||
' bug:' . join(',', $objects['bugs']));
|
||||
|
||||
$this->saveAction2PMS($objects, $log, $repo->encoding);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->printLog('no objects found' . "\n");
|
||||
}
|
||||
|
||||
/* Create compile by comment. */
|
||||
$integrations = zget($commitGroup, $repoID, array());
|
||||
foreach($integrations as $integration)
|
||||
{
|
||||
foreach(explode(',', $integration->comment) as $comment)
|
||||
{
|
||||
if(strpos($log->msg, $comment) !== false) $this->compile->createByIntegration($integration->id);
|
||||
}
|
||||
}
|
||||
$version = $this->repo->saveOneCommit($repoID, $log, $version);
|
||||
$commits += count($logs)
|
||||
}
|
||||
}
|
||||
$this->repo->updateCommitCount($repoID, $commits);
|
||||
$this->dao->update(TABLE_REPO)->set('lastSync')->eq(helper::now())->where('id')->eq($repoID)->exec();
|
||||
|
||||
$this->saveLastRevision($latestRevision);
|
||||
$this->printLog("save revision $latestRevision");
|
||||
$this->deleteRestartFile();
|
||||
$this->printLog("\n\nrepo #" . $repo->id . ': ' . $repo->path . " finished");
|
||||
}
|
||||
@@ -162,9 +171,9 @@ class gitModel extends model
|
||||
$integrations = zget($tagGroup, $repoID, array());
|
||||
foreach($integrations as $integration)
|
||||
{
|
||||
$dirs = $this->getRepoTags($repo);
|
||||
end($dirs);
|
||||
$lastTag = current($dirs);
|
||||
$tags = $this->getRepoTags($repo);
|
||||
end($tags);
|
||||
$lastTag = current($tags);
|
||||
if($lastTag != $integration->lastTag)
|
||||
{
|
||||
$this->compile->createByIntegration($integration->id, $lastTag, 'tag');
|
||||
@@ -263,7 +272,6 @@ class gitModel extends model
|
||||
$this->setClient($repo);
|
||||
if(empty($this->client)) return false;
|
||||
|
||||
$this->setLogFile($repo->id);
|
||||
$this->setRepoRoot($repo);
|
||||
return true;
|
||||
}
|
||||
@@ -282,18 +290,6 @@ class gitModel extends model
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the log file of a repo.
|
||||
*
|
||||
* @param string $repoId
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function setLogFile($repoId)
|
||||
{
|
||||
$this->logFile = $this->logRoot . $repoId . '.log';
|
||||
}
|
||||
|
||||
/**
|
||||
* set the root path of a repo.
|
||||
*
|
||||
@@ -696,31 +692,6 @@ class gitModel extends model
|
||||
return $this->dao->select('id, project, product')->from(TABLE_BUG)->where('id')->in($bugs)->fetchAll('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the saved revision.
|
||||
*
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function getSavedRevision()
|
||||
{
|
||||
if(!file_exists($this->logFile)) return 0;
|
||||
if(file_exists($this->restartFile)) return 0;
|
||||
return trim(file_get_contents($this->logFile));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the last revision.
|
||||
*
|
||||
* @param int $revision
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function saveLastRevision($revision)
|
||||
{
|
||||
$ret = file_put_contents($this->logFile, $revision);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pring log.
|
||||
*
|
||||
|
||||
@@ -66,8 +66,6 @@ class jenkins extends control
|
||||
$this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse')));
|
||||
}
|
||||
|
||||
$this->app->loadLang('action');
|
||||
|
||||
$this->view->title = $this->lang->jenkins->common . $this->lang->colon . $this->lang->jenkins->create;
|
||||
$this->view->position[] = html::a(inlink('browse'), $this->lang->jenkins->common);
|
||||
$this->view->position[] = $this->lang->jenkins->create;
|
||||
@@ -92,8 +90,6 @@ class jenkins extends control
|
||||
$this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse')));
|
||||
}
|
||||
|
||||
$this->app->loadLang('action');
|
||||
|
||||
$this->view->title = $this->lang->jenkins->common . $this->lang->colon . $this->lang->jenkins->edit;
|
||||
$this->view->position[] = html::a(inlink('browse'), $this->lang->jenkins->common);
|
||||
$this->view->position[] = $this->lang->jenkins->edit;
|
||||
|
||||
@@ -44,6 +44,48 @@ class jenkinsModel extends model
|
||||
->fetchAll('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get jenkins pairs
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPairs()
|
||||
{
|
||||
$jenkins = $this->dao->select('id,name')->from(TABLE_JENKINS)->where('deleted')->eq('0')->orderBy('id')->fetchPairs('id', 'name');
|
||||
$jenkins = array('' => '') + $jenkins;
|
||||
return $jenkins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get jenkins tasks.
|
||||
*
|
||||
* @param int $id
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getTasks($id)
|
||||
{
|
||||
$jenkins = $this->getById($id);
|
||||
|
||||
$jenkinsServer = $jenkins->url;
|
||||
$jenkinsUser = $jenkins->account;
|
||||
$jenkinsPassword = $jenkins->token ? $jenkins->token : $jenkins->password;
|
||||
|
||||
$jenkinsAuth = '://' . $jenkinsUser . ':' . $jenkinsPassword . '@';
|
||||
$jenkinsServer = str_replace('://', $jenkinsAuth, $jenkinsServer);
|
||||
|
||||
$response = common::http($jenkinsServer . '/api/json/items/list');
|
||||
$response = json_decode($response);
|
||||
|
||||
$tasks = array();
|
||||
if(isset($response->jobs))
|
||||
{
|
||||
foreach($response->jobs as $job) $tasks[basename($job->url)] = $job->name;
|
||||
}
|
||||
return $tasks;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a jenkins.
|
||||
*
|
||||
@@ -93,46 +135,4 @@ class jenkinsModel extends model
|
||||
->exec();
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
/**
|
||||
* list jenkins for ci task edit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPairs()
|
||||
{
|
||||
$jenkins = $this->dao->select('id,name')->from(TABLE_JENKINS)->where('deleted')->eq('0')->orderBy('id')->fetchPairs('id', 'name');
|
||||
$jenkins = array('' => '') + $jenkins;
|
||||
return $jenkins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get jenkins tasks.
|
||||
*
|
||||
* @param int $id
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getTasks($id)
|
||||
{
|
||||
$jenkins = $this->getById($id);
|
||||
|
||||
$jenkinsServer = $jenkins->url;
|
||||
$jenkinsUser = $jenkins->account;
|
||||
$jenkinsPassword = $jenkins->token ? $jenkins->token : $jenkins->password;
|
||||
|
||||
$jenkinsAuth = '://' . $jenkinsUser . ':' . $jenkinsPassword . '@';
|
||||
$jenkinsServer = str_replace('://', $jenkinsAuth, $jenkinsServer);
|
||||
|
||||
$response = common::http($jenkinsServer . '/api/json/items/list');
|
||||
$response = json_decode($response);
|
||||
|
||||
$tasks = array();
|
||||
if(isset($response->jobs))
|
||||
{
|
||||
foreach($response->jobs as $job) $tasks[basename($job->url)] = $job->name;
|
||||
}
|
||||
return $tasks;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,7 +312,6 @@ class repo extends control
|
||||
{
|
||||
$infos = unserialize(file_get_contents($cacheFile));
|
||||
}
|
||||
if($refresh) $this->repo->updateLatestCommit($repo);
|
||||
if($this->cookie->repoRefresh) setcookie('repoRefresh', 0, 0, $this->config->webRoot);
|
||||
|
||||
$logType = 'dir';
|
||||
@@ -808,26 +807,6 @@ class repo extends control
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax sync latest commit.
|
||||
*
|
||||
* @param int $repoID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxSyncLatestCommit($repoID)
|
||||
{
|
||||
set_time_limit(0);
|
||||
$repo = $this->repo->getRepoByID($repoID);
|
||||
if((time() - strtotime($repo->lastSync)) / 60 >= $this->config->repo->syncTime)
|
||||
{
|
||||
$commits = $this->repo->updateLatestCommit($repo);
|
||||
if($commits > 0) die('finished');
|
||||
}
|
||||
|
||||
die('norecords');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax get svn tags
|
||||
*
|
||||
|
||||
@@ -1,36 +1,6 @@
|
||||
$(document).ready(function()
|
||||
{
|
||||
processCheckbox();
|
||||
|
||||
$.get(createLink('repo', 'ajaxSyncLatestCommit', "repoID=" + repoID), function(data)
|
||||
{
|
||||
if(data == 'finished')
|
||||
{
|
||||
$('#logList').load(location.href + ' #logList', function()
|
||||
{
|
||||
$('#logList #logList thead').unwrap();
|
||||
|
||||
if($("input:checkbox[name='revision[]']:checked").length < 2)
|
||||
{
|
||||
$("input:checkbox[name='revision[]']:lt(2)").attr('checked', 'checked');
|
||||
}
|
||||
$("input:checkbox[name='revision[]']").each(function(){ if(!$(this).is(':checked')) $(this).attr("disabled","disabled")});
|
||||
$("input:checkbox[name='revision[]']").click(function(){
|
||||
var checkNum = $("input:checkbox[name='revision[]']:checked").length;
|
||||
if (checkNum >= 2)
|
||||
{
|
||||
$("input:checkbox[name='revision[]']").each(function(){ if(!$(this).is(':checked')) $(this).attr("disabled","disabled")});
|
||||
}
|
||||
else
|
||||
{
|
||||
$("input:checkbox[name='revision[]']").each(function(){$(this).attr("disabled", false)});
|
||||
}
|
||||
});
|
||||
|
||||
processCheckbox();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function processCheckbox()
|
||||
|
||||
@@ -541,6 +541,56 @@ class repoModel extends model
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save One Commit.
|
||||
*
|
||||
* @param int $repoID
|
||||
* @param object $commit
|
||||
* @param int $version
|
||||
* @param string $branch
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function saveOneCommit($repoID, $commit, $version, $branch = '')
|
||||
{
|
||||
$existsRevision = $this->dao->select('id,revision')->from(TABLE_REPOHISTORY)->where('repo')->eq($repoID)->andWhere('revision')->eq($commit->revision)->fetch();
|
||||
if($existsRevision)
|
||||
{
|
||||
if($branch) $this->dao->replace(TABLE_REPOBRANCH)->set('repo')->eq($repoID)->set('revision')->eq($existsRevision->id)->set('branch')->eq($branch)->exec();
|
||||
continue;
|
||||
}
|
||||
|
||||
$commit->repo = $repoID;
|
||||
$commit->commit = $version;
|
||||
$commit->comment = htmlspecialchars($commit->comment);
|
||||
$this->dao->insert(TABLE_REPOHISTORY)->data($commit)->exec();
|
||||
if(!dao::isError())
|
||||
{
|
||||
$commitID = $this->dao->lastInsertID();
|
||||
if($branch) $this->dao->replace(TABLE_REPOBRANCH)->set('repo')->eq($repoID)->set('revision')->eq($commitID)->set('branch')->eq($branch)->exec();
|
||||
foreach($commit->change as $file => $info)
|
||||
{
|
||||
$parentPath = dirname($file);
|
||||
|
||||
$repoFile = new stdclass();
|
||||
$repoFile->repo = $repoID;
|
||||
$repoFile->revision = $commitID;
|
||||
$repoFile->path = $file;
|
||||
$repoFile->parent = $parentPath == '\\' ? '/' : $parentPath;
|
||||
$repoFile->type = $info['kind'];
|
||||
$repoFile->action = $info['action'];
|
||||
$this->dao->insert(TABLE_REPOFILES)->data($repoFile)->exec();
|
||||
}
|
||||
$version++;
|
||||
}
|
||||
else
|
||||
{
|
||||
dao::getError();
|
||||
}
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save exists log branch.
|
||||
*
|
||||
@@ -578,6 +628,44 @@ class repoModel extends model
|
||||
return $this->dao->update(TABLE_REPO)->set('commits')->eq($count)->where('id')->eq($repoID)->exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unsync logs
|
||||
*
|
||||
* @param object $repo
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getUnsyncLogs($repo)
|
||||
{
|
||||
$repoID = $repo->id;
|
||||
$lastInDB = $this->getLatestComment($repoID);
|
||||
|
||||
$scm = $this->app->loadClass('scm');
|
||||
$scm->setEngine($repo);
|
||||
|
||||
$logs = $scm->log('', $lastInDB->revision);
|
||||
if(empty($logs)) return false;
|
||||
|
||||
/* Process logs. */
|
||||
foreach($logs as $i => $log)
|
||||
{
|
||||
if($lastInDB->revision == $log->revision)
|
||||
{
|
||||
unset($logs[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$log->author = $log->committer;
|
||||
$log->msg = $log->comment;
|
||||
$log->date = $log->time;
|
||||
|
||||
/* Process files. */
|
||||
$log->files = array();
|
||||
foreach($log->change as $file => $info) $log->files[$info['action']][] = $file;
|
||||
}
|
||||
return $logs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update latest commit.
|
||||
*
|
||||
|
||||
@@ -76,38 +76,4 @@
|
||||
<div class='side-body'><?php include 'ajaxsidelogs.html.php';?></div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$(function()
|
||||
{
|
||||
$.get(createLink('repo', 'ajaxSyncLatestCommit', "repoID=<?php echo $repoID;?>"), function(data)
|
||||
{
|
||||
if(data == 'finished')
|
||||
{
|
||||
$('#mainContent').load(location.href + ' #mainContent', function()
|
||||
{
|
||||
$('#mainContent #mainContent .main-col').unwrap();
|
||||
$('#sidebar #logForm').table();
|
||||
|
||||
if($("input:checkbox[name='revision[]']:checked").length < 2)
|
||||
{
|
||||
$("input:checkbox[name='revision[]']:lt(2)").attr('checked', 'checked');
|
||||
}
|
||||
$("input:checkbox[name='revision[]']").each(function(){ if(!$(this).is(':checked')) $(this).attr("disabled","disabled")});
|
||||
$("input:checkbox[name='revision[]']").click(function()
|
||||
{
|
||||
var checkNum = $("input:checkbox[name='revision[]']:checked").length;
|
||||
if (checkNum >= 2)
|
||||
{
|
||||
$("input:checkbox[name='revision[]']").each(function(){ if(!$(this).is(':checked')) $(this).attr("disabled","disabled")});
|
||||
}
|
||||
else
|
||||
{
|
||||
$("input:checkbox[name='revision[]']").each(function(){$(this).attr("disabled", false)});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php include '../../common/view/footer.html.php';?>
|
||||
|
||||
@@ -99,15 +99,19 @@ class svnModel extends model
|
||||
$tagGroup = array();
|
||||
foreach($tagPlans as $integration) $tagGroup[$integration->repo][$integration->id] = $integration;
|
||||
|
||||
$_COOKIE['repoBranch'] = '';
|
||||
foreach($this->repos as $repoID => $repo)
|
||||
{
|
||||
$this->printLog("begin repo {$repo->name}");
|
||||
if(!$this->setRepo($repo)) return false;
|
||||
|
||||
$savedRevision = $this->getSavedRevision();
|
||||
$this->printLog("start from revision $savedRevision");
|
||||
$this->printLog("get this repo logs.");
|
||||
$lastInDB = $this->getLatestComment($repoID);
|
||||
/* Ignore unsynced repo. */
|
||||
if(empty($lastInDB)) continue;
|
||||
|
||||
$logs = $this->getRepoLogs($repo, $savedRevision);
|
||||
$version = $lastInDB->commit;
|
||||
$logs = $this->repo->getUnsyncLogs($repo);
|
||||
$objects = array();
|
||||
if(!empty($logs))
|
||||
{
|
||||
@@ -117,12 +121,6 @@ class svnModel extends model
|
||||
foreach($logs as $log)
|
||||
{
|
||||
$this->printLog("parsing log {$log->revision}");
|
||||
if($log->revision == $savedRevision)
|
||||
{
|
||||
$this->printLog("{$log->revision} alread parsed, commit it");
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->printLog("comment is\n----------\n" . trim($log->msg) . "\n----------");
|
||||
|
||||
$objects = $this->repo->parseComment($log->msg);
|
||||
@@ -150,11 +148,11 @@ class svnModel extends model
|
||||
}
|
||||
}
|
||||
|
||||
if($log->revision > $savedRevision) $savedRevision = $log->revision;
|
||||
$version = $this->repo->saveOneCommit($repoID, $log, $version);
|
||||
}
|
||||
$this->repo->updateCommitCount($repoID, $lastInDB->commit + count($logs));
|
||||
$this->dao->update(TABLE_REPO)->set('lastSync')->eq(helper::now())->where('id')->eq($repoID)->exec();
|
||||
|
||||
$this->saveLastRevision($savedRevision);
|
||||
$this->printLog("save revision $savedRevision");
|
||||
$this->deleteRestartFile();
|
||||
$this->printLog("\n\nrepo #" . $repo->id . ': ' . $repo->path . " finished");
|
||||
}
|
||||
@@ -265,7 +263,6 @@ class svnModel extends model
|
||||
$this->setClient($repo);
|
||||
if(empty($this->client)) return false;
|
||||
|
||||
$this->setLogFile($repo->id);
|
||||
$this->setRepoRoot($repo);
|
||||
return true;
|
||||
}
|
||||
@@ -293,18 +290,6 @@ class svnModel extends model
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the log file of a repo.
|
||||
*
|
||||
* @param string $repoName
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function setLogFile($repoId)
|
||||
{
|
||||
$this->logFile = $this->logRoot . $repoId . '.log';
|
||||
}
|
||||
|
||||
/**
|
||||
* set the root path of a repo.
|
||||
*
|
||||
@@ -679,31 +664,6 @@ class svnModel extends model
|
||||
return $this->dao->select('id, project, product')->from(TABLE_BUG)->where('id')->in($bugs)->fetchAll('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the saved revision.
|
||||
*
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function getSavedRevision()
|
||||
{
|
||||
if(!file_exists($this->logFile)) return 0;
|
||||
if(file_exists($this->restartFile)) return 0;
|
||||
return (int)trim(file_get_contents($this->logFile));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the last revision.
|
||||
*
|
||||
* @param int $revision
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function saveLastRevision($revision)
|
||||
{
|
||||
file_put_contents($this->logFile, $revision);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pring log.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user