This commit is contained in:
Guan Xiying
2021-06-29 15:32:32 +08:00
7 changed files with 59 additions and 29 deletions
+6 -2
View File
@@ -559,7 +559,9 @@ class bug extends control
/* Set gitlabProjects. */
$allGitlabs = $this->loadModel('gitlab')->getPairs();
$gitlabProjects = $this->loadModel('gitlab')->getProjectsByExecution($executionID);
if(!empty($executionID)) $gitlabProjects = $this->loadModel('gitlab')->getProjectsByExecution($executionID);
elseif(!empty($productID)) $gitlabProjects = $this->loadModel('gitlab')->getProjectsByProduct($productID);
foreach($allGitlabs as $id => $name) if($id and !isset($gitlabProjects[$id])) unset($allGitlabs[$id]);
$this->view->gitlabList = $allGitlabs;
$this->view->gitlabProjects = $gitlabProjects;
@@ -1247,6 +1249,8 @@ class bug extends control
$this->executeHooks($bugID);
$this->loadModel('gitlab')->pushBug($bugID, $this->post->gitlab, $this->post->gitlabProject);
if($bug->toTask != 0)
{
/* If task is not finished, update it's status. */
@@ -1549,7 +1553,7 @@ class bug extends control
{
/* Delete related issue in gitlab. */
$relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('bug', $bugID);
$this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'bug', $bugID);
if(!empty($relation)) $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'bug', $bugID, $relation->issueID);
$this->bug->delete(TABLE_BUG, $bugID);
if($bug->toTask != 0)
+9 -1
View File
@@ -646,6 +646,10 @@ class bugModel extends model
if(!empty($bug->resolvedBy)) $this->loadModel('score')->create('bug', 'resolve', $bugID);
$this->file->updateObjectID($this->post->uid, $bugID, 'bug');
$relation = $this->loadModel('gitlab')->getGitlabIDprojectID('bug',$bugID);
if($relation) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $relation->gitlabID, $relation->projectID);
return common::createChanges($oldBug, $bug);
}
}
@@ -1178,6 +1182,9 @@ class bugModel extends model
$this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec();
$this->dao->update(TABLE_BUG)->set('activatedCount = activatedCount + 1')->where('id')->eq((int)$bugID)->exec();
$relation = $this->loadModel('gitlab')->getGitlabIDprojectID('bug',$bugID);
if($relation) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $relation->gitlabID, $relation->projectID);
$openedBuilds = $this->post->openedBuild;
if($openedBuilds)
{
@@ -1185,6 +1192,7 @@ class bugModel extends model
foreach($openedBuilds as $openedBuild)
{
$build = $this->build->getByID($openedBuild);
if(empty($build)) continue;
$build->bugs = trim(str_replace(",$bugID,", ',', ",$build->bugs,"), ',');
$this->dao->update(TABLE_BUILD)->set('bugs')->eq($build->bugs)->where('id')->eq((int)$openedBuild)->exec();
}
@@ -1220,7 +1228,7 @@ class bugModel extends model
$this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec();
$objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('bug',$bugID);
if($objectID) $this->loadModel('bug')->pushToissue('bug', $bugID, $objectID->gitlabID, $objectID->projectID);
if($objectID) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $objectID->gitlabID, $objectID->projectID);
return common::createChanges($oldBug, $bug);
}
+35 -21
View File
@@ -478,6 +478,16 @@ class gitlabModel extends model
->fetchGroup('AID');
}
public function getProjectsByProduct($productID)
{
return $this->dao->select('AID, BID as gitlabProject')->from(TABLE_RELATION)
->where('relation')->eq('interrated')
->andWhere('AType')->eq('gitlab')
->andWhere('BType')->eq('gitlabProject')
->andWhere('product')->eq($productID)
->fetchGroup('AID');
}
/**
* Get gitlabID and projectID.
*
@@ -570,12 +580,11 @@ class gitlabModel extends model
}
$syncedIssue = $this->getSyncedIssue($objectType = 'task', $objectID = $taskID, $gitlab);
$issue = $this->taskToIssue($gitlab, $gitlabProject, $task);
if($syncedIssue)
{
$issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue);
$this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue->BID, $issue);
}
else
{
@@ -612,7 +621,7 @@ class gitlabModel extends model
if($syncedIssue)
{
$this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->AID, $issue);
$this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->BID, $issue);
}
else
{
@@ -627,12 +636,12 @@ class gitlabModel extends model
* Push bug to gitlab issue.
*
* @param int $bugID
* @param int $gitlab
* @param int $gitlabProject
* @param int $gitlabID
* @param int $projectID
* @access public
* @return void
*/
public function pushBug($bugID, $gitlab, $gitlabProject)
public function pushBug($bugID, $gitlabID, $projectID)
{
$bug = $this->loadModel('bug')->getByID($bugID);
@@ -643,19 +652,19 @@ class gitlabModel extends model
$projectID = $result->projectID;
}
$syncedIssue = $this->getSyncedIssue($objectType = 'bug', $objectID = $bugID, $gitlab);
$issue = $this->bugToIssue($gitlab, $gitlabProject, $bug);
$syncedIssue = $this->getSyncedIssue($objectType = 'bug', $objectID = $bugID, $gitlabID);
$issue = $this->bugToIssue($gitlabID, $projectID, $bug);
if($syncedIssue)
{
$issue = $this->apiUpdateIssue($gitlab, $gitlabProject, $syncedIssue, $issue);
$this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->BID, $issue);
}
else
{
$this->createZentaoObjectLabel($gitlab, $gitlabProject, 'bug', $bugID);
$this->createZentaoObjectLabel($gitlabID, $projectID, '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);
$issue = $this->apiCreateIssue($gitlabID, $projectID, $issue);
if($issue) $this->saveSyncedIssue('bug', $bug, $gitlabID, $issue);
}
}
@@ -664,7 +673,7 @@ class gitlabModel extends model
*
* @param string $objectType
* @param int $objectID
* @param int $gitlab
* @param int $gitlabID
* @param int $projectID
* @access public
* @return void
@@ -683,10 +692,9 @@ class gitlabModel extends model
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)
{
$this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue, $issue);
$this->apiUpdateIssue($gitlabID, $projectID, $syncedIssue->BID, $issue);
}
else
{
@@ -698,20 +706,22 @@ class gitlabModel extends model
}
/**
* Delete ans issue.
* Delete an issue.
*
* @param int $gitlabID
* @param int $projectID
* @param string $objectType
* @param int $objectID
* @param int $issueID
* @access public
* @return void
*/
public function deleteIssue($gitlabID, $projectID, $objectType, $objectID)
public function deleteIssue($gitlabID, $projectID, $objectType, $objectID, $issueID)
{
$object = $this->loadModel($objectType)->getByID($objectID);
$relationID = $this->getRelationID($objectType, $objectID);
if(!empty($relationID)) $this->dao->delete(TABLE_RELATION, $relationID);
if(!empty($relationID)) $this->dao->delete()->from(TABLE_RELATION)->where('id')->eq($relationID)->exec();
$this->apiDeleteIssue($gitlabID, $projectID, $issueID);
}
/**
@@ -845,12 +855,12 @@ class gitlabModel extends model
* Parse bug to issue.
*
* @param int $gitlabID
* @param int $gitlabProjectID
* @param int $projectID
* @param object $story
* @access public
* @return object
*/
public function bugToIssue($gitlabID, $gitlabProjectID, $bug)
public function bugToIssue($gitlabID, $projectID, $bug)
{
$map = $this->config->gitlab->maps->bug;
$issue = new stdclass;
@@ -874,6 +884,10 @@ class gitlabModel extends model
if($value) $issue->$field = $value;
}
/* issue->state is null when creating it, we should put status_event when updating it. */
if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close';
if(isset($issue->state) and $issue->state == 'opened') $issue->state_event='reopen';
return $issue;
}
+1 -1
View File
@@ -989,7 +989,7 @@ class story extends control
{
/* Delete related issue in gitlab. */
$relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('story', $storyID);
$this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'story', $storyID);
$this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'story', $storyID, $relation->issueID);
$this->story->delete(TABLE_STORY, $storyID);
if($story->parent > 0)
+2 -2
View File
@@ -830,8 +830,8 @@ class storyModel extends model
$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, $objectID->gitlabID, $objectID->projectID);
$objectID = $this->loadModel('gitlab')->getGitlabidProjectID('story',$storyID);
if($objectID) $this->loadModel('gitlab')->pushToIssue('story', $storyID, $objectID->gitlabID, $objectID->projectID);
unset($oldStory->parent);
unset($story->parent);
+1 -1
View File
@@ -1282,7 +1282,7 @@ class task extends control
{
/* Delete related issue in gitlab. */
$relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('task', $taskID);
$this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'task', $taskID);
$this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'task', $taskID, $relation->issueID);
$this->task->delete(TABLE_TASK, $taskID);
if($task->parent > 0)
+5 -1
View File
@@ -122,7 +122,7 @@ class taskModel extends model
$taskID = $this->dao->lastInsertID();
/* Sync this task to gitlab issue. */
$this->loadModel('gitlab')->pushTask($taskID, $this->post->gitlab, $this->post->gitlabProject);
$this->loadModel('gitlab')->pushToIssue('task', $taskID, $this->post->gitlab, $this->post->gitlabProject);
/* Mark design version.*/
if(isset($task->design) && !empty($task->design))
@@ -941,6 +941,10 @@ class taskModel extends model
->batchCheckIF($task->closedReason == 'cancel', 'finishedBy, finishedDate', 'empty')
->where('id')->eq((int)$taskID)->exec();
/* update story to gitlab issue. */
$objectID = $this->loadModel('gitlab')->getGitlabidProjectID('task',$taskID);
if($objectID) $this->loadModel('gitlab')->pushToIssue('task', $taskID, $objectID->gitlabID, $objectID->projectID);
if(!dao::isError())
{
/* Mark design version.*/