Skip to content

Commit

Permalink
Merge pull request #6132 from JamiKX1/issue_6118
Browse files Browse the repository at this point in the history
feat: 红线git评论分开发送 #6118
  • Loading branch information
royalhuang authored Feb 17, 2022
2 parents 258e3d8 + dab0094 commit c3056ac
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.tencent.devops.plugin.api.pojo.GitCommitCheckEvent
import com.tencent.devops.plugin.utils.QualityUtils
import com.tencent.devops.process.utils.Credential
import com.tencent.devops.process.utils.CredentialUtils
import com.tencent.devops.quality.api.v2.ServiceQualityInterceptResource
import com.tencent.devops.repository.api.ServiceGithubResource
import com.tencent.devops.repository.api.ServiceOauthResource
import com.tencent.devops.repository.api.ServiceRepositoryResource
Expand Down Expand Up @@ -98,27 +99,32 @@ class ScmCheckService @Autowired constructor(private val client: Client) {
else ->
throw OperationException("不是Git 代码仓库")
}
val request = CommitCheckRequest(
projectName = repo.projectName,
url = repo.url,
type = type,
privateKey = null,
passPhrase = null,
token = token,
region = null,
commitId = commitId,
state = state,
targetUrl = targetUrl,
context = context,
description = description,
block = block,
mrRequestId = event.mergeRequestId,
reportData = QualityUtils.getQualityGitMrResult(client, event)
)
if (isOauth) {
client.get(ServiceScmOauthResource::class).addCommitCheck(request)
} else {
client.get(ServiceScmResource::class).addCommitCheck(request)
// 红线评论分开发送
val interceptHistory = client.get(ServiceQualityInterceptResource::class)
.listHistory(projectId, pipelineId, buildId).data
interceptHistory?.forEach { ruleIntercept ->
val request = CommitCheckRequest(
projectName = repo.projectName,
url = repo.url,
type = type,
privateKey = null,
passPhrase = null,
token = token,
region = null,
commitId = commitId,
state = state,
targetUrl = targetUrl,
context = context,
description = description,
block = block,
mrRequestId = event.mergeRequestId,
reportData = QualityUtils.getQualityGitMrResult(client, event, ruleIntercept)
)
if (isOauth) {
client.get(ServiceScmOauthResource::class).addCommitCheck(request)
} else {
client.get(ServiceScmResource::class).addCommitCheck(request)
}
}
return repo.projectName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ package com.tencent.devops.plugin.utils
import com.tencent.devops.common.api.util.DateTimeUtil
import com.tencent.devops.common.client.Client
import com.tencent.devops.common.pipeline.enums.StartType
import com.tencent.devops.common.quality.pojo.QualityRuleIntercept
import com.tencent.devops.common.service.utils.HomeHostUtil
import com.tencent.devops.plugin.api.pojo.GitCommitCheckEvent
import com.tencent.devops.plugin.codecc.CodeccUtils
import com.tencent.devops.process.api.service.ServicePipelineResource
import com.tencent.devops.process.api.service.ServiceVarResource
import com.tencent.devops.quality.api.v2.ServiceQualityIndicatorResource
import com.tencent.devops.quality.api.v2.ServiceQualityInterceptResource
import com.tencent.devops.common.quality.pojo.enums.QualityOperation
import com.tencent.devops.quality.constant.DEFAULT_CODECC_URL
import com.tencent.devops.quality.constant.codeccToolUrlPathMap
Expand All @@ -45,7 +45,8 @@ import com.tencent.devops.quality.constant.codeccToolUrlPathMap
object QualityUtils {
fun getQualityGitMrResult(
client: Client,
event: GitCommitCheckEvent
event: GitCommitCheckEvent,
ruleIntercept: QualityRuleIntercept
): Pair<List<String>, MutableMap<String, MutableList<List<String>>>> {
val projectId = event.projectId
val pipelineId = event.pipelineId
Expand All @@ -67,35 +68,32 @@ object QualityUtils {
// key:质量红线产出插件
// value:指标、预期、结果、状态
val resultMap = mutableMapOf<String, MutableList<List<String>>>()
client.get(ServiceQualityInterceptResource::class)
.listHistory(projectId, pipelineId, buildId).data?.forEach { ruleIntercept ->
ruleIntercept.resultMsg.forEach { interceptItem ->
val indicator = client.get(ServiceQualityIndicatorResource::class)
.get(projectId, interceptItem.indicatorId).data
val indicatorElementName = indicator?.elementType ?: ""
val elementCnName = ElementUtils.getElementCnName(indicatorElementName, projectId)
val resultList = resultMap[elementCnName] ?: mutableListOf()
val actualValue = if (CodeccUtils.isCodeccAtom(indicatorElementName)) {
getActualValue(
projectId = projectId,
pipelineId = pipelineId,
buildId = buildId,
detail = indicator?.elementDetail,
value = interceptItem.actualValue ?: "null",
client = client)
} else {
interceptItem.actualValue ?: "null"
}
resultList.add(listOf(
interceptItem.indicatorName,
actualValue,
QualityOperation.convertToSymbol(interceptItem.operation) + "" + interceptItem.value,
interceptItem.pass.toString(), ""
))
resultMap[elementCnName] = resultList
ruleIntercept.resultMsg.forEach { interceptItem ->
val indicator = client.get(ServiceQualityIndicatorResource::class)
.get(projectId, interceptItem.indicatorId).data
val indicatorElementName = indicator?.elementType ?: ""
val elementCnName = ElementUtils.getElementCnName(indicatorElementName, projectId)
val resultList = resultMap[elementCnName] ?: mutableListOf()
val actualValue = if (CodeccUtils.isCodeccAtom(indicatorElementName)) {
getActualValue(
projectId = projectId,
pipelineId = pipelineId,
buildId = buildId,
detail = indicator?.elementDetail,
value = interceptItem.actualValue ?: "null",
client = client)
} else {
interceptItem.actualValue ?: "null"
}
ruleName.add(ruleIntercept.ruleName)
resultList.add(listOf(
interceptItem.indicatorName,
actualValue,
QualityOperation.convertToSymbol(interceptItem.operation) + "" + interceptItem.value,
interceptItem.pass.toString(), ""
))
resultMap[elementCnName] = resultList
}
ruleName.add(ruleIntercept.ruleName)
titleData.add(ruleName.joinToString(""))
return Pair(titleData, resultMap)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ interface ServiceQualityInterceptResource {
buildId: String
): Result<List<QualityRuleIntercept>>

@ApiOperation("获取红线执行历史")
@ApiOperation("获取stream红线执行历史")
@Path("/project/{projectId}/pipeline/{pipelineId}/build/{buildId}/history")
@POST
fun listRuleHistory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ class QualityHistoryService @Autowired constructor(
)
}

fun serviceListByBuildId(projectId: String, pipelineId: String, buildId: String): List<QualityRuleIntercept> {
fun serviceListByBuildId(
projectId: String,
pipelineId: String,
buildId: String
): List<QualityRuleIntercept> {
val interceptHistory = historyDao.listByBuildId(
dslContext = dslContext,
projectId = projectId,
Expand All @@ -220,12 +224,12 @@ class QualityHistoryService @Autowired constructor(
projectId = projectId,
ruleIds = ruleIdSet
)?.map { it.id to it }?.toMap()
return interceptHistory.map {
return interceptHistory.distinctBy { it.ruleId }.map {
QualityRuleIntercept(
pipelineId = it.pipelineId,
pipelineName = "",
buildId = it.buildId,
ruleHashId = "",
ruleHashId = HashUtil.encodeLongId(it.ruleId),
ruleName = ruleMap?.get(it.ruleId)?.name ?: "",
interceptTime = it.createTime.timestampmilli(),
result = RuleInterceptResult.valueOf(it.result),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.tencent.devops.plugin.codecc.CodeccUtils
import com.tencent.devops.process.api.service.ServiceVarResource
import com.tencent.devops.quality.constant.DEFAULT_CODECC_URL
import com.tencent.devops.quality.constant.codeccToolUrlPathMap
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component

Expand All @@ -41,6 +42,8 @@ class QualityUrlUtils {
@Value("\${quality.codecc.host:}")
private val codeccHost: String = ""

private val logger = LoggerFactory.getLogger(QualityUrlUtils::class.java)

fun getCodeCCUrl(
projectId: String,
pipelineId: String,
Expand All @@ -65,6 +68,5 @@ class QualityUrlUtils {
.replace("##detail##", detail)
"http://$codeccHost$fillDetailUrl"
}
return ""
}
}

0 comments on commit c3056ac

Please sign in to comment.