save tag build histories to db for svn repo

This commit is contained in:
aaronchen2k
2020-02-03 10:57:14 +08:00
parent b6ec537ec3
commit 091a6b4743
5 changed files with 39 additions and 24 deletions
+1
View File
@@ -173,6 +173,7 @@ define('TABLE_CREDENTIALS', '`' . $config->db->prefix . 'credentials`');
define('TABLE_JENKINS', '`' . $config->db->prefix . 'jenkins`');
define('TABLE_CI_JOB', '`' . $config->db->prefix . 'cijob`');
define('TABLE_CI_BUILD', '`' . $config->db->prefix . 'cibuild`');
define('TABLE_TAG', '`' . $config->db->prefix . 'tag`');
define('TABLE_REPO', '`' . $config->db->prefix . 'repo`');
define('TABLE_REPOHISTORY', '`' . $config->db->prefix . 'repohistory`');
+7
View File
@@ -2,6 +2,13 @@
ALTER TABLE `zt_repo`
ADD COLUMN `desc` TEXT NULL AFTER `lastSync`;
CREATE TABLE `zt_tag` (
`id` mediumint(9) NOT NULL AUTO_INCREMENT,
`repo` mediumint(9) NOT NULL,
`name` varchar(40) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `zt_jenkins` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
+2
View File
@@ -184,6 +184,8 @@ class ciModel extends model
->where('job.id')->eq($jobID)
->fetch();
$po->password = base64_decode($po->password);
$jenkinsServer = $po->serviceUrl;
$jenkinsUser = $po->account;
$jenkinsTokenOrPassword = $po->token ? $po->token : $po->password;
+2
View File
@@ -16,6 +16,8 @@
*
*/
$config->svn->tagRequiredFields = 'name,repo';
/* will use the config of repo records in db
$config->svn = new stdClass();
$config->svn->encodings = 'utf-8';
+27 -24
View File
@@ -129,8 +129,8 @@ class svnModel extends model
if($log->revision > $savedRevision) $savedRevision = $log->revision;
}
$this->saveLastRevision(savedRevision);
$this->printLog("save revision $latestRevision");
$this->saveLastRevision($savedRevision);
$this->printLog("save revision $savedRevision");
$this->deleteRestartFile();
$this->printLog("\n\nrepo ' . $repo->id . ': ' . $repo->path . ' finished");
@@ -146,27 +146,21 @@ class svnModel extends model
// dealwith tag commands
$this->printLog("dealwith tag commands");
$savedTag = $this->getSavedTag();
$savedTags = $this->getSavedTags($repo->id);
$tags = $this->getRepoTags($repo);
if(!empty($tags)) {
$arriveLastTag = false;
$jobToBuild = [];
foreach ($tags as $tag) {
if (!empty($savedTag) && $tag === $savedTag) { // get the last build tag position
$arriveLastTag = true;
continue;
}
if (!empty($savedTag) && !$arriveLastTag) { // not get
if ($savedTags[$tag]) { // old
continue;
}
$scm = $this->app->loadClass('scm');
$scm->parseTag($tag, $jobToBuild);
}
$this->saveLastTag($tags[count($tags) - 1]);
$this->saveLastTag($tag, $repo->id);
}
$this->printLog('extract tasks to build: ' . json_encode($jobToBuild));
// exe ci jobs in tag
@@ -353,18 +347,24 @@ class svnModel extends model
*/
public function getRepoTags($repo)
{
$path = $repo->path;
if (substr($path, -1) != '/') {
$path .= '/';
}
$path = str_replace("/trunk/","/tags/", $path);
$parsedTags = array();
/* The svn tag command. */
chdir($this->repoRoot);
exec("{$this->client} config core.quotepath false");
$cmd = "$this->client for-each-ref --sort=taggerdate | grep refs/tags | grep -v commit";
$cmd = "$this->client ls $path";
exec($cmd, $list, $return);
foreach($list as $line)
{
$arr = explode('refs/tags/', $line);
$parsedTags[] = $arr[count($arr) - 1];
if (substr($path, -1) == '/') {
$line = substr($line, 0, strlen($line) - 1);
}
$parsedTags[] = $line;
}
return $parsedTags;
@@ -798,11 +798,10 @@ class svnModel extends model
* @access public
* @return int
*/
public function getSavedTag()
public function getSavedTags($repoId)
{
if(!file_exists($this->tagFile)) return 0;
if(file_exists($this->restartFile)) return 0;
return trim(file_get_contents($this->tagFile));
$tags = $this->dao->select('name, id')->from(TABLE_TAG)->where('repo')->eq($repoId)->fetchPairs();
return $tags;
}
/**
@@ -812,8 +811,12 @@ class svnModel extends model
* @access public
* @return void
*/
public function saveLastTag($tag)
public function saveLastTag($tag, $repoId)
{
$ret = file_put_contents($this->tagFile, $tag);
$data = (object) array('name'=>$tag, 'repo'=>$repoId);
$ret = $this->dao->insert(TABLE_TAG)->data($data)
->batchCheck($this->config->svn->tagRequiredFields, 'notempty')
->autoCheck()->exec();
}
}