diff --git a/db/update16.0.beta1.sql b/db/update16.0.beta1.sql index 001bf88948..e71d9d859d 100644 --- a/db/update16.0.beta1.sql +++ b/db/update16.0.beta1.sql @@ -121,6 +121,7 @@ ALTER TABLE `zt_mr` ADD `synced` enum('0','1') COLLATE 'utf8_general_ci' NOT NUL ALTER TABLE `zt_mr` ADD `hasNoConflict` enum('0','1') COLLATE 'utf8_general_ci' NOT NULL DEFAULT '0'; ALTER TABLE `zt_mr` ADD `diffs` longtext COLLATE 'utf8_general_ci' NULL AFTER `synced`; ALTER TABLE `zt_mr` ADD `removeSourceBranch` ENUM('0','1') NOT NULL DEFAULT '0' AFTER `compileStatus`; +ALTER TABLE `zt_mr` ADD `syncError` VARCHAR(255) NOT NULL AFTER `synced`; ALTER TABLE zt_repo ADD `fileServerUrl` text COLLATE 'utf8_general_ci' NULL AFTER `job`; ALTER TABLE zt_repo ADD `fileServerAccount` varchar(40) NOT NULL default '' AFTER `fileServerUrl`; diff --git a/db/zentao.sql b/db/zentao.sql index 64b8292590..8d819b8877 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -849,6 +849,7 @@ CREATE TABLE IF NOT EXISTS `zt_mr` ( `compileStatus` char(30) NOT NULL, `removeSourceBranch` enum('0','1') NOT NULL DEFAULT '0', `synced` enum('0','1') COLLATE 'utf8_general_ci' NOT NULL DEFAULT '1', + `syncError` varchar(255) NOT NULL, `hasNoConflict` enum('0','1') COLLATE 'utf8_general_ci' NOT NULL DEFAULT '0', `diffs` longtext COLLATE 'utf8_general_ci' NULL, PRIMARY KEY (`id`) diff --git a/module/ci/model.php b/module/ci/model.php index 2a5fcf2fae..64198ceaaf 100644 --- a/module/ci/model.php +++ b/module/ci/model.php @@ -57,7 +57,7 @@ class ciModel extends model /* Max retry times is: 3. */ if($compile->times >= 3) { - $this->dao->update(TABLE_COMPILE)->set('status')->eq('failure')->where('id')->eq($compile->id)->exec(); + $this->updateBuildStatus($compile, 'failure'); return false; } @@ -223,6 +223,33 @@ class ciModel extends model $rawMR = $this->loadModel('mr')->apiCreateMR($relateMR->gitlabID, $relateMR->sourceProject, $MRObject); + /** + * Another open merge request already exists for this source branch. + * The type of variable `$rawMR->message` is array. + */ + if(isset($rawMR->message) and !isset($rawMR->iid)) + { + foreach($this->lang->mr->apiErrorMap as $key => $errorMsg) + { + if(strpos($errorMsg, '/') === 0) + { + $result = preg_match($errorMsg, $rawMR->message[0], $matches); + if($result) $errorMessage = sprintf(zget($this->lang->mr->errorLang, $key), $matches[1]); + } + else + { + if($rawMR->message[0] == $errorMsg) $errorMessage = zget($this->lang->mr->errorLang, $key, $rawMR->message[0]); + } + + if(isset($errorMessage)) break; + } + $newMR->syncError = sprintf($this->lang->mr->apiError->createMR, isset($errorMessage) ? $errorMessage : $rawMR->message[0]); + } + elseif(!isset($rawMR->iid)) + { + $newMR->syncError = $this->lang->mr->createFailedFromAPI; + } + if(!empty($rawMR->iid)) { $newMR->mriid = $rawMR->iid; diff --git a/module/job/model.php b/module/job/model.php index fa08a254cd..97673d40cc 100644 --- a/module/job/model.php +++ b/module/job/model.php @@ -366,12 +366,12 @@ class jobModel extends model /** * Exec job. * - * @param int $id - * @param object $reference + * @param int $id + * @param array $extraParam * @access public * @return string|bool */ - public function exec($id) + public function exec($id, $extraParam = array()) { $job = $this->dao->select('t1.id,t1.name,t1.product,t1.repo,t1.server,t1.pipeline,t1.triggerType,t1.atTime,t1.customParam,t1.engine,t2.name as jenkinsName,t2.url,t2.account,t2.token,t2.password') ->from(TABLE_JOB)->alias('t1') @@ -408,7 +408,7 @@ class jobModel extends model $this->dao->insert(TABLE_COMPILE)->data($build)->exec(); $compileID = $this->dao->lastInsertId(); - if($job->engine == 'jenkins') $compile = $this->execJenkinsPipeline($job, $repo, $compileID); + if($job->engine == 'jenkins') $compile = $this->execJenkinsPipeline($job, $repo, $compileID, $extraParam); if($job->engine == 'gitlab') $compile = $this->execGitlabPipeline($job); $this->dao->update(TABLE_COMPILE)->data($compile)->where('id')->eq($compileID)->exec(); @@ -428,10 +428,11 @@ class jobModel extends model * @param object $job * @param object $repo * @param int $compileID + * @param array $extraParam * @access public * @return object */ - public function execJenkinsPipeline($job, $repo, $compileID) + public function execJenkinsPipeline($job, $repo, $compileID, $extraParam = array()) { $pipeline = new stdclass(); $pipeline->PARAM_TAG = ''; @@ -449,6 +450,11 @@ class jobModel extends model $pipeline->$paramName = $paramValue; } + foreach($extraParam as $paramName => $paramValue) + { + if(!isset($pipeline->$paramName)) $pipeline->$paramName = $paramValue; + } + $url = $this->loadModel('compile')->getBuildUrl($job); $compile = new stdclass(); diff --git a/module/mr/model.php b/module/mr/model.php index 342703d3f9..9cb3b4fc05 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -225,8 +225,12 @@ class mrModel extends model /* Exec Job */ if($MR->hasNoConflict == '0' && $MR->mergeStatus == 'can_be_merged' && $MR->jobID) { - $MRID = $this->dao->lastInsertId(); - $pipeline = $this->loadModel('job')->exec($MR->jobID); + $MRID = $this->dao->lastInsertId(); + + $extraParam = array(); + if(!empty($repo->fileServerUrl)) $extraParam = array('ZENTAO_REPOPATH' => $repo->fileServerUrl); + + $pipeline = $this->loadModel('job')->exec($MR->jobID, $extraParam); $newMR = new stdClass(); if(!empty($pipeline->queue)) { diff --git a/module/mr/view/view.html.php b/module/mr/view/view.html.php index 1e1c31c8c3..9c7259e463 100644 --- a/module/mr/view/view.html.php +++ b/module/mr/view/view.html.php @@ -62,7 +62,13 @@
' . $lang->mr->noChanges . '';?>
-