From 862b2dcca55134e72ae3875e7d5908bf4f6344fa Mon Sep 17 00:00:00 2001 From: jamikxu Date: Fri, 11 Feb 2022 11:21:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BA=A2=E7=BA=BFgit=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E5=88=86=E5=BC=80=E5=8F=91=E9=80=81=20#6118?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/plugin/service/ScmCheckService.kt | 48 +++++++++++-------- .../devops/plugin/utils/QualityUtils.kt | 5 +- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/backend/ci/core/plugin/biz-plugin/src/main/kotlin/com/tencent/devops/plugin/service/ScmCheckService.kt b/src/backend/ci/core/plugin/biz-plugin/src/main/kotlin/com/tencent/devops/plugin/service/ScmCheckService.kt index 7459f97cb13..834486ed45d 100644 --- a/src/backend/ci/core/plugin/biz-plugin/src/main/kotlin/com/tencent/devops/plugin/service/ScmCheckService.kt +++ b/src/backend/ci/core/plugin/biz-plugin/src/main/kotlin/com/tencent/devops/plugin/service/ScmCheckService.kt @@ -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 @@ -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 qualityHistory = client.get(ServiceQualityInterceptResource::class) + .listHistory(projectId, pipelineId, buildId).data + qualityHistory?.forEach { history -> + 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, listOf(history.ruleHashId)) + ) + if (isOauth) { + client.get(ServiceScmOauthResource::class).addCommitCheck(request) + } else { + client.get(ServiceScmResource::class).addCommitCheck(request) + } } return repo.projectName } diff --git a/src/backend/ci/core/plugin/biz-plugin/src/main/kotlin/com/tencent/devops/plugin/utils/QualityUtils.kt b/src/backend/ci/core/plugin/biz-plugin/src/main/kotlin/com/tencent/devops/plugin/utils/QualityUtils.kt index 54d36864672..b3f90f39a03 100644 --- a/src/backend/ci/core/plugin/biz-plugin/src/main/kotlin/com/tencent/devops/plugin/utils/QualityUtils.kt +++ b/src/backend/ci/core/plugin/biz-plugin/src/main/kotlin/com/tencent/devops/plugin/utils/QualityUtils.kt @@ -45,7 +45,8 @@ import com.tencent.devops.quality.constant.codeccToolUrlPathMap object QualityUtils { fun getQualityGitMrResult( client: Client, - event: GitCommitCheckEvent + event: GitCommitCheckEvent, + ruleIds: List ): Pair, MutableMap>>> { val projectId = event.projectId val pipelineId = event.pipelineId @@ -68,7 +69,7 @@ object QualityUtils { // value:指标、预期、结果、状态 val resultMap = mutableMapOf>>() client.get(ServiceQualityInterceptResource::class) - .listHistory(projectId, pipelineId, buildId).data?.forEach { ruleIntercept -> + .listRuleHistory(projectId, pipelineId, buildId, ruleIds).data?.forEach { ruleIntercept -> ruleIntercept.resultMsg.forEach { interceptItem -> val indicator = client.get(ServiceQualityIndicatorResource::class) .get(projectId, interceptItem.indicatorId).data