diff --git a/module/mr/model.php b/module/mr/model.php index 5565966381..0c0b56f3db 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -87,6 +87,8 @@ class mrModel extends model $MR = fixer::input('post') ->setDefault('jobID', 0) ->setDefault('repoID', 0) + ->setDefault('sourceProject,targetProject', 0) + ->setDefault('sourceBranch,targetBranch', '') ->setDefault('removeSourceBranch','0') ->setDefault('needCI', 0) ->add('createdBy', $this->app->user->account) diff --git a/module/repo/model.php b/module/repo/model.php index 4a3245d85c..013f1ccbd3 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -1671,16 +1671,16 @@ class repoModel extends model if($objects['stories']) { - $productsAndExecutions = $this->getTaskProductsAndExecutions($objects['stories']); + $stories = $this->loadModel('story')->getByList($objects['stories']); foreach($objects['stories'] as $storyID) { $storyID = (int)$storyID; - if(!isset($productsAndExecutions[$storyID])) continue; + if(!isset($stories[$storyID])) continue; $action->objectType = 'story'; $action->objectID = $storyID; - $action->product = $productsAndExecutions[$storyID]['product']; - $action->execution = $productsAndExecutions[$storyID]['execution']; + $action->product = $stories[$storyID]->product; + $action->execution = 0; $this->saveRecord($action, $changes); } diff --git a/test/model/mr/apicreate.php b/test/model/mr/apicreate.php index 129f749a6d..8970278ebe 100644 --- a/test/model/mr/apicreate.php +++ b/test/model/mr/apicreate.php @@ -39,6 +39,13 @@ r($result) && p() && e('fail'); //使用正确的RepoUrl,错误的分支数据 dao::$errors = array(); $_POST['data']['RepoSrcBranch'] = 'master'; $_POST['data']['RepoDistBranch'] = 'master'; + +/* Get same opened MR and close it.*/ +$gitlabID = 1; +$projectID = 42; +$oldMR = $mrModel->apiGetSameOpened($gitlabID, $projectID, 'master', $projectID, 'master'); +if($oldMR) $mrModel->apiCloseMR(1, 42, $oldMR->iid); + $result = $mrModel->apiCreate(); if($result) $result = 'success'; r($result) && p() && e('success'); //使用源分支和目标分支一样的数据创建mr请求 @@ -46,6 +53,9 @@ r($result) && p() && e('success'); //使用源分支和目标分支一样的数 dao::$errors = array(); $_POST['data']['RepoSrcBranch'] = 'branch-08'; $_POST['data']['RepoDistBranch'] = 'master'; +$oldMR = $mrModel->apiGetSameOpened($gitlabID, $projectID, 'branch-08', $projectID, 'master'); +if($oldMR) $mrModel->apiCloseMR(1, 42, $oldMR->iid); + $result = $mrModel->apiCreate(); if($result) $result = 'success'; r($result) && p() && e('success'); //使用正确的数据创建mr请求 diff --git a/test/model/mr/create.php b/test/model/mr/create.php index bf8f987a6c..634c7c4596 100644 --- a/test/model/mr/create.php +++ b/test/model/mr/create.php @@ -35,7 +35,7 @@ $_POST['assignee'] = ''; $_POST['removeSourceBranch'] = '1'; $result = $mrModel->create(); if($result['result'] == 'success') $result = 'success'; -$result = preg_match('/通过API创建合并请求失败,失败原因:存在另外一个同样的合并请求在源项目分支中: !([0-9]+)/', $result['message'], $matches); //检查错误原因是否是已存在一样的mr请求 +$result = preg_match('/存在另外一个同样的合并请求在源项目分支中/', $result['message'], $matches); //检查错误原因是否是已存在一样的mr请求 if($result) $result = 'success'; r($result) && p() && e('success'); //使用正确的repoID, gitlabID。POST数据正确 或者错误原因为已存在一样的mr请求