+ Add funcs to update issue when the assigned user changed in task.

This commit is contained in:
dingguodong
2021-06-24 14:56:23 +08:00
parent 49af2b3bb1
commit 86c7e9b4cc
2 changed files with 46 additions and 2 deletions
+36 -2
View File
@@ -56,7 +56,10 @@ class gitlabModel extends model
*/
public function getUserIdAccountPairs($gitlab)
{
return $this->dao->select('openID,account')->from(TABLE_OAUTH)->where('providerType')->eq('gitlab')->andWhere('providerID')->eq($gitlab)->fetchPairs();
return $this->dao->select('openID,account')->from(TABLE_OAUTH)
->where('providerType')->eq('gitlab')
->andWhere('providerID')->eq($gitlab)
->fetchPairs();
}
/**
@@ -68,7 +71,10 @@ class gitlabModel extends model
*/
public function getUserAccountIdPairs($gitlab)
{
return $this->dao->select('account,openID')->from(TABLE_OAUTH)->where('providerType')->eq('gitlab')->andWhere('providerID')->eq($gitlab)->fetchPairs();
return $this->dao->select('account,openID')->from(TABLE_OAUTH)
->where('providerType')->eq('gitlab')
->andWhere('providerID')->eq($gitlab)
->fetchPairs();
}
/**
@@ -659,6 +665,25 @@ class gitlabModel extends model
return json_decode(commonModel::http($url, $issue));
}
/**
* Update issue with new attribute using gitlab API.
*
* @param int $gitlabID
* @param int $projectID
* @param int $issueID
* @param object $attribute
* @access public
* @return object
*/
public function apiUpdateIssue($gitlabID, $projectID, $issueID, $attribute)
{
$apiRoot = $this->getApiRoot($gitlabID);
$apiPath = "/projects/{$projectID}/issues/{$issueID}";
$url = sprintf($apiRoot, $apiPath);
$response = json_decode(commonModel::http($url, $attribute, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT')));
return $response;
}
public function pushTask($gitlabID, $projectID, $task)
{
$task->label = $this->config->gitlab->taskLabel->name;
@@ -779,6 +804,15 @@ class gitlabModel extends model
->fetch('account');
}
public function getGitlabUserID($gitlabID, $account)
{
return $this->dao->select('openID')->from(TABLE_OAUTH)
->where('providerType')->eq('gitlab')
->andWhere('providerID')->eq($gitlabID)
->andWhere('account')->eq($account)
->fetch('openID');
}
/**
* Get gitlab issue from relation by object type and id.
*
+10
View File
@@ -1325,6 +1325,16 @@ class taskModel extends model
->autoCheck()
->check('left', 'float')
->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 != '')
{
// 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($oldTask, $task);
}