diff --git a/db/zentao.sql b/db/zentao.sql index da2f2bbf50..271011a187 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -664,6 +664,10 @@ CREATE TABLE IF NOT EXISTS `zt_mr` ( `status` char(30) NOT NULL, `mergeStatus` char(30) NOT NULL, `approvalStatus` char(30) NOT NULL, + `repoID` mediumint(8) unsigned NOT NULL, + `jobID` mediumint(8) unsigned NOT NULL, + `compileID` mediumint(8) unsigned NOT NULL, + `compileStatus` char(30) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- DROP TABLE IF NOT EXISTS `zt_mrapproval`; diff --git a/module/compile/model.php b/module/compile/model.php index ce3a4b538b..a6633e868a 100644 --- a/module/compile/model.php +++ b/module/compile/model.php @@ -45,6 +45,22 @@ class compileModel extends model ->page($pager) ->fetchAll('id'); } + + /** + * Get list by jobID. + * + * @param int $jobID + * @return array + */ + public function getListByJobID($jobID) + { + return $this->dao->select('id, name, status')->from(TABLE_COMPILE) + ->where('deleted')->eq('0') + ->andWhere('job')->ne('0') + ->beginIF(!empty($jobID))->andWhere('job')->eq($jobID)->fi() + ->orderBy('id_desc') + ->fetchAll('id'); + } /** * Get unexecuted list. diff --git a/module/job/model.php b/module/job/model.php index ecd520b333..ffb55b7803 100644 --- a/module/job/model.php +++ b/module/job/model.php @@ -50,7 +50,23 @@ class jobModel extends model ->fetchAll('id'); } - /** + /** + * Get job list by RepoID. + * + * @param int $repoID + * @access public + * @return array + */ + public function getListByRepoID($repoID) + { + return $this->dao->select('id, name, lastStatus')->from(TABLE_JOB) + ->where('deleted')->eq('0') + ->andWhere('repo')->eq($repoID) + ->orderBy('id_desc') + ->fetchAll('id'); + } + + /** * Get list by triggerType field. * * @param string $triggerType diff --git a/module/mr/config.php b/module/mr/config.php index 3052f040a8..3d38ccd826 100644 --- a/module/mr/config.php +++ b/module/mr/config.php @@ -2,7 +2,7 @@ $config->mr = new stdclass(); $config->mr->create = new stdclass(); -$config->mr->create->skippedFields = 'projectID'; +$config->mr->create->skippedFields = 'projectID,repo,job,compile'; $config->mr->create->requiredFields = 'gitlabID,sourceProject,sourceBranch,targetProject,targetBranch,title'; $config->mr->edit = new stdclass; diff --git a/module/mr/control.php b/module/mr/control.php index 8879746012..888867b042 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -66,7 +66,10 @@ class mr extends control return $this->send($result); } + $this->app->loadLang('repo'); /* Import lang in repo module. */ + $this->app->loadLang('compile'); $this->view->title = $this->lang->mr->create; + $this->view->jobList = $this->loadModel('job')->getList(); $this->view->gitlabHosts = $this->loadModel('gitlab')->getPairs(); $this->display(); } @@ -219,46 +222,6 @@ class mr extends control return $this->send(array('result' => 'fail', 'message' => $this->lang->mr->mergeFailed, 'locate' => helper::createLink('mr', 'view', "mr={$MRID}"))); } - /** - * AJAX: Get MR target projects. - * - * @param int $gitlabID - * @param int $projectID - * @access public - * @return void - */ - public function ajaxGetMRTargetProjects($gitlabID, $projectID) - { - $this->loadModel('gitlab'); - - /* First step: get forks. Only get first level forks(not recursively). */ - $projects = $this->gitlab->apiGetForks($gitlabID, $projectID); - - /* Second step: get project itself. */ - $projects[] = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); - - /* Last step: find its upstream recursively. */ - $project = $this->gitlab->apiGetUpstream($gitlabID, $projectID); - if(!empty($project)) $projects[] = $project; - - while(!empty($project) and isset($project->id)) - { - $project = $this->gitlab->apiGetUpstream($gitlabID, $project->id); - if(empty($project)) break; - $projects[] = $project; - } - - if(!$projects) return $this->send(array('message' => array())); - - $options = ""; - foreach($projects as $project) - { - $options .= ""; - } - - $this->send($options); - } - /** * View diff between MR source and target branches. * @@ -374,4 +337,96 @@ class mr extends control $MR = $this->mr->getByID($MRID); return $this->send($this->mr->reopen($MR)); } + + /** + * AJAX: Get MR target projects. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ + public function ajaxGetMRTargetProjects($gitlabID, $projectID) + { + $this->loadModel('gitlab'); + + /* First step: get forks. Only get first level forks(not recursively). */ + $projects = $this->gitlab->apiGetForks($gitlabID, $projectID); + + /* Second step: get project itself. */ + $projects[] = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); + + /* Last step: find its upstream recursively. */ + $project = $this->gitlab->apiGetUpstream($gitlabID, $projectID); + if(!empty($project)) $projects[] = $project; + + while(!empty($project) and isset($project->id)) + { + $project = $this->gitlab->apiGetUpstream($gitlabID, $project->id); + if(empty($project)) break; + $projects[] = $project; + } + + if(!$projects) return $this->send(array('message' => array())); + + $options = ""; + foreach($projects as $project) + { + $options .= ""; + } + + $this->send($options); + } + + /** + * AJAX: Get repo list. + * + * @param int $gitlabID + * @param int $projectID + * @return void + */ + public function ajaxGetRepoList($gitlabID, $projectID) + { + $this->loadModel('repo'); + $repoList = $this->repo->getGitLabRepoList($gitlabID, $projectID); + + if(!$repoList) return $this->send(array('message' => array())); + $options = ""; + foreach($repoList as $repo) $options .= ""; + $this->send($options); + } + + /** + * AJAX: Get job list. + * + * @param int $repoID + * @return void + */ + public function ajaxGetJobList($repoID) + { + $this->loadModel('job'); + $jobList = $this->job->getListByRepoID($repoID); + + if(!$jobList) return $this->send(array('message' => array())); + $options = ""; + foreach($jobList as $job) $options .= ""; + $this->send($options); + } + + /** + * AJAX: Get compile list. + * + * @param int $jobID + * @return void + */ + public function ajaxGetCompileList($jobID) + { + $this->loadModel('compile'); + $compileList = $this->compile->getListByJobID($jobID); + + if(!$compileList) return $this->send(array('message' => array())); + $options = ""; + foreach($compileList as $compile) $options .= ""; + $this->send($options); + } } diff --git a/module/mr/js/create.js b/module/mr/js/create.js index 2194a15d88..5314ad3f82 100644 --- a/module/mr/js/create.js +++ b/module/mr/js/create.js @@ -35,6 +35,13 @@ $(function() $('#targetProject').html('').append(response); $('#targetProject').chosen().trigger("chosen:updated");; }); + + repoUrl = createLink('mr', 'ajaxGetRepoList', "gitlabID=" + gitlabID + "&projectID=" + sourceProject); + $.get(repoUrl, function(response) + { + $('#repo').html('').append(response); + $('#repo').chosen().trigger("chosen:updated");; + }); }); $('#targetProject').change(function() @@ -52,5 +59,26 @@ $(function() }); }); + $('#repo').change(function() + { + repoID = $(this).val(); + jobUrl = createLink('mr', 'ajaxGetJobList', "repoID=" + repoID); + $.get(jobUrl, function(response) + { + $('#job').html('').append(response); + $('#job').chosen().trigger("chosen:updated");; + }); + }); + + $('#job').change(function() + { + jobID = $(this).val(); + compileUrl = createLink('mr', 'ajaxGetCompileList', "job=" + jobID); + $.get(compileUrl, function(response) + { + $('#compile').html('').append(response); + $('#compile').chosen().trigger("chosen:updated");; + }); + }); }); diff --git a/module/mr/model.php b/module/mr/model.php index 76776302ef..fa4afccc88 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -85,10 +85,29 @@ class mrModel extends model */ public function create() { - $MR = fixer::input('post') - ->add('createdBy', $this->app->user->account) - ->add('createdDate', helper::now()) - ->get(); + if (!empty($_POST['compile'])) + { + $repoID = $this->post->repo; + $jobID = $this->post->job; + $compileID = $this->post->compile; + $compileStatus = $this->loadModel('compile')->getByID($this->post->compile)->status; + + $MR = fixer::input('post') + ->add('createdBy', $this->app->user->account) + ->add('createdDate', helper::now()) + ->add('repoID', $repoID) + ->add('jobID', $jobID) + ->add('compileID', $compileID) + ->add('compileStatus', $compileStatus) + ->get(); + } + else + { + $MR = fixer::input('post') + ->add('createdBy', $this->app->user->account) + ->add('createdDate', helper::now()) + ->get(); + } $this->dao->insert(TABLE_MR)->data($MR, $this->config->mr->create->skippedFields) ->batchCheck($this->config->mr->create->requiredFields, 'notempty') @@ -719,6 +738,4 @@ class mrModel extends model if(isset($rawMR->state) and $rawMR->state == 'opened') return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => helper::createLink('mr', 'view', "mr={$MR->id}")); return array('result' => 'fail', 'message' => $this->lang->fail, 'locate' => helper::createLink('mr', 'view', "mr={$MR->id}")); } - } - diff --git a/module/mr/view/create.html.php b/module/mr/view/create.html.php index 8326fe50a7..10aff8735d 100644 --- a/module/mr/view/create.html.php +++ b/module/mr/view/create.html.php @@ -50,6 +50,18 @@