From 9623172398753a02f5f9454cc9115d466dd9d5c4 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 28 Jun 2021 14:39:33 +0800 Subject: [PATCH] * Ready for pushing story to issue. --- module/gitlab/config.php | 1 + module/gitlab/model.php | 53 +++++++++++++++++++++++++++++++--------- module/story/model.php | 23 ++++++++++++++--- 3 files changed, 61 insertions(+), 16 deletions(-) diff --git a/module/gitlab/config.php b/module/gitlab/config.php index 7a1656ad3b..5f802dcc6c 100644 --- a/module/gitlab/config.php +++ b/module/gitlab/config.php @@ -43,6 +43,7 @@ $config->gitlab->maps->story['title'] = 'title|field|'; $config->gitlab->maps->story['spec'] = 'description|fields|verify'; $config->gitlab->maps->story['openedDate'] = 'created_at|field|'; $config->gitlab->maps->story['openedBy'] = 'assignee_id|userPairs|'; +$config->gitlab->maps->story['assignedTo'] = 'assignee_id|userPairs|'; $config->gitlab->maps->story['pri'] = 'weight|configItems|storyWeightMap'; $config->gitlab->maps->bug = array(); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index db3d77d6a5..9d03b2bc4d 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -478,6 +478,23 @@ class gitlabModel extends model ->fetchGroup('AID'); } + /** + * Get gitlabID and projectID. + * + * @param string $objectType + * @param int $objectID + * @access public + * @return object + */ + public function getGitlabIDprojectID($objectType, $objectID) + { + return $this->dao->select('extra as gitlabID, BVersion as projectID')->from(TABLE_RELATION) + ->where('relation')->eq('gitlab') + ->andWhere('Atype')->eq($objectType) + ->andWhere('AID')->eq($objectID) + ->fetch(); + } + /** * Create relationship between zentao product and gitlab project. * @@ -558,7 +575,7 @@ class gitlabModel extends model } /** - * Sync story to gitlab issue. + * Push story to gitlab issue. * * @param int $storyID * @param int $gitlab @@ -566,18 +583,30 @@ class gitlabModel extends model * @access public * @return void */ - public function syncStory($storyID, $gitlab, $gitlabProject) + public function pushStory($storyID, $gitlabID, $projectID) { $story = $this->loadModel('story')->getByID($storyID); - $syncedIssue = $this->getSyncedIssue($objectType = 'story', $objectID = $storyID, $gitlab); - $issue = $this->storyToIssue($gitlab, $gitlabProject, $story); - - $this->createZentaoObjectLabel($gitlab, $gitlabProject, 'story', $storyID); - $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'story', $storyID); - - if($syncedIssue) $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue); - $issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue); - if($issue) $this->saveSyncedIssue('story', $story, $gitlab, $issue); + if(!$gitlabID or !$projectID) + { + $result = $this->getGitlabIDprojectID('story', $storyID); + $gitlabID = $result->gitlabID; + $projectID = $result->projectID; + } + + $syncedIssue = $this->getSyncedIssue($objectType = 'story', $objectID = $storyID, $gitlabID); + $issue = $this->storyToIssue($gitlabID, $projectID, $story); + + if($syncedIssue) + { + $this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->AID, $issue); + } + else + { + $this->createZentaoObjectLabel($gitlabID, $projectID, 'story', $storyID); + $issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'story', $storyID); + $issue = $this->apiCreateIssue($gitlabID, $projectID, $issue); + if($issue) $this->saveSyncedIssue('story', $story, $gitlabID, $issue); + } } /** @@ -710,7 +739,7 @@ class gitlabModel extends model } if($value) $issue->$field = $value; } - + return $issue; } diff --git a/module/story/model.php b/module/story/model.php index 194ab52831..d92b9329d3 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -339,8 +339,8 @@ class storyModel extends model /* Callback the callable method to process the related data for object that is transfered to story. */ if($from && is_callable(array($this, $this->config->story->fromObjects[$from]['callback']))) call_user_func(array($this, $this->config->story->fromObjects[$from]['callback']), $storyID); - /* sync this story to gitlab issue */ - $this->loadModel('gitlab')->syncStory($storyID, $this->post->gitlab, $this->post->gitlabProject); + /* push this story to gitlab issue */ + $this->loadModel('gitlab')->pushStory($storyID, $this->post->gitlab, $this->post->gitlabProject); return array('status' => 'created', 'id' => $storyID); } @@ -830,6 +830,9 @@ class storyModel extends model $this->dao->insert(TABLE_STORYREVIEW)->data($reviewData)->exec(); } + /* Push this story to gitlab issue. */ + $this->loadModel('gitlab')->pushStory($storyID, $this->post->gitlab, $this->post->gitlabProject); + unset($oldStory->parent); unset($story->parent); return common::createChanges($oldStory, $story); @@ -1765,7 +1768,13 @@ class storyModel extends model $story->assignedDate = $now; $this->dao->update(TABLE_STORY)->data($story)->autoCheck()->where('id')->eq((int)$storyID)->exec(); - if(!dao::isError()) return common::createChanges($oldStory, $story); + if(!dao::isError()) + { + /* Push this story to gitlab issue. */ + $this->loadModel('gitlab')->pushStory($storyID, $this->post->gitlab, $this->post->gitlabProject); + + return common::createChanges($oldStory, $story); + } return false; } @@ -1794,7 +1803,13 @@ class storyModel extends model $story->assignedDate = $now; $this->dao->update(TABLE_STORY)->data($story)->autoCheck()->where('id')->eq((int)$storyID)->exec(); - if(!dao::isError()) $allChanges[$storyID] = common::createChanges($oldStory, $story); + if(!dao::isError()) + { + /* Push this story to gitlab issue. */ + $this->loadModel('gitlab')->pushStory($storyID, $this->post->gitlab, $this->post->gitlabProject); + + $allChanges[$storyID] = common::createChanges($oldStory, $story); + } } return $allChanges; }