This commit is contained in:
Guan Xiying
2021-06-29 10:01:49 +08:00
8 changed files with 207 additions and 56 deletions
+4
View File
@@ -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)
{
+10 -1
View File
@@ -90,7 +90,7 @@ class bugModel extends model
$bugID = $this->dao->lastInsertID();
/* Sync this bug to gitlab issue. */
$this->loadModel('gitlab')->syncBug($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);
}
+3 -2
View File
@@ -44,13 +44,14 @@ $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();
$config->gitlab->maps->bug['title'] = 'title|field|';
$config->gitlab->maps->bug['spec'] = 'description|field|';
$config->gitlab->maps->bug['steps'] = 'description|field|';
$config->gitlab->maps->bug['openedDate'] = 'created_at|field|';
$config->gitlab->maps->bug['openedBy'] = 'assignee_id|userPairs|';
$config->gitlab->maps->bug['assignedTo'] = 'assignee_id|userPairs|';
$config->gitlab->maps->bug['pri'] = 'weight|configItems|bugWeightMap';
$config->gitlab->taskWeightMap = array();
+160 -45
View File
@@ -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.
*
@@ -533,7 +550,7 @@ class gitlabModel extends model
}
/**
* Sync task to gitlab issue.
* Push task to gitlab issue.
*
* @param int $taskID
* @param int $gitlab
@@ -541,67 +558,162 @@ class gitlabModel extends model
* @access public
* @return void
*/
public function syncTask($taskID, $gitlab, $gitlabProject)
public function pushTask($taskID, $gitlab, $gitlabProject)
{
$task = $this->loadModel('task')->getByID($taskID);
$syncedIssue = $this->getSyncedIssue($objectType = 'task', $objectID = $taskID, $gitlab);
$issue = $this->taskToIssue($gitlab, $gitlabProject, $task);
$this->createZentaoObjectLabel($gitlab, $gitlabProject, 'task', $taskID);
$issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'task', $taskID);
if($syncedIssue) $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue);
$issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue);
$this->saveSyncedIssue('task', $task, $gitlab, $issue);
if($syncedIssue)
{
$issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue);
}
else
{
$this->createZentaoObjectLabel($gitlab, $gitlabProject, 'task', $taskID);
$issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'task', $taskID);
$issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue);
$this->saveSyncedIssue('task', $task, $gitlab, $issue);
}
}
/**
* Sync story to gitlab issue.
* 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 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(empty($bug)) return false;
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);
}
}
/**
* Sync bug to gitlab issue.
* Push bug to gitlab issue.
*
* @param int $storyID
* @param int $bugID
* @param int $gitlab
* @param int $gitlabProject
* @access public
* @return void
*/
public function syncBug($bugID, $gitlab, $gitlabProject)
public function pushBug($bugID, $gitlab, $gitlabProject)
{
$bug = $this->loadModel('bug')->getByID($bugID);
$syncedIssue = $this->getSyncedIssue($objectType = 'bug', $objectID = $bugID, $gitlab);
$issue = $this->bugToIssue($gitlab, $gitlabProject, $bug);
$this->createZentaoObjectLabel($gitlab, $gitlabProject, 'bug', $bugID);
sprintf($this->config->gitlab->zentaoObjectLabel->name, 'bug', $bugID);
if($syncedIssue)
{
$issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue);
}
else
{
$this->createZentaoObjectLabel($gitlab, $gitlabProject, 'bug', $bugID);
$issue->labels = sprintf($this->config->gitlab->zentaoObjectLabel->name, 'bug', $bugID);
$issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue);
if($issue) $this->saveSyncedIssue('bug', $bug, $gitlab, $issue);
}
}
/**
* Push to gitlab issue.
*
* @param string $objectType
* @param int $objectID
* @param int $gitlab
* @param int $projectID
* @access public
* @return void
*/
public function pushToIssue($objectType, $objectID, $gitlabID, $projectID)
{
$object = $this->loadModel($objectType)->getByID($objectID);
if(!$gitlabID or !$projectID)
{
$result = $this->getGitlabIDprojectID($objectType, $objectID);
$gitlabID = $result->gitlabID;
$projectID = $result->projectID;
}
$syncedIssue = $this->getSyncedIssue($objectType = $objectType, $objectID = $objectID, $gitlabID);
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) $issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue);
$issue = $this->apiCreateIssue($gitlab, $gitlabProject, $issue);
if($issue) $this->saveSyncedIssue('bug', $bug, $gitlab, $issue);
if($syncedIssue)
{
$this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue, $issue);
}
else
{
$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, $object, $gitlabID, $issue);
}
}
/**
* Delete ans issue.
*
* @param int $gitlabID
* @param int $projectID
* @param string $objectType
* @param int $objectID
* @access public
* @return void
*/
public function deleteIssue($gitlabID, $projectID, $objectType, $objectID)
{
$object = $this->loadModel($objectType)->getByID($objectID);
$relationID = $this->getRelationID($objectType, $objectID);
if(!empty($relationID)) $this->dao->delete(TABLE_RELATION, $relationID);
}
/**
* Get relation id.
*
* @param string $objectType
* @param int $objectID
* @access public
* @return void
*/
public function getRelationID($objectType, $objectID)
{
return $this->dao->select('id')->from(TABLE_RELATION)
->where('AType')->eq($objectType)
->andWhere('AID')->eq($objectID)
->andWhere('relation')->eq('gitlab')
->fetch('id');
}
/**
@@ -654,7 +766,7 @@ class gitlabModel extends model
*
* @param int $gitlabID
* @param int $gitlabProjectID
* @param object $task
* @param object $task
* @access public
* @return object
*/
@@ -710,7 +822,7 @@ class gitlabModel extends model
}
if($value) $issue->$field = $value;
}
return $issue;
}
@@ -735,7 +847,7 @@ class gitlabModel extends model
$value = '';
list($field, $optionType, $options) = explode('|', $config);
if($optionType == 'field') $value = $bug->$bugField;
if($optionType == 'fields') $value = $bug->$bugField . "\n\n" . $story->$options;
if($optionType == 'fields') $value = $bug->$bugField . "\n\n" . $bug->$options;
if($optionType == 'userPairs')
{
$value = zget($gitlabUsers, $bug->$bugField);
@@ -791,19 +903,22 @@ class gitlabModel extends model
return $response;
}
public function pushTask($gitlabID, $projectID, $task)
/**
* Delete an issue.
*
* @param int $gitlabID
* @param int $projectID
* @param int $issueID
* @access public
* @return void
*/
public function apiDeleteIssue($gitlabID, $projectID, $issueID)
{
$task->label = $this->config->gitlab->taskLabel->name;
$response = $this->apiCreateIssue($gitlabID, $projectID, $task);
return $response;
}
public function pushBug($gitlabID, $projectID, $bug)
{
$bug->label = $this->config->gitlab->bugLabel->name;
$response = $this->apiCreateIssue($gitlabID, $projectID, $bug);
return $response;
}
$apiRoot = $this->getApiRoot($gitlabID);
$apiPath = "/projects/{$projectID}/issues/{$issueID}";
$url = sprintf($apiRoot, $apiPath);
commonModel::http($url, $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE'));
}
/**
* webhook check token.
+4
View File
@@ -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)
{
+21 -6
View File
@@ -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);
}
@@ -828,7 +828,10 @@ class storyModel extends model
$reviewData->version = $oldStory->version;
$reviewData->reviewer = $reviewer;
$this->dao->insert(TABLE_STORYREVIEW)->data($reviewData)->exec();
}
}
/* update story to gitlab issue. */
$objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('story',$storyID);
if($objectID) $this->loadModel('gitlab')->pushToissue('story', $storyID, $this->post->gitlab, $this->post->gitlabProject);
unset($oldStory->parent);
unset($story->parent);
@@ -1764,8 +1767,14 @@ class storyModel extends model
$story->assignedTo = $assignedTo;
$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())
{
/* Update this story to gitlab issue. */
$objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('story',$storyID);
if($objectID) $this->loadModel('gitlab')->pushToissue('story', $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;
}
+4
View File
@@ -1280,6 +1280,10 @@ class task extends control
}
else
{
/* Delete related issue in gitlab. */
$relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('task', $taskID);
$this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'task', $taskID);
$this->task->delete(TABLE_TASK, $taskID);
if($task->parent > 0)
{
+1 -2
View File
@@ -122,7 +122,7 @@ class taskModel extends model
$taskID = $this->dao->lastInsertID();
/* Sync this task to gitlab issue. */
$this->loadModel('gitlab')->syncTask($taskID, $this->post->gitlab, $this->post->gitlabProject);
$this->loadModel('gitlab')->pushTask($taskID, $this->post->gitlab, $this->post->gitlabProject);
/* Mark design version.*/
if(isset($task->design) && !empty($task->design))
@@ -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 != '')