From 86c7e9b4ccd86f09318cdb5bc18bcbfb84f42c1a Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 24 Jun 2021 14:56:23 +0800 Subject: [PATCH] + Add funcs to update issue when the assigned user changed in task. --- module/gitlab/model.php | 38 ++++++++++++++++++++++++++++++++++++-- module/task/model.php | 10 ++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 00716526d5..31e37a404c 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -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. * diff --git a/module/task/model.php b/module/task/model.php index 329799e567..f465c053d9 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -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); }