Skip to content

Commit

Permalink
feat: 触发器的自定义触发控制回调增加事件类型 TencentBlueKing#11196
Browse files Browse the repository at this point in the history
  • Loading branch information
hejieehe committed Nov 8, 2024
1 parent a55e150 commit 246193a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ class ThirdFilter(
private val thirdSecretToken: String? = null,
private val gitScmService: GitScmService,
private val callbackCircuitBreakerRegistry: CircuitBreakerRegistry?,
private val failedReason: String = ""
private val failedReason: String = "",
private val eventType: String
) : WebhookFilter {

companion object {
private const val FILTER_TOKEN_HEADER = "X-DEVOPS-FILTER-TOKEN"
private const val FILTER_EVENT_TYPE_HEADER = "X-DEVOPS-EVENT-TYPE"
private const val MAX_RETRY_COUNT = 3
private val logger = LoggerFactory.getLogger(ThirdFilter::class.java)
}
Expand Down Expand Up @@ -63,7 +65,8 @@ class ThirdFilter(
projectId = projectId,
pipelineId = pipelineId,
event = event,
changeFiles = changeFiles
changeFiles = changeFiles,
eventType = eventType
)
)
val builder = Request.Builder()
Expand All @@ -77,6 +80,7 @@ class ThirdFilter(
credentialId = thirdSecretToken
)
builder.addHeader(FILTER_TOKEN_HEADER, thirdSecretTokenValue)
builder.addHeader(FILTER_EVENT_TYPE_HEADER, eventType)
}
return HttpRetryUtils.retry(MAX_RETRY_COUNT) {
OkhttpUtils.doShortHttp(request = builder.build()).use { response ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ class TGitMrTriggerHandler(
thirdSecretToken = thirdSecretToken,
gitScmService = gitScmService,
callbackCircuitBreakerRegistry = callbackCircuitBreakerRegistry,
failedReason = I18Variable(code = WebhookI18nConstants.THIRD_FILTER_NOT_MATCH).toJsonStr()
failedReason = I18Variable(code = WebhookI18nConstants.THIRD_FILTER_NOT_MATCH).toJsonStr(),
eventType = getEventType().name
)
return listOf(
wipFilter, userFilter, targetBranchFilter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ class TGitPushTriggerHandler(
thirdSecretToken = thirdSecretToken,
gitScmService = gitScmService,
callbackCircuitBreakerRegistry = callbackCircuitBreakerRegistry,
failedReason = I18Variable(code = WebhookI18nConstants.THIRD_FILTER_NOT_MATCH).toJsonStr()
failedReason = I18Variable(code = WebhookI18nConstants.THIRD_FILTER_NOT_MATCH).toJsonStr(),
eventType = getEventType().name
)
return listOf(
userFilter, branchFilter, skipCiFilter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ data class ThirdFilterBody(
val projectId: String,
val pipelineId: String,
val event: CodeWebhookEvent,
val changeFiles: Set<String>? = emptySet()
val changeFiles: Set<String>? = emptySet(),
val eventType: String
)

0 comments on commit 246193a

Please sign in to comment.