* finish task #6954.

This commit is contained in:
wangyidong
2020-03-02 10:04:38 +08:00
parent 154efa0b59
commit 653c4d5cf6
10 changed files with 45 additions and 40 deletions
+4
View File
@@ -70,3 +70,7 @@ DROP `tagKeywords`,
DROP `commentKeywords`,
ADD `comment` varchar(255) COLLATE 'utf8_general_ci' NULL AFTER `atTime`,
ADD `lastTag` varchar(255) COLLATE 'utf8_general_ci' NULL;
ALTER TABLE `zt_compile`
CHANGE `cijob` `integration` mediumint(8) unsigned NOT NULL AFTER `name`,
CHANGE `queueItem` `queue` mediumint(8) NOT NULL AFTER `integration`;
+5 -5
View File
@@ -33,7 +33,7 @@ class ciModel extends model
{
$compiles = $this->dao->select('t1.*, t2.jkJob, t3.name jenkinsName,t3.serviceUrl,t3.account,t3.token,t3.password')
->from(TABLE_COMPILE)->alias('t1')
->leftJoin(TABLE_INTEGRATION)->alias('t2')->on('t1.cijob=t2.id')
->leftJoin(TABLE_INTEGRATION)->alias('t2')->on('t1.integration=t2.id')
->leftJoin(TABLE_JENKINS)->alias('t3')->on('t2.jkHost=t3.id')
->where('t1.status')->ne('success')
->andWhere('t1.status')->ne('fail')
@@ -49,19 +49,19 @@ class ciModel extends model
$jenkinsAuth = '://' . $jenkinsUser . ':' . $jenkinsPassword . '@';
$jenkinsServer = str_replace('://', $jenkinsAuth, $jenkinsServer);
$queueUrl = sprintf('%s/queue/item/%s/api/json', $jenkinsServer, $compile->queueItem);
$queueUrl = sprintf('%s/queue/item/%s/api/json', $jenkinsServer, $compile->queue);
$response = common::http($queueUrl);
if(strripos($response, "404") > -1)
{
/* Queue expired, use another api. */
$infoUrl = sprintf('%s/job/%s/%s/api/json', $jenkinsServer, $compile->jkJob, $compile->queueItem);
$infoUrl = sprintf('%s/job/%s/%s/api/json', $jenkinsServer, $compile->jkJob, $compile->queue);
$response = common::http($infoUrl);
$buildInfo = json_decode($response);
$result = strtolower($buildInfo->result);
$this->updateBuildStatus($compile, $result);
$logUrl = sprintf('%s/job/%s/%s/consoleText', $jenkinsServer, $compile->jkJob, $compile->queueItem);
$logUrl = sprintf('%s/job/%s/%s/consoleText', $jenkinsServer, $compile->jkJob, $compile->queue);
$response = common::http($logUrl);
$logs = json_decode($response);
@@ -111,7 +111,7 @@ class ciModel extends model
public function updateBuildStatus($build, $status)
{
$this->dao->update(TABLE_COMPILE)->set('status')->eq($status)->where('id')->eq($build->id)->exec();
$this->dao->update(TABLE_INTEGRATION)->set('lastExec')->eq(helper::now())->set('lastStatus')->eq($status)->where('id')->eq($build->cijob)->exec();
$this->dao->update(TABLE_INTEGRATION)->set('lastExec')->eq(helper::now())->set('lastStatus')->eq($status)->where('id')->eq($build->integration)->exec();
}
/**
+7 -6
View File
@@ -28,6 +28,7 @@ class compile extends control
/**
* Browse jenkins build.
*
* @param int $integrationID
* @param string $orderBy
* @param int $recTotal
* @param int $recPerPage
@@ -35,7 +36,7 @@ class compile extends control
* @access public
* @return void
*/
public function browse($jobID = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
public function browse($integrationID = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
{
$this->app->loadClass('pager', $static = true);
$pager = new pager($recTotal, $recPerPage, $pageID);
@@ -45,10 +46,10 @@ class compile extends control
$this->view->position[] = $this->lang->compile->browse;
$this->app->loadLang('integration');
$this->view->buildList = $this->compile->getList($jobID, $orderBy, $pager);
$this->view->jobID = $jobID;
$this->view->orderBy = $orderBy;
$this->view->pager = $pager;
$this->view->integrationID = $integrationID;
$this->view->buildList = $this->compile->getList($integrationID, $orderBy, $pager);
$this->view->orderBy = $orderBy;
$this->view->pager = $pager;
$this->display();
}
@@ -67,7 +68,7 @@ class compile extends control
$this->view->title = $this->lang->ci->job . $this->lang->colon . $this->lang->compile->logs;
$this->view->position[] = html::a($this->createLink('integration', 'browse'), $this->lang->ci->job);
$this->view->position[] = html::a($this->createLink('compile', 'browse', "jobID=" . $build->cijob), $this->lang->compile->browse);
$this->view->position[] = html::a($this->createLink('compile', 'browse', "integrationID=" . $build->integration), $this->lang->compile->browse);
$this->view->position[] = $this->lang->compile->logs;
$this->display();
}
+17 -17
View File
@@ -14,21 +14,21 @@ class compileModel extends model
/**
* Get build list.
*
* @param int $jobID
* @param int $integrationID
* @param string $orderBy
* @param object $pager
* @access public
* @return array
*/
public function getList($jobID, $orderBy = 'id_desc', $pager = null)
public function getList($integrationID, $orderBy = 'id_desc', $pager = null)
{
return $this->dao->select('t1.id, t1.name, t1.status, t1.createdDate, t2.triggerType, t3.name as repoName, t4.name as jenkinsName')->from(TABLE_COMPILE)->alias('t1')
->leftJoin(TABLE_INTEGRATION)->alias('t2')->on('t1.cijob=t2.id')
->leftJoin(TABLE_INTEGRATION)->alias('t2')->on('t1.integration=t2.id')
->leftJoin(TABLE_REPO)->alias('t3')->on('t2.repo=t3.id')
->leftJoin(TABLE_JENKINS)->alias('t4')->on('t2.jkHost=t4.id')
->where('t1.deleted')->eq('0')
->andWhere('t1.cijob')->ne('0')
->beginIF(!empty($jobID))->andWhere('t1.cijob')->eq($jobID)->fi()
->andWhere('t1.integration')->ne('0')
->beginIF(!empty($integrationID))->andWhere('t1.integration')->eq($integrationID)->fi()
->orderBy($orderBy)
->page($pager)
->fetchAll('id');
@@ -58,9 +58,9 @@ class compileModel extends model
}
/**
* Save build by job
* Save build by integration
*
* @param object $job
* @param int $integrationID
* @access public
* @return void
*/
@@ -69,7 +69,7 @@ class compileModel extends model
$integration = $this->dao->select('id,name')->from(TABLE_INTEGRATION)->where('id')->eq($integrationID)->fetch();
$build = new stdClass();
$build->cijob = $integration->id;
$build->integration = $integration->id;
$build->name = $integration->name;
$build->createdBy = $this->app->user->account;
$build->createdDate = helper::now();
@@ -86,18 +86,18 @@ class compileModel extends model
*/
public function execByCompile($compile, $data = null)
{
$integration = $this->dao->select('t1.id as jobId,t1.name as jobName,t1.repo,t1.jkJob,t2.name as jenkinsName,t2.serviceUrl,t2.account,t2.token,t2.password')
$integration = $this->dao->select('t1.id,t1.name,t1.repo,t1.jkJob,t2.name as jenkinsName,t2.serviceUrl,t2.account,t2.token,t2.password')
->from(TABLE_INTEGRATION)->alias('t1')
->leftJoin(TABLE_JENKINS)->alias('t2')->on('t1.jkHost=t2.id')
->where('t1.id')->eq($compile->cijob)
->where('t1.id')->eq($compile->integration)
->fetch();
if(!$integration) return false;
$buildUrl = $this->getBuildUrl($integration);
$build = new stdclass();
$build->queueItem = $this->loadModel('ci')->sendRequest($buildUrl, $data);
$build->status = $build->queueItem ? 'created' : 'create_fail';
$build->queue = $this->loadModel('ci')->sendRequest($buildUrl, $data);
$build->status = $build->queue ? 'created' : 'create_fail';
$this->dao->update(TABLE_COMPILE)->data($build)->where('id')->eq($compile->id)->exec();
return !dao::isError();
@@ -112,7 +112,7 @@ class compileModel extends model
*/
public function execByIntegration($integrationID, $data = null)
{
$integration = $this->dao->select('t1.id as jobId,t1.name as jobName,t1.repo,t1.jkJob,t2.name as jenkinsName,t2.serviceUrl,t2.account,t2.token,t2.password')
$integration = $this->dao->select('t1.id,t1.name,t1.repo,t1.jkJob,t2.name as jenkinsName,t2.serviceUrl,t2.account,t2.token,t2.password')
->from(TABLE_INTEGRATION)->alias('t1')
->leftJoin(TABLE_JENKINS)->alias('t2')->on('t1.jkHost=t2.id')
->where('t1.id')->eq($integrationID)
@@ -122,10 +122,10 @@ class compileModel extends model
$buildUrl = $this->getBuildUrl($integration);
$build = new stdClass();
$build->cijob = $integration->jobId;
$build->name = $integration->jobName;
$build->queueItem = $this->loadModel('ci')->sendRequest($buildUrl, $data);
$build->status = $build->queueItem ? 'created' : 'create_fail';
$build->integration = $integration->id;
$build->name = $integration->name;
$build->queue = $this->loadModel('ci')->sendRequest($buildUrl, $data);
$build->status = $build->queue ? 'created' : 'create_fail';
$build->createdBy = $this->app->user->account;
$build->createdDate = helper::now();
$this->dao->insert(TABLE_COMPILE)->data($build)->exec();
+1 -1
View File
@@ -25,7 +25,7 @@
<table id='buildList' class='table has-sort-head table-fixed'>
<thead>
<tr class='text-center'>
<?php $vars = "jobID={$jobID}&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?>
<?php $vars = "integrationID={$integrationID}&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?>
<th class='w-60px'><?php common::printOrderLink('id', $orderBy, $vars, $lang->compile->id);?></th>
<th class='text-left'><?php common::printOrderLink('name', $orderBy, $vars, $lang->compile->name);?></th>
<th class='text-left'><?php echo $lang->integration->repo;?></th>
+1 -1
View File
@@ -18,7 +18,7 @@
</div>
</div>
<div class="btn-toolbar pull-right">
<?php echo html::a(helper::createLink('compile', "browse", "jobId=$build->cijob"), "<i class='icon icon-back icon-sm'></i> ". $lang->goback, '', "class='btn btn-secondary'");?>
<?php echo html::a(helper::createLink('compile', "browse", "integrationID=$build->integration"), "<i class='icon icon-back icon-sm'></i> ". $lang->goback, '', "class='btn btn-secondary'");?>
</div>
</div>
<div id='mainContent'>
+3 -3
View File
@@ -137,10 +137,10 @@ class gitModel extends model
$this->printLog("\n\nrepo #" . $repo->id . ': ' . $repo->path . " finished");
}
// exe ci jobs in log
$cijobIdList = zget($objects, 'integrations', array());
// Create compile by integration.
$integrations = zget($objects, 'integrations', array());
$this->loadModel('compile');
foreach($cijobIdList as $id) $this->compile->execByIntegration($id);
foreach($integrations as $id) $this->compile->createByIntegration($id);
}
}
+1 -1
View File
@@ -139,7 +139,7 @@ class integration extends control
*/
public function delete($id, $confirm = 'no')
{
if($confirm != 'yes') die(js::confirm($this->lang->integration->confirmDelete, inlink('delete', "jobID=$id&confirm=yes")));
if($confirm != 'yes') die(js::confirm($this->lang->integration->confirmDelete, inlink('delete', "integrationID=$id&confirm=yes")));
$this->integration->delete(TABLE_INTEGRATION, $id);
die(js::reload('parent'));
+3 -3
View File
@@ -52,9 +52,9 @@
<td class='text'><?php if($job->lastStatus) echo zget($lang->compile->statusList, $job->lastStatus) . $lang->ci->at . $job->lastExec;?></td>
<td class='c-actions text-center'>
<?php
common::printIcon('compile', 'browse', "jobID=$id", '', 'list', 'file-text');
common::printIcon('integration', 'edit', "jobID=$id", '', 'list', 'edit');
if(common::hasPriv('integration', 'delete')) echo html::a($this->createLink('integration', 'delete', "jobID=$id"), '<i class="icon-trash"></i>', 'hiddenwin', "title='{$lang->integration->delete}' class='btn'");
common::printIcon('compile', 'browse', "integrationID=$id", '', 'list', 'file-text');
common::printIcon('integration', 'edit', "integrationID=$id", '', 'list', 'edit');
if(common::hasPriv('integration', 'delete')) echo html::a($this->createLink('integration', 'delete', "integrationID=$id"), '<i class="icon-trash"></i>', 'hiddenwin', "title='{$lang->integration->delete}' class='btn'");
?>
</td>
</tr>
+3 -3
View File
@@ -138,10 +138,10 @@ class svnModel extends model
$this->printLog("\n\nrepo #" . $repo->id . ': ' . $repo->path . " finished");
}
// exe ci jobs in log
$cijobIdList = zget($objects, 'integrations', array());
// Create compile by integration.
$integrations = zget($objects, 'integrations', array());
$this->loadModel('compile');
foreach($cijobIdList as $id) $this->compile->execByCompile($id);
foreach($integrations as $id) $this->compile->createByIntegration($id);
}
}