exe git pull and retrive git log
This commit is contained in:
@@ -438,7 +438,7 @@ class ci extends control
|
||||
*/
|
||||
public function deleteRepo($id)
|
||||
{
|
||||
$this->ci->delete(TABLE_JENKINS, $id);
|
||||
$this->ci->delete(TABLE_REPO, $id);
|
||||
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
|
||||
$this->send(array('result' => 'success'));
|
||||
|
||||
@@ -698,6 +698,22 @@ class ciModel extends model
|
||||
return $repos;
|
||||
}
|
||||
|
||||
/**
|
||||
* list repos for jenkins task edit
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function listRepoForSync($whr)
|
||||
{
|
||||
$repos = $this->dao->select('*')->from(TABLE_REPO)
|
||||
->where('deleted')->eq('0')
|
||||
->beginIF(!empty(whr))->andWhere($whr)->fi()
|
||||
->orderBy(id)
|
||||
->fetchAll();
|
||||
$repos[''] = '';
|
||||
return $repos;
|
||||
}
|
||||
|
||||
/**
|
||||
* list jenkins for ci task edit
|
||||
*
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
*/
|
||||
$config->git = new stdClass();
|
||||
$config->git->encodings = 'utf-8';
|
||||
$config->git->client = '';
|
||||
$config->git->client = '/usr/bin/git';
|
||||
|
||||
$i = 1;
|
||||
$config->git->repos[$i]['path'] = '';
|
||||
$config->git->repos[$i]['path'] = '/Users/aaron/devops/project/devops_test';
|
||||
$config->git->repos[$i]['encoding'] = 'utf-8';
|
||||
|
||||
/*
|
||||
|
||||
@@ -94,6 +94,8 @@ class gitModel extends model
|
||||
$repo->name = $name;
|
||||
if(!$this->setRepo($repo)) return false;
|
||||
|
||||
$this->pull();
|
||||
|
||||
$savedRevision = $this->getSavedRevision();
|
||||
$this->printLog("start from revision $savedRevision");
|
||||
$logs = $this->getRepoLogs($repo, $savedRevision);
|
||||
@@ -135,6 +137,23 @@ class gitModel extends model
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pull codes from remote repo.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function pull()
|
||||
{
|
||||
chdir($this->repoRoot);
|
||||
|
||||
// exec('sudo -u aaron whoami', $output, $return);
|
||||
|
||||
$cmd = "{$this->client} pull 2>&1";
|
||||
exec($cmd, $output, $return);
|
||||
$this->printLog("{$cmd}, {$output}, {$return}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the log root.
|
||||
*
|
||||
@@ -177,13 +196,33 @@ class gitModel extends model
|
||||
*/
|
||||
public function setRepos()
|
||||
{
|
||||
if(!$this->config->git->repos)
|
||||
$ci = $this->loadModel('ci');
|
||||
$repoObjs = $ci->listRepoForSync("true");
|
||||
|
||||
$gitRepos = [];
|
||||
$paths = [];
|
||||
foreach($repoObjs as $repoInDb)
|
||||
{
|
||||
if(strtolower($repoInDb->SCM) === 'git' && !in_array($repoInDb->path, $gitRepos)) {
|
||||
$gitRepos[] = array(path => $repoInDb->path, encoding => 'utf-8');
|
||||
$paths[] = $repoInDb->path;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->config->git->repos as $repoInConfig)
|
||||
{
|
||||
if(!empty($repoInConfig['path']) && !in_array($repoInConfig['path'], $paths)) {
|
||||
$gitRepos[] = $repoInConfig;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$gitRepos)
|
||||
{
|
||||
echo "You must set one git repo.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->repos = $this->config->git->repos;
|
||||
$this->repos = $gitRepos;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user