From 31aba45ddc2e697050b992c15463cab206dcddd0 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Fri, 6 Mar 2020 17:35:33 +0800 Subject: [PATCH] * move integration to job. --- config/zentaopms.php | 2 +- db/update12.0.1.sql | 2 + module/ci/control.php | 4 +- module/ci/lang/en.php | 6 +- module/ci/lang/zh-cn.php | 6 +- module/ci/model.php | 4 +- module/common/lang/en.php | 18 +-- module/common/lang/zh-cn.php | 26 ++-- module/compile/control.php | 20 +-- module/compile/model.php | 34 ++--- module/compile/view/browse.html.php | 51 +++---- module/compile/view/logs.html.php | 2 +- module/git/model.php | 30 ++-- module/integration/config.php | 6 - module/integration/lang/en.php | 38 ----- module/integration/lang/zh-cn.php | 38 ----- module/integration/view/browse.html.php | 87 ----------- module/job/config.php | 6 + module/{integration => job}/control.php | 56 ++++---- module/{integration => job}/css/create.css | 0 module/{integration => job}/css/edit.css | 0 module/{integration => job}/js/create.js | 0 module/{integration => job}/js/edit.js | 0 module/job/lang/en.php | 38 +++++ module/job/lang/zh-cn.php | 38 +++++ module/{integration => job}/model.php | 136 ++++++++++-------- module/job/view/browse.html.php | 68 +++++++++ .../{integration => job}/view/create.html.php | 30 ++-- .../{integration => job}/view/edit.html.php | 32 ++--- module/svn/model.php | 34 ++--- 30 files changed, 400 insertions(+), 412 deletions(-) delete mode 100644 module/integration/config.php delete mode 100644 module/integration/lang/en.php delete mode 100644 module/integration/lang/zh-cn.php delete mode 100644 module/integration/view/browse.html.php create mode 100644 module/job/config.php rename module/{integration => job}/control.php (70%) rename module/{integration => job}/css/create.css (100%) rename module/{integration => job}/css/edit.css (100%) rename module/{integration => job}/js/create.js (100%) rename module/{integration => job}/js/edit.js (100%) create mode 100644 module/job/lang/en.php create mode 100644 module/job/lang/zh-cn.php rename module/{integration => job}/model.php (56%) create mode 100644 module/job/view/browse.html.php rename module/{integration => job}/view/create.html.php (76%) rename module/{integration => job}/view/edit.html.php (79%) diff --git a/config/zentaopms.php b/config/zentaopms.php index 4181858390..8ae47750ff 100644 --- a/config/zentaopms.php +++ b/config/zentaopms.php @@ -170,7 +170,7 @@ define('TABLE_SCORE', '`' . $config->db->prefix . 'score`'); define('TABLE_NOTIFY', '`' . $config->db->prefix . 'notify`'); define('TABLE_OAUTH', '`' . $config->db->prefix . 'oauth`'); define('TABLE_JENKINS', '`' . $config->db->prefix . 'jenkins`'); -define('TABLE_INTEGRATION', '`' . $config->db->prefix . 'integration`'); +define('TABLE_JOB', '`' . $config->db->prefix . 'job`'); define('TABLE_COMPILE', '`' . $config->db->prefix . 'compile`'); define('TABLE_REPO', '`' . $config->db->prefix . 'repo`'); diff --git a/db/update12.0.1.sql b/db/update12.0.1.sql index a08e055c32..d85ac5c911 100644 --- a/db/update12.0.1.sql +++ b/db/update12.0.1.sql @@ -86,3 +86,5 @@ ALTER TABLE `zt_jenkins` DROP `encrypt`; ALTER TABLE `zt_compile` ADD `atTime` varchar(10) COLLATE 'utf8_general_ci' NULL AFTER `logs`; ALTER TABLE `zt_compile` ADD `tag` varchar(255) COLLATE 'utf8_general_ci' NULL AFTER `logs`; +ALTER TABLE `zt_integration` RENAME TO `zt_job`; +ALTER TABLE `zt_compile` CHANGE `integration` `job` mediumint(8) unsigned NOT NULL AFTER `name`; diff --git a/module/ci/control.php b/module/ci/control.php index e6b85da185..a1ebca1b13 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -30,13 +30,13 @@ class ci extends control */ public function initQueue() { - $scheduleJobs = $this->loadModel('integration')->getListByTriggerType('schedule'); + $scheduleJobs = $this->loadModel('job')->getListByTriggerType('schedule'); $week = date('w'); $this->loadModel('compile'); foreach($scheduleJobs as $job) { - if(strpos($job->atDay, $week) !== false) $this->compile->createByIntegration($job->id, $job->atTime, 'atTime'); + if(strpos($job->atDay, $week) !== false) $this->compile->createByJob($job->id, $job->atTime, 'atTime'); } echo 'success'; } diff --git a/module/ci/lang/en.php b/module/ci/lang/en.php index 1d6662ce39..66b4aeba19 100644 --- a/module/ci/lang/en.php +++ b/module/ci/lang/en.php @@ -1,6 +1,6 @@ ci->common = 'CI'; -$lang->ci->integration = 'Integration'; -$lang->ci->plan = 'Plan'; -$lang->ci->history = 'History'; +$lang->ci->job = 'Construction'; +$lang->ci->plan = 'Plan'; +$lang->ci->history = 'History'; diff --git a/module/ci/lang/zh-cn.php b/module/ci/lang/zh-cn.php index d17cf4cec2..4b28062e18 100644 --- a/module/ci/lang/zh-cn.php +++ b/module/ci/lang/zh-cn.php @@ -1,6 +1,6 @@ ci->common = '持续集成'; -$lang->ci->integration = '构建'; -$lang->ci->plan = '构建计划'; -$lang->ci->history = '构建历史'; +$lang->ci->job = '构建'; +$lang->ci->plan = '构建计划'; +$lang->ci->history = '构建历史'; diff --git a/module/ci/model.php b/module/ci/model.php index bafd54c474..c28314a532 100644 --- a/module/ci/model.php +++ b/module/ci/model.php @@ -33,7 +33,7 @@ class ciModel extends model { $compiles = $this->dao->select('t1.*, t2.jkJob, t3.name as jenkinsName,t3.url,t3.account,t3.token,t3.password') ->from(TABLE_COMPILE)->alias('t1') - ->leftJoin(TABLE_INTEGRATION)->alias('t2')->on('t1.integration=t2.id') + ->leftJoin(TABLE_JOB)->alias('t2')->on('t1.job=t2.id') ->leftJoin(TABLE_JENKINS)->alias('t3')->on('t2.jkHost=t3.id') ->where('t1.status')->ne('success') ->andWhere('t1.status')->ne('fail') @@ -109,7 +109,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->integration)->exec(); + $this->dao->update(TABLE_JOB)->set('lastExec')->eq(helper::now())->set('lastStatus')->eq($status)->where('id')->eq($build->job)->exec(); } /** diff --git a/module/common/lang/en.php b/module/common/lang/en.php index 5a12b985cd..33d86cacfc 100644 --- a/module/common/lang/en.php +++ b/module/common/lang/en.php @@ -335,19 +335,19 @@ $lang->caselib->menu->caselib = array('link' => 'Case Library|caselib|browse|l $lang->ci = new stdclass(); $lang->ci->menu = new stdclass(); $lang->ci->menu->code = array('link' => 'Code|repo|browse|repoID=%s', 'alias' => 'diff,view,revision,log,blame,showsynccomment'); -$lang->ci->menu->build = array('link' => 'Build|integration|browse', 'subModule' => 'compile,integration'); +$lang->ci->menu->build = array('link' => 'Build|job|browse', 'subModule' => 'compile,job'); $lang->ci->menu->jenkins = array('link' => 'Jenkins|jenkins|browse', 'alias' => 'create,edit'); $lang->ci->menu->maintain = array('link' => 'Repo|repo|maintain', 'alias' => 'create,edit'); $lang->ci->menu->rules = array('link' => 'Rule|repo|setrules'); -$lang->repo = new stdclass(); -$lang->jenkins = new stdclass(); -$lang->compile = new stdclass(); -$lang->integration = new stdclass(); -$lang->repo->menu = $lang->ci->menu; -$lang->jenkins->menu = $lang->ci->menu; -$lang->compile->menu = $lang->ci->menu; -$lang->integration->menu = $lang->ci->menu; +$lang->repo = new stdclass(); +$lang->jenkins = new stdclass(); +$lang->compile = new stdclass(); +$lang->job = new stdclass(); +$lang->repo->menu = $lang->ci->menu; +$lang->jenkins->menu = $lang->ci->menu; +$lang->compile->menu = $lang->ci->menu; +$lang->job->menu = $lang->ci->menu; /* Doc menu settings. */ $lang->doc = new stdclass(); diff --git a/module/common/lang/zh-cn.php b/module/common/lang/zh-cn.php index df58ea9592..060ecdc628 100644 --- a/module/common/lang/zh-cn.php +++ b/module/common/lang/zh-cn.php @@ -335,19 +335,19 @@ $lang->caselib->menu->caselib = array('link' => '用例库|caselib|browse|libI $lang->ci = new stdclass(); $lang->ci->menu = new stdclass(); $lang->ci->menu->code = array('link' => '代码|repo|browse|repoID=%s', 'alias' => 'diff,view,revision,log,blame,showsynccomment'); -$lang->ci->menu->build = array('link' => '构建|integration|browse', 'subModule' => 'compile,integration'); +$lang->ci->menu->build = array('link' => '构建|job|browse', 'subModule' => 'compile,job'); $lang->ci->menu->jenkins = array('link' => 'Jenkins|jenkins|browse', 'alias' => 'create,edit'); $lang->ci->menu->maintain = array('link' => '版本库|repo|maintain', 'alias' => 'create,edit'); $lang->ci->menu->rules = array('link' => '指令|repo|setrules'); -$lang->repo = new stdclass(); -$lang->jenkins = new stdclass(); -$lang->compile = new stdclass(); -$lang->integration = new stdclass(); -$lang->repo->menu = $lang->ci->menu; -$lang->jenkins->menu = $lang->ci->menu; -$lang->compile->menu = $lang->ci->menu; -$lang->integration->menu = $lang->ci->menu; +$lang->repo = new stdclass(); +$lang->jenkins = new stdclass(); +$lang->compile = new stdclass(); +$lang->job = new stdclass(); +$lang->repo->menu = $lang->ci->menu; +$lang->jenkins->menu = $lang->ci->menu; +$lang->compile->menu = $lang->ci->menu; +$lang->job->menu = $lang->ci->menu; /* 文档视图菜单设置。*/ $lang->doc = new stdclass(); @@ -487,10 +487,10 @@ $lang->menugroup->entry = 'admin'; $lang->menugroup->webhook = 'admin'; $lang->menugroup->message = 'admin'; -$lang->menugroup->repo = 'ci'; -$lang->menugroup->jenkins = 'ci'; -$lang->menugroup->compile = 'ci'; -$lang->menugroup->integration = 'ci'; +$lang->menugroup->repo = 'ci'; +$lang->menugroup->jenkins = 'ci'; +$lang->menugroup->compile = 'ci'; +$lang->menugroup->job = 'ci'; /* 错误提示信息。*/ $lang->error = new stdclass(); diff --git a/module/compile/control.php b/module/compile/control.php index 326e1cb79c..25dc9c93df 100644 --- a/module/compile/control.php +++ b/module/compile/control.php @@ -28,7 +28,7 @@ class compile extends control /** * Browse jenkins build. * - * @param int $integrationID + * @param int $jobID * @param string $orderBy * @param int $recTotal * @param int $recPerPage @@ -36,18 +36,18 @@ class compile extends control * @access public * @return void */ - public function browse($integrationID = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) + public function browse($jobID = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { $this->app->loadClass('pager', $static = true); $pager = new pager($recTotal, $recPerPage, $pageID); - $this->view->title = $this->lang->ci->integration . $this->lang->colon . $this->lang->compile->browse; - $this->view->position[] = html::a($this->createLink('integration', 'browse'), $this->lang->ci->integration); + $this->view->title = $this->lang->ci->job . $this->lang->colon . $this->lang->compile->browse; + $this->view->position[] = html::a($this->createLink('job', 'browse'), $this->lang->ci->job); $this->view->position[] = $this->lang->compile->browse; - $this->app->loadLang('integration'); - $this->view->integrationID = $integrationID; - $this->view->buildList = $this->compile->getList($integrationID, $orderBy, $pager); + $this->app->loadLang('job'); + $this->view->jobID = $jobID; + $this->view->buildList = $this->compile->getList($jobID, $orderBy, $pager); $this->view->orderBy = $orderBy; $this->view->pager = $pager; $this->display(); @@ -66,9 +66,9 @@ class compile extends control $this->view->logs = str_replace("\r\n","
", $build->logs); $this->view->build = $build; - $this->view->title = $this->lang->ci->integration . $this->lang->colon . $this->lang->compile->logs; - $this->view->position[] = html::a($this->createLink('integration', 'browse'), $this->lang->ci->integration); - $this->view->position[] = html::a($this->createLink('compile', 'browse', "integrationID=" . $build->integration), $this->lang->compile->browse); + $this->view->title = $this->lang->ci->job . $this->lang->colon . $this->lang->compile->logs; + $this->view->position[] = html::a($this->createLink('job', 'browse'), $this->lang->ci->job); + $this->view->position[] = html::a($this->createLink('compile', 'browse', "jobID=" . $build->job), $this->lang->compile->browse); $this->view->position[] = $this->lang->compile->logs; $this->display(); } diff --git a/module/compile/model.php b/module/compile/model.php index 5ea1777535..2d9831af77 100644 --- a/module/compile/model.php +++ b/module/compile/model.php @@ -26,21 +26,21 @@ class compileModel extends model /** * Get build list. * - * @param int $integrationID + * @param int $jobID * @param string $orderBy * @param object $pager * @access public * @return array */ - public function getList($integrationID, $orderBy = 'id_desc', $pager = null) + public function getList($jobID, $orderBy = 'id_desc', $pager = null) { return $this->dao->select('t1.id, t1.name, t1.status, t1.createdDate, t2.jkJob,t2.triggerType,t2.comment,t2.atDay,t2.atTime, t3.name as repoName, t4.name as jenkinsName')->from(TABLE_COMPILE)->alias('t1') - ->leftJoin(TABLE_INTEGRATION)->alias('t2')->on('t1.integration=t2.id') + ->leftJoin(TABLE_JOB)->alias('t2')->on('t1.job=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.integration')->ne('0') - ->beginIF(!empty($integrationID))->andWhere('t1.integration')->eq($integrationID)->fi() + ->andWhere('t1.job')->ne('0') + ->beginIF(!empty($jobID))->andWhere('t1.job')->eq($jobID)->fi() ->orderBy($orderBy) ->page($pager) ->fetchAll('id'); @@ -77,21 +77,21 @@ class compileModel extends model } /** - * Save build by integration + * Save build by job * - * @param int $integrationID + * @param int $jobID * @param string $data * @param string $type * @access public * @return void */ - public function createByIntegration($integrationID, $data = '', $type = 'tag') + public function createByJob($jobID, $data = '', $type = 'tag') { - $integration = $this->dao->select('id,name')->from(TABLE_INTEGRATION)->where('id')->eq($integrationID)->fetch(); + $job = $this->dao->select('id,name')->from(TABLE_JOB)->where('id')->eq($jobID)->fetch(); $build = new stdClass(); - $build->integration = $integration->id; - $build->name = $integration->name; + $build->job = $job->id; + $build->name = $job->name; $build->$type = $data; $build->createdBy = $this->app->user->account; $build->createdDate = helper::now(); @@ -108,13 +108,13 @@ class compileModel extends model */ public function execByCompile($compile) { - $integration = $this->dao->select('t1.id,t1.name,t1.repo,t1.jkJob,t2.name as jenkinsName,t2.url,t2.account,t2.token,t2.password') - ->from(TABLE_INTEGRATION)->alias('t1') + $job = $this->dao->select('t1.id,t1.name,t1.repo,t1.jkJob,t2.name as jenkinsName,t2.url,t2.account,t2.token,t2.password') + ->from(TABLE_JOB)->alias('t1') ->leftJoin(TABLE_JENKINS)->alias('t2')->on('t1.jkHost=t2.id') - ->where('t1.id')->eq($compile->integration) + ->where('t1.id')->eq($compile->job) ->fetch(); - if(!$integration) return false; + if(!$job) return false; $tagData = ''; if($compile->tag) @@ -123,13 +123,13 @@ class compileModel extends model $tagData->PARAM_TAG = $compile->tag; } - $buildUrl = $this->getBuildUrl($integration); + $buildUrl = $this->getBuildUrl($job); $build = new stdclass(); $build->queue = $this->loadModel('ci')->sendRequest($buildUrl, $tagData); $build->status = $build->queue ? 'created' : 'create_fail'; $build->updateDate = helper::now(); $this->dao->update(TABLE_COMPILE)->data($build)->where('id')->eq($compile->id)->exec(); - $this->dao->update(TABLE_INTEGRATION)->set('lastStatus')->eq($build->status)->set('lastExec')->eq($build->updateDate)->where('id')->eq($compile->integration)->exec(); + $this->dao->update(TABLE_JOB)->set('lastStatus')->eq($build->status)->set('lastExec')->eq($build->updateDate)->where('id')->eq($compile->job)->exec(); return !dao::isError(); } diff --git a/module/compile/view/browse.html.php b/module/compile/view/browse.html.php index 834a70c87e..1e243e9338 100644 --- a/module/compile/view/browse.html.php +++ b/module/compile/view/browse.html.php @@ -14,7 +14,7 @@ - diff --git a/module/job/config.php b/module/job/config.php new file mode 100644 index 0000000000..fbca68a83a --- /dev/null +++ b/module/job/config.php @@ -0,0 +1,6 @@ +job = new stdclass(); +$config->job->create = new stdclass(); +$config->job->edit = new stdclass(); +$config->job->create->requiredFields = 'name,repo,jkHost,jkJob,triggerType'; +$config->job->edit->requiredFields = 'name,repo,jkHost,jkJob,triggerType'; diff --git a/module/integration/control.php b/module/job/control.php similarity index 70% rename from module/integration/control.php rename to module/job/control.php index 465cb97a19..cf2fe17c49 100644 --- a/module/integration/control.php +++ b/module/job/control.php @@ -1,15 +1,15 @@ - * @package integration + * @package job * @version $Id$ * @link http://www.zentao.net */ -class integration extends control +class job extends control { /** * Construct @@ -26,7 +26,7 @@ class integration extends control } /** - * Browse integration. + * Browse job. * * @param string $orderBy * @param int $recTotal @@ -41,11 +41,11 @@ class integration extends control $pager = new pager($recTotal, $recPerPage, $pageID); $this->app->loadLang('compile'); - $this->view->jobList = $this->integration->getList($orderBy, $pager); + $this->view->jobList = $this->job->getList($orderBy, $pager); - $this->view->title = $this->lang->ci->integration . $this->lang->colon . $this->lang->integration->browse; - $this->view->position[] = $this->lang->ci->integration; - $this->view->position[] = $this->lang->integration->browse; + $this->view->title = $this->lang->ci->job . $this->lang->colon . $this->lang->job->browse; + $this->view->position[] = $this->lang->ci->job; + $this->view->position[] = $this->lang->job->browse; $this->view->orderBy = $orderBy; $this->view->pager = $pager; @@ -53,7 +53,7 @@ class integration extends control } /** - * Create a integration. + * Create a job. * * @access public * @return void @@ -62,16 +62,16 @@ class integration extends control { if($_POST) { - $this->integration->create(); + $this->job->create(); if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); } $this->app->loadLang('action'); - $this->view->title = $this->lang->ci->integration . $this->lang->colon . $this->lang->integration->create; - $this->view->position[] = html::a(inlink('browse'), $this->lang->ci->integration); - $this->view->position[] = $this->lang->integration->create; + $this->view->title = $this->lang->ci->job . $this->lang->colon . $this->lang->job->create; + $this->view->position[] = html::a(inlink('browse'), $this->lang->ci->job); + $this->view->position[] = $this->lang->job->create; $repoList = $this->loadModel('repo')->getList(); $repoPairs = array(0 => ''); @@ -90,7 +90,7 @@ class integration extends control } /** - * Edit a integration. + * Edit a job. * * @param int $id * @access public @@ -98,17 +98,17 @@ class integration extends control */ public function edit($id) { - $job = $this->integration->getByID($id); + $job = $this->job->getByID($id); if($_POST) { - $this->integration->update($id); + $this->job->update($id); if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); } - $this->view->title = $this->lang->ci->integration . $this->lang->colon . $this->lang->integration->edit; - $this->view->position[] = html::a(inlink('browse'), $this->lang->ci->integration); - $this->view->position[] = $this->lang->integration->edit; + $this->view->title = $this->lang->ci->job . $this->lang->colon . $this->lang->job->edit; + $this->view->position[] = html::a(inlink('browse'), $this->lang->ci->job); + $this->view->position[] = $this->lang->job->edit; $repo = $this->loadModel('repo')->getRepoByID($job->repo); $this->view->repo = $this->loadModel('repo')->getRepoByID($job->repo); @@ -134,7 +134,7 @@ class integration extends control } /** - * Delete a integration. + * Delete a job. * * @param int $id * @access public @@ -142,14 +142,14 @@ class integration extends control */ public function delete($id, $confirm = 'no') { - if($confirm != 'yes') die(js::confirm($this->lang->integration->confirmDelete, inlink('delete', "integrationID=$id&confirm=yes"))); + if($confirm != 'yes') die(js::confirm($this->lang->job->confirmDelete, inlink('delete', "jobID=$id&confirm=yes"))); - $this->integration->delete(TABLE_INTEGRATION, $id); + $this->job->delete(TABLE_JOB, $id); die(js::reload('parent')); } /** - * Exec a integration. + * Exec a job. * * @param int $id * @access public @@ -157,9 +157,11 @@ class integration extends control */ public function exec($id) { - $result = $this->integration->exec($id); - if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); - if(!$result) $this->send(array('result' => 'fail', 'message' => 'not found')); - die(js::alert($this->lang->integration->sendExec)); + $status = $this->job->exec($id); + if(dao::isError()) die(js::error(dao::getError())); + + $this->app->loadLang('compile'); + echo js::alert(sprintf($this->lang->job->sendExec, zget($this->lang->compile->statusList, $status))); + die(js::reload('parent')); } } diff --git a/module/integration/css/create.css b/module/job/css/create.css similarity index 100% rename from module/integration/css/create.css rename to module/job/css/create.css diff --git a/module/integration/css/edit.css b/module/job/css/edit.css similarity index 100% rename from module/integration/css/edit.css rename to module/job/css/edit.css diff --git a/module/integration/js/create.js b/module/job/js/create.js similarity index 100% rename from module/integration/js/create.js rename to module/job/js/create.js diff --git a/module/integration/js/edit.js b/module/job/js/edit.js similarity index 100% rename from module/integration/js/edit.js rename to module/job/js/edit.js diff --git a/module/job/lang/en.php b/module/job/lang/en.php new file mode 100644 index 0000000000..a37fc4a4a9 --- /dev/null +++ b/module/job/lang/en.php @@ -0,0 +1,38 @@ +job->common = 'Job'; +$lang->job->browse = 'Browse Job'; +$lang->job->create = 'Create Job'; +$lang->job->edit = 'Edit Job'; +$lang->job->exec = 'Execute Job'; +$lang->job->delete = 'Delete Job'; +$lang->job->confirmDelete = 'Do you want to delete this job?'; +$lang->job->dirChange = 'Directory Changed'; +$lang->job->buildTag = 'Build Tag'; + +$lang->job->id = 'ID'; +$lang->job->name = 'Name'; +$lang->job->repo = 'Repo'; +$lang->job->svnDir = 'SVN Tag Watch Path'; +$lang->job->jenkins = 'Jenkins'; +$lang->job->jkHost = 'Jenkins Server'; +$lang->job->buildType = 'Build Type'; +$lang->job->jkJob = 'Jenkins Task'; +$lang->job->triggerType = 'Trigger'; +$lang->job->atDay = 'Custom Days'; +$lang->job->atTime = 'At Time'; +$lang->job->lastStatus = 'Last Status'; +$lang->job->lastExec = 'Last Executed'; +$lang->job->comment = 'Match Keywords'; + +$lang->job->example = 'e.g.'; +$lang->job->commitEx = "Used to match the keywords used to create a compile. Multiple keywords are separated by ','"; +$lang->job->cronSample = 'e.g. 0 0 2 * * 2-6/1 means 2:00 a.m. every weekday.'; +$lang->job->sendExec = 'Send execute request success.'; + +$lang->job->buildTypeList['build'] = 'Only Build'; +$lang->job->buildTypeList['buildAndDeploy'] = 'Build And Deploy'; +$lang->job->buildTypeList['buildAndTest'] = 'Build And Test'; + +$lang->job->triggerTypeList['tag'] = 'Tag'; +$lang->job->triggerTypeList['commit'] = 'Code Commit'; +$lang->job->triggerTypeList['schedule'] = 'Schedule'; diff --git a/module/job/lang/zh-cn.php b/module/job/lang/zh-cn.php new file mode 100644 index 0000000000..6b44810294 --- /dev/null +++ b/module/job/lang/zh-cn.php @@ -0,0 +1,38 @@ +job->common = '构建计划'; +$lang->job->browse = '浏览构建计划'; +$lang->job->create = '创建构建计划'; +$lang->job->edit = '编辑构建计划'; +$lang->job->exec = '执行构建'; +$lang->job->delete = '删除构建计划'; +$lang->job->confirmDelete = '确认删除该构建计划吗?'; +$lang->job->dirChange = '目录改动'; +$lang->job->buildTag = '打标签'; + +$lang->job->id = 'ID'; +$lang->job->name = '名称'; +$lang->job->repo = '代码库'; +$lang->job->svnDir = 'SVN监控路径'; +$lang->job->jenkins = 'Jenkins'; +$lang->job->jkHost = 'Jenkins服务器'; +$lang->job->buildType = '构建类型'; +$lang->job->jkJob = 'Jenkins任务'; +$lang->job->triggerType = '触发方式'; +$lang->job->atDay = '自定义日期'; +$lang->job->atTime = '执行时间'; +$lang->job->lastStatus = '最后执行状态'; +$lang->job->lastExec = '最后执行时间'; +$lang->job->comment = '匹配关键字'; + +$lang->job->example = '举例'; +$lang->job->commitEx = "用于匹配创建构建任务的关键字,多个关键字用','分割"; +$lang->job->cronSample = '如 0 0 2 * * 2-6/1 表示每个工作日凌晨2点'; +$lang->job->sendExec = '发送执行请求成功!执行结果:%s'; + +$lang->job->buildTypeList['build'] = '仅构建'; +$lang->job->buildTypeList['buildAndDeploy'] = '构建部署'; +$lang->job->buildTypeList['buildAndTest'] = '构建测试'; + +$lang->job->triggerTypeList['tag'] = '打标签'; +$lang->job->triggerTypeList['commit'] = '提交注释包含关键字'; +$lang->job->triggerTypeList['schedule'] = '定时计划'; diff --git a/module/integration/model.php b/module/job/model.php similarity index 56% rename from module/integration/model.php rename to module/job/model.php index 71f8c8c613..05dcfa5c7d 100644 --- a/module/integration/model.php +++ b/module/job/model.php @@ -1,15 +1,15 @@ - * @package integration + * @package job * @version $Id$ * @link http://www.zentao.net */ -class integrationModel extends model +class jobModel extends model { /** * Get by id. @@ -20,11 +20,11 @@ class integrationModel extends model */ public function getByID($id) { - return $this->dao->select('*')->from(TABLE_INTEGRATION)->where('id')->eq($id)->fetch(); + return $this->dao->select('*')->from(TABLE_JOB)->where('id')->eq($id)->fetch(); } /** - * Get integration list. + * Get job list. * * @param string $orderBy * @param object $pager @@ -33,7 +33,7 @@ class integrationModel extends model */ public function getList($orderBy = 'id_desc', $pager = null) { - return $this->dao->select('t1.*, t2.name as repoName, t3.name as jenkinsName')->from(TABLE_INTEGRATION)->alias('t1') + return $this->dao->select('t1.*, t2.name as repoName, t3.name as jenkinsName')->from(TABLE_JOB)->alias('t1') ->leftJoin(TABLE_REPO)->alias('t2')->on('t1.repo=t2.id') ->leftJoin(TABLE_JENKINS)->alias('t3')->on('t1.jkHost=t3.id') ->where('t1.deleted')->eq('0') @@ -51,54 +51,76 @@ class integrationModel extends model */ public function getListByTriggerType($triggerType, $repoIdList = array()) { - return $this->dao->select('*')->from(TABLE_INTEGRATION) + return $this->dao->select('*')->from(TABLE_JOB) ->where('deleted')->eq('0') ->andWhere('triggerType')->eq($triggerType) ->beginIF($repoIdList)->andWhere('repo')->in($repoIdList)->fi() ->fetchAll('id'); } + public function getTriggerConfig($job) + { + $triggerType = zget($this->lang->job->triggerTypeList, $job->triggerType); + if($job->triggerType == 'tag') + { + if(empty($job->svnDir)) return $triggerType; + + $triggerType = $this->lang->job->dirChange; + return "{$triggerType}({$job->svnDir})"; + } + + if($job->triggerType == 'commit') return "{$triggerType}({$job->comment})"; + + if($job->triggerType == 'schedule') + { + $atDay = ''; + foreach(explode(',', $job->atDay) as $day) $atDay .= zget($this->lang->datepicker->dayNames, trim($day), '') . ','; + $atDay = trim($atDay, ','); + return "{$triggerType}({$atDay}, {$job->atTime})"; + } + } + /** - * Create integration + * Create job * * @access public * @return void */ public function create() { - $integration = fixer::input('post') + $job = fixer::input('post') ->setDefault('atDay', '') ->setIF($this->post->repoType != 'Subversion', 'svnDir', '') ->add('createdBy', $this->app->user->account) ->add('createdDate', helper::now()) ->remove('repoType') ->get(); - if($integration->triggerType == 'schedule') $integration->atDay = empty($_POST['atDay']) ? '' : join(',', $this->post->atDay); - if($integration->triggerType == 'tag' and $this->post->repoType == 'Subversion') + if($job->triggerType == 'schedule') $job->atDay = empty($_POST['atDay']) ? '' : join(',', $this->post->atDay); + if($job->triggerType == 'tag' and $this->post->repoType == 'Subversion') { - $integration->svnDir = array_pop($_POST['svnDir']); - if($integration->svnDir == '/' and $_POST['svnDir']) $integration->svnDir = array_pop($_POST['svnDir']); + $job->svnDir = array_pop($_POST['svnDir']); + if($job->svnDir == '/' and $_POST['svnDir']) $job->svnDir = array_pop($_POST['svnDir']); } - $this->dao->insert(TABLE_INTEGRATION)->data($integration) - ->batchCheck($this->config->integration->create->requiredFields, 'notempty') + $this->dao->insert(TABLE_JOB)->data($job) + ->batchCheck($this->config->job->create->requiredFields, 'notempty') - ->batchCheckIF($integration->triggerType === 'schedule', "atDay,atTime", 'notempty') - ->batchCheckIF($integration->triggerType === 'commit', "comment", 'notempty') + ->batchCheckIF($job->triggerType === 'schedule', "atDay,atTime", 'notempty') + ->batchCheckIF($job->triggerType === 'commit', "comment", 'notempty') ->batchCheckIF($this->post->repoType == 'Subversion', "svnDir", 'notempty') ->autoCheck() ->exec(); $id = $this->dao->lastInsertId(); - if($integration->triggerType == 'schedule' and strpos($integration->atDay, date('w')) !== false) $this->loadModel('compile')->createByIntegration($id); - if($integration->triggerType == 'tag') + if($job->triggerType == 'schedule' and strpos($job->atDay, date('w')) !== false) $this->loadModel('compile')->createByJob($id); + if($job->triggerType == 'tag') { - $repo = $this->loadModel('repo')->getRepoByID($integration->repo); + $repo = $this->loadModel('repo')->getRepoByID($job->repo); $lastTag = ''; if($this->post->repoType != 'Subversion') { - $dirs = $this->loadModel('svn')->getRepoTags($repo, $integration->svnDir); + $dirs = $this->loadModel('svn')->getRepoTags($repo, $job->svnDir); end($dirs); $lastTag = current($dirs); } @@ -108,13 +130,13 @@ class integrationModel extends model end($tags); $lastTag = current($tags); } - $this->dao->update(TABLE_INTEGRATION)->set('lastTag')->eq($lastTag)->where('id')->eq($id)->exec(); + $this->dao->update(TABLE_JOB)->set('lastTag')->eq($lastTag)->where('id')->eq($id)->exec(); } return true; } /** - * Update integration + * Update job * * @param int $id * @access public @@ -122,8 +144,8 @@ class integrationModel extends model */ public function update($id) { - $oldIntegration = $this->getById($id); - $integration = fixer::input('post') + $oldJob = $this->getById($id); + $job = fixer::input('post') ->setDefault('atDay', '') ->setIF($this->post->repoType != 'Subversion', 'svnDir', '') ->setIF($this->post->triggerType != 'commit', 'comment', '') @@ -134,41 +156,41 @@ class integrationModel extends model ->add('editedDate', helper::now()) ->remove('repoType') ->get(); - if($integration->triggerType == 'schedule') $integration->atDay = empty($_POST['atDay']) ? '' : join(',', $this->post->atDay); - if($integration->triggerType == 'tag' and $this->post->repoType == 'Subversion') + if($job->triggerType == 'schedule') $job->atDay = empty($_POST['atDay']) ? '' : join(',', $this->post->atDay); + if($job->triggerType == 'tag' and $this->post->repoType == 'Subversion') { - $integration->svnDir = array_pop($_POST['svnDir']); - if($integration->svnDir == '/' and $_POST['svnDir']) $integration->svnDir = array_pop($_POST['svnDir']); + $job->svnDir = array_pop($_POST['svnDir']); + if($job->svnDir == '/' and $_POST['svnDir']) $job->svnDir = array_pop($_POST['svnDir']); } - $this->dao->update(TABLE_INTEGRATION)->data($integration) - ->batchCheck($this->config->integration->edit->requiredFields, 'notempty') + $this->dao->update(TABLE_JOB)->data($job) + ->batchCheck($this->config->job->edit->requiredFields, 'notempty') - ->batchCheckIF($integration->triggerType === 'schedule', "atDay,atTime", 'notempty') - ->batchCheckIF($integration->triggerType === 'commit', "comment", 'notempty') + ->batchCheckIF($job->triggerType === 'schedule', "atDay,atTime", 'notempty') + ->batchCheckIF($job->triggerType === 'commit', "comment", 'notempty') ->batchCheckIF($this->post->repoType == 'Subversion', "svnDir", 'notempty') ->autoCheck() ->where('id')->eq($id) ->exec(); - if($integration->triggerType == 'schedule') + if($job->triggerType == 'schedule') { $week = date('w'); - if($integration->triggerType != $oldIntegration->triggerType or strpos($oldIntegration->atDay, $week) === false) + if($job->triggerType != $oldJob->triggerType or strpos($oldJob->atDay, $week) === false) { - if(strpos($integration->atDay, $week) !== false) $this->loadModel('compile')->createByIntegration($integration->id); + if(strpos($job->atDay, $week) !== false) $this->loadModel('compile')->createByJob($job->id); } } - elseif($integration->triggerType == 'tag') + elseif($job->triggerType == 'tag') { - if($integration->triggerType != $oldIntegration->triggerType or $integration->repo != $oldIntegration->repo) + if($job->triggerType != $oldJob->triggerType or $job->repo != $oldJob->repo) { - $repo = $this->loadModel('repo')->getRepoByID($integration->repo); + $repo = $this->loadModel('repo')->getRepoByID($job->repo); $lastTag = ''; if($this->post->repoType == 'Subversion') { - $dirs = $this->loadModel('svn')->getRepoTags($repo, $integration->svnDir); + $dirs = $this->loadModel('svn')->getRepoTags($repo, $job->svnDir); end($dirs); $lastTag = current($dirs); } @@ -178,14 +200,14 @@ class integrationModel extends model end($tags); $lastTag = current($tags); } - $this->dao->update(TABLE_INTEGRATION)->set('lastTag')->eq($lastTag)->where('id')->eq($id)->exec(); + $this->dao->update(TABLE_JOB)->set('lastTag')->eq($lastTag)->where('id')->eq($id)->exec(); } } return true; } /** - * Exec integration. + * Exec job. * * @param int $id * @access public @@ -193,32 +215,32 @@ class integrationModel extends model */ public function exec($id) { - $integration = $this->dao->select('t1.id,t1.name,t1.repo,t1.jkJob,t1.triggerType,t1.atTime,t2.name as jenkinsName,t2.url,t2.account,t2.token,t2.password') - ->from(TABLE_INTEGRATION)->alias('t1') + $job = $this->dao->select('t1.id,t1.name,t1.repo,t1.jkJob,t1.triggerType,t1.atTime,t2.name as jenkinsName,t2.url,t2.account,t2.token,t2.password') + ->from(TABLE_JOB)->alias('t1') ->leftJoin(TABLE_JENKINS)->alias('t2')->on('t1.jkHost=t2.id') ->where('t1.id')->eq($id) ->fetch(); - if(!$integration) return false; + if(!$job) return false; - $buildUrl = $this->loadModel('compile')->getBuildUrl($integration); + $buildUrl = $this->loadModel('compile')->getBuildUrl($job); $build = new stdclass(); - $build->integration = $integration->id; - $build->name = $integration->name; + $build->job = $job->id; + $build->name = $job->name; $now = helper::now(); $data = ''; - if($integration->triggerType == 'tag') + if($job->triggerType == 'tag') { - $repo = $this->loadModel('repo')->getRepoById($integration->repo); + $repo = $this->loadModel('repo')->getRepoById($job->repo); $lastTag = ''; if($repo->SCM == 'Subversion') { - $dirs = $this->loadModel('svn')->getRepoTags($repo, $integration->svnDir); + $dirs = $this->loadModel('svn')->getRepoTags($repo, $job->svnDir); if($dirs) { end($dirs); $lastTag = current($dirs); - $lastTag = rtrim($repo->path , '/') . '/' . trim($integration->svnDir, '/') . '/' . $lastTag; + $lastTag = rtrim($repo->path , '/') . '/' . trim($job->svnDir, '/') . '/' . $lastTag; } } else @@ -234,15 +256,15 @@ class integrationModel extends model if($lastTag) { $build->tag = $lastTag; - $this->dao->update(TABLE_INTEGRATION)->set('lastTag')->eq($lastTag)->where('id')->eq($integration->id)->exec(); + $this->dao->update(TABLE_JOB)->set('lastTag')->eq($lastTag)->where('id')->eq($job->id)->exec(); $data = new stdClass(); $data->PARAM_TAG = $lastTag; } } - elseif($integration->triggerType == 'schedule') + elseif($job->triggerType == 'schedule') { - $build->atTime = $integration->atTime; + $build->atTime = $job->atTime; } $build->queue = $this->loadModel('ci')->sendRequest($buildUrl, $data); @@ -251,8 +273,8 @@ class integrationModel extends model $build->createdDate = $now; $build->updateDate = $now; $this->dao->insert(TABLE_COMPILE)->data($build)->exec(); - $this->dao->update(TABLE_INTEGRATION)->set('lastExec')->eq($now)->set('lastStatus')->eq($build->status)->where('id')->eq($integration->id)->exec(); + $this->dao->update(TABLE_JOB)->set('lastExec')->eq($now)->set('lastStatus')->eq($build->status)->where('id')->eq($job->id)->exec(); - return !dao::isError(); + return $build->status; } } diff --git a/module/job/view/browse.html.php b/module/job/view/browse.html.php new file mode 100644 index 0000000000..b2c0e613e8 --- /dev/null +++ b/module/job/view/browse.html.php @@ -0,0 +1,68 @@ + + * @package job + * @version $Id$ + * @link http://www.zentao.net + */ +?> + + +
+
+ + + + recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?> + + + + + + + + + + + + $job):?> + + + + + jkJob) . '@' . $job->jenkinsName;?> + + job->getTriggerConfig($job);?> + + + + + + + +
job->id);?>job->name);?>job->repo);?>job->jenkins);?>job->triggerType;?>job->lastStatus);?>job->lastExec);?>actions;?>
name; ?>repoName; ?>lastStatus) echo zget($lang->compile->statusList, $job->lastStatus);?>lastStatus) echo $job->lastExec;?> + createLink('job', 'delete', "jobID=$id"), '', 'hiddenwin', "title='{$lang->job->delete}' class='btn'"); + ?> +
+ + + +
+
+ diff --git a/module/integration/view/create.html.php b/module/job/view/create.html.php similarity index 76% rename from module/integration/view/create.html.php rename to module/job/view/create.html.php index ed7d9830b4..d36b50d71e 100644 --- a/module/integration/view/create.html.php +++ b/module/job/view/create.html.php @@ -1,11 +1,11 @@ - * @package integration + * @package job * @version $Id$ * @link http://www.zentao.net */ @@ -14,33 +14,33 @@ -integration->dirChange);?> -integration->buildTag);?> +job->dirChange);?> +job->buildTag);?>
-

integration->create; ?>

+

job->create; ?>

- + - + - - + + - + - + - + @@ -59,19 +59,19 @@ - +
integration->name; ?>job->name; ?>
integration->repo; ?>job->repo; ?>
integration->triggerType; ?>integration->triggerTypeList, '', "class='form-control chosen'");?>job->triggerType; ?>job->triggerTypeList, '', "class='form-control chosen'");?>
integration->svnDir;?>job->svnDir;?>
''), '', "class='form-control chosen'");?> @@ -48,9 +48,9 @@
integration->comment;?>job->comment;?> integration->commitEx;?>job->commitEx;?>
- integration->atTime;?> + job->atTime;?>
integration->jkHost; ?>job->jkHost; ?>
- integration->jkJob; ?> + job->jkJob; ?> ''), '', "class='form-control chosen'"); ?>
diff --git a/module/integration/view/edit.html.php b/module/job/view/edit.html.php similarity index 79% rename from module/integration/view/edit.html.php rename to module/job/view/edit.html.php index 401ab084c7..984e267d04 100644 --- a/module/integration/view/edit.html.php +++ b/module/job/view/edit.html.php @@ -1,11 +1,11 @@ - * @package integration + * @package job * @version $Id$ * @link http://www.zentao.net */ @@ -15,35 +15,35 @@ triggerType);?> jkJob);?> -integration->dirChange);?> -integration->buildTag);?> +job->dirChange);?> +job->buildTag);?>
-

integration->edit; ?>

+

job->edit; ?>

- + - + - - integration->triggerTypeList['tag'] = $lang->integration->dirChange;?> - + + job->triggerTypeList['tag'] = $lang->job->dirChange;?> + - + - + - + @@ -82,19 +82,19 @@ - +
integration->name; ?>job->name; ?> name, "class='form-control'"); ?>
integration->repo; ?>job->repo; ?> repo, "class='form-control chosen'");?>
integration->triggerType; ?>integration->triggerTypeList, $job->triggerType, "class='form-control chosen'");?>job->triggerType; ?>job->triggerTypeList, $job->triggerType, "class='form-control chosen'");?>
integration->svnDir;?>job->svnDir;?>
integration->comment;?>job->comment;?> comment, "class='form-control'");?>integration->commitEx;?>job->commitEx;?>
- integration->atTime;?> + job->atTime;?> atTime, "class='form-control form-time'");?>
integration->jkHost; ?>job->jkHost; ?>
jkHost, "class='form-control chosen'");?>
- integration->jkJob; ?> + job->jkJob; ?> ''), $job->jkJob, "class='form-control chosen'");?>
diff --git a/module/svn/model.php b/module/svn/model.php index ca8f3e4adf..ae1e85c578 100644 --- a/module/svn/model.php +++ b/module/svn/model.php @@ -70,15 +70,15 @@ class svnModel extends model if(empty($this->repos)) return false; $this->loadModel('compile'); - /* Get commit triggerType integrations by repoIdList */ - $commitPlans = $this->loadModel('integration')->getListByTriggerType('commit', array_keys($this->repos)); + /* Get commit triggerType jobs by repoIdList */ + $commitJobs = $this->loadModel('job')->getListByTriggerType('commit', array_keys($this->repos)); $commitGroup = array(); - foreach($commitPlans as $integration) $commitGroup[$integration->repo][$integration->id] = $integration; + foreach($commitJobs as $job) $commitGroup[$job->repo][$job->id] = $job; - /* Get tag triggerType integrations by repoIdList */ - $tagPlans = $this->integration->getListByTriggerType('tag', array_keys($this->repos)); + /* Get tag triggerType jobs by repoIdList */ + $tagJobs = $this->job->getListByTriggerType('tag', array_keys($this->repos)); $tagGroup = array(); - foreach($tagPlans as $integration) $tagGroup[$integration->repo][$integration->id] = $integration; + foreach($tagJobs as $job) $tagGroup[$job->repo][$job->id] = $job; $_COOKIE['repoBranch'] = ''; foreach($this->repos as $repoID => $repo) @@ -118,12 +118,12 @@ class svnModel extends model } /* Create compile by comment. */ - $integrations = zget($commitGroup, $repoID, array()); - foreach($integrations as $integration) + $jobs = zget($commitGroup, $repoID, array()); + foreach($jobs as $job) { - foreach(explode(',', $integration->comment) as $comment) + foreach(explode(',', $job->comment) as $comment) { - if(strpos($log->msg, $comment) !== false) $this->compile->createByIntegration($integration->id); + if(strpos($log->msg, $comment) !== false) $this->compile->createByJob($job->id); } } @@ -136,17 +136,17 @@ class svnModel extends model } /* Create compile by tag. */ - $integrations = zget($tagGroup, $repoID, array()); - foreach($integrations as $integration) + $jobs = zget($tagGroup, $repoID, array()); + foreach($jobs as $job) { - $dirs = $this->getRepoTags($repo, $integration->svnDir); + $dirs = $this->getRepoTags($repo, $job->svnDir); end($dirs); $lastTag = current($dirs); - if($lastTag != $integration->lastTag) + if($lastTag != $job->lastTag) { - $tag = rtrim($repo->path , '/') . '/' . trim($integration->svnDir, '/') . '/' . $lastTag; - $this->compile->createByIntegration($integration->id, $tag, 'tag'); - $this->dao->update(TABLE_INTEGRATION)->set('lastTag')->eq($lastTag)->where('id')->eq($integration->id)->exec(); + $tag = rtrim($repo->path , '/') . '/' . trim($job->svnDir, '/') . '/' . $lastTag; + $this->compile->createByJob($job->id, $tag, 'tag'); + $this->dao->update(TABLE_JOB)->set('lastTag')->eq($lastTag)->where('id')->eq($job->id)->exec(); } } }