From 172a9724e2989246d04125063e66c6d3cc659afa Mon Sep 17 00:00:00 2001 From: wangyidong Date: Fri, 28 Feb 2020 15:05:56 +0800 Subject: [PATCH] * code for task #6912,6913,6914,6916. --- db/update12.0.1.sql | 11 +++ lib/base/filter/filter.class.php | 29 +++--- .../{parsegit.class.php => gitrepo.class.php} | 2 +- lib/scm/scm.class.php | 2 +- lib/scm/subversion.class.php | 3 +- module/ci/control.php | 6 +- module/ci/model.php | 8 +- module/common/lang/menuOrder.php | 2 +- module/common/lang/zh-cn.php | 2 +- module/compile/model.php | 12 +-- module/compile/view/browse.html.php | 2 +- module/integration/config.php | 4 +- module/integration/control.php | 16 ++-- module/integration/css/create.css | 3 + module/integration/css/edit.css | 3 + module/integration/js/create.js | 92 ++++++++---------- module/integration/js/edit.js | 95 ++++++++----------- module/integration/lang/en.php | 8 +- module/integration/lang/zh-cn.php | 16 ++-- module/integration/model.php | 43 ++++----- module/integration/view/browse.html.php | 11 ++- module/integration/view/create.html.php | 60 ++++++++---- module/integration/view/edit.html.php | 62 ++++++++---- module/jenkins/control.php | 2 + module/repo/control.php | 66 +++++-------- module/repo/view/create.html.php | 59 ------------ module/svn/config.php | 2 - module/webhook/control.php | 19 ++-- www/js/misc/highlight/export.html | 6 +- 29 files changed, 302 insertions(+), 344 deletions(-) rename lib/scm/{parsegit.class.php => gitrepo.class.php} (99%) diff --git a/db/update12.0.1.sql b/db/update12.0.1.sql index a4a24335ae..c45645a1f5 100644 --- a/db/update12.0.1.sql +++ b/db/update12.0.1.sql @@ -59,3 +59,14 @@ INSERT INTO `zt_cron` (`m`, `h`, `dom`, `mon`, `dow`, `command`, `remark`, `type ('1', '1', '*', '*', '*', 'moduleName=ci&methodName=buildTodayJob', '创建周期性任务', 'zentao', 1, 'normal', '0000-00-00 00:00:00'), ('*/5', '*', '*', '*', '*', 'moduleName=ci&methodName=checkBuildStatus', '同步Jenkins任务状态', 'zentao', 1, 'normal', '0000-00-00 00:00:00'), ('*/5', '*', '*', '*', '*', 'moduleName=ci&methodName=exec', '执行Jenkins任务', 'zentao', 1, 'normal', '0000-00-00 00:00:00'); + +ALTER TABLE `zt_integration` +CHANGE `jenkins` `jkHost` mediumint(8) unsigned NOT NULL AFTER `repo`, +CHANGE `jenkinsJob` `jkJob` varchar(500) COLLATE 'utf8_general_ci' NOT NULL AFTER `jkHost`, +CHANGE `svnFolder` `svnDir` varchar(255) COLLATE 'utf8_general_ci' NOT NULL AFTER `triggerType`, +CHANGE `scheduleDay` `atDay` varchar(20) COLLATE 'utf8_general_ci' NULL AFTER `svnDir`, +ADD `atTime` varchar(10) COLLATE 'utf8_general_ci' NULL AFTER `atDay`, +DROP `tagKeywords`, +DROP `commentKeywords`, +ADD `comment` varchar(255) COLLATE 'utf8_general_ci' NULL AFTER `atTime`, +ADD `lastTag` varchar(255) COLLATE 'utf8_general_ci' NULL; diff --git a/lib/base/filter/filter.class.php b/lib/base/filter/filter.class.php index 079235fb3c..62413638b6 100644 --- a/lib/base/filter/filter.class.php +++ b/lib/base/filter/filter.class.php @@ -1085,6 +1085,20 @@ class baseFixer return $data; } + /** + * 去除字符串左右空格 + * Remove the left and right Spaces of the string. + * + * @param string $fieldName + * @access public + * @return object fixer object + */ + public function trim($fieldName) + { + if(isset($this->data->$fieldName)) $this->data->$fieldName = trim($this->data->$fieldName); + return $this; + } + /** * 忽略处理给定的字段。 * Skip special chars check. @@ -1296,19 +1310,4 @@ class baseFixer foreach($fields as $key => $fieldName) if(!isset($this->data->$fieldName)) unset($fields[$key]); return $fields; } - - /** - * 去除字符串左右空格 - * Remove the left and right Spaces of the string. - * - * @param string $fieldName - * @access public - * @return object fixer object - */ - public function trim($fieldName) - { - if(isset($this->data->$fieldName)) $this->data->$fieldName = trim($this->data->$fieldName); - return $this; - } - } diff --git a/lib/scm/parsegit.class.php b/lib/scm/gitrepo.class.php similarity index 99% rename from lib/scm/parsegit.class.php rename to lib/scm/gitrepo.class.php index c0468db89a..2478569f16 100644 --- a/lib/scm/parsegit.class.php +++ b/lib/scm/gitrepo.class.php @@ -1,5 +1,5 @@ SCM; - if($className == 'Git') $className = 'ParseGit'; + if($className == 'Git') $className = 'GitRepo'; if(!class_exists($className)) require(strtolower($className) . '.class.php'); $this->engine = new $className($repo->client, $repo->path, $repo->account, $repo->password, $repo->encoding); } diff --git a/lib/scm/subversion.class.php b/lib/scm/subversion.class.php index 6c52fbf48b..aaa34a4f49 100644 --- a/lib/scm/subversion.class.php +++ b/lib/scm/subversion.class.php @@ -100,7 +100,8 @@ class Subversion foreach($infos as $info) { if($onlyDir and $info->kind != 'dir') continue; - $tags[$info->name] = $info->name; + $dirPath = $path . '/' . $info->name; + $tags[$dirPath] = $info->name; } return $tags; diff --git a/module/ci/control.php b/module/ci/control.php index d5a9f9b119..f3e0230c24 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -36,7 +36,7 @@ class ci extends control $this->loadModel('compile'); foreach($scheduleJobs as $job) { - if(strpos($job->scheduleDay, $week) !== false) $this->compile->createByIntegration($job->id); + if(strpos($job->atDay, $week) !== false) $this->compile->createByIntegration($job->id); } echo 'success'; } @@ -67,7 +67,7 @@ class ci extends control $scm = $repo->SCM == 'Git' ? 'git' : 'svn'; $savedTag = $this->loadModel($scm)->getSavedTag($repo->id); - $tags = $this->$scm->getRepoTags($repo, $scm == 'svn' ? $integration->svnFolder : ''); + $tags = $this->$scm->getRepoTags($repo, $scm == 'svn' ? $integration->svnDir : ''); if(!empty($tags)) { $arriveLastTag = false; @@ -86,7 +86,7 @@ class ci extends control elseif($scm == 'svn') { if(isset($savedTag[$tag])) continue; - $tag = rtrim($repo->path , '/') . '/' . trim($integration->svnFolder, '/') . '/' . $tag; + $tag = rtrim($repo->path , '/') . '/' . trim($integration->svnDir, '/') . '/' . $tag; } $tagData = new stdclass(); diff --git a/module/ci/model.php b/module/ci/model.php index 127d685dd5..d6c0623e10 100644 --- a/module/ci/model.php +++ b/module/ci/model.php @@ -31,10 +31,10 @@ class ciModel extends model */ public function checkBuildStatus() { - $compiles = $this->dao->select('t1.*, t2.jenkinsJob, t3.name jenkinsName,t3.serviceUrl,t3.account,t3.token,t3.password') + $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_JENKINS)->alias('t3')->on('t2.jenkins=t3.id') + ->leftJoin(TABLE_JENKINS)->alias('t3')->on('t2.jkHost=t3.id') ->where('t1.status')->ne('success') ->andWhere('t1.status')->ne('fail') ->andWhere('t1.status')->ne('timeout') @@ -55,13 +55,13 @@ class ciModel extends model if(strripos($response, "404") > -1) { /* Queue expired, use another api. */ - $infoUrl = sprintf('%s/job/%s/%s/api/json', $jenkinsServer, $compile->jenkinsJob, $compile->queueItem); + $infoUrl = sprintf('%s/job/%s/%s/api/json', $jenkinsServer, $compile->jkJob, $compile->queueItem); $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->jenkinsJob, $compile->queueItem); + $logUrl = sprintf('%s/job/%s/%s/consoleText', $jenkinsServer, $compile->jkJob, $compile->queueItem); $response = common::http($logUrl); $logs = json_decode($response); diff --git a/module/common/lang/menuOrder.php b/module/common/lang/menuOrder.php index a92c4942b0..0f4795e6a6 100644 --- a/module/common/lang/menuOrder.php +++ b/module/common/lang/menuOrder.php @@ -79,8 +79,8 @@ $lang->testreport->menuOrder = $lang->testcase->menuOrder; $lang->ci->menuOrder[5] = 'browse'; $lang->ci->menuOrder[10] = 'job'; -$lang->ci->menuOrder[15] = 'maintain'; $lang->ci->menuOrder[20] = 'jenkins'; +$lang->ci->menuOrder[15] = 'maintain'; $lang->ci->menuOrder[25] = 'match'; $lang->repo->menuOrder = $lang->ci->menuOrder; diff --git a/module/common/lang/zh-cn.php b/module/common/lang/zh-cn.php index 71e2229138..2595345871 100644 --- a/module/common/lang/zh-cn.php +++ b/module/common/lang/zh-cn.php @@ -336,8 +336,8 @@ $lang->ci = new stdclass(); $lang->ci->menu = new stdclass(); $lang->ci->menu->browse = array('link' =>'代码|repo|browse|repoID=%s', 'alias' => 'diff,view,revision,log,blame,showsynccomment'); $lang->ci->menu->job = array('link' =>'构建|integration|browse', 'subModule' => 'compile,integration'); -$lang->ci->menu->maintain = array('link' =>'版本库|repo|maintain', 'alias' => 'create,edit'); $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->match = array('link' =>'匹配设置|repo|setmatchcomment'); $lang->repo = new stdclass(); diff --git a/module/compile/model.php b/module/compile/model.php index adb7a1fca5..5d80cd9006 100644 --- a/module/compile/model.php +++ b/module/compile/model.php @@ -25,7 +25,7 @@ class compileModel extends model 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_REPO)->alias('t3')->on('t2.repo=t3.id') - ->leftJoin(TABLE_JENKINS)->alias('t4')->on('t2.jenkins=t4.id') + ->leftJoin(TABLE_JENKINS)->alias('t4')->on('t2.jkHost=t4.id') ->where('t1.deleted')->eq('0') ->andWhere('t1.cijob')->eq($jobID) ->orderBy($orderBy) @@ -85,9 +85,9 @@ 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.jenkinsJob,t2.name as jenkinsName,t2.serviceUrl,t2.account,t2.token,t2.password') + $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') ->from(TABLE_INTEGRATION)->alias('t1') - ->leftJoin(TABLE_JENKINS)->alias('t2')->on('t1.jenkins=t2.id') + ->leftJoin(TABLE_JENKINS)->alias('t2')->on('t1.jkHost=t2.id') ->where('t1.id')->eq($compile->cijob) ->fetch(); @@ -111,9 +111,9 @@ 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.jenkinsJob,t2.name as jenkinsName,t2.serviceUrl,t2.account,t2.token,t2.password') + $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') ->from(TABLE_INTEGRATION)->alias('t1') - ->leftJoin(TABLE_JENKINS)->alias('t2')->on('t1.jenkins=t2.id') + ->leftJoin(TABLE_JENKINS)->alias('t2')->on('t1.jkHost=t2.id') ->where('t1.id')->eq($integrationID) ->fetch(); @@ -147,7 +147,7 @@ class compileModel extends model $jenkinsAuth = '://' . $jenkinsUser . ':' . $jenkinsPassword . '@'; $jenkinsServer = str_replace('://', $jenkinsAuth, $jenkinsServer); - $buildUrl = sprintf('%s/job/%s/buildWithParameters/api/json', $jenkinsServer, $jenkins->jenkinsJob); + $buildUrl = sprintf('%s/job/%s/buildWithParameters/api/json', $jenkinsServer, $jenkins->jkJob); return $buildUrl; } } diff --git a/module/compile/view/browse.html.php b/module/compile/view/browse.html.php index d4e8477276..dcb0b3dcf0 100644 --- a/module/compile/view/browse.html.php +++ b/module/compile/view/browse.html.php @@ -29,7 +29,7 @@ compile->id);?> compile->name);?> integration->repo;?> - integration->jenkins;?> + integration->jkHost;?> integration->triggerType;?> compile->status);?> compile->time);?> diff --git a/module/integration/config.php b/module/integration/config.php index dd9ddf2640..1f185e342a 100644 --- a/module/integration/config.php +++ b/module/integration/config.php @@ -2,5 +2,5 @@ $config->integration = new stdclass(); $config->integration->create = new stdclass(); $config->integration->edit = new stdclass(); -$config->integration->create->requiredFields = 'name,repo,jenkins,jenkinsJob,triggerType'; -$config->integration->edit->requiredFields = 'name,repo,jenkins,jenkinsJob,triggerType'; +$config->integration->create->requiredFields = 'name,repo,jkHost,jkJob,triggerType'; +$config->integration->edit->requiredFields = 'name,repo,jkHost,jkJob,triggerType'; diff --git a/module/integration/control.php b/module/integration/control.php index 6eb3ca7c43..9db7b0dda7 100644 --- a/module/integration/control.php +++ b/module/integration/control.php @@ -81,9 +81,9 @@ class integration extends control $repoPairs[$repo->id] = $repo->name; $repoTypes[$repo->id] = $repo->SCM; } - $this->view->repoPairs = $repoPairs; - $this->view->repoTypes = $repoTypes; - $this->view->jenkinsList = $this->loadModel('jenkins')->getPairs(); + $this->view->repoPairs = $repoPairs; + $this->view->repoTypes = $repoTypes; + $this->view->jkHostList = $this->loadModel('jenkins')->getPairs(); $this->display(); } @@ -121,11 +121,11 @@ class integration extends control $repoTypes[$repo->id] = $repo->SCM; } - $this->view->repoPairs = $repoPairs; - $this->view->repoTypes = $repoTypes; - $this->view->job = $job; - $this->view->jenkinsList = $this->loadModel('jenkins')->getPairs(); - $this->view->jenkinsJobs = $this->jenkins->getTasks($job->jenkins); + $this->view->repoPairs = $repoPairs; + $this->view->repoTypes = $repoTypes; + $this->view->job = $job; + $this->view->jkHostList = $this->loadModel('jenkins')->getPairs(); + $this->view->jkJobs = $this->jenkins->getTasks($job->jkHost); $this->display(); } diff --git a/module/integration/css/create.css b/module/integration/css/create.css index f286553966..7c6b27bae7 100644 --- a/module/integration/css/create.css +++ b/module/integration/css/create.css @@ -2,3 +2,6 @@ .only-pick-time thead th, .only-pick-time tfoot th {color: transparent !important;} .checkbox-primary.checkbox-inline{display:inline-block !important;} .checkbox-primary.checkbox-inline label{padding-left:5px !important;} +#jkHost_chosen .chosen-single{border-right:0px;} +#jkJobBox{width:392px;} +#svnDirBox{width:392px;} diff --git a/module/integration/css/edit.css b/module/integration/css/edit.css index 5f526c2e30..52c6386abf 100644 --- a/module/integration/css/edit.css +++ b/module/integration/css/edit.css @@ -2,3 +2,6 @@ .only-pick-time thead th, .only-pick-time tfoot th {color: transparent !important;} .checkbox-primary.checkbox-inline{display:inline-block !important;} .checkbox-primary.checkbox-inline label{padding-left:5px !important;} +#jkHost_chosen .chosen-single{border-right:0px;} +#jkJobBox{width:392px;} +#svnDirBox{width:392px;} diff --git a/module/integration/js/create.js b/module/integration/js/create.js index 06b63e32f5..6c06bc430c 100644 --- a/module/integration/js/create.js +++ b/module/integration/js/create.js @@ -5,97 +5,79 @@ $('#repo').change(function() if(typeof(repoTypes[repoID]) != 'undefined') type = repoTypes[repoID]; $('.svn-fields').toggleClass('hidden', type != 'Subversion'); $('#repoType').val(type); + $('#triggerType option[value=tag]').html(type == 'Subversion' ? dirChange : buildTag).trigger('chosen:updated'); + $('#repo_chosen .chosen-single').attr('style', type == 'Subversion' ? 'border-right:0px' : ''); if(type == 'Subversion') { - $('#svnFolderBox').html("
"); - $.getJSON(createLink('repo', 'ajaxGetSVNTags', 'repoID=' + repoID), function(svnTags) + $('#svnDirBox #svnDir').remove(); + $('#svnDirBox #svnDir_chosen').remove(); + $('#svnDirBox .input-group').append("
"); + $.getJSON(createLink('repo', 'ajaxGetSVNDirs', 'repoID=' + repoID), function(tags) { - var tags = svnTags['tags']; - var parents = svnTags['parent']; - - html = ""; + for(path in tags) { - var info = parents[tag]; - html += ""; - } - - for(tag in tags) - { - var info = tags[tag]; - html += ""; + var encodePath = tags[path]; + html += ""; } html += ''; - $('#svnFolderBox').html(html); - $('#svnFolderBox #svnFolder').chosen(); + $('#svnDirBox .loading').remove(); + $('#svnDirBox .input-group').append(html); + $('#svnDirBox #svnDir').chosen(); }) } }) -$(document).on('change', '#svnFolder', function() +$(document).on('change', '#svnDir', function() { var repoID = $('#repo').val(); var selectedTag = $(this).val(); var encodePath = $(this).find("option:selected").attr('data-encodePath'); - $('#svnFolderBox').html("
"); - $.getJSON(createLink('repo', 'ajaxGetSVNTags', 'repoID=' + repoID + '&path=' + encodePath), function(svnTags) + $('#svnDirBox #svnDir').remove(); + $('#svnDirBox #svnDir_chosen').remove(); + $('#svnDirBox .input-group').append("
"); + $.getJSON(createLink('repo', 'ajaxGetSVNDirs', 'repoID=' + repoID + '&path=' + encodePath), function(tags) { - var tags = svnTags['tags']; - var parents = svnTags['parent']; - - html = ""; + for(path in tags) { - var info = parents[tag]; - html += ""; - } - - for(tag in tags) - { - var info = tags[tag]; - html += ""; + var encodePath = tags[path]; + html += ""; } html += ''; - $('#svnFolderBox').html(html); - $('#svnFolderBox #svnFolder').val(selectedTag).chosen(); + $('#svnDirBox .loading').remove(); + $('#svnDirBox .input-group').append(html); + $('#svnDirBox #svnDir').val(selectedTag).chosen(); }) }) $('#triggerType').change(function() { var type = $(this).val(); - if(type == 'tag') - { - $('.comment-fields').addClass('hidden'); - $('.custom-fields').addClass('hidden'); - } - else if(type == 'commit') - { - $('.comment-fields').removeClass('hidden'); - $('.custom-fields').addClass('hidden'); - } - else if(type == 'schedule') - { - $('.comment-fields').addClass('hidden'); - $('.custom-fields').removeClass('hidden'); - } + $('.comment-fields').addClass('hidden'); + $('.custom-fields').addClass('hidden'); + if(type == 'commit') $('.comment-fields').removeClass('hidden'); + if(type == 'schedule') $('.custom-fields').removeClass('hidden'); }); -$('#jenkins').change(function() +$('#jkHost').change(function() { var jenkinsID = $(this).val(); - $('#jenkinsJobBox').html("
"); + $('#jkJobBox #jkJob').remove(); + $('#jkJobBox #jkJob_chosen').remove(); + $('#jkJobBox .input-group').append("
"); $.getJSON(createLink('jenkins', 'ajaxGetTasks', 'jenkinsID=' + jenkinsID), function(tasks) { - html = ""; for(taskKey in tasks) { var task = tasks[taskKey]; html += ""; } html += ''; - $('#jenkinsJobBox').html(html); - $('#jenkinsJobBox #jenkinsJob').chosen(); + $('#jkJobBox .loading').remove(); + $('#jkJobBox .input-group').append(html); + $('#jkJobBox #jkJob').chosen(); }) }) diff --git a/module/integration/js/edit.js b/module/integration/js/edit.js index a772843d13..3732992e23 100644 --- a/module/integration/js/edit.js +++ b/module/integration/js/edit.js @@ -5,105 +5,88 @@ $('#repo').change(function() if(typeof(repoTypes[repoID]) != 'undefined') type = repoTypes[repoID]; $('.svn-fields').toggleClass('hidden', type != 'Subversion'); $('#repoType').val(type); + $('#triggerType option[value=tag]').html(type == 'Subversion' ? dirChange : buildTag).trigger('chosen:updated'); + $('#repo_chosen .chosen-single').attr('style', type == 'Subversion' ? 'border-right:0px' : ''); if(type == 'Subversion') { - $('#svnFolderBox').html("
"); + $('#svnDirBox #svnDir').remove(); + $('#svnDirBox #svnDir_chosen').remove(); + $('#svnDirBox .input-group').append("
"); var params = 'repoID=' + repoID; - if(jobRepo == repoID) params = 'repoID=' + repoID + '&path=' + encodeSVNFolder; - $.getJSON(createLink('repo', 'ajaxGetSVNTags', params), function(svnTags) + if(jobRepo == repoID) params = 'repoID=' + repoID + '&path=' + encodeSVNDir; + $.getJSON(createLink('repo', 'ajaxGetSVNDirs', params), function(tags) { - var tags = svnTags['tags']; - var parents = svnTags['parent']; - - html = ""; + for(path in tags) { - var info = parents[tag]; - html += ""; - } - - for(tag in tags) - { - var info = tags[tag]; - html += ""; + var encodePath = tags[path]; + html += ""; } html += ''; - $('#svnFolderBox').html(html); - $('#svnFolderBox #svnFolder').val(svnFolder).chosen(); + $('#svnDirBox .loading').remove(); + $('#svnDirBox .input-group').append(html); + $('#svnDirBox #svnDir').val(svnDir).chosen(); }) } }) -$(document).on('change', '#svnFolder', function() +$(document).on('change', '#svnDir', function() { var repoID = $('#repo').val(); var selectedTag = $(this).val(); var encodePath = $(this).find("option:selected").attr('data-encodePath'); - $('#svnFolderBox').html("
"); - $.getJSON(createLink('repo', 'ajaxGetSVNTags', 'repoID=' + repoID + '&path=' + encodePath), function(svnTags) + $('#svnDirBox #svnDir').remove(); + $('#svnDirBox #svnDir_chosen').remove(); + $('#svnDirBox .input-group').append("
"); + $.getJSON(createLink('repo', 'ajaxGetSVNDirs', 'repoID=' + repoID + '&path=' + encodePath), function(tags) { - var tags = svnTags['tags']; - var parents = svnTags['parent']; - - html = ""; + for(path in tags) { - var info = parents[tag]; - html += ""; - } - - for(tag in tags) - { - var info = tags[tag]; - html += ""; + var encodePath = tags[path]; + html += ""; } html += ''; - $('#svnFolderBox').html(html); - $('#svnFolderBox #svnFolder').val(selectedTag).chosen(); + $('#svnDirBox .loading').remove(); + $('#svnDirBox .input-group').append(html); + $('#svnDirBox #svnDir').val(selectedTag).chosen(); }) }) $('#triggerType').change(function() { var type = $(this).val(); - if(type == 'tag') - { - $('.comment-fields').addClass('hidden'); - $('.custom-fields').addClass('hidden'); - } - else if(type == 'commit') - { - $('.comment-fields').removeClass('hidden'); - $('.custom-fields').addClass('hidden'); - } - else if(type == 'schedule') - { - $('.comment-fields').addClass('hidden'); - $('.custom-fields').removeClass('hidden'); - } + $('.comment-fields').addClass('hidden'); + $('.custom-fields').addClass('hidden'); + if(type == 'commit') $('.comment-fields').removeClass('hidden'); + if(type == 'schedule') $('.custom-fields').removeClass('hidden'); }); -$('#jenkins').change(function() +$('#jkHost').change(function() { var jenkinsID = $(this).val(); - $('#jenkinsJobBox').html("
"); + $('#jkJobBox #jkJob').remove(); + $('#jkJobBox #jkJob_chosen').remove(); + $('#jkJobBox .input-group').append("
"); $.getJSON(createLink('jenkins', 'ajaxGetTasks', 'jenkinsID=' + jenkinsID), function(tasks) { - html = ""; for(taskKey in tasks) { var task = tasks[taskKey]; html += ""; } html += ''; - $('#jenkinsJobBox').html(html); - $('#jenkinsJobBox #jenkinsJob').chosen(); + $('#jkJobBox .loading').remove(); + $('#jkJobBox .input-group').append(html); + $('#jkJobBox #jkJob').val(jkJob).chosen(); }) }) $(function() { $('#repo').change(); + $('#jkHost').change(); $('#triggerType').change(); }); diff --git a/module/integration/lang/en.php b/module/integration/lang/en.php index 148eb157e0..9b9ade6ab9 100644 --- a/module/integration/lang/en.php +++ b/module/integration/lang/en.php @@ -9,12 +9,12 @@ $lang->integration->confirmDelete = 'Do you want to delete this Build?'; $lang->integration->id = 'ID'; $lang->integration->name = 'Name'; $lang->integration->repo = 'Repo'; -$lang->integration->svnFolder = 'SVN Tag Watch Path'; -$lang->integration->jenkins = 'Jenkins Server'; +$lang->integration->svnDir = 'SVN Tag Watch Path'; +$lang->integration->jkHost = 'Jenkins Server'; $lang->integration->buildType = 'Build Type'; -$lang->integration->jenkinsJob = 'Jenkins Task'; +$lang->integration->jkJob = 'Jenkins Task'; $lang->integration->triggerType = 'Trigger'; -$lang->integration->scheduleDay = 'Custom Days'; +$lang->integration->atDay = 'Custom Days'; $lang->integration->lastExec = 'Last Executed'; $lang->integration->example = 'e.g.'; diff --git a/module/integration/lang/zh-cn.php b/module/integration/lang/zh-cn.php index dc327991d9..40436d5705 100644 --- a/module/integration/lang/zh-cn.php +++ b/module/integration/lang/zh-cn.php @@ -7,20 +7,24 @@ $lang->integration->edit = '编辑构建任务'; $lang->integration->execNow = '立即执行'; $lang->integration->delete = '删除构建任务'; $lang->integration->confirmDelete = '确认删除该构建任务吗?'; +$lang->integration->dirChange = '目录改动'; +$lang->integration->buildTag = '打标签'; $lang->integration->id = 'ID'; $lang->integration->name = '名称'; $lang->integration->repo = '代码库'; -$lang->integration->svnFolder = 'SVN Tag监控路径'; -$lang->integration->jenkins = 'Jenkins服务'; +$lang->integration->svnDir = 'SVN Tag监控路径'; +$lang->integration->jkHost = 'Jenkins服务'; $lang->integration->buildType = '构建类型'; -$lang->integration->jenkinsJob = 'Jenkins任务名'; +$lang->integration->jkJob = 'Jenkins任务名'; $lang->integration->triggerType = '触发方式'; -$lang->integration->scheduleDay = '自定义天数'; +$lang->integration->atDay = '自定义日期'; +$lang->integration->atTime = '执行时间'; $lang->integration->lastExec = '最后执行'; +$lang->integration->comment = '匹配关键字'; $lang->integration->example = '举例'; -$lang->integration->commitEx = '%build% %integration% %id%15,其中15为Jenkins任务编号'; +$lang->integration->commitEx = "用于匹配创建构建任务的关键字,多个关键字用','分割"; $lang->integration->cronSample = '如 0 0 2 * * 2-6/1 表示每个工作日凌晨2点'; $lang->integration->sendExec = '发送执行请求成功!'; @@ -29,5 +33,5 @@ $lang->integration->buildTypeList['buildAndDeploy'] = '构建部署'; $lang->integration->buildTypeList['buildAndTest'] = '构建测试'; $lang->integration->triggerTypeList['tag'] = '打标签'; -$lang->integration->triggerTypeList['commit'] = '代码提交注释'; +$lang->integration->triggerTypeList['commit'] = '提交注释包含关键字'; $lang->integration->triggerTypeList['schedule'] = '定时计划'; diff --git a/module/integration/model.php b/module/integration/model.php index 1f446e07d2..6b5e54fbe3 100644 --- a/module/integration/model.php +++ b/module/integration/model.php @@ -35,7 +35,7 @@ class integrationModel extends model { return $this->dao->select('t1.*, t2.name as repoName, t3.name as jenkinsName')->from(TABLE_INTEGRATION)->alias('t1') ->leftJoin(TABLE_REPO)->alias('t2')->on('t1.repo=t2.id') - ->leftJoin(TABLE_JENKINS)->alias('t3')->on('t1.jenkins=t3.id') + ->leftJoin(TABLE_JENKINS)->alias('t3')->on('t1.jkHost=t3.id') ->where('t1.deleted')->eq('0') ->orderBy($orderBy) ->page($pager) @@ -66,30 +66,26 @@ class integrationModel extends model public function create() { $integration = 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') - { - if(!isset($integration->scheduleDay)) $integration->scheduleDay = array(); - $integration->scheduleDay = join(',', $integration->scheduleDay); - } - else - { - $integration->scheduleDay = ''; - } + if($integration->triggerType == 'schedule') $integration->atDay = empty($_POST['atDay']) ? '' : join(',', $this->post->atDay); $this->dao->insert(TABLE_INTEGRATION)->data($integration) ->batchCheck($this->config->integration->create->requiredFields, 'notempty') - ->batchCheckIF($integration->triggerType === 'schedule', "scheduleDay", 'notempty') - ->batchCheckIF($this->post->repoType == 'Subversion', "svnFolder", 'notempty') + ->batchCheckIF($integration->triggerType === 'schedule', "atDay,atTime", 'notempty') + ->batchCheckIF($integration->triggerType === 'commit', "comment", 'notempty') + ->batchCheckIF($this->post->repoType == 'Subversion', "svnDir", 'notempty') ->autoCheck() ->exec(); - if($integration->triggerType == 'schedule' and strpos($integration->scheduleDay, date('w')) !== false) $this->loadModel('compile')->createByIntegration($integration->id); + $id = $this->dao->lastInsertId(); + if($integration->triggerType == 'schedule' and strpos($integration->atDay, date('w')) !== false) $this->loadModel('compile')->createByIntegration($id); return true; } @@ -104,25 +100,20 @@ class integrationModel extends model { $oldIntegration = $this->getById($id); $integration = fixer::input('post') + ->setDefault('atDay', '') + ->setIF($this->post->repoType != 'Subversion', 'svnDir', '') ->add('editedBy', $this->app->user->account) ->add('editedDate', helper::now()) ->remove('repoType') ->get(); - if($integration->triggerType == 'schedule') - { - if(!isset($integration->scheduleDay)) $integration->scheduleDay = array(); - $integration->scheduleDay = join(',', $integration->scheduleDay); - } - else - { - $integration->scheduleDay = ''; - } + if($integration->triggerType == 'schedule') $integration->atDay = empty($_POST['atDay']) ? '' : join(',', $this->post->atDay); $this->dao->update(TABLE_INTEGRATION)->data($integration) ->batchCheck($this->config->integration->edit->requiredFields, 'notempty') - ->batchCheckIF($integration->triggerType === 'schedule', "scheduleDay", 'notempty') - ->batchCheckIF($this->post->repoType == 'Subversion', "svnFolder", 'notempty') + ->batchCheckIF($integration->triggerType === 'schedule', "atDay,atTime", 'notempty') + ->batchCheckIF($integration->triggerType === 'commit', "comment", 'notempty') + ->batchCheckIF($this->post->repoType == 'Subversion', "svnDir", 'notempty') ->autoCheck() ->where('id')->eq($id) @@ -131,9 +122,9 @@ class integrationModel extends model if($integration->triggerType == 'schedule') { $week = date('w'); - if($integration->triggerType != $oldIntegration->triggerType or strpos($oldIntegration->scheduleDay, $week) === false) + if($integration->triggerType != $oldIntegration->triggerType or strpos($oldIntegration->atDay, $week) === false) { - if(strpos($integration->scheduleDay, $week) !== false) $this->loadModel('compile')->createByIntegration($integration->id); + if(strpos($integration->atDay, $week) !== false) $this->loadModel('compile')->createByIntegration($integration->id); } } return true; diff --git a/module/integration/view/browse.html.php b/module/integration/view/browse.html.php index 81e3381211..431189be80 100644 --- a/module/integration/view/browse.html.php +++ b/module/integration/view/browse.html.php @@ -29,8 +29,8 @@ integration->name);?> integration->repo);?> integration->triggerType;?> - integration->jenkins);?> - integration->jenkinsJob;?> + integration->jkHost);?> + integration->jkJob;?> integration->lastExec;?> actions;?> @@ -41,10 +41,13 @@ name; ?> repoName; ?> - integration->triggerTypeList, $job->triggerType);?> + integration->triggerTypeList, $job->triggerType); + if($job->triggerType == 'tag' and !empty($job->svnDir)) $triggerType = $lang->integration->dirChange; + ?> jenkinsName; ?> - jenkinsJob);?> + jkJob);?> lastStatus) echo zget($lang->compile->statusList, $job->lastStatus) . $lang->ci->at . $job->lastExec;?> - - + + +integration->dirChange);?> +integration->buildTag);?>
@@ -30,29 +32,53 @@ integration->repo; ?> - - integration->svnFolder; ?> - - - - integration->jenkins; ?> - - integration->jenkinsJob; ?> - ''), '', "class='form-control chosen'"); ?> + +
+
+
+ +
+
+ integration->triggerType; ?> integration->triggerTypeList, '', "class='form-control chosen'");?> - - integration->example; ?> - repo->matchComment)) $config->repo->matchComment = json_decode($config->repo->matchComment, true);?> - repo->matchComment['integration']['start'], $config->repo->matchComment['module']['integration'], $config->repo->matchComment['id']['mark']), $lang->integration->commitEx);?> + + integration->comment;?> + + integration->commitEx;?> - integration->scheduleDay; ?> - datepicker->dayNames, '', '', 'inline');?> + + datepicker->dayNames, '', '', 'inline');?> + + + +
+ integration->atTime;?> + +
+ + + + integration->jkHost; ?> + +
+
+
+
+ integration->jkJob; ?> + ''), '', "class='form-control chosen'"); ?> +
+
+
+ diff --git a/module/integration/view/edit.html.php b/module/integration/view/edit.html.php index f75dd42000..031324428f 100644 --- a/module/integration/view/edit.html.php +++ b/module/integration/view/edit.html.php @@ -15,9 +15,11 @@ triggerType);?> repo);?> -svnFolder);?> -loadModel('repo')->encodePath($job->svnFolder));?> -jenkinsJob);?> +svnDir);?> +loadModel('repo')->encodePath($job->svnDir));?> +jkJob);?> +integration->dirChange);?> +integration->buildTag);?>
@@ -34,29 +36,53 @@ integration->repo; ?> - repo, "class='form-control chosen'"); ?> - integration->svnFolder; ?> - - - - integration->jenkins; ?> - jenkins, "class='form-control chosen'"); ?> - integration->jenkinsJob; ?> - jenkinsJob, "class='form-control chosen'");?> + +
+
repo, "class='form-control chosen'");?>
+
+ +
+
+ integration->triggerType; ?> - integration->triggerTypeList, $job->triggerType, "class='form-control chosen'"); ?> + integration->triggerTypeList, $job->triggerType, "class='form-control chosen'");?> - integration->example; ?> - repo->matchComment)) $config->repo->matchComment = json_decode($config->repo->matchComment, true);?> - repo->matchComment['integration']['start'], $config->repo->matchComment['module']['integration'], $config->repo->matchComment['id']['mark']), $lang->integration->commitEx);?> + integration->comment;?> + + integration->commitEx;?> - integration->scheduleDay;?> - datepicker->dayNames, $job->scheduleDay, '', 'inline');?> + + datepicker->dayNames, $job->atDay, '', 'inline');?> + + + +
+ integration->atTime;?> + atTime, "class='form-control form-time'");?> +
+ + + + integration->jkHost; ?> + +
+
jkHost, "class='form-control chosen'");?>
+
+
+ integration->jkJob; ?> + ''), $job->jkJob, "class='form-control chosen'");?> +
+
+
+ diff --git a/module/jenkins/control.php b/module/jenkins/control.php index 9771be1d3b..79fad57eb3 100644 --- a/module/jenkins/control.php +++ b/module/jenkins/control.php @@ -127,6 +127,8 @@ class jenkins extends control */ public function ajaxGetTasks($id) { + if(empty($id)) die(json_encode(array('' => ''))); + $tasks = $this->jenkins->getTasks($id); die(json_encode($tasks)); } diff --git a/module/repo/control.php b/module/repo/control.php index 4e368fffc6..d5ae319317 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -769,61 +769,47 @@ class repo extends control * * @param int $repoID * @param string $path - * @param string $revision * @access public * @return void */ - public function ajaxGetSVNTags($repoID, $path = '', $revision = 'HEAD') + public function ajaxGetSVNDirs($repoID, $path = '') { - if($this->get->path) $entry = $this->get->path; $repo = $this->repo->getRepoByID($repoID); if($repo->SCM != 'Subversion') die(json_encode(array())); - $this->scm->setEngine($repo); $path = $this->repo->decodePath($path); - $tags = $this->scm->tags($path, $revision); + if(empty($path) and empty($repo->prefix)) $path = '/'; - $parentInfos = array(); - $parentPath = ''; - - $info = array(); - $info['path'] = '/'; - $info['url'] = $repo->path . $info['path']; - $info['encodePath'] = $this->repo->encodePath($info['path']); - $parentInfos['/'] = $info; - - foreach(explode('/', $path) as $parent) + $dirs['/'] = ''; + $parent = ''; + foreach(explode('/', $path) as $subPath) { - if(empty($parent)) continue; - $parentPath .= '/' . $parent; - - $info = array(); - $info['path'] = $parentPath; - $info['url'] = $repo->path . $info['path']; - - $info['encodePath'] = $this->repo->encodePath($info['path']); - - $parentInfos[$parent] = $info; + if(empty($subPath)) continue; + $parent .= '/' . $subPath; + $dirs[$parent] = $this->repo->encodePath($parent); } - $tagInfos = array(); - foreach($tags as $tag) + $parent = '/'; + if($repo->prefix) $parent = rtrim($repo->prefix, '/'); + if(trim($path, '/')) $parent = rtrim($repo->prefix, '/') . '/' . trim($path, '/'); + $stmt = $this->dao->select('t1.*,t2.revision as svnRevision,t2.time')->from(TABLE_REPOFILES)->alias('t1') + ->leftJoin(TABLE_REPOHISTORY)->alias('t2')->on('t1.revision = t2.id') + ->where('t1.repo')->eq($repoID) + ->andWhere('t1.type')->eq('dir') + ->andWhere('t1.parent')->eq($parent) + ->orderBy('path,svnRevision,time') + ->query(); + + while($row = $stmt->fetch()) { - $info = array(); - $info['path'] = '/'; - if($path) $info['path'] .= $path . '/'; - $info['path'] .= $tag; - $info['url'] = $repo->path . $info['path']; + $path = $row->path; + if($repo->prefix) $path = str_replace($repo->prefix, '', $path); + if(empty($path)) $path = '/'; - $info['encodePath'] = $this->repo->encodePath($info['path']); - - $tagInfos[$tag] = $info; + $dirs[$path] = $this->repo->encodePath($path); + if($row->action == 'D') unset($dirs[$path]); } - $svnTags = array(); - $svnTags['parent'] = $parentInfos; - $svnTags['tags'] = $tagInfos; - - die(json_encode($svnTags)); + die(json_encode($dirs)); } } diff --git a/module/repo/view/create.html.php b/module/repo/view/create.html.php index 5907f079fa..161f8f4755 100644 --- a/module/repo/view/create.html.php +++ b/module/repo/view/create.html.php @@ -92,65 +92,6 @@
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
repo->SCM;?>repo->scmList, 'Subversion', "class='form-control'");?>
repo->name;?>
repo->path;?>repo->example->path;?>
repo->encoding;?>
repo->client;?>repo->example->client;?>
repo->account;?>
repo->password;?> -
- - - repo->encryptList, 'base64', "class='form-control'");?> -
-
repo->acl;?> -
- repo->group?> - -
-
- repo->user?> - -
-
- - -
-
diff --git a/module/svn/config.php b/module/svn/config.php index ee4fdfa852..69f910ce48 100644 --- a/module/svn/config.php +++ b/module/svn/config.php @@ -16,8 +16,6 @@ * */ -$config->svn->tagRequiredFields = 'name,repo'; - /* will use the config of repo records in db $config->svn = new stdClass(); $config->svn->encodings = 'utf-8'; diff --git a/module/webhook/control.php b/module/webhook/control.php index f996bb7616..1c3107d27a 100644 --- a/module/webhook/control.php +++ b/module/webhook/control.php @@ -83,7 +83,6 @@ class webhook extends control */ public function edit($id) { - $webhook = $this->webhook->getByID($id); if($_POST) { $this->webhook->update($id); @@ -91,14 +90,16 @@ class webhook extends control $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); } - $this->app->loadLang('action'); - $this->view->title = $this->lang->webhook->edit . $this->lang->colon . $webhook->name; - $this->view->products = $this->loadModel('product')->getPairs(); - $this->view->projects = $this->loadModel('project')->getPairs(); - $this->view->position[] = html::a(inlink('browse'), $this->lang->webhook->api); - $this->view->position[] = html::a(inlink('browse'), $this->lang->webhook->common); - $this->view->position[] = $this->lang->webhook->edit; - $this->view->webhook = $webhook; + $webhook = $this->webhook->getByID($id); + + $this->view->title = $this->lang->webhook->edit . $this->lang->colon . $webhook->name; + $this->view->position[] = html::a(inlink('browse'), $this->lang->webhook->api); + $this->view->position[] = html::a(inlink('browse'), $this->lang->webhook->common); + $this->view->position[] = $this->lang->webhook->edit; + + $this->view->products = $this->loadModel('product')->getPairs(); + $this->view->projects = $this->loadModel('project')->getPairs(); + $this->view->webhook = $webhook; $this->display(); } diff --git a/www/js/misc/highlight/export.html b/www/js/misc/highlight/export.html index 5512354a7b..86ac892848 100755 --- a/www/js/misc/highlight/export.html +++ b/www/js/misc/highlight/export.html @@ -42,11 +42,9 @@ Copyright (c) Vladimir Gubarkov } function copyToBuffer(textToCopy) { - if (window.clipboardData) - { // IE + if (window.clipboardData) { // IE window.clipboardData.setData("Text", textToCopy); - } else if (window.netscape) - { // FF + } else if (window.netscape) { // FF // from http://developer.mozilla.org/en/docs/Using_the_Clipboard netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); var gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);