From 4cedcb2997aa92f3aaef0a5b7d3e5e9820538eba Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Mon, 27 Nov 2023 16:03:50 +0800 Subject: [PATCH] * Adjust method name and params. --- module/gitea/model.php | 2 +- module/gitlab/model.php | 2 +- .../test/model/getgitlablistbyaccount.php | 21 ------- module/gitlab/test/model/getlistbyaccount.php | 21 +++++++ module/gogs/model.php | 2 +- module/mr/control.php | 60 ++++++++----------- module/mr/model.php | 2 +- module/repo/model.php | 3 +- 8 files changed, 50 insertions(+), 63 deletions(-) delete mode 100755 module/gitlab/test/model/getgitlablistbyaccount.php create mode 100755 module/gitlab/test/model/getlistbyaccount.php diff --git a/module/gitea/model.php b/module/gitea/model.php index 0e48069538..eefba29b90 100644 --- a/module/gitea/model.php +++ b/module/gitea/model.php @@ -279,7 +279,7 @@ class giteaModel extends model * @access public * @return array */ - public function getGiteaListByAccount($account = '') + public function getListByAccount($account = '') { if(!$account) $account = $this->app->user->account; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index befb9e2cea..3e8e8d9be5 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -154,7 +154,7 @@ class gitlabModel extends model * @access public * @return array */ - public function getGitLabListByAccount($account = '') + public function getListByAccount($account = '') { if(!$account) $account = $this->app->user->account; diff --git a/module/gitlab/test/model/getgitlablistbyaccount.php b/module/gitlab/test/model/getgitlablistbyaccount.php deleted file mode 100755 index fe0a806f06..0000000000 --- a/module/gitlab/test/model/getgitlablistbyaccount.php +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env php -> 0 -使用已绑定一个gitlab服务器的用户查询 >> 1 -使用未绑定gitlab服务器的用户查询 >> 0 - -*/ - -$gitlab = $tester->loadModel('gitlab'); - -r(count($gitlab->getGitLabListByAccount())) && p() && e('0'); //默认admin用户查询绑定的gitlab服务器 -r(count($gitlab->getGitLabListByAccount('user3'))) && p() && e('1'); //使用已绑定一个gitlab服务器的用户查询 -r(count($gitlab->getGitLabListByAccount('test1'))) && p() && e('0'); //使用未绑定gitlab服务器的用户查询 \ No newline at end of file diff --git a/module/gitlab/test/model/getlistbyaccount.php b/module/gitlab/test/model/getlistbyaccount.php new file mode 100755 index 0000000000..62ade29ede --- /dev/null +++ b/module/gitlab/test/model/getlistbyaccount.php @@ -0,0 +1,21 @@ +#!/usr/bin/env php +> 0 +使用已绑定一个gitlab服务器的用户查询 >> 1 +使用未绑定gitlab服务器的用户查询 >> 0 + +*/ + +$gitlab = $tester->loadModel('gitlab'); + +r(count($gitlab->getListByAccount())) && p() && e('0'); //默认admin用户查询绑定的gitlab服务器 +r(count($gitlab->getListByAccount('user3'))) && p() && e('1'); //使用已绑定一个gitlab服务器的用户查询 +r(count($gitlab->getListByAccount('test1'))) && p() && e('0'); //使用未绑定gitlab服务器的用户查询 diff --git a/module/gogs/model.php b/module/gogs/model.php index 1dcb89b1e7..9a9549c2f0 100644 --- a/module/gogs/model.php +++ b/module/gogs/model.php @@ -226,7 +226,7 @@ class gogsModel extends model * @access public * @return array */ - public function getGogsListByAccount($account = '') + public function getListByAccount($account = '') { if(!$account) $account = $this->app->user->account; diff --git a/module/mr/control.php b/module/mr/control.php index c2fb114187..b83bec9302 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -1,4 +1,14 @@ + * @package mr + * @link https://www.zentao.net + */ class mr extends control { /** @@ -6,7 +16,7 @@ class mr extends control * @param string $moduleName * @param string $methodName */ - public function __construct($moduleName = '', $methodName = '') + public function __construct(string $moduleName = '', string $methodName = '') { parent::__construct($moduleName, $methodName); @@ -25,6 +35,7 @@ class mr extends control } /** + * 获取合并请求列表. * Browse mr. * * @param int $repoID @@ -38,14 +49,14 @@ class mr extends control * @access public * @return void */ - public function browse($repoID = 0, $mode = 'status', $param = 'opened', $objectID = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) + public function browse(int $repoID = 0, string $mode = 'status', string $param = 'opened', int $objectID = 0, string $orderBy = 'id_desc', int $recTotal = 0, int $recPerPage = 20, int $pageID = 1) { if($this->app->tab == 'execution') { $this->session->set('execution', $objectID); $execution = $this->loadModel('execution')->getByID($objectID); $features = $this->execution->getExecutionFeatures($execution); - if(!$features['devops']) return print($this->locate($this->createLink('execution', 'task', "objectID=$executionID"))); + if(!$features['devops']) return $this->locate($this->createLink('execution', 'task', "objectID=$executionID")); $this->loadModel('execution')->setMenu($objectID); } @@ -58,20 +69,13 @@ class mr extends control $this->app->loadClass('pager', true); $pager = new pager($recTotal, $recPerPage, $pageID); - $repoCount = $this->dao->select('*')->from(TABLE_REPO)->where('deleted')->eq('0') - ->andWhere('SCM')->in(array('Gitlab', 'Gitea', 'Gogs')) - ->andWhere('synced')->eq(1) - ->orderBy('id') - ->count(); - if($repoCount == 0) $this->locate($this->loadModel('repo')->createLink('create')); + $repoList = $this->loadModel('repo')->getListBySCM('Gitlab,Gitea,Gogs'); + if(empty($repoList)) $this->locate($this->loadModel('repo')->createLink('create')); + + if(!isset($repoList[$repoID]) $repoID = key($repoList); + $repoID = $this->repo->saveState($repoID, $objectID); + $repo = $repoList[$repoID]; - $repoID = $this->loadModel('repo')->saveState($repoID, $objectID); - $repo = $this->repo->getByID($repoID); - if(!in_array(strtolower($repo->SCM), $this->config->mr->gitServiceList)) - { - $repoID = $this->dao->select('id')->from(TABLE_REPO)->where('deleted')->eq('0')->andWhere('SCM')->in(array('Gitlab', 'Gitea', 'Gogs'))->andWhere('synced')->eq(1)->orderBy('id')->fetch('id'); - $repo = $this->repo->getByID($repoID); - } $this->loadModel('ci')->setMenu($repo->id); if($param == 'assignee' || $param == 'creator') @@ -109,23 +113,7 @@ class mr extends control /* Load lang from compile module */ $this->app->loadLang('compile'); - - $openIDList = array(); - if(!$this->app->user->admin) - { - if($repo->SCM == 'Gitlab') - { - $openIDList = $this->loadModel('gitlab')->getGitLabListByAccount($this->app->user->account); - } - elseif($repo->SCM == 'Gitea') - { - $openIDList = $this->loadModel('gitea')->getGiteaListByAccount($this->app->user->account); - } - elseif($repo->SCM == 'Gogs') - { - $openIDList = $this->loadModel('gogs')->getGogsListByAccount($this->app->user->account); - } - } + $openIDList = $this->app->user->admin ? array() : $this->loadModel(strtolower($repo->SCM))->getListByAccount($this->app->user->account); if($this->app->tab == 'execution') $this->view->executionID = $objectID; $this->view->title = $this->lang->mr->common . $this->lang->colon . $this->lang->mr->browse; @@ -200,9 +188,9 @@ class mr extends control $openIDList = array(); if(!$this->app->user->admin) { - $openIDList += $this->loadModel('gitlab')->getGitLabListByAccount($this->app->user->account); - $openIDList += $this->loadModel('gitea')->getGiteaListByAccount($this->app->user->account); - $openIDList += $this->loadModel('gogs')->getGogsListByAccount($this->app->user->account); + $openIDList += $this->loadModel('gitlab')->getListByAccount($this->app->user->account); + $openIDList += $this->loadModel('gitea')->getListByAccount($this->app->user->account); + $openIDList += $this->loadModel('gogs')->getListByAccount($this->app->user->account); } $this->view->title = $this->lang->mr->common . $this->lang->colon . $this->lang->mr->browse; diff --git a/module/mr/model.php b/module/mr/model.php index 549d5d5f70..0dffb99126 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -153,7 +153,7 @@ class mrModel extends model { $allProjects = array(); $allGroups = array(); - $gitlabUsers = $this->loadModel('gitlab')->getGitLabListByAccount(); + $gitlabUsers = $this->loadModel('gitlab')->getListByAccount(); if(!$this->app->user->admin and !isset($gitlabUsers[$hostID])) return array(); $minProject = $maxProject = 0; diff --git a/module/repo/model.php b/module/repo/model.php index b4bb002522..18b5c735d2 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -152,8 +152,7 @@ class repoModel extends model $repos = $this->dao->select('*')->from(TABLE_REPO)->where('deleted')->eq('0') ->andWhere('SCM')->in($scm) ->andWhere('synced')->eq(1) - ->orderBy('id') - ->fetchAll(); + ->fetchAll('id'); foreach($repos as $i => $repo) {