diff --git a/module/bug/control.php b/module/bug/control.php index 84d137d9f0..f40ca35713 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -1547,6 +1547,10 @@ class bug extends control } else { + /* Delete related issue in gitlab. */ + $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('bug', $bugID); + $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'bug', $bugID); + $this->bug->delete(TABLE_BUG, $bugID); if($bug->toTask != 0) { diff --git a/module/bug/model.php b/module/bug/model.php index a52f200b1e..fe879e49e8 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -90,7 +90,7 @@ class bugModel extends model $bugID = $this->dao->lastInsertID(); /* Sync this bug to gitlab issue. */ - $this->loadModel('gitlab')->pushToissue('bug', $bugID, $this->post->gitlab, $this->post->gitlabProject); + $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $this->post->gitlab, $this->post->gitlabProject); $this->file->updateObjectID($this->post->uid, $bugID, 'bug'); $this->file->saveUpload('bug', $bugID); @@ -852,6 +852,15 @@ class bugModel extends model ->autoCheck() ->where('id')->eq($bugID)->exec(); + $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('bug', $bugID); + $attribute = new stdclass(); + $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $bug->assignedTo); + if($attribute->assignee_id != '') + { + // TODO(dingguodong) we should alert to operator when can not find the user, and the operator should reconfigure user binding. + $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID , $attribute); + } + if(!dao::isError()) return common::createChanges($oldBug, $bug); } diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 7a2c9fd117..f09d022bc6 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -593,14 +593,16 @@ class gitlabModel extends model * Push story to gitlab issue. * * @param int $storyID - * @param int $gitlab - * @param int $gitlabProject + * @param int $gitlabID + * @param int $projectID * @access public * @return void */ public function pushStory($storyID, $gitlabID, $projectID) { $story = $this->loadModel('story')->getByID($storyID); + if(empty($bug)) return false; + if(!$gitlabID or !$projectID) { $result = $this->getGitlabIDprojectID('story', $storyID); @@ -627,7 +629,7 @@ class gitlabModel extends model /** * Sync bug to gitlab issue. * - * @param int $storyID + * @param int $bugID * @param int $gitlab * @param int $gitlabProject * @access public @@ -658,7 +660,7 @@ class gitlabModel extends model * @access public * @return void */ - public function pushToissue($objectType, $objectID, $gitlabID, $projectID) + public function pushToIssue($objectType, $objectID, $gitlabID, $projectID) { $object = $this->loadModel($objectType)->getByID($objectID); if(!$gitlabID or !$projectID) @@ -669,9 +671,9 @@ class gitlabModel extends model } $syncedIssue = $this->getSyncedIssue($objectType = $objectType, $objectID = $objectID, $gitlabID); - if($objectType == 'story') $issue = $this->storyToIssue($gitlabID, $projectID, $objectID); - if($objectType == 'task') $issue = $this->taskToIssue($gitlabID, $projectID, $objectID); - if($objectType == 'bug') $issue = $this->bugToIssue($gitlabID, $projectID, $objectID); + if($objectType == 'story') $issue = $this->storyToIssue($gitlabID, $projectID, $object); + if($objectType == 'task') $issue = $this->taskToIssue($gitlabID, $projectID, $object); + if($objectType == 'bug') $issue = $this->bugToIssue($gitlabID, $projectID, $object); if($syncedIssue) { @@ -682,7 +684,7 @@ class gitlabModel extends model $this->createZentaoObjectLabel($gitlabID, $projectID, $objectType, $objectID); $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, $objectType, $objectID); $issue = $this->apiCreateIssue($gitlabID, $projectID, $issue); - if($issue) $this->saveSyncedIssue($objectType, $objectID, $gitlabID, $issue); + if($issue) $this->saveSyncedIssue($objectType, $object, $gitlabID, $issue); } } @@ -770,7 +772,7 @@ class gitlabModel extends model * * @param int $gitlabID * @param int $gitlabProjectID - * @param object $task + * @param object $task * @access public * @return object */ diff --git a/module/story/control.php b/module/story/control.php index 869e0c053a..1a43a84db7 100644 --- a/module/story/control.php +++ b/module/story/control.php @@ -987,6 +987,10 @@ class story extends control } else { + /* Delete related issue in gitlab. */ + $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('story', $storyID); + $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'story', $storyID); + $this->story->delete(TABLE_STORY, $storyID); if($story->parent > 0) { diff --git a/module/task/model.php b/module/task/model.php index f465c053d9..246a17f9c0 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -1327,7 +1327,6 @@ class taskModel extends model ->where('id')->eq($taskID)->exec(); $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('task', $taskID); - $attribute = new stdclass(); $attribute->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $task->assignedTo); if($attribute->assignee_id != '')