* Adjust sonarqube unit test.
This commit is contained in:
@@ -7,24 +7,23 @@ su('admin');
|
||||
/**
|
||||
|
||||
title=测试 sonarqubeModel::apiCreateProject();
|
||||
timeout=0
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
使用空的sonarqubeID、项目对象创建sonarqube项目 >> return false
|
||||
使用空的sonarqubeID、正确的项目对象创建sonarqube项目 >> return false
|
||||
使用正确的sonarqubeID,项目对象创建sonarqube项目 >> unit test
|
||||
使用重复的项目对象创建sonarqube项目 >> Could not create Project, key already exists: unit_test
|
||||
- 使用空的sonarqubeID、项目对象创建sonarqube项目 @return false
|
||||
- 使用空的sonarqubeID、正确的项目对象创建sonarqube项目 @return false
|
||||
- 使用正确的sonarqubeID,项目对象创建sonarqube项目 @1
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->config('pipeline')->gen(5);
|
||||
|
||||
$sonarqubeID = 2;
|
||||
|
||||
$t_empty_project = array();
|
||||
$t_project = array('projectName' => 'unit_test', 'projectKey' => 'unit_test');
|
||||
$t_project = array('projectName' => 'unit_test17', 'projectKey' => 'unittest17');
|
||||
|
||||
$sonarqube = new sonarqubeTest();
|
||||
r($sonarqube->apiCreateProjectTest(0, $t_empty_project)) && p() && e('return false'); //使用空的sonarqubeID、项目对象创建sonarqube项目
|
||||
r($sonarqube->apiCreateProjectTest(0, $t_project)) && p() && e('return false'); //使用空的sonarqubeID、正确的项目对象创建sonarqube项目
|
||||
$sonarqube->apiDeleteProjectTest($sonarqubeID, 'unit_test');
|
||||
r($sonarqube->apiCreateProjectTest($sonarqubeID, $t_project)) && p('project:key') && e('unit test'); //使用正确的sonarqubeID,项目对象创建sonarqube项目
|
||||
r($sonarqube->apiCreateProjectTest($sonarqubeID, $t_project)) && p('0:msg') && e("Could not create Project, key already exists: unit_test"); //使用重复的项目对象创建sonarqube项目
|
||||
r($sonarqube->apiCreateProjectTest(0, $t_empty_project)) && p() && e('return false'); //使用空的sonarqubeID、项目对象创建sonarqube项目
|
||||
r($sonarqube->apiCreateProjectTest(0, $t_project)) && p() && e('return false'); //使用空的sonarqubeID、正确的项目对象创建sonarqube项目
|
||||
r($sonarqube->apiCreateProjectTest($sonarqubeID, $t_project)) && p() && e('1'); //使用正确的sonarqubeID,项目对象创建sonarqube项目
|
||||
@@ -7,21 +7,24 @@ su('admin');
|
||||
/**
|
||||
|
||||
title=测试 sonarqubeModel::apiDeleteProject();
|
||||
timeout=0
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
通过不正确的sonarqubeID、projectKey,删除SonarQube项目 >> return false
|
||||
正确的sonarqubeID,空的projectKey,删除SonarQube项目 >> The 'project' parameter is missing
|
||||
正确的sonarqubeID,不存在的projectKey,删除SonarQube项目 >> Project 'no_project' not found
|
||||
正确的sonarqubeID、projectKey,删除SonarQube项目 >> return true
|
||||
- 通过不正确的sonarqubeID、projectKey,删除SonarQube项目 @return false
|
||||
- 正确的sonarqubeID,空的projectKey,删除SonarQube项目第0条的msg属性 @The 'project' parameter is missing
|
||||
- 正确的sonarqubeID,不存在的projectKey,删除SonarQube项目第0条的msg属性 @Project 'no_project' not found
|
||||
- 正确的sonarqubeID、projectKey,删除SonarQube项目 @return true
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->config('pipeline')->gen(5);
|
||||
|
||||
$sonarqubeID = 2;
|
||||
|
||||
$t_empty_projectkey = '';
|
||||
$t_no_projectkey = 'no_project';
|
||||
$t_projectkey = 'new_project';
|
||||
$t_projectkey = 'unittest17';
|
||||
$t_projectName = 'unit_test17';
|
||||
|
||||
$sonarqube = new sonarqubeTest();
|
||||
r($sonarqube->apiDeleteProjectTest(0, $t_empty_projectkey)) && p() && e('return false'); //通过不正确的sonarqubeID、projectKey,删除SonarQube项目
|
||||
|
||||
@@ -7,19 +7,22 @@ su('admin');
|
||||
/**
|
||||
|
||||
title=测试 sonarqubeModel::apiGetIssues();
|
||||
timeout=0
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
通过sonarqubeID,获取SonarQube问题列表 >> 1
|
||||
通过sonarqubeID,项目key获取SonarQube问题列表 >> 1
|
||||
当sonarqubeID为0时,获取SonarQube问题列表 >> return empty
|
||||
- 通过sonarqubeID,项目key获取SonarQube问题列表 @1
|
||||
- 通过sonarqubeID,项目key获取SonarQube问题列表数量 @1
|
||||
- 当sonarqubeID为0时,获取SonarQube问题列表 @return empty
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->config('pipeline')->gen(5);
|
||||
|
||||
$sonarqubeID = 2;
|
||||
$projectKey = 'zentaopms';
|
||||
$projectKey = 'bendi';
|
||||
|
||||
$sonarqube = new sonarqubeTest();
|
||||
r($sonarqube->apiGetIssuesTest($sonarqubeID)) && p() && e('1'); //通过sonarqubeID,获取SonarQube问题列表
|
||||
r($sonarqube->apiGetIssuesTest($sonarqubeID, $projectKey)) && p() && e('1'); //通过sonarqubeID,项目key获取SonarQube问题列表
|
||||
r($sonarqube->apiGetIssuesTest(0)) && p() && e('return empty'); //当sonarqubeID为0时,获取SonarQube问题列表
|
||||
$result = $sonarqube->apiGetIssuesTest($sonarqubeID, $projectKey);
|
||||
r(isset($result[0]->message)) && p() && e('1'); //通过sonarqubeID,项目key获取SonarQube问题列表
|
||||
r(count($result) > 100) && p() && e('1'); //通过sonarqubeID,项目key获取SonarQube问题列表数量
|
||||
r($sonarqube->apiGetIssuesTest(0)) && p() && e('return empty'); //当sonarqubeID为0时,获取SonarQube问题列表
|
||||
@@ -7,21 +7,24 @@ su('admin');
|
||||
/**
|
||||
|
||||
title=测试 sonarqubeModel::apiGetProjects();
|
||||
timeout=0
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
通过sonarqubeID,获取SonarQube项目列表 >> 1
|
||||
通过sonarqubeID,获取SonarQube项目数量 >> 1
|
||||
通过sonarqubeID,关键字,搜索获取SonarQube项目 >> 1
|
||||
当sonarqubeID为0时,获取SonarQube项目列表 >> return empty
|
||||
- 通过sonarqubeID,获取SonarQube项目列表 @1
|
||||
- 通过sonarqubeID,获取SonarQube项目数量 @1
|
||||
- 通过sonarqubeID,关键字,搜索获取SonarQube项目第0条的name属性 @unittest
|
||||
- 当sonarqubeID为0时,获取SonarQube项目列表 @return empty
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->config('pipeline')->gen(5);
|
||||
|
||||
$sonarqubeID = 2;
|
||||
$keyword = '02';
|
||||
$keyword = 'unit';
|
||||
|
||||
$sonarqube = new sonarqubeTest();
|
||||
r($sonarqube->apiGetProjectsTest($sonarqubeID)) && p() && e('1'); //通过sonarqubeID,获取SonarQube项目列表
|
||||
r(count($sonarqube->apiGetProjectsTest($sonarqubeID)) > 0) && p() && e('1'); //通过sonarqubeID,获取SonarQube项目数量
|
||||
r($sonarqube->apiGetProjectsTest($sonarqubeID, $keyword)) && p() && e('1'); //通过sonarqubeID,关键字,搜索获取SonarQube项目
|
||||
r($sonarqube->apiGetProjectsTest(0)) && p() && e('return empty'); //当sonarqubeID为0时,获取SonarQube项目列表
|
||||
$result = $sonarqube->apiGetProjectsTest($sonarqubeID);
|
||||
r(isset($result[0]->name)) && p() && e('1'); //通过sonarqubeID,获取SonarQube项目列表
|
||||
r(count($result) > 1) && p() && e('1'); //通过sonarqubeID,获取SonarQube项目数量
|
||||
r($sonarqube->apiGetProjectsTest($sonarqubeID, $keyword)) && p('0:name') && e('unittest'); //通过sonarqubeID,关键字,搜索获取SonarQube项目
|
||||
r($sonarqube->apiGetProjectsTest(0)) && p() && e('return empty'); //当sonarqubeID为0时,获取SonarQube项目列表
|
||||
@@ -5,15 +5,17 @@ include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
/**
|
||||
|
||||
title=测试 sonarqubeModel::apiGetQualitygate();
|
||||
timeout=0
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
通过错误的sonarqubeID、projectKey,查询sonarqube质量门信息 >> return empty
|
||||
通过正确的sonarqubeID,不存在的projectKey查询sonarqube质量门信息 >> Project 'wrong_project' not found
|
||||
通过正确的sonarqubeID、projectKey查询sonarqube质量门信息 >> success
|
||||
- 通过错误的sonarqubeID、projectKey,查询sonarqube质量门信息 @return empty
|
||||
- 通过正确的sonarqubeID,不存在的projectKey查询sonarqube质量门信息第0条的msg属性 @Project 'wrong_project' not found
|
||||
- 通过正确的sonarqubeID、projectKey查询sonarqube质量门信息 @success
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->config('pipeline')->gen(5);
|
||||
|
||||
$sonarqube = $tester->loadModel('sonarqube');
|
||||
|
||||
$sonarqubeID = 0;
|
||||
@@ -27,7 +29,7 @@ $projectKey = 'wrong_project';
|
||||
$result = $sonarqube->apiGetQualitygate($sonarqubeID, $projectKey);
|
||||
r($result->errors) && p('0:msg') && e("Project 'wrong_project' not found"); //通过正确的sonarqubeID,不存在的projectKey查询sonarqube质量门信息
|
||||
|
||||
$projectKey = 'zentaopms';
|
||||
$result = $sonarqube->apiGetReport($sonarqubeID, $projectKey);
|
||||
if(!empty($result->component)) $result = 'success';
|
||||
$projectKey = 'unittest';
|
||||
$result = $sonarqube->apiGetQualitygate($sonarqubeID, $projectKey);
|
||||
if(!empty($result->projectStatus)) $result = 'success';
|
||||
r($result) && p() && e("success"); //通过正确的sonarqubeID、projectKey查询sonarqube质量门信息
|
||||
@@ -5,16 +5,18 @@ include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
/**
|
||||
|
||||
title=测试 sonarqubeModel::apiGetReport();
|
||||
timeout=0
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
通过错误的sonarqubeID、projectKey,查询sonarqube报告 >> return empty
|
||||
通过正确的sonarqubeID,不存在的projectKey查询sonarqube报告 >> Component key 'wrong_project' not found
|
||||
通过正确的sonarqubeID、projectKey,不正确的metricKeys查询sonarqube报告 >> The following metric keys are not found: wrong_params
|
||||
通过正确的sonarqubeID、projectKey、metricKeys,查询sonarqube报告 >> success
|
||||
- 通过错误的sonarqubeID、projectKey,查询sonarqube报告 @return empty
|
||||
- 通过正确的sonarqubeID,不存在的projectKey查询sonarqube报告第0条的msg属性 @Component key 'wrong_project' not found
|
||||
- 通过正确的sonarqubeID、projectKey,不正确的metricKeys查询sonarqube报告第0条的msg属性 @The following metric keys are not found: wrong_params
|
||||
- 通过正确的sonarqubeID、projectKey、metricKeys,查询sonarqube报告 @success
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->config('pipeline')->gen(5);
|
||||
|
||||
$sonarqube = $tester->loadModel('sonarqube');
|
||||
|
||||
$sonarqubeID = 0;
|
||||
@@ -28,7 +30,7 @@ $projectKey = 'wrong_project';
|
||||
$result = $sonarqube->apiGetReport($sonarqubeID, $projectKey);
|
||||
r($result->errors) && p('0:msg') && e("Component key 'wrong_project' not found"); //通过正确的sonarqubeID,不存在的projectKey查询sonarqube报告
|
||||
|
||||
$projectKey = 'zentaopms';
|
||||
$projectKey = 'unittest';
|
||||
$metricKeys = 'wrong_params';
|
||||
$result = $sonarqube->apiGetReport($sonarqubeID, $projectKey, $metricKeys);
|
||||
r($result->errors) && p('0:msg') && e("The following metric keys are not found: wrong_params"); //通过正确的sonarqubeID、projectKey,不正确的metricKeys查询sonarqube报告
|
||||
|
||||
@@ -7,15 +7,17 @@ su('admin');
|
||||
/**
|
||||
|
||||
title=测试 sonarqubeModel::apiValidate();
|
||||
timeout=0
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
通过host,token检验api权限 >> success
|
||||
通过正确的host,错误的token获取api权限 >> return false
|
||||
通过正确的host,非管理员权限的token获取api权限 >> return false
|
||||
- 通过host,token检验api权限 @success
|
||||
- 通过正确的host,错误的token获取api权限 @return false
|
||||
- 通过正确的host,非管理员权限的token获取api权限 @return false
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->config('pipeline')->gen(5);
|
||||
|
||||
$sonarqubeID = 2;
|
||||
|
||||
$errorToken = 'abc';
|
||||
|
||||
@@ -7,24 +7,24 @@ su('admin');
|
||||
/**
|
||||
|
||||
title=测试 sonarqubeModel::createProject();
|
||||
timeout=0
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
使用空的项目数据,空的sonarqubeID创建Sonarqube项目 >> 『项目名称』不能为空
|
||||
使用错误项目数据,正确的sonarqubeID创建Sonarqube项目 >> return error
|
||||
使用正确的项目数据,空的sonarqubeID创建Sonarqube项目 >> return false
|
||||
- 使用错误项目数据,正确的sonarqubeID创建Sonarqube项目 @return error
|
||||
- 使用正确的项目数据,空的sonarqubeID创建Sonarqube项目 @return false
|
||||
- 使用正确的sonarqubeID和Sonarqube项目信息创建Sonarqube项目 @1
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->config('pipeline')->gen(5);
|
||||
|
||||
$sonarqubeID = 2;
|
||||
|
||||
$empty_post = array('projectName' => '', 'projectKey' => '');
|
||||
$error_post = array('projectName' => 'unit_test', 'projectKey' => '@#');
|
||||
$true_post = array('projectName' => 'unit_test', 'projectKey' => 'unit_test');
|
||||
$true_post = array('projectName' => 'unit_test17', 'projectKey' => 'unittest17');
|
||||
|
||||
$sonarqube = new sonarqubeTest();
|
||||
r($sonarqube->createProjectTest(0, $empty_post)) && p('projectName:0') && e('『项目名称』不能为空'); //使用空的项目数据,空的sonarqubeID创建Sonarqube项目
|
||||
r($sonarqube->createProjectTest($sonarqubeID, $error_post)) && p() && e("return error"); //使用错误项目数据,正确的sonarqubeID创建Sonarqube项目
|
||||
r($sonarqube->createProjectTest(0, $true_post)) && p() && e('return false'); //使用正确的项目数据,空的sonarqubeID创建Sonarqube项目
|
||||
$sonarqube->apiDeleteProjectTest($sonarqubeID, 'unit_test');
|
||||
r($sonarqube->createProjectTest($sonarqubeID, $true_post)) && p() && e(1); //使用正确的sonarqubeID和Sonarqube项目信息创建Sonarqube项目
|
||||
@@ -7,16 +7,18 @@ su('admin');
|
||||
/**
|
||||
|
||||
title=测试 sonarqubeModel::getApiBase();
|
||||
timeout=0
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
通过sonarqubeID,获取SonarQube url和header >> http://192.168.1.161:59001/api/%s
|
||||
当sonarqubeID为0时,获取SonarQube url和header >> return empty
|
||||
- 通过sonarqubeID,获取SonarQube url和header @https://sonardev.qc.oop.cc/api/%s
|
||||
- 当sonarqubeID为0时,获取SonarQube url和header @return empty
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
|
||||
$sonarqubeID = 2;
|
||||
|
||||
$sonarqube = new sonarqubeTest();
|
||||
r($sonarqube->getApiBaseTest($sonarqubeID)) && p() && e('http://192.168.1.161:59001/api/%s'); //通过sonarqubeID,获取SonarQube url和header
|
||||
r($sonarqube->getApiBaseTest($sonarqubeID)) && p() && e('https://sonardev.qc.oop.cc/api/%s'); //通过sonarqubeID,获取SonarQube url和header
|
||||
r($sonarqube->getApiBaseTest(0)) && p() && e('return empty'); //当sonarqubeID为0时,获取SonarQube url和header
|
||||
@@ -7,13 +7,15 @@ su('admin');
|
||||
/**
|
||||
|
||||
title=测试 sonarqubeModel::getCacheFile();
|
||||
timeout=0
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
|
||||
- 使用正确的sonarqubeID,项目key获取缓存文件 @1
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->config('pipeline')->gen(5);
|
||||
|
||||
$sonarqubeID = 2;
|
||||
$projectKey = 'unit_test';
|
||||
|
||||
|
||||
@@ -5,14 +5,17 @@ include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
/**
|
||||
|
||||
title=测试 sonarqubeModel::getLinkedProducts();
|
||||
timeout=0
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
通过错误的sonarqubeID和projectKey获取关联产品ID >> return false
|
||||
通过正确的sonarqubeID和projectKey获取关联产品ID >> 1
|
||||
- 通过错误的sonarqubeID和projectKey获取关联产品ID @return false
|
||||
- 通过正确的sonarqubeID和projectKey获取关联产品ID @1
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->config('pipeline')->gen(5);
|
||||
zdTable('job')->gen(5);
|
||||
|
||||
$sonarqube = $tester->loadModel('sonarqube');
|
||||
|
||||
$sonarqubeID = 0;
|
||||
@@ -24,4 +27,4 @@ r($result) && p() && e('return false'); //通过错误的sonarqubeID和projectKe
|
||||
$sonarqubeID = 2;
|
||||
$projectKey = 'zentaopms';
|
||||
$result = $sonarqube->getLinkedProducts($sonarqubeID, $projectKey);
|
||||
r($result) && p() && e('1'); //通过正确的sonarqubeID和projectKey获取关联产品ID
|
||||
r($result) && p() && e('1'); //通过正确的sonarqubeID和projectKey获取关联产品ID
|
||||
|
||||
@@ -13,21 +13,24 @@ class sonarqubeTest
|
||||
$result = $this->objectModel->apiCreateProject($sonarqubeID, (object)$project);
|
||||
|
||||
if($result === false) $result = 'return false';
|
||||
if(isset($result->errors)) $result = $result->errors;
|
||||
if(isset($result->errors))
|
||||
{
|
||||
$result = $result->errors;
|
||||
if($result[0]->msg == 'Could not create Project with key: "' . $project['projectKey'] . '". A similar key already exists: "' . $project['projectKey'] . '"') return true;
|
||||
}
|
||||
if(isset($result->name) && $result->name == $project['projectName']) return true;
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function createProjectTest($sonarqubeID, $post)
|
||||
{
|
||||
$_POST['projectName'] = $post['projectName'];
|
||||
$_POST['projectKey'] = $post['projectKey'];
|
||||
|
||||
$result = $this->objectModel->createProject($sonarqubeID);
|
||||
$result = $this->objectModel->createProject($sonarqubeID, (object)$post);
|
||||
$errors = dao::getError();
|
||||
if($errors)
|
||||
{
|
||||
if(current($errors) == "项目标识的格式不正确。允许的字符为字母、数字、'-'、''、'.'和“:”,至少有一个非数字。") return 'return error';
|
||||
if(current($errors) == false) return 'return false';
|
||||
if(current($errors['name']) == "项目标识的格式不正确。允许的字符为字母、数字、'-'、''、'.'和“:”,至少有一个非数字。") return 'return error';
|
||||
if(current($errors['name']) == false) return 'return false';
|
||||
if(current($errors['name']) == 'Could not create Project with key: "' . $post['projectKey'] . '". A similar key already exists: "' . $post['projectKey'] . '"') return true;
|
||||
return $errors;
|
||||
}
|
||||
else
|
||||
@@ -52,7 +55,6 @@ class sonarqubeTest
|
||||
$result = $this->objectModel->apiGetIssues($sonarqubeID, $projectKey);
|
||||
|
||||
if(empty($result)) $result = 'return empty';
|
||||
if(isset($result[0]->message)) $result = true;
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -61,8 +63,6 @@ class sonarqubeTest
|
||||
$result = $this->objectModel->apiGetProjects($sonarqubeID, $keyword);
|
||||
|
||||
if(empty($result)) $result = 'return empty';
|
||||
if($keyword == '' and isset($result[0]->name)) $result = true;
|
||||
if($keyword != '' and strpos($result[0]->name, $keyword) !== false) $result = true;
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ class sonarqubeTest
|
||||
return $apiRoot;
|
||||
}
|
||||
|
||||
public function getCacheFile($sonarqubeID, $projectKey)
|
||||
public function getCacheFileTest($sonarqubeID, $projectKey)
|
||||
{
|
||||
$result = $this->objectModel->getCacheFile($sonarqubeID, $projectKey);
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
title: zt_pipeline
|
||||
author: Zeng gang
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: id
|
||||
range: 1-6
|
||||
- field: type
|
||||
range: gitlab,sonarqube,jenkins,gitea,gogs,nexus
|
||||
- field: name
|
||||
range: GitLab服务器,SonarQube服务器,Jenkins服务器,Gitea服务器,Gogs服务器,Nexus服务器
|
||||
- field: url
|
||||
range: "[https://gitlabdev.qc.oop.cc],[https://sonardev.qc.oop.cc],[https://jenkinsdev.qc.oop.cc],[https://giteadev.qc.oop.cc],[https://gogsdev.qc.oop.cc],[https://nexus3dev.qc.oop.cc]"
|
||||
- field: account
|
||||
range: "root,sonar,jenkins,gitea,gogs-admin,admin"
|
||||
- field: password
|
||||
range: "[bGFjdTdCSUgwTEljY21tbnZRQUs=],[a2tHQXpFMXA5cE9vcUpBOWJMSWg=],[MXJZN1JWREEyQlZrak81ME9qTUo=],[UGNVb1dhSFE1aUp6ZTl5RU9WYmk=],[RUgwM3ByWDJWUWVnOGRha1Fnc2g=],[TTV6c0dWemZUVDdMWGNoeFozN3I=]"
|
||||
- field: token
|
||||
range: '[glpat-b8Sa1pM9k9ygxMZYPN6w],[c29uYXI6a2tHQXpFMXA5cE9vcUpBOWJMSWg=],[11eb8b38c99143c7c6d872291e291abff4],[6149a6013047301b116389d50db5cbf599772082],[6aafc3d332b70312a680fedf26039c67e98cfabe],[d0b31569-1f36-3b0e-a8a0-c556e5627a3e]'
|
||||
- field: private
|
||||
range: 08bcc98f75d7d40053dc80722bdc117b,228b25587479f2fc7570428e8bcbabdc,ec8e41481723685d9106c88be5967c41,a56af13f4c4a6a4ed77f24e59794cf39,4fabcbd31314365506ebc56c0c83c1ec
|
||||
- field: createdBy
|
||||
range: admin
|
||||
- field: createdDate
|
||||
range: "[2022-08-01 09:09:37]"
|
||||
- field: deleted
|
||||
range: 0
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* The zen file of sonarqube module of ZenTaoPMS.
|
||||
*
|
||||
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
|
||||
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
|
||||
* @author Gang Zeng<zenggang@easycorp.ltd>
|
||||
* @package sonarqube
|
||||
* @link https://www.zentao.net
|
||||
*/
|
||||
class sonarqubeZen extends sonarqube
|
||||
{
|
||||
/**
|
||||
* 检查token必须数据。
|
||||
* Check token required data.
|
||||
*
|
||||
* @param object $sonarqube
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function checkTokenRequire(object $sonarqube): void
|
||||
{
|
||||
$this->dao->update('sonarqube')->data($sonarqube)
|
||||
->batchCheck(empty($sonarqubeID) ? $this->config->sonarqube->create->requiredFields : $this->config->sonarqube->edit->requiredFields, 'notempty')
|
||||
->batchCheck("url", 'URL');
|
||||
if(strpos($sonarqube->url, 'http') !== 0) dao::$errors['url'][] = $this->lang->sonarqube->hostError;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对数据进行排序和分页。
|
||||
* Sort and page data list.
|
||||
*
|
||||
* @param array $dataList
|
||||
* @param string $orderBy
|
||||
* @param int $recPerPage
|
||||
* @param int $pageID
|
||||
* @access protected
|
||||
* @return array
|
||||
*/
|
||||
protected function sortAndPage(array $dataList, string $orderBy, int $recPerPage, int $pageID): array
|
||||
{
|
||||
/* Data sort. */
|
||||
list($order, $sort) = explode('_', $orderBy);
|
||||
$orderList = array();
|
||||
foreach($dataList as $data) $orderList[] = $data->$order;
|
||||
array_multisort($orderList, $sort == 'desc' ? SORT_DESC : SORT_ASC, $dataList);
|
||||
|
||||
/* Pager. */
|
||||
$this->app->loadClass('pager', true);
|
||||
$recTotal = count($dataList);
|
||||
$pager = new pager($recTotal, $recPerPage, $pageID);
|
||||
$dataList = array_chunk($dataList, $pager->recPerPage);
|
||||
|
||||
$this->view->pager = $pager;
|
||||
return $dataList;
|
||||
}
|
||||
|
||||
protected function getIssueList(int $sonarqubeID, string $projectKey)
|
||||
{
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
$cacheFile = $this->sonarqube->getCacheFile($sonarqubeID, $projectKey);
|
||||
if(!$cacheFile or !file_exists($cacheFile) or (time() - filemtime($cacheFile)) / 60 > $this->config->sonarqube->cacheTime)
|
||||
{
|
||||
$sonarqubeIssueList = $this->sonarqube->apiGetIssues($sonarqubeID, $projectKey);
|
||||
foreach($sonarqubeIssueList as $key => $sonarqubeIssue)
|
||||
{
|
||||
if(!isset($sonarqubeIssue->line)) $sonarqubeIssue->line = '';
|
||||
if(!isset($sonarqubeIssue->effort)) $sonarqubeIssue->effort = '';
|
||||
$sonarqubeIssue->message = htmlspecialchars($sonarqubeIssue->message);
|
||||
$sonarqubeIssue->creationDate = date('Y-m-d H:i:s', strtotime($sonarqubeIssue->creationDate));
|
||||
|
||||
list(, $file) = explode(':', $sonarqubeIssue->component);
|
||||
$sonarqubeIssue->file = $file;
|
||||
}
|
||||
|
||||
if($cacheFile && !file_exists($cacheFile . '.lock'))
|
||||
{
|
||||
touch($cacheFile . '.lock');
|
||||
file_put_contents($cacheFile, serialize($sonarqubeIssueList));
|
||||
unlink($cacheFile . '.lock');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$sonarqubeIssueList = unserialize(file_get_contents($cacheFile));
|
||||
}
|
||||
|
||||
return $sonarqubeIssueList;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user