Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 社区版质量红线支持CodeCC和三方插件 #5836 #6838

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ object CodeccUtils {

const val BK_CI_CODECC_V3_ATOM = "CodeccCheckAtomDebug"

const val BK_CI_CODECC_COMMUNITY_ATOM = "CodeCCCheckAtom"

fun isCodeccAtom(atomName: String?): Boolean {
return isCodeccNewAtom(atomName) || isCodeccV1Atom(atomName)
}
Expand All @@ -57,6 +59,11 @@ object CodeccUtils {
return atomName == BK_CI_CODECC_V3_ATOM
}

// 社区版插件code和内网版不同
fun isCodeccCommunityAtom(atomName: String?): Boolean {
return atomName == BK_CI_CODECC_COMMUNITY_ATOM
}

// 主要是因为codecc插件版本太多,又要统一处理,故加此map
val realAtomCodeMap = mapOf(
LinuxCodeCCScriptElement.classType to BK_CI_CODECC_V3_ATOM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class QualityIndicatorService @Autowired constructor(

// 根据codeccToolNameMap的key顺序排序
val detailIndicatorSortedMap = Maps.newLinkedHashMap<String /*detail*/, MutableList<QualityIndicator>>()
if (CodeccUtils.isCodeccAtom(elementType)) {
if (CodeccUtils.isCodeccAtom(elementType) || CodeccUtils.isCodeccCommunityAtom(elementType)) {
val propertyMap = codeccToolNameMap.entries.mapIndexed { index, entry ->
entry.key to index
}.toMap()
Expand All @@ -121,7 +121,7 @@ class QualityIndicatorService @Autowired constructor(
val indicatorList: List<QualityIndicator> = detailEntry.value

// codecc的指标要排序和中文特殊处理
if (CodeccUtils.isCodeccAtom(elementType)) {
if (CodeccUtils.isCodeccAtom(elementType) || CodeccUtils.isCodeccCommunityAtom(elementType)) {
detailCnName = codeccToolNameMap[elementDetail] ?: elementDetail
}

Expand Down Expand Up @@ -351,13 +351,19 @@ class QualityIndicatorService @Autowired constructor(
extra = it.extra)
}

var indicatorCnName = ""
if (CodeccUtils.isCodeccAtom(indicator.elementType) ||
CodeccUtils.isCodeccCommunityAtom(indicator.elementType)) {
indicatorCnName = codeccToolNameMap[indicator.elementDetail] ?: ""
}

val item = IndicatorListResponse.IndicatorListItem(
hashId = HashUtil.encodeLongId(indicator.id),
name = indicator.enName,
cnName = indicator.cnName,
elementType = indicator.elementType,
elementName = indicator.elementName,
elementDetail = indicator.elementDetail,
elementDetail = if (indicatorCnName.isNullOrBlank()) indicator.elementDetail else indicatorCnName,
metadatas = metadata,
availableOperation = indicator.operationAvailable.split(",").map { QualityOperation.valueOf(it) },
dataType = QualityDataType.valueOf(indicator.thresholdType.toUpperCase()),
Expand Down Expand Up @@ -671,22 +677,24 @@ class QualityIndicatorService @Autowired constructor(
"STANDARD" to "代码规范",
"DEFECT" to "代码缺陷",
"SECURITY" to "安全漏洞",
"CCN" to "圈复杂度",
"DUPC" to "重复率",
"COVERITY" to "Coverity",
"KLOCWORK" to "Klocwork",
"RIPS" to "啄木鸟漏洞扫描-PHP",
"SENSITIVE" to "敏感信息",
"WOODPECKER_SENSITIVE" to "啄木鸟敏感信息",
"BKCHECK-CPP" to "bkcheck-cpp",
"BKCHECK-OC" to "bkcheck-oc",
"CHECKSTYLE" to "Checkstyle",
"CPPLINT" to "CppLint",
"DETEKT" to "detekt",
"ESLINT" to "ESLint",
"PYLINT" to "PyLint",
"GOML" to "Gometalinter",
"CHECKSTYLE" to "Checkstyle",
"STYLECOP" to "StyleCop",
"DETEKT" to "detekt",
"PHPCS" to "PHPCS",
"SENSITIVE" to "敏感信息",
"OCCHECK" to "OCCheck",
"RIPS" to "啄木鸟漏洞扫描-PHP",
"WOODPECKER_SENSITIVE" to "啄木鸟敏感信息")
"PHPCS" to "PHPCS",
"PYLINT" to "PyLint",
"STYLECOP" to "StyleCop",
"CCN" to "圈复杂度",
"DUPC" to "重复率")

private val codeccToolDescMap = mapOf(
"STANDARD" to "按维度(推荐)",
Expand All @@ -705,6 +713,9 @@ class QualityIndicatorService @Autowired constructor(
"DETEKT" to "Kotlin静态代码分析工具 ",
"PHPCS" to "PHP代码风格检查工具",
"SENSITIVE" to "可扫描代码中有安全风险的敏感信息",
"OCCHECK" to "OC代码风格检查工具")
"OCCHECK" to "OC代码风格检查工具",
"WOODPECKER_SENSITIVE" to "敏感信息检查工具",
"BKCHECK-CPP" to "C++代码风格检查工具",
"BKCHECK-OC" to "OC代码风格检查工具")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,8 @@ class QualityRuleCheckService @Autowired constructor(

private fun getDetailMsg(record: QualityRuleInterceptRecord, params: Map<String, String>): String {
// codecc跳到独立入口页面
return if (CodeccUtils.isCodeccAtom(record.indicatorType)) {
return if (CodeccUtils.isCodeccAtom(record.indicatorType) ||
CodeccUtils.isCodeccCommunityAtom(record.indicatorType)) {
val projectId = params["projectId"] ?: ""
val pipelineId = params["pipelineId"] ?: ""
val buildId = params["buildId"] ?: ""
Expand Down
36 changes: 24 additions & 12 deletions support-files/sql/5001_ci_quality-init_dml_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,32 @@ INSERT IGNORE INTO `T_QUALITY_METADATA` (`ID`, `DATA_ID`, `DATA_NAME`, `ELEMENT_


-- 创建模板
INSERT IGNORE INTO `T_QUALITY_RULE_TEMPLATE` (`ID`, `NAME`, `TYPE`, `DESC`, `STAGE`, `CONTROL_POINT`, `CONTROL_POINT_POSITION`, `CREATE_USER`, `UPDATE_USER`, `CREATE_TIME`, `UPDATE_TIME`, `ENABLE`) values('2','日常构建','TEMPLATE','用于控制日常构建的告警数','开发','linuxPaasCodeCCScript','AFTER','admin','admin','2019-04-10 10:56:57','2019-04-10 11:03:51',b'1');
INSERT IGNORE INTO `T_QUALITY_RULE_TEMPLATE` (`ID`, `NAME`, `TYPE`, `DESC`, `STAGE`, `CONTROL_POINT`, `CONTROL_POINT_POSITION`, `CREATE_USER`, `UPDATE_USER`, `CREATE_TIME`, `UPDATE_TIME`, `ENABLE`) values('3','版本转测','TEMPLATE','用于版本转测时的质量控制','部署测试环境','jobDevOpsFastPushFile','BEFORE','admin','admin','2019-04-10 10:58:12','2019-04-10 11:03:52',b'1');
INSERT IGNORE INTO `T_QUALITY_RULE_TEMPLATE` (`ID`, `NAME`, `TYPE`, `DESC`, `STAGE`, `CONTROL_POINT`, `CONTROL_POINT_POSITION`, `CREATE_USER`, `UPDATE_USER`, `CREATE_TIME`, `UPDATE_TIME`, `ENABLE`) values('4','发布上线','TEMPLATE','用于发布版本时的质量控制','部署正式环境','cosCdnDistribution','BEFORE','admin','admin','2019-04-10 11:01:34','2019-04-10 11:43:06',b'1');
REPLACE INTO `T_QUALITY_RULE_TEMPLATE` (`ID`, `NAME`, `TYPE`, `DESC`, `STAGE`, `CONTROL_POINT`, `CONTROL_POINT_POSITION`, `CREATE_USER`, `UPDATE_USER`, `CREATE_TIME`, `UPDATE_TIME`, `ENABLE`) values('2','日常构建','TEMPLATE','用于控制日常构建的告警数','开发','CodeCCCheckAtom','AFTER','admin','admin','2019-04-10 10:56:57','2019-04-10 11:03:51',b'1');
REPLACE INTO `T_QUALITY_RULE_TEMPLATE` (`ID`, `NAME`, `TYPE`, `DESC`, `STAGE`, `CONTROL_POINT`, `CONTROL_POINT_POSITION`, `CREATE_USER`, `UPDATE_USER`, `CREATE_TIME`, `UPDATE_TIME`, `ENABLE`) values('3','版本转测','TEMPLATE','用于版本转测时的质量控制','部署测试环境','CodeCCCheckAtom','AFTER','admin','admin','2019-04-10 10:58:12','2019-04-10 11:03:52',b'1');
REPLACE INTO `T_QUALITY_RULE_TEMPLATE` (`ID`, `NAME`, `TYPE`, `DESC`, `STAGE`, `CONTROL_POINT`, `CONTROL_POINT_POSITION`, `CREATE_USER`, `UPDATE_USER`, `CREATE_TIME`, `UPDATE_TIME`, `ENABLE`) values('4','发布上线','TEMPLATE','用于发布版本时的质量控制','部署正式环境','CodeCCCheckAtom','AFTER','admin','admin','2019-04-10 11:01:34','2019-04-10 11:43:06',b'1');
REPLACE INTO `T_QUALITY_RULE_TEMPLATE` (`ID`, `NAME`, `TYPE`, `DESC`, `STAGE`, `CONTROL_POINT`, `CONTROL_POINT_POSITION`, `CREATE_USER`, `UPDATE_USER`, `CREATE_TIME`, `UPDATE_TIME`, `ENABLE`) values('5','安全相关','INDICATOR_SET','包含Coverity安全规则包和敏感信息告警',NULL,NULL,NULL,'admin','admin','2019-04-10 11:42:27','2019-04-10 11:42:33','');
INSERT IGNORE INTO `T_QUALITY_RULE_TEMPLATE` (`ID`, `NAME`, `TYPE`, `DESC`, `STAGE`, `CONTROL_POINT`, `CONTROL_POINT_POSITION`, `CREATE_USER`, `UPDATE_USER`, `CREATE_TIME`, `UPDATE_TIME`, `ENABLE`) values('6','Java工具规范','INDICATOR_SET','CheckStyle工具规范',NULL,NULL,NULL,'admin','admin','2019-04-10 11:01:34','2019-04-10 11:43:06',b'1');


INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('15','2','1011','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('16','3','1011','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('17','3','1015','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('42','5','1048','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('43','5','1009','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('44','4','1009','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('45','4','1015','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('46','4','1011','LE','0');
REPLACE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('15','2','1016','LE','0');
REPLACE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('16','2','1027','LE','0');
REPLACE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('17','2','1029','LE','0');
REPLACE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('42','2','1030','LE','0');
REPLACE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('43','2','1031','LE','0');
REPLACE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('44','3','1016','LE','0');
REPLACE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('45','3','1027','LE','0');
REPLACE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('46','3','1029','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('47','6','1034','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('48','6','1036','LE','10');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('48','6','1036','LE','10');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('49','3','1030','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('50','3','1031','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('51','4','1016','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('52','4','1027','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('53','4','1029','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('54','4','1030','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('55','4','1031','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('56','5','1016','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('57','5','1027','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('58','5','1029','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('59','5','1030','LE','0');
INSERT IGNORE INTO `T_QUALITY_TEMPLATE_INDICATOR_MAP` (`ID`, `TEMPLATE_ID`, `INDICATOR_ID`, `OPERATION`, `THRESHOLD`) values('60','5','1031','LE','0');