diff --git a/module/bug/config.php b/module/bug/config.php index ab1efb6707..bc508859ab 100644 --- a/module/bug/config.php +++ b/module/bug/config.php @@ -2,6 +2,7 @@ $config->bug = new stdClass(); $config->bug->batchCreate = 10; $config->bug->longlife = 7; +$config->bug->removeFields= 'objectTypeList,productList,executionList,gitlabID,gitlabProjectID'; $config->bug->create = new stdclass(); $config->bug->edit = new stdclass(); diff --git a/module/bug/model.php b/module/bug/model.php index d9e90aff41..d481824988 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -273,6 +273,51 @@ class bugModel extends model return $actions; } + /** + * Create bug from gitlab issue. + * + * @param object $bug + * @param int $executionID + * @access public + * @return int + */ + public function createBugFromGitlabIssue($bug, $executionID) + { + foreach($bug as $feild => $value) $_POST[$feild] = $value; + $now = helper::now(); + $bug = fixer::input('post') + ->setDefault('openedBy', $this->app->user->account) + ->setDefault('openedDate', $now) + ->setDefault('project,execution,story,task', 0) + ->setDefault('openedBuild', '1') // todo(dingguodong) openedBuild is hard-coded. + ->setDefault('deadline', '0000-00-00') + ->setIF($this->config->systemMode == 'new' && $this->lang->navGroup->bug != 'qa', 'project', $this->session->project) + ->setIF(strpos($this->config->bug->create->requiredFields, 'deadline') !== false, 'deadline', $bug->deadline) + ->setIF(isset($bug->assignedTo) and $bug->assignedTo != '', 'assignedDate', $now) + ->stripTags($this->config->bug->editor->create['id'], $this->config->allowedTags) + ->cleanInt('product,execution,module,severity') + ->join('openedBuild', ',') + ->join('mailto', ',') + ->remove('files, labels,uid,oldTaskID,contactListMenu') + ->remove($this->config->bug->removeFields) + ->get(); + + if($executionID != 0) + { + $bug->project = $this->dao->select('parent')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch('parent'); + $bug->execution = $executionID; + } + + $this->dao->insert(TABLE_BUG)->data($bug, $skip = 'gitlab,gitlabProject')->autoCheck()->batchCheck($this->config->bug->create->requiredFields, 'notempty')->exec(); + if(!dao::isError()) + { + $bugID = $this->dao->lastInsertID(); + return $bugID; + } + + return false; + } + /** * Get bugs. * diff --git a/module/gitlab/config.php b/module/gitlab/config.php index f3fff35b4d..84ee284a8d 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -55,6 +55,7 @@ $config->gitlab->maps->bug = array(); $config->gitlab->maps->bug['title'] = 'title|field|'; $config->gitlab->maps->bug['steps'] = 'description|field|'; $config->gitlab->maps->bug['openedDate'] = 'created_at|field|datetime'; +$config->gitlab->maps->bug['deadline'] = 'due_date|field|date'; $config->gitlab->maps->bug['assignedTo'] = 'assignee_id|userPairs|'; $config->gitlab->maps->bug['status'] = 'state|configItems|bugStateMap'; $config->gitlab->maps->bug['pri'] = 'weight|configItems|bugWeightMap'; diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 0fa6a04612..11a3aed968 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -269,6 +269,8 @@ class gitlab extends control $executionList = $this->post->executionList; $objectTypeList = $this->post->objectTypeList; $productList = $this->post->productList; + + $failedIssues = array(); foreach($executionList as $issueID => $executionID) { if($executionID) @@ -281,6 +283,8 @@ class gitlab extends control $issue->updated_by_id = $issue->author->id; // here can be replaced by current zentao user. $object = $this->gitlab->issueToZentaoObject($issue, $gitlabID); + $object->product = $productList[$issueID]; + $object->execution = $executionID; if($objectType == 'task') { $objectID = $this->loadModel('task')->createTaskFromGitlabIssue($object, $executionID); @@ -288,23 +292,31 @@ class gitlab extends control if($objectType == 'bug') { + $objectID = $this->loadModel('bug')->createBugFromGitlabIssue($object, $executionID); } if($objectType == 'story') { + $objectID = $this->loadModel('story')->createStoryFromGitlabIssue($object, $executionID); } - - $object->id = $objectID; - $object->product = $productList[$issueID]; - $object->execution = $executionID; - $this->gitlab->saveImportedIssue($gitlabID, $projectID, $objectType, $objectID, $issue, $object); + if($objectID) + { + $object->id = $objectID; + $this->gitlab->saveImportedIssue($gitlabID, $projectID, $objectType, $objectID, $issue, $object); + } + else + { + $failedIssues[] = $issue->iid; + } } else { if($productList[$issueID] != 0) $this->send(array('result' => 'fail', 'message' => $this->lang->gitlab->importIssueError, 'locate' => $this->server->http_referer)); } } + + if($failedIssues) $this->send(array('result' => 'success', 'message' => $this->lang->gitlab->importIssueWarn, 'locate' => $this->server->http_referer)); $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->server->http_referer)); } diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index 6c5e6ad25d..e2df334a72 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -40,3 +40,4 @@ $lang->gitlab->tokenError = "当前token非管理员权限。"; $lang->gitlab->hostError = "无效的gitlab服务地址。"; $lang->gitlab->bindUserError = "不能重复绑定用户 %s"; $lang->gitlab->importIssueError = "未选择该议题所属的执行。"; +$lang->gitlab->importIssueWarn = "存在导入失败的议题,可再次尝试导入。"; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 85dc58983d..f4cba5b9c2 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -1154,8 +1154,8 @@ class gitlabModel extends model if(!isset($changes->$gitlabField) and $object->id != 0) continue; if($optionType == 'field') $value = $issue->$gitlabField; if($optionType == 'field') $value = $issue->$gitlabField; - if($options == 'date') $value = date('Y-m-d', strtotime($value)); - if($options == 'datetime') $value = date('Y-m-d H:i:s', strtotime($value)); + if($options == 'date') $value = $value ? date('Y-m-d', strtotime($value)) : '0000-00-00'; + if($options == 'datetime') $value = $value ? date('Y-m-d H:i:s', strtotime($value)) : '0000-00-00 00:00:00'; if($optionType == 'userPairs' and isset($issue->$gitlabField)) $value = zget($gitlabUsers, $issue->$gitlabField); if($optionType == 'configItems' and isset($issue->$gitlabField)) $value = array_search($issue->$gitlabField, $this->config->gitlab->$options); if($value) $object->$zentaoField = $value; diff --git a/module/task/config.php b/module/task/config.php index ab950c3b2e..cb5c12a616 100644 --- a/module/task/config.php +++ b/module/task/config.php @@ -26,7 +26,7 @@ $config->task->editor->activate = array('id' => 'comment', 'tools' => 'simpleToo $config->task->editor->cancel = array('id' => 'comment', 'tools' => 'simpleTools'); $config->task->editor->pause = array('id' => 'comment', 'tools' => 'simpleTools'); -$config->task->removeFields = 'objectTypeList,productList,executionList,gitlabID,gitlabProjectID,after,files,labels,assignedTo,uid,storyEstimate,storyDesc,storyPri,team,teamEstimate,teamMember,multiple,teams,contactListMenu,selectTestStory,testStory,testPri,testEstStarted,testDeadline,testAssignedTo,testEstimate,sync'; +$config->task->removeFields = 'objectTypeList,productList,executionList,gitlabID,gitlabProjectID'; $config->task->exportFields = ' id, execution, module, story, name, desc, diff --git a/module/task/model.php b/module/task/model.php index a17ae4b1a9..f01fba6664 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -489,6 +489,7 @@ class taskModel extends model ->cleanINT('execution,story,module') ->stripTags($this->config->task->editor->create['id'], $this->config->allowedTags) ->join('mailto', ',') + ->remove('after,files,labels,assignedTo,uid,storyEstimate,storyDesc,storyPri,team,teamEstimate,teamMember,multiple,teams,contactListMenu,selectTestStory,testStory,testPri,testEstStarted,testDeadline,testAssignedTo,testEstimate,sync') ->remove($this->config->task->removeFields) ->add('version', 1) ->get();