Skip to content

Commit

Permalink
【PAC】feat:开启PAC模式的代码库支持自动同步代码库YAML变更到蓝盾 #8130
Browse files Browse the repository at this point in the history
  • Loading branch information
mingshewhe committed Oct 23, 2023
1 parent 9b34436 commit 23e4931
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,10 @@ data class CodeGitWebHookTriggerElement(
) : WebHookTriggerElement(name, id, status) {
companion object {
const val classType = "codeGitWebHookTrigger"
const val taskAtom = "codeGitWebhookTriggerTaskAtom"
}

override fun getClassType() = classType

override fun getTaskAtom(): String = taskAtom

override fun findFirstTaskIdByStartType(startType: StartType): String {
return if (startType.name == StartType.WEB_HOOK.name) {
this.id!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,10 @@ data class CodeGithubWebHookTriggerElement(
) : WebHookTriggerElement(name, id, status) {
companion object {
const val classType = "codeGithubWebHookTrigger"
const val taskAtom = "codeGithubWebHookTriggerTaskAtom"
}

override fun getClassType() = classType

override fun getTaskAtom() = taskAtom

override fun findFirstTaskIdByStartType(startType: StartType): String {
return if (startType.name == StartType.WEB_HOOK.name) {
this.id!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,10 @@ data class CodeGitlabWebHookTriggerElement(
) : WebHookTriggerElement(name, id, status) {
companion object {
const val classType = "codeGitlabWebHookTrigger"
const val taskAtom = "codeGitlabWebHookTriggerTaskAtom"
}

override fun getClassType() = classType

override fun getTaskAtom() = taskAtom

override fun findFirstTaskIdByStartType(startType: StartType): String {
return if (startType.name == StartType.WEB_HOOK.name) {
this.id!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,10 @@ data class CodeP4WebHookTriggerElement(
) : WebHookTriggerElement(name, id, status) {
companion object {
const val classType = "codeP4WebHookTrigger"
const val taskAtom = "codeP4WebHookTriggerTaskAtom"
}

override fun getClassType() = classType

override fun getTaskAtom() = taskAtom

override fun findFirstTaskIdByStartType(startType: StartType): String {
return if (startType.name == StartType.WEB_HOOK.name) {
this.id!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,10 @@ data class CodeSVNWebHookTriggerElement(
) : WebHookTriggerElement(name, id, status) {
companion object {
const val classType = "codeSVNWebHookTrigger"
const val taskAtom = "codeSvnWebHookTriggerTaskAtom"
}

override fun getClassType() = classType

override fun getTaskAtom() = taskAtom

override fun findFirstTaskIdByStartType(startType: StartType): String {
return if (startType.name == StartType.WEB_HOOK.name) {
this.id!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,10 @@ data class CodeTGitWebHookTriggerElement(
) : WebHookTriggerElement(name, id, status) {
companion object {
const val classType = "codeTGitWebHookTrigger"
const val taskAtom = "codeTGitWebhookTriggerTaskAtom"
}

override fun getClassType() = classType

override fun getTaskAtom() = taskAtom

override fun findFirstTaskIdByStartType(startType: StartType): String {
return if (startType.name == StartType.WEB_HOOK.name) {
this.id!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
package com.tencent.devops.process.engine.service

import com.fasterxml.jackson.databind.ObjectMapper
import com.google.common.cache.CacheBuilder
import com.tencent.devops.common.api.enums.RepositoryConfig
import com.tencent.devops.common.api.enums.RepositoryType
import com.tencent.devops.common.api.enums.ScmType
Expand Down Expand Up @@ -79,6 +78,7 @@ import org.jooq.DSLContext
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import java.util.Optional
import java.util.concurrent.Executors

/**
Expand Down Expand Up @@ -668,9 +668,7 @@ class PipelineWebhookService @Autowired constructor(
private fun updateWebhookEventInfoTask() {
var offset = 0
val limit = 1000
val repoCache = CacheBuilder.newBuilder()
.maximumSize(1000)
.build<String, Repository>()
val repoCache = mutableMapOf<String, Optional<Repository>>()
// 上一个更新的项目ID
var preProjectId: String? = null
do {
Expand All @@ -682,7 +680,7 @@ class PipelineWebhookService @Autowired constructor(
pipelines.forEach { (projectId, pipelineId) ->
// 更改项目,清空代码库缓存
if (preProjectId != null && preProjectId != projectId) {
repoCache.cleanUp()
repoCache.clear()
}
preProjectId = projectId
val model = getModel(projectId, pipelineId)
Expand Down Expand Up @@ -718,8 +716,8 @@ class PipelineWebhookService @Autowired constructor(
)
return@webhook
}
val repository =
repoCache.get("${projectId}_${elementRepositoryConfig.getRepositoryId()}") {
val repository = repoCache.putIfAbsent(
"${projectId}_${elementRepositoryConfig.getRepositoryId()}", Optional.ofNullable(
try {
scmProxyService.getRepo(
projectId = projectId,
Expand All @@ -729,7 +727,8 @@ class PipelineWebhookService @Autowired constructor(
logger.warn("fail to get repository info", ignored)
null
}
}
)
)?.get()
if (repository != null && webhook.projectName != repository.projectName) {
logger.info(
"webhook projectName different from repo projectName|" +
Expand Down

0 comments on commit 23e4931

Please sign in to comment.