Skip to content

Commit

Permalink
【PAC】feat:支持从代码库维度查看对应的代码库事件 #8122
Browse files Browse the repository at this point in the history
  • Loading branch information
mingshewhe committed Oct 28, 2023
1 parent 6493faa commit 03d6cc1
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ data class PipelineTriggerEvent(
@ApiModelProperty("事件描述")
val eventDesc: String,
@ApiModelProperty("重放事件ID")
val replayEventId: Long? = null,
val replayRequestId: String? = null,
@ApiModelProperty("事件请求参数, 记录手动/openapi/定时/远程触发启动参数")
val requestParams: Map<String, String>? = null,
@ApiModelProperty("触发事件")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class UserPipelineTriggerEventResourceImpl(
pageSize: Int?
): Result<SQLPage<PipelineTriggerEventVo>> {
return Result(
pipelineTriggerEventService.listTriggerEvent(
pipelineTriggerEventService.listPipelineTriggerEvent(
userId = userId,
projectId = projectId,
pipelineId = pipelineId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ package com.tencent.devops.process.api.external
import com.tencent.devops.common.api.exception.InvalidParamException
import com.tencent.devops.common.api.exception.ParamBlankException
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.service.trace.TraceTag
import com.tencent.devops.common.web.RestResource
import com.tencent.devops.process.webhook.CodeWebhookEventDispatcher
import com.tencent.devops.process.webhook.pojo.event.commit.GitWebhookEvent
Expand All @@ -38,6 +39,7 @@ import com.tencent.devops.process.webhook.pojo.event.commit.P4WebhookEvent
import com.tencent.devops.process.webhook.pojo.event.commit.SvnWebhookEvent
import com.tencent.devops.process.webhook.pojo.event.commit.TGitWebhookEvent
import org.slf4j.LoggerFactory
import org.slf4j.MDC
import org.springframework.amqp.rabbit.core.RabbitTemplate
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
Expand All @@ -60,8 +62,9 @@ class ExternalScmResourceImpl @Autowired constructor(
secret: String?,
traceId: String,
body: String
) =
Result(
): Result<Boolean> {
logger.info("traceId: ${MDC.get(TraceTag.BIZID)}")
return Result(
CodeWebhookEventDispatcher.dispatchEvent(
rabbitTemplate = rabbitTemplate,
event = GitWebhookEvent(
Expand All @@ -71,6 +74,8 @@ class ExternalScmResourceImpl @Autowired constructor(
)
)
)
}


override fun webHookGitlabCommit(event: String) =
Result(CodeWebhookEventDispatcher.dispatchEvent(rabbitTemplate, GitlabWebhookEvent(requestContent = event)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class PipelineTriggerEventDao {
EVENT_TYPE,
TRIGGER_USER,
EVENT_DESC,
REPLAY_EVENT_ID,
REPLAY_REQUEST_ID,
REQUEST_PARAMS,
CREATE_TIME
).values(
Expand All @@ -83,7 +83,7 @@ class PipelineTriggerEventDao {
triggerEvent.eventType,
triggerEvent.triggerUser,
JsonUtil.toJson(triggerEvent.eventDesc),
triggerEvent.replayEventId,
triggerEvent.replayRequestId,
triggerEvent.requestParams?.let { JsonUtil.toJson(it) },
triggerEvent.createTime
).onDuplicateKeyIgnore().execute()
Expand Down Expand Up @@ -126,7 +126,7 @@ class PipelineTriggerEventDao {
}
}

fun listTriggerEvent(
fun listTriggerDetail(
dslContext: DSLContext,
projectId: String,
eventId: Long? = null,
Expand Down Expand Up @@ -172,7 +172,7 @@ class PipelineTriggerEventDao {
t2.BUILD_NUM,
t2.REASON,
t2.REASON_DETAIL
).from(t1).leftJoin(t2)
).from(t2).leftJoin(t1)
.on(t1.EVENT_ID.eq(t2.EVENT_ID)).and(t1.PROJECT_ID.eq(t2.PROJECT_ID))
.where(conditions)
.orderBy(t1.CREATE_TIME.desc()).limit(limit)
Expand Down Expand Up @@ -200,7 +200,7 @@ class PipelineTriggerEventDao {
}
}

fun countTriggerEvent(
fun countTriggerDetail(
dslContext: DSLContext,
projectId: String,
eventId: Long? = null,
Expand Down Expand Up @@ -447,7 +447,7 @@ class PipelineTriggerEventDao {
triggerUser = triggerUser,
eventType = eventType,
eventDesc = JsonUtil.to(eventDesc, I18Variable::class.java).getCodeLanMessage(),
replayEventId = replayEventId,
replayRequestId = replayRequestId,
requestParams = requestParams?.let {
JsonUtil.to(
it,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ class PipelineWebhookService @Autowired constructor(
}
val elementRepositoryConfig = webhookElementParams.repositoryConfig
val webhookRepositoryConfig = getRepositoryConfig(webhook, params)
// 插件的配置与表中数据不一致,如保存流水线时,注册webhook失败,就会导致数据不一致,不更新
// 插件的配置与表中数据不一致,如保存流水线时,注册webhook失败,就会导致数据不一致,打印日志统计
if (elementRepositoryConfig.getRepositoryId() != webhookRepositoryConfig.getRepositoryId()) {
logger.info(
"webhook repository config different from element repository config|" +
Expand Down Expand Up @@ -777,14 +777,21 @@ class PipelineWebhookService @Autowired constructor(
"webhook:${webhook.projectName}|repo:${repository.projectName}"
)
}
val repositoryHashId = when {
repository != null -> repository.repoHashId
webhookRepositoryConfig.repositoryType == RepositoryType.ID ->
webhookRepositoryConfig.repositoryHashId

else -> null
}
pipelineWebhookDao.updateWebhookEventInfo(
dslContext = dslContext,
eventType = webhookElementParams.eventType?.name ?: "",
externalId = getExternalId(repository),
projectId = projectId,
pipelineId = pipelineId,
taskId = webhook.taskId!!,
repositoryHashId = repository?.repoHashId
repositoryHashId = repositoryHashId
)
} catch (ignored: Exception) {
logger.info("update webhook event info error|$webhook", ignored)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class PipelineTriggerEventService @Autowired constructor(
}
}

fun listTriggerEvent(
fun listPipelineTriggerEvent(
userId: String,
projectId: String,
pipelineId: String,
Expand All @@ -137,7 +137,7 @@ class PipelineTriggerEventService @Autowired constructor(
val pageSizeNotNull = pageSize ?: PageUtil.MAX_PAGE_SIZE
val sqlLimit = PageUtil.convertPageSizeToSQLMAXLimit(pageNotNull, pageSizeNotNull)
val language = I18nUtil.getLanguage(userId)
val count = pipelineTriggerEventDao.countTriggerEvent(
val count = pipelineTriggerEventDao.countTriggerDetail(
dslContext = dslContext,
projectId = projectId,
eventType = eventType,
Expand All @@ -147,7 +147,7 @@ class PipelineTriggerEventService @Autowired constructor(
startTime = startTime,
endTime = endTime
)
val records = pipelineTriggerEventDao.listTriggerEvent(
val records = pipelineTriggerEventDao.listTriggerDetail(
dslContext = dslContext,
projectId = projectId,
eventType = eventType,
Expand Down Expand Up @@ -240,7 +240,7 @@ class PipelineTriggerEventService @Autowired constructor(
val pageSizeNotNull = pageSize ?: PageUtil.MAX_PAGE_SIZE
val sqlLimit = PageUtil.convertPageSizeToSQLMAXLimit(pageNotNull, pageSizeNotNull)
val language = I18nUtil.getLanguage(userId)
val records = pipelineTriggerEventDao.listTriggerEvent(
val records = pipelineTriggerEventDao.listTriggerDetail(
dslContext = dslContext,
projectId = projectId,
eventId = eventId,
Expand All @@ -251,7 +251,7 @@ class PipelineTriggerEventService @Autowired constructor(
).map {
fillEventDetailParam(it, language)
}
val count = pipelineTriggerEventDao.countTriggerEvent(
val count = pipelineTriggerEventDao.countTriggerDetail(
dslContext = dslContext,
projectId = projectId,
eventId = eventId,
Expand Down Expand Up @@ -323,7 +323,8 @@ class PipelineTriggerEventService @Autowired constructor(
code = EVENT_REPLAY_DESC,
params = listOf(eventId.toString(), userId)
).toJsonStr(),
replayEventId = eventId,
// 如果重试的事件也由重试产生,则应该记录最开始的请求ID
replayRequestId = triggerEvent.replayRequestId ?: triggerEvent.requestId,
requestParams = requestParams,
createTime = LocalDateTime.now()
)
Expand Down
2 changes: 1 addition & 1 deletion support-files/sql/1001_ci_process_ddl_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ CREATE TABLE IF NOT EXISTS `T_PIPELINE_TRIGGER_EVENT`
`EVENT_TYPE` varchar(64) NOT NULL COMMENT '事件类型',
`TRIGGER_USER` varchar(100) NOT NULL COMMENT '触发用户',
`EVENT_DESC` text NOT NULL COMMENT '事件描述',
`REPLAY_EVENT_ID` bigint(20) NULL COMMENT '重放事件ID',
`REPLAY_REQUEST_ID` varchar(64) NULL COMMENT '重放请求ID',
`REQUEST_PARAMS` text DEFAULT NULL COMMENT '请求参数',
`CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '事件时间',
PRIMARY KEY (`EVENT_ID`, `CREATE_TIME`),
Expand Down

0 comments on commit 03d6cc1

Please sign in to comment.