diff --git a/module/repo/model.php b/module/repo/model.php index 8fe8418aff..6a94b14893 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -681,29 +681,7 @@ class repoModel extends model { if(empty($url)) return array('result' => 'fail', 'message' => 'Url is empty.'); - /* Convert to id by url. */ - $this->loadModel('gitlab'); - $matches = array(); - $parsedUrl = parse_url($url); - $isSSH = $parsedUrl['scheme'] == 'ssh'; - $baseURL = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . (isset($parsedUrl['port']) ? ":{$parsedUrl['port']}" : ''); - $url = str_replace('https://', 'http://', strtolower($url)); - $gitlabs = $this->loadModel('pipeline')->getList('gitlab'); - foreach($gitlabs as $gitlabID => $gitlab) - { - if((!$isSSH && $gitlab->url != $baseURL) || ($isSSH && strpos($gitlab->url, $parsedUrl['host']) === false)) - { - unset($gitlabs[$gitlabID]); - continue; - } - - $projects = $this->gitlab->apiGetProjects($gitlabID); - foreach($projects as $project) - { - $urlToRepo = str_replace('https://', 'http://', strtolower($project->http_url_to_repo)); - if((!$isSSH && $urlToRepo == $url) || ($isSSH && strtolower($project->ssh_url_to_repo) == $url)) $matches[] = array('gitlab' => $gitlabID, 'project' => $project->id); - } - } + $matches = $this->repoTao->getMatchedReposByUrl($url); if(empty($matches)) return array('result' => 'fail', 'message' => 'No matched gitlab.'); $conditions = array(); @@ -743,33 +721,11 @@ class repoModel extends model { if(empty($url)) return array('status' => 'fail', 'message' => 'Url is empty.'); - /* Convert to id by url. */ - $this->loadModel('gitlab'); - $matches = array(); - $parsedUrl = parse_url($url); - $isSSH = $parsedUrl['scheme'] == 'ssh'; - $baseURL = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . (isset($parsedUrl['port']) ? ":{$parsedUrl['port']}" : ''); - $url = str_replace('https://', 'http://', strtolower($url)); - $gitlabs = $this->loadModel('pipeline')->getList('gitlab'); - foreach($gitlabs as $gitlabID => $gitlab) - { - if((!$isSSH && $gitlab->url != $baseURL) || ($isSSH && strpos($gitlab->url, $parsedUrl['host']) === false)) - { - unset($gitlabs[$gitlabID]); - continue; - } - - $projects = $this->gitlab->apiGetProjects($gitlabID); - foreach($projects as $project) - { - $urlToRepo = str_replace('https://', 'http://', strtolower($project->http_url_to_repo)); - if((!$isSSH && $urlToRepo == $url) || ($isSSH && strtolower($project->ssh_url_to_repo) == $url)) $matches[] = array('gitlab' => $gitlabID, 'project' => $project->id); - } - } + $matches = $this->repoTao->getMatchedReposByUrl($url); if(empty($matches)) return array('status' => 'fail', 'message' => 'No matched gitlab.'); $conditions = array(); - foreach($matches as $matched) $conditions[] = "(`client`='$matched->gitlab' and `path`='{$matched['project']}')"; + foreach($matches as $matched) $conditions[] = "(`serviceHost`='{$matched['gitlab']}' and `serviceProject`='{$matched['project']}')"; $matchedRepos = $this->getListByCondition('(' . implode(' OR ', $conditions). ')', 'Gitlab'); foreach($matchedRepos as $key => $repo) @@ -1045,7 +1001,7 @@ class repoModel extends model public function getProductsByRepo(int $repoID): array { $repo = $this->getByID($repoID); - if(empty($repo)) return array(); + if(empty($repo->id)) return array(); return $this->dao->select('id,name')->from(TABLE_PRODUCT) ->where('id')->in($repo->product) diff --git a/module/repo/tao.php b/module/repo/tao.php index 1d9201e974..3d82b407d8 100644 --- a/module/repo/tao.php +++ b/module/repo/tao.php @@ -273,4 +273,41 @@ class repoTao extends repoModel array_multisort($pathName, SORT_ASC, $fileName, SORT_ASC, $treeList); return $treeList; } + + /** + * 根据url获取匹配得版本库。 + * Get matched repos by url. + * + * @param string $url + * @access protected + * @return array + */ + protected function getMatchedReposByUrl(string $url): array + { + /* Convert to id by url. */ + $this->loadModel('gitlab'); + $matches = array(); + $parsedUrl = parse_url($url); + $isSSH = $parsedUrl['scheme'] == 'ssh'; + $baseURL = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . (isset($parsedUrl['port']) ? ":{$parsedUrl['port']}" : ''); + $url = str_replace('https://', 'http://', strtolower($url)); + $gitlabs = $this->loadModel('pipeline')->getList('gitlab'); + foreach($gitlabs as $gitlabID => $gitlab) + { + if((!$isSSH && $gitlab->url != $baseURL) || ($isSSH && strpos($gitlab->url, $parsedUrl['host']) === false)) + { + unset($gitlabs[$gitlabID]); + continue; + } + + $projects = $this->gitlab->apiGetProjects($gitlabID); + foreach($projects as $project) + { + $urlToRepo = str_replace('https://', 'http://', strtolower($project->http_url_to_repo)); + if((!$isSSH && $urlToRepo == $url) || ($isSSH && strtolower($project->ssh_url_to_repo) == $url)) $matches[] = array('gitlab' => $gitlabID, 'project' => $project->id); + } + } + + return $matches; + } } diff --git a/module/repo/test/model/getrepolistbyurl.php b/module/repo/test/model/getrepolistbyurl.php index cbfedbe5de..5bfb36cca4 100644 --- a/module/repo/test/model/getrepolistbyurl.php +++ b/module/repo/test/model/getrepolistbyurl.php @@ -10,10 +10,30 @@ title=测试 repoModel->getRepoListByUrl(); timeout=0 cid=1 -- 执行repo模块的getRepoListByUrlTest方法 @ +- 使用空的url属性message @Url is empty. +- 使用错误的url属性message @No matched gitlab. +- 使用正确的url @return normal */ -$repo = new repoTest(); +zdTable('pipeline')->gen(5); +zdTable('repo')->config('repo')->gen(4); -r($repo->getRepoListByUrlTest()) && p() && e(); \ No newline at end of file +$repoModel = $tester->loadModel('repo'); + +$url = ''; +$result = $repoModel->getRepoListByUrl($url); +r($result) && p('message') && e('Url is empty.'); //使用空的url + +$url = 'http://192.168.1.161:51080/gitlab-instance-f9325ed1/azalea723test.git'; +$result = $repoModel->getRepoListByUrl($url); +r($result) && p('message') && e('No matched gitlab.'); //使用错误的url + +$url = 'https://gitlabdev.qc.oop.cc/gitlab-instance-76af86df/testhtml.git'; +$result = $repoModel->getRepoListByUrl($url); +if(!empty($result)) +{ + if($result['status'] == 'fail' and $result['message'] != 'No matched gitlab.') $result = 'return normal'; + if(is_array($result) and $result['status'] == 'success') $result = 'return normal'; +} +r($result) && p() && e('return normal'); //使用正确的url \ No newline at end of file diff --git a/module/repo/test/model/getrevisionsfromdb.php b/module/repo/test/model/getrevisionsfromdb.php index f25467371c..8f9c897feb 100644 --- a/module/repo/test/model/getrevisionsfromdb.php +++ b/module/repo/test/model/getrevisionsfromdb.php @@ -10,10 +10,30 @@ title=测试 repoModel->getRevisionsFromDB(); timeout=0 cid=1 -- 执行repo模块的getRevisionsFromDBTest方法 @ +- 获取提交记录 @ */ +zdTable('pipeline')->gen(5); +zdTable('repo')->config('repo')->gen(4); +zdTable('repohistory')->config('repohistory')->gen(3); + $repo = new repoTest(); -r($repo->getRevisionsFromDBTest()) && p() && e(); \ No newline at end of file +$repoID = 3; +$limit = 1; +$maxRevision = '0dbb150d4904c9a9d5a804b6cdddea3cb3d856bb'; +$minRevision = 'd30919bdb9b4cf8e2698f4a6a30e41910427c01c'; + +r($repo->getRevisionsFromDBTest($repoID)) && p('0dbb150d4904c9a9d5a804b6cdddea3cb3d856bb:id') && e('3'); //获取版本库提交记录 + +$result = $repo->getRevisionsFromDBTest($repoID, $limit); +r(count($result)) && p() && e('1'); //获取limit为1版本库提交记录数量 + +$result = $repo->getRevisionsFromDBTest($repoID, 0, $maxRevision, ''); +r($result) && p('0dbb150d4904c9a9d5a804b6cdddea3cb3d856bb:commit') && e('1'); // 获取maxrevision的列表 +r(count($result)) && p() && e('1'); // 获取maxrevision的列表数量 + +$result = $repo->getRevisionsFromDBTest($repoID, 0, '', $minRevision); +r($result) && p('d30919bdb9b4cf8e2698f4a6a30e41910427c01c:commit') && e('2'); // 获取minrevision的列表 +r(count($result)) && p() && e('1'); // 获取minrevision的列表数量 diff --git a/module/repo/test/model/getswitcher.php b/module/repo/test/model/getswitcher.php deleted file mode 100644 index 40322c761b..0000000000 --- a/module/repo/test/model/getswitcher.php +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env php -getSwitcher(); -cid=1 -pid=1 - -*/ - -$repo = new repoTest(); diff --git a/module/repo/test/model/gettaskproductsandexecutions.php b/module/repo/test/model/gettaskproductsandexecutions.php index cef2dfe8d4..6f1e0ac8d7 100644 --- a/module/repo/test/model/gettaskproductsandexecutions.php +++ b/module/repo/test/model/gettaskproductsandexecutions.php @@ -10,10 +10,24 @@ title=测试 repoModel->getTaskProductsAndExecutions(); timeout=0 cid=1 -- 执行repo模块的getTaskProductsAndExecutionsTest方法 @ +- 获取任务执行第1条的execution属性 @30 +- 获取任务产品第4条的product属性 @,23, +- 任务为空时获取列表 @0 */ -$repo = new repoTest(); +$task = zdTable('task'); +$task->execution->range('30-60'); +$task->gen(10); +zdTable('product')->gen(50); +zdTable('project')->gen(50); +zdTable('projectproduct')->gen(100); -r($repo->getTaskProductsAndExecutionsTest()) && p() && e(); \ No newline at end of file +$repo = $tester->loadModel('repo'); + +$taskIds = array(1, 2, 4); + +$result = $repo->getTaskProductsAndExecutions($taskIds); +r($result) && p('1:execution') && e('30'); //获取任务执行 +r($result) && p('4:product', ';') && e(',23,'); //获取任务产品 +r($repo->getTaskProductsAndExecutions(array())) && p() && e('0'); //任务为空时获取列表 \ No newline at end of file diff --git a/module/repo/test/model/getunsyncedcommits.php b/module/repo/test/model/getunsyncedcommits.php index 9812132853..e663d9987b 100644 --- a/module/repo/test/model/getunsyncedcommits.php +++ b/module/repo/test/model/getunsyncedcommits.php @@ -10,10 +10,31 @@ title=测试 repoModel->getUnsyncedCommits(); timeout=0 cid=1 -- 执行repo模块的getUnsyncedCommitsTest方法 @ +- 获取gitlab版本库未同步commit属性revision @2e0dd521b4a29930d5670a2c142a4400d7cffc1a +- 获取gitlab版本库未同步commit file数量 @1 +- 获取gitlab版本库未同步commit数量 @1 +- 获取svn版本库未同步commit属性comment @+ Add file. +- 获取svn版本库未同步commit file数量 @1 +- 获取svn版本库未同步commit数量 @1 */ +zdTable('pipeline')->gen(5); +zdTable('repo')->config('repo')->gen(4); + $repo = new repoTest(); -r($repo->getUnsyncedCommitsTest()) && p() && e(); \ No newline at end of file +$gitlabID = 1; +$svnID = 4; + +$result = $repo->getUnsyncedCommitsTest($gitlabID); +$oneCommit = array_shift($result); +r($oneCommit) && p('revision') && e('2e0dd521b4a29930d5670a2c142a4400d7cffc1a'); //获取gitlab版本库未同步commit +r(count($oneCommit->files['A']) > 2) && p() && e('1'); //获取gitlab版本库未同步commit file数量 +r(count($result) > 2) && p() && e('1'); //获取gitlab版本库未同步commit数量 + +$result = $repo->getUnsyncedCommitsTest($svnID); +$oneCommit = array_shift($result); +r($oneCommit) && p('comment') && e('+ Add file.'); //获取svn版本库未同步commit +r(count($oneCommit->files['A']) > 0) && p() && e('1'); //获取svn版本库未同步commit file数量 +r(count($result) > 1) && p() && e('1'); //获取svn版本库未同步commit数量 \ No newline at end of file diff --git a/module/repo/test/model/parsecomment.php b/module/repo/test/model/parsecomment.php index 1a2b0e41be..82e851970f 100644 --- a/module/repo/test/model/parsecomment.php +++ b/module/repo/test/model/parsecomment.php @@ -10,10 +10,36 @@ title=测试 repoModel->parseComment(); timeout=0 cid=1 -- 执行repo模块的parseCommentTest方法 @ +- 解析完成任务第tasks条的8属性 @8 +- 解析完成多个任务 + - 第tasks条的1属性 @1 + - 第tasks条的8属性 @8 + - 第tasks条的12属性 @12 +- 解析修复bug第bugs条的3属性 @3 +- 解析修复多个bug + - 第bugs条的3属性 @3 + - 第bugs条的5属性 @5 + - 第bugs条的12属性 @12 +- 解析需求第stories条的1属性 @1 +- 解析多个需求 + - 第stories条的1属性 @1 + - 第stories条的2属性 @2 + - 第stories条的3属性 @3 */ $repo = new repoTest(); -r($repo->parseCommentTest()) && p() && e(); \ No newline at end of file +$finishTaskComment = 'Finish task#8.'; +$finishTaskComment2 = 'Finish task#1,8,12.'; +$fixBugComment = 'Fix bug#3'; +$fixBugComment2 = 'Fix bug#3,5,12'; +$storyComment = 'Story#1'; +$storyComment2 = 'Story#1,2,3'; + +r($repo->parseCommentTest($finishTaskComment)) && p('tasks:8') && e('8'); //解析完成任务 +r($repo->parseCommentTest($finishTaskComment2)) && p('tasks:1,8,12') && e('1,8,12'); //解析完成多个任务 +r($repo->parseCommentTest($fixBugComment)) && p('bugs:3') && e('3'); //解析修复bug +r($repo->parseCommentTest($fixBugComment2)) && p('bugs:3,5,12') && e('3,5,12'); //解析修复多个bug +r($repo->parseCommentTest($storyComment)) && p('stories:1') && e('1'); //解析需求 +r($repo->parseCommentTest($storyComment2)) && p('stories:1,2,3') && e('1,2,3'); //解析多个需求 \ No newline at end of file diff --git a/module/repo/test/model/replacecommentlink.php b/module/repo/test/model/replacecommentlink.php index 3a07ee4606..321d750b68 100644 --- a/module/repo/test/model/replacecommentlink.php +++ b/module/repo/test/model/replacecommentlink.php @@ -10,10 +10,29 @@ title=测试 repoModel->replaceCommentLink(); timeout=0 cid=1 -- 执行repo模块的replaceCommentLinkTest方法 @ +- 替换完成任务 @Finish task #8. +- 替换完成多个任务 @Finish task #1,8,12. + +- 替换修复bug @Fix bug #3 +- 替换修复多个bug @Fix bug #3,5,12 + +- 替换需求 @Story #1 +- 替换多个需求 @Story #1,2,3 */ -$repo = new repoTest(); +$repo = new repotest(); -r($repo->replaceCommentLinkTest()) && p() && e(); \ No newline at end of file +$finishTaskComment = 'Finish task#8.'; +$finishTaskComment2 = 'Finish task#1,8,12.'; +$fixBugComment = 'Fix bug#3'; +$fixBugComment2 = 'Fix bug#3,5,12'; +$storyComment = 'Story#1'; +$storyComment2 = 'Story#1,2,3'; + +r($repo->replaceCommentLinkTest($finishTaskComment)) && p() && e("Finish task #8."); //替换完成任务 +r($repo->replaceCommentLinkTest($finishTaskComment2)) && p() && e("Finish task #1,8,12."); //替换完成多个任务 +r($repo->replaceCommentLinkTest($fixBugComment)) && p() && e("Fix bug #3"); //替换修复bug +r($repo->replaceCommentLinkTest($fixBugComment2)) && p() && e("Fix bug #3,5,12"); //替换修复多个bug +r($repo->replaceCommentLinkTest($storyComment)) && p() && e("Story #1"); //替换需求 +r($repo->replaceCommentLinkTest($storyComment2)) && p() && e("Story #1,2,3"); //替换多个需求 \ No newline at end of file diff --git a/module/repo/test/model/savecommit.php b/module/repo/test/model/savecommit.php index 3548af2c13..f7abcc980c 100644 --- a/module/repo/test/model/savecommit.php +++ b/module/repo/test/model/savecommit.php @@ -10,7 +10,10 @@ title=测试 repoModel->saveCommit(); timeout=0 cid=1 -- 执行repo模块的saveCommitTest方法 @ +- 保存版gitlab版本库commit @5 +- 保存版gitlab版本库commit第5条的commit属性 @10 +- 保存版svn版本库commit @3 +- 查看svn版本库files @1 */ @@ -29,4 +32,4 @@ r($repo->saveCommitTest($gitlabID, $version2)) && p('5:commit') && e('10'); // $result = $repo->saveCommitTest($svnID, $version); r($result['count']) && p() && e('3'); //保存版svn版本库commit -r(count($result['files']) > 0) && p() && e('1'); //查看svn版本库files +r(count($result['files']) > 0) && p() && e('1'); //查看svn版本库files \ No newline at end of file diff --git a/module/repo/test/repo.class.php b/module/repo/test/repo.class.php index 7ca5375a41..8fe69d46c0 100644 --- a/module/repo/test/repo.class.php +++ b/module/repo/test/repo.class.php @@ -243,9 +243,9 @@ class repoTest return $objects; } - public function getRevisionsFromDBTest($repoID, $limit = '', $maxRevision = '', $minRevision = '') + public function getRevisionsFromDBTest(int $repoID, int $limit = 0, string $maxRevision = '', string $minRevision = '') { - $objects = $this->objectModel->getRevisionsFromDB($repoID, $limit = '', $maxRevision = '', $minRevision = ''); + $objects = $this->objectModel->getRevisionsFromDB($repoID, $limit, $maxRevision, $minRevision); if(dao::isError()) return dao::getError(); @@ -344,8 +344,13 @@ class repoTest return $this->objectModel->getByID($repoID); } - public function getUnsyncedCommitsTest($repo) + public function getUnsyncedCommitsTest(int $repoID) { + global $dao; + $dao->exec('truncate table zt_repohistory'); + + $repo = $this->objectModel->getByID($repoID); + $objects = $this->objectModel->getUnsyncedCommits($repo); if(dao::isError()) return dao::getError(); @@ -428,11 +433,14 @@ class repoTest public function replaceCommentLinkTest($comment) { + $this->objectModel->config->webRoot = ''; + $this->objectModel->config->requestType = 'PATH_INFO'; + $objects = $this->objectModel->replaceCommentLink($comment); if(dao::isError()) return dao::getError(); - return $objects; + return str_replace(PHP_EOL, '', $objects); } public function addLinkTest($comment, $type)