diff --git a/module/mr/model.php b/module/mr/model.php index 9f81b753af..471121134a 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -265,6 +265,12 @@ class mrModel extends model $MR->createdBy = $this->app->user->account; $MR->createdDate = date('Y-m-d H:i:s'); + if($MR->sourceProject == $MR->targetProject and $MR->sourceBranch == $MR->targetBranch) + { + dao::$errors[] = $this->lang->mr->errorLang[1]; + return false; + } + $result = $this->checkSameOpened($MR->gitlabID, $MR->sourceProject, $MR->sourceBranch, $MR->targetProject, $MR->targetBranch); if($result['result'] == 'fail') { diff --git a/module/mr/view/create.html.php b/module/mr/view/create.html.php index c05f0cc6a5..624501db02 100644 --- a/module/mr/view/create.html.php +++ b/module/mr/view/create.html.php @@ -20,8 +20,7 @@ - - + diff --git a/test/data/job.yaml b/test/data/job.yaml new file mode 100644 index 0000000000..6489d78c76 --- /dev/null +++ b/test/data/job.yaml @@ -0,0 +1,146 @@ +title: table zt_job +desc: "构建任务" +author: automated export +version: "1.0" +fields: + - field: id + note: "ID" + range: 1-10000 + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: name + note: "名称" + range: 1-10000 + prefix: "这是一个Job" + postfix: "" + loop: 0 + format: "" + - field: repo + note: "代码库" + range: 1-10000 + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: product + note: "关联产品" + range: 1-10000 + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: frame + note: "工具/框架" + range: junit,testng,phpunit,pytest,jtest,cppunit,gtest,qtest + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: engine + note: "引擎" + range: jenkins,gitlab + - field: triggerType + note: "触发方式" + range: tag,commit,schedule + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: svnDir + note: "SVN监控路径" + range: caselib,effort,git,mail,output + prefix: "/module/" + postfix: "" + loop: 0 + format: "" + - field: atDay + note: "自定义日期" + range: 0-6 + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: atTime + note: "执行时间" + range: "22:05" + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: customParam + note: "自定义构建参数" + range: '' + prefix: "[" + postfix: "]" + loop: 0 + format: "" + - field: comment + note: "匹配关键字" + range: a-z + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: createdBy + note: "创建者" + from: common.user.v1.yaml + use: user + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: createdDate + note: "创建日期" + from: common.date.v1.yaml + use: dateA + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: editedBy + note: "编辑者" + from: common.user.v1.yaml + use: user + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: editedDate + note: "编辑日期" + from: common.date.v1.yaml + use: dateA + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: lastExec + note: "最后执行时间" + from: common.date.v1.yaml + use: dateA + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: lastStatus + note: "最后执行状态" + range: "a-z" + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: lastTag + note: "最后执行标签" + range: "a-z" + prefix: "" + postfix: "" + loop: 0 + format: "" + - field: deleted + note: "是否删除" + range: 0 + prefix: "" + postfix: "" + loop: 0 + format: "" diff --git a/test/data/repo.yaml b/test/data/repo.yaml index fee052df1d..1ff0e40ec1 100644 --- a/test/data/repo.yaml +++ b/test/data/repo.yaml @@ -16,5 +16,9 @@ fields: range: 1 - field: extra range: 42 + - field: preMerge + range: 1 + - field: job + range: 1 - field: deleted range: 0 diff --git a/test/data/zentao/config.php b/test/data/zentao/config.php index e122bb76fc..eb26a4b76b 100644 --- a/test/data/zentao/config.php +++ b/test/data/zentao/config.php @@ -22,4 +22,5 @@ $builder->release = array('rows' => 8, 'extends' => array('release')); $builder->pipeline = array('rows' => 2, 'extends' => array('pipeline')); $builder->repo = array('rows' => 1, 'extends' => array('repo')); +$builder->job = array('rows' => 2, 'extends' => array('job')); $builder->mr = array('rows' => 1, 'extends' => array('mr')); diff --git a/test/data/zt_job.yaml b/test/data/zt_job.yaml index 4b89dc991d..d1f5d7df37 100644 --- a/test/data/zt_job.yaml +++ b/test/data/zt_job.yaml @@ -38,6 +38,9 @@ fields: postfix: "" loop: 0 format: "" + - field: engine + note: "引擎" + range: jenkins,gitlab - field: jkHost note: "Jenkins服务器" range: 1-10000 diff --git a/test/model/gitlab/apicreatebranch.php b/test/model/gitlab/apicreatebranch.php index 2136ed0726..e5613f6c67 100755 --- a/test/model/gitlab/apicreatebranch.php +++ b/test/model/gitlab/apicreatebranch.php @@ -30,7 +30,7 @@ $branch->branch = 'test_branch17'; $branch->ref = 'master'; $result = $gitlab->apiCreateBranch($gitlabID, $projectID, $branch); if($result === null) $result = 'return null'; -r($result) && p() && e('return false'); //使用空的gitlabID、projectID,正确的分支对象创建GitLab分支 +r($result) && p() && e('return null'); //使用空的gitlabID、projectID,正确的分支对象创建GitLab分支 $gitlabID = 1; r($gitlab->apiCreateBranch($gitlabID, $projectID, $branch)) && p('message') && e('404 Project Not Found'); //使用正确的gitlabID、分支信息,错误的projectID创建分支 @@ -39,5 +39,5 @@ $projectID = 1555; $result = $gitlab->apiCreateBranch($gitlabID, $projectID, $branch); if(!empty($result->name) and $result->name == $branch->branch) $result = true; if(!empty($result->message) and $result->message == 'Branch already exists') $result = true; -r($result) && p() && e(1); //通过gitlabID,projectID,分支对象正确创建GitLab分支 +r($result) && p() && e('1'); //通过gitlabID,projectID,分支对象正确创建GitLab分支 r($gitlab->apiCreateBranch($gitlabID, $projectID, $branch)) && p('message') && e('Branch already exists'); //使用重复的分支信息创建分支 diff --git a/test/model/gitlab/apicreatebranchpriv.php b/test/model/gitlab/apicreatebranchpriv.php index 13f298a261..b2f7e479ac 100755 --- a/test/model/gitlab/apicreatebranchpriv.php +++ b/test/model/gitlab/apicreatebranchpriv.php @@ -41,6 +41,6 @@ r($result) && p() && e('return false'); //使用正确的gitlabID、保护分支 $projectID = 966; $gitlab->apiDeleteBranchPriv($gitlabID, $projectID, $branch->name); -r($gitlab->apiCreateBranchPriv($gitlabID, $projectID, $branch)) && p('name') && e($branch->name); //通过gitlabID,projectID,保护分支对象正确创建GitLab保护分支 +r($gitlab->apiCreateBranchPriv($gitlabID, $projectID, $branch)) && p('name') && e('master'); //通过gitlabID,projectID,保护分支对象正确创建GitLab保护分支 r($gitlab->apiCreateBranchPriv($gitlabID, $projectID, $branch)) && p('message') && e("Protected branch 'master' already exists"); //使用重复的保护分支信息创建保护分支 diff --git a/test/model/gitlab/apigetbranches.php b/test/model/gitlab/apigetbranches.php index 62b57b1e44..01e1cf7cf7 100755 --- a/test/model/gitlab/apigetbranches.php +++ b/test/model/gitlab/apigetbranches.php @@ -21,12 +21,12 @@ $gitlab = $tester->loadModel('gitlab'); $gitlabID = 1; $projectID = 1552; $result = $gitlab->apiGetBranches($gitlabID, $projectID); -r(isset(array_shift($result)->name)) && p() && e(1); //通过gitlabID,projectID,获取GitLab分支列表 -r(count($result) > 0) && p() && e(1); //通过gitlabID,projectID,获取GitLab分支数量 +r(isset(array_shift($result)->name)) && p() && e('1'); //通过gitlabID,projectID,获取GitLab分支列表 +r(count($result) > 0) && p() && e('1'); //通过gitlabID,projectID,获取GitLab分支数量 $gitlabID = 1; $projectID = 959; -r(count($gitlab->apiGetBranches($gitlabID, $projectID))) && p() && e(0); //当前项目没有分支时,获取GitLab分支列表 +r(count($gitlab->apiGetBranches($gitlabID, $projectID))) && p() && e('0'); //当前项目没有分支时,获取GitLab分支列表 $gitlabID = 1; $projectID = 0; diff --git a/test/model/gitlab/apigetbranchprivs.php b/test/model/gitlab/apigetbranchprivs.php index f008fdb511..5397b0ee9f 100755 --- a/test/model/gitlab/apigetbranchprivs.php +++ b/test/model/gitlab/apigetbranchprivs.php @@ -8,7 +8,7 @@ title=测试 gitlabModel::apiGetBranchPrivs(); cid=1 pid=1 -获取指定项目下受保护分支列表 >> master +获取指定项目下受保护分支列表 >> master 获取指定项目下受保护分支数量 >> 3 获取无保护分支的项目下受保护分支数量 >> 0 通过不存在projectID,获取受保护分支列表 >> 404 Project Not Found @@ -23,11 +23,11 @@ $projectID = 961; $keyword = ''; $orderBy = 'name_desc'; $result = $gitlab->apiGetBranchPrivs($gitlabID, $projectID, $keyword, $orderBy); -r($result) && p('master:name') && e('master'); //获取指定项目下受保护分支列表 -r(count($result)) && p() && e(3); //获取指定项目下受保护分支数量 +r($result) && p('master:name') && e('master'); //获取指定项目下受保护分支列表 +r(count($result)) && p() && e('3'); //获取指定项目下受保护分支数量 $projectID = 1572; -r(count($gitlab->apiGetBranchPrivs($gitlabID, $projectID))) && p() && e(0); //获取无保护分支的项目下受保护分支数量 +r(count($gitlab->apiGetBranchPrivs($gitlabID, $projectID))) && p() && e('0'); //获取无保护分支的项目下受保护分支数量 $projectID = 0; r($gitlab->apiGetBranchPrivs($gitlabID, $projectID)) && p('message') && e('404 Project Not Found'); //通过不存在projectID,获取受保护分支列表 diff --git a/test/model/gitlab/apigettagprivs.php b/test/model/gitlab/apigettagprivs.php index 09b7e7b5ac..eaef7ba9d0 100644 --- a/test/model/gitlab/apigettagprivs.php +++ b/test/model/gitlab/apigettagprivs.php @@ -21,12 +21,12 @@ $gitlab = $tester->loadModel('gitlab'); $gitlabID = 1; $projectID = 1552; $result = $gitlab->apiGetTagPrivs($gitlabID, $projectID); -r(isset(array_shift($result)->name)) && p() && e(1); //通过gitlabID,projectID,获取GitLab标签保护列表 -r(count($result) > 0) && p() && e(1); //通过gitlabID,projectID,获取GitLab标签保护数量 +r(isset(array_shift($result)->name)) && p() && e('1'); //通过gitlabID,projectID,获取GitLab标签保护列表 +r(count($result) > 0) && p() && e('1'); //通过gitlabID,projectID,获取GitLab标签保护数量 $gitlabID = 1; $projectID = 1570; -r(count($gitlab->apiGetTagPrivs($gitlabID, $projectID))) && p() && e(0); //当前项目没有标签保护时,获取GitLab标签保护列表 +r(count($gitlab->apiGetTagPrivs($gitlabID, $projectID))) && p() && e('0'); //当前项目没有标签保护时,获取GitLab标签保护列表 $gitlabID = 1; $projectID = 0; diff --git a/test/model/gitlab/apigettags.php b/test/model/gitlab/apigettags.php index eaa97f08c4..8afe4552ea 100644 --- a/test/model/gitlab/apigettags.php +++ b/test/model/gitlab/apigettags.php @@ -24,12 +24,12 @@ $gitlab = $tester->loadModel('gitlab'); $gitlabID = 1; $projectID = 1552; $result = $gitlab->apiGetTags($gitlabID, $projectID); -r(isset($result[0]->name)) && p() && e(1); //通过gitlabID,projectID,获取GitLab标签列表 -r(count($result) > 0) && p() && e(1); //通过gitlabID,projectID,获取GitLab标签数量 +r(isset($result[0]->name)) && p() && e('1'); //通过gitlabID,projectID,获取GitLab标签列表 +r(count($result) > 0) && p() && e('1'); //通过gitlabID,projectID,获取GitLab标签数量 $gitlabID = 1; $projectID = 1570; -r(count($gitlab->apiGetTags($gitlabID, $projectID))) && p() && e(0); //当前项目没有标签时,获取GitLab标签列表 +r(count($gitlab->apiGetTags($gitlabID, $projectID))) && p() && e('0'); //当前项目没有标签时,获取GitLab标签列表 $gitlabID = 1; $projectID = 0; diff --git a/test/model/gitlab/createtagpriv.php b/test/model/gitlab/createtagpriv.php index 6cdc29658e..4db30a37e8 100755 --- a/test/model/gitlab/createtagpriv.php +++ b/test/model/gitlab/createtagpriv.php @@ -16,15 +16,13 @@ pid=1 */ -global $lang; - $gitlab = $tester->loadModel('gitlab'); $gitlabID = 0; $projectID = 0; $gitlab->createTagPriv($gitlabID, $projectID); -r(dao::getError()) && p('name:0') && e($lang->gitlab->tag->emptyPrivNameError); //使用空的gitlabID,projectID,保护标签对象创建GitLab保护标签 +r(dao::getError()) && p('name:0') && e('标签不能为空'); //使用空的gitlabID,projectID,保护标签对象创建GitLab保护标签 $_POST['name'] = 'test_tag1'; $_POST['create_access_level'] = '40'; diff --git a/test/model/mr/apicreate.php b/test/model/mr/apicreate.php index 129f749a6d..baddd0e7f7 100644 --- a/test/model/mr/apicreate.php +++ b/test/model/mr/apicreate.php @@ -15,6 +15,7 @@ pid=0 */ +global $lang; $mrModel = $tester->loadModel('mr'); $_POST = array( @@ -40,12 +41,21 @@ dao::$errors = array(); $_POST['data']['RepoSrcBranch'] = 'master'; $_POST['data']['RepoDistBranch'] = 'master'; $result = $mrModel->apiCreate(); -if($result) $result = 'success'; +if(!$result and dao::isError()) +{ + $errors = dao::getError(); + if($errors[0] == $lang->mr->errorLang[1]) $result = 'success'; +} r($result) && p() && e('success'); //使用源分支和目标分支一样的数据创建mr请求 dao::$errors = array(); $_POST['data']['RepoSrcBranch'] = 'branch-08'; $_POST['data']['RepoDistBranch'] = 'master'; $result = $mrModel->apiCreate(); +if(dao::isError()) +{ + $errors = dao::getError(); + $result = preg_match('/[存在另外一个同样的合并请求在源项目分支中,存在重复并且未关闭的合并请求]: ID([0-9]+)/', $errors[0], $matches); //检查错误原因是否是已存在一样的mr请求 +} if($result) $result = 'success'; r($result) && p() && e('success'); //使用正确的数据创建mr请求 diff --git a/test/model/mr/apigetsameopened.php b/test/model/mr/apigetsameopened.php index faf98a3e22..b34f368a41 100644 --- a/test/model/mr/apigetsameopened.php +++ b/test/model/mr/apigetsameopened.php @@ -28,6 +28,17 @@ $sourceProject = '42'; $sourceBranch = 'branch-08'; $targetProject = '42'; $targetBranch = 'master'; +$_POST['gitlabID'] = $gitlabID; +$_POST['title'] = 'test_create'; +$_POST['description'] = 'test_create'; +$_POST['repoID'] = 1; +$_POST['assignee'] = ''; +$_POST['removeSourceBranch'] = '1'; +$_POST['sourceProject'] = $sourceProject; +$_POST['sourceBranch'] = $sourceBranch; +$_POST['targetProject'] = $targetProject; +$_POST['targetBranch'] = $targetBranch; +$result = $mrModel->create(); $result = $mrModel->apiGetSameOpened($gitlabID, $sourceProject, $sourceBranch, $targetProject, $targetBranch); if(isset($result->iid)) $result = 'success'; r($result) && p() && e('success'); //使用正确的gitlabID, sourceProject,sourceBranch,targetProject,targetBranch diff --git a/test/model/mr/update.php b/test/model/mr/update.php index e36c15bf41..e4b9829a2a 100644 --- a/test/model/mr/update.php +++ b/test/model/mr/update.php @@ -19,7 +19,7 @@ $MRID = 1; $_POST = array(); $_POST['targetBranch'] = 'master'; $_POST['title'] = 'Test MR'; -$_POST['description'] = date("Y-m-d H:i:s"); +$_POST['description'] = '2022-01-31 23:59:59'; $_POST['repoID'] = 1; $_POST['assignee'] = ''; $_POST['removeSourceBranch'] = '0'; diff --git a/test/model/sonarqube/apigetprojects.php b/test/model/sonarqube/apigetprojects.php index 77404afa4c..b05bc00902 100644 --- a/test/model/sonarqube/apigetprojects.php +++ b/test/model/sonarqube/apigetprojects.php @@ -19,12 +19,12 @@ $sonarqube = $tester->loadModel('sonarqube'); $sonarqubeID = 2; $result = $sonarqube->apiGetProjects($sonarqubeID); -r(isset($result[0]->name)) && p() && e(1); //通过sonarqubeID,获取SonarQube项目列表 -r(count($result) > 0) && p() && e(1); //通过sonarqubeID,获取SonarQube项目数量 +r(isset($result[0]->name)) && p() && e('1'); //通过sonarqubeID,获取SonarQube项目列表 +r(count($result) > 0) && p() && e('1'); //通过sonarqubeID,获取SonarQube项目数量 $keyword = '02'; $result = $sonarqube->apiGetProjects($sonarqubeID, $keyword); -r(strpos($result[0]->name, '02') !== false) && p() && e(1); //通过sonarqubeID,关键字,搜索获取SonarQube项目 +r(strpos($result[0]->name, '02') !== false) && p() && e('1'); //通过sonarqubeID,关键字,搜索获取SonarQube项目 $sonarqubeID = 0; $result = $sonarqube->apiGetProjects($sonarqubeID);
gitlab->common;?>
mr->sourceProject;?>