From 7f71a63468447dfbcfbbcd87001ebd706193abaa Mon Sep 17 00:00:00 2001 From: lichengjun Date: Wed, 1 Sep 2021 07:02:17 +0000 Subject: [PATCH] * Sync GitLab Todo ZenTao Todo. --- module/mr/model.php | 71 ++++++++++++++++++++++++++++++++++++++ module/todo/lang/zh-cn.php | 13 +++---- 2 files changed, 78 insertions(+), 6 deletions(-) diff --git a/module/mr/model.php b/module/mr/model.php index 1cba029e8f..20f3b4bb7d 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -218,10 +218,81 @@ class mrModel extends model $this->dao->update(TABLE_MR)->data($newMR) ->where('id')->eq($MR->id) ->exec(); + + /*Sync GitLab Todo ZenTao Todo. */ + + $gitlabTodoList = $this->apiTodoList($MR->gitlabID, $MR->targetProject); + if($gitlabTodoList) + { + foreach($gitlabTodoList as $do) + { + $todoDesc = $this->dao->select('*') + ->from(TABLE_TODO) + ->where('idvalue') + ->eq($do->id) + ->fetch(); + if(empty($todoDesc)) + { + $todo = new stdClass; + $todo->account = $this->app->user->account; + $todo->assignedTo = $this->app->user->account; + $todo->assignedBy = $this->app->user->account; + $todo->date = $do->target->created_at; + $todo->assignedDate = $do->target->created_at; + $todo->begin = $do->target->created_at; + $todo->end = ''; + $todo->type = 'mrapprove'; + $todo->idvalue = $do->id; + $todo->pri = 1; + $todo->name = $do->target->title; + $todo->desc = $do->target->description . "
" . $this->todoDescriptionLink($MR->gitlabID, $MR->targetProject); + $todo->private = 0; + $todo->config = 0; + $todo->finishedBy = ''; + $todo->finishedDate = ''; + $todo->closedBy = ''; + $todo->closedDate = '0000-00-00 00:00:00'; + $this->dao->insert(TABLE_TODO)->data($todo)->exec(); + } + } + } } return $this->dao->findByID($MR->id)->from(TABLE_MR)->fetch(); } + /** + * Get a list of to-do items. + * + * @docs https://docs.gitlab.com/ee/api/todos.html + * @param int $gitlabID + * @param int $projectID + * @access public + * @return object + */ + public function apiTodoList($gitlabID, $projectID) + { + $gitlab = $this->loadModel('gitlab')->getByID($gitlabID); + if(!$gitlab) return ''; + $url = rtrim($gitlab->url, '/')."/api/v4/todos?project_id=$projectID&type=MergeRequest&private_token={$gitlab->token}"; + return json_decode(commonModel::http($url)); + } + + /** + * Get a list of to-do items. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return object + */ + public function todoDescriptionLink($gitlabID, $projectID) + { + $gitlab = $this->loadModel('gitlab')->getByID($gitlabID); + if(!$gitlab) return ''; + return rtrim($gitlab->url, '/')."/dashboard/todos?project_id=$projectID&type=MergeRequest"; + } + + /** * Create MR by API. * diff --git a/module/todo/lang/zh-cn.php b/module/todo/lang/zh-cn.php index 18cfc39a1b..697ffa97c1 100644 --- a/module/todo/lang/zh-cn.php +++ b/module/todo/lang/zh-cn.php @@ -93,12 +93,13 @@ $lang->todo->priList[2] = 2; $lang->todo->priList[3] = 3; $lang->todo->priList[4] = 4; -$lang->todo->typeList['custom'] = '自定义'; -$lang->todo->typeList['cycle'] = '周期'; -$lang->todo->typeList['bug'] = 'Bug'; -$lang->todo->typeList['task'] = '任务'; -$lang->todo->typeList['story'] = $lang->SRCommon; -$lang->todo->typeList['testtask'] = '测试单'; +$lang->todo->typeList['custom'] = '自定义'; +$lang->todo->typeList['cycle'] = '周期'; +$lang->todo->typeList['bug'] = 'Bug'; +$lang->todo->typeList['task'] = '任务'; +$lang->todo->typeList['story'] = $lang->SRCommon; +$lang->todo->typeList['testtask'] = '测试单'; +$lang->todo->typeList['mrapprove'] = '合并请求审批'; $lang->todo->confirmDelete = "您确定要删除这条待办吗?"; $lang->todo->thisIsPrivate = '这是一条私人事务。:)';