Skip to content

Commit

Permalink
Merge branch 'feat_8122' of http://git.woa.com/bkdevops/bk-ci into fe…
Browse files Browse the repository at this point in the history
…at_8122
  • Loading branch information
mingshewhe committed Oct 27, 2023
2 parents f0ca8d4 + 6714f72 commit 403de73
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ data class I18Variable(
val defaultMessage: String? = null
) {
fun toJsonStr() = JsonUtil.toJson(this, false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ data class PipelineTriggerEventVo(
var buildNum: String? = null,
@ApiModelProperty("原因")
var reason: String? = null,
@ApiModelProperty("原因详情", required = false)
var reasonDetailList: List<String>? = null
@ApiModelProperty("失败原因详情", required = false)
var reasonDetailList: List<String>? = null,
@ApiModelProperty("失败原因", required = false)
var failReason: String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ class PipelineRemoteAuthService @Autowired constructor(
不使用client.get直接调用,因client内不支持同服务间的feign调用。故只能通过网关代理下 */
val projectConsulTag = redisOperation.hget(ConsulConstants.PROJECT_TAG_REDIS_KEY, pipeline.projectId)
return bkTag.invokeByTag(projectConsulTag) {
logger.info("start call service api ${pipeline.projectId} ${pipeline.pipelineId}, $projectConsulTag ${bkTag.getFinalTag()}")
logger.info("start call service api ${pipeline.projectId} ${pipeline.pipelineId}, " +
"$projectConsulTag ${bkTag.getFinalTag()}")
val buildId = pipelineTriggerEventService.saveSpecificEvent(
projectId = pipeline.projectId,
pipelineId = pipeline.pipelineId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class PipelineTriggerEventService @Autowired constructor(
val pageNotNull = page ?: 0
val pageSizeNotNull = pageSize ?: PageUtil.MAX_PAGE_SIZE
val sqlLimit = PageUtil.convertPageSizeToSQLMAXLimit(pageNotNull, pageSizeNotNull)
val language = I18nUtil.getLanguage(userId)
val count = pipelineTriggerEventDao.countTriggerEvent(
dslContext = dslContext,
projectId = projectId,
Expand All @@ -157,12 +158,8 @@ class PipelineTriggerEventService @Autowired constructor(
limit = sqlLimit.limit,
offset = sqlLimit.offset
).map {
it.eventDesc = try {
JsonUtil.to(it.eventDesc, I18Variable::class.java).getCodeLanMessage(I18nUtil.getLanguage(userId))
} catch (ignored: Exception) {
logger.warn("Failed to resolve repo trigger event|sourceDesc[${it.eventDesc}]", ignored)
it.eventDesc
}
it.eventDesc = it.getI18nEventDesc(language)
it.reason = getI18nReason(it.reason,language)
it
}
return SQLPage(count = count, records = records)
Expand Down Expand Up @@ -251,11 +248,7 @@ class PipelineTriggerEventService @Autowired constructor(
limit = sqlLimit.limit,
offset = sqlLimit.offset
).map {
it.eventDesc = it.getI18nEventDesc(language)
it.buildNum = it.getBuildNumUrl()
it.reasonDetailList = it.getI18nReasonDetailDesc(language)
it.reason = it.getI18nReason(language)
it
fillEventDetailParam(it, language)
}
val count = pipelineTriggerEventDao.countTriggerEvent(
dslContext = dslContext,
Expand Down Expand Up @@ -472,14 +465,14 @@ class PipelineTriggerEventService @Autowired constructor(
listOf()
}

private fun PipelineTriggerEventVo.getI18nReason(language: String): String = getCodeLanMessage(
messageCode = if (this.reason.isNullOrBlank()) {
private fun getI18nReason(reason: String?, language: String): String = getCodeLanMessage(
messageCode = if (reason.isNullOrBlank()) {
PipelineTriggerReason.TRIGGER_SUCCESS.name
} else {
this.reason!!
reason
},
language = language,
defaultMessage = this.reason
defaultMessage = reason
)

/**
Expand All @@ -494,4 +487,26 @@ class PipelineTriggerEventService @Autowired constructor(
null
}
}

/**
* 填充事件相关参数
* 事件描述国际化,构建链接,失败详情国际化,触发状态国际化,失败状态国际化
*/
private fun fillEventDetailParam(
eventParam: PipelineTriggerEventVo,
language: String
): PipelineTriggerEventVo {
return with(eventParam) {
eventDesc = getI18nEventDesc(language)
buildNum = getBuildNumUrl()
reasonDetailList = getI18nReasonDetailDesc(language)
reason = getI18nReason(eventParam.reason, language)
failReason = if (!reasonDetailList.isNullOrEmpty()) {
getI18nReason(PipelineTriggerReason.TRIGGER_NOT_MATCH.name, language)
} else {
""
}
this
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class WebhookEventListener constructor(
private val webhookRequestService: WebhookRequestService
) {

@SuppressWarnings("ComplexMethod", "LongMethod")
fun handleCommitEvent(event: ICodeWebhookEvent) {
val traceId = MDC.get(TraceTag.BIZID)
if (traceId.isNullOrEmpty()) {
Expand Down

0 comments on commit 403de73

Please sign in to comment.