Skip to content

Commit

Permalink
feat:yaml 方式下,mr 触发器支持配置是否阻塞 mr 合并 #9412
Browse files Browse the repository at this point in the history
  • Loading branch information
yongyiduan committed Oct 8, 2023
1 parent 6b440d5 commit 21bce96
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

package com.tencent.devops.stream.trigger.listener.components

import com.fasterxml.jackson.core.type.TypeReference
import com.tencent.devops.common.api.enums.BuildReviewType
import com.tencent.devops.common.api.exception.ParamBlankException
import com.tencent.devops.common.api.util.YamlUtil
Expand All @@ -37,8 +36,7 @@ import com.tencent.devops.common.pipeline.enums.ChannelCode
import com.tencent.devops.common.pipeline.enums.ManualReviewAction
import com.tencent.devops.common.web.utils.I18nUtil
import com.tencent.devops.process.api.service.ServiceBuildResource
import com.tencent.devops.process.yaml.v2.parsers.template.models.NoReplaceTemplate
import com.tencent.devops.process.yaml.v2.utils.ScriptYmlUtils
import com.tencent.devops.process.yaml.v2.models.ScriptBuildYaml
import com.tencent.devops.stream.config.StreamGitConfig
import com.tencent.devops.stream.constant.StreamMessageCode.STARTUP_CONFIG_MISSING
import com.tencent.devops.stream.trigger.actions.BaseAction
Expand All @@ -50,13 +48,13 @@ import com.tencent.devops.stream.trigger.actions.data.context.isSuccess
import com.tencent.devops.stream.trigger.actions.data.isStreamMr
import com.tencent.devops.stream.trigger.parsers.StreamTriggerCache
import com.tencent.devops.stream.util.StreamPipelineUtils
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
import java.time.Duration
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneId
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component

@Suppress("NestedBlockDepth")
@Component
Expand Down Expand Up @@ -93,16 +91,14 @@ class SendCommitCheck @Autowired constructor(
}

private fun fixSettingFromYaml(action: BaseAction) {
val realYaml = ScriptYmlUtils.formatYaml(action.data.context.originYaml!!)
val preTriggerOn = YamlUtil.getObjectMapper().readValue(
realYaml, object : TypeReference<NoReplaceTemplate>() {}
val triggerOn = YamlUtil.getObjectMapper().readValue(
action.data.context.finishData?.normalizedYaml, ScriptBuildYaml::class.java
).triggerOn
val triggerOn = ScriptYmlUtils.formatTriggerOn(preTriggerOn)
if (triggerOn.mr?.reportCommitCheck != null) {
if (triggerOn?.mr?.reportCommitCheck != null) {
action.data.setting.enableCommitCheck = triggerOn.mr?.reportCommitCheck!!
}

if (triggerOn.mr?.blockMr != null) {
if (triggerOn?.mr?.blockMr != null) {
action.data.setting.enableMrBlock = triggerOn.mr?.blockMr!!
}
}
Expand Down Expand Up @@ -138,9 +134,11 @@ class SendCommitCheck @Autowired constructor(
BuildStatus.REVIEWING -> {
getStageReviewDesc(finishData)
}

BuildStatus.REVIEW_PROCESSED -> {
BUILD_RUNNING_DESC
}

else -> {
getFinishDesc(finishData, pipelineName)
}
Expand All @@ -157,6 +155,7 @@ class SendCommitCheck @Autowired constructor(
BuildReviewType.STAGE_REVIEW -> {
BUILD_MANUAL_REVIEW_DESC
}

BuildReviewType.QUALITY_CHECK_IN, BuildReviewType.QUALITY_CHECK_OUT -> {
BUILD_GATE_REVIEW_DESC
}
Expand All @@ -165,6 +164,7 @@ class SendCommitCheck @Autowired constructor(
logger.warn("SendCommitCheck|getStageReviewDesc|event not match|${finishData.reviewType}")
BUILD_RUNNING_DESC
}

BuildReviewType.QUALITY_TASK_REVIEW_PASS, BuildReviewType.QUALITY_TASK_REVIEW_ABORT,
BuildReviewType.TRIGGER_REVIEW -> {
""
Expand All @@ -184,9 +184,11 @@ class SendCommitCheck @Autowired constructor(
BUILD_SUCCESS_DESC.format(getFinishTime(finishData.startTime))
}
}

finishData.getBuildStatus().isCancel() -> {
BUILD_CANCEL_DESC.format(pipelineName)
}

else -> {
BUILD_FAILED_DESC.format(getFinishTime(finishData.startTime))
}
Expand Down Expand Up @@ -275,13 +277,15 @@ private fun BuildFinishStageData.isCheckInOrOut(): Pair<String?, String?> {
BuildReviewType.STAGE_REVIEW, BuildReviewType.QUALITY_CHECK_IN -> {
Pair(this.stageId, null)
}

BuildReviewType.QUALITY_CHECK_OUT -> {
Pair(null, this.stageId)
}
// 这里先这么写,未来如果这么枚举扩展代码编译时可以第一时间感知,防止漏过事件
BuildReviewType.TASK_REVIEW -> {
Pair(null, null)
}

BuildReviewType.QUALITY_TASK_REVIEW_PASS, BuildReviewType.QUALITY_TASK_REVIEW_ABORT,
BuildReviewType.TRIGGER_REVIEW -> {
Pair(null, null)
Expand Down

0 comments on commit 21bce96

Please sign in to comment.