Merge branch 'jihu'

This commit is contained in:
Guan Xiying
2021-07-14 09:48:58 +08:00
84 changed files with 3798 additions and 225 deletions

View File

@@ -84,10 +84,13 @@ class bugModel extends model
/* Use classic mode to replace required project. */
if($this->config->systemMode == 'classic' and strpos($this->config->bug->create->requiredFields, 'project') !== false) $this->config->bug->create->requiredFields = str_replace('project', 'execution', $this->config->bug->create->requiredFields);
$this->dao->insert(TABLE_BUG)->data($bug)->autoCheck()->batchCheck($this->config->bug->create->requiredFields, 'notempty')->exec();
$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();
$this->loadModel('gitlab')->apiCreateIssue($this->post->gitlab, $this->post->gitlabProject, 'bug', $bugID, $bug);
$this->file->updateObjectID($this->post->uid, $bugID, 'bug');
$this->file->saveUpload('bug', $bugID);
empty($bug->case) ? $this->loadModel('score')->create('bug', 'create', $bugID) : $this->loadModel('score')->create('bug', 'createFormCase', $bug->case);
@@ -273,6 +276,32 @@ 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)
{
$bug->openedBy = $this->app->user->account;
$bug->openedDate = helper::now(); // TODO(dingguodong) use from issue->created_at ?
$bug->assignedDate = isset($bug->assignedTo) ? helper::now() : 0;
$bug->openedBuild = 1;
$bug->story = 0;
$bug->task = 0;
$bug->pri = 3;
$bug->severity = 3;
$bug->project = $this->dao->select('parent')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch('parent');
$this->dao->insert(TABLE_BUG)->data($bug, $skip = 'gitlab,gitlabProject')->autoCheck()->batchCheck($this->config->bug->create->requiredFields, 'notempty')->exec();
if(!dao::isError()) return $this->dao->lastInsertID();
return false;
}
/**
* Get bugs.
*
@@ -645,6 +674,12 @@ class bugModel extends model
if(!empty($bug->resolvedBy)) $this->loadModel('score')->create('bug', 'resolve', $bugID);
$this->file->updateObjectID($this->post->uid, $bugID, 'bug');
if(!empty($bug))
{
$relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID);
if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug, $bugID);
}
return common::createChanges($oldBug, $bug);
}
}
@@ -766,6 +801,10 @@ class bugModel extends model
$this->executeHooks($bugID);
$allChanges[$bugID] = common::createChanges($oldBug, $bug);
/* update bug to gitlab issue. */
$relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID);
if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug, $bugID);
}
else
{
@@ -820,6 +859,12 @@ class bugModel extends model
/* Update bugs. */
foreach($activateBugs as $bugID => $bug)
{
if(!empty($bug))
{
$relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID);
if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', (Object)$bug, $bugID);
}
$oldBug = $bugs[$bugID];
$this->dao->update(TABLE_BUG)->data($bug, $skipFields = 'comment')->autoCheck()->where('id')->eq((int)$bugID)->exec();
if(dao::isError()) die(js::error('bug#' . $bugID . dao::getError(true)));
@@ -854,6 +899,15 @@ class bugModel extends model
->autoCheck()
->where('id')->eq($bugID)->exec();
$relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID);
$bug = $this->getById($bugID); // get full bug object to update issue.
$bug->assignee_id = $this->loadModel('gitlab')->getGitlabUserID($relation->gitlabID, $bug->assignedTo);
if($bug->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, 'bug', $bug, $bugID);
}
if(!dao::isError()) return common::createChanges($oldBug, $bug);
}
@@ -908,6 +962,12 @@ class bugModel extends model
$bug->lastEditedDate = $now;
$bug->confirmed = 1;
if(!empty($bug))
{
$relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID);
if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug, $bugID);
}
$this->dao->update(TABLE_BUG)->data($bug)->where('id')->eq($bugID)->exec();
$this->executeHooks($bugID);
}
@@ -991,6 +1051,7 @@ class bugModel extends model
->checkIF($bug->resolution == 'fixed', 'resolvedBuild','notempty')
->where('id')->eq((int)$bugID)
->exec();
if(!dao::isError())
{
$this->loadModel('score')->create('bug', 'resolve', $oldBug);
@@ -998,6 +1059,9 @@ class bugModel extends model
/* Link bug to build and release. */
$this->linkBugToBuild($bugID, $bug->resolvedBuild);
$relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID);
if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug, $bugID);
return common::createChanges($oldBug, $bug);
}
@@ -1127,6 +1191,10 @@ class bugModel extends model
$this->dao->update(TABLE_BUG)->data($bug)->where('id')->eq($bugID)->exec();
$this->executeHooks($bugID);
/* batch resolve issure bugs.*/
$relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID);
if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug, $bugID);
$changes[$bugID] = common::createChanges($oldBug, $bug);
}
@@ -1178,11 +1246,18 @@ 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();
}
}
if(!empty($bug))
{
$relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID);
if($relation) $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug, $bugID);
}
$bug->activatedCount += 1;
return common::createChanges($oldBug, $bug);
}
@@ -1212,6 +1287,12 @@ class bugModel extends model
$this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec();
$relation = $this->loadModel('gitlab')->getRelationByObject('bug', $bugID);
if(!empty($relation))
{
$currentIssue = $this->loadModel('gitlab')->apiGetSingleIssue($relation->gitlabID, $relation->projectID, $relation->issueID);
if($currentIssue->state != 'closed') $this->loadModel('gitlab')->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'bug', $bug, $bugID);
}
return common::createChanges($oldBug, $bug);
}