From 254232ad718e9342bf5e4757b92ace0acd80f2e1 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Fri, 21 Jul 2023 10:25:01 +0800 Subject: [PATCH 001/143] =?UTF-8?q?feat=EF=BC=9A=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4=E5=BA=A6=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3=E7=A0=81=E5=BA=93?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trigger/CodeGitWebHookTriggerElement.kt | 3 + .../CodeGithubWebHookTriggerElement.kt | 1 + .../CodeGitlabWebHookTriggerElement.kt | 1 + .../trigger/CodeP4WebHookTriggerElement.kt | 1 + .../trigger/CodeSVNWebHookTriggerElement.kt | 1 + .../trigger/CodeTGitWebHookTriggerElement.kt | 1 + .../pipeline/utils/RepositoryConfigUtils.kt | 34 ++ .../common/webhook/atom/IWebhookAtomTask.kt | 47 +++ .../webhook/pojo/ReplayWebhookRequest.kt | 50 +++ .../common/webhook/pojo/WebhookRequest.kt | 36 ++ .../webhook/pojo/code/PathFilterConfig.kt | 4 + .../service/code/filter/BasePathFilter.kt | 16 +- .../service/code/filter/BranchFilter.kt | 17 +- .../service/code/filter/PathFilterFactory.kt | 6 +- .../service/code/filter/PathPrefixFilter.kt | 10 +- .../service/code/filter/PathRegexFilter.kt | 6 + .../service/code/filter/PathStreamFilter.kt | 10 +- .../webhook/service/code/filter/UserFilter.kt | 19 +- .../code/filter/WebhookFilterResponse.kt | 12 +- .../code/handler/CodeWebhookTriggerHandler.kt | 26 +- .../code/handler/GitHookTriggerHandler.kt | 17 +- .../handler/github/GithubPrTriggerHandler.kt | 32 +- .../github/GithubPushTriggerHandler.kt | 32 +- .../code/handler/p4/P4ChangeTriggerHandler.kt | 4 +- .../code/handler/p4/P4ShelveTriggerHandler.kt | 4 +- .../handler/svn/SvnCommitTriggerHandler.kt | 11 +- .../code/handler/tgit/TGitMrTriggerHandler.kt | 44 ++- .../handler/tgit/TGitPushTriggerHandler.kt | 43 ++- .../handler/tgit/TGitTagPushTriggerHandler.kt | 21 +- .../code/matcher/AbstractScmWebhookMatcher.kt | 11 +- .../service/code/matcher/GitWebHookMatcher.kt | 5 +- .../code/matcher/GithubWebHookMatcher.kt | 5 +- .../code/matcher/GitlabWebHookMatcher.kt | 5 +- .../service/code/matcher/P4WebHookMatcher.kt | 5 +- .../service/code/matcher/ScmWebhookMatcher.kt | 15 +- .../service/code/matcher/SvnWebHookMatcher.kt | 5 +- .../code/param/GitWebHookStartParam.kt | 3 +- .../code/param/GithubWebHookStartParam.kt | 3 +- .../code/param/GitlabWebHookStartParam.kt | 3 +- .../service/code/param/P4WebHookStartParam.kt | 3 +- .../code/param/ScmWebhookStartParams.kt | 5 +- .../code/param/SvnWebHookStartParam.kt | 3 +- .../code/param/TGitWebHookStartParam.kt | 3 +- .../service/code/pojo/WebhookMatchResult.kt | 42 +++ .../user/UserPipelineTriggerEventResource.kt | 193 ++++++++++ .../pojo/trigger/PipelineTriggerEvent.kt | 72 ++++ .../trigger/PipelineTriggerEventBuilder.kt | 116 ++++++ .../pojo/trigger/PipelineTriggerReason.kt | 34 ++ .../pojo/trigger/PipelineTriggerStatus.kt | 34 ++ .../pojo/trigger/PipelineTriggerType.kt | 68 ++++ .../pojo/webhook/PipelineTriggerTask.kt | 38 ++ .../pojo/webhook/PipelineWebhookEvent.kt | 59 ++++ .../pojo/webhook/PipelineWebhookSubscriber.kt | 35 ++ .../process/pojo/webhook/RepoWebhookEvent.kt | 50 +++ .../process/engine/dao/PipelineWebhookDao.kt | 88 ++++- .../process/service/scm/ScmProxyService.kt | 8 +- .../SamplePipelineBuildWebhookService.kt | 12 +- .../UserPipelineTriggerEventResourceImpl.kt | 147 ++++++++ .../process/dao/PipelineTriggerEventDao.kt | 329 ++++++++++++++++++ .../process/dao/PipelineWebhookEventDao.kt | 198 +++++++++++ .../engine/service/PipelineWebhookService.kt | 59 +++- .../trigger/PipelineTriggerEventService.kt | 267 ++++++++++++++ .../webhook/PipelineBuildWebhookService.kt | 304 +++------------- .../webhook/WebHookTriggerElementBizPlugin.kt | 11 - .../atom/CodeGitWebhookTriggerTaskAtom.kt | 162 +++++++++ .../atom/CodeGithubWebHookTriggerTaskAtom.kt | 194 +++++++++++ .../atom/CodeGitlabWebHookTriggerTaskAtom.kt | 150 ++++++++ .../atom/CodeP4WebHookTriggerTaskAtom.kt | 148 ++++++++ .../atom/CodeSvnWebHookTriggerTaskAtom.kt | 149 ++++++++ .../atom/CodeTGitWebhookTriggerTaskAtom.kt | 58 +++ .../atom/WebhookTriggerTaskAtomService.kt | 73 ++++ .../CodeGitWebHookTriggerElementBizPlugin.kt | 103 ++++++ .../webhook/listener/WebhookEventListener.kt | 97 +++--- .../webhook/listener/WebhookRequestService.kt | 47 +++ .../api/ServiceRepositoryWebhookResource.kt | 65 ++++ .../pojo/RepositoryWebhookRequest.kt | 29 ++ .../dao/RepositoryWebhookRequestDao.kt | 104 ++++++ .../ServiceRepositoryWebhookResourceImpl.kt | 50 +++ .../service/RepositoryWebhookService.kt | 40 +++ .../stream/trigger/actions/GitActionCommon.kt | 6 +- .../triggerMatch/matchUtils/PathMatchUtils.kt | 2 +- .../sql/1001_ci_process_ddl_mysql.sql | 51 +++ .../sql/1001_ci_repository_ddl_mysql.sql | 19 + .../5001_ci_project-init_dml_mysql.sql | 2 + 84 files changed, 3870 insertions(+), 426 deletions(-) create mode 100644 src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/atom/IWebhookAtomTask.kt create mode 100644 src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/ReplayWebhookRequest.kt create mode 100644 src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequest.kt create mode 100644 src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/pojo/WebhookMatchResult.kt create mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt create mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt create mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventBuilder.kt create mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerReason.kt create mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerStatus.kt create mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt create mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineTriggerTask.kt create mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhookEvent.kt create mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhookSubscriber.kt create mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/RepoWebhookEvent.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineWebhookEventDao.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGithubWebHookTriggerTaskAtom.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitlabWebHookTriggerTaskAtom.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeP4WebHookTriggerTaskAtom.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeSvnWebHookTriggerTaskAtom.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeTGitWebhookTriggerTaskAtom.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/WebhookTriggerTaskAtomService.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/element/CodeGitWebHookTriggerElementBizPlugin.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookRequestService.kt create mode 100644 src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryWebhookResource.kt create mode 100644 src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepositoryWebhookRequest.kt create mode 100644 src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryWebhookRequestDao.kt create mode 100644 src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceRepositoryWebhookResourceImpl.kt create mode 100644 src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepositoryWebhookService.kt diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitWebHookTriggerElement.kt index fd31ed72a56..9b9e53e1ab4 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitWebHookTriggerElement.kt @@ -103,10 +103,13 @@ 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!! diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt index 3eb1827f1a0..c01b3075e81 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt @@ -58,6 +58,7 @@ data class CodeGithubWebHookTriggerElement( ) : WebHookTriggerElement(name, id, status) { companion object { const val classType = "codeGithubWebHookTrigger" + const val taskAtom = "codeGithubWebHookTriggerTaskAtom" } override fun getClassType() = classType diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt index 22e323e58aa..baacd99fe62 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt @@ -81,6 +81,7 @@ data class CodeGitlabWebHookTriggerElement( ) : WebHookTriggerElement(name, id, status) { companion object { const val classType = "codeGitlabWebHookTrigger" + const val taskAtom = "codeGitlabWebHookTriggerTaskAtom" } override fun getClassType() = classType diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt index fe96c9dad04..e32775e87c9 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt @@ -46,6 +46,7 @@ data class CodeP4WebHookTriggerElement( ) : WebHookTriggerElement(name, id, status) { companion object { const val classType = "codeP4WebHookTrigger" + const val taskAtom = "codeP4WebHookTriggerTaskAtom" } override fun getClassType() = classType diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt index aeecec816f6..27a89db06f0 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt @@ -60,6 +60,7 @@ data class CodeSVNWebHookTriggerElement( ) : WebHookTriggerElement(name, id, status) { companion object { const val classType = "codeSVNWebHookTrigger" + const val taskAtom = "codeSvnWebHookTriggerTaskAtom" } override fun getClassType() = classType diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt index 4cb174d9369..ccf26694e3e 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt @@ -47,6 +47,7 @@ data class CodeTGitWebHookTriggerElement( ) : WebHookTriggerElement(name, id, status) { companion object { const val classType = "codeTGitWebHookTrigger" + const val taskAtom = "codeTGitWebhookTriggerTaskAtom" } override fun getClassType() = classType diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/utils/RepositoryConfigUtils.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/utils/RepositoryConfigUtils.kt index 8b29e007b29..db6a41d50d2 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/utils/RepositoryConfigUtils.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/utils/RepositoryConfigUtils.kt @@ -160,4 +160,38 @@ object RepositoryConfigUtils { repositoryType = RepositoryType.NAME ) } + + fun getRepositoryConfig( + repoHashId: String?, + repoName: String?, + repoType: RepositoryType?, + variable: Map? = null + ): RepositoryConfig { + return when (repoType) { + RepositoryType.ID -> RepositoryConfig(repoHashId, null, RepositoryType.ID) + RepositoryType.NAME -> { + val repositoryName = if (variable.isNullOrEmpty()) { + repoName!! + } else { + EnvUtils.parseEnv(repoName!!, variable) + } + RepositoryConfig(null, repositoryName, RepositoryType.NAME) + } + else -> { + if (!repoHashId.isNullOrBlank()) { + RepositoryConfig(repoHashId, null, RepositoryType.ID) + } else if (!repoName.isNullOrBlank()) { + val repositoryName = if (variable.isNullOrEmpty()) { + repoName + } else { + EnvUtils.parseEnv(repoName, variable) + } + RepositoryConfig(null, repositoryName, RepositoryType.NAME) + } else { + // 两者不能同时为空 + throw IllegalArgumentException("repoName and Id cannot both be empty") + } + } + } + } } diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/atom/IWebhookAtomTask.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/atom/IWebhookAtomTask.kt new file mode 100644 index 00000000000..babed8b84ea --- /dev/null +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/atom/IWebhookAtomTask.kt @@ -0,0 +1,47 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.common.webhook.atom + +import com.tencent.devops.common.webhook.pojo.ReplayWebhookRequest +import com.tencent.devops.common.webhook.pojo.WebhookRequest + +/** + * 触发器原子业务逻辑接口定义 + */ +interface IWebhookAtomTask { + /** + * webhook事件执行 + */ + fun request(request: WebhookRequest) + + /** + * webhook事件重放 + */ + fun replay(request: ReplayWebhookRequest) +} diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/ReplayWebhookRequest.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/ReplayWebhookRequest.kt new file mode 100644 index 00000000000..82469822176 --- /dev/null +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/ReplayWebhookRequest.kt @@ -0,0 +1,50 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.common.webhook.pojo + +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty + +@ApiModel +class ReplayWebhookRequest( + @ApiModelProperty("事件处理类") + val taskAtom: String, + @ApiModelProperty("用户ID") + val userId: String, + @ApiModelProperty("项目ID") + val projectId: String, + @ApiModelProperty("事件ID") + val eventId: Long, + @ApiModelProperty("请求ID") + val requestId: Long, + @ApiModelProperty("事件源") + val eventSource: String, + @ApiModelProperty("重试流水线ID") + val pipelineId: String? = null +) diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequest.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequest.kt new file mode 100644 index 00000000000..b877173d5eb --- /dev/null +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequest.kt @@ -0,0 +1,36 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.common.webhook.pojo + +data class WebhookRequest( + val taskAtom: String, + val headers: Map? = null, + val queryParams: Map? = null, + val body: String +) diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/PathFilterConfig.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/PathFilterConfig.kt index 2f1425ad408..a9afda34326 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/PathFilterConfig.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/PathFilterConfig.kt @@ -35,5 +35,9 @@ data class PathFilterConfig( val triggerOnPath: List, val includedPaths: List, val excludedPaths: List, + // 包含过滤失败原因 + val includedFailedReason: String, + // 排除过滤失败原因 + val excludedFailedReason: String, val caseSensitive: Boolean = true ) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/BasePathFilter.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/BasePathFilter.kt index 508c1243d7c..23f6489a818 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/BasePathFilter.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/BasePathFilter.kt @@ -35,6 +35,10 @@ abstract class BasePathFilter( private val triggerOnPath: List, private val includedPaths: List, private val excludedPaths: List, + // 包含过滤失败原因 + private val includedFailedReason: String, + // 排除过滤失败原因 + private val excludedFailedReason: String, private val caseSensitive: Boolean = true ) : WebhookFilter { @@ -90,8 +94,16 @@ abstract class BasePathFilter( // 1. 包含不为空,过滤为空,判断matchIncludePaths是否为空 // 2. 包含为空,过滤不为空,matchIncludePaths与triggerOnPath相同,判断matchIncludePaths与matchExcludedPaths大小 return when { - excludedPaths.isEmpty() && includedPaths.isNotEmpty() && matchIncludePaths.isEmpty() -> false - matchIncludePaths.size == matchExcludedPaths.size -> false + excludedPaths.isEmpty() && includedPaths.isNotEmpty() && matchIncludePaths.isEmpty() -> { + response.failedReason = includedFailedReason + false + } + + matchIncludePaths.size == matchExcludedPaths.size -> { + response.failedReason = excludedFailedReason + false + } + else -> true } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/BranchFilter.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/BranchFilter.kt index 7bea9f12b3e..f5ecc47140c 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/BranchFilter.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/BranchFilter.kt @@ -35,7 +35,11 @@ class BranchFilter( private val pipelineId: String, private val triggerOnBranchName: String, private val includedBranches: List, - private val excludedBranches: List + private val excludedBranches: List, + // 包含过滤失败原因 + private val includedFailedReason: String, + // 排除过滤失败原因 + private val excludedFailedReason: String ) : WebhookFilter { companion object { @@ -48,19 +52,20 @@ class BranchFilter( "$pipelineId|triggerOnBranchName:$triggerOnBranchName|includedBranches:$includedBranches" + "|excludedBranches:$excludedBranches|branch filter" ) - return hasNoBranchSpecs() || (isBranchNotExcluded() && isBranchIncluded(response)) + return hasNoBranchSpecs() || (isBranchNotExcluded(response) && isBranchIncluded(response)) } private fun hasNoBranchSpecs(): Boolean { return includedBranches.isEmpty() && excludedBranches.isEmpty() } - private fun isBranchNotExcluded(): Boolean { + private fun isBranchNotExcluded(response: WebhookFilterResponse): Boolean { excludedBranches.forEach { excludePattern -> if (matcher.match(excludePattern, triggerOnBranchName)) { logger.warn( "$pipelineId|the excluded branch match the git event branch $excludePattern" ) + response.failedReason = excludedFailedReason return false } } @@ -77,6 +82,10 @@ class BranchFilter( return true } } - return includedBranches.isEmpty() + val branchIncluded = includedBranches.isEmpty() + if (!branchIncluded) { + response.failedReason = includedFailedReason + } + return branchIncluded } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathFilterFactory.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathFilterFactory.kt index 9873485c278..e6250aacefc 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathFilterFactory.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathFilterFactory.kt @@ -41,6 +41,8 @@ object PathFilterFactory { triggerOnPath = triggerOnPath, includedPaths = includedPaths, excludedPaths = excludedPaths, + includedFailedReason = includedFailedReason, + excludedFailedReason = excludedFailedReason, caseSensitive = caseSensitive ) else -> @@ -48,7 +50,9 @@ object PathFilterFactory { pipelineId = pipelineId, triggerOnPath = triggerOnPath, includedPaths = includedPaths, - excludedPaths = excludedPaths + excludedPaths = excludedPaths, + includedFailedReason = includedFailedReason, + excludedFailedReason = excludedFailedReason ) } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathPrefixFilter.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathPrefixFilter.kt index 37cbc1fb314..318e64756c3 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathPrefixFilter.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathPrefixFilter.kt @@ -31,12 +31,18 @@ class PathPrefixFilter( private val pipelineId: String, private val triggerOnPath: List, private val includedPaths: List, - private val excludedPaths: List + private val excludedPaths: List, + // 包含过滤失败原因 + private val includedFailedReason: String, + // 排除过滤失败原因 + private val excludedFailedReason: String, ) : BasePathFilter( pipelineId = pipelineId, triggerOnPath = triggerOnPath, includedPaths = includedPaths, - excludedPaths = excludedPaths + excludedPaths = excludedPaths, + includedFailedReason = includedFailedReason, + excludedFailedReason = excludedFailedReason ) { override fun isPathMatch(eventPath: String, userPath: String): Boolean { diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathRegexFilter.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathRegexFilter.kt index e41fa0ef6c4..5e66c3d309c 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathRegexFilter.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathRegexFilter.kt @@ -34,12 +34,18 @@ class PathRegexFilter( private val triggerOnPath: List, private val includedPaths: List, private val excludedPaths: List, + // 包含过滤失败原因 + private val includedFailedReason: String, + // 排除过滤失败原因 + private val excludedFailedReason: String, private val caseSensitive: Boolean ) : BasePathFilter( pipelineId = pipelineId, triggerOnPath = triggerOnPath, includedPaths = includedPaths, excludedPaths = excludedPaths, + includedFailedReason = includedFailedReason, + excludedFailedReason = excludedFailedReason, caseSensitive = caseSensitive ) { private val matcher = AntPathMatcher() diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathStreamFilter.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathStreamFilter.kt index f35c32c49fc..77e5d97fe60 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathStreamFilter.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathStreamFilter.kt @@ -12,12 +12,18 @@ class PathStreamFilter( private val pipelineId: String, private val triggerOnPath: List, private val includedPaths: List, - private val excludedPaths: List + private val excludedPaths: List, + // 包含过滤失败原因 + private val includedFailedReason: String = "", + // 排除过滤失败原因 + private val excludedFailedReason: String = "", ) : BasePathFilter( pipelineId = pipelineId, triggerOnPath = triggerOnPath, includedPaths = includedPaths, - excludedPaths = excludedPaths + excludedPaths = excludedPaths, + includedFailedReason = includedFailedReason, + excludedFailedReason = excludedFailedReason ) { companion object { diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/UserFilter.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/UserFilter.kt index 30577e7ad7e..3b7da07a8d0 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/UserFilter.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/UserFilter.kt @@ -33,7 +33,11 @@ class UserFilter( private val pipelineId: String, private val triggerOnUser: String, private val includedUsers: List, - private val excludedUsers: List + private val excludedUsers: List, + // 包含过滤失败原因 + private val includedFailedReason: String, + // 排除过滤失败原因 + private val excludedFailedReason: String ) : WebhookFilter { companion object { @@ -45,30 +49,35 @@ class UserFilter( "$pipelineId|triggerOnUser:$triggerOnUser|includedUsers:$includedUsers" + "|excludedUsers:$excludedUsers|user filter" ) - return hasNoUserSpecs() || (isUserNotExcluded() && isUserIncluded()) + return hasNoUserSpecs() || (isUserNotExcluded(response) && isUserIncluded(response)) } private fun hasNoUserSpecs(): Boolean { return includedUsers.isEmpty() && excludedUsers.isEmpty() } - private fun isUserNotExcluded(): Boolean { + private fun isUserNotExcluded(response: WebhookFilterResponse): Boolean { excludedUsers.forEach { excludeUser -> if (excludeUser == triggerOnUser) { logger.warn("$pipelineId|$excludeUser|the exclude user match the git event user") + response.failedReason = excludedFailedReason return false } } return true } - private fun isUserIncluded(): Boolean { + private fun isUserIncluded(response: WebhookFilterResponse): Boolean { includedUsers.forEach { includedUser -> if (includedUser == triggerOnUser) { logger.warn("$pipelineId|includedUser|the included user match the git event user") return true } } - return includedUsers.isEmpty() + val userIncluded = includedUsers.isEmpty() + if (!userIncluded) { + response.failedReason = includedFailedReason + } + return userIncluded } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/WebhookFilterResponse.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/WebhookFilterResponse.kt index 038b2227bce..5811a18a32b 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/WebhookFilterResponse.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/WebhookFilterResponse.kt @@ -30,14 +30,12 @@ package com.tencent.devops.common.webhook.service.code.filter /** * webhook过滤器返回结果 */ -class WebhookFilterResponse { - private val params = mutableMapOf() - +data class WebhookFilterResponse( + val params: MutableMap = mutableMapOf(), + // 过滤失败原因 + var failedReason: String? = null +) { fun addParam(key: String, value: String) { params[key] = value } - - fun getParam(): Map { - return params - } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt index f547ef5b4d1..e84118bc7a4 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt @@ -33,7 +33,7 @@ import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilterChain import com.tencent.devops.common.webhook.service.code.filter.WebhookFilterResponse -import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.pojo.WebhookCommit @@ -67,9 +67,22 @@ interface CodeWebhookTriggerHandler { fun getMergeRequestId(event: T): Long? = null + /** + * 事件产生时的消息 + */ fun getMessage(event: T): String? - fun preMatch(event: T): ScmWebhookMatcher.MatchResult = ScmWebhookMatcher.MatchResult(isMatch = true) + /** + * 获取事件说明,根据不同的事件组织事件说明 + */ + fun getEventDesc(event: T): String = "" + + /** + * 获取webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port + */ + fun getExternalId(event: T): String = "" + + fun preMatch(event: T): WebhookMatchResult = WebhookMatchResult(isMatch = true) fun getWebhookCommitList( event: T, @@ -90,7 +103,7 @@ interface CodeWebhookTriggerHandler { pipelineId: String, repository: Repository, webHookParams: WebHookParams - ): ScmWebhookMatcher.MatchResult { + ): WebhookMatchResult { val filters = getWebhookFilters( event = event, projectId = projectId, @@ -100,12 +113,13 @@ interface CodeWebhookTriggerHandler { ) val response = WebhookFilterResponse() return if (filters.isNotEmpty()) { - ScmWebhookMatcher.MatchResult( + WebhookMatchResult( isMatch = WebhookFilterChain(filters = filters).doFilter(response), - extra = response.getParam() + extra = response.params, + reason = response.failedReason ) } else { - ScmWebhookMatcher.MatchResult(isMatch = true) + WebhookMatchResult(isMatch = true) } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/GitHookTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/GitHookTriggerHandler.kt index df8faa42548..8b81ca145a4 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/GitHookTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/GitHookTriggerHandler.kt @@ -29,12 +29,9 @@ package com.tencent.devops.common.webhook.service.code.handler import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent import com.tencent.devops.common.webhook.pojo.code.WebHookParams -import com.tencent.devops.common.webhook.service.code.filter.BranchFilter import com.tencent.devops.common.webhook.service.code.filter.EventTypeFilter import com.tencent.devops.common.webhook.service.code.filter.GitUrlFilter -import com.tencent.devops.common.webhook.service.code.filter.UserFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter -import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository interface GitHookTriggerHandler : CodeWebhookTriggerHandler { @@ -96,19 +93,7 @@ interface GitHookTriggerHandler : CodeWebhookTriggerHandle eventType = eventType, action = getAction(event) ) - val userFilter = UserFilter( - pipelineId = pipelineId, - triggerOnUser = getUsername(event), - includedUsers = WebhookUtils.convert(includeUsers), - excludedUsers = WebhookUtils.convert(excludeUsers) - ) - val branchFilter = BranchFilter( - pipelineId = pipelineId, - triggerOnBranchName = getBranchName(event), - includedBranches = WebhookUtils.convert(branchName), - excludedBranches = WebhookUtils.convert(excludeBranchName) - ) - return listOf(urlFilter, eventTypeFilter, userFilter, branchFilter) + return listOf(urlFilter, eventTypeFilter) } } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt index 1ad6e95151d..1b3a454ffba 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt @@ -78,9 +78,11 @@ import com.tencent.devops.common.webhook.pojo.code.PIPELINE_WEBHOOK_TARGET_REPO_ import com.tencent.devops.common.webhook.pojo.code.PIPELINE_WEBHOOK_TARGET_URL import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.pojo.code.github.GithubPullRequestEvent +import com.tencent.devops.common.webhook.service.code.filter.BranchFilter +import com.tencent.devops.common.webhook.service.code.filter.UserFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.GitHookTriggerHandler -import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils @@ -138,12 +140,12 @@ class GithubPrTriggerHandler : GitHookTriggerHandler { return event.pullRequest.base.repo.cloneUrl } - override fun preMatch(event: GithubPullRequestEvent): ScmWebhookMatcher.MatchResult { + override fun preMatch(event: GithubPullRequestEvent): WebhookMatchResult { if (!(event.action == "opened" || event.action == "reopened" || event.action == "synchronize")) { logger.info("Github pull request no open or update") - return ScmWebhookMatcher.MatchResult(false) + return WebhookMatchResult(false) } - return ScmWebhookMatcher.MatchResult(true) + return WebhookMatchResult(true) } override fun getEventFilters( @@ -153,7 +155,27 @@ class GithubPrTriggerHandler : GitHookTriggerHandler { repository: Repository, webHookParams: WebHookParams ): List { - return emptyList() + with(webHookParams) { + val userId = getUsername(event) + val userFilter = UserFilter( + pipelineId = pipelineId, + triggerOnUser = userId, + includedUsers = WebhookUtils.convert(includeUsers), + excludedUsers = WebhookUtils.convert(excludeUsers), + includedFailedReason = "on.push.users trigger user($userId) not match", + excludedFailedReason = "on.push.users-ignore trigger user($userId) match" + ) + val targetBranch = getBranchName(event) + val targetBranchFilter = BranchFilter( + pipelineId = pipelineId, + triggerOnBranchName = getBranchName(event), + includedBranches = WebhookUtils.convert(branchName), + excludedBranches = WebhookUtils.convert(excludeBranchName), + includedFailedReason = "on.mr.target-branches target branch($targetBranch) not match", + excludedFailedReason = "on.mr.target-branches-ignore target branch($targetBranch) match" + ) + return listOf(userFilter, targetBranchFilter) + } } override fun retrieveParams( diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt index 78a2fbce7d6..96e8d2f5021 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt @@ -53,9 +53,11 @@ import com.tencent.devops.common.webhook.pojo.code.git.GitCommit import com.tencent.devops.common.webhook.pojo.code.git.GitCommitAuthor import com.tencent.devops.common.webhook.pojo.code.git.GitPushEvent import com.tencent.devops.common.webhook.pojo.code.github.GithubPushEvent +import com.tencent.devops.common.webhook.service.code.filter.BranchFilter +import com.tencent.devops.common.webhook.service.code.filter.UserFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.GitHookTriggerHandler -import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils @@ -101,12 +103,12 @@ class GithubPushTriggerHandler : GitHookTriggerHandler { return event.headCommit?.message ?: "" } - override fun preMatch(event: GithubPushEvent): ScmWebhookMatcher.MatchResult { + override fun preMatch(event: GithubPushEvent): WebhookMatchResult { if (event.commits.isEmpty()) { logger.info("Github web hook no commit") - return ScmWebhookMatcher.MatchResult(false) + return WebhookMatchResult(false) } - return ScmWebhookMatcher.MatchResult(true) + return WebhookMatchResult(true) } override fun getEventFilters( @@ -116,7 +118,27 @@ class GithubPushTriggerHandler : GitHookTriggerHandler { repository: Repository, webHookParams: WebHookParams ): List { - return emptyList() + with(webHookParams) { + val userId = getUsername(event) + val userFilter = UserFilter( + pipelineId = pipelineId, + triggerOnUser = userId, + includedUsers = WebhookUtils.convert(includeUsers), + excludedUsers = WebhookUtils.convert(excludeUsers), + includedFailedReason = "on.push.users trigger user($userId) not match", + excludedFailedReason = "on.push.users-ignore trigger user($userId) match" + ) + val triggerOnBranchName = getBranchName(event) + val branchFilter = BranchFilter( + pipelineId = pipelineId, + triggerOnBranchName = getBranchName(event), + includedBranches = WebhookUtils.convert(branchName), + excludedBranches = WebhookUtils.convert(excludeBranchName), + includedFailedReason = "on.push.branches branch($triggerOnBranchName) not match", + excludedFailedReason = "on.push.branches-ignore branch($triggerOnBranchName) match" + ) + return listOf(userFilter, branchFilter) + } } override fun retrieveParams( diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt index 1be9e9b3058..121726aafb0 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt @@ -140,7 +140,9 @@ class P4ChangeTriggerHandler( triggerOnPath = changeFiles, includedPaths = WebhookUtils.convert(includePaths), excludedPaths = WebhookUtils.convert(excludePaths), - caseSensitive = caseSensitive + caseSensitive = caseSensitive, + includedFailedReason = "on.change-commit.paths change path($includePaths) not match", + excludedFailedReason = "on.change-commit.paths-ignore change path($excludePaths) match" ) ).doFilter(response) } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt index 77b229b049a..a71af276483 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt @@ -137,7 +137,9 @@ class P4ShelveTriggerHandler( triggerOnPath = changeFiles, includedPaths = WebhookUtils.convert(includePaths), excludedPaths = WebhookUtils.convert(excludePaths), - caseSensitive = caseSensitive + caseSensitive = caseSensitive, + includedFailedReason = "on.shelve-commit.paths change path($includePaths) not match", + excludedFailedReason = "on.shelve-commit.paths-ignore change path($excludePaths) match" ) ).doFilter(response) } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt index 7834389cb22..205166dab1a 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt @@ -92,11 +92,14 @@ class SvnCommitTriggerHandler : CodeWebhookTriggerHandler { projectName = repository.projectName, triggerOnProjectName = event.rep_name ) + val userId = getUsername(event) val userFilter = UserFilter( pipelineId = pipelineId, - triggerOnUser = getUsername(event), + triggerOnUser = userId, includedUsers = WebhookUtils.convert(includeUsers), - excludedUsers = WebhookUtils.convert(excludeUsers) + excludedUsers = WebhookUtils.convert(excludeUsers), + includedFailedReason = "on.post-commit.users trigger user($userId) not match", + excludedFailedReason = "on.post-commit.users-ignore trigger user($userId) match" ) val projectRelativePath = WebhookUtils.getRelativePath(repository.url) val pathFilter = PathFilterFactory.newPathFilter( @@ -110,7 +113,9 @@ class SvnCommitTriggerHandler : CodeWebhookTriggerHandler { relativeSubPath = path ) }, - includedPaths = getIncludePaths(projectRelativePath) + includedPaths = getIncludePaths(projectRelativePath), + includedFailedReason = "on.post-commit.paths change path($includePaths) not match", + excludedFailedReason = "on.post-commit.paths-ignore change path($excludePaths) match" ) ) return listOf(projectNameFilter, userFilter, pathFilter) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt index 16f287b80e2..a2d105f6d86 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt @@ -78,10 +78,11 @@ import com.tencent.devops.common.webhook.service.code.filter.ContainsFilter import com.tencent.devops.common.webhook.service.code.filter.PathFilterFactory import com.tencent.devops.common.webhook.service.code.filter.SkipCiFilter import com.tencent.devops.common.webhook.service.code.filter.ThirdFilter +import com.tencent.devops.common.webhook.service.code.filter.UserFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilterResponse import com.tencent.devops.common.webhook.service.code.handler.GitHookTriggerHandler -import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.common.webhook.util.WebhookUtils.convert import com.tencent.devops.common.webhook.util.WebhookUtils.getBranch @@ -164,7 +165,7 @@ class TGitMrTriggerHandler( ) } - override fun preMatch(event: GitMergeRequestEvent): ScmWebhookMatcher.MatchResult { + override fun preMatch(event: GitMergeRequestEvent): WebhookMatchResult { if (event.object_attributes.action == "close" || ( event.object_attributes.action == "update" && @@ -172,9 +173,9 @@ class TGitMrTriggerHandler( ) ) { logger.info("Git web hook is ${event.object_attributes.action} merge request") - return ScmWebhookMatcher.MatchResult(false) + return WebhookMatchResult(false) } - return ScmWebhookMatcher.MatchResult(true) + return WebhookMatchResult(true) } override fun getEventFilters( @@ -185,11 +186,32 @@ class TGitMrTriggerHandler( webHookParams: WebHookParams ): List { with(webHookParams) { + val userId = getUsername(event) + val userFilter = UserFilter( + pipelineId = pipelineId, + triggerOnUser = getUsername(event), + includedUsers = convert(includeUsers), + excludedUsers = convert(excludeUsers), + includedFailedReason = "on.mr.users trigger user($userId) not match", + excludedFailedReason = "on.mr.users-ignore trigger user($userId) match" + ) + val targetBranch = getBranchName(event) + val targetBranchFilter = BranchFilter( + pipelineId = pipelineId, + triggerOnBranchName = getBranchName(event), + includedBranches = convert(branchName), + excludedBranches = convert(excludeBranchName), + includedFailedReason = "on.mr.target-branches target branch($targetBranch) not match", + excludedFailedReason = "on.mr.target-branches-ignore target branch($targetBranch) match" + ) + val sourceBranch = getBranch(event.object_attributes.source_branch) val sourceBranchFilter = BranchFilter( pipelineId = pipelineId, - triggerOnBranchName = getBranch(event.object_attributes.source_branch), + triggerOnBranchName = sourceBranch, includedBranches = convert(includeSourceBranchName), - excludedBranches = convert(excludeSourceBranchName) + excludedBranches = convert(excludeSourceBranchName), + includedFailedReason = "on.mr.source-branches source branch($sourceBranch) not match", + excludedFailedReason = "on.mr.source-branches-ignore source branch($sourceBranch) match" ) val skipCiFilter = SkipCiFilter( pipelineId = pipelineId, @@ -224,7 +246,9 @@ class TGitMrTriggerHandler( pipelineId = pipelineId, triggerOnPath = changeFiles, includedPaths = convert(includePaths), - excludedPaths = convert(excludePaths) + excludedPaths = convert(excludePaths), + includedFailedReason = "on.mr.paths change path($includePaths) not match", + excludedFailedReason = "on.mr.paths-ignore change path($excludePaths) match" ) ).doFilter(response) } @@ -246,7 +270,11 @@ class TGitMrTriggerHandler( gitScmService = gitScmService, callbackCircuitBreakerRegistry = callbackCircuitBreakerRegistry ) - return listOf(sourceBranchFilter, skipCiFilter, pathFilter, commitMessageFilter, actionFilter, thirdFilter) + return listOf( + userFilter, targetBranchFilter, + sourceBranchFilter, skipCiFilter, pathFilter, + commitMessageFilter, actionFilter, thirdFilter + ) } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt index fa3c0111dae..97e01edacdb 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt @@ -56,14 +56,16 @@ import com.tencent.devops.common.webhook.pojo.code.git.GitPushEvent import com.tencent.devops.common.webhook.pojo.code.git.isDeleteBranch import com.tencent.devops.common.webhook.service.code.EventCacheService import com.tencent.devops.common.webhook.service.code.GitScmService +import com.tencent.devops.common.webhook.service.code.filter.BranchFilter import com.tencent.devops.common.webhook.service.code.filter.PathFilterFactory import com.tencent.devops.common.webhook.service.code.filter.PushKindFilter import com.tencent.devops.common.webhook.service.code.filter.SkipCiFilter import com.tencent.devops.common.webhook.service.code.filter.ThirdFilter +import com.tencent.devops.common.webhook.service.code.filter.UserFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilterResponse import com.tencent.devops.common.webhook.service.code.handler.GitHookTriggerHandler -import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.common.webhook.util.WebhookUtils.convert import com.tencent.devops.process.engine.service.code.filter.CommitMessageFilter @@ -125,7 +127,15 @@ class TGitPushTriggerHandler( } } - override fun preMatch(event: GitPushEvent): ScmWebhookMatcher.MatchResult { + override fun getEventDesc(event: GitPushEvent): String { + return "${getBranchName(event)} commit ${event.checkout_sha} pushed by ${event.user_name}" + } + + override fun getExternalId(event: GitPushEvent): String { + return event.project_id.toString() + } + + override fun preMatch(event: GitPushEvent): WebhookMatchResult { val isMatch = when { event.total_commits_count <= 0 -> { logger.info("Git web hook no commit(${event.total_commits_count})") @@ -138,7 +148,7 @@ class TGitPushTriggerHandler( else -> true } - return ScmWebhookMatcher.MatchResult(isMatch) + return WebhookMatchResult(isMatch) } override fun getEventFilters( @@ -149,6 +159,24 @@ class TGitPushTriggerHandler( webHookParams: WebHookParams ): List { with(webHookParams) { + val userId = getUsername(event) + val userFilter = UserFilter( + pipelineId = pipelineId, + triggerOnUser = userId, + includedUsers = convert(includeUsers), + excludedUsers = convert(excludeUsers), + includedFailedReason = "on.push.users trigger user($userId) not match", + excludedFailedReason = "on.push.users-ignore trigger user($userId) match" + ) + val triggerOnBranchName = getBranchName(event) + val branchFilter = BranchFilter( + pipelineId = pipelineId, + triggerOnBranchName = getBranchName(event), + includedBranches = convert(branchName), + excludedBranches = convert(excludeBranchName), + includedFailedReason = "on.push.branches branch($triggerOnBranchName) not match", + excludedFailedReason = "on.push.branches-ignore branch($triggerOnBranchName) match" + ) val skipCiFilter = SkipCiFilter( pipelineId = pipelineId, triggerOnMessage = event.commits?.get(0)?.message ?: "" @@ -183,7 +211,9 @@ class TGitPushTriggerHandler( pipelineId = pipelineId, triggerOnPath = eventPaths.toList(), includedPaths = convert(includePaths), - excludedPaths = convert(excludePaths) + excludedPaths = convert(excludePaths), + includedFailedReason = "on.push.paths change path($includePaths) not match", + excludedFailedReason = "on.push.paths-ignore change path($excludePaths) match" ) ).doFilter(response) } @@ -204,7 +234,10 @@ class TGitPushTriggerHandler( gitScmService = gitScmService, callbackCircuitBreakerRegistry = callbackCircuitBreakerRegistry ) - return listOf(skipCiFilter, pathFilter, commitMessageFilter, pushKindFilter, thirdFilter) + return listOf( + userFilter, branchFilter, skipCiFilter, + pathFilter, commitMessageFilter, pushKindFilter, thirdFilter + ) } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt index 0967f010098..a06987ce5e2 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt @@ -154,23 +154,36 @@ class TGitTagPushTriggerHandler : CodeWebhookTriggerHandler { triggerOnEventType = getEventType(), eventType = eventType ) + val eventTag = getBranchName(event) val branchFilter = BranchFilter( pipelineId = pipelineId, - triggerOnBranchName = getBranchName(event), + triggerOnBranchName = eventTag, includedBranches = WebhookUtils.convert(tagName), - excludedBranches = WebhookUtils.convert(excludeTagName) + excludedBranches = WebhookUtils.convert(excludeTagName), + includedFailedReason = "on.tag.tags tag($eventTag) not match", + excludedFailedReason = "on.tag.tags-ignore tag($eventTag) match" ) + val userId = getUsername(event) val userFilter = UserFilter( pipelineId = pipelineId, triggerOnUser = getUsername(event), includedUsers = WebhookUtils.convert(includeUsers), - excludedUsers = WebhookUtils.convert(excludeUsers) + excludedUsers = WebhookUtils.convert(excludeUsers), + includedFailedReason = "on.tag.users trigger user($userId) not match", + excludedFailedReason = "on.tag.users-ignore trigger user($userId) match" ) + val fromBranch = event.create_from val fromBranchFilter = BranchFilter( pipelineId = pipelineId, triggerOnBranchName = event.create_from ?: "", includedBranches = WebhookUtils.convert(fromBranches), - excludedBranches = emptyList() + excludedBranches = emptyList(), + includedFailedReason = if (fromBranch.isNullOrBlank()) { + "on.tag.from-branches client push tag not support from-branches" + } else { + "on.tag.from-branches tag from branch($fromBranch) not match" + }, + excludedFailedReason = "" ) return listOf(urlFilter, eventTypeFilter, branchFilter, userFilter, fromBranchFilter) } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt index 5044e86eb8d..813f906aa9a 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt @@ -30,6 +30,7 @@ package com.tencent.devops.common.webhook.service.code.matcher import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent import com.tencent.devops.common.webhook.service.code.loader.CodeWebhookHandlerRegistrar +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.repository.pojo.Repository @Suppress("TooManyFunctions") @@ -38,7 +39,7 @@ abstract class AbstractScmWebhookMatcher( ) : ScmWebhookMatcher { protected val eventHandler by lazy { CodeWebhookHandlerRegistrar.getHandler(webhookEvent = event) } - override fun preMatch(): ScmWebhookMatcher.MatchResult { + override fun preMatch(): WebhookMatchResult { return eventHandler.preMatch(event) } @@ -82,6 +83,14 @@ abstract class AbstractScmWebhookMatcher( return eventHandler.getMessage(event) } + override fun getEventDesc(): String { + return eventHandler.getEventDesc(event) + } + + override fun getExternalId(): String { + return eventHandler.getExternalId(event) + } + override fun retrieveParams(projectId: String?, repository: Repository?): Map { return eventHandler.retrieveParams( event = event, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/GitWebHookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/GitWebHookMatcher.kt index d8e95a7b119..47a30f556ff 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/GitWebHookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/GitWebHookMatcher.kt @@ -30,6 +30,7 @@ package com.tencent.devops.common.webhook.service.code.matcher import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeType import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.pojo.code.git.GitEvent +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.repository.pojo.CodeGitRepository import com.tencent.devops.repository.pojo.CodeTGitRepository import com.tencent.devops.repository.pojo.Repository @@ -49,12 +50,12 @@ open class GitWebHookMatcher( pipelineId: String, repository: Repository, webHookParams: WebHookParams - ): ScmWebhookMatcher.MatchResult { + ): WebhookMatchResult { if (repository !is CodeGitRepository && repository !is CodeTGitRepository ) { logger.warn("$pipelineId|Is not code repo for git web hook for repo and pipeline: $repository") - return ScmWebhookMatcher.MatchResult(isMatch = false) + return WebhookMatchResult(isMatch = false) } return eventHandler.isMatch( event = event, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/GithubWebHookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/GithubWebHookMatcher.kt index 32b168b37ab..49b9b723722 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/GithubWebHookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/GithubWebHookMatcher.kt @@ -30,6 +30,7 @@ package com.tencent.devops.common.webhook.service.code.matcher import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeType import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.pojo.code.github.GithubEvent +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.repository.pojo.GithubRepository import com.tencent.devops.repository.pojo.Repository import org.slf4j.LoggerFactory @@ -48,10 +49,10 @@ class GithubWebHookMatcher( pipelineId: String, repository: Repository, webHookParams: WebHookParams - ): ScmWebhookMatcher.MatchResult { + ): WebhookMatchResult { if (repository !is GithubRepository) { logger.warn("$pipelineId|The repo($repository) is not code git repo for github web hook") - return ScmWebhookMatcher.MatchResult(isMatch = false) + return WebhookMatchResult(isMatch = false) } return eventHandler.isMatch( event = event, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/GitlabWebHookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/GitlabWebHookMatcher.kt index 3469dee5056..f5d01b1bbd4 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/GitlabWebHookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/GitlabWebHookMatcher.kt @@ -30,6 +30,7 @@ package com.tencent.devops.common.webhook.service.code.matcher import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeType import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.pojo.code.git.GitEvent +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.repository.pojo.CodeGitlabRepository import com.tencent.devops.repository.pojo.Repository import org.slf4j.LoggerFactory @@ -47,10 +48,10 @@ class GitlabWebHookMatcher( pipelineId: String, repository: Repository, webHookParams: WebHookParams - ): ScmWebhookMatcher.MatchResult { + ): WebhookMatchResult { if (repository !is CodeGitlabRepository) { logger.warn("$$pipelineId|the repo($repository) is not code git repo for git web hook") - return ScmWebhookMatcher.MatchResult(isMatch = false) + return WebhookMatchResult(isMatch = false) } return eventHandler.isMatch( event = event, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/P4WebHookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/P4WebHookMatcher.kt index 011df0a3565..9b095b1780c 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/P4WebHookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/P4WebHookMatcher.kt @@ -30,6 +30,7 @@ package com.tencent.devops.common.webhook.service.code.matcher import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeType import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.pojo.code.p4.P4Event +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.repository.pojo.CodeP4Repository import com.tencent.devops.repository.pojo.Repository import org.slf4j.LoggerFactory @@ -47,10 +48,10 @@ class P4WebHookMatcher( pipelineId: String, repository: Repository, webHookParams: WebHookParams - ): ScmWebhookMatcher.MatchResult { + ): WebhookMatchResult { if (repository !is CodeP4Repository) { logger.warn("$pipelineId|The repo($repository) is not code p4 repo for p4 web hook") - return ScmWebhookMatcher.MatchResult(isMatch = false) + return WebhookMatchResult(isMatch = false) } return eventHandler.isMatch( event = event, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt index a6c7d047ce7..718fbae741e 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt @@ -30,6 +30,7 @@ package com.tencent.devops.common.webhook.service.code.matcher import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeType import com.tencent.devops.common.webhook.pojo.code.WebHookParams +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.pojo.WebhookCommit import org.slf4j.LoggerFactory @@ -40,14 +41,14 @@ interface ScmWebhookMatcher { /** * 预匹配,在还没有解析流水线列表时判断 */ - fun preMatch(): MatchResult + fun preMatch(): WebhookMatchResult fun isMatch( projectId: String, pipelineId: String, repository: Repository, webHookParams: WebHookParams - ): MatchResult + ): WebhookMatchResult fun getUsername(): String @@ -71,6 +72,16 @@ interface ScmWebhookMatcher { fun getMessage(): String? + /** + * 获取事件描述,根据不同的事件组织事件说明 + */ + fun getEventDesc(): String = "" + + /** + * 获取webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port + */ + fun getExternalId(): String = "" + fun getWebHookParamsMap(): Map = emptyMap() fun retrieveParams( diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/SvnWebHookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/SvnWebHookMatcher.kt index b35513abd10..1c5c0d6958d 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/SvnWebHookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/SvnWebHookMatcher.kt @@ -30,6 +30,7 @@ package com.tencent.devops.common.webhook.service.code.matcher import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeType import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.pojo.code.svn.SvnCommitEvent +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.repository.pojo.CodeSvnRepository import com.tencent.devops.repository.pojo.Repository import org.slf4j.LoggerFactory @@ -48,10 +49,10 @@ class SvnWebHookMatcher( pipelineId: String, repository: Repository, webHookParams: WebHookParams - ): ScmWebhookMatcher.MatchResult { + ): WebhookMatchResult { if (repository !is CodeSvnRepository) { logger.warn("$pipelineId|The repo($repository) is not code svn repo for svn web hook") - return ScmWebhookMatcher.MatchResult(isMatch = false) + return WebhookMatchResult(isMatch = false) } return eventHandler.isMatch( event = event, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GitWebHookStartParam.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GitWebHookStartParam.kt index b9f7d476507..3631406142d 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GitWebHookStartParam.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GitWebHookStartParam.kt @@ -46,6 +46,7 @@ import com.tencent.devops.common.webhook.pojo.code.MATCH_PATHS import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.service.code.EventCacheService import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.repository.pojo.CodeGitRepository import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.repository.pojo.enums.RepoAuthType @@ -68,7 +69,7 @@ class GitWebHookStartParam @Autowired constructor( matcher: ScmWebhookMatcher, variables: Map, params: WebHookParams, - matchResult: ScmWebhookMatcher.MatchResult + matchResult: WebhookMatchResult ): Map { val startParams = mutableMapOf() startParams[BK_REPO_GIT_WEBHOOK_COMMIT_ID] = matcher.getRevision() diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GithubWebHookStartParam.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GithubWebHookStartParam.kt index 91389386616..08f60315cec 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GithubWebHookStartParam.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GithubWebHookStartParam.kt @@ -35,6 +35,7 @@ import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_EXCLUDE_U import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_INCLUDE_BRANCHS import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.repository.pojo.Repository import org.springframework.stereotype.Service @@ -52,7 +53,7 @@ class GithubWebHookStartParam : ScmWebhookStartParams, params: WebHookParams, - matchResult: ScmWebhookMatcher.MatchResult + matchResult: WebhookMatchResult ): Map { val startParams = mutableMapOf() startParams[BK_REPO_GIT_WEBHOOK_COMMIT_ID] = matcher.getRevision() diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GitlabWebHookStartParam.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GitlabWebHookStartParam.kt index edf44d05355..14442ac5822 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GitlabWebHookStartParam.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GitlabWebHookStartParam.kt @@ -41,6 +41,7 @@ import com.tencent.devops.common.webhook.pojo.code.MATCH_BRANCH import com.tencent.devops.common.webhook.pojo.code.MATCH_PATHS import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.repository.pojo.Repository import org.springframework.stereotype.Service @@ -58,7 +59,7 @@ class GitlabWebHookStartParam : ScmWebhookStartParams, params: WebHookParams, - matchResult: ScmWebhookMatcher.MatchResult + matchResult: WebhookMatchResult ): Map { val startParams = mutableMapOf() startParams[BK_REPO_GIT_WEBHOOK_COMMIT_ID] = matcher.getRevision() diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/P4WebHookStartParam.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/P4WebHookStartParam.kt index 3969e41f0b6..3d69b07fb22 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/P4WebHookStartParam.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/P4WebHookStartParam.kt @@ -33,6 +33,7 @@ import com.tencent.devops.common.webhook.pojo.code.BK_REPO_P4_WEBHOOK_INCLUDE_PA import com.tencent.devops.common.webhook.pojo.code.BK_REPO_P4_WEBHOOK_P4PORT import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.repository.pojo.Repository import org.springframework.stereotype.Service @@ -50,7 +51,7 @@ class P4WebHookStartParam : ScmWebhookStartParams { matcher: ScmWebhookMatcher, variables: Map, params: WebHookParams, - matchResult: ScmWebhookMatcher.MatchResult + matchResult: WebhookMatchResult ): Map { val startParams = mutableMapOf() with(element.data.input) { diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/ScmWebhookStartParams.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/ScmWebhookStartParams.kt index 1badbd260b5..7168d5b32fa 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/ScmWebhookStartParams.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/ScmWebhookStartParams.kt @@ -53,6 +53,7 @@ import com.tencent.devops.common.webhook.pojo.code.PIPELINE_WEBHOOK_TARGET_URL import com.tencent.devops.common.webhook.pojo.code.PIPELINE_WEBHOOK_TYPE import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.process.utils.PIPELINE_BUILD_MSG import com.tencent.devops.process.utils.PIPELINE_START_TASK_ID import com.tencent.devops.repository.pojo.Repository @@ -70,7 +71,7 @@ interface ScmWebhookStartParams { matcher: ScmWebhookMatcher, variables: Map, params: WebHookParams, - matchResult: ScmWebhookMatcher.MatchResult + matchResult: WebhookMatchResult ): Map { val startParams = mutableMapOf() startParams.putAll( @@ -160,6 +161,6 @@ interface ScmWebhookStartParams { matcher: ScmWebhookMatcher, variables: Map, params: WebHookParams, - matchResult: ScmWebhookMatcher.MatchResult + matchResult: WebhookMatchResult ): Map } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/SvnWebHookStartParam.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/SvnWebHookStartParam.kt index af3f0c82b22..cd2076278f9 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/SvnWebHookStartParam.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/SvnWebHookStartParam.kt @@ -36,6 +36,7 @@ import com.tencent.devops.common.webhook.pojo.code.BK_REPO_SVN_WEBHOOK_RELATIVE_ import com.tencent.devops.common.webhook.pojo.code.MATCH_PATHS import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.repository.pojo.Repository import org.springframework.stereotype.Service @@ -53,7 +54,7 @@ class SvnWebHookStartParam : ScmWebhookStartParams matcher: ScmWebhookMatcher, variables: Map, params: WebHookParams, - matchResult: ScmWebhookMatcher.MatchResult + matchResult: WebhookMatchResult ): Map { val startParams = mutableMapOf() startParams[BK_REPO_SVN_WEBHOOK_RELATIVE_PATH] = element.relativePath ?: "" diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/TGitWebHookStartParam.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/TGitWebHookStartParam.kt index 629c558f0b3..42effc5e8d3 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/TGitWebHookStartParam.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/TGitWebHookStartParam.kt @@ -43,6 +43,7 @@ import com.tencent.devops.common.webhook.pojo.code.MATCH_PATHS import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.service.code.GitScmService import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.repository.pojo.CodeTGitRepository import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.repository.pojo.enums.RepoAuthType @@ -65,7 +66,7 @@ class TGitWebHookStartParam @Autowired constructor( matcher: ScmWebhookMatcher, variables: Map, params: WebHookParams, - matchResult: ScmWebhookMatcher.MatchResult + matchResult: WebhookMatchResult ): Map { val startParams = mutableMapOf() with(element.data.input) { diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/pojo/WebhookMatchResult.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/pojo/WebhookMatchResult.kt new file mode 100644 index 00000000000..aa8a6be062d --- /dev/null +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/pojo/WebhookMatchResult.kt @@ -0,0 +1,42 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.common.webhook.service.code.pojo + +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty + +@ApiModel +data class WebhookMatchResult( + @ApiModelProperty("是否匹配") + val isMatch: Boolean, + @ApiModelProperty("匹配时输出的变量") + val extra: Map = mapOf(), + @ApiModelProperty("匹配失败原因") + val reason: String? = null +) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt new file mode 100644 index 00000000000..036762223bb --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt @@ -0,0 +1,193 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.api.user + +import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID +import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID_DEFAULT_VALUE +import com.tencent.devops.common.api.model.SQLPage +import com.tencent.devops.common.api.pojo.Result +import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent +import com.tencent.devops.process.pojo.webhook.RepoWebhookEvent +import io.swagger.annotations.Api +import io.swagger.annotations.ApiOperation +import io.swagger.annotations.ApiParam +import javax.ws.rs.Consumes +import javax.ws.rs.GET +import javax.ws.rs.HeaderParam +import javax.ws.rs.POST +import javax.ws.rs.Path +import javax.ws.rs.PathParam +import javax.ws.rs.Produces +import javax.ws.rs.QueryParam +import javax.ws.rs.core.MediaType + +@Api(tags = ["USER_PIPELINE_TRIGGER_EVENT"], description = "用户-流水线触发事件") +@Path("/user/trigger/event") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +interface UserPipelineTriggerEventResource { + + @ApiOperation("获取流水线触发事件列表") + @GET + @Path("/{projectId}/{pipelineId}/listTriggerEvent") + fun listTriggerEvent( + @ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, + @ApiParam("项目ID", required = true) + @PathParam("projectId") + projectId: String, + @ApiParam("流水线ID", required = true) + @PathParam("pipelineId") + pipelineId: String, + @ApiParam("事件类型", required = false) + @QueryParam("eventType") + eventType: String?, + @ApiParam("触发类型", required = false) + @QueryParam("triggerType") + triggerType: String?, + @ApiParam("触发用户", required = false) + @QueryParam("triggerUser") + triggerUser: String?, + @ApiParam("开始时间", required = false) + @QueryParam("startTime") + startTime: Long?, + @ApiParam("结束", required = false) + @QueryParam("startTime") + endTime: Long?, + @ApiParam("第几页", required = false, defaultValue = "1") + @QueryParam("page") + page: Int?, + @ApiParam("每页多少条", required = false, defaultValue = "20") + @QueryParam("pageSize") + pageSize: Int? + ): Result> + + @ApiOperation("获取代码库webhook事件列表") + @GET + @Path("/{projectId}/{repoHashId}/listRepoWebhookEvent") + fun listRepoWebhookEvent( + @ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, + @ApiParam("项目ID", required = true) + @PathParam("projectId") + projectId: String, + @ApiParam("代码库hashId", required = true) + @PathParam("repoHashId") + repoHashId: String, + @ApiParam("事件类型", required = false) + @QueryParam("eventType") + eventType: String?, + @ApiParam("触发类型", required = false) + @QueryParam("triggerType") + triggerType: String?, + @ApiParam("触发用户", required = false) + @QueryParam("triggerUser") + triggerUser: String?, + @ApiParam("流水线ID", required = true) + @QueryParam("pipelineId") + pipelineId: String?, + @ApiParam("事件ID", required = true) + @QueryParam("eventId") + eventId: Long?, + @ApiParam("开始时间", required = false) + @QueryParam("startTime") + startTime: Long?, + @ApiParam("结束", required = false) + @QueryParam("startTime") + endTime: Long?, + @ApiParam("第几页", required = false, defaultValue = "1") + @QueryParam("page") + page: Int?, + @ApiParam("每页多少条", required = false, defaultValue = "20") + @QueryParam("pageSize") + pageSize: Int? + ): Result> + + @ApiOperation("获取代码库webhook事件触发详情") + @GET + @Path("/{projectId}/{repoHashId}/listRepoWebhookEvent") + fun listRepoWebhookEventDetail( + @ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, + @ApiParam("项目ID", required = true) + @PathParam("projectId") + projectId: String, + @ApiParam("代码库hashId", required = true) + @PathParam("repoHashId") + repoHashId: String, + @ApiParam("事件ID", required = true) + @QueryParam("eventId") + eventId: Long, + @ApiParam("流水线ID", required = true) + @PathParam("pipelineId") + pipelineId: String, + @ApiParam("第几页", required = false, defaultValue = "1") + @QueryParam("page") + page: Int?, + @ApiParam("每页多少条", required = false, defaultValue = "20") + @QueryParam("pageSize") + pageSize: Int?, + ): Result> + + @ApiOperation("重新触发") + @POST + @Path("/{projectId}/{id}/replay") + fun replay( + @ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, + @ApiParam("项目ID", required = true) + @PathParam("projectId") + projectId: String, + @ApiParam("触发ID", required = true) + @PathParam("id") + id: Long + ): Result + + @ApiOperation("一键重新触发") + @POST + @Path("/{projectId}/{repoHashId}/{eventId}/replayAll") + fun replayAll( + @ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, + @ApiParam("项目ID", required = true) + @PathParam("projectId") + projectId: String, + @ApiParam("代码库ID", required = true) + @PathParam("repoHashId") + repoHashId: String, + @ApiParam("触发ID", required = true) + @PathParam("eventId") + eventId: Long + ): Result +} diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt new file mode 100644 index 00000000000..9e3b6e26a52 --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt @@ -0,0 +1,72 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.pojo.trigger + +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty +import java.time.LocalDateTime + +@ApiModel("流水线触发事件模型") +data class PipelineTriggerEvent( + var id: Long? = null, + @ApiModelProperty("蓝盾项目ID") + val projectId: String, + @ApiModelProperty("事件ID") + val eventId: Long, + @ApiModelProperty("触发类型") + val triggerType: String, + @ApiModelProperty("事件触发源,代码库触发-代码库ID", required = false) + val eventSource: String? = "", + @ApiModelProperty("事件类型") + val eventType: String, + @ApiModelProperty("触发人") + val triggerUser: String, + @ApiModelProperty("事件信息") + val eventMessage: String, + @ApiModelProperty("事件描述") + val eventDesc: String, + @ApiModelProperty("事件时间") + val eventTime: LocalDateTime, + @ApiModelProperty("触发状态") + var status: String, + @ApiModelProperty("流水线Id") + var pipelineId: String? = null, + @ApiModelProperty("流水线名称") + var pipelineName: String? = null, + @ApiModelProperty("构建Id") + var buildId: String? = null, + @ApiModelProperty("构建编号") + var buildNum: String? = null, + @ApiModelProperty("原因") + var reason: String? = null, + @ApiModelProperty("原因详情", required = false) + var reasonDetailList: List? = null, + @ApiModelProperty("创建时间", required = false) + val createTime: Long? = null +) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventBuilder.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventBuilder.kt new file mode 100644 index 00000000000..64ae831e4b1 --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventBuilder.kt @@ -0,0 +1,116 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.pojo.trigger + +import com.tencent.devops.process.pojo.webhook.PipelineWebhookEvent +import java.time.LocalDateTime + +class PipelineTriggerEventBuilder { + private lateinit var projectId: String + private var eventId: Long? = null + private lateinit var triggerType: String + private lateinit var eventType: String + private lateinit var triggerUser: String + private lateinit var eventMessage: String + private lateinit var eventDesc: String + private lateinit var eventTime: LocalDateTime + private var eventSource: String? = null + private var status: String = "" + private var pipelineId: String? = null + private var pipelineName: String? = null + private var buildId: String? = null + private var buildNum: String? = null + private var reason: String? = null + private var reasonDetailList: MutableList? = null + + fun webhookEvent(webhookEvent: PipelineWebhookEvent) = apply { + this.eventId = webhookEvent.eventId + this.eventType = webhookEvent.eventType + this.triggerUser = webhookEvent.triggerUser + this.eventMessage = webhookEvent.eventMessage + this.eventDesc = webhookEvent.eventDesc + this.eventTime = webhookEvent.eventTime + this.triggerType = webhookEvent.triggerType + } + + fun projectId(projectId: String) = apply { + this.projectId = projectId + } + + fun pipelineId(pipelineId: String) = apply { + this.pipelineId = pipelineId + } + + fun pipelineName(pipelineName: String) = apply { + this.pipelineName = pipelineName + } + + fun eventSource(eventSource: String) = apply { + this.eventSource = eventSource + } + + fun getEventSource() = eventSource + + fun buildId(buildId: String) = apply { + this.buildId = buildId + } + + fun reason(reason: String) = apply { + this.reason = reason + } + + fun reasonDetail(reasonDetail: String) = apply { + if (reasonDetailList == null) { + reasonDetailList = mutableListOf(reasonDetail) + } else { + reasonDetailList!!.add(reasonDetail) + } + } + + fun build(): PipelineTriggerEvent { + return PipelineTriggerEvent( + projectId = projectId, + eventId = eventId!!, + triggerType = triggerType, + eventSource = eventSource, + eventType = eventType, + triggerUser = triggerUser, + eventMessage = eventMessage, + eventDesc = eventDesc, + eventTime = eventTime, + status = status, + pipelineId = pipelineId, + pipelineName = pipelineName, + buildId = buildId, + buildNum = buildNum, + reason = reason, + reasonDetailList = reasonDetailList + ) + } +} diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerReason.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerReason.kt new file mode 100644 index 00000000000..e4338f1b025 --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerReason.kt @@ -0,0 +1,34 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.pojo.trigger + +enum class PipelineTriggerReason(val detail: String) { + TRIGGER_SUCCESS("Trigger success"), + TRIGGER_NOT_MATCH("Does not meet the trigger condition :%s") +} diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerStatus.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerStatus.kt new file mode 100644 index 00000000000..aaa77a02dc1 --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerStatus.kt @@ -0,0 +1,34 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.pojo.trigger + +enum class PipelineTriggerStatus { + SUCCEED, + FAILED +} diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt new file mode 100644 index 00000000000..f796b5bec0e --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt @@ -0,0 +1,68 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.devops.process.pojo.trigger + +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty + +@ApiModel("流水线触发类型") +enum class PipelineTriggerType { + // WEB_HOOK 触发 + @ApiModelProperty("SVN 代码库") + CODE_SVN, + @ApiModelProperty("GIT 代码库") + CODE_GIT, + @ApiModelProperty("Gitlab 代码库") + CODE_GITLAB, + @ApiModelProperty("Github 代码库") + GITHUB, + @ApiModelProperty("TGIT 代码库") + CODE_TGIT, + @ApiModelProperty("P4 代码库") + CODE_P4, + + // 手动触发 + @ApiModelProperty("手动触发") + MANUAL, + + // 定时触发 + @ApiModelProperty("定时触发") + TIME_TRIGGER, + + // 服务触发 + @ApiModelProperty("服务触发") + SERVICE, + + // 流水线触发 + @ApiModelProperty("流水线触发") + PIPELINE, + + // 远程触发 + @ApiModelProperty("远程触发") + REMOTE; +} diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineTriggerTask.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineTriggerTask.kt new file mode 100644 index 00000000000..b1512a27770 --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineTriggerTask.kt @@ -0,0 +1,38 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.pojo.webhook + +/** + * 流水线webhook触发插件 + */ +data class PipelineTriggerTask( + val projectId: String, + val pipelineId: String, + val taskId: String +) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhookEvent.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhookEvent.kt new file mode 100644 index 00000000000..f399aa3723d --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhookEvent.kt @@ -0,0 +1,59 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.pojo.webhook + +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty +import java.time.LocalDateTime + +@ApiModel("流水线webhook事件") +data class PipelineWebhookEvent( + @ApiModelProperty("事件处理类") + val taskAtom: String, + @ApiModelProperty("事件请求ID") + val requestId: Long, + @ApiModelProperty("事件ID") + val eventId: Long, + @ApiModelProperty("触发类型") + val triggerType: String, + @ApiModelProperty("事件类型") + val eventType: String, + @ApiModelProperty("触发人") + val triggerUser: String, + @ApiModelProperty("事件信息") + val eventMessage: String, + @ApiModelProperty("事件描述") + val eventDesc: String, + @ApiModelProperty("触发事件") + val eventTime: LocalDateTime, + @ApiModelProperty("项目ID") + var projectId: String? = null, + @ApiModelProperty("事件源", required = false) + var eventSource: String? = null, +) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhookSubscriber.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhookSubscriber.kt new file mode 100644 index 00000000000..29a4a3bd4f9 --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhookSubscriber.kt @@ -0,0 +1,35 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.pojo.webhook + +data class PipelineWebhookSubscriber( + val projectId: String, + val pipelineId: String, + val version: Int? = null +) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/RepoWebhookEvent.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/RepoWebhookEvent.kt new file mode 100644 index 00000000000..350af4c02df --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/RepoWebhookEvent.kt @@ -0,0 +1,50 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.pojo.webhook + +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty + +@ApiModel("代码库webhook事件记录") +data class RepoWebhookEvent( + @ApiModelProperty("项目ID") + val projectId: String, + @ApiModelProperty("事件ID") + val eventId: Long, + @ApiModelProperty("代码库ID", required = false) + val repoHashId: String, + @ApiModelProperty("事件描述") + val eventDesc: String, + @ApiModelProperty("触发时间") + val eventTime: Long, + @ApiModelProperty("总流水线数") + val total: Int, + @ApiModelProperty("成功的流水线数") + val success: Int +) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt index 52f9ccc5f76..2d5848e5f03 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt @@ -31,12 +31,14 @@ import com.tencent.devops.common.api.enums.RepositoryType import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.model.process.Tables.T_PIPELINE_WEBHOOK import com.tencent.devops.model.process.tables.records.TPipelineWebhookRecord +import com.tencent.devops.process.pojo.webhook.PipelineTriggerTask import com.tencent.devops.process.pojo.webhook.PipelineWebhook +import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber import org.jooq.DSLContext -import org.jooq.Record2 import org.jooq.Result import org.slf4j.LoggerFactory import org.springframework.stereotype.Repository +import java.time.LocalDateTime @Suppress("ALL") @Repository @@ -151,14 +153,19 @@ class PipelineWebhookDao { dslContext: DSLContext, projectName: String, repositoryType: String - ): Result>? { + ): List? { with(T_PIPELINE_WEBHOOK) { return dslContext.select(PROJECT_ID, PIPELINE_ID).from(this) .where(PROJECT_NAME.eq(projectName)) .and(REPOSITORY_TYPE.eq(repositoryType)) .and(DELETE.eq(false)) .groupBy(PROJECT_ID, PIPELINE_ID) - .fetch() + .fetch().map { + PipelineWebhookSubscriber( + projectId = it.value1(), + pipelineId = it.value2() + ) + } } } @@ -220,6 +227,81 @@ class PipelineWebhookDao { }?.map { convert(it) } } + fun save( + dslContext: DSLContext, + projectId: String, + pipelineId: String, + repositoryType: String, + repoType: String, + repoHashId: String?, + repoName: String?, + projectName: String, + taskId: String, + eventSource: String, + eventType: String + ): Int { + val now = LocalDateTime.now() + return with(T_PIPELINE_WEBHOOK) { + dslContext.insertInto( + this, + PROJECT_ID, + PIPELINE_ID, + REPOSITORY_TYPE, + REPO_TYPE, + REPO_HASH_ID, + REPO_NAME, + PROJECT_NAME, + TASK_ID, + EVENT_SOURCE, + EVENT_TYPE, + CREATE_TIME, + UPDATE_TIME + ) + .values( + projectId, + pipelineId, + repositoryType, + repoType, + repoHashId, + repoName, + projectName, + taskId, + eventSource, + eventType, + now, + now + ) + .onDuplicateKeyUpdate() + .set(REPO_TYPE, repoType) + .set(REPO_HASH_ID, repoHashId) + .set(REPO_NAME, repoName) + .set(PROJECT_NAME, projectName) + .set(EVENT_SOURCE, eventSource) + .set(EVENT_TYPE, eventType) + .set(UPDATE_TIME, now) + .execute() + } + } + + fun getSubscriber( + dslContext: DSLContext, + eventSource: String, + eventType: String + ): List { + return with(T_PIPELINE_WEBHOOK) { + dslContext.select(PROJECT_ID, PIPELINE_ID, TASK_ID).from(this) + .where(EVENT_SOURCE.eq(eventSource)) + .and(EVENT_TYPE.eq(eventType)) + .fetch { + PipelineTriggerTask( + projectId = it.value1(), + pipelineId = it.value2(), + taskId = it.value3() + ) + } + } + } + companion object { private val logger = LoggerFactory.getLogger(PipelineWebhookDao::class.java) } diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/scm/ScmProxyService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/scm/ScmProxyService.kt index 41c4fdd33fe..59f8f72aa96 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/scm/ScmProxyService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/scm/ScmProxyService.kt @@ -379,7 +379,11 @@ class ScmProxyService @Autowired constructor(private val client: Client) { } } - fun addGitWebhook(projectId: String, repositoryConfig: RepositoryConfig, codeEventType: CodeEventType?): String { + fun addGitWebhook( + projectId: String, + repositoryConfig: RepositoryConfig, + codeEventType: CodeEventType? + ): CodeGitRepository { checkRepoID(repositoryConfig) val repo = getRepo(projectId, repositoryConfig) as? CodeGitRepository ?: throw ErrorCodeException(errorCode = ProcessMessageCode.GIT_INVALID) @@ -418,7 +422,7 @@ class ScmProxyService @Autowired constructor(private val client: Client) { ) } - return repo.projectName + return repo } fun addGitlabWebhook(projectId: String, repositoryConfig: RepositoryConfig, codeEventType: CodeEventType?): String { diff --git a/src/backend/ci/core/process/biz-process-sample/src/main/kotlin/com/tencent/devops/process/service/webhook/SamplePipelineBuildWebhookService.kt b/src/backend/ci/core/process/biz-process-sample/src/main/kotlin/com/tencent/devops/process/service/webhook/SamplePipelineBuildWebhookService.kt index ea5daee43d7..f72b81a5261 100644 --- a/src/backend/ci/core/process/biz-process-sample/src/main/kotlin/com/tencent/devops/process/service/webhook/SamplePipelineBuildWebhookService.kt +++ b/src/backend/ci/core/process/biz-process-sample/src/main/kotlin/com/tencent/devops/process/service/webhook/SamplePipelineBuildWebhookService.kt @@ -33,6 +33,7 @@ import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.permission.PipelinePermissionService +import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventBuilder import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service @@ -59,9 +60,14 @@ class SamplePipelineBuildWebhookService : PipelineBuildWebhookService() { override fun webhookTriggerPipelineBuild( projectId: String, pipelineId: String, - codeRepositoryType: String, - matcher: ScmWebhookMatcher + matcher: ScmWebhookMatcher, + builder: PipelineTriggerEventBuilder ): Boolean { - return super.webhookTriggerPipelineBuild(projectId, pipelineId, codeRepositoryType, matcher) + return super.webhookTriggerPipelineBuild( + projectId = projectId, + pipelineId = pipelineId, + matcher = matcher, + builder = builder + ) } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt new file mode 100644 index 00000000000..bfc83cca320 --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt @@ -0,0 +1,147 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.api + +import com.tencent.devops.common.api.model.SQLPage +import com.tencent.devops.common.api.pojo.Result +import com.tencent.devops.common.web.RestResource +import com.tencent.devops.process.api.user.UserPipelineTriggerEventResource +import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent +import com.tencent.devops.process.pojo.webhook.RepoWebhookEvent +import com.tencent.devops.process.service.trigger.PipelineTriggerEventService + +@RestResource +class UserPipelineTriggerEventResourceImpl( + private val pipelineTriggerEventService: PipelineTriggerEventService +) : UserPipelineTriggerEventResource { + override fun listTriggerEvent( + userId: String, + projectId: String, + pipelineId: String, + eventType: String?, + triggerType: String?, + triggerUser: String?, + startTime: Long?, + endTime: Long?, + page: Int?, + pageSize: Int? + ): Result> { + return Result( + pipelineTriggerEventService.listTriggerEvent( + projectId = projectId, + pipelineId = pipelineId, + eventType = eventType, + triggerType = triggerType, + triggerUser = triggerUser, + startTime = startTime, + endTime = endTime, + page = page, + pageSize = pageSize + ) + ) + } + + override fun listRepoWebhookEvent( + userId: String, + projectId: String, + repoHashId: String, + eventType: String?, + triggerType: String?, + triggerUser: String?, + pipelineId: String?, + eventId: Long?, + startTime: Long?, + endTime: Long?, + page: Int?, + pageSize: Int? + ): Result> { + return Result( + pipelineTriggerEventService.listRepoWebhookEvent( + projectId = projectId, + repoHashId = repoHashId, + triggerType = triggerType, + eventType = eventType, + triggerUser = triggerUser, + pipelineId = pipelineId, + eventId = eventId, + startTime = startTime, + endTime = endTime, + page = page, + pageSize = pageSize + ) + ) + } + + override fun listRepoWebhookEventDetail( + userId: String, + projectId: String, + repoHashId: String, + eventId: Long, + pipelineId: String, + page: Int?, + pageSize: Int? + ): Result> { + return Result( + pipelineTriggerEventService.listRepoWebhookEventDetail( + projectId = projectId, + repoHashId = repoHashId, + eventId = eventId, + pipelineId = pipelineId, + page = page, + pageSize = pageSize + ) + ) + } + + override fun replay(userId: String, projectId: String, id: Long): Result { + return Result( + pipelineTriggerEventService.replay( + userId = userId, + projectId = projectId, + id = id + ) + ) + } + + override fun replayAll( + userId: String, + projectId: String, + repoHashId: String, + eventId: Long + ): Result { + return Result( + pipelineTriggerEventService.replayAll( + userId = userId, + projectId = projectId, + repoHashId = repoHashId, + eventId = eventId + ) + ) + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt new file mode 100644 index 00000000000..237b387b26c --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -0,0 +1,329 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.devops.process.dao + +import com.fasterxml.jackson.core.type.TypeReference +import com.tencent.devops.common.api.util.JsonUtil +import com.tencent.devops.common.api.util.timestamp +import com.tencent.devops.common.api.util.timestampmilli +import com.tencent.devops.model.process.tables.TPipelineTriggerEvent +import com.tencent.devops.model.process.tables.records.TPipelineTriggerEventRecord +import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus +import com.tencent.devops.process.pojo.webhook.RepoWebhookEvent +import org.jooq.Condition +import org.jooq.DSLContext +import org.jooq.Result +import org.jooq.impl.DSL.count +import org.jooq.impl.DSL.`when` +import org.springframework.stereotype.Repository +import java.sql.Timestamp +import java.time.LocalDateTime + +@Suppress("ALL") +@Repository +class PipelineTriggerEventDao { + fun save( + dslContext: DSLContext, + triggerEvent: PipelineTriggerEvent + ) { + with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { + dslContext.insertInto(this).columns( + ID, + PROJECT_ID, + EVENT_ID, + TRIGGER_TYPE, + EVENT_SOURCE, + EVENT_TYPE, + TRIGGER_USER, + EVENT_MESSAGE, + EVENT_DESC, + EVENT_TIME, + STATUS, + PIPELINE_ID, + PIPELINE_NAME, + BUILD_ID, + BUILD_NUM, + REASON, + REASON_DETAIL, + CREATE_TIME + ).values( + triggerEvent.id!!, + triggerEvent.projectId, + triggerEvent.eventId, + triggerEvent.triggerType, + triggerEvent.eventSource, + triggerEvent.eventType, + triggerEvent.triggerUser, + triggerEvent.eventMessage, + triggerEvent.eventDesc, + triggerEvent.eventTime, + triggerEvent.status, + triggerEvent.pipelineId, + triggerEvent.pipelineName, + triggerEvent.buildId, + triggerEvent.buildNum, + triggerEvent.reason, + triggerEvent.reasonDetailList?.let { + JsonUtil.toJson(it) + }, + LocalDateTime.now() + ).execute() + } + } + + fun listTriggerEvent( + dslContext: DSLContext, + projectId: String, + eventSource: String? = null, + eventId: Long? = null, + eventType: String? = null, + triggerType: String? = null, + triggerUser: String? = null, + pipelineId: String? = null, + startTime: Long? = null, + endTime: Long? = null, + limit: Int, + offset: Int + ): Result { + with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { + val conditions = buildConditions( + projectId = projectId, + eventSource = eventSource, + eventId = eventId, + eventType = eventType, + triggerUser = triggerUser, + triggerType = triggerType, + pipelineId = pipelineId, + startTime = startTime, + endTime = endTime + ) + return dslContext.selectFrom(this) + .where(conditions) + .orderBy(EVENT_TIME.desc()) + .limit(limit) + .offset(offset) + .fetch() + } + } + + fun countTriggerEvent( + dslContext: DSLContext, + projectId: String, + eventSource: String? = null, + eventId: Long? = null, + eventType: String? = null, + triggerType: String? = null, + triggerUser: String? = null, + pipelineId: String? = null, + startTime: Long? = null, + endTime: Long? = null + ): Long { + return with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { + val conditions = buildConditions( + projectId = projectId, + eventSource = eventSource, + eventId = eventId, + eventType = eventType, + triggerUser = triggerUser, + triggerType = triggerType, + pipelineId = pipelineId + ) + dslContext.selectCount().from(this) + .where(conditions) + .fetchOne(0, Long::class.java)!! + } + } + + fun listByEventIds( + dslContext: DSLContext, + eventIds: List + ): Result { + return with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { + dslContext.selectFrom(this) + .where(EVENT_ID.`in`(eventIds)) + .fetch() + } + } + + fun listRepoWebhookEvent( + dslContext: DSLContext, + projectId: String, + eventSource: String? = null, + eventId: Long? = null, + eventType: String? = null, + triggerType: String? = null, + triggerUser: String? = null, + pipelineId: String? = null, + startTime: Long? = null, + endTime: Long? = null, + limit: Int, + offset: Int + ): List { + return with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { + val conditions = buildConditions( + projectId = projectId, + eventSource = eventSource, + eventId = eventId, + eventType = eventType, + triggerUser = triggerUser, + triggerType = triggerType, + pipelineId = pipelineId + ) + dslContext.select( + PROJECT_ID, + EVENT_ID, + EVENT_SOURCE, + EVENT_DESC, + EVENT_TIME, + count().`as`("total"), + count(`when`(STATUS.eq(PipelineTriggerStatus.SUCCEED.name), 1)).`as`("success ") + ) + .from(this) + .where(conditions) + .groupBy(PROJECT_ID, EVENT_ID, EVENT_SOURCE, EVENT_DESC, EVENT_TIME) + .orderBy(EVENT_TIME.desc()) + .limit(limit) + .offset(offset) + .fetch().map { + RepoWebhookEvent( + projectId = it.value1(), + eventId = it.value2(), + repoHashId = it.value3(), + eventDesc = it.value4(), + eventTime = it.value5().timestampmilli(), + total = it.value6(), + success = it.value7() + ) + } + } + } + + fun countRepoWebhookEvent( + dslContext: DSLContext, + projectId: String, + eventSource: String? = null, + eventId: Long? = null, + eventType: String? = null, + triggerType: String? = null, + triggerUser: String? = null, + pipelineId: String? = null, + startTime: Long? = null, + endTime: Long? = null + ): Long { + return with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { + val conditions = buildConditions( + projectId = projectId, + eventSource = eventSource, + eventId = eventId, + eventType = eventType, + triggerUser = triggerUser, + triggerType = triggerType, + pipelineId = pipelineId + ) + dslContext.selectCount().from(this) + .where(conditions) + .groupBy(PROJECT_ID, EVENT_ID, EVENT_SOURCE, EVENT_DESC, EVENT_TIME) + .fetchOne(0, Long::class.java)!! + } + } + + fun get( + dslContext: DSLContext, + id: Long + ): PipelineTriggerEvent? { + val record = with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { + dslContext.selectFrom(this).where(ID.eq(id)).fetchOne() + } + return record?.let { convert(it) } + } + + private fun TPipelineTriggerEvent.buildConditions( + projectId: String, + eventSource: String? = null, + eventId: Long? = null, + eventType: String? = null, + triggerUser: String? = null, + triggerType: String? = null, + pipelineId: String? = null, + startTime: Long? = null, + endTime: Long? = null + ): List { + val conditions = mutableListOf() + conditions.add(PROJECT_ID.eq(projectId)) + if (!eventSource.isNullOrBlank()) { + conditions.add(EVENT_SOURCE.eq(eventSource)) + } + if (eventId != null) { + conditions.add(EVENT_ID.eq(eventId)) + } + if (!eventType.isNullOrBlank()) { + conditions.add(EVENT_TYPE.eq(eventType)) + } + if (!triggerUser.isNullOrBlank()) { + conditions.add(TRIGGER_USER.eq(triggerUser)) + } + if (!triggerType.isNullOrBlank()) { + conditions.add(TRIGGER_TYPE.eq(triggerType)) + } + if (!pipelineId.isNullOrBlank()) { + conditions.add(PIPELINE_ID.eq(pipelineId)) + } + if (startTime != null && startTime > 0) { + conditions.add(CREATE_TIME.ge(Timestamp(startTime).toLocalDateTime())) + } + if (endTime != null && endTime > 0) { + conditions.add(CREATE_TIME.le(Timestamp(endTime).toLocalDateTime())) + } + return conditions + } + + fun convert(record: TPipelineTriggerEventRecord): PipelineTriggerEvent { + return with (record) { + PipelineTriggerEvent( + projectId = projectId, + eventId = eventId, + eventSource = eventSource, + triggerType = triggerType, + triggerUser = triggerUser, + eventType = eventType, + eventMessage = eventMessage, + eventDesc = eventDesc, + eventTime = eventTime, + status = status, + pipelineId = pipelineId, + pipelineName = pipelineName, + buildId = buildId, + buildNum = buildNum, + reason = reason, + reasonDetailList = JsonUtil.to(reasonDetail, object: TypeReference>(){}), + createTime = createTime.timestamp() + ) + } + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineWebhookEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineWebhookEventDao.kt new file mode 100644 index 00000000000..9248c5c3523 --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineWebhookEventDao.kt @@ -0,0 +1,198 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.dao + +import com.tencent.devops.model.process.tables.TPipelineWebhookEvent +import com.tencent.devops.model.process.tables.records.TPipelineWebhookEventRecord +import com.tencent.devops.process.pojo.webhook.PipelineWebhookEvent +import org.jooq.Condition +import org.jooq.DSLContext +import org.springframework.stereotype.Repository +import java.sql.Timestamp + +@Repository +class PipelineWebhookEventDao { + + fun save(dslContext: DSLContext, webhookEvent: PipelineWebhookEvent) { + with(TPipelineWebhookEvent.T_PIPELINE_WEBHOOK_EVENT) { + dslContext.insertInto(this).columns( + PROJECT_ID, + REQUEST_ID, + EVENT_ID, + TRIGGER_TYPE, + EVENT_SOURCE, + EVENT_TYPE, + TRIGGER_USER, + EVENT_MESSAGE, + EVENT_DESC, + EVENT_TIME, + TASK_ATOM + ).values( + webhookEvent.projectId, + webhookEvent.requestId, + webhookEvent.eventId, + webhookEvent.triggerType, + webhookEvent.eventSource!!, + webhookEvent.eventType, + webhookEvent.triggerUser, + webhookEvent.eventMessage, + webhookEvent.eventDesc, + webhookEvent.eventTime, + webhookEvent.taskAtom + ).onDuplicateKeyIgnore().execute() + } + } + + fun list( + dslContext: DSLContext, + projectId: String, + eventSource: String, + triggerType: String?, + eventType: String?, + triggerUser: String?, + startTime: Long?, + endTime: Long?, + limit: Int, + offset: Int + ): List { + return with(TPipelineWebhookEvent.T_PIPELINE_WEBHOOK_EVENT) { + val conditions = buildConditions( + projectId = projectId, + eventSource = eventSource, + triggerType = triggerType, + triggerUser = triggerUser, + eventType = eventType, + startTime = startTime, + endTime = endTime + ) + dslContext.selectFrom(this) + .where(conditions) + .limit(limit) + .offset(offset) + .fetch { + convert(it) + } + } + } + + fun count( + dslContext: DSLContext, + projectId: String, + eventSource: String, + triggerType: String?, + eventType: String?, + triggerUser: String?, + startTime: Long?, + endTime: Long?, + ): Long { + return with(TPipelineWebhookEvent.T_PIPELINE_WEBHOOK_EVENT) { + val conditions = buildConditions( + projectId = projectId, + eventSource = eventSource, + triggerType = triggerType, + triggerUser = triggerUser, + eventType = eventType, + startTime = startTime, + endTime = endTime + ) + dslContext.selectCount() + .from(this) + .where(conditions) + .fetchOne(0, Long::class.java)!! + } + } + + fun get( + dslContext: DSLContext, + eventId: Long, + eventSource: String + ): PipelineWebhookEvent? { + val record = with(TPipelineWebhookEvent.T_PIPELINE_WEBHOOK_EVENT) { + dslContext.selectFrom(this) + .where(EVENT_ID.eq(eventId)) + .and(EVENT_SOURCE.eq(eventSource)) + .fetchOne() + } + return record?.let { convert(it) } + } + + private fun TPipelineWebhookEvent.buildConditions( + projectId: String, + eventSource: String? = null, + eventId: Long? = null, + eventType: String? = null, + triggerUser: String? = null, + triggerType: String? = null, + startTime: Long? = null, + endTime: Long? = null + ): List { + val conditions = mutableListOf() + conditions.add(PROJECT_ID.eq(projectId)) + if (!eventSource.isNullOrBlank()) { + conditions.add(EVENT_SOURCE.eq(eventSource)) + } + if (eventId != null) { + conditions.add(EVENT_ID.eq(eventId)) + } + if (!eventType.isNullOrBlank()) { + conditions.add(EVENT_TYPE.eq(eventType)) + } + if (!triggerUser.isNullOrBlank()) { + conditions.add(TRIGGER_USER.eq(triggerUser)) + } + if (!triggerType.isNullOrBlank()) { + conditions.add(TRIGGER_TYPE.eq(triggerType)) + } + if (startTime != null && startTime > 0) { + conditions.add(EVENT_TIME.ge(Timestamp(startTime).toLocalDateTime())) + } + if (endTime != null && endTime > 0) { + conditions.add(EVENT_TIME.le(Timestamp(endTime).toLocalDateTime())) + } + return conditions + } + + fun convert(record: TPipelineWebhookEventRecord): PipelineWebhookEvent { + return with(record) { + PipelineWebhookEvent( + projectId = projectId, + requestId = requestId, + eventId = eventId, + triggerType = triggerType, + eventSource = eventSource, + eventType = eventType, + triggerUser = triggerUser, + eventMessage = eventMessage, + eventDesc = eventDesc, + eventTime = eventTime, + taskAtom = taskAtom + ) + } + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index f4eaced2395..d769b794e31 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -63,7 +63,9 @@ import com.tencent.devops.process.engine.dao.PipelineWebhookDao import com.tencent.devops.process.engine.pojo.WebhookElementParams import com.tencent.devops.process.permission.PipelinePermissionService import com.tencent.devops.process.pojo.PipelineNotifyTemplateEnum +import com.tencent.devops.process.pojo.webhook.PipelineTriggerTask import com.tencent.devops.process.pojo.webhook.PipelineWebhook +import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber import com.tencent.devops.process.service.scm.ScmProxyService import com.tencent.devops.repository.api.ServiceRepositoryResource import org.jooq.DSLContext @@ -207,7 +209,11 @@ class PipelineWebhookService @Autowired constructor( redisLock.lock() return when (pipelineWebhook.repositoryType) { ScmType.CODE_GIT -> - scmProxyService.addGitWebhook(pipelineWebhook.projectId, repositoryConfig, codeEventType) + scmProxyService.addGitWebhook( + projectId = pipelineWebhook.projectId, + repositoryConfig = repositoryConfig, + codeEventType = codeEventType + ).projectName ScmType.CODE_SVN -> scmProxyService.addSvnWebhook(pipelineWebhook.projectId, repositoryConfig) ScmType.CODE_GITLAB -> @@ -250,6 +256,33 @@ class PipelineWebhookService @Autowired constructor( private fun pipelineEditUrl(projectId: String, pipelineId: String) = "${HomeHostUtil.innerServerHost()}/console/pipeline/$projectId/$pipelineId/edit" + fun save( + projectId: String, + pipelineId: String, + repositoryType: String, + repoType: String, + repoHashId: String?, + repoName: String?, + projectName: String, + taskId: String, + eventSource: String, + eventType: String + ) { + pipelineWebhookDao.save( + dslContext = dslContext, + projectId = projectId, + pipelineId = pipelineId, + repositoryType = repositoryType, + repoType = repoType, + repoHashId = repoHashId, + repoName = repoName, + projectName = projectName, + taskId = taskId, + eventSource = eventSource, + eventType = eventType + ) + } + fun deleteWebhook(projectId: String, pipelineId: String, userId: String): Result { logger.info("delete $pipelineId webhook by $userId") pipelineWebhookDao.deleteByPipelineId(dslContext, projectId, pipelineId) @@ -278,17 +311,12 @@ class PipelineWebhookService @Autowired constructor( } } - fun getWebhookPipelines(name: String, type: String): Set> { - val records = pipelineWebhookDao.getByProjectNameAndType( + fun getWebhookPipelines(name: String, repositoryType: String): List { + return pipelineWebhookDao.getByProjectNameAndType( dslContext = dslContext, projectName = getProjectName(name), - repositoryType = getWebhookScmType(type).name - ) - val pipelineWebhookSet = mutableSetOf>() - records?.forEach { - pipelineWebhookSet.add(Pair(it.value1(), it.value2())) - } - return pipelineWebhookSet + repositoryType = repositoryType + ) ?: emptyList() } fun getWebhookScmType(type: String) = @@ -621,6 +649,17 @@ class PipelineWebhookService @Autowired constructor( } } + fun getSubscriber( + eventSource: String, + eventType: String + ): List { + return pipelineWebhookDao.getSubscriber( + dslContext = dslContext, + eventSource = eventSource, + eventType = eventType + ) + } + private fun PipelineWebhook.doUpdateWebhookSecret( pipelines: MutableMap>, pipelineVariables: HashMap> diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt new file mode 100644 index 00000000000..a3d21f647fa --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt @@ -0,0 +1,267 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.service.trigger + +import com.tencent.devops.common.api.exception.ParamBlankException +import com.tencent.devops.common.api.model.SQLPage +import com.tencent.devops.common.api.util.PageUtil +import com.tencent.devops.common.client.Client +import com.tencent.devops.common.webhook.pojo.ReplayWebhookRequest +import com.tencent.devops.process.dao.PipelineTriggerEventDao +import com.tencent.devops.process.dao.PipelineWebhookEventDao +import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent +import com.tencent.devops.process.pojo.webhook.PipelineWebhookEvent +import com.tencent.devops.process.pojo.webhook.RepoWebhookEvent +import com.tencent.devops.process.webhook.listener.WebhookRequestService +import com.tencent.devops.project.api.service.ServiceAllocIdResource +import org.jooq.DSLContext +import org.jooq.impl.DSL +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.stereotype.Service + +@Suppress("ALL") +@Service +class PipelineTriggerEventService @Autowired constructor( + private val dslContext: DSLContext, + private val client: Client, + private val pipelineTriggerEventDao: PipelineTriggerEventDao, + private val pipelineWebhookEventDao: PipelineWebhookEventDao, + private val webhookRequestService: WebhookRequestService +) { + + companion object { + private val logger = LoggerFactory.getLogger(PipelineTriggerEventService::class.java) + private const val PIPELINE_WEBHOOK_EVENT_BIZ_ID = "PIPELINE_WEBHOOK_EVENT" + private const val PIPELINE_TRIGGER_EVENT_BIZ_ID = "PIPELINE_TRIGGER_EVENT" + } + + fun getWebhookEventId(): Long { + return client.get(ServiceAllocIdResource::class).generateSegmentId(PIPELINE_WEBHOOK_EVENT_BIZ_ID).data ?: 0 + } + + fun getTriggerEventId(): Long { + return client.get(ServiceAllocIdResource::class).generateSegmentId(PIPELINE_TRIGGER_EVENT_BIZ_ID).data ?: 0 + } + + fun saveEvent( + webhookEvent: PipelineWebhookEvent, + triggerEvent: PipelineTriggerEvent + ) { + triggerEvent.id = getTriggerEventId() + dslContext.transaction { configuration -> + val transactionContext = DSL.using(configuration) + pipelineWebhookEventDao.save( + dslContext = transactionContext, + webhookEvent = webhookEvent + ) + pipelineTriggerEventDao.save( + dslContext = transactionContext, + triggerEvent = triggerEvent + ) + } + } + + fun listTriggerEvent( + projectId: String, + pipelineId: String, + eventType: String?, + triggerType: String?, + triggerUser: String?, + startTime: Long?, + endTime: Long?, + page: Int?, + pageSize: Int? + ): SQLPage { + val pageNotNull = page ?: 0 + val pageSizeNotNull = pageSize ?: PageUtil.MAX_PAGE_SIZE + val sqlLimit = PageUtil.convertPageSizeToSQLMAXLimit(pageNotNull, pageSizeNotNull) + val count = pipelineTriggerEventDao.countTriggerEvent( + dslContext = dslContext, + projectId = projectId, + eventType = eventType, + triggerType = triggerType, + triggerUser = triggerUser, + pipelineId = pipelineId, + startTime = startTime, + endTime = endTime + ) + val records = pipelineTriggerEventDao.listTriggerEvent( + dslContext = dslContext, + projectId = projectId, + eventType = eventType, + triggerUser = triggerUser, + triggerType = triggerType, + pipelineId = pipelineId, + startTime = startTime, + endTime = endTime, + limit = sqlLimit.limit, + offset = sqlLimit.offset + ).map { pipelineTriggerEventDao.convert(it) } + return SQLPage(count = count, records = records) + } + + fun listRepoWebhookEvent( + projectId: String, + repoHashId: String, + triggerType: String?, + eventType: String?, + triggerUser: String?, + pipelineId: String?, + eventId: Long?, + startTime: Long?, + endTime: Long?, + page: Int?, + pageSize: Int? + ): SQLPage { + val pageNotNull = page ?: 0 + val pageSizeNotNull = pageSize ?: PageUtil.MAX_PAGE_SIZE + val sqlLimit = PageUtil.convertPageSizeToSQLMAXLimit(pageNotNull, pageSizeNotNull) + val count = pipelineTriggerEventDao.countRepoWebhookEvent( + dslContext = dslContext, + projectId = projectId, + eventSource = repoHashId, + eventType = eventType, + triggerType = triggerType, + triggerUser = triggerUser, + pipelineId = pipelineId, + eventId = eventId, + startTime = startTime, + endTime = endTime + ) + val records = pipelineTriggerEventDao.listRepoWebhookEvent( + dslContext = dslContext, + projectId = projectId, + eventSource = repoHashId, + eventType = eventType, + triggerType = triggerType, + triggerUser = triggerUser, + pipelineId = pipelineId, + eventId = eventId, + startTime = startTime, + endTime = endTime, + limit = sqlLimit.limit, + offset = sqlLimit.offset + ) + return SQLPage(count = count, records = records) + } + + fun listRepoWebhookEventDetail( + projectId: String, + repoHashId: String, + eventId: Long, + pipelineId: String?, + page: Int?, + pageSize: Int? + ): SQLPage { + if (projectId.isBlank()) { + throw ParamBlankException("Invalid projectId") + } + if (repoHashId.isBlank()) { + throw ParamBlankException("Invalid repoHashId") + } + val pageNotNull = page ?: 0 + val pageSizeNotNull = pageSize ?: PageUtil.MAX_PAGE_SIZE + val sqlLimit = PageUtil.convertPageSizeToSQLMAXLimit(pageNotNull, pageSizeNotNull) + val records = pipelineTriggerEventDao.listTriggerEvent( + dslContext = dslContext, + projectId = projectId, + eventSource = repoHashId, + eventId = eventId, + pipelineId = pipelineId, + limit = sqlLimit.limit, + offset = sqlLimit.offset + ).map { + pipelineTriggerEventDao.convert(it) + } + val count = pipelineTriggerEventDao.countTriggerEvent( + dslContext = dslContext, + projectId = projectId, + eventSource = repoHashId, + eventId = eventId, + pipelineId = pipelineId + ) + return SQLPage(count = count, records = records) + } + + fun replay( + userId: String, + projectId: String, + id: Long + ): Boolean { + val pipelineTriggerEvent = pipelineTriggerEventDao.get(dslContext = dslContext, id = id) ?: return false + val eventId = pipelineTriggerEvent.eventId + val repoHashId = pipelineTriggerEvent.eventSource!! + val webhookEvent = pipelineWebhookEventDao.get( + dslContext = dslContext, + eventId = eventId, + eventSource = repoHashId + ) ?: return false + + val replayWebhookRequest = with(webhookEvent) { + ReplayWebhookRequest( + taskAtom = webhookEvent.taskAtom, + userId = userId, + projectId = projectId, + eventId = webhookEvent.eventId, + requestId = requestId, + eventSource = eventSource!!, + pipelineId = pipelineTriggerEvent.pipelineId!! + ) + } + webhookRequestService.handleReplayRequest(request = replayWebhookRequest) + return true + } + + fun replayAll( + userId: String, + projectId: String, + repoHashId: String, + eventId: Long + ): Boolean { + val webhookEvent = pipelineWebhookEventDao.get( + dslContext = dslContext, + eventId = eventId, + eventSource = repoHashId + ) ?: return false + + val replayWebhookRequest = with(webhookEvent) { + ReplayWebhookRequest( + taskAtom = taskAtom, + userId = userId, + projectId = projectId, + eventId = eventId, + requestId = requestId, + eventSource = repoHashId + ) + } + webhookRequestService.handleReplayRequest(request = replayWebhookRequest) + return true + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt index 3ed4f069ed7..43dcb891d71 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt @@ -28,56 +28,36 @@ package com.tencent.devops.process.service.webhook import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.module.kotlin.readValue -import com.tencent.devops.common.api.enums.RepositoryTypeNew -import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.util.JsonUtil -import com.tencent.devops.common.api.util.Watcher import com.tencent.devops.common.client.Client import com.tencent.devops.common.log.pojo.message.LogMessage import com.tencent.devops.common.log.utils.BuildLogPrinter import com.tencent.devops.common.pipeline.container.TriggerContainer -import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.common.pipeline.enums.StartType import com.tencent.devops.common.pipeline.pojo.BuildParameters -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitGenericWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGithubWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitlabWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeP4WebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeSVNWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeTGitWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.WebHookTriggerElement -import com.tencent.devops.common.webhook.pojo.code.git.GitEvent -import com.tencent.devops.common.webhook.pojo.code.git.GitReviewEvent -import com.tencent.devops.common.webhook.pojo.code.github.GithubCheckRunEvent -import com.tencent.devops.common.webhook.pojo.code.github.GithubCreateEvent -import com.tencent.devops.common.webhook.pojo.code.github.GithubEvent -import com.tencent.devops.common.webhook.pojo.code.github.GithubPullRequestEvent -import com.tencent.devops.common.webhook.pojo.code.github.GithubPushEvent -import com.tencent.devops.common.webhook.pojo.code.p4.P4Event -import com.tencent.devops.common.webhook.pojo.code.svn.SvnCommitEvent import com.tencent.devops.common.webhook.service.code.loader.WebhookElementParamsRegistrar import com.tencent.devops.common.webhook.service.code.loader.WebhookStartParamsRegistrar import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher import com.tencent.devops.common.webhook.util.EventCacheUtil -import com.tencent.devops.process.api.service.ServiceBuildResource import com.tencent.devops.process.api.service.ServiceScmWebhookResource import com.tencent.devops.process.engine.service.PipelineRepositoryService import com.tencent.devops.process.engine.service.PipelineWebHookQueueService -import com.tencent.devops.process.engine.service.PipelineWebhookBuildLogContext import com.tencent.devops.process.engine.service.PipelineWebhookService import com.tencent.devops.process.engine.service.WebhookBuildParameterService import com.tencent.devops.process.engine.service.code.GitWebhookUnlockDispatcher import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder import com.tencent.devops.process.pojo.code.WebhookCommit +import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventBuilder +import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason +import com.tencent.devops.process.pojo.webhook.PipelineWebhookEvent +import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber import com.tencent.devops.process.service.builds.PipelineBuildCommitService import com.tencent.devops.process.service.pipeline.PipelineBuildService +import com.tencent.devops.process.service.trigger.PipelineTriggerEventService import com.tencent.devops.process.utils.PIPELINE_START_TASK_ID import com.tencent.devops.process.utils.PipelineVarUtil -import com.tencent.devops.project.api.service.ServiceAllocIdResource import com.tencent.devops.repository.api.ServiceRepositoryResource -import com.tencent.devops.repository.utils.RepositoryUtils import org.slf4j.LoggerFactory import org.springframework.context.ApplicationContext import org.springframework.context.ApplicationContextAware @@ -98,6 +78,7 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { pipelinebuildWebhookService = applicationContext.getBean(PipelineBuildWebhookService::class.java) pipelineBuildCommitService = applicationContext.getBean(PipelineBuildCommitService::class.java) webhookBuildParameterService = applicationContext.getBean(WebhookBuildParameterService::class.java) + pipelineTriggerEventService = applicationContext.getBean(PipelineTriggerEventService::class.java) } companion object { @@ -113,165 +94,48 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { lateinit var pipelinebuildWebhookService: PipelineBuildWebhookService // 给AOP调用 lateinit var pipelineBuildCommitService: PipelineBuildCommitService lateinit var webhookBuildParameterService: WebhookBuildParameterService + lateinit var pipelineTriggerEventService: PipelineTriggerEventService private val logger = LoggerFactory.getLogger(PipelineBuildWebhookService::class.java) } - fun externalCodeSvnBuild(e: String): Boolean { - logger.info("Trigger code svn build - $e") - - val event = try { - objectMapper.readValue(e, SvnCommitEvent::class.java) - } catch (e: Exception) { - logger.warn("Fail to parse the svn web hook commit event", e) - return false - } - - val svnWebHookMatcher = scmWebhookMatcherBuilder.createSvnWebHookMatcher(event) - - return startProcessByWebhook(CodeSVNWebHookTriggerElement.classType, svnWebHookMatcher) - } - - fun externalCodeGitBuild(codeRepositoryType: String, event: String?, body: String): Boolean { - logger.info("Trigger code git build($body|$event)") - - val gitEvent = try { - if (event == "Review Hook") { - objectMapper.readValue(body) - } else { - objectMapper.readValue(body) - } - } catch (e: Exception) { - logger.warn("Fail to parse the git web hook commit event", e) - return false - } - - val gitWebHookMatcher = scmWebhookMatcherBuilder.createGitWebHookMatcher(gitEvent) - if (!gitWebHookMatcher.preMatch().isMatch) { - return true - } - - return startProcessByWebhook(codeRepositoryType, gitWebHookMatcher) - } - - fun externalGitlabBuild(e: String): Boolean { - logger.info("Trigger gitlab build($e)") - - val event = try { - objectMapper.readValue(e, GitEvent::class.java) - } catch (e: Exception) { - logger.warn("Fail to parse the gitlab web hook commit event", e) - return false - } - - val gitlabWebHookMatcher = scmWebhookMatcherBuilder.createGitlabWebHookMatcher(event) - - return startProcessByWebhook(CodeGitlabWebHookTriggerElement.classType, gitlabWebHookMatcher) - } - - fun externalCodeGithubBuild(eventType: String, guid: String, signature: String, body: String): Boolean { - logger.info("Trigger code github build (event=$eventType, guid=$guid, signature=$signature, body=$body)") - - val event: GithubEvent = when (eventType) { - GithubPushEvent.classType -> objectMapper.readValue(body) - GithubCreateEvent.classType -> objectMapper.readValue(body) - GithubPullRequestEvent.classType -> objectMapper.readValue(body) - GithubCheckRunEvent.classType -> objectMapper.readValue(body) - else -> { - logger.info("Github event($eventType) is ignored") - return true - } - } - val githubWebHookMatcher = scmWebhookMatcherBuilder.createGithubWebHookMatcher(event) - if (!githubWebHookMatcher.preMatch().isMatch) { - return true - } - if (event is GithubCheckRunEvent) { - if (event.action != "rerequested") { - logger.info("Unsupported check run action:${event.action}") - return true - } - if (event.checkRun.externalId == null) { - logger.info("github check run externalId is empty") - return true - } - val buildInfo = event.checkRun.externalId!!.split("_") - if (buildInfo.size < 4) { - logger.info("the buildInfo of github check run is error") - return true - } - client.get(ServiceBuildResource::class).retry( - userId = buildInfo[0], - projectId = buildInfo[1], - pipelineId = buildInfo[2], - buildId = buildInfo[3], - channelCode = ChannelCode.BS - ) - return true - } - return startProcessByWebhook(CodeGithubWebHookTriggerElement.classType, githubWebHookMatcher) - } - - fun externalP4Build(body: String): Boolean { - logger.info("Trigger p4 build($body)") - - val event = try { - objectMapper.readValue(body, P4Event::class.java) - } catch (e: Exception) { - logger.warn("Fail to parse the p4 web hook event", e) - return false - } - - val p4WebHookMatcher = scmWebhookMatcherBuilder.createP4WebHookMatcher(event) - - return startProcessByWebhook(CodeP4WebHookTriggerElement.classType, p4WebHookMatcher) - } - - private fun startProcessByWebhook(codeRepositoryType: String, matcher: ScmWebhookMatcher): Boolean { - val watcher = Watcher("${matcher.getRepoName()}|${matcher.getRevision()}|webhook trigger") - PipelineWebhookBuildLogContext.addRepoInfo(repoName = matcher.getRepoName(), commitId = matcher.getRevision()) + fun dispatchPipelineSubscribers( + matcher: ScmWebhookMatcher, + webhookEvent: PipelineWebhookEvent, + subscribers: List + ): Boolean { try { - watcher.start("getWebhookPipelines") - logger.info("startProcessByWebhook|repo(${matcher.getRepoName()})|type($codeRepositoryType)") - val pipelines = pipelineWebhookService.getWebhookPipelines( - name = matcher.getRepoName(), - type = codeRepositoryType - ) + logger.info("dispatch pipeline webhook subscriber|repo(${matcher.getRepoName()})") - if (pipelines.isEmpty()) { + if (subscribers.isEmpty()) { gitWebhookUnlockDispatcher.dispatchUnlockHookLockEvent(matcher) return false } - watcher.start("webhookTriggerPipelineBuild") EventCacheUtil.initEventCache() - pipelines.forEach outside@{ pipeline -> - val projectId = pipeline.first - val pipelineId = pipeline.second + subscribers.forEach outside@{ subscriber -> + val projectId = subscriber.projectId + val pipelineId = subscriber.pipelineId try { logger.info("pipelineId is $pipelineId") - val model = pipelineRepositoryService.getModel(projectId, pipelineId) ?: run { - logger.info("$pipelineId|pipeline does not exists, ignore") - return@outside - } - - /** - * 验证流水线参数构建启动参数 - */ - val triggerContainer = model.stages[0].containers[0] as TriggerContainer - val canWebhookStartup = canWebhookStartup(triggerContainer, codeRepositoryType) + val builder = PipelineTriggerEventBuilder() + .webhookEvent(webhookEvent) + .projectId(projectId) + .pipelineId(pipelineId) - if (!canWebhookStartup) { - logger.info("$pipelineId|can not start by $codeRepositoryType, ignore") - return@outside - } - - if (pipelinebuildWebhookService.webhookTriggerPipelineBuild( - projectId = projectId, - pipelineId = pipelineId, - codeRepositoryType = codeRepositoryType, - matcher = matcher + webhookTriggerPipelineBuild( + projectId = projectId, + pipelineId = pipelineId, + matcher = matcher, + builder = builder + ) + if (!builder.getEventSource().isNullOrBlank()) { + webhookEvent.eventSource = builder.getEventSource() + webhookEvent.projectId = projectId + pipelineTriggerEventService.saveEvent( + webhookEvent = webhookEvent, + triggerEvent = builder.build() ) - ) return@outside + } } catch (e: Throwable) { logger.warn("[$pipelineId]|webhookTriggerPipelineBuild fail: $e", e) } @@ -292,65 +156,14 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { ) } EventCacheUtil.remove() - logger.info("$watcher") - } - } - - private fun canWebhookStartup( - triggerContainer: TriggerContainer, - codeRepositoryType: String - ): Boolean { - var canWebhookStartup = false - run lit@{ - triggerContainer.elements.forEach { - when (codeRepositoryType) { - CodeSVNWebHookTriggerElement.classType -> { - if ((it is CodeSVNWebHookTriggerElement && it.isElementEnable())) { - canWebhookStartup = true - return@lit - } - } - CodeGitWebHookTriggerElement.classType -> { - if ((it is CodeGitWebHookTriggerElement && it.isElementEnable())) { - canWebhookStartup = true - return@lit - } - } - CodeGithubWebHookTriggerElement.classType -> { - if ((it is CodeGithubWebHookTriggerElement && it.isElementEnable())) { - canWebhookStartup = true - return@lit - } - } - CodeGitlabWebHookTriggerElement.classType -> { - if ((it is CodeGitlabWebHookTriggerElement && it.isElementEnable())) { - canWebhookStartup = true - return@lit - } - } - CodeTGitWebHookTriggerElement.classType -> { - if ((it is CodeTGitWebHookTriggerElement && it.isElementEnable())) { - canWebhookStartup = true - return@lit - } - } - CodeP4WebHookTriggerElement.classType -> { - if (it is CodeP4WebHookTriggerElement && it.isElementEnable()) { - canWebhookStartup = true - return@lit - } - } - } - } } - return canWebhookStartup } open fun webhookTriggerPipelineBuild( projectId: String, pipelineId: String, - codeRepositoryType: String, - matcher: ScmWebhookMatcher + matcher: ScmWebhookMatcher, + builder: PipelineTriggerEventBuilder ): Boolean { val pipelineInfo = pipelineRepositoryService.getPipelineInfo(projectId, pipelineId) ?: return false @@ -386,24 +199,11 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { logger.info("$pipelineId|${element.name}|Get the code trigger pipeline") // #2958 如果仓库找不到,会抛出404异常,就不会继续往下遍历 val repo = try { - if (element is CodeGitGenericWebHookTriggerElement && - element.data.input.repositoryType == RepositoryTypeNew.URL - ) { - RepositoryUtils.buildRepository( - projectId = pipelineInfo.projectId, - userName = pipelineInfo.lastModifyUser, - scmType = ScmType.valueOf(element.data.input.scmType), - repositoryUrl = repositoryConfig.repositoryName!!, - credentialId = element.data.input.credentialId - ) - } else { - client.get(ServiceRepositoryResource::class) - .get( - projectId, - repositoryConfig.getURLEncodeRepositoryId(), - repositoryConfig.repositoryType - ).data - } + client.get(ServiceRepositoryResource::class).get( + projectId, + repositoryConfig.getURLEncodeRepositoryId(), + repositoryConfig.repositoryType + ).data } catch (e: Exception) { null } @@ -436,16 +236,6 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { ) val buildId = client.getGateway(ServiceScmWebhookResource::class).webhookCommit(projectId, webhookCommit).data - PipelineWebhookBuildLogContext.addLogBuildInfo( - projectId = projectId, - pipelineId = pipelineId, - taskId = element.id!!, - taskName = element.name, - success = true, - triggerResult = buildId, - id = client.get(ServiceAllocIdResource::class) - .generateSegmentId("PIPELINE_WEBHOOK_BUILD_LOG_DETAIL").data - ) logger.info("$pipelineId|$buildId|webhook trigger|(${element.name}|repo(${matcher.getRepoName()})") if (!buildId.isNullOrEmpty()) { pipelineBuildCommitService.create( @@ -455,6 +245,9 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { matcher = matcher, repo = repo ) + builder.buildId(buildId) + .eventSource(eventSource = repo.repoHashId!!) + .reason(PipelineTriggerReason.TRIGGER_SUCCESS.name) } } catch (ignore: Exception) { logger.warn("$pipelineId|webhook trigger|(${element.name})|repo(${matcher.getRepoName()})", ignore) @@ -464,8 +257,17 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { logger.info( "$pipelineId|webhook trigger match unsuccess|(${element.name})|repo(${matcher.getRepoName()})" ) + if (!matchResult.reason.isNullOrBlank()) { + builder.eventSource(eventSource = repo.repoHashId!!) + .reasonDetail("${element.name}-${matchResult.reason}") + } } } + + // 历史原因,webhook表没有记录eventType,所以查找出来的订阅者可能因为事件类型不匹配,事件不需要记录 + if (!builder.getEventSource().isNullOrBlank()) { + builder.reason(PipelineTriggerReason.TRIGGER_NOT_MATCH.name) + } return false } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebHookTriggerElementBizPlugin.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebHookTriggerElementBizPlugin.kt index fba577862ff..ad004afc0cf 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebHookTriggerElementBizPlugin.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebHookTriggerElementBizPlugin.kt @@ -34,7 +34,6 @@ import com.tencent.devops.common.pipeline.container.Container import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitGenericWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGithubWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitlabWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeP4WebHookTriggerElement @@ -73,16 +72,6 @@ abstract class WebHookTriggerElementBizPlugin constru override fun check(element: T, appearedCnt: Int) = Unit } -@ElementBiz -class CodeGitWebHookTriggerElementBizPlugin constructor( - pipelineWebhookService: PipelineWebhookService -) : WebHookTriggerElementBizPlugin(pipelineWebhookService) { - - override fun elementClass(): Class { - return CodeGitWebHookTriggerElement::class.java - } -} - @ElementBiz class CodeGithubWebHookTriggerElementBizPlugin constructor( pipelineWebhookService: PipelineWebhookService diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt new file mode 100644 index 00000000000..de7680d8bd8 --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt @@ -0,0 +1,162 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.webhook.atom + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.kotlin.readValue +import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.webhook.atom.IWebhookAtomTask +import com.tencent.devops.common.webhook.pojo.ReplayWebhookRequest +import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.code.git.GitEvent +import com.tencent.devops.common.webhook.pojo.code.git.GitReviewEvent +import com.tencent.devops.process.engine.service.PipelineWebhookService +import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder +import com.tencent.devops.process.pojo.webhook.PipelineWebhookEvent +import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber +import com.tencent.devops.process.service.trigger.PipelineTriggerEventService +import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.stereotype.Service +import java.time.LocalDateTime + +@Service +class CodeGitWebhookTriggerTaskAtom @Autowired constructor( + private val objectMapper: ObjectMapper, + private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder, + private val pipelineWebhookService: PipelineWebhookService, + private val pipelineBuildWebhookService: PipelineBuildWebhookService, + private val pipelineTriggerEventService: PipelineTriggerEventService, + private val webhookTriggerTaskAtomService: WebhookTriggerTaskAtomService +) : IWebhookAtomTask { + + companion object { + private val logger = LoggerFactory.getLogger(CodeGitWebhookTriggerTaskAtom::class.java) + } + + override fun request(request: WebhookRequest) { + val eventType = request.headers?.get("X-Event") + val body = request.body + logger.info("Trigger code git build($body|$eventType)") + val event = getEvent(request = request) ?: return + val matcher = scmWebhookMatcherBuilder.createGitWebHookMatcher(event) + if (!matcher.preMatch().isMatch) { + return + } + + val eventTime = LocalDateTime.now() + val requestId = webhookTriggerTaskAtomService.saveRepoWebhookRequest( + matcher = matcher, + request = request, + eventTime = eventTime, + scmType = getScmType() + ) + val webhookEvent = PipelineWebhookEvent( + taskAtom = request.taskAtom, + requestId = requestId, + eventId = pipelineTriggerEventService.getWebhookEventId(), + triggerType = getScmType().name, + eventType = matcher.getEventType().name, + triggerUser = matcher.getUsername(), + eventMessage = matcher.getMessage() ?: "", + eventDesc = matcher.getEventDesc(), + eventTime = eventTime + ) + val subscribers = pipelineWebhookService.getWebhookPipelines( + name = matcher.getRepoName(), + repositoryType = getScmType().name + ) + pipelineBuildWebhookService.dispatchPipelineSubscribers( + matcher = matcher, + webhookEvent = webhookEvent, + subscribers = subscribers + ) + } + + override fun replay(request: ReplayWebhookRequest) { + val repoWebhookRequest = + webhookTriggerTaskAtomService.getRepoWebhookRequest(requestId = request.requestId) ?: return + val event = getEvent( + request = WebhookRequest( + taskAtom = request.taskAtom, + headers = repoWebhookRequest.requestHeader, + body = repoWebhookRequest.requestBody + ) + ) ?: return + val matcher = scmWebhookMatcherBuilder.createGitWebHookMatcher(event) + val eventTime = LocalDateTime.now() + val webhookEvent = PipelineWebhookEvent( + taskAtom = request.taskAtom, + requestId = request.requestId, + eventId = pipelineTriggerEventService.getWebhookEventId(), + triggerType = getScmType().name, + eventType = matcher.getEventType().name, + triggerUser = matcher.getUsername(), + eventMessage = matcher.getMessage() ?: "", + eventDesc = matcher.getEventDesc(), + eventTime = eventTime + ) + val subscribers = request.pipelineId?.let { + listOf( + PipelineWebhookSubscriber( + projectId = request.projectId, + pipelineId = request.pipelineId!! + ) + ) + } ?: run { + pipelineWebhookService.getWebhookPipelines( + name = matcher.getRepoName(), + repositoryType = getScmType().name + ) + } + pipelineBuildWebhookService.dispatchPipelineSubscribers( + matcher = matcher, + webhookEvent = webhookEvent, + subscribers = subscribers + ) + } + + private fun getEvent(request: WebhookRequest): GitEvent? { + val eventType = request.headers?.get("X-Event") + val body = request.body + return try { + if (eventType == "Review Hook") { + objectMapper.readValue(body) + } else { + objectMapper.readValue(body) + } + } catch (e: Exception) { + logger.warn("Fail to parse the git web hook commit event", e) + return null + } + } + + fun getScmType() = ScmType.CODE_GIT +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGithubWebHookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGithubWebHookTriggerTaskAtom.kt new file mode 100644 index 00000000000..55060244d0b --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGithubWebHookTriggerTaskAtom.kt @@ -0,0 +1,194 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.webhook.atom + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.kotlin.readValue +import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.client.Client +import com.tencent.devops.common.pipeline.enums.ChannelCode +import com.tencent.devops.common.webhook.atom.IWebhookAtomTask +import com.tencent.devops.common.webhook.pojo.ReplayWebhookRequest +import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.code.github.GithubCheckRunEvent +import com.tencent.devops.common.webhook.pojo.code.github.GithubCreateEvent +import com.tencent.devops.common.webhook.pojo.code.github.GithubEvent +import com.tencent.devops.common.webhook.pojo.code.github.GithubPullRequestEvent +import com.tencent.devops.common.webhook.pojo.code.github.GithubPushEvent +import com.tencent.devops.process.api.service.ServiceBuildResource +import com.tencent.devops.process.engine.service.PipelineWebhookService +import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder +import com.tencent.devops.process.pojo.trigger.PipelineTriggerType +import com.tencent.devops.process.pojo.webhook.PipelineWebhookEvent +import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber +import com.tencent.devops.process.service.trigger.PipelineTriggerEventService +import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service +import java.time.LocalDateTime + +@Service +class CodeGithubWebHookTriggerTaskAtom( + private val objectMapper: ObjectMapper, + private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder, + private val pipelineWebhookService: PipelineWebhookService, + private val pipelineBuildWebhookService: PipelineBuildWebhookService, + private val pipelineTriggerEventService: PipelineTriggerEventService, + private val webhookTriggerTaskAtomService: WebhookTriggerTaskAtomService, + private val client: Client +) : IWebhookAtomTask { + + companion object { + private val logger = LoggerFactory.getLogger(CodeGithubWebHookTriggerTaskAtom::class.java) + } + + override fun request(request: WebhookRequest) { + val event = getEvent(request) ?: return + val matcher = scmWebhookMatcherBuilder.createGithubWebHookMatcher(event) + if (!matcher.preMatch().isMatch) { + return + } + if (event is GithubCheckRunEvent) { + retry(event) + return + } + val eventTime = LocalDateTime.now() + val requestId = webhookTriggerTaskAtomService.saveRepoWebhookRequest( + matcher = matcher, + request = request, + eventTime = eventTime, + scmType = ScmType.GITHUB + ) + val webhookEvent = PipelineWebhookEvent( + taskAtom = request.taskAtom, + requestId = requestId, + eventId = pipelineTriggerEventService.getWebhookEventId(), + triggerType = PipelineTriggerType.GITHUB.name, + eventType = matcher.getEventType().name, + triggerUser = matcher.getUsername(), + eventMessage = matcher.getMessage() ?: "", + eventDesc = matcher.getEventDesc(), + eventTime = eventTime + ) + val subscribers = pipelineWebhookService.getWebhookPipelines( + name = matcher.getRepoName(), + repositoryType = ScmType.CODE_GIT.name + ) + pipelineBuildWebhookService.dispatchPipelineSubscribers( + matcher = matcher, + webhookEvent = webhookEvent, + subscribers = subscribers + ) + } + + override fun replay(request: ReplayWebhookRequest) { + val webhookRequest = + webhookTriggerTaskAtomService.getRepoWebhookRequest(requestId = request.requestId) ?: return + val event = getEvent( + request = WebhookRequest( + taskAtom = request.taskAtom, + headers = webhookRequest.requestHeader, + body = webhookRequest.requestBody + ) + ) ?: return + val matcher = scmWebhookMatcherBuilder.createGithubWebHookMatcher(event) + val eventTime = LocalDateTime.now() + val webhookEvent = PipelineWebhookEvent( + taskAtom = request.taskAtom, + requestId = request.requestId, + eventId = pipelineTriggerEventService.getWebhookEventId(), + triggerType = PipelineTriggerType.GITHUB.name, + eventType = matcher.getEventType().name, + triggerUser = matcher.getUsername(), + eventMessage = matcher.getMessage() ?: "", + eventDesc = matcher.getEventDesc(), + eventTime = eventTime + ) + val subscribers = request.pipelineId?.let { + listOf( + PipelineWebhookSubscriber( + projectId = request.projectId, + pipelineId = request.pipelineId!! + ) + ) + } ?: run { + pipelineWebhookService.getWebhookPipelines( + name = matcher.getRepoName(), + repositoryType = ScmType.GITHUB.name + ) + } + pipelineBuildWebhookService.dispatchPipelineSubscribers( + matcher = matcher, + webhookEvent = webhookEvent, + subscribers = subscribers + ) + } + + private fun retry(event: GithubCheckRunEvent) { + if (event.action != "rerequested") { + logger.info("Unsupported check run action:${event.action}") + return + } + if (event.checkRun.externalId == null) { + logger.info("github check run externalId is empty") + return + } + val buildInfo = event.checkRun.externalId!!.split("_") + if (buildInfo.size < 4) { + logger.info("the buildInfo of github check run is error") + return + } + client.get(ServiceBuildResource::class).retry( + userId = buildInfo[0], + projectId = buildInfo[1], + pipelineId = buildInfo[2], + buildId = buildInfo[3], + channelCode = ChannelCode.BS + ) + } + + private fun getEvent(request: WebhookRequest): GithubEvent? { + val eventType = request.headers?.get("X-GitHub-Event") + val guid = request.headers?.get("X-Github-Delivery") + val signature = request.headers?.get("X-Hub-Signature") + val body = request.body + logger.info("Trigger code github build (event=$eventType, guid=$guid, signature=$signature, body=$body)") + + return when (eventType) { + GithubPushEvent.classType -> objectMapper.readValue(body) + GithubCreateEvent.classType -> objectMapper.readValue(body) + GithubPullRequestEvent.classType -> objectMapper.readValue(body) + GithubCheckRunEvent.classType -> objectMapper.readValue(body) + else -> { + logger.info("Github event($eventType) is ignored") + return null + } + } + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitlabWebHookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitlabWebHookTriggerTaskAtom.kt new file mode 100644 index 00000000000..ec8609c50f0 --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitlabWebHookTriggerTaskAtom.kt @@ -0,0 +1,150 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.webhook.atom + +import com.fasterxml.jackson.databind.ObjectMapper +import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.webhook.atom.IWebhookAtomTask +import com.tencent.devops.common.webhook.pojo.ReplayWebhookRequest +import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.code.git.GitEvent +import com.tencent.devops.process.engine.service.PipelineWebhookService +import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder +import com.tencent.devops.process.pojo.trigger.PipelineTriggerType +import com.tencent.devops.process.pojo.webhook.PipelineWebhookEvent +import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber +import com.tencent.devops.process.service.trigger.PipelineTriggerEventService +import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.stereotype.Service +import java.time.LocalDateTime + +@Service +class CodeGitlabWebHookTriggerTaskAtom @Autowired constructor( + private val objectMapper: ObjectMapper, + private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder, + private val pipelineWebhookService: PipelineWebhookService, + private val pipelineBuildWebhookService: PipelineBuildWebhookService, + private val pipelineTriggerEventService: PipelineTriggerEventService, + private val webhookTriggerTaskAtomService: WebhookTriggerTaskAtomService +) : IWebhookAtomTask { + + companion object { + private val logger = LoggerFactory.getLogger(CodeGitlabWebHookTriggerTaskAtom::class.java) + } + + override fun request(request: WebhookRequest) { + logger.info("Trigger gitlab build(${request.body})") + + val event = getEvent(request = request) ?: return + + val matcher = scmWebhookMatcherBuilder.createGitlabWebHookMatcher(event) + + val eventTime = LocalDateTime.now() + val requestId = webhookTriggerTaskAtomService.saveRepoWebhookRequest( + matcher = matcher, + request = request, + eventTime = eventTime, + scmType = ScmType.CODE_GITLAB + ) + val webhookEvent = PipelineWebhookEvent( + taskAtom = request.taskAtom, + requestId = requestId, + eventId = pipelineTriggerEventService.getWebhookEventId(), + triggerType = PipelineTriggerType.CODE_GITLAB.name, + eventType = matcher.getEventType().name, + triggerUser = matcher.getUsername(), + eventMessage = matcher.getMessage() ?: "", + eventDesc = matcher.getEventDesc(), + eventTime = eventTime + ) + val subscribers = pipelineWebhookService.getWebhookPipelines( + name = matcher.getRepoName(), + repositoryType = ScmType.CODE_GITLAB.name + ) + pipelineBuildWebhookService.dispatchPipelineSubscribers( + matcher = matcher, + webhookEvent = webhookEvent, + subscribers = subscribers + ) + } + + override fun replay(request: ReplayWebhookRequest) { + val repoWebhookRequest = + webhookTriggerTaskAtomService.getRepoWebhookRequest(requestId = request.requestId) ?: return + val event = getEvent( + request = WebhookRequest( + taskAtom = request.taskAtom, + headers = repoWebhookRequest.requestHeader, + body = repoWebhookRequest.requestBody + ) + ) ?: return + val matcher = scmWebhookMatcherBuilder.createGitWebHookMatcher(event) + val eventTime = LocalDateTime.now() + val webhookEvent = PipelineWebhookEvent( + taskAtom = request.taskAtom, + requestId = request.requestId, + eventId = pipelineTriggerEventService.getWebhookEventId(), + triggerType = PipelineTriggerType.CODE_GIT.name, + eventType = matcher.getEventType().name, + triggerUser = matcher.getUsername(), + eventMessage = matcher.getMessage() ?: "", + eventDesc = matcher.getEventDesc(), + eventTime = eventTime + ) + val subscribers = request.pipelineId?.let { + listOf( + PipelineWebhookSubscriber( + projectId = request.projectId, + pipelineId = request.pipelineId!! + ) + ) + } ?: run { + pipelineWebhookService.getWebhookPipelines( + name = matcher.getRepoName(), + repositoryType = ScmType.CODE_GITLAB.name + ) + } + pipelineBuildWebhookService.dispatchPipelineSubscribers( + matcher = matcher, + webhookEvent = webhookEvent, + subscribers = subscribers + ) + } + + private fun getEvent(request: WebhookRequest): GitEvent? { + return try { + objectMapper.readValue(request.body, GitEvent::class.java) + } catch (e: Exception) { + logger.warn("Fail to parse the gitlab web hook commit event", e) + return null + } + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeP4WebHookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeP4WebHookTriggerTaskAtom.kt new file mode 100644 index 00000000000..2874d97d402 --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeP4WebHookTriggerTaskAtom.kt @@ -0,0 +1,148 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.webhook.atom + +import com.fasterxml.jackson.databind.ObjectMapper +import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.webhook.atom.IWebhookAtomTask +import com.tencent.devops.common.webhook.pojo.ReplayWebhookRequest +import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.code.p4.P4Event +import com.tencent.devops.process.engine.service.PipelineWebhookService +import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder +import com.tencent.devops.process.pojo.trigger.PipelineTriggerType +import com.tencent.devops.process.pojo.webhook.PipelineWebhookEvent +import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber +import com.tencent.devops.process.service.trigger.PipelineTriggerEventService +import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service +import java.time.LocalDateTime + +@Service +class CodeP4WebHookTriggerTaskAtom( + private val objectMapper: ObjectMapper, + private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder, + private val pipelineWebhookService: PipelineWebhookService, + private val pipelineBuildWebhookService: PipelineBuildWebhookService, + private val pipelineTriggerEventService: PipelineTriggerEventService, + private val webhookTriggerTaskAtomService: WebhookTriggerTaskAtomService +) : IWebhookAtomTask { + + companion object { + private val logger = LoggerFactory.getLogger(CodeP4WebHookTriggerTaskAtom::class.java) + } + + override fun request(request: WebhookRequest) { + logger.info("Trigger p4 build(${request.body})") + + val event = getEvent(request = request) ?: return + + val matcher = scmWebhookMatcherBuilder.createP4WebHookMatcher(event) + val eventTime = LocalDateTime.now() + val requestId = webhookTriggerTaskAtomService.saveRepoWebhookRequest( + matcher = matcher, + request = request, + eventTime = eventTime, + scmType = ScmType.CODE_P4 + ) + val webhookEvent = PipelineWebhookEvent( + taskAtom = request.taskAtom, + requestId = requestId, + eventId = pipelineTriggerEventService.getWebhookEventId(), + triggerType = PipelineTriggerType.CODE_P4.name, + eventType = matcher.getEventType().name, + triggerUser = matcher.getUsername(), + eventMessage = matcher.getMessage() ?: "", + eventDesc = matcher.getEventDesc(), + eventTime = eventTime + ) + val subscribers = pipelineWebhookService.getWebhookPipelines( + name = matcher.getRepoName(), + repositoryType = ScmType.CODE_P4.name + ) + pipelineBuildWebhookService.dispatchPipelineSubscribers( + matcher = matcher, + webhookEvent = webhookEvent, + subscribers = subscribers + ) + } + + override fun replay(request: ReplayWebhookRequest) { + val repoWebhookRequest = + webhookTriggerTaskAtomService.getRepoWebhookRequest(requestId = request.requestId) ?: return + val event = getEvent( + request = WebhookRequest( + taskAtom = request.taskAtom, + headers = repoWebhookRequest.requestHeader, + body = repoWebhookRequest.requestBody + ) + ) ?: return + val matcher = scmWebhookMatcherBuilder.createP4WebHookMatcher(event) + val eventTime = LocalDateTime.now() + val webhookEvent = PipelineWebhookEvent( + taskAtom = request.taskAtom, + requestId = request.requestId, + eventId = pipelineTriggerEventService.getWebhookEventId(), + triggerType = PipelineTriggerType.CODE_P4.name, + eventType = matcher.getEventType().name, + triggerUser = matcher.getUsername(), + eventMessage = matcher.getMessage() ?: "", + eventDesc = matcher.getEventDesc(), + eventTime = eventTime + ) + val subscribers = request.pipelineId?.let { + listOf( + PipelineWebhookSubscriber( + projectId = request.projectId, + pipelineId = request.pipelineId!! + ) + ) + } ?: run { + pipelineWebhookService.getWebhookPipelines( + name = matcher.getRepoName(), + repositoryType = ScmType.CODE_P4.name + ) + } + pipelineBuildWebhookService.dispatchPipelineSubscribers( + matcher = matcher, + webhookEvent = webhookEvent, + subscribers = subscribers + ) + } + + private fun getEvent(request: WebhookRequest): P4Event? { + return try { + objectMapper.readValue(request.body, P4Event::class.java) + } catch (e: Exception) { + logger.warn("Fail to parse the p4 web hook event", e) + return null + } + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeSvnWebHookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeSvnWebHookTriggerTaskAtom.kt new file mode 100644 index 00000000000..6dcfd3c369f --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeSvnWebHookTriggerTaskAtom.kt @@ -0,0 +1,149 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.webhook.atom + +import com.fasterxml.jackson.databind.ObjectMapper +import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.webhook.atom.IWebhookAtomTask +import com.tencent.devops.common.webhook.pojo.ReplayWebhookRequest +import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.code.svn.SvnCommitEvent +import com.tencent.devops.process.engine.service.PipelineWebhookService +import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder +import com.tencent.devops.process.pojo.trigger.PipelineTriggerType +import com.tencent.devops.process.pojo.webhook.PipelineWebhookEvent +import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber +import com.tencent.devops.process.service.trigger.PipelineTriggerEventService +import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service +import java.time.LocalDateTime + +@Service +class CodeSvnWebHookTriggerTaskAtom ( + private val objectMapper: ObjectMapper, + private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder, + private val pipelineWebhookService: PipelineWebhookService, + private val pipelineBuildWebhookService: PipelineBuildWebhookService, + private val pipelineTriggerEventService: PipelineTriggerEventService, + private val webhookTriggerTaskAtomService: WebhookTriggerTaskAtomService +) : IWebhookAtomTask { + + companion object { + private val logger = LoggerFactory.getLogger(CodeSvnWebHookTriggerTaskAtom::class.java) + } + + override fun request(request: WebhookRequest) { + logger.info("Trigger code svn build - ${request.body}") + + val event = getEvent(request = request) ?: return + + val matcher = scmWebhookMatcherBuilder.createSvnWebHookMatcher(event) + + val eventTime = LocalDateTime.now() + val requestId = webhookTriggerTaskAtomService.saveRepoWebhookRequest( + matcher = matcher, + request = request, + eventTime = eventTime, + scmType = ScmType.CODE_SVN + ) + val webhookEvent = PipelineWebhookEvent( + taskAtom = request.taskAtom, + requestId = requestId, + eventId = pipelineTriggerEventService.getWebhookEventId(), + triggerType = PipelineTriggerType.CODE_SVN.name, + eventType = matcher.getEventType().name, + triggerUser = matcher.getUsername(), + eventMessage = matcher.getMessage() ?: "", + eventDesc = matcher.getEventDesc(), + eventTime = eventTime + ) + + val subscribers = pipelineWebhookService.getWebhookPipelines( + name = matcher.getRepoName(), + repositoryType = ScmType.CODE_SVN.name + ) + pipelineBuildWebhookService.dispatchPipelineSubscribers( + matcher = matcher, + webhookEvent = webhookEvent, + subscribers = subscribers + ) + } + + override fun replay(request: ReplayWebhookRequest) { + val repoWebhookRequest = + webhookTriggerTaskAtomService.getRepoWebhookRequest(requestId = request.requestId) ?: return + val event = getEvent( + request = WebhookRequest( + taskAtom = request.taskAtom, + body = repoWebhookRequest.requestBody + ) + ) ?: return + val matcher = scmWebhookMatcherBuilder.createSvnWebHookMatcher(event) + val eventTime = LocalDateTime.now() + val webhookEvent = PipelineWebhookEvent( + taskAtom = request.taskAtom, + requestId = request.requestId, + eventId = pipelineTriggerEventService.getWebhookEventId(), + triggerType = PipelineTriggerType.CODE_SVN.name, + eventType = matcher.getEventType().name, + triggerUser = matcher.getUsername(), + eventMessage = matcher.getMessage() ?: "", + eventDesc = matcher.getEventDesc(), + eventTime = eventTime + ) + val subscribers = request.pipelineId?.let { + listOf( + PipelineWebhookSubscriber( + projectId = request.projectId, + pipelineId = request.pipelineId!! + ) + ) + } ?: run { + pipelineWebhookService.getWebhookPipelines( + name = matcher.getRepoName(), + repositoryType = ScmType.CODE_SVN.name + ) + } + pipelineBuildWebhookService.dispatchPipelineSubscribers( + matcher = matcher, + webhookEvent = webhookEvent, + subscribers = subscribers + ) + } + + private fun getEvent(request: WebhookRequest): SvnCommitEvent? { + return try { + objectMapper.readValue(request.body, SvnCommitEvent::class.java) + } catch (e: Exception) { + logger.warn("Fail to parse the svn web hook commit event", e) + return null + } + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeTGitWebhookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeTGitWebhookTriggerTaskAtom.kt new file mode 100644 index 00000000000..029dca03346 --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeTGitWebhookTriggerTaskAtom.kt @@ -0,0 +1,58 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.webhook.atom + +import com.fasterxml.jackson.databind.ObjectMapper +import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.process.engine.service.PipelineWebhookService +import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder +import com.tencent.devops.process.service.trigger.PipelineTriggerEventService +import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.stereotype.Service + +@Service +class CodeTGitWebhookTriggerTaskAtom @Autowired constructor( + private val objectMapper: ObjectMapper, + private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder, + private val pipelineWebhookService: PipelineWebhookService, + private val pipelineBuildWebhookService: PipelineBuildWebhookService, + private val pipelineTriggerEventService: PipelineTriggerEventService, + private val webhookTriggerTaskAtomService: WebhookTriggerTaskAtomService +) : CodeGitWebhookTriggerTaskAtom( + objectMapper = objectMapper, + scmWebhookMatcherBuilder = scmWebhookMatcherBuilder, + pipelineWebhookService = pipelineWebhookService, + pipelineBuildWebhookService = pipelineBuildWebhookService, + pipelineTriggerEventService = pipelineTriggerEventService, + webhookTriggerTaskAtomService = webhookTriggerTaskAtomService +) { + + override fun getScmType() = ScmType.CODE_TGIT +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/WebhookTriggerTaskAtomService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/WebhookTriggerTaskAtomService.kt new file mode 100644 index 00000000000..4fad4726ddc --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/WebhookTriggerTaskAtomService.kt @@ -0,0 +1,73 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.webhook.atom + +import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.client.Client +import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher +import com.tencent.devops.repository.api.ServiceRepositoryWebhookResource +import com.tencent.devops.repository.pojo.RepositoryWebhookRequest +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.stereotype.Service +import java.time.LocalDateTime + +@Service +class WebhookTriggerTaskAtomService @Autowired constructor( + private val client: Client +) { + + fun saveRepoWebhookRequest( + matcher: ScmWebhookMatcher, + request: WebhookRequest, + eventTime: LocalDateTime, + scmType: ScmType + ): Long { + val repositoryWebhookRequest = RepositoryWebhookRequest( + externalId = matcher.getExternalId(), + eventType = matcher.getEventType().name, + triggerUser = matcher.getUsername(), + eventMessage = matcher.getMessage() ?: "", + repositoryType = scmType.name, + requestHeader = request.headers, + requestParam = request.queryParams, + requestBody = request.body, + createTime = eventTime + ) + return client.get(ServiceRepositoryWebhookResource::class).saveWebhookRequest( + repositoryWebhookRequest = repositoryWebhookRequest + ).data!! + } + + fun getRepoWebhookRequest( + requestId: Long + ): RepositoryWebhookRequest? { + return client.get(ServiceRepositoryWebhookResource::class).getWebhookRequest(requestId = requestId).data + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/element/CodeGitWebHookTriggerElementBizPlugin.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/element/CodeGitWebHookTriggerElementBizPlugin.kt new file mode 100644 index 00000000000..eff4b6aa981 --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/element/CodeGitWebHookTriggerElementBizPlugin.kt @@ -0,0 +1,103 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.webhook.element + +import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.pipeline.container.Container +import com.tencent.devops.common.pipeline.container.TriggerContainer +import com.tencent.devops.common.pipeline.enums.ChannelCode +import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam +import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitWebHookTriggerElement +import com.tencent.devops.common.pipeline.utils.RepositoryConfigUtils +import com.tencent.devops.process.engine.service.PipelineWebhookService +import com.tencent.devops.process.plugin.ElementBizPlugin +import com.tencent.devops.process.plugin.annotation.ElementBiz +import com.tencent.devops.process.service.scm.ScmProxyService +import org.springframework.beans.factory.annotation.Autowired + +@ElementBiz +class CodeGitWebHookTriggerElementBizPlugin @Autowired constructor( + private val scmProxyService: ScmProxyService, + private val pipelineWebhookService: PipelineWebhookService +) : ElementBizPlugin { + override fun elementClass(): Class { + return CodeGitWebHookTriggerElement::class.java + } + + override fun check(element: CodeGitWebHookTriggerElement, appearedCnt: Int) = Unit + + override fun beforeDelete(element: CodeGitWebHookTriggerElement, param: BeforeDeleteParam) { + if (param.pipelineId.isNotBlank()) { + pipelineWebhookService.deleteWebhook( + projectId = param.projectId, + pipelineId = param.pipelineId, + taskId = element.id!!, + userId = param.userId + ) + } + } + + override fun afterCreate( + element: CodeGitWebHookTriggerElement, + projectId: String, + pipelineId: String, + pipelineName: String, + userId: String, + channelCode: ChannelCode, + create: Boolean, + container: Container + ) { + val variable = (container as TriggerContainer).params.associate { param -> + param.id to param.defaultValue.toString() + } + val repositoryConfig = RepositoryConfigUtils.getRepositoryConfig( + repoHashId = element.repositoryHashId, + repoName = element.repositoryName, + repoType = element.repositoryType, + variable = variable + ) + val repository = scmProxyService.addGitWebhook( + projectId = projectId, + repositoryConfig = repositoryConfig, + codeEventType = element.eventType + ) + pipelineWebhookService.save( + projectId = projectId, + pipelineId = pipelineId, + repositoryType = ScmType.CODE_GIT.name, + repoType = repositoryConfig.repositoryType.name, + repoHashId = repositoryConfig.repositoryHashId, + repoName = repositoryConfig.repositoryName, + projectName = repository.projectName, + taskId = element.id!!, + eventSource = repository.gitProjectId?.toString() ?: repository.projectName, + eventType = element.eventType!!.name + ) + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt index 3aa9f9e8646..241657de362 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt @@ -28,12 +28,12 @@ package com.tencent.devops.process.webhook.listener import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitWebHookTriggerElement +import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGithubWebHookTriggerElement +import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitlabWebHookTriggerElement +import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeSVNWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeTGitWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeType import com.tencent.devops.common.service.trace.TraceTag -import com.tencent.devops.process.engine.service.PipelineWebhookBuildLogContext -import com.tencent.devops.process.engine.service.PipelineWebhookBuildLogService -import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService +import com.tencent.devops.common.webhook.pojo.WebhookRequest import com.tencent.devops.process.webhook.CodeWebhookEventDispatcher import com.tencent.devops.process.webhook.pojo.event.commit.GitWebhookEvent import com.tencent.devops.process.webhook.pojo.event.commit.GithubWebhookEvent @@ -50,9 +50,8 @@ import org.springframework.stereotype.Component @Component class WebhookEventListener constructor( - private val pipelineBuildService: PipelineBuildWebhookService, private val rabbitTemplate: RabbitTemplate, - private val triggerBuildLogService: PipelineWebhookBuildLogService + private val webhookRequestService: WebhookRequestService ) { fun handleCommitEvent(event: ICodeWebhookEvent) { @@ -67,30 +66,48 @@ class WebhookEventListener constructor( logger.info("Receive WebhookEvent from MQ [${event.commitEventType}|${event.requestContent}]|[${event.event}]") var result = false try { - PipelineWebhookBuildLogContext.initTriggerLog( - codeType = event.commitEventType.name, - requestContent = event.requestContent - ) when (event.commitEventType) { - CommitEventType.SVN -> pipelineBuildService.externalCodeSvnBuild(event.requestContent) + CommitEventType.SVN -> { + val request = WebhookRequest( + taskAtom = CodeSVNWebHookTriggerElement.taskAtom, + body = event.requestContent + ) + webhookRequestService.handleRequest(request) + } CommitEventType.GIT -> { - pipelineBuildService.externalCodeGitBuild( - codeRepositoryType = CodeGitWebHookTriggerElement.classType, - event = event.event, + val request = WebhookRequest( + taskAtom = CodeGitWebHookTriggerElement.taskAtom, + headers = mapOf( + "X-Event" to event.event!!, + ), body = event.requestContent ) + webhookRequestService.handleRequest(request) + } + CommitEventType.GITLAB -> { + val request = WebhookRequest( + taskAtom = CodeGitlabWebHookTriggerElement.taskAtom, + body = event.requestContent + ) + webhookRequestService.handleRequest(request) } - CommitEventType.GITLAB -> pipelineBuildService.externalGitlabBuild( - e = event.requestContent - ) CommitEventType.TGIT -> { - pipelineBuildService.externalCodeGitBuild( - codeRepositoryType = CodeTGitWebHookTriggerElement.classType, - event = event.event, + val request = WebhookRequest( + taskAtom = CodeTGitWebHookTriggerElement.taskAtom, + headers = mapOf( + "X-Event" to event.event!!, + ), + body = event.requestContent + ) + webhookRequestService.handleRequest(request) + } + CommitEventType.P4 -> { + val request = WebhookRequest( + taskAtom = CodeGitlabWebHookTriggerElement.taskAtom, body = event.requestContent ) + webhookRequestService.handleRequest(request) } - CommitEventType.P4 -> pipelineBuildService.externalP4Build(event.requestContent) } result = true } catch (ignore: Throwable) { @@ -99,8 +116,6 @@ class WebhookEventListener constructor( if (!result) { retryCommitEvent(event) } - saveWebhookTriggerLog(event.commitEventType.name) - PipelineWebhookBuildLogContext.remove() MDC.remove(TraceTag.BIZID) } } @@ -169,24 +184,28 @@ class WebhookEventListener constructor( logger.info("Receive Github from MQ [GITHUB|${event.githubWebhook.event}]") val thisGithubWebhook = event.githubWebhook var result = false - PipelineWebhookBuildLogContext.initTriggerLog( - codeType = CodeType.GITHUB.name, - requestContent = thisGithubWebhook.body - ) try { - pipelineBuildService.externalCodeGithubBuild( - eventType = thisGithubWebhook.event, - guid = thisGithubWebhook.guid, - signature = thisGithubWebhook.signature, - body = thisGithubWebhook.body - ) + val request = with(thisGithubWebhook) { + WebhookRequest( + taskAtom = CodeGithubWebHookTriggerElement.taskAtom, + headers = mapOf( + "X-GitHub-Event" to thisGithubWebhook.event, + "X-Github-Delivery" to guid, + "X-Hub-Signature" to signature + ), + body = thisGithubWebhook.body + ) + } + webhookRequestService.handleRequest(request) + result = true } catch (ignore: Throwable) { logger.warn("Fail to handle the Github event [${event.retryTime}]", ignore) } finally { if (!result && event.retryTime >= 0) { logger.warn("Retry to handle the Github event [${event.retryTime}]") - CodeWebhookEventDispatcher.dispatchGithubEvent(rabbitTemplate, + CodeWebhookEventDispatcher.dispatchGithubEvent( + rabbitTemplate, GithubWebhookEvent( thisGithubWebhook, retryTime = event.retryTime - 1, @@ -194,20 +213,10 @@ class WebhookEventListener constructor( ) ) } - saveWebhookTriggerLog(CodeType.GITHUB.name) - PipelineWebhookBuildLogContext.remove() MDC.remove(TraceTag.BIZID) } } - private fun saveWebhookTriggerLog(codeType: String) { - try { - triggerBuildLogService.saveWebhookBuildLog(PipelineWebhookBuildLogContext.get()) - } catch (ignore: Throwable) { - logger.error("save webhook trigger log failed|codeType=$codeType", ignore) - } - } - companion object { private val logger = LoggerFactory.getLogger(WebhookEventListener::class.java) private const val DELAY_MILLS = 3 * 1000 diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookRequestService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookRequestService.kt new file mode 100644 index 00000000000..0a533289803 --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookRequestService.kt @@ -0,0 +1,47 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.webhook.listener + +import com.tencent.devops.common.service.utils.SpringContextUtil +import com.tencent.devops.common.webhook.atom.IWebhookAtomTask +import com.tencent.devops.common.webhook.pojo.ReplayWebhookRequest +import com.tencent.devops.common.webhook.pojo.WebhookRequest +import org.springframework.stereotype.Service + +@Service +class WebhookRequestService { + + fun handleRequest(request: WebhookRequest) { + SpringContextUtil.getBean(IWebhookAtomTask::class.java, request.taskAtom).request(request = request) + } + + fun handleReplayRequest(request: ReplayWebhookRequest) { + SpringContextUtil.getBean(IWebhookAtomTask::class.java, request.taskAtom).replay(request = request) + } +} diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryWebhookResource.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryWebhookResource.kt new file mode 100644 index 00000000000..56c913bbeb2 --- /dev/null +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryWebhookResource.kt @@ -0,0 +1,65 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.devops.repository.api + +import com.tencent.devops.common.api.pojo.Result +import com.tencent.devops.repository.pojo.RepositoryWebhookRequest +import io.swagger.annotations.Api +import io.swagger.annotations.ApiOperation +import io.swagger.annotations.ApiParam +import javax.ws.rs.Consumes +import javax.ws.rs.GET +import javax.ws.rs.POST +import javax.ws.rs.Path +import javax.ws.rs.PathParam +import javax.ws.rs.Produces +import javax.ws.rs.core.MediaType + +@Api(tags = ["SERVICE_REPOSITORY_WEBHOOK"], description = "服务-代码库webhook") +@Path("/service/repository/webhook") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +interface ServiceRepositoryWebhookResource { + + @ApiOperation("保存代码库触发事件") + @POST + @Path("/save") + fun saveWebhookRequest( + @ApiParam(value = "代码库触发事件", required = true) + repositoryWebhookRequest: RepositoryWebhookRequest + ): Result + + @ApiOperation("获取代码库事件请求") + @GET + @Path("/{eventId}") + fun getWebhookRequest( + @ApiParam(value = "事件ID", required = true) + @PathParam("requestId") + requestId: Long + ): Result +} diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepositoryWebhookRequest.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepositoryWebhookRequest.kt new file mode 100644 index 00000000000..84abaaf63e7 --- /dev/null +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepositoryWebhookRequest.kt @@ -0,0 +1,29 @@ +package com.tencent.devops.repository.pojo + +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty +import java.time.LocalDateTime + +@ApiModel("代码库webhook请求") +data class RepositoryWebhookRequest( + @ApiModelProperty("事件Id,网关traceId") + var requestId: Long? = null, + @ApiModelProperty("事件源,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port") + val externalId: String, + @ApiModelProperty("事件类型") + val eventType: String, + @ApiModelProperty("代码库类型") + val repositoryType: String, + @ApiModelProperty("触发人") + val triggerUser: String, + @ApiModelProperty("事件信息") + val eventMessage: String, + @ApiModelProperty("请求头") + val requestHeader: Map? = null, + @ApiModelProperty("请求参数") + val requestParam:Map? = null, + @ApiModelProperty("请求体") + val requestBody: String, + @ApiModelProperty("事件时间") + val createTime: LocalDateTime +) diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryWebhookRequestDao.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryWebhookRequestDao.kt new file mode 100644 index 00000000000..09b89cff78b --- /dev/null +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryWebhookRequestDao.kt @@ -0,0 +1,104 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.devops.repository.dao + +import com.fasterxml.jackson.core.type.TypeReference +import com.tencent.devops.common.api.util.JsonUtil +import com.tencent.devops.model.repository.tables.TRepositoryWebhookRequest +import com.tencent.devops.model.repository.tables.records.TRepositoryWebhookRequestRecord +import com.tencent.devops.repository.pojo.RepositoryWebhookRequest +import org.jooq.DSLContext +import org.springframework.stereotype.Repository + +@Suppress("ALL") +@Repository +class RepositoryWebhookRequestDao { + fun saveWebhookRequest(dslContext: DSLContext, webhookRequest: RepositoryWebhookRequest): Long { + return with(TRepositoryWebhookRequest.T_REPOSITORY_WEBHOOK_REQUEST) { + dslContext.insertInto( + this, + EXTERNAL_ID, + REPOSITORY_TYPE, + EVENT_TYPE, + TRIGGER_USER, + EVENT_MESSAGE, + REQUEST_HEADER, + REQUEST_PARAM, + REQUEST_BODY, + CREATE_TIME + ).values( + webhookRequest.externalId, + webhookRequest.repositoryType, + webhookRequest.eventType, + webhookRequest.triggerUser, + webhookRequest.eventMessage, + webhookRequest.requestHeader?.let { JsonUtil.toJson(it) }, + webhookRequest.requestParam?.let { JsonUtil.toJson(it) }, + webhookRequest.requestBody, + webhookRequest.createTime + ).returning(REQUEST_ID).fetchOne()?.requestId ?: 1 + } + } + + fun get( + dslContext: DSLContext, + requestId: Long + ): RepositoryWebhookRequest? { + val record = with(TRepositoryWebhookRequest.T_REPOSITORY_WEBHOOK_REQUEST) { + dslContext.selectFrom(this) + .where(REQUEST_ID.eq(requestId)) + .fetchOne() + } + return record?.let { convert(it) } + } + + fun convert(record: TRepositoryWebhookRequestRecord): RepositoryWebhookRequest { + return with(record) { + RepositoryWebhookRequest( + requestId = requestId, + externalId = externalId, + eventType = eventType, + repositoryType = repositoryType, + triggerUser = triggerUser, + eventMessage = eventMessage, + requestHeader = requestHeader?.let { + JsonUtil.to( + it, + object : TypeReference>() {}) + }, + requestParam = requestParam?.let { + JsonUtil.to( + it, + object : TypeReference>() {}) + }, + requestBody = requestBody, + createTime = createTime + ) + } + } +} diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceRepositoryWebhookResourceImpl.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceRepositoryWebhookResourceImpl.kt new file mode 100644 index 00000000000..64bc9bfc9bc --- /dev/null +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceRepositoryWebhookResourceImpl.kt @@ -0,0 +1,50 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.devops.repository.resources + +import com.tencent.devops.common.api.pojo.Result +import com.tencent.devops.common.web.RestResource +import com.tencent.devops.repository.api.ServiceRepositoryWebhookResource +import com.tencent.devops.repository.pojo.RepositoryWebhookRequest +import com.tencent.devops.repository.service.RepositoryWebhookService +import org.springframework.beans.factory.annotation.Autowired + +@Suppress("ALL") +@RestResource +class ServiceRepositoryWebhookResourceImpl @Autowired constructor( + val repositoryWebhookService: RepositoryWebhookService +) : ServiceRepositoryWebhookResource { + + override fun saveWebhookRequest(repositoryWebhookRequest: RepositoryWebhookRequest): Result { + return Result(repositoryWebhookService.saveWebhookRequest(repositoryWebhookRequest)) + } + + override fun getWebhookRequest(requestId: Long): Result { + return Result(repositoryWebhookService.getWebhookRequest(requestId = requestId)) + } +} diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepositoryWebhookService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepositoryWebhookService.kt new file mode 100644 index 00000000000..c7d6ffdfbf9 --- /dev/null +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepositoryWebhookService.kt @@ -0,0 +1,40 @@ +package com.tencent.devops.repository.service + +import com.tencent.devops.common.api.exception.ParamBlankException +import com.tencent.devops.repository.dao.RepositoryWebhookRequestDao +import com.tencent.devops.repository.pojo.RepositoryWebhookRequest +import org.jooq.DSLContext +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.stereotype.Service + +@Service +@SuppressWarnings("ALL") +class RepositoryWebhookService @Autowired constructor( + val repositoryWebhookRequestDao: RepositoryWebhookRequestDao, + val dslContext: DSLContext +) { + fun saveWebhookRequest(repositoryWebhookRequest: RepositoryWebhookRequest): Long { + with(repositoryWebhookRequest) { + if (externalId.isBlank()) { + throw ParamBlankException("Invalid eventSource") + } + if (repositoryType.isBlank()) { + throw ParamBlankException("Invalid triggerType") + } + if (eventType.isBlank()) { + throw ParamBlankException("Invalid eventType") + } + return repositoryWebhookRequestDao.saveWebhookRequest( + dslContext = dslContext, + webhookRequest = repositoryWebhookRequest + ) + } + } + + fun getWebhookRequest(requestId: Long): RepositoryWebhookRequest? { + return repositoryWebhookRequestDao.get( + dslContext = dslContext, + requestId = requestId + ) + } +} diff --git a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/GitActionCommon.kt b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/GitActionCommon.kt index 29ab48d4d1d..b1eb41a6c01 100644 --- a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/GitActionCommon.kt +++ b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/GitActionCommon.kt @@ -3,8 +3,8 @@ package com.tencent.devops.stream.trigger.actions import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.webhook.service.code.loader.WebhookElementParamsRegistrar import com.tencent.devops.common.webhook.service.code.loader.WebhookStartParamsRegistrar -import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher import com.tencent.devops.common.webhook.service.code.pojo.EventRepositoryCache +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.EventCacheUtil import com.tencent.devops.process.yaml.v2.models.on.TriggerOn import com.tencent.devops.stream.common.Constansts @@ -17,7 +17,7 @@ import org.joda.time.DateTime import org.slf4j.LoggerFactory import java.io.File import java.text.SimpleDateFormat -import java.util.Date +import java.util.* object GitActionCommon { @@ -97,7 +97,7 @@ object GitActionCommon { matcher = matcher, variables = mapOf(), params = webHookParams, - matchResult = ScmWebhookMatcher.MatchResult(isMatch = isMatch) + matchResult = WebhookMatchResult(isMatch = isMatch) ).map { entry -> entry.key to entry.value.toString() }.toMap() } else { emptyMap() diff --git a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/parsers/triggerMatch/matchUtils/PathMatchUtils.kt b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/parsers/triggerMatch/matchUtils/PathMatchUtils.kt index 65876a6ef88..81a09390bce 100644 --- a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/parsers/triggerMatch/matchUtils/PathMatchUtils.kt +++ b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/parsers/triggerMatch/matchUtils/PathMatchUtils.kt @@ -27,7 +27,7 @@ object PathMatchUtils { // 包含匹配失败 val includePathsMatch = pathIgnoreList.isEmpty() && pathList.isNotEmpty() && - response.getParam()[MATCH_PATHS] == null + response.params[MATCH_PATHS] == null return if (includePathsMatch) { TriggerBody().triggerFail("on.push.paths", "change path($pathList) not match") } else { diff --git a/support-files/sql/1001_ci_process_ddl_mysql.sql b/support-files/sql/1001_ci_process_ddl_mysql.sql index 7d4ea03a464..ab3b606fd46 100644 --- a/support-files/sql/1001_ci_process_ddl_mysql.sql +++ b/support-files/sql/1001_ci_process_ddl_mysql.sql @@ -1170,4 +1170,55 @@ CREATE TABLE IF NOT EXISTS `T_PIPELINE_BUILD_RECORD_TASK` ( PRIMARY KEY (`BUILD_ID`,`TASK_ID`,`EXECUTE_COUNT`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='流水线构建任务表'; + +-- ---------------------------- +-- Table structure for T_PIPELINE_WEBHOOK_EVENT +-- ---------------------------- + +CREATE TABLE IF NOT EXISTS `T_PIPELINE_WEBHOOK_EVENT` +( + `PROJECT_ID` varchar(64) NOT NULL COMMENT '项目ID', + `REQUEST_ID` bigint(20) NOT NULL COMMENT '请求ID', + `EVENT_ID` bigint(20) NOT NULL COMMENT '事件ID', + `TRIGGER_TYPE` varchar(64) NOT NULL COMMENT '触发类型', + `EVENT_SOURCE` varchar(255) NOT NULL COMMENT '触发源', + `EVENT_TYPE` varchar(64) NOT NULL COMMENT '事件类型', + `TRIGGER_USER` varchar(100) NOT NULL COMMENT '触发用户', + `EVENT_MESSAGE` text NOT NULL COMMENT '事件信息', + `EVENT_DESC` text NOT NULL COMMENT '事件描述', + `EVENT_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '事件时间', + `TASK_ATOM` varchar(128) COMMENT '事件处理类', + PRIMARY KEY (`EVENT_ID`, `EVENT_TIME`), + unique UQ_EVENT_ID_EVENT_SOURCE (`PROJECT_ID`,`EVENT_ID`, `EVENT_SOURCE`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT ='流水线WEBHOOK事件表'; + +-- ---------------------------- +-- Table structure for T_PIPELINE_TRIGGER_EVENT +-- ---------------------------- + +CREATE TABLE IF NOT EXISTS `T_PIPELINE_TRIGGER_EVENT` +( + `ID` bigint(20) NOT NULL COMMENT '触发ID', + `PROJECT_ID` varchar(64) NOT NULL COMMENT '蓝盾项目ID', + `EVENT_ID` bigint(20) NOT NULL COMMENT '事件ID', + `TRIGGER_TYPE` varchar(64) NOT NULL COMMENT '触发类型', + `EVENT_SOURCE` varchar(255) NOT NULL COMMENT '触发源', + `EVENT_TYPE` varchar(64) NOT NULL COMMENT '事件类型', + `TRIGGER_USER` varchar(100) NOT NULL COMMENT '触发用户', + `EVENT_MESSAGE` text NOT NULL COMMENT '事件信息', + `EVENT_DESC` text NOT NULL COMMENT '事件描述', + `EVENT_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '事件时间', + `STATUS` varchar(100) DEFAULT NULL COMMENT '状态(success or failure)', + `PIPELINE_ID` varchar(100) DEFAULT NULL COMMENT '流水线ID', + `PIPELINE_NAME` varchar(100) DEFAULT NULL COMMENT '流水线名称', + `VERSION` int DEFAULT NULL COMMENT '流水线版本号', + `BUILD_ID` varchar(100) DEFAULT NULL COMMENT '构建ID', + `BUILD_NUM` varchar(100) DEFAULT NULL COMMENT '构建编号', + `REASON` varchar(100) DEFAULT NULL COMMENT '原因', + `REASON_DETAIL` varchar(100) DEFAULT NULL COMMENT '原因详情', + `CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + PRIMARY KEY (`ID`, `CREATE_TIME`), + index IDX_EVENT_ID_EVENT_SOURCE (`PROJECT_ID`,`EVENT_ID`, `EVENT_SOURCE`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT ='流水线触发事件信息表'; + SET FOREIGN_KEY_CHECKS = 1; diff --git a/support-files/sql/1001_ci_repository_ddl_mysql.sql b/support-files/sql/1001_ci_repository_ddl_mysql.sql index dea8a3f0926..16cc5b91759 100644 --- a/support-files/sql/1001_ci_repository_ddl_mysql.sql +++ b/support-files/sql/1001_ci_repository_ddl_mysql.sql @@ -176,4 +176,23 @@ CREATE TABLE IF NOT EXISTS `T_REPOSITORY_CODE_P4` ( ) ENGINE=INNODB DEFAULT CHARSET=utf8mb4; +-- ---------------------------- +-- Table structure for T_REPOSITORY_WEBHOOK_REQUEST +-- ---------------------------- + +CREATE TABLE IF NOT EXISTS `T_REPOSITORY_WEBHOOK_REQUEST` +( + `REQUEST_ID` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '请求ID', + `EXTERNAL_ID` varchar(255) DEFAULT NULL COMMENT '代码库平台ID', + `REPOSITORY_TYPE` varchar(32) DEFAULT NULL COMMENT '触发类型', + `EVENT_TYPE` varchar(255) DEFAULT NULL COMMENT '事件类型', + `TRIGGER_USER` varchar(100) NOT NULL COMMENT '触发用户', + `EVENT_MESSAGE` text NOT NULL COMMENT '事件信息', + `REQUEST_HEADER` text COMMENT '事件请求头', + `REQUEST_PARAM` text COMMENT '事件请求参数', + `REQUEST_BODY` text COMMENT '事件请求体', + `CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + PRIMARY KEY (`REQUEST_ID`, `CREATE_TIME`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT ='代码库WEBHOOK请求表'; + SET FOREIGN_KEY_CHECKS = 1; diff --git a/support-files/sql/5001_init_dml/5001_ci_project-init_dml_mysql.sql b/support-files/sql/5001_init_dml/5001_ci_project-init_dml_mysql.sql index 7351f8eac88..874a83d459e 100755 --- a/support-files/sql/5001_init_dml/5001_ci_project-init_dml_mysql.sql +++ b/support-files/sql/5001_init_dml/5001_ci_project-init_dml_mysql.sql @@ -48,6 +48,8 @@ REPLACE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ( REPLACE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ('T_ATOM_INDEX_STATISTICS_DAILY', 1, 100, '插件每日指标数据ID管理'); REPLACE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ('AUTH_RESOURCE', 1, 100, '权限资源'); REPLACE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ('ATOM_MONITOR_DATA_DAILY', 1, 100, '插件每日监控数据ID管理'); +INSERT IGNORE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ('PIPELINE_WEBHOOK_EVENT', 1, 2000, '流水线webhook事件'); +INSERT IGNORE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ('PIPELINE_TRIGGER_EVENT', 1, 2000, '流水线触发事件'); REPLACE INTO `T_I18N_MESSAGE` (`ID`, `MODULE_CODE`, `LANGUAGE`, `KEY`, `VALUE`, `CREATOR`, `MODIFIER`, `UPDATE_TIME`, `CREATE_TIME`) VALUES('12cfe76hgu9cn4047bfd4e6ddd0aaada', 'STORE', 'zh_CN', 'reason.e20897c838564d61b5af1a8c9c1d26d2.content', '只是试用下', 'system', 'system', '2023-06-26 10:59:20.561', '2023-06-26 10:59:47'); REPLACE INTO `T_I18N_MESSAGE` (`ID`, `MODULE_CODE`, `LANGUAGE`, `KEY`, `VALUE`, `CREATOR`, `MODIFIER`, `UPDATE_TIME`, `CREATE_TIME`) VALUES('13312a05cxt1468088bdb71637sc14ds', 'STORE', 'en_US', 'reason.e20897c838564d61b5af1a8c9c1d26d2.content', 'Just trying it out.', 'system', 'system', '2023-06-26 10:59:20.561', '2023-06-26 10:59:47'); From efa10ed84f800b4aaf002d75509922adf57e59ed Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Tue, 1 Aug 2023 21:56:08 +0800 Subject: [PATCH 002/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pojo/webhook/PipelineTriggerTask.kt | 38 ------- .../process/engine/dao/PipelineWebhookDao.kt | 77 ------------- .../engine/service/PipelineWebhookService.kt | 64 ----------- .../webhook/WebHookTriggerElementBizPlugin.kt | 54 ++------- .../CodeGitWebHookTriggerElementBizPlugin.kt | 103 ------------------ .../stream/trigger/actions/GitActionCommon.kt | 2 +- 6 files changed, 12 insertions(+), 326 deletions(-) delete mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineTriggerTask.kt delete mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/element/CodeGitWebHookTriggerElementBizPlugin.kt diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineTriggerTask.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineTriggerTask.kt deleted file mode 100644 index b1512a27770..00000000000 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineTriggerTask.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.tencent.devops.process.pojo.webhook - -/** - * 流水线webhook触发插件 - */ -data class PipelineTriggerTask( - val projectId: String, - val pipelineId: String, - val taskId: String -) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt index 2d5848e5f03..8e5f7ec7a0f 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt @@ -31,14 +31,12 @@ import com.tencent.devops.common.api.enums.RepositoryType import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.model.process.Tables.T_PIPELINE_WEBHOOK import com.tencent.devops.model.process.tables.records.TPipelineWebhookRecord -import com.tencent.devops.process.pojo.webhook.PipelineTriggerTask import com.tencent.devops.process.pojo.webhook.PipelineWebhook import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber import org.jooq.DSLContext import org.jooq.Result import org.slf4j.LoggerFactory import org.springframework.stereotype.Repository -import java.time.LocalDateTime @Suppress("ALL") @Repository @@ -227,81 +225,6 @@ class PipelineWebhookDao { }?.map { convert(it) } } - fun save( - dslContext: DSLContext, - projectId: String, - pipelineId: String, - repositoryType: String, - repoType: String, - repoHashId: String?, - repoName: String?, - projectName: String, - taskId: String, - eventSource: String, - eventType: String - ): Int { - val now = LocalDateTime.now() - return with(T_PIPELINE_WEBHOOK) { - dslContext.insertInto( - this, - PROJECT_ID, - PIPELINE_ID, - REPOSITORY_TYPE, - REPO_TYPE, - REPO_HASH_ID, - REPO_NAME, - PROJECT_NAME, - TASK_ID, - EVENT_SOURCE, - EVENT_TYPE, - CREATE_TIME, - UPDATE_TIME - ) - .values( - projectId, - pipelineId, - repositoryType, - repoType, - repoHashId, - repoName, - projectName, - taskId, - eventSource, - eventType, - now, - now - ) - .onDuplicateKeyUpdate() - .set(REPO_TYPE, repoType) - .set(REPO_HASH_ID, repoHashId) - .set(REPO_NAME, repoName) - .set(PROJECT_NAME, projectName) - .set(EVENT_SOURCE, eventSource) - .set(EVENT_TYPE, eventType) - .set(UPDATE_TIME, now) - .execute() - } - } - - fun getSubscriber( - dslContext: DSLContext, - eventSource: String, - eventType: String - ): List { - return with(T_PIPELINE_WEBHOOK) { - dslContext.select(PROJECT_ID, PIPELINE_ID, TASK_ID).from(this) - .where(EVENT_SOURCE.eq(eventSource)) - .and(EVENT_TYPE.eq(eventType)) - .fetch { - PipelineTriggerTask( - projectId = it.value1(), - pipelineId = it.value2(), - taskId = it.value3() - ) - } - } - } - companion object { private val logger = LoggerFactory.getLogger(PipelineWebhookDao::class.java) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index d769b794e31..6eb56fc1a4e 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -63,7 +63,6 @@ import com.tencent.devops.process.engine.dao.PipelineWebhookDao import com.tencent.devops.process.engine.pojo.WebhookElementParams import com.tencent.devops.process.permission.PipelinePermissionService import com.tencent.devops.process.pojo.PipelineNotifyTemplateEnum -import com.tencent.devops.process.pojo.webhook.PipelineTriggerTask import com.tencent.devops.process.pojo.webhook.PipelineWebhook import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber import com.tencent.devops.process.service.scm.ScmProxyService @@ -256,33 +255,6 @@ class PipelineWebhookService @Autowired constructor( private fun pipelineEditUrl(projectId: String, pipelineId: String) = "${HomeHostUtil.innerServerHost()}/console/pipeline/$projectId/$pipelineId/edit" - fun save( - projectId: String, - pipelineId: String, - repositoryType: String, - repoType: String, - repoHashId: String?, - repoName: String?, - projectName: String, - taskId: String, - eventSource: String, - eventType: String - ) { - pipelineWebhookDao.save( - dslContext = dslContext, - projectId = projectId, - pipelineId = pipelineId, - repositoryType = repositoryType, - repoType = repoType, - repoHashId = repoHashId, - repoName = repoName, - projectName = projectName, - taskId = taskId, - eventSource = eventSource, - eventType = eventType - ) - } - fun deleteWebhook(projectId: String, pipelineId: String, userId: String): Result { logger.info("delete $pipelineId webhook by $userId") pipelineWebhookDao.deleteByPipelineId(dslContext, projectId, pipelineId) @@ -319,31 +291,6 @@ class PipelineWebhookService @Autowired constructor( ) ?: emptyList() } - fun getWebhookScmType(type: String) = - when (type) { - CodeGitWebHookTriggerElement.classType -> { - ScmType.CODE_GIT - } - CodeSVNWebHookTriggerElement.classType -> { - ScmType.CODE_SVN - } - CodeGitlabWebHookTriggerElement.classType -> { - ScmType.CODE_GITLAB - } - CodeGithubWebHookTriggerElement.classType -> { - ScmType.GITHUB - } - CodeTGitWebHookTriggerElement.classType -> { - ScmType.CODE_TGIT - } - CodeP4WebHookTriggerElement.classType -> { - ScmType.CODE_P4 - } - else -> { - throw IllegalArgumentException("Unknown web hook type($type)") - } - } - fun getProjectName(projectName: String): String { // 如果项目名是三层的,比如a/b/c,那对应的rep_name是b val repoSplit = projectName.split("/") @@ -649,17 +596,6 @@ class PipelineWebhookService @Autowired constructor( } } - fun getSubscriber( - eventSource: String, - eventType: String - ): List { - return pipelineWebhookDao.getSubscriber( - dslContext = dslContext, - eventSource = eventSource, - eventType = eventType - ) - } - private fun PipelineWebhook.doUpdateWebhookSecret( pipelines: MutableMap>, pipelineVariables: HashMap> diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebHookTriggerElementBizPlugin.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebHookTriggerElementBizPlugin.kt index ad004afc0cf..35a57e003ef 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebHookTriggerElementBizPlugin.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebHookTriggerElementBizPlugin.kt @@ -27,13 +27,10 @@ package com.tencent.devops.process.webhook -import com.tencent.devops.common.api.constant.CommonMessageCode -import com.tencent.devops.common.api.enums.RepositoryTypeNew -import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.pipeline.container.Container import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitGenericWebHookTriggerElement +import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGithubWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitlabWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeP4WebHookTriggerElement @@ -72,6 +69,16 @@ abstract class WebHookTriggerElementBizPlugin constru override fun check(element: T, appearedCnt: Int) = Unit } +@ElementBiz +class CodeGitWebHookTriggerElementBizPlugin constructor( + pipelineWebhookService: PipelineWebhookService +) : WebHookTriggerElementBizPlugin(pipelineWebhookService) { + + override fun elementClass(): Class { + return CodeGitWebHookTriggerElement::class.java + } +} + @ElementBiz class CodeGithubWebHookTriggerElementBizPlugin constructor( pipelineWebhookService: PipelineWebhookService @@ -109,45 +116,6 @@ class CodeTGitWebHookTriggerElementBizPlugin constructor( } } -@ElementBiz -class CodeGitGenericWebHookTriggerElementBizPlugin constructor( - pipelineWebhookService: PipelineWebhookService -) : WebHookTriggerElementBizPlugin(pipelineWebhookService) { - override fun elementClass(): Class { - return CodeGitGenericWebHookTriggerElement::class.java - } - - override fun check(element: CodeGitGenericWebHookTriggerElement, appearedCnt: Int) { - with(element.data.input) { - if (repositoryType == RepositoryTypeNew.URL && - credentialId.isNullOrBlank() && - token.isNullOrBlank() - ) { - throw ErrorCodeException( - errorCode = CommonMessageCode.PARAMETER_IS_NULL, - params = arrayOf("credentialId") - ) - } - } - } - - override fun afterCreate( - element: CodeGitGenericWebHookTriggerElement, - projectId: String, - pipelineId: String, - pipelineName: String, - userId: String, - channelCode: ChannelCode, - create: Boolean, - container: Container - ) { - // 只支持codecc才能自定义hookUrl - if (channelCode != ChannelCode.CODECC && !element.data.input.hookUrl.isNullOrBlank()) { - element.data.input.hookUrl = null - } - } -} - @ElementBiz class CodeP4WebHookTriggerElementBizPlugin constructor( pipelineWebhookService: PipelineWebhookService diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/element/CodeGitWebHookTriggerElementBizPlugin.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/element/CodeGitWebHookTriggerElementBizPlugin.kt deleted file mode 100644 index eff4b6aa981..00000000000 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/element/CodeGitWebHookTriggerElementBizPlugin.kt +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.tencent.devops.process.webhook.element - -import com.tencent.devops.common.api.enums.ScmType -import com.tencent.devops.common.pipeline.container.Container -import com.tencent.devops.common.pipeline.container.TriggerContainer -import com.tencent.devops.common.pipeline.enums.ChannelCode -import com.tencent.devops.common.pipeline.pojo.element.atom.BeforeDeleteParam -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitWebHookTriggerElement -import com.tencent.devops.common.pipeline.utils.RepositoryConfigUtils -import com.tencent.devops.process.engine.service.PipelineWebhookService -import com.tencent.devops.process.plugin.ElementBizPlugin -import com.tencent.devops.process.plugin.annotation.ElementBiz -import com.tencent.devops.process.service.scm.ScmProxyService -import org.springframework.beans.factory.annotation.Autowired - -@ElementBiz -class CodeGitWebHookTriggerElementBizPlugin @Autowired constructor( - private val scmProxyService: ScmProxyService, - private val pipelineWebhookService: PipelineWebhookService -) : ElementBizPlugin { - override fun elementClass(): Class { - return CodeGitWebHookTriggerElement::class.java - } - - override fun check(element: CodeGitWebHookTriggerElement, appearedCnt: Int) = Unit - - override fun beforeDelete(element: CodeGitWebHookTriggerElement, param: BeforeDeleteParam) { - if (param.pipelineId.isNotBlank()) { - pipelineWebhookService.deleteWebhook( - projectId = param.projectId, - pipelineId = param.pipelineId, - taskId = element.id!!, - userId = param.userId - ) - } - } - - override fun afterCreate( - element: CodeGitWebHookTriggerElement, - projectId: String, - pipelineId: String, - pipelineName: String, - userId: String, - channelCode: ChannelCode, - create: Boolean, - container: Container - ) { - val variable = (container as TriggerContainer).params.associate { param -> - param.id to param.defaultValue.toString() - } - val repositoryConfig = RepositoryConfigUtils.getRepositoryConfig( - repoHashId = element.repositoryHashId, - repoName = element.repositoryName, - repoType = element.repositoryType, - variable = variable - ) - val repository = scmProxyService.addGitWebhook( - projectId = projectId, - repositoryConfig = repositoryConfig, - codeEventType = element.eventType - ) - pipelineWebhookService.save( - projectId = projectId, - pipelineId = pipelineId, - repositoryType = ScmType.CODE_GIT.name, - repoType = repositoryConfig.repositoryType.name, - repoHashId = repositoryConfig.repositoryHashId, - repoName = repositoryConfig.repositoryName, - projectName = repository.projectName, - taskId = element.id!!, - eventSource = repository.gitProjectId?.toString() ?: repository.projectName, - eventType = element.eventType!!.name - ) - } -} diff --git a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/GitActionCommon.kt b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/GitActionCommon.kt index b1eb41a6c01..1543a447e42 100644 --- a/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/GitActionCommon.kt +++ b/src/backend/ci/core/stream/biz-stream/src/main/kotlin/com/tencent/devops/stream/trigger/actions/GitActionCommon.kt @@ -17,7 +17,7 @@ import org.joda.time.DateTime import org.slf4j.LoggerFactory import java.io.File import java.text.SimpleDateFormat -import java.util.* +import java.util.Date object GitActionCommon { From 2e2a8cfffee148225def9694225b59c6fc4f2b08 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Wed, 2 Aug 2023 12:26:12 +0800 Subject: [PATCH 003/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/api/user/UserPipelineTriggerEventResource.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt index 036762223bb..8510b455e4e 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt @@ -133,7 +133,7 @@ interface UserPipelineTriggerEventResource { @ApiOperation("获取代码库webhook事件触发详情") @GET - @Path("/{projectId}/{repoHashId}/listRepoWebhookEvent") + @Path("/{projectId}/{repoHashId}/listRepoWebhookEventDetail") fun listRepoWebhookEventDetail( @ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE) @HeaderParam(AUTH_HEADER_USER_ID) @@ -148,7 +148,7 @@ interface UserPipelineTriggerEventResource { @QueryParam("eventId") eventId: Long, @ApiParam("流水线ID", required = true) - @PathParam("pipelineId") + @QueryParam("pipelineId") pipelineId: String, @ApiParam("第几页", required = false, defaultValue = "1") @QueryParam("page") From 1e1f0060bc8dc447243bf0cc311abcc5b8fef912 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 3 Aug 2023 21:39:31 +0800 Subject: [PATCH 004/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/webhook/atom/IWebhookAtomTask.kt | 4 +- .../common/webhook/pojo/WebhookRequest.kt | 1 - ...hookRequest.kt => WebhookRequestReplay.kt} | 12 +- .../user/UserPipelineTriggerEventResource.kt | 29 +- .../process/constant/ProcessMessageCode.kt | 6 + .../pojo/trigger/PipelineTriggerDetail.kt} | 44 ++- .../pojo/trigger/PipelineTriggerEvent.kt | 37 +- .../trigger/PipelineTriggerEventBuilder.kt | 38 +- .../PipelineTriggerEventVo.kt} | 41 +- .../RepoTriggerEventVo.kt} | 4 +- .../UserPipelineTriggerEventResourceImpl.kt | 23 +- .../process/dao/PipelineTriggerEventDao.kt | 374 ++++++++++++------ .../process/dao/PipelineWebhookEventDao.kt | 198 ---------- .../trigger/PipelineTriggerEventService.kt | 121 +++--- .../webhook/PipelineBuildWebhookService.kt | 48 ++- .../atom/CodeGitWebhookTriggerTaskAtom.kt | 37 +- .../atom/CodeGithubWebHookTriggerTaskAtom.kt | 41 +- .../atom/CodeGitlabWebHookTriggerTaskAtom.kt | 39 +- .../atom/CodeP4WebHookTriggerTaskAtom.kt | 37 +- .../atom/CodeSvnWebHookTriggerTaskAtom.kt | 37 +- .../atom/CodeTGitWebhookTriggerTaskAtom.kt | 3 - .../listener/PipelineTriggerRequestService.kt | 99 +++++ .../webhook/listener/WebhookEventListener.kt | 38 +- 23 files changed, 656 insertions(+), 655 deletions(-) rename src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/{ReplayWebhookRequest.kt => WebhookRequestReplay.kt} (86%) rename src/backend/ci/core/process/{biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookRequestService.kt => api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetail.kt} (60%) rename src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/{webhook/PipelineWebhookEvent.kt => trigger/PipelineTriggerEventVo.kt} (66%) rename src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/{webhook/RepoWebhookEvent.kt => trigger/RepoTriggerEventVo.kt} (96%) delete mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineWebhookEventDao.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/PipelineTriggerRequestService.kt diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/atom/IWebhookAtomTask.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/atom/IWebhookAtomTask.kt index babed8b84ea..4e3fc58be3d 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/atom/IWebhookAtomTask.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/atom/IWebhookAtomTask.kt @@ -28,7 +28,7 @@ package com.tencent.devops.common.webhook.atom -import com.tencent.devops.common.webhook.pojo.ReplayWebhookRequest +import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay import com.tencent.devops.common.webhook.pojo.WebhookRequest /** @@ -43,5 +43,5 @@ interface IWebhookAtomTask { /** * webhook事件重放 */ - fun replay(request: ReplayWebhookRequest) + fun replay(request: WebhookRequestReplay) } diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequest.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequest.kt index b877173d5eb..a0e9d7a60c3 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequest.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequest.kt @@ -29,7 +29,6 @@ package com.tencent.devops.common.webhook.pojo data class WebhookRequest( - val taskAtom: String, val headers: Map? = null, val queryParams: Map? = null, val body: String diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/ReplayWebhookRequest.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequestReplay.kt similarity index 86% rename from src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/ReplayWebhookRequest.kt rename to src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequestReplay.kt index 82469822176..81be3f33ff4 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/ReplayWebhookRequest.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequestReplay.kt @@ -32,19 +32,13 @@ import io.swagger.annotations.ApiModel import io.swagger.annotations.ApiModelProperty @ApiModel -class ReplayWebhookRequest( - @ApiModelProperty("事件处理类") - val taskAtom: String, +class WebhookRequestReplay( @ApiModelProperty("用户ID") val userId: String, @ApiModelProperty("项目ID") val projectId: String, - @ApiModelProperty("事件ID") - val eventId: Long, - @ApiModelProperty("请求ID") - val requestId: Long, - @ApiModelProperty("事件源") - val eventSource: String, + @ApiModelProperty("webhook请求ID") + val hookRequestId: Long, @ApiModelProperty("重试流水线ID") val pipelineId: String? = null ) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt index 8510b455e4e..b634e49b078 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt @@ -32,8 +32,8 @@ import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID_DEFAULT_VALUE import com.tencent.devops.common.api.model.SQLPage import com.tencent.devops.common.api.pojo.Result -import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent -import com.tencent.devops.process.pojo.webhook.RepoWebhookEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventVo +import com.tencent.devops.process.pojo.trigger.RepoTriggerEventVo import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation import io.swagger.annotations.ApiParam @@ -79,7 +79,7 @@ interface UserPipelineTriggerEventResource { @QueryParam("startTime") startTime: Long?, @ApiParam("结束", required = false) - @QueryParam("startTime") + @QueryParam("endTime") endTime: Long?, @ApiParam("第几页", required = false, defaultValue = "1") @QueryParam("page") @@ -87,7 +87,7 @@ interface UserPipelineTriggerEventResource { @ApiParam("每页多少条", required = false, defaultValue = "20") @QueryParam("pageSize") pageSize: Int? - ): Result> + ): Result> @ApiOperation("获取代码库webhook事件列表") @GET @@ -121,7 +121,7 @@ interface UserPipelineTriggerEventResource { @QueryParam("startTime") startTime: Long?, @ApiParam("结束", required = false) - @QueryParam("startTime") + @QueryParam("endTime") endTime: Long?, @ApiParam("第几页", required = false, defaultValue = "1") @QueryParam("page") @@ -129,7 +129,7 @@ interface UserPipelineTriggerEventResource { @ApiParam("每页多少条", required = false, defaultValue = "20") @QueryParam("pageSize") pageSize: Int? - ): Result> + ): Result> @ApiOperation("获取代码库webhook事件触发详情") @GET @@ -156,11 +156,11 @@ interface UserPipelineTriggerEventResource { @ApiParam("每页多少条", required = false, defaultValue = "20") @QueryParam("pageSize") pageSize: Int?, - ): Result> + ): Result> @ApiOperation("重新触发") @POST - @Path("/{projectId}/{id}/replay") + @Path("/{projectId}/{detailId}/replay") fun replay( @ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE) @HeaderParam(AUTH_HEADER_USER_ID) @@ -168,14 +168,14 @@ interface UserPipelineTriggerEventResource { @ApiParam("项目ID", required = true) @PathParam("projectId") projectId: String, - @ApiParam("触发ID", required = true) - @PathParam("id") - id: Long + @ApiParam("触发详情ID", required = true) + @PathParam("detailId") + detailId: Long ): Result @ApiOperation("一键重新触发") @POST - @Path("/{projectId}/{repoHashId}/{eventId}/replayAll") + @Path("/{projectId}/{eventId}/replayAll") fun replayAll( @ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE) @HeaderParam(AUTH_HEADER_USER_ID) @@ -183,10 +183,7 @@ interface UserPipelineTriggerEventResource { @ApiParam("项目ID", required = true) @PathParam("projectId") projectId: String, - @ApiParam("代码库ID", required = true) - @PathParam("repoHashId") - repoHashId: String, - @ApiParam("触发ID", required = true) + @ApiParam("事件ID", required = true) @PathParam("eventId") eventId: Long ): Result diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/constant/ProcessMessageCode.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/constant/ProcessMessageCode.kt index e1f502aac50..fb2541bb177 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/constant/ProcessMessageCode.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/constant/ProcessMessageCode.kt @@ -280,6 +280,12 @@ object ProcessMessageCode { const val PIPELINE_BUILD_HAS_ENDED_CANNOT_BE_CANCELED = "2101179" // 流水线: 流水线构建已结束,不能取消 const val GET_PIPELINE_ATOM_INFO_NO_PERMISSION = "2101180" // 无权访问插件{0}的流水线信息,请联系组件管理员 + const val ERROR_TRIGGER_DETAIL_NOT_FOUND = "2101181" // 触发详情{0}不存在 + const val ERROR_TRIGGER_EVENT_NOT_FOUND = "2101182" // 触发事件{0}不存在 + const val ERROR_TRIGGER_TYPE_REPLAY_NOT_SUPPORT = "2101183" // 触发类型{0}不支持重放 + const val ERROR_TRIGGER_REPLAY_PIPELINE_NOT_EMPTY = "2101184" // 重放流水线ID不能为空 + const val ERROR_WEBHOOK_REQUEST_NOT_FOUND = "2101185" // webhook {0} 不存在 + const val BK_SUCCESSFULLY_DISTRIBUTED = "bkSuccessfullyDistributed" // 跨项目构件分发成功,共分发了{0}个文件 const val BK_SUCCESSFULLY_FAILED = "bkSuccessfullyFailed" // 跨项目构件分发失败, const val BK_NO_MATCH_FILE_DISTRIBUTE = "bkNoMatchFileDistribute" // 匹配不到待分发的文件: {0} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookRequestService.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetail.kt similarity index 60% rename from src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookRequestService.kt rename to src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetail.kt index 0a533289803..9329a4c2ad9 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookRequestService.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetail.kt @@ -26,22 +26,32 @@ * */ -package com.tencent.devops.process.webhook.listener +package com.tencent.devops.process.pojo.trigger -import com.tencent.devops.common.service.utils.SpringContextUtil -import com.tencent.devops.common.webhook.atom.IWebhookAtomTask -import com.tencent.devops.common.webhook.pojo.ReplayWebhookRequest -import com.tencent.devops.common.webhook.pojo.WebhookRequest -import org.springframework.stereotype.Service +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty -@Service -class WebhookRequestService { - - fun handleRequest(request: WebhookRequest) { - SpringContextUtil.getBean(IWebhookAtomTask::class.java, request.taskAtom).request(request = request) - } - - fun handleReplayRequest(request: ReplayWebhookRequest) { - SpringContextUtil.getBean(IWebhookAtomTask::class.java, request.taskAtom).replay(request = request) - } -} +@ApiModel("流水线触发详情") +data class PipelineTriggerDetail( + var detailId: Long? = null, + @ApiModelProperty("蓝盾项目ID") + val projectId: String, + @ApiModelProperty("事件ID") + val eventId: Long, + @ApiModelProperty("触发状态") + var status: String, + @ApiModelProperty("流水线Id") + var pipelineId: String? = null, + @ApiModelProperty("流水线名称") + var pipelineName: String? = null, + @ApiModelProperty("构建Id") + var buildId: String? = null, + @ApiModelProperty("构建编号") + var buildNum: String? = null, + @ApiModelProperty("原因") + var reason: String? = null, + @ApiModelProperty("原因详情", required = false) + var reasonDetailList: List? = null, + @ApiModelProperty("创建时间", required = false) + val createTime: Long? = null +) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt index 9e3b6e26a52..fc3f1c921cb 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt @@ -32,41 +32,26 @@ import io.swagger.annotations.ApiModel import io.swagger.annotations.ApiModelProperty import java.time.LocalDateTime -@ApiModel("流水线触发事件模型") +@ApiModel("流水线触发事件") data class PipelineTriggerEvent( - var id: Long? = null, - @ApiModelProperty("蓝盾项目ID") - val projectId: String, + @ApiModelProperty("项目ID") + var projectId: String? = null, @ApiModelProperty("事件ID") - val eventId: Long, + var eventId: Long? = null, @ApiModelProperty("触发类型") val triggerType: String, - @ApiModelProperty("事件触发源,代码库触发-代码库ID", required = false) - val eventSource: String? = "", + @ApiModelProperty("事件源", required = false) + var eventSource: String? = null, @ApiModelProperty("事件类型") val eventType: String, @ApiModelProperty("触发人") val triggerUser: String, - @ApiModelProperty("事件信息") - val eventMessage: String, @ApiModelProperty("事件描述") val eventDesc: String, - @ApiModelProperty("事件时间") + @ApiModelProperty("webhook事件请求ID") + val hookRequestId: Long?, + @ApiModelProperty("事件请求参数, 记录手动/openapi/定时/远程触发启动参数") + val requestParams: Map? = null, + @ApiModelProperty("触发事件") val eventTime: LocalDateTime, - @ApiModelProperty("触发状态") - var status: String, - @ApiModelProperty("流水线Id") - var pipelineId: String? = null, - @ApiModelProperty("流水线名称") - var pipelineName: String? = null, - @ApiModelProperty("构建Id") - var buildId: String? = null, - @ApiModelProperty("构建编号") - var buildNum: String? = null, - @ApiModelProperty("原因") - var reason: String? = null, - @ApiModelProperty("原因详情", required = false) - var reasonDetailList: List? = null, - @ApiModelProperty("创建时间", required = false) - val createTime: Long? = null ) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventBuilder.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventBuilder.kt index 64ae831e4b1..e7a1a574fe3 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventBuilder.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventBuilder.kt @@ -28,18 +28,9 @@ package com.tencent.devops.process.pojo.trigger -import com.tencent.devops.process.pojo.webhook.PipelineWebhookEvent -import java.time.LocalDateTime - class PipelineTriggerEventBuilder { private lateinit var projectId: String private var eventId: Long? = null - private lateinit var triggerType: String - private lateinit var eventType: String - private lateinit var triggerUser: String - private lateinit var eventMessage: String - private lateinit var eventDesc: String - private lateinit var eventTime: LocalDateTime private var eventSource: String? = null private var status: String = "" private var pipelineId: String? = null @@ -49,20 +40,14 @@ class PipelineTriggerEventBuilder { private var reason: String? = null private var reasonDetailList: MutableList? = null - fun webhookEvent(webhookEvent: PipelineWebhookEvent) = apply { - this.eventId = webhookEvent.eventId - this.eventType = webhookEvent.eventType - this.triggerUser = webhookEvent.triggerUser - this.eventMessage = webhookEvent.eventMessage - this.eventDesc = webhookEvent.eventDesc - this.eventTime = webhookEvent.eventTime - this.triggerType = webhookEvent.triggerType - } - fun projectId(projectId: String) = apply { this.projectId = projectId } + fun eventId(eventId: Long) = apply { + this.eventId = eventId + } + fun pipelineId(pipelineId: String) = apply { this.pipelineId = pipelineId } @@ -77,6 +62,10 @@ class PipelineTriggerEventBuilder { fun getEventSource() = eventSource + fun status(status: String) = apply { + this.status = status + } + fun buildId(buildId: String) = apply { this.buildId = buildId } @@ -93,17 +82,10 @@ class PipelineTriggerEventBuilder { } } - fun build(): PipelineTriggerEvent { - return PipelineTriggerEvent( + fun build(): PipelineTriggerDetail { + return PipelineTriggerDetail( projectId = projectId, eventId = eventId!!, - triggerType = triggerType, - eventSource = eventSource, - eventType = eventType, - triggerUser = triggerUser, - eventMessage = eventMessage, - eventDesc = eventDesc, - eventTime = eventTime, status = status, pipelineId = pipelineId, pipelineName = pipelineName, diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhookEvent.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventVo.kt similarity index 66% rename from src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhookEvent.kt rename to src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventVo.kt index f399aa3723d..beb9eb11394 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhookEvent.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventVo.kt @@ -26,34 +26,41 @@ * */ -package com.tencent.devops.process.pojo.webhook +package com.tencent.devops.process.pojo.trigger -import io.swagger.annotations.ApiModel import io.swagger.annotations.ApiModelProperty -import java.time.LocalDateTime -@ApiModel("流水线webhook事件") -data class PipelineWebhookEvent( - @ApiModelProperty("事件处理类") - val taskAtom: String, - @ApiModelProperty("事件请求ID") - val requestId: Long, +data class PipelineTriggerEventVo( + @ApiModelProperty("事件明细ID") + var detailId: Long, + @ApiModelProperty("蓝盾项目ID") + val projectId: String, @ApiModelProperty("事件ID") val eventId: Long, @ApiModelProperty("触发类型") val triggerType: String, + @ApiModelProperty("事件触发源,代码库触发-代码库ID", required = false) + val eventSource: String? = "", @ApiModelProperty("事件类型") val eventType: String, @ApiModelProperty("触发人") val triggerUser: String, - @ApiModelProperty("事件信息") - val eventMessage: String, @ApiModelProperty("事件描述") val eventDesc: String, - @ApiModelProperty("触发事件") - val eventTime: LocalDateTime, - @ApiModelProperty("项目ID") - var projectId: String? = null, - @ApiModelProperty("事件源", required = false) - var eventSource: String? = null, + @ApiModelProperty("事件时间") + val eventTime: Long, + @ApiModelProperty("触发状态") + var status: String, + @ApiModelProperty("流水线Id") + var pipelineId: String? = null, + @ApiModelProperty("流水线名称") + var pipelineName: String? = null, + @ApiModelProperty("构建Id") + var buildId: String? = null, + @ApiModelProperty("构建编号") + var buildNum: String? = null, + @ApiModelProperty("原因") + var reason: String? = null, + @ApiModelProperty("原因详情", required = false) + var reasonDetailList: List? = null ) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/RepoWebhookEvent.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/RepoTriggerEventVo.kt similarity index 96% rename from src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/RepoWebhookEvent.kt rename to src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/RepoTriggerEventVo.kt index 350af4c02df..1a6304f2693 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/RepoWebhookEvent.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/RepoTriggerEventVo.kt @@ -26,13 +26,13 @@ * */ -package com.tencent.devops.process.pojo.webhook +package com.tencent.devops.process.pojo.trigger import io.swagger.annotations.ApiModel import io.swagger.annotations.ApiModelProperty @ApiModel("代码库webhook事件记录") -data class RepoWebhookEvent( +data class RepoTriggerEventVo( @ApiModelProperty("项目ID") val projectId: String, @ApiModelProperty("事件ID") diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt index bfc83cca320..d6522da2930 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt @@ -32,8 +32,8 @@ import com.tencent.devops.common.api.model.SQLPage import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.common.web.RestResource import com.tencent.devops.process.api.user.UserPipelineTriggerEventResource -import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent -import com.tencent.devops.process.pojo.webhook.RepoWebhookEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventVo +import com.tencent.devops.process.pojo.trigger.RepoTriggerEventVo import com.tencent.devops.process.service.trigger.PipelineTriggerEventService @RestResource @@ -51,7 +51,7 @@ class UserPipelineTriggerEventResourceImpl( endTime: Long?, page: Int?, pageSize: Int? - ): Result> { + ): Result> { return Result( pipelineTriggerEventService.listTriggerEvent( projectId = projectId, @@ -80,9 +80,9 @@ class UserPipelineTriggerEventResourceImpl( endTime: Long?, page: Int?, pageSize: Int? - ): Result> { + ): Result> { return Result( - pipelineTriggerEventService.listRepoWebhookEvent( + pipelineTriggerEventService.listRepoTriggerEvent( projectId = projectId, repoHashId = repoHashId, triggerType = triggerType, @@ -106,9 +106,9 @@ class UserPipelineTriggerEventResourceImpl( pipelineId: String, page: Int?, pageSize: Int? - ): Result> { + ): Result> { return Result( - pipelineTriggerEventService.listRepoWebhookEventDetail( + pipelineTriggerEventService.listRepoTriggerEventDetail( projectId = projectId, repoHashId = repoHashId, eventId = eventId, @@ -119,12 +119,15 @@ class UserPipelineTriggerEventResourceImpl( ) } - override fun replay(userId: String, projectId: String, id: Long): Result { + override fun replay( + userId: String, + projectId: String, detailId: Long + ): Result { return Result( pipelineTriggerEventService.replay( userId = userId, projectId = projectId, - id = id + detailId = detailId ) ) } @@ -132,14 +135,12 @@ class UserPipelineTriggerEventResourceImpl( override fun replayAll( userId: String, projectId: String, - repoHashId: String, eventId: Long ): Result { return Result( pipelineTriggerEventService.replayAll( userId = userId, projectId = projectId, - repoHashId = repoHashId, eventId = eventId ) ) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index 237b387b26c..61c8b6a55db 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -31,14 +31,19 @@ import com.fasterxml.jackson.core.type.TypeReference import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.timestamp import com.tencent.devops.common.api.util.timestampmilli +import com.tencent.devops.model.process.tables.TPipelineTriggerDetail import com.tencent.devops.model.process.tables.TPipelineTriggerEvent +import com.tencent.devops.model.process.tables.records.TPipelineTriggerDetailRecord import com.tencent.devops.model.process.tables.records.TPipelineTriggerEventRecord +import com.tencent.devops.process.pojo.trigger.PipelineTriggerDetail import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventVo import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus -import com.tencent.devops.process.pojo.webhook.RepoWebhookEvent +import com.tencent.devops.process.pojo.trigger.RepoTriggerEventVo import org.jooq.Condition import org.jooq.DSLContext import org.jooq.Result +import org.jooq.impl.DSL import org.jooq.impl.DSL.count import org.jooq.impl.DSL.`when` import org.springframework.stereotype.Repository @@ -48,48 +53,70 @@ import java.time.LocalDateTime @Suppress("ALL") @Repository class PipelineTriggerEventDao { + fun save( dslContext: DSLContext, triggerEvent: PipelineTriggerEvent ) { with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { - dslContext.insertInto(this).columns( - ID, + dslContext.insertInto( + this, + ).values( PROJECT_ID, EVENT_ID, TRIGGER_TYPE, EVENT_SOURCE, EVENT_TYPE, TRIGGER_USER, - EVENT_MESSAGE, EVENT_DESC, + HOOK_REQUEST_ID, + REQUEST_PARAMS, EVENT_TIME, - STATUS, - PIPELINE_ID, - PIPELINE_NAME, - BUILD_ID, - BUILD_NUM, - REASON, - REASON_DETAIL, - CREATE_TIME ).values( - triggerEvent.id!!, + triggerEvent.eventId, triggerEvent.projectId, triggerEvent.eventId, triggerEvent.triggerType, triggerEvent.eventSource, triggerEvent.eventType, triggerEvent.triggerUser, - triggerEvent.eventMessage, triggerEvent.eventDesc, + triggerEvent.hookRequestId, + triggerEvent.requestParams, triggerEvent.eventTime, - triggerEvent.status, - triggerEvent.pipelineId, - triggerEvent.pipelineName, - triggerEvent.buildId, - triggerEvent.buildNum, - triggerEvent.reason, - triggerEvent.reasonDetailList?.let { + ).onDuplicateKeyIgnore().execute() + } + } + + fun saveDetail( + dslContext: DSLContext, + triggerDetail: PipelineTriggerDetail + ) { + with(TPipelineTriggerDetail.T_PIPELINE_TRIGGER_DETAIL) { + dslContext.insertInto( + this, + DETAIL_ID, + PROJECT_ID, + EVENT_ID, + STATUS, + PIPELINE_ID, + PIPELINE_NAME, + BUILD_ID, + BUILD_NUM, + REASON, + REASON_DETAIL, + CREATE_TIME + ).values( + triggerDetail.detailId!!, + triggerDetail.projectId, + triggerDetail.eventId, + triggerDetail.status, + triggerDetail.pipelineId, + triggerDetail.pipelineName, + triggerDetail.buildId, + triggerDetail.buildNum, + triggerDetail.reason, + triggerDetail.reasonDetailList?.let { JsonUtil.toJson(it) }, LocalDateTime.now() @@ -110,26 +137,65 @@ class PipelineTriggerEventDao { endTime: Long? = null, limit: Int, offset: Int - ): Result { - with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { - val conditions = buildConditions( - projectId = projectId, - eventSource = eventSource, - eventId = eventId, - eventType = eventType, - triggerUser = triggerUser, - triggerType = triggerType, - pipelineId = pipelineId, - startTime = startTime, - endTime = endTime - ) - return dslContext.selectFrom(this) - .where(conditions) - .orderBy(EVENT_TIME.desc()) - .limit(limit) - .offset(offset) - .fetch() - } + ): List { + val t1 = TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT.`as`("t1") + val t2 = TPipelineTriggerDetail.T_PIPELINE_TRIGGER_DETAIL.`as`("t2") + val conditions = buildConditions( + t1 = t1, + t2 = t2, + projectId = projectId, + eventSource = eventSource, + eventId = eventId, + eventType = eventType, + triggerUser = triggerUser, + triggerType = triggerType, + pipelineId = pipelineId, + startTime = startTime, + endTime = endTime + ) + return dslContext.select( + t2.DETAIL_ID, + t1.PROJECT_ID, + t1.EVENT_ID, + t1.TRIGGER_TYPE, + t1.EVENT_SOURCE, + t1.EVENT_TYPE, + t1.TRIGGER_USER, + t1.EVENT_DESC, + t1.EVENT_TIME, + t2.STATUS, + t2.PIPELINE_ID, + t2.PIPELINE_NAME, + t2.BUILD_ID, + t2.BUILD_NUM, + t2.REASON, + t2.REASON_DETAIL + ).from(t1).leftJoin(t2) + .on(t1.EVENT_ID.eq(t2.EVENT_ID)).and(t1.PROJECT_ID.eq(t2.PROJECT_ID)) + .where(conditions) + .orderBy(t1.EVENT_TIME.desc()).limit(limit) + .offset(offset) + .fetch().map { + PipelineTriggerEventVo( + detailId = it.value1(), + projectId = it.value2(), + eventId = it.value3(), + triggerType = it.value4(), + eventSource = it.value5(), + eventType = it.value6(), + triggerUser = it.value7(), + eventDesc = it.value8(), + eventTime = it.value9().timestampmilli(), + status = it.value10(), + pipelineId = it.value11(), + pipelineName = it.value12(), + buildId = it.value13(), + buildNum = it.value14(), + reason = it.value15(), + reasonDetailList = it.value16() + ?.let { r -> JsonUtil.to(r, object : TypeReference>() {}) } + ) + } } fun countTriggerEvent( @@ -144,20 +210,25 @@ class PipelineTriggerEventDao { startTime: Long? = null, endTime: Long? = null ): Long { - return with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { - val conditions = buildConditions( - projectId = projectId, - eventSource = eventSource, - eventId = eventId, - eventType = eventType, - triggerUser = triggerUser, - triggerType = triggerType, - pipelineId = pipelineId - ) - dslContext.selectCount().from(this) - .where(conditions) - .fetchOne(0, Long::class.java)!! - } + val t1 = TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT.`as`("t1") + val t2 = TPipelineTriggerDetail.T_PIPELINE_TRIGGER_DETAIL.`as`("t2") + val conditions = buildConditions( + t1 = t1, + t2 = t2, + projectId = projectId, + eventSource = eventSource, + eventId = eventId, + eventType = eventType, + triggerUser = triggerUser, + triggerType = triggerType, + pipelineId = pipelineId, + startTime = startTime, + endTime = endTime + ) + return dslContext.selectCount().from(t1).leftJoin(t2) + .on(t1.EVENT_ID.eq(t2.EVENT_ID)).and(t1.PROJECT_ID.eq(t2.PROJECT_ID)) + .where(conditions) + .fetchOne(0, Long::class.java)!! } fun listByEventIds( @@ -171,7 +242,7 @@ class PipelineTriggerEventDao { } } - fun listRepoWebhookEvent( + fun listRepoTriggerEvent( dslContext: DSLContext, projectId: String, eventSource: String? = null, @@ -184,47 +255,51 @@ class PipelineTriggerEventDao { endTime: Long? = null, limit: Int, offset: Int - ): List { - return with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { - val conditions = buildConditions( - projectId = projectId, - eventSource = eventSource, - eventId = eventId, - eventType = eventType, - triggerUser = triggerUser, - triggerType = triggerType, - pipelineId = pipelineId - ) - dslContext.select( - PROJECT_ID, - EVENT_ID, - EVENT_SOURCE, - EVENT_DESC, - EVENT_TIME, - count().`as`("total"), - count(`when`(STATUS.eq(PipelineTriggerStatus.SUCCEED.name), 1)).`as`("success ") - ) - .from(this) - .where(conditions) - .groupBy(PROJECT_ID, EVENT_ID, EVENT_SOURCE, EVENT_DESC, EVENT_TIME) - .orderBy(EVENT_TIME.desc()) - .limit(limit) - .offset(offset) - .fetch().map { - RepoWebhookEvent( - projectId = it.value1(), - eventId = it.value2(), - repoHashId = it.value3(), - eventDesc = it.value4(), - eventTime = it.value5().timestampmilli(), - total = it.value6(), - success = it.value7() - ) - } - } + ): List { + val t1 = TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT.`as`("t1") + val t2 = TPipelineTriggerDetail.T_PIPELINE_TRIGGER_DETAIL.`as`("t2") + val conditions = buildConditions( + t1 = t1, + t2 = t2, + projectId = projectId, + eventSource = eventSource, + eventId = eventId, + eventType = eventType, + triggerUser = triggerUser, + triggerType = triggerType, + pipelineId = pipelineId, + startTime = startTime, + endTime = endTime + ) + return dslContext.select( + t1.PROJECT_ID, + t1.EVENT_ID, + t1.EVENT_SOURCE, + t1.EVENT_DESC, + t1.EVENT_TIME, + count().`as`("total"), + count(`when`(t2.STATUS.eq(PipelineTriggerStatus.SUCCEED.name), 1)).`as`("success ") + ).from(t1).leftJoin(t2) + .on(t1.EVENT_ID.eq(t2.EVENT_ID)).and(t1.PROJECT_ID.eq(t2.PROJECT_ID)) + .where(conditions) + .groupBy(t1.PROJECT_ID, t1.EVENT_ID, t1.EVENT_SOURCE, t1.EVENT_DESC, t1.EVENT_TIME) + .orderBy(t1.EVENT_TIME.desc()) + .limit(limit) + .offset(offset) + .fetch().map { + RepoTriggerEventVo( + projectId = it.value1(), + eventId = it.value2(), + repoHashId = it.value3(), + eventDesc = it.value4(), + eventTime = it.value5().timestampmilli(), + total = it.value6(), + success = it.value7() + ) + } } - fun countRepoWebhookEvent( + fun countRepoTriggerEvent( dslContext: DSLContext, projectId: String, eventSource: String? = null, @@ -236,34 +311,60 @@ class PipelineTriggerEventDao { startTime: Long? = null, endTime: Long? = null ): Long { - return with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { - val conditions = buildConditions( - projectId = projectId, - eventSource = eventSource, - eventId = eventId, - eventType = eventType, - triggerUser = triggerUser, - triggerType = triggerType, - pipelineId = pipelineId - ) - dslContext.selectCount().from(this) - .where(conditions) - .groupBy(PROJECT_ID, EVENT_ID, EVENT_SOURCE, EVENT_DESC, EVENT_TIME) - .fetchOne(0, Long::class.java)!! - } + val t1 = TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT.`as`("t1") + val t2 = TPipelineTriggerDetail.T_PIPELINE_TRIGGER_DETAIL.`as`("t2") + val conditions = buildConditions( + t1 = t1, + t2 = t2, + projectId = projectId, + eventSource = eventSource, + eventId = eventId, + eventType = eventType, + triggerUser = triggerUser, + triggerType = triggerType, + pipelineId = pipelineId, + startTime = startTime, + endTime = endTime + ) + return dslContext.select(DSL.countDistinct(t1.PROJECT_ID, t1.EVENT_ID, t1.EVENT_SOURCE)) + .from(t1) + .leftJoin(t2) + .on(t1.EVENT_ID.eq(t2.EVENT_ID)).and(t1.PROJECT_ID.eq(t2.PROJECT_ID)) + .where(conditions) + .fetchOne(0, Long::class.java)!! } - fun get( + fun getTriggerEvent( dslContext: DSLContext, - id: Long + projectId: String, + eventId: Long ): PipelineTriggerEvent? { val record = with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { - dslContext.selectFrom(this).where(ID.eq(id)).fetchOne() + dslContext.selectFrom(this) + .where(EVENT_ID.eq(eventId)) + .and(PROJECT_ID.eq(projectId)) + .fetchOne() } - return record?.let { convert(it) } + return record?.let { convertEvent(it) } } - private fun TPipelineTriggerEvent.buildConditions( + fun getTriggerDetail( + dslContext: DSLContext, + projectId: String, + detailId: Long + ): PipelineTriggerDetail? { + val record = with(TPipelineTriggerDetail.T_PIPELINE_TRIGGER_DETAIL) { + dslContext.selectFrom(this) + .where(DETAIL_ID.eq(detailId)) + .and(PROJECT_ID.eq(projectId)) + .fetchOne() + } + return record?.let { convertDetail(it) } + } + + private fun buildConditions( + t1: TPipelineTriggerEvent, + t2: TPipelineTriggerDetail, projectId: String, eventSource: String? = null, eventId: Long? = null, @@ -275,36 +376,36 @@ class PipelineTriggerEventDao { endTime: Long? = null ): List { val conditions = mutableListOf() - conditions.add(PROJECT_ID.eq(projectId)) + conditions.add(t1.PROJECT_ID.eq(projectId)) if (!eventSource.isNullOrBlank()) { - conditions.add(EVENT_SOURCE.eq(eventSource)) + conditions.add(t1.EVENT_SOURCE.eq(eventSource)) } if (eventId != null) { - conditions.add(EVENT_ID.eq(eventId)) + conditions.add(t1.EVENT_ID.eq(eventId)) } if (!eventType.isNullOrBlank()) { - conditions.add(EVENT_TYPE.eq(eventType)) + conditions.add(t1.EVENT_TYPE.eq(eventType)) } if (!triggerUser.isNullOrBlank()) { - conditions.add(TRIGGER_USER.eq(triggerUser)) + conditions.add(t1.TRIGGER_USER.eq(triggerUser)) } if (!triggerType.isNullOrBlank()) { - conditions.add(TRIGGER_TYPE.eq(triggerType)) + conditions.add(t1.TRIGGER_TYPE.eq(triggerType)) } if (!pipelineId.isNullOrBlank()) { - conditions.add(PIPELINE_ID.eq(pipelineId)) + conditions.add(t2.PIPELINE_ID.eq(pipelineId)) } if (startTime != null && startTime > 0) { - conditions.add(CREATE_TIME.ge(Timestamp(startTime).toLocalDateTime())) + conditions.add(t1.EVENT_TIME.ge(Timestamp(startTime).toLocalDateTime())) } if (endTime != null && endTime > 0) { - conditions.add(CREATE_TIME.le(Timestamp(endTime).toLocalDateTime())) + conditions.add(t1.EVENT_TIME.le(Timestamp(endTime).toLocalDateTime())) } return conditions } - fun convert(record: TPipelineTriggerEventRecord): PipelineTriggerEvent { - return with (record) { + fun convertEvent(record: TPipelineTriggerEventRecord): PipelineTriggerEvent { + return with(record) { PipelineTriggerEvent( projectId = projectId, eventId = eventId, @@ -312,16 +413,31 @@ class PipelineTriggerEventDao { triggerType = triggerType, triggerUser = triggerUser, eventType = eventType, - eventMessage = eventMessage, eventDesc = eventDesc, - eventTime = eventTime, + hookRequestId = hookRequestId, + requestParams = requestParams?.let { + JsonUtil.to( + it, + object : TypeReference>() {}) + }, + eventTime = eventTime + ) + } + } + + fun convertDetail(record: TPipelineTriggerDetailRecord): PipelineTriggerDetail { + return with(record) { + PipelineTriggerDetail( + detailId = detailId, + projectId = projectId, + eventId = eventId, status = status, pipelineId = pipelineId, pipelineName = pipelineName, buildId = buildId, buildNum = buildNum, reason = reason, - reasonDetailList = JsonUtil.to(reasonDetail, object: TypeReference>(){}), + reasonDetailList = reasonDetail?.let { JsonUtil.to(it, object : TypeReference>() {}) }, createTime = createTime.timestamp() ) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineWebhookEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineWebhookEventDao.kt deleted file mode 100644 index 9248c5c3523..00000000000 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineWebhookEventDao.kt +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.tencent.devops.process.dao - -import com.tencent.devops.model.process.tables.TPipelineWebhookEvent -import com.tencent.devops.model.process.tables.records.TPipelineWebhookEventRecord -import com.tencent.devops.process.pojo.webhook.PipelineWebhookEvent -import org.jooq.Condition -import org.jooq.DSLContext -import org.springframework.stereotype.Repository -import java.sql.Timestamp - -@Repository -class PipelineWebhookEventDao { - - fun save(dslContext: DSLContext, webhookEvent: PipelineWebhookEvent) { - with(TPipelineWebhookEvent.T_PIPELINE_WEBHOOK_EVENT) { - dslContext.insertInto(this).columns( - PROJECT_ID, - REQUEST_ID, - EVENT_ID, - TRIGGER_TYPE, - EVENT_SOURCE, - EVENT_TYPE, - TRIGGER_USER, - EVENT_MESSAGE, - EVENT_DESC, - EVENT_TIME, - TASK_ATOM - ).values( - webhookEvent.projectId, - webhookEvent.requestId, - webhookEvent.eventId, - webhookEvent.triggerType, - webhookEvent.eventSource!!, - webhookEvent.eventType, - webhookEvent.triggerUser, - webhookEvent.eventMessage, - webhookEvent.eventDesc, - webhookEvent.eventTime, - webhookEvent.taskAtom - ).onDuplicateKeyIgnore().execute() - } - } - - fun list( - dslContext: DSLContext, - projectId: String, - eventSource: String, - triggerType: String?, - eventType: String?, - triggerUser: String?, - startTime: Long?, - endTime: Long?, - limit: Int, - offset: Int - ): List { - return with(TPipelineWebhookEvent.T_PIPELINE_WEBHOOK_EVENT) { - val conditions = buildConditions( - projectId = projectId, - eventSource = eventSource, - triggerType = triggerType, - triggerUser = triggerUser, - eventType = eventType, - startTime = startTime, - endTime = endTime - ) - dslContext.selectFrom(this) - .where(conditions) - .limit(limit) - .offset(offset) - .fetch { - convert(it) - } - } - } - - fun count( - dslContext: DSLContext, - projectId: String, - eventSource: String, - triggerType: String?, - eventType: String?, - triggerUser: String?, - startTime: Long?, - endTime: Long?, - ): Long { - return with(TPipelineWebhookEvent.T_PIPELINE_WEBHOOK_EVENT) { - val conditions = buildConditions( - projectId = projectId, - eventSource = eventSource, - triggerType = triggerType, - triggerUser = triggerUser, - eventType = eventType, - startTime = startTime, - endTime = endTime - ) - dslContext.selectCount() - .from(this) - .where(conditions) - .fetchOne(0, Long::class.java)!! - } - } - - fun get( - dslContext: DSLContext, - eventId: Long, - eventSource: String - ): PipelineWebhookEvent? { - val record = with(TPipelineWebhookEvent.T_PIPELINE_WEBHOOK_EVENT) { - dslContext.selectFrom(this) - .where(EVENT_ID.eq(eventId)) - .and(EVENT_SOURCE.eq(eventSource)) - .fetchOne() - } - return record?.let { convert(it) } - } - - private fun TPipelineWebhookEvent.buildConditions( - projectId: String, - eventSource: String? = null, - eventId: Long? = null, - eventType: String? = null, - triggerUser: String? = null, - triggerType: String? = null, - startTime: Long? = null, - endTime: Long? = null - ): List { - val conditions = mutableListOf() - conditions.add(PROJECT_ID.eq(projectId)) - if (!eventSource.isNullOrBlank()) { - conditions.add(EVENT_SOURCE.eq(eventSource)) - } - if (eventId != null) { - conditions.add(EVENT_ID.eq(eventId)) - } - if (!eventType.isNullOrBlank()) { - conditions.add(EVENT_TYPE.eq(eventType)) - } - if (!triggerUser.isNullOrBlank()) { - conditions.add(TRIGGER_USER.eq(triggerUser)) - } - if (!triggerType.isNullOrBlank()) { - conditions.add(TRIGGER_TYPE.eq(triggerType)) - } - if (startTime != null && startTime > 0) { - conditions.add(EVENT_TIME.ge(Timestamp(startTime).toLocalDateTime())) - } - if (endTime != null && endTime > 0) { - conditions.add(EVENT_TIME.le(Timestamp(endTime).toLocalDateTime())) - } - return conditions - } - - fun convert(record: TPipelineWebhookEventRecord): PipelineWebhookEvent { - return with(record) { - PipelineWebhookEvent( - projectId = projectId, - requestId = requestId, - eventId = eventId, - triggerType = triggerType, - eventSource = eventSource, - eventType = eventType, - triggerUser = triggerUser, - eventMessage = eventMessage, - eventDesc = eventDesc, - eventTime = eventTime, - taskAtom = taskAtom - ) - } - } -} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt index a3d21f647fa..ca74aa92c8b 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt @@ -28,17 +28,19 @@ package com.tencent.devops.process.service.trigger +import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.api.exception.ParamBlankException import com.tencent.devops.common.api.model.SQLPage import com.tencent.devops.common.api.util.PageUtil import com.tencent.devops.common.client.Client -import com.tencent.devops.common.webhook.pojo.ReplayWebhookRequest +import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_TRIGGER_DETAIL_NOT_FOUND +import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_TRIGGER_REPLAY_PIPELINE_NOT_EMPTY import com.tencent.devops.process.dao.PipelineTriggerEventDao -import com.tencent.devops.process.dao.PipelineWebhookEventDao +import com.tencent.devops.process.pojo.trigger.PipelineTriggerDetail import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent -import com.tencent.devops.process.pojo.webhook.PipelineWebhookEvent -import com.tencent.devops.process.pojo.webhook.RepoWebhookEvent -import com.tencent.devops.process.webhook.listener.WebhookRequestService +import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventVo +import com.tencent.devops.process.pojo.trigger.RepoTriggerEventVo +import com.tencent.devops.process.webhook.listener.PipelineTriggerRequestService import com.tencent.devops.project.api.service.ServiceAllocIdResource import org.jooq.DSLContext import org.jooq.impl.DSL @@ -52,39 +54,38 @@ class PipelineTriggerEventService @Autowired constructor( private val dslContext: DSLContext, private val client: Client, private val pipelineTriggerEventDao: PipelineTriggerEventDao, - private val pipelineWebhookEventDao: PipelineWebhookEventDao, - private val webhookRequestService: WebhookRequestService + private val pipelineTriggerRequestService: PipelineTriggerRequestService ) { companion object { private val logger = LoggerFactory.getLogger(PipelineTriggerEventService::class.java) - private const val PIPELINE_WEBHOOK_EVENT_BIZ_ID = "PIPELINE_WEBHOOK_EVENT" private const val PIPELINE_TRIGGER_EVENT_BIZ_ID = "PIPELINE_TRIGGER_EVENT" + private const val PIPELINE_TRIGGER_DETAIL_BIZ_ID = "PIPELINE_TRIGGER_DETAIL" } - fun getWebhookEventId(): Long { - return client.get(ServiceAllocIdResource::class).generateSegmentId(PIPELINE_WEBHOOK_EVENT_BIZ_ID).data ?: 0 + fun getDetailId(): Long { + return client.get(ServiceAllocIdResource::class).generateSegmentId(PIPELINE_TRIGGER_DETAIL_BIZ_ID).data ?: 0 } - fun getTriggerEventId(): Long { + fun getEventId(): Long { return client.get(ServiceAllocIdResource::class).generateSegmentId(PIPELINE_TRIGGER_EVENT_BIZ_ID).data ?: 0 } fun saveEvent( - webhookEvent: PipelineWebhookEvent, - triggerEvent: PipelineTriggerEvent + triggerEvent: PipelineTriggerEvent, + triggerDetail: PipelineTriggerDetail ) { - triggerEvent.id = getTriggerEventId() + triggerDetail.detailId = getDetailId() dslContext.transaction { configuration -> val transactionContext = DSL.using(configuration) - pipelineWebhookEventDao.save( - dslContext = transactionContext, - webhookEvent = webhookEvent - ) pipelineTriggerEventDao.save( dslContext = transactionContext, triggerEvent = triggerEvent ) + pipelineTriggerEventDao.saveDetail( + dslContext = transactionContext, + triggerDetail = triggerDetail + ) } } @@ -98,7 +99,7 @@ class PipelineTriggerEventService @Autowired constructor( endTime: Long?, page: Int?, pageSize: Int? - ): SQLPage { + ): SQLPage { val pageNotNull = page ?: 0 val pageSizeNotNull = pageSize ?: PageUtil.MAX_PAGE_SIZE val sqlLimit = PageUtil.convertPageSizeToSQLMAXLimit(pageNotNull, pageSizeNotNull) @@ -123,11 +124,11 @@ class PipelineTriggerEventService @Autowired constructor( endTime = endTime, limit = sqlLimit.limit, offset = sqlLimit.offset - ).map { pipelineTriggerEventDao.convert(it) } + ) return SQLPage(count = count, records = records) } - fun listRepoWebhookEvent( + fun listRepoTriggerEvent( projectId: String, repoHashId: String, triggerType: String?, @@ -139,11 +140,11 @@ class PipelineTriggerEventService @Autowired constructor( endTime: Long?, page: Int?, pageSize: Int? - ): SQLPage { + ): SQLPage { val pageNotNull = page ?: 0 val pageSizeNotNull = pageSize ?: PageUtil.MAX_PAGE_SIZE val sqlLimit = PageUtil.convertPageSizeToSQLMAXLimit(pageNotNull, pageSizeNotNull) - val count = pipelineTriggerEventDao.countRepoWebhookEvent( + val count = pipelineTriggerEventDao.countRepoTriggerEvent( dslContext = dslContext, projectId = projectId, eventSource = repoHashId, @@ -155,7 +156,7 @@ class PipelineTriggerEventService @Autowired constructor( startTime = startTime, endTime = endTime ) - val records = pipelineTriggerEventDao.listRepoWebhookEvent( + val records = pipelineTriggerEventDao.listRepoTriggerEvent( dslContext = dslContext, projectId = projectId, eventSource = repoHashId, @@ -172,14 +173,14 @@ class PipelineTriggerEventService @Autowired constructor( return SQLPage(count = count, records = records) } - fun listRepoWebhookEventDetail( + fun listRepoTriggerEventDetail( projectId: String, repoHashId: String, eventId: Long, pipelineId: String?, page: Int?, pageSize: Int? - ): SQLPage { + ): SQLPage { if (projectId.isBlank()) { throw ParamBlankException("Invalid projectId") } @@ -197,9 +198,7 @@ class PipelineTriggerEventService @Autowired constructor( pipelineId = pipelineId, limit = sqlLimit.limit, offset = sqlLimit.offset - ).map { - pipelineTriggerEventDao.convert(it) - } + ) val count = pipelineTriggerEventDao.countTriggerEvent( dslContext = dslContext, projectId = projectId, @@ -213,55 +212,41 @@ class PipelineTriggerEventService @Autowired constructor( fun replay( userId: String, projectId: String, - id: Long + detailId: Long ): Boolean { - val pipelineTriggerEvent = pipelineTriggerEventDao.get(dslContext = dslContext, id = id) ?: return false - val eventId = pipelineTriggerEvent.eventId - val repoHashId = pipelineTriggerEvent.eventSource!! - val webhookEvent = pipelineWebhookEventDao.get( + logger.info("replay pipeline trigger event|$userId|$projectId|$detailId") + val triggerDetail = pipelineTriggerEventDao.getTriggerDetail( dslContext = dslContext, - eventId = eventId, - eventSource = repoHashId - ) ?: return false - - val replayWebhookRequest = with(webhookEvent) { - ReplayWebhookRequest( - taskAtom = webhookEvent.taskAtom, - userId = userId, - projectId = projectId, - eventId = webhookEvent.eventId, - requestId = requestId, - eventSource = eventSource!!, - pipelineId = pipelineTriggerEvent.pipelineId!! - ) - } - webhookRequestService.handleReplayRequest(request = replayWebhookRequest) + projectId = projectId, + detailId = detailId + ) ?: throw ErrorCodeException( + errorCode = ERROR_TRIGGER_DETAIL_NOT_FOUND, + params = arrayOf(detailId.toString()) + ) + val pipelineId = triggerDetail.pipelineId ?: throw ErrorCodeException( + errorCode = ERROR_TRIGGER_REPLAY_PIPELINE_NOT_EMPTY, + params = arrayOf(detailId.toString()) + ) + pipelineTriggerRequestService.handleReplayRequest( + userId = userId, + projectId = projectId, + eventId = triggerDetail.eventId, + pipelineId = pipelineId + ) return true } fun replayAll( userId: String, projectId: String, - repoHashId: String, eventId: Long ): Boolean { - val webhookEvent = pipelineWebhookEventDao.get( - dslContext = dslContext, - eventId = eventId, - eventSource = repoHashId - ) ?: return false - - val replayWebhookRequest = with(webhookEvent) { - ReplayWebhookRequest( - taskAtom = taskAtom, - userId = userId, - projectId = projectId, - eventId = eventId, - requestId = requestId, - eventSource = repoHashId - ) - } - webhookRequestService.handleReplayRequest(request = replayWebhookRequest) + logger.info("replay all pipeline trigger event|$userId|$projectId|$eventId") + pipelineTriggerRequestService.handleReplayRequest( + userId = userId, + projectId = projectId, + eventId = eventId + ) return true } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt index 43dcb891d71..6f822fd3e7f 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt @@ -48,9 +48,10 @@ import com.tencent.devops.process.engine.service.WebhookBuildParameterService import com.tencent.devops.process.engine.service.code.GitWebhookUnlockDispatcher import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder import com.tencent.devops.process.pojo.code.WebhookCommit +import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventBuilder import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason -import com.tencent.devops.process.pojo.webhook.PipelineWebhookEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber import com.tencent.devops.process.service.builds.PipelineBuildCommitService import com.tencent.devops.process.service.pipeline.PipelineBuildService @@ -100,7 +101,7 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { fun dispatchPipelineSubscribers( matcher: ScmWebhookMatcher, - webhookEvent: PipelineWebhookEvent, + triggerEvent: PipelineTriggerEvent, subscribers: List ): Boolean { try { @@ -112,13 +113,14 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { } EventCacheUtil.initEventCache() + // 代码库触发的事件ID,一个代码库会触发多条流水线,但应该只有一条触发事件 + val repoEventIdMap = mutableMapOf() subscribers.forEach outside@{ subscriber -> val projectId = subscriber.projectId val pipelineId = subscriber.pipelineId try { logger.info("pipelineId is $pipelineId") val builder = PipelineTriggerEventBuilder() - .webhookEvent(webhookEvent) .projectId(projectId) .pipelineId(pipelineId) @@ -128,14 +130,12 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { matcher = matcher, builder = builder ) - if (!builder.getEventSource().isNullOrBlank()) { - webhookEvent.eventSource = builder.getEventSource() - webhookEvent.projectId = projectId - pipelineTriggerEventService.saveEvent( - webhookEvent = webhookEvent, - triggerEvent = builder.build() - ) - } + saveTriggerEvent( + projectId = projectId, + builder = builder, + triggerEvent = triggerEvent, + repoEventIdMap = repoEventIdMap + ) } catch (e: Throwable) { logger.warn("[$pipelineId]|webhookTriggerPipelineBuild fail: $e", e) } @@ -159,6 +159,29 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { } } + private fun saveTriggerEvent( + projectId: String, + builder: PipelineTriggerEventBuilder, + triggerEvent: PipelineTriggerEvent, + repoEventIdMap: MutableMap + ) { + if (!builder.getEventSource().isNullOrBlank()) { + triggerEvent.eventSource = builder.getEventSource() + triggerEvent.projectId = projectId + val eventId = repoEventIdMap[builder.getEventSource()] ?: run { + val eventId = pipelineTriggerEventService.getEventId() + repoEventIdMap[builder.getEventSource()!!] = eventId + eventId + } + triggerEvent.eventId = eventId + builder.eventId(eventId) + pipelineTriggerEventService.saveEvent( + triggerEvent = triggerEvent, + triggerDetail = builder.build() + ) + } + } + open fun webhookTriggerPipelineBuild( projectId: String, pipelineId: String, @@ -246,6 +269,7 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { repo = repo ) builder.buildId(buildId) + .status(PipelineTriggerStatus.SUCCEED.name) .eventSource(eventSource = repo.repoHashId!!) .reason(PipelineTriggerReason.TRIGGER_SUCCESS.name) } @@ -266,7 +290,7 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { // 历史原因,webhook表没有记录eventType,所以查找出来的订阅者可能因为事件类型不匹配,事件不需要记录 if (!builder.getEventSource().isNullOrBlank()) { - builder.reason(PipelineTriggerReason.TRIGGER_NOT_MATCH.name) + builder.status(PipelineTriggerStatus.FAILED.name).reason(PipelineTriggerReason.TRIGGER_NOT_MATCH.name) } return false } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt index de7680d8bd8..8506f35727f 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt @@ -31,16 +31,17 @@ package com.tencent.devops.process.webhook.atom import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.readValue import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.webhook.atom.IWebhookAtomTask -import com.tencent.devops.common.webhook.pojo.ReplayWebhookRequest import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay import com.tencent.devops.common.webhook.pojo.code.git.GitEvent import com.tencent.devops.common.webhook.pojo.code.git.GitReviewEvent +import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.engine.service.PipelineWebhookService import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder -import com.tencent.devops.process.pojo.webhook.PipelineWebhookEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber -import com.tencent.devops.process.service.trigger.PipelineTriggerEventService import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -53,7 +54,6 @@ class CodeGitWebhookTriggerTaskAtom @Autowired constructor( private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder, private val pipelineWebhookService: PipelineWebhookService, private val pipelineBuildWebhookService: PipelineBuildWebhookService, - private val pipelineTriggerEventService: PipelineTriggerEventService, private val webhookTriggerTaskAtomService: WebhookTriggerTaskAtomService ) : IWebhookAtomTask { @@ -78,15 +78,12 @@ class CodeGitWebhookTriggerTaskAtom @Autowired constructor( eventTime = eventTime, scmType = getScmType() ) - val webhookEvent = PipelineWebhookEvent( - taskAtom = request.taskAtom, - requestId = requestId, - eventId = pipelineTriggerEventService.getWebhookEventId(), + val webhookEvent = PipelineTriggerEvent( triggerType = getScmType().name, eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), - eventMessage = matcher.getMessage() ?: "", eventDesc = matcher.getEventDesc(), + hookRequestId = requestId, eventTime = eventTime ) val subscribers = pipelineWebhookService.getWebhookPipelines( @@ -95,32 +92,32 @@ class CodeGitWebhookTriggerTaskAtom @Autowired constructor( ) pipelineBuildWebhookService.dispatchPipelineSubscribers( matcher = matcher, - webhookEvent = webhookEvent, + triggerEvent = webhookEvent, subscribers = subscribers ) } - override fun replay(request: ReplayWebhookRequest) { - val repoWebhookRequest = - webhookTriggerTaskAtomService.getRepoWebhookRequest(requestId = request.requestId) ?: return + override fun replay(request: WebhookRequestReplay) { + val repoWebhookRequest = webhookTriggerTaskAtomService.getRepoWebhookRequest( + requestId = request.hookRequestId + ) ?: throw ErrorCodeException( + errorCode = ProcessMessageCode.ERROR_WEBHOOK_REQUEST_NOT_FOUND, + params = arrayOf(request.hookRequestId.toString()) + ) val event = getEvent( request = WebhookRequest( - taskAtom = request.taskAtom, headers = repoWebhookRequest.requestHeader, body = repoWebhookRequest.requestBody ) ) ?: return val matcher = scmWebhookMatcherBuilder.createGitWebHookMatcher(event) val eventTime = LocalDateTime.now() - val webhookEvent = PipelineWebhookEvent( - taskAtom = request.taskAtom, - requestId = request.requestId, - eventId = pipelineTriggerEventService.getWebhookEventId(), + val triggerEvent = PipelineTriggerEvent( triggerType = getScmType().name, eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), - eventMessage = matcher.getMessage() ?: "", eventDesc = matcher.getEventDesc(), + hookRequestId = request.hookRequestId, eventTime = eventTime ) val subscribers = request.pipelineId?.let { @@ -138,7 +135,7 @@ class CodeGitWebhookTriggerTaskAtom @Autowired constructor( } pipelineBuildWebhookService.dispatchPipelineSubscribers( matcher = matcher, - webhookEvent = webhookEvent, + triggerEvent = triggerEvent, subscribers = subscribers ) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGithubWebHookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGithubWebHookTriggerTaskAtom.kt index 55060244d0b..9564449fd9c 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGithubWebHookTriggerTaskAtom.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGithubWebHookTriggerTaskAtom.kt @@ -31,23 +31,24 @@ package com.tencent.devops.process.webhook.atom import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.readValue import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.client.Client import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.common.webhook.atom.IWebhookAtomTask -import com.tencent.devops.common.webhook.pojo.ReplayWebhookRequest import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay import com.tencent.devops.common.webhook.pojo.code.github.GithubCheckRunEvent import com.tencent.devops.common.webhook.pojo.code.github.GithubCreateEvent import com.tencent.devops.common.webhook.pojo.code.github.GithubEvent import com.tencent.devops.common.webhook.pojo.code.github.GithubPullRequestEvent import com.tencent.devops.common.webhook.pojo.code.github.GithubPushEvent import com.tencent.devops.process.api.service.ServiceBuildResource +import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.engine.service.PipelineWebhookService import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder +import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent import com.tencent.devops.process.pojo.trigger.PipelineTriggerType -import com.tencent.devops.process.pojo.webhook.PipelineWebhookEvent import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber -import com.tencent.devops.process.service.trigger.PipelineTriggerEventService import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -59,7 +60,6 @@ class CodeGithubWebHookTriggerTaskAtom( private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder, private val pipelineWebhookService: PipelineWebhookService, private val pipelineBuildWebhookService: PipelineBuildWebhookService, - private val pipelineTriggerEventService: PipelineTriggerEventService, private val webhookTriggerTaskAtomService: WebhookTriggerTaskAtomService, private val client: Client ) : IWebhookAtomTask { @@ -85,15 +85,12 @@ class CodeGithubWebHookTriggerTaskAtom( eventTime = eventTime, scmType = ScmType.GITHUB ) - val webhookEvent = PipelineWebhookEvent( - taskAtom = request.taskAtom, - requestId = requestId, - eventId = pipelineTriggerEventService.getWebhookEventId(), + val webhookEvent = PipelineTriggerEvent( triggerType = PipelineTriggerType.GITHUB.name, eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), - eventMessage = matcher.getMessage() ?: "", eventDesc = matcher.getEventDesc(), + hookRequestId = requestId, eventTime = eventTime ) val subscribers = pipelineWebhookService.getWebhookPipelines( @@ -102,32 +99,32 @@ class CodeGithubWebHookTriggerTaskAtom( ) pipelineBuildWebhookService.dispatchPipelineSubscribers( matcher = matcher, - webhookEvent = webhookEvent, + triggerEvent = webhookEvent, subscribers = subscribers ) } - override fun replay(request: ReplayWebhookRequest) { - val webhookRequest = - webhookTriggerTaskAtomService.getRepoWebhookRequest(requestId = request.requestId) ?: return + override fun replay(request: WebhookRequestReplay) { + val repoWebhookRequest = webhookTriggerTaskAtomService.getRepoWebhookRequest( + requestId = request.hookRequestId + ) ?: throw ErrorCodeException( + errorCode = ProcessMessageCode.ERROR_WEBHOOK_REQUEST_NOT_FOUND, + params = arrayOf(request.hookRequestId.toString()) + ) val event = getEvent( request = WebhookRequest( - taskAtom = request.taskAtom, - headers = webhookRequest.requestHeader, - body = webhookRequest.requestBody + headers = repoWebhookRequest.requestHeader, + body = repoWebhookRequest.requestBody ) ) ?: return val matcher = scmWebhookMatcherBuilder.createGithubWebHookMatcher(event) val eventTime = LocalDateTime.now() - val webhookEvent = PipelineWebhookEvent( - taskAtom = request.taskAtom, - requestId = request.requestId, - eventId = pipelineTriggerEventService.getWebhookEventId(), + val triggerEvent = PipelineTriggerEvent( triggerType = PipelineTriggerType.GITHUB.name, eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), - eventMessage = matcher.getMessage() ?: "", eventDesc = matcher.getEventDesc(), + hookRequestId = request.hookRequestId, eventTime = eventTime ) val subscribers = request.pipelineId?.let { @@ -145,7 +142,7 @@ class CodeGithubWebHookTriggerTaskAtom( } pipelineBuildWebhookService.dispatchPipelineSubscribers( matcher = matcher, - webhookEvent = webhookEvent, + triggerEvent = triggerEvent, subscribers = subscribers ) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitlabWebHookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitlabWebHookTriggerTaskAtom.kt index ec8609c50f0..d642becfacb 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitlabWebHookTriggerTaskAtom.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitlabWebHookTriggerTaskAtom.kt @@ -30,16 +30,17 @@ package com.tencent.devops.process.webhook.atom import com.fasterxml.jackson.databind.ObjectMapper import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.webhook.atom.IWebhookAtomTask -import com.tencent.devops.common.webhook.pojo.ReplayWebhookRequest import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay import com.tencent.devops.common.webhook.pojo.code.git.GitEvent +import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.engine.service.PipelineWebhookService import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder +import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent import com.tencent.devops.process.pojo.trigger.PipelineTriggerType -import com.tencent.devops.process.pojo.webhook.PipelineWebhookEvent import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber -import com.tencent.devops.process.service.trigger.PipelineTriggerEventService import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -52,7 +53,6 @@ class CodeGitlabWebHookTriggerTaskAtom @Autowired constructor( private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder, private val pipelineWebhookService: PipelineWebhookService, private val pipelineBuildWebhookService: PipelineBuildWebhookService, - private val pipelineTriggerEventService: PipelineTriggerEventService, private val webhookTriggerTaskAtomService: WebhookTriggerTaskAtomService ) : IWebhookAtomTask { @@ -74,15 +74,12 @@ class CodeGitlabWebHookTriggerTaskAtom @Autowired constructor( eventTime = eventTime, scmType = ScmType.CODE_GITLAB ) - val webhookEvent = PipelineWebhookEvent( - taskAtom = request.taskAtom, - requestId = requestId, - eventId = pipelineTriggerEventService.getWebhookEventId(), + val triggerEvent = PipelineTriggerEvent( triggerType = PipelineTriggerType.CODE_GITLAB.name, eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), - eventMessage = matcher.getMessage() ?: "", eventDesc = matcher.getEventDesc(), + hookRequestId = requestId, eventTime = eventTime ) val subscribers = pipelineWebhookService.getWebhookPipelines( @@ -91,32 +88,32 @@ class CodeGitlabWebHookTriggerTaskAtom @Autowired constructor( ) pipelineBuildWebhookService.dispatchPipelineSubscribers( matcher = matcher, - webhookEvent = webhookEvent, + triggerEvent = triggerEvent, subscribers = subscribers ) } - override fun replay(request: ReplayWebhookRequest) { - val repoWebhookRequest = - webhookTriggerTaskAtomService.getRepoWebhookRequest(requestId = request.requestId) ?: return + override fun replay(request: WebhookRequestReplay) { + val repoWebhookRequest = webhookTriggerTaskAtomService.getRepoWebhookRequest( + requestId = request.hookRequestId + ) ?: throw ErrorCodeException( + errorCode = ProcessMessageCode.ERROR_WEBHOOK_REQUEST_NOT_FOUND, + params = arrayOf(request.hookRequestId.toString()) + ) val event = getEvent( request = WebhookRequest( - taskAtom = request.taskAtom, headers = repoWebhookRequest.requestHeader, body = repoWebhookRequest.requestBody ) ) ?: return val matcher = scmWebhookMatcherBuilder.createGitWebHookMatcher(event) val eventTime = LocalDateTime.now() - val webhookEvent = PipelineWebhookEvent( - taskAtom = request.taskAtom, - requestId = request.requestId, - eventId = pipelineTriggerEventService.getWebhookEventId(), - triggerType = PipelineTriggerType.CODE_GIT.name, + val triggerEvent = PipelineTriggerEvent( + triggerType = PipelineTriggerType.CODE_GITLAB.name, eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), - eventMessage = matcher.getMessage() ?: "", eventDesc = matcher.getEventDesc(), + hookRequestId = request.hookRequestId, eventTime = eventTime ) val subscribers = request.pipelineId?.let { @@ -134,7 +131,7 @@ class CodeGitlabWebHookTriggerTaskAtom @Autowired constructor( } pipelineBuildWebhookService.dispatchPipelineSubscribers( matcher = matcher, - webhookEvent = webhookEvent, + triggerEvent = triggerEvent, subscribers = subscribers ) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeP4WebHookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeP4WebHookTriggerTaskAtom.kt index 2874d97d402..8dee4ea0237 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeP4WebHookTriggerTaskAtom.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeP4WebHookTriggerTaskAtom.kt @@ -30,16 +30,17 @@ package com.tencent.devops.process.webhook.atom import com.fasterxml.jackson.databind.ObjectMapper import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.webhook.atom.IWebhookAtomTask -import com.tencent.devops.common.webhook.pojo.ReplayWebhookRequest import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay import com.tencent.devops.common.webhook.pojo.code.p4.P4Event +import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.engine.service.PipelineWebhookService import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder +import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent import com.tencent.devops.process.pojo.trigger.PipelineTriggerType -import com.tencent.devops.process.pojo.webhook.PipelineWebhookEvent import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber -import com.tencent.devops.process.service.trigger.PipelineTriggerEventService import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -51,7 +52,6 @@ class CodeP4WebHookTriggerTaskAtom( private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder, private val pipelineWebhookService: PipelineWebhookService, private val pipelineBuildWebhookService: PipelineBuildWebhookService, - private val pipelineTriggerEventService: PipelineTriggerEventService, private val webhookTriggerTaskAtomService: WebhookTriggerTaskAtomService ) : IWebhookAtomTask { @@ -72,15 +72,12 @@ class CodeP4WebHookTriggerTaskAtom( eventTime = eventTime, scmType = ScmType.CODE_P4 ) - val webhookEvent = PipelineWebhookEvent( - taskAtom = request.taskAtom, - requestId = requestId, - eventId = pipelineTriggerEventService.getWebhookEventId(), + val triggerEvent = PipelineTriggerEvent( triggerType = PipelineTriggerType.CODE_P4.name, eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), - eventMessage = matcher.getMessage() ?: "", eventDesc = matcher.getEventDesc(), + hookRequestId = requestId, eventTime = eventTime ) val subscribers = pipelineWebhookService.getWebhookPipelines( @@ -89,32 +86,32 @@ class CodeP4WebHookTriggerTaskAtom( ) pipelineBuildWebhookService.dispatchPipelineSubscribers( matcher = matcher, - webhookEvent = webhookEvent, + triggerEvent = triggerEvent, subscribers = subscribers ) } - override fun replay(request: ReplayWebhookRequest) { - val repoWebhookRequest = - webhookTriggerTaskAtomService.getRepoWebhookRequest(requestId = request.requestId) ?: return + override fun replay(request: WebhookRequestReplay) { + val repoWebhookRequest = webhookTriggerTaskAtomService.getRepoWebhookRequest( + requestId = request.hookRequestId + ) ?: throw ErrorCodeException( + errorCode = ProcessMessageCode.ERROR_WEBHOOK_REQUEST_NOT_FOUND, + params = arrayOf(request.hookRequestId.toString()) + ) val event = getEvent( request = WebhookRequest( - taskAtom = request.taskAtom, headers = repoWebhookRequest.requestHeader, body = repoWebhookRequest.requestBody ) ) ?: return val matcher = scmWebhookMatcherBuilder.createP4WebHookMatcher(event) val eventTime = LocalDateTime.now() - val webhookEvent = PipelineWebhookEvent( - taskAtom = request.taskAtom, - requestId = request.requestId, - eventId = pipelineTriggerEventService.getWebhookEventId(), + val triggerEvent = PipelineTriggerEvent( triggerType = PipelineTriggerType.CODE_P4.name, eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), - eventMessage = matcher.getMessage() ?: "", eventDesc = matcher.getEventDesc(), + hookRequestId = request.hookRequestId, eventTime = eventTime ) val subscribers = request.pipelineId?.let { @@ -132,7 +129,7 @@ class CodeP4WebHookTriggerTaskAtom( } pipelineBuildWebhookService.dispatchPipelineSubscribers( matcher = matcher, - webhookEvent = webhookEvent, + triggerEvent = triggerEvent, subscribers = subscribers ) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeSvnWebHookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeSvnWebHookTriggerTaskAtom.kt index 6dcfd3c369f..2a47894436c 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeSvnWebHookTriggerTaskAtom.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeSvnWebHookTriggerTaskAtom.kt @@ -30,16 +30,17 @@ package com.tencent.devops.process.webhook.atom import com.fasterxml.jackson.databind.ObjectMapper import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.webhook.atom.IWebhookAtomTask -import com.tencent.devops.common.webhook.pojo.ReplayWebhookRequest import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay import com.tencent.devops.common.webhook.pojo.code.svn.SvnCommitEvent +import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.engine.service.PipelineWebhookService import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder +import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent import com.tencent.devops.process.pojo.trigger.PipelineTriggerType -import com.tencent.devops.process.pojo.webhook.PipelineWebhookEvent import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber -import com.tencent.devops.process.service.trigger.PipelineTriggerEventService import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -51,7 +52,6 @@ class CodeSvnWebHookTriggerTaskAtom ( private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder, private val pipelineWebhookService: PipelineWebhookService, private val pipelineBuildWebhookService: PipelineBuildWebhookService, - private val pipelineTriggerEventService: PipelineTriggerEventService, private val webhookTriggerTaskAtomService: WebhookTriggerTaskAtomService ) : IWebhookAtomTask { @@ -73,15 +73,12 @@ class CodeSvnWebHookTriggerTaskAtom ( eventTime = eventTime, scmType = ScmType.CODE_SVN ) - val webhookEvent = PipelineWebhookEvent( - taskAtom = request.taskAtom, - requestId = requestId, - eventId = pipelineTriggerEventService.getWebhookEventId(), + val triggerEvent = PipelineTriggerEvent( triggerType = PipelineTriggerType.CODE_SVN.name, eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), - eventMessage = matcher.getMessage() ?: "", eventDesc = matcher.getEventDesc(), + hookRequestId = requestId, eventTime = eventTime ) @@ -91,31 +88,31 @@ class CodeSvnWebHookTriggerTaskAtom ( ) pipelineBuildWebhookService.dispatchPipelineSubscribers( matcher = matcher, - webhookEvent = webhookEvent, + triggerEvent = triggerEvent, subscribers = subscribers ) } - override fun replay(request: ReplayWebhookRequest) { - val repoWebhookRequest = - webhookTriggerTaskAtomService.getRepoWebhookRequest(requestId = request.requestId) ?: return + override fun replay(request: WebhookRequestReplay) { + val repoWebhookRequest = webhookTriggerTaskAtomService.getRepoWebhookRequest( + requestId = request.hookRequestId + ) ?: throw ErrorCodeException( + errorCode = ProcessMessageCode.ERROR_WEBHOOK_REQUEST_NOT_FOUND, + params = arrayOf(request.hookRequestId.toString()) + ) val event = getEvent( request = WebhookRequest( - taskAtom = request.taskAtom, body = repoWebhookRequest.requestBody ) ) ?: return val matcher = scmWebhookMatcherBuilder.createSvnWebHookMatcher(event) val eventTime = LocalDateTime.now() - val webhookEvent = PipelineWebhookEvent( - taskAtom = request.taskAtom, - requestId = request.requestId, - eventId = pipelineTriggerEventService.getWebhookEventId(), + val triggerEvent = PipelineTriggerEvent( triggerType = PipelineTriggerType.CODE_SVN.name, eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), - eventMessage = matcher.getMessage() ?: "", eventDesc = matcher.getEventDesc(), + hookRequestId = request.hookRequestId, eventTime = eventTime ) val subscribers = request.pipelineId?.let { @@ -133,7 +130,7 @@ class CodeSvnWebHookTriggerTaskAtom ( } pipelineBuildWebhookService.dispatchPipelineSubscribers( matcher = matcher, - webhookEvent = webhookEvent, + triggerEvent = triggerEvent, subscribers = subscribers ) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeTGitWebhookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeTGitWebhookTriggerTaskAtom.kt index 029dca03346..b11db27909e 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeTGitWebhookTriggerTaskAtom.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeTGitWebhookTriggerTaskAtom.kt @@ -32,7 +32,6 @@ import com.fasterxml.jackson.databind.ObjectMapper import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.process.engine.service.PipelineWebhookService import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder -import com.tencent.devops.process.service.trigger.PipelineTriggerEventService import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service @@ -43,14 +42,12 @@ class CodeTGitWebhookTriggerTaskAtom @Autowired constructor( private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder, private val pipelineWebhookService: PipelineWebhookService, private val pipelineBuildWebhookService: PipelineBuildWebhookService, - private val pipelineTriggerEventService: PipelineTriggerEventService, private val webhookTriggerTaskAtomService: WebhookTriggerTaskAtomService ) : CodeGitWebhookTriggerTaskAtom( objectMapper = objectMapper, scmWebhookMatcherBuilder = scmWebhookMatcherBuilder, pipelineWebhookService = pipelineWebhookService, pipelineBuildWebhookService = pipelineBuildWebhookService, - pipelineTriggerEventService = pipelineTriggerEventService, webhookTriggerTaskAtomService = webhookTriggerTaskAtomService ) { diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/PipelineTriggerRequestService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/PipelineTriggerRequestService.kt new file mode 100644 index 00000000000..8fc61e37efd --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/PipelineTriggerRequestService.kt @@ -0,0 +1,99 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.webhook.listener + +import com.tencent.devops.common.api.exception.ErrorCodeException +import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitWebHookTriggerElement +import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGithubWebHookTriggerElement +import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitlabWebHookTriggerElement +import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeP4WebHookTriggerElement +import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeSVNWebHookTriggerElement +import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeTGitWebHookTriggerElement +import com.tencent.devops.common.service.utils.SpringContextUtil +import com.tencent.devops.common.webhook.atom.IWebhookAtomTask +import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay +import com.tencent.devops.process.constant.ProcessMessageCode +import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_TRIGGER_TYPE_REPLAY_NOT_SUPPORT +import com.tencent.devops.process.dao.PipelineTriggerEventDao +import com.tencent.devops.process.pojo.trigger.PipelineTriggerType +import org.jooq.DSLContext +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.stereotype.Service + +@Service +class PipelineTriggerRequestService @Autowired constructor( + private val dslContext: DSLContext, + private val pipelineTriggerEventDao: PipelineTriggerEventDao +) { + + companion object { + private val logger = LoggerFactory.getLogger(PipelineTriggerRequestService::class.java) + private val triggerTypeToTaskAtom = mapOf( + PipelineTriggerType.CODE_GIT.name to CodeGitWebHookTriggerElement.taskAtom, + PipelineTriggerType.CODE_TGIT.name to CodeTGitWebHookTriggerElement.taskAtom, + PipelineTriggerType.CODE_P4.name to CodeP4WebHookTriggerElement.taskAtom, + PipelineTriggerType.CODE_GITLAB to CodeGitlabWebHookTriggerElement.taskAtom, + PipelineTriggerType.CODE_SVN to CodeSVNWebHookTriggerElement.taskAtom, + PipelineTriggerType.GITHUB to CodeGithubWebHookTriggerElement.taskAtom + ) + } + + fun handleRequest(taskAtom: String, request: WebhookRequest) { + SpringContextUtil.getBean(IWebhookAtomTask::class.java, taskAtom).request(request = request) + } + + fun handleReplayRequest( + userId: String, + projectId: String, + eventId: Long, + pipelineId: String? = null + ) { + val triggerEvent = pipelineTriggerEventDao.getTriggerEvent( + dslContext = dslContext, + projectId = projectId, + eventId = eventId + ) ?: throw ErrorCodeException( + errorCode = ProcessMessageCode.ERROR_TRIGGER_EVENT_NOT_FOUND, + params = arrayOf(eventId.toString()) + ) + val taskAtom = triggerTypeToTaskAtom[triggerEvent.triggerType] ?: throw ErrorCodeException( + errorCode = ERROR_TRIGGER_TYPE_REPLAY_NOT_SUPPORT, + params = arrayOf(triggerEvent.triggerType) + ) + val request = WebhookRequestReplay( + userId = userId, + projectId = projectId, + hookRequestId = triggerEvent.hookRequestId!!, + pipelineId = pipelineId + ) + SpringContextUtil.getBean(IWebhookAtomTask::class.java, taskAtom).replay(request = request) + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt index 241657de362..9667639d302 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt @@ -51,7 +51,7 @@ import org.springframework.stereotype.Component @Component class WebhookEventListener constructor( private val rabbitTemplate: RabbitTemplate, - private val webhookRequestService: WebhookRequestService + private val pipelineTriggerRequestService: PipelineTriggerRequestService ) { fun handleCommitEvent(event: ICodeWebhookEvent) { @@ -69,44 +69,54 @@ class WebhookEventListener constructor( when (event.commitEventType) { CommitEventType.SVN -> { val request = WebhookRequest( - taskAtom = CodeSVNWebHookTriggerElement.taskAtom, body = event.requestContent ) - webhookRequestService.handleRequest(request) + pipelineTriggerRequestService.handleRequest( + taskAtom = CodeSVNWebHookTriggerElement.taskAtom, + request = request + ) } CommitEventType.GIT -> { val request = WebhookRequest( - taskAtom = CodeGitWebHookTriggerElement.taskAtom, headers = mapOf( "X-Event" to event.event!!, ), body = event.requestContent ) - webhookRequestService.handleRequest(request) + pipelineTriggerRequestService.handleRequest( + taskAtom = CodeGitWebHookTriggerElement.taskAtom, + request = request + ) } CommitEventType.GITLAB -> { val request = WebhookRequest( - taskAtom = CodeGitlabWebHookTriggerElement.taskAtom, body = event.requestContent ) - webhookRequestService.handleRequest(request) + pipelineTriggerRequestService.handleRequest( + taskAtom = CodeGitlabWebHookTriggerElement.taskAtom, + request = request + ) } CommitEventType.TGIT -> { val request = WebhookRequest( - taskAtom = CodeTGitWebHookTriggerElement.taskAtom, headers = mapOf( "X-Event" to event.event!!, ), body = event.requestContent ) - webhookRequestService.handleRequest(request) + pipelineTriggerRequestService.handleRequest( + taskAtom = CodeTGitWebHookTriggerElement.taskAtom, + request = request + ) } CommitEventType.P4 -> { val request = WebhookRequest( - taskAtom = CodeGitlabWebHookTriggerElement.taskAtom, body = event.requestContent ) - webhookRequestService.handleRequest(request) + pipelineTriggerRequestService.handleRequest( + taskAtom = CodeGitlabWebHookTriggerElement.taskAtom, + request = request + ) } } result = true @@ -187,7 +197,6 @@ class WebhookEventListener constructor( try { val request = with(thisGithubWebhook) { WebhookRequest( - taskAtom = CodeGithubWebHookTriggerElement.taskAtom, headers = mapOf( "X-GitHub-Event" to thisGithubWebhook.event, "X-Github-Delivery" to guid, @@ -196,7 +205,10 @@ class WebhookEventListener constructor( body = thisGithubWebhook.body ) } - webhookRequestService.handleRequest(request) + pipelineTriggerRequestService.handleRequest( + taskAtom = CodeGithubWebHookTriggerElement.taskAtom, + request = request + ) result = true } catch (ignore: Throwable) { From bbd8504f74d8ebad5159b9efc50696cc559699a9 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Fri, 4 Aug 2023 10:16:25 +0800 Subject: [PATCH 005/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tencent/devops/process/dao/PipelineTriggerEventDao.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index 61c8b6a55db..2deee5ab004 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -71,7 +71,7 @@ class PipelineTriggerEventDao { EVENT_DESC, HOOK_REQUEST_ID, REQUEST_PARAMS, - EVENT_TIME, + EVENT_TIME ).values( triggerEvent.eventId, triggerEvent.projectId, @@ -83,7 +83,7 @@ class PipelineTriggerEventDao { triggerEvent.eventDesc, triggerEvent.hookRequestId, triggerEvent.requestParams, - triggerEvent.eventTime, + triggerEvent.eventTime ).onDuplicateKeyIgnore().execute() } } From c2de58f81d6e9a571ba13f55981aa7c80f1257f6 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Fri, 4 Aug 2023 10:33:22 +0800 Subject: [PATCH 006/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tencent/devops/process/dao/PipelineTriggerEventDao.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index 2deee5ab004..072de84bc81 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -61,7 +61,6 @@ class PipelineTriggerEventDao { with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { dslContext.insertInto( this, - ).values( PROJECT_ID, EVENT_ID, TRIGGER_TYPE, @@ -73,7 +72,6 @@ class PipelineTriggerEventDao { REQUEST_PARAMS, EVENT_TIME ).values( - triggerEvent.eventId, triggerEvent.projectId, triggerEvent.eventId, triggerEvent.triggerType, @@ -82,7 +80,7 @@ class PipelineTriggerEventDao { triggerEvent.triggerUser, triggerEvent.eventDesc, triggerEvent.hookRequestId, - triggerEvent.requestParams, + triggerEvent.requestParams?.let { JsonUtil.toJson(it) }, triggerEvent.eventTime ).onDuplicateKeyIgnore().execute() } From 63ac23c5f5016e4d0ec84dfd65c6864beac518c2 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Fri, 4 Aug 2023 16:01:09 +0800 Subject: [PATCH 007/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../element/trigger/enums/CodeEventType.kt | 4 ++ .../user/UserPipelineTriggerEventResource.kt | 34 +++++---- ...der.kt => PipelineTriggerDetailBuilder.kt} | 2 +- .../pojo/trigger/PipelineTriggerReason.kt | 1 + .../pojo/trigger/PipelineTriggerType.kt | 17 +++++ .../SamplePipelineBuildWebhookService.kt | 4 +- .../UserPipelineTriggerEventResourceImpl.kt | 32 +++++++-- .../process/dao/PipelineTriggerEventDao.kt | 4 -- .../trigger/PipelineTriggerEventService.kt | 6 -- .../webhook/PipelineBuildWebhookService.kt | 8 +-- .../api/ServiceRepositoryWebhookResource.kt | 2 +- .../sql/1001_ci_process_ddl_mysql.sql | 70 ++++++++----------- 12 files changed, 108 insertions(+), 76 deletions(-) rename src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/{PipelineTriggerEventBuilder.kt => PipelineTriggerDetailBuilder.kt} (98%) diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/enums/CodeEventType.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/enums/CodeEventType.kt index 8262b1fc0cd..c6020b6b9d5 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/enums/CodeEventType.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/enums/CodeEventType.kt @@ -59,4 +59,8 @@ enum class CodeEventType { SHELVE_COMMIT, SHELVE_DELETE, SHELVE_SUBMIT; + + companion object { + const val MESSAGE_CODE_PREFIX = "EVENT_TYPE" + } } diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt index b634e49b078..9bc9d640e7d 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt @@ -31,6 +31,7 @@ package com.tencent.devops.process.api.user import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID_DEFAULT_VALUE import com.tencent.devops.common.api.model.SQLPage +import com.tencent.devops.common.api.pojo.IdValue import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventVo import com.tencent.devops.process.pojo.trigger.RepoTriggerEventVo @@ -53,10 +54,20 @@ import javax.ws.rs.core.MediaType @Consumes(MediaType.APPLICATION_JSON) interface UserPipelineTriggerEventResource { + @ApiOperation("获取触发类型") + @GET + @Path("listTriggerType") + fun listTriggerType(): Result> + + @ApiOperation("获取事件类型") + @GET + @Path("listEventType") + fun listEventType(): Result> + @ApiOperation("获取流水线触发事件列表") @GET - @Path("/{projectId}/{pipelineId}/listTriggerEvent") - fun listTriggerEvent( + @Path("/{projectId}/{pipelineId}/listPipelineTriggerEvent") + fun listPipelineTriggerEvent( @ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE) @HeaderParam(AUTH_HEADER_USER_ID) userId: String, @@ -91,8 +102,8 @@ interface UserPipelineTriggerEventResource { @ApiOperation("获取代码库webhook事件列表") @GET - @Path("/{projectId}/{repoHashId}/listRepoWebhookEvent") - fun listRepoWebhookEvent( + @Path("/{projectId}/{repoHashId}/listRepoTriggerEvent") + fun listRepoTriggerEvent( @ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE) @HeaderParam(AUTH_HEADER_USER_ID) userId: String, @@ -131,25 +142,22 @@ interface UserPipelineTriggerEventResource { pageSize: Int? ): Result> - @ApiOperation("获取代码库webhook事件触发详情") + @ApiOperation("获取触发事件详情") @GET - @Path("/{projectId}/{repoHashId}/listRepoWebhookEventDetail") - fun listRepoWebhookEventDetail( + @Path("/{projectId}/{eventId}/listEventDetail") + fun listEventDetail( @ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE) @HeaderParam(AUTH_HEADER_USER_ID) userId: String, @ApiParam("项目ID", required = true) @PathParam("projectId") projectId: String, - @ApiParam("代码库hashId", required = true) - @PathParam("repoHashId") - repoHashId: String, @ApiParam("事件ID", required = true) - @QueryParam("eventId") + @PathParam("eventId") eventId: Long, - @ApiParam("流水线ID", required = true) + @ApiParam("流水线ID", required = false) @QueryParam("pipelineId") - pipelineId: String, + pipelineId: String?, @ApiParam("第几页", required = false, defaultValue = "1") @QueryParam("page") page: Int?, diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventBuilder.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetailBuilder.kt similarity index 98% rename from src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventBuilder.kt rename to src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetailBuilder.kt index e7a1a574fe3..aa177421a2f 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventBuilder.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetailBuilder.kt @@ -28,7 +28,7 @@ package com.tencent.devops.process.pojo.trigger -class PipelineTriggerEventBuilder { +class PipelineTriggerDetailBuilder { private lateinit var projectId: String private var eventId: Long? = null private var eventSource: String? = null diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerReason.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerReason.kt index e4338f1b025..765328ecc43 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerReason.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerReason.kt @@ -30,5 +30,6 @@ package com.tencent.devops.process.pojo.trigger enum class PipelineTriggerReason(val detail: String) { TRIGGER_SUCCESS("Trigger success"), + TRIGGER_FAILED("Trigger failed"), TRIGGER_NOT_MATCH("Does not meet the trigger condition :%s") } diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt index f796b5bec0e..6630db6c5f6 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt @@ -27,6 +27,8 @@ package com.tencent.devops.process.pojo.trigger +import com.tencent.devops.common.api.pojo.IdValue +import com.tencent.devops.common.web.utils.I18nUtil import io.swagger.annotations.ApiModel import io.swagger.annotations.ApiModelProperty @@ -65,4 +67,19 @@ enum class PipelineTriggerType { // 远程触发 @ApiModelProperty("远程触发") REMOTE; + + companion object { + + fun toMap(): List { + return PipelineTriggerType.values().map { + IdValue( + id = it.name, + value = I18nUtil.getCodeLanMessage( + messageCode = "TRIGGER_TYPE_${it.name}", + defaultMessage = it.name + ) + ) + } + } + } } diff --git a/src/backend/ci/core/process/biz-process-sample/src/main/kotlin/com/tencent/devops/process/service/webhook/SamplePipelineBuildWebhookService.kt b/src/backend/ci/core/process/biz-process-sample/src/main/kotlin/com/tencent/devops/process/service/webhook/SamplePipelineBuildWebhookService.kt index f72b81a5261..1fc6098283b 100644 --- a/src/backend/ci/core/process/biz-process-sample/src/main/kotlin/com/tencent/devops/process/service/webhook/SamplePipelineBuildWebhookService.kt +++ b/src/backend/ci/core/process/biz-process-sample/src/main/kotlin/com/tencent/devops/process/service/webhook/SamplePipelineBuildWebhookService.kt @@ -33,7 +33,7 @@ import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.permission.PipelinePermissionService -import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventBuilder +import com.tencent.devops.process.pojo.trigger.PipelineTriggerDetailBuilder import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service @@ -61,7 +61,7 @@ class SamplePipelineBuildWebhookService : PipelineBuildWebhookService() { projectId: String, pipelineId: String, matcher: ScmWebhookMatcher, - builder: PipelineTriggerEventBuilder + builder: PipelineTriggerDetailBuilder ): Boolean { return super.webhookTriggerPipelineBuild( projectId = projectId, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt index d6522da2930..8dba5829e37 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt @@ -29,10 +29,14 @@ package com.tencent.devops.process.api import com.tencent.devops.common.api.model.SQLPage +import com.tencent.devops.common.api.pojo.IdValue import com.tencent.devops.common.api.pojo.Result +import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.web.RestResource +import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.process.api.user.UserPipelineTriggerEventResource import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventVo +import com.tencent.devops.process.pojo.trigger.PipelineTriggerType import com.tencent.devops.process.pojo.trigger.RepoTriggerEventVo import com.tencent.devops.process.service.trigger.PipelineTriggerEventService @@ -40,7 +44,25 @@ import com.tencent.devops.process.service.trigger.PipelineTriggerEventService class UserPipelineTriggerEventResourceImpl( private val pipelineTriggerEventService: PipelineTriggerEventService ) : UserPipelineTriggerEventResource { - override fun listTriggerEvent( + + override fun listTriggerType(): Result> { + return Result(PipelineTriggerType.toMap()) + } + + override fun listEventType(): Result> { + val eventTypes = CodeEventType.values().map { + IdValue( + id = it.name, + value = I18nUtil.getCodeLanMessage( + messageCode = "${CodeEventType.MESSAGE_CODE_PREFIX}_${it.name}", + defaultMessage = it.name + ) + ) + } + return Result(eventTypes) + } + + override fun listPipelineTriggerEvent( userId: String, projectId: String, pipelineId: String, @@ -67,7 +89,7 @@ class UserPipelineTriggerEventResourceImpl( ) } - override fun listRepoWebhookEvent( + override fun listRepoTriggerEvent( userId: String, projectId: String, repoHashId: String, @@ -98,19 +120,17 @@ class UserPipelineTriggerEventResourceImpl( ) } - override fun listRepoWebhookEventDetail( + override fun listEventDetail( userId: String, projectId: String, - repoHashId: String, eventId: Long, - pipelineId: String, + pipelineId: String?, page: Int?, pageSize: Int? ): Result> { return Result( pipelineTriggerEventService.listRepoTriggerEventDetail( projectId = projectId, - repoHashId = repoHashId, eventId = eventId, pipelineId = pipelineId, page = page, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index 072de84bc81..68d655a33ca 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -125,7 +125,6 @@ class PipelineTriggerEventDao { fun listTriggerEvent( dslContext: DSLContext, projectId: String, - eventSource: String? = null, eventId: Long? = null, eventType: String? = null, triggerType: String? = null, @@ -142,7 +141,6 @@ class PipelineTriggerEventDao { t1 = t1, t2 = t2, projectId = projectId, - eventSource = eventSource, eventId = eventId, eventType = eventType, triggerUser = triggerUser, @@ -199,7 +197,6 @@ class PipelineTriggerEventDao { fun countTriggerEvent( dslContext: DSLContext, projectId: String, - eventSource: String? = null, eventId: Long? = null, eventType: String? = null, triggerType: String? = null, @@ -214,7 +211,6 @@ class PipelineTriggerEventDao { t1 = t1, t2 = t2, projectId = projectId, - eventSource = eventSource, eventId = eventId, eventType = eventType, triggerUser = triggerUser, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt index ca74aa92c8b..97932152b53 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt @@ -175,7 +175,6 @@ class PipelineTriggerEventService @Autowired constructor( fun listRepoTriggerEventDetail( projectId: String, - repoHashId: String, eventId: Long, pipelineId: String?, page: Int?, @@ -184,16 +183,12 @@ class PipelineTriggerEventService @Autowired constructor( if (projectId.isBlank()) { throw ParamBlankException("Invalid projectId") } - if (repoHashId.isBlank()) { - throw ParamBlankException("Invalid repoHashId") - } val pageNotNull = page ?: 0 val pageSizeNotNull = pageSize ?: PageUtil.MAX_PAGE_SIZE val sqlLimit = PageUtil.convertPageSizeToSQLMAXLimit(pageNotNull, pageSizeNotNull) val records = pipelineTriggerEventDao.listTriggerEvent( dslContext = dslContext, projectId = projectId, - eventSource = repoHashId, eventId = eventId, pipelineId = pipelineId, limit = sqlLimit.limit, @@ -202,7 +197,6 @@ class PipelineTriggerEventService @Autowired constructor( val count = pipelineTriggerEventDao.countTriggerEvent( dslContext = dslContext, projectId = projectId, - eventSource = repoHashId, eventId = eventId, pipelineId = pipelineId ) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt index 6f822fd3e7f..84b1162f24d 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt @@ -49,7 +49,7 @@ import com.tencent.devops.process.engine.service.code.GitWebhookUnlockDispatcher import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder import com.tencent.devops.process.pojo.code.WebhookCommit import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent -import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventBuilder +import com.tencent.devops.process.pojo.trigger.PipelineTriggerDetailBuilder import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber @@ -120,7 +120,7 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { val pipelineId = subscriber.pipelineId try { logger.info("pipelineId is $pipelineId") - val builder = PipelineTriggerEventBuilder() + val builder = PipelineTriggerDetailBuilder() .projectId(projectId) .pipelineId(pipelineId) @@ -161,7 +161,7 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { private fun saveTriggerEvent( projectId: String, - builder: PipelineTriggerEventBuilder, + builder: PipelineTriggerDetailBuilder, triggerEvent: PipelineTriggerEvent, repoEventIdMap: MutableMap ) { @@ -186,7 +186,7 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { projectId: String, pipelineId: String, matcher: ScmWebhookMatcher, - builder: PipelineTriggerEventBuilder + builder: PipelineTriggerDetailBuilder ): Boolean { val pipelineInfo = pipelineRepositoryService.getPipelineInfo(projectId, pipelineId) ?: return false diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryWebhookResource.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryWebhookResource.kt index 56c913bbeb2..44899531dfa 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryWebhookResource.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryWebhookResource.kt @@ -56,7 +56,7 @@ interface ServiceRepositoryWebhookResource { @ApiOperation("获取代码库事件请求") @GET - @Path("/{eventId}") + @Path("/{requestId}") fun getWebhookRequest( @ApiParam(value = "事件ID", required = true) @PathParam("requestId") diff --git a/support-files/sql/1001_ci_process_ddl_mysql.sql b/support-files/sql/1001_ci_process_ddl_mysql.sql index ab3b606fd46..d5df8981e1b 100644 --- a/support-files/sql/1001_ci_process_ddl_mysql.sql +++ b/support-files/sql/1001_ci_process_ddl_mysql.sql @@ -1172,53 +1172,45 @@ CREATE TABLE IF NOT EXISTS `T_PIPELINE_BUILD_RECORD_TASK` ( -- ---------------------------- --- Table structure for T_PIPELINE_WEBHOOK_EVENT +-- Table structure for T_PIPELINE_TRIGGER_EVENT -- ---------------------------- -CREATE TABLE IF NOT EXISTS `T_PIPELINE_WEBHOOK_EVENT` +CREATE TABLE IF NOT EXISTS `T_PIPELINE_TRIGGER_EVENT` ( - `PROJECT_ID` varchar(64) NOT NULL COMMENT '项目ID', - `REQUEST_ID` bigint(20) NOT NULL COMMENT '请求ID', - `EVENT_ID` bigint(20) NOT NULL COMMENT '事件ID', - `TRIGGER_TYPE` varchar(64) NOT NULL COMMENT '触发类型', - `EVENT_SOURCE` varchar(255) NOT NULL COMMENT '触发源', - `EVENT_TYPE` varchar(64) NOT NULL COMMENT '事件类型', - `TRIGGER_USER` varchar(100) NOT NULL COMMENT '触发用户', - `EVENT_MESSAGE` text NOT NULL COMMENT '事件信息', - `EVENT_DESC` text NOT NULL COMMENT '事件描述', - `EVENT_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '事件时间', - `TASK_ATOM` varchar(128) COMMENT '事件处理类', + `PROJECT_ID` varchar(64) NOT NULL COMMENT '项目ID', + `EVENT_ID` bigint(20) NOT NULL COMMENT '事件ID', + `TRIGGER_TYPE` varchar(64) NOT NULL COMMENT '触发类型', + `EVENT_SOURCE` varchar(255) NOT NULL COMMENT '触发源', + `EVENT_TYPE` varchar(64) NOT NULL COMMENT '事件类型', + `TRIGGER_USER` varchar(100) NOT NULL COMMENT '触发用户', + `EVENT_DESC` text NOT NULL COMMENT '事件描述', + `HOOK_REQUEST_ID` bigint(20) NULL COMMENT 'WEBHOOK请求ID', + `REQUEST_PARAMS` text DEFAULT NULL COMMENT '请求参数', + `EVENT_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '事件时间', PRIMARY KEY (`EVENT_ID`, `EVENT_TIME`), - unique UQ_EVENT_ID_EVENT_SOURCE (`PROJECT_ID`,`EVENT_ID`, `EVENT_SOURCE`) -) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT ='流水线WEBHOOK事件表'; + INDEX IDX_PROJECT_ID_EVENT_ID (`PROJECT_ID`, `EVENT_ID`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT ='流水线触发事件表'; -- ---------------------------- --- Table structure for T_PIPELINE_TRIGGER_EVENT +-- Table structure for T_PIPELINE_TRIGGER_DETAIL -- ---------------------------- -CREATE TABLE IF NOT EXISTS `T_PIPELINE_TRIGGER_EVENT` +CREATE TABLE IF NOT EXISTS `T_PIPELINE_TRIGGER_DETAIL` ( - `ID` bigint(20) NOT NULL COMMENT '触发ID', - `PROJECT_ID` varchar(64) NOT NULL COMMENT '蓝盾项目ID', - `EVENT_ID` bigint(20) NOT NULL COMMENT '事件ID', - `TRIGGER_TYPE` varchar(64) NOT NULL COMMENT '触发类型', - `EVENT_SOURCE` varchar(255) NOT NULL COMMENT '触发源', - `EVENT_TYPE` varchar(64) NOT NULL COMMENT '事件类型', - `TRIGGER_USER` varchar(100) NOT NULL COMMENT '触发用户', - `EVENT_MESSAGE` text NOT NULL COMMENT '事件信息', - `EVENT_DESC` text NOT NULL COMMENT '事件描述', - `EVENT_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '事件时间', - `STATUS` varchar(100) DEFAULT NULL COMMENT '状态(success or failure)', - `PIPELINE_ID` varchar(100) DEFAULT NULL COMMENT '流水线ID', - `PIPELINE_NAME` varchar(100) DEFAULT NULL COMMENT '流水线名称', - `VERSION` int DEFAULT NULL COMMENT '流水线版本号', - `BUILD_ID` varchar(100) DEFAULT NULL COMMENT '构建ID', - `BUILD_NUM` varchar(100) DEFAULT NULL COMMENT '构建编号', - `REASON` varchar(100) DEFAULT NULL COMMENT '原因', - `REASON_DETAIL` varchar(100) DEFAULT NULL COMMENT '原因详情', - `CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - PRIMARY KEY (`ID`, `CREATE_TIME`), - index IDX_EVENT_ID_EVENT_SOURCE (`PROJECT_ID`,`EVENT_ID`, `EVENT_SOURCE`) -) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT ='流水线触发事件信息表'; + `DETAIL_ID` bigint(20) NOT NULL COMMENT '事件明细ID', + `PROJECT_ID` varchar(64) NOT NULL COMMENT '项目ID', + `EVENT_ID` bigint(20) NOT NULL COMMENT '事件ID', + `STATUS` varchar(100) DEFAULT NULL COMMENT '状态(success or failure)', + `PIPELINE_ID` varchar(100) DEFAULT NULL COMMENT '流水线ID', + `PIPELINE_NAME` varchar(100) DEFAULT NULL COMMENT '流水线名称', + `VERSION` int DEFAULT NULL COMMENT '流水线版本号', + `BUILD_ID` varchar(100) DEFAULT NULL COMMENT '构建ID', + `BUILD_NUM` varchar(100) DEFAULT NULL COMMENT '构建编号', + `REASON` varchar(100) DEFAULT NULL COMMENT '失败原因', + `REASON_DETAIL` text DEFAULT NULL COMMENT '原因详情', + `CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + PRIMARY KEY (`DETAIL_ID`, `CREATE_TIME`), + INDEX IDX_PROJECT_ID_EVENT_ID (`PROJECT_ID`, `EVENT_ID`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT ='流水线触发事件明细表'; SET FOREIGN_KEY_CHECKS = 1; From 9287ecb1be3e4cac0140b563659f5e6d1efcbff4 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Sat, 5 Aug 2023 09:55:24 +0800 Subject: [PATCH 008/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tencent/devops/process/dao/PipelineTriggerEventDao.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index 68d655a33ca..d66234e01be 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -320,7 +320,7 @@ class PipelineTriggerEventDao { startTime = startTime, endTime = endTime ) - return dslContext.select(DSL.countDistinct(t1.PROJECT_ID, t1.EVENT_ID, t1.EVENT_SOURCE)) + return dslContext.select(DSL.countDistinct(t1.PROJECT_ID, t1.EVENT_ID)) .from(t1) .leftJoin(t2) .on(t1.EVENT_ID.eq(t2.EVENT_ID)).and(t1.PROJECT_ID.eq(t2.PROJECT_ID)) From 8ad1f492d0d05eb2c1c007c600fe074ffc9ee421 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Tue, 8 Aug 2023 10:08:07 +0800 Subject: [PATCH 009/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/common/api/pojo/I18Variable.kt | 42 +++++++++++++++++++ .../devops/common/web/utils/I18nUtil.kt | 8 ++++ .../webhook/enums/WebhookI18nConstants.kt | 34 +++++++++++++++ .../webhook/pojo/code/git/GitPushEvent.kt | 2 + .../code/handler/CodeWebhookTriggerHandler.kt | 3 +- .../handler/tgit/TGitPushTriggerHandler.kt | 17 +++++++- .../process/dao/PipelineTriggerEventDao.kt | 4 +- .../i18n/process/message_en_US.properties | 1 + .../i18n/process/message_zh_CN.properties | 3 +- 9 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/pojo/I18Variable.kt create mode 100644 src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt diff --git a/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/pojo/I18Variable.kt b/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/pojo/I18Variable.kt new file mode 100644 index 00000000000..1a1cb16b3b8 --- /dev/null +++ b/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/pojo/I18Variable.kt @@ -0,0 +1,42 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.common.api.pojo + +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty + +@ApiModel("国际化变量") +data class I18Variable( + @ApiModelProperty("国际化变量名") + val code: String, + @ApiModelProperty("国际化参数") + val params: List, + @ApiModelProperty("默认信息") + val defaultMessage: String? = null +) diff --git a/src/backend/ci/core/common/common-web/src/main/kotlin/com/tencent/devops/common/web/utils/I18nUtil.kt b/src/backend/ci/core/common/common-web/src/main/kotlin/com/tencent/devops/common/web/utils/I18nUtil.kt index c418d69a126..ca06335dc9f 100644 --- a/src/backend/ci/core/common/common-web/src/main/kotlin/com/tencent/devops/common/web/utils/I18nUtil.kt +++ b/src/backend/ci/core/common/common-web/src/main/kotlin/com/tencent/devops/common/web/utils/I18nUtil.kt @@ -33,6 +33,7 @@ import com.tencent.devops.common.api.constant.DEFAULT_LOCALE_LANGUAGE import com.tencent.devops.common.api.constant.REQUEST_CHANNEL import com.tencent.devops.common.api.enums.RequestChannelTypeEnum import com.tencent.devops.common.api.enums.SystemModuleEnum +import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.common.api.util.LocaleUtil import com.tencent.devops.common.api.util.MessageUtil @@ -221,6 +222,13 @@ object I18nUtil { } } + fun I18Variable.getCodeLanMessage(): String { + return getCodeLanMessage( + messageCode = code, + params = params.toTypedArray() + ) + } + /** * 生成请求响应对象 * @param messageCode 状态码 diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt new file mode 100644 index 00000000000..ccd244e296f --- /dev/null +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt @@ -0,0 +1,34 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.common.webhook.enums + +object WebhookI18nConstants { + const val TGIT_PUSH_EVENT_DESC = "bkTgitPushEventDesc" + +} diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitPushEvent.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitPushEvent.kt index 2e98b768deb..d1416ef5124 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitPushEvent.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitPushEvent.kt @@ -47,6 +47,8 @@ data class GitPushEvent( val operation_kind: String?, val action_kind: String?, val push_options: Map?, + @JsonProperty("push_timestamp") + val pushTimestamp: String?, val create_and_update: Boolean?, @JsonProperty("diff_files") val diffFiles: List? diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt index e84118bc7a4..92d63dfbb3e 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt @@ -27,6 +27,7 @@ package com.tencent.devops.common.webhook.service.code.handler +import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent import com.tencent.devops.common.webhook.pojo.code.WebHookParams @@ -75,7 +76,7 @@ interface CodeWebhookTriggerHandler { /** * 获取事件说明,根据不同的事件组织事件说明 */ - fun getEventDesc(event: T): String = "" + fun getEventDesc(event: T): I18Variable /** * 获取webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt index 97e01edacdb..f7490680d6a 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt @@ -28,7 +28,9 @@ package com.tencent.devops.common.webhook.service.code.handler.tgit import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.util.DateTimeUtil +import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_ACTION import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_BEFORE_SHA @@ -39,6 +41,7 @@ import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_EVENT_URL import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_REF import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_REPO_URL import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants.TGIT_PUSH_EVENT_DESC import com.tencent.devops.common.webhook.enums.code.tgit.TGitPushActionType import com.tencent.devops.common.webhook.enums.code.tgit.TGitPushOperationKind import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_BRANCH @@ -75,6 +78,7 @@ import com.tencent.devops.scm.utils.code.git.GitUtils import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired +import java.time.LocalDateTime import java.util.Date @CodeWebhookHandler @@ -127,8 +131,17 @@ class TGitPushTriggerHandler( } } - override fun getEventDesc(event: GitPushEvent): String { - return "${getBranchName(event)} commit ${event.checkout_sha} pushed by ${event.user_name}" + override fun getEventDesc(event: GitPushEvent): I18Variable { + return I18Variable( + code = TGIT_PUSH_EVENT_DESC, + params = listOf( + getBranchName(event), + "${event.repository.homepage}/commit/${event.checkout_sha}", + event.user_name, + DateTimeUtil.formatMilliTime(event.pushTimestamp?.let { + DateTimeUtil.zoneDateToTimestamp(it) + } ?: LocalDateTime.now().timestampmilli())) + ) } override fun getExternalId(event: GitPushEvent): String { diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index d66234e01be..12f6000d9ce 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -28,9 +28,11 @@ package com.tencent.devops.process.dao import com.fasterxml.jackson.core.type.TypeReference +import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.timestamp import com.tencent.devops.common.api.util.timestampmilli +import com.tencent.devops.common.web.utils.I18nUtil.getCodeLanMessage import com.tencent.devops.model.process.tables.TPipelineTriggerDetail import com.tencent.devops.model.process.tables.TPipelineTriggerEvent import com.tencent.devops.model.process.tables.records.TPipelineTriggerDetailRecord @@ -407,7 +409,7 @@ class PipelineTriggerEventDao { triggerType = triggerType, triggerUser = triggerUser, eventType = eventType, - eventDesc = eventDesc, + eventDesc = JsonUtil.to(eventDesc, I18Variable::class.java).getCodeLanMessage(), hookRequestId = hookRequestId, requestParams = requestParams?.let { JsonUtil.to( diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index c5a8d0ed3fd..4452df349c6 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -358,3 +358,4 @@ bkQualityOut=Quality out bkBuildFinishedAndDenyPause=Build Finished And Deny Pause commonShutdownSuccessContent=【${%s}】- 【${%s}】#${%s} Execution succeed,consume time${%s}, trigger user: ${%s}。 commonShutdownFailureContent=【${%s}】- 【${%s}】#${%s} Execution failed,consume time${%s}, trigger user: ${%s}。 +bkTgitPushEventDesc=[{0}] commit [{1}] pushed by {2} {3} diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 1147ae58384..fb05e6cd8a7 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -357,4 +357,5 @@ bkQualityIn=质量红线(准入) bkQualityOut=质量红线(准出) bkBuildFinishedAndDenyPause=构建已结束,禁止暂停请求 commonShutdownSuccessContent=【${%s}】- 【${%s}】#${%s} 执行成功,耗时${%s}, 触发人: ${%s}。 -commonShutdownFailureContent=【${%s}】- 【${%s}】#${%s} 执行失败,耗时${%s}, 触发人: ${%s}。 \ No newline at end of file +commonShutdownFailureContent=【${%s}】- 【${%s}】#${%s} 执行失败,耗时${%s}, 触发人: ${%s}。 +bkTgitPushEventDesc=【{0}】提交【{1}】被{2}提交于 {3} \ No newline at end of file From 42299d3387d902ab6d1051a0342bad851f63f326 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Tue, 8 Aug 2023 10:16:26 +0800 Subject: [PATCH 010/143] =?UTF-8?q?feat=EF=BC=9A=E5=85=B3=E8=81=94?= =?UTF-8?q?=E5=B7=A5=E8=9C=82=E4=BB=A3=E7=A0=81=E5=BA=93=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=BC=80=E5=90=AF=20Pipeline=20as=20Code=20?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=20#8115?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/code/matcher/AbstractScmWebhookMatcher.kt | 3 ++- .../common/webhook/service/code/matcher/ScmWebhookMatcher.kt | 3 ++- .../tencent/devops/process/dao/PipelineTriggerEventDao.kt | 2 +- .../process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt | 5 +++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt index 813f906aa9a..31423d5b4b4 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt @@ -27,6 +27,7 @@ package com.tencent.devops.common.webhook.service.code.matcher +import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent import com.tencent.devops.common.webhook.service.code.loader.CodeWebhookHandlerRegistrar @@ -83,7 +84,7 @@ abstract class AbstractScmWebhookMatcher( return eventHandler.getMessage(event) } - override fun getEventDesc(): String { + override fun getEventDesc(): I18Variable { return eventHandler.getEventDesc(event) } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt index 718fbae741e..c3d5c907516 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt @@ -27,6 +27,7 @@ package com.tencent.devops.common.webhook.service.code.matcher +import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeType import com.tencent.devops.common.webhook.pojo.code.WebHookParams @@ -75,7 +76,7 @@ interface ScmWebhookMatcher { /** * 获取事件描述,根据不同的事件组织事件说明 */ - fun getEventDesc(): String = "" + fun getEventDesc(): I18Variable /** * 获取webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index 12f6000d9ce..f351ce2c89d 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -80,7 +80,7 @@ class PipelineTriggerEventDao { triggerEvent.eventSource, triggerEvent.eventType, triggerEvent.triggerUser, - triggerEvent.eventDesc, + JsonUtil.toJson(triggerEvent.eventDesc), triggerEvent.hookRequestId, triggerEvent.requestParams?.let { JsonUtil.toJson(it) }, triggerEvent.eventTime diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt index 8506f35727f..ae647e910b5 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt @@ -32,6 +32,7 @@ import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.readValue import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.exception.ErrorCodeException +import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.webhook.atom.IWebhookAtomTask import com.tencent.devops.common.webhook.pojo.WebhookRequest import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay @@ -82,7 +83,7 @@ class CodeGitWebhookTriggerTaskAtom @Autowired constructor( triggerType = getScmType().name, eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), - eventDesc = matcher.getEventDesc(), + eventDesc = JsonUtil.toJson(matcher.getEventDesc()), hookRequestId = requestId, eventTime = eventTime ) @@ -116,7 +117,7 @@ class CodeGitWebhookTriggerTaskAtom @Autowired constructor( triggerType = getScmType().name, eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), - eventDesc = matcher.getEventDesc(), + eventDesc = JsonUtil.toJson(matcher.getEventDesc()), hookRequestId = request.hookRequestId, eventTime = eventTime ) From fd2a1dae2ed33ca37272d60f4c538cbb2d53e592 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Tue, 8 Aug 2023 10:19:34 +0800 Subject: [PATCH 011/143] =?UTF-8?q?feat=EF=BC=9A=E5=85=B3=E8=81=94?= =?UTF-8?q?=E5=B7=A5=E8=9C=82=E4=BB=A3=E7=A0=81=E5=BA=93=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=BC=80=E5=90=AF=20Pipeline=20as=20Code=20?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=20#8115?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/code/handler/CodeWebhookTriggerHandler.kt | 2 +- .../service/code/handler/tgit/TGitPushTriggerHandler.kt | 6 ++++-- .../service/code/matcher/AbstractScmWebhookMatcher.kt | 2 +- .../webhook/service/code/matcher/ScmWebhookMatcher.kt | 2 +- .../process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt | 4 ++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt index 92d63dfbb3e..0eef601bb25 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt @@ -76,7 +76,7 @@ interface CodeWebhookTriggerHandler { /** * 获取事件说明,根据不同的事件组织事件说明 */ - fun getEventDesc(event: T): I18Variable + fun getEventDesc(event: T): String = "" /** * 获取webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt index f7490680d6a..78ef7f0e1f2 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt @@ -30,6 +30,7 @@ package com.tencent.devops.common.webhook.service.code.handler.tgit import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.util.DateTimeUtil +import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_ACTION @@ -131,8 +132,8 @@ class TGitPushTriggerHandler( } } - override fun getEventDesc(event: GitPushEvent): I18Variable { - return I18Variable( + override fun getEventDesc(event: GitPushEvent): String { + val i18Variable = I18Variable( code = TGIT_PUSH_EVENT_DESC, params = listOf( getBranchName(event), @@ -142,6 +143,7 @@ class TGitPushTriggerHandler( DateTimeUtil.zoneDateToTimestamp(it) } ?: LocalDateTime.now().timestampmilli())) ) + return JsonUtil.toJson(i18Variable) } override fun getExternalId(event: GitPushEvent): String { diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt index 31423d5b4b4..25c3a3d1e57 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt @@ -84,7 +84,7 @@ abstract class AbstractScmWebhookMatcher( return eventHandler.getMessage(event) } - override fun getEventDesc(): I18Variable { + override fun getEventDesc(): String { return eventHandler.getEventDesc(event) } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt index c3d5c907516..2aa4cd5bf37 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt @@ -76,7 +76,7 @@ interface ScmWebhookMatcher { /** * 获取事件描述,根据不同的事件组织事件说明 */ - fun getEventDesc(): I18Variable + fun getEventDesc(): String = "" /** * 获取webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt index ae647e910b5..888c4245b96 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt @@ -83,7 +83,7 @@ class CodeGitWebhookTriggerTaskAtom @Autowired constructor( triggerType = getScmType().name, eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), - eventDesc = JsonUtil.toJson(matcher.getEventDesc()), + eventDesc = matcher.getEventDesc(), hookRequestId = requestId, eventTime = eventTime ) @@ -117,7 +117,7 @@ class CodeGitWebhookTriggerTaskAtom @Autowired constructor( triggerType = getScmType().name, eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), - eventDesc = JsonUtil.toJson(matcher.getEventDesc()), + eventDesc = matcher.getEventDesc(), hookRequestId = request.hookRequestId, eventTime = eventTime ) From b6d658794b52795663bf78cb7f70db0dd53dbca6 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 8 Aug 2023 15:34:27 +0800 Subject: [PATCH 012/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/common/api/util/EnumUtil.kt | 418 +++++++++--------- .../webhook/enums/WebhookI18nConstants.kt | 67 ++- .../webhook/pojo/code/git/GitIssueEvent.kt | 4 + .../pojo/code/git/GitMergeRequestEvent.kt | 5 + .../webhook/pojo/code/git/GitReviewEvent.kt | 10 +- .../webhook/pojo/code/git/GitTagPushEvent.kt | 3 + .../webhook/pojo/code/svn/SvnCommitEvent.kt | 4 +- .../github/GithubCreateTriggerHandler.kt | 28 ++ .../handler/github/GithubPrTriggerHandler.kt | 24 + .../github/GithubPushTriggerHandler.kt | 29 ++ .../code/handler/p4/P4ChangeTriggerHandler.kt | 23 + .../code/handler/p4/P4ShelveTriggerHandler.kt | 23 + .../handler/svn/SvnCommitTriggerHandler.kt | 23 + .../handler/tgit/TGitIssueTriggerHandler.kt | 32 ++ .../code/handler/tgit/TGitMrTriggerHandler.kt | 54 +++ .../handler/tgit/TGitNoteTriggerHandler.kt | 19 + .../handler/tgit/TGitPushTriggerHandler.kt | 8 +- .../handler/tgit/TGitReviewTriggerHandler.kt | 29 ++ .../handler/tgit/TGitTagPushTriggerHandler.kt | 21 + .../tencent/devops/process/pojo/BuildId.kt | 4 +- .../engine/service/PipelineRuntimeService.kt | 3 +- .../process/api/ServiceBuildResourceImpl.kt | 37 +- .../process/api/UserBuildResourceImpl.kt | 26 +- .../service/PipelineRemoteAuthService.kt | 31 +- .../trigger/PipelineTriggerEventService.kt | 95 ++++ .../i18n/process/message_en_US.properties | 17 +- .../i18n/process/message_zh_CN.properties | 17 +- 27 files changed, 803 insertions(+), 251 deletions(-) diff --git a/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/util/EnumUtil.kt b/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/util/EnumUtil.kt index f30a88eb446..94d5042a8b6 100644 --- a/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/util/EnumUtil.kt +++ b/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/util/EnumUtil.kt @@ -1,209 +1,209 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package com.tencent.devops.common.api.util - -import sun.reflect.ConstructorAccessor -import sun.reflect.FieldAccessor -import sun.reflect.ReflectionFactory -import java.lang.reflect.AccessibleObject -import java.lang.reflect.Field -import java.lang.reflect.Modifier -import kotlin.reflect.full.isSubclassOf - -/** - * 枚举工具类,用于动态修改枚举值和内容 - * - */ -@Suppress("ALL") -object EnumUtil { - - /** - * 动态修改枚举,但动态范围仅限于后来使用枚举类的values或valueOf方法实例化出来的枚举值 - * - * 不支持动态替换:直接在代码中使用 MyEnum.APPLE.type 这种写法在编译期已经生成为常量,就无法实现动态替换了. - * 支持动态替换: MyEnum.valueOf("APPLE") MyEnum.values() 这种可以实现动态读取到 - * - * @param 枚举的泛型 - * @param enumType 要动态修改的枚举类 - * @param enumName 枚举值名称 - * @param additionalValues 枚举定义的其他字段的值,如果有,如果无传空数组 - */ - inline fun addEnum(enumType: Class, enumName: String, additionalValues: Array) { - - // 检查是否是枚举类型,如果不是则抛出异常 - if (!Enum::class.java.isAssignableFrom(enumType)) { - throw RuntimeException("class $enumType is not an instance of Enum") - } - // 1. Lookup "$VALUES" holder in enum class and get previous enum instances - var valuesField: Field? = null - val fields: Array = enumType.declaredFields - for (field in fields) { - if (field.name.contains("\$VALUES")) { - valuesField = field - break - } - } - - val additionalTypes = mutableListOf>() - additionalValues.forEach { value -> - when { - // kotlin 中 List可变mutable与不可变immutable是两个不同的接口,需要区分对待 - value::class.isSubclassOf(MutableList::class) -> additionalTypes.add(MutableList::class.java) - // 赋值时注意其他Java对List的各种扩展子类,都转为List - value::class.isSubclassOf(List::class) -> additionalTypes.add(List::class.java) - // 其他场景暂时未覆盖完 - else -> additionalTypes.add(value::class.java) - } - } - - AccessibleObject.setAccessible(arrayOf(valuesField), true) - - try { - // 将先之前的枚举值保存下来 - val previousValues = valuesField!![enumType] as Array - - val values: MutableList = mutableListOf() - var ordinal = previousValues.size - - previousValues.forEachIndexed { idx, value -> - // 如果是存在的枚举值,则服它替换旧值 - if (value.toString() == enumName) { - ordinal = idx - } - values.add(value) - } - - // 构建新枚举值 - val newValue: T = makeEnum( - enumClass = enumType, - value = enumName, - ordinal = ordinal, - additionalTypes = additionalTypes.toTypedArray(), - additionalValues = additionalValues - ) - - if (ordinal < previousValues.size) { - values[ordinal] = newValue - } else { - values.add(newValue) - } - - setFailSafeFieldValue(field = valuesField, target = null, value = values.toTypedArray()) - - cleanEnumCache(enumType) - } catch (e: Exception) { - println(e) - e.printStackTrace() - throw RuntimeException(e.message, e) - } - } - - @Throws(NoSuchFieldException::class, IllegalAccessException::class) - fun setFailSafeFieldValue(field: Field, target: Any?, value: Any?) { - field.isAccessible = true - val modifiersField: Field = Field::class.java.getDeclaredField("modifiers") - modifiersField.isAccessible = true - var modifiers: Int = modifiersField.getInt(field) - modifiers = modifiers and Modifier.FINAL.inv() - modifiersField.setInt(field, modifiers) - val fieldAccessor: FieldAccessor = reflectionFactory.newFieldAccessor(field, false) - fieldAccessor.set(target, value) - } - - @Throws(NoSuchFieldException::class, IllegalAccessException::class) - inline fun blankField(enumClass: Class, fieldName: String) { - for (field in Class::class.java.declaredFields) { - if (field.name.contains(fieldName)) { - setFailSafeFieldValue(field, enumClass, null) - break - } - } - } - - @Throws(NoSuchFieldException::class, IllegalAccessException::class) - inline fun cleanEnumCache(enumClass: Class) { - blankField(enumClass, "enumConstantDirectory") // OracleJDK & OpenJDK - blankField(enumClass, "enumConstants") // IBM JDK - } - - @Throws(NoSuchMethodException::class) - inline fun getConstructorAccessor( - enumClass: Class, - additionalParameterTypes: Array> - ): ConstructorAccessor? { - val parameterTypes = arrayOfNulls?>(additionalParameterTypes.size + 2) - parameterTypes[0] = String::class.java // enum class first field: field name - parameterTypes[1] = Int::class.javaPrimitiveType // enum class second field: ordinal - System.arraycopy(additionalParameterTypes, 0, parameterTypes, 2, additionalParameterTypes.size) - enumClass.declaredConstructors.forEach { constructor -> - if (compareParameterType(constructor.parameterTypes, parameterTypes)) { - try { - return reflectionFactory.newConstructorAccessor(constructor) - } catch (ignored: IllegalArgumentException) { - // skip illegal argument try next one - } - } - } - - return reflectionFactory.newConstructorAccessor(enumClass.getDeclaredConstructor(*parameterTypes)) - } - - fun compareParameterType(constructorParameterType: Array>, parameterTypes: Array?>): Boolean { - if (constructorParameterType.size != parameterTypes.size) { - return false - } - for (i in constructorParameterType.indices) { - if (constructorParameterType[i] !== parameterTypes[i]) { - if (constructorParameterType[i].isPrimitive && parameterTypes[i]!!.isPrimitive) { - if (constructorParameterType[i].kotlin.javaPrimitiveType - !== parameterTypes[i]!!.kotlin.javaPrimitiveType) { - return false - } - } - } - } - return true - } - - @Throws(Exception::class) - inline fun makeEnum( - enumClass: Class, - value: String, - ordinal: Int, - additionalTypes: Array>, - additionalValues: Array - ): T { - val params = arrayOfNulls(additionalValues.size + 2) - params[0] = value - params[1] = Integer.valueOf(ordinal) - System.arraycopy(additionalValues, 0, params, 2, additionalValues.size) - return enumClass.cast(getConstructorAccessor(enumClass, additionalTypes)!!.newInstance(params)) - } - - val reflectionFactory: ReflectionFactory = ReflectionFactory.getReflectionFactory() -} +///* +// * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. +// * +// * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. +// * +// * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. +// * +// * A copy of the MIT License is included in this file. +// * +// * +// * Terms of the MIT License: +// * --------------------------------------------------- +// * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +// * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the +// * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +// * permit persons to whom the Software is furnished to do so, subject to the following conditions: +// * +// * The above copyright notice and this permission notice shall be included in all copies or substantial portions of +// * the Software. +// * +// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +// * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// */ +// +//package com.tencent.devops.common.api.util +// +//import sun.reflect.ConstructorAccessor +//import sun.reflect.FieldAccessor +//import sun.reflect.ReflectionFactory +//import java.lang.reflect.AccessibleObject +//import java.lang.reflect.Field +//import java.lang.reflect.Modifier +//import kotlin.reflect.full.isSubclassOf +// +///** +// * 枚举工具类,用于动态修改枚举值和内容 +// * +// */ +//@Suppress("ALL") +//object EnumUtil { +// +// /** +// * 动态修改枚举,但动态范围仅限于后来使用枚举类的values或valueOf方法实例化出来的枚举值 +// * +// * 不支持动态替换:直接在代码中使用 MyEnum.APPLE.type 这种写法在编译期已经生成为常量,就无法实现动态替换了. +// * 支持动态替换: MyEnum.valueOf("APPLE") MyEnum.values() 这种可以实现动态读取到 +// * +// * @param 枚举的泛型 +// * @param enumType 要动态修改的枚举类 +// * @param enumName 枚举值名称 +// * @param additionalValues 枚举定义的其他字段的值,如果有,如果无传空数组 +// */ +// inline fun addEnum(enumType: Class, enumName: String, additionalValues: Array) { +// +// // 检查是否是枚举类型,如果不是则抛出异常 +// if (!Enum::class.java.isAssignableFrom(enumType)) { +// throw RuntimeException("class $enumType is not an instance of Enum") +// } +// // 1. Lookup "$VALUES" holder in enum class and get previous enum instances +// var valuesField: Field? = null +// val fields: Array = enumType.declaredFields +// for (field in fields) { +// if (field.name.contains("\$VALUES")) { +// valuesField = field +// break +// } +// } +// +// val additionalTypes = mutableListOf>() +// additionalValues.forEach { value -> +// when { +// // kotlin 中 List可变mutable与不可变immutable是两个不同的接口,需要区分对待 +// value::class.isSubclassOf(MutableList::class) -> additionalTypes.add(MutableList::class.java) +// // 赋值时注意其他Java对List的各种扩展子类,都转为List +// value::class.isSubclassOf(List::class) -> additionalTypes.add(List::class.java) +// // 其他场景暂时未覆盖完 +// else -> additionalTypes.add(value::class.java) +// } +// } +// +// AccessibleObject.setAccessible(arrayOf(valuesField), true) +// +// try { +// // 将先之前的枚举值保存下来 +// val previousValues = valuesField!![enumType] as Array +// +// val values: MutableList = mutableListOf() +// var ordinal = previousValues.size +// +// previousValues.forEachIndexed { idx, value -> +// // 如果是存在的枚举值,则服它替换旧值 +// if (value.toString() == enumName) { +// ordinal = idx +// } +// values.add(value) +// } +// +// // 构建新枚举值 +// val newValue: T = makeEnum( +// enumClass = enumType, +// value = enumName, +// ordinal = ordinal, +// additionalTypes = additionalTypes.toTypedArray(), +// additionalValues = additionalValues +// ) +// +// if (ordinal < previousValues.size) { +// values[ordinal] = newValue +// } else { +// values.add(newValue) +// } +// +// setFailSafeFieldValue(field = valuesField, target = null, value = values.toTypedArray()) +// +// cleanEnumCache(enumType) +// } catch (e: Exception) { +// println(e) +// e.printStackTrace() +// throw RuntimeException(e.message, e) +// } +// } +// +// @Throws(NoSuchFieldException::class, IllegalAccessException::class) +// fun setFailSafeFieldValue(field: Field, target: Any?, value: Any?) { +// field.isAccessible = true +// val modifiersField: Field = Field::class.java.getDeclaredField("modifiers") +// modifiersField.isAccessible = true +// var modifiers: Int = modifiersField.getInt(field) +// modifiers = modifiers and Modifier.FINAL.inv() +// modifiersField.setInt(field, modifiers) +// val fieldAccessor: FieldAccessor = reflectionFactory.newFieldAccessor(field, false) +// fieldAccessor.set(target, value) +// } +// +// @Throws(NoSuchFieldException::class, IllegalAccessException::class) +// inline fun blankField(enumClass: Class, fieldName: String) { +// for (field in Class::class.java.declaredFields) { +// if (field.name.contains(fieldName)) { +// setFailSafeFieldValue(field, enumClass, null) +// break +// } +// } +// } +// +// @Throws(NoSuchFieldException::class, IllegalAccessException::class) +// inline fun cleanEnumCache(enumClass: Class) { +// blankField(enumClass, "enumConstantDirectory") // OracleJDK & OpenJDK +// blankField(enumClass, "enumConstants") // IBM JDK +// } +// +// @Throws(NoSuchMethodException::class) +// inline fun getConstructorAccessor( +// enumClass: Class, +// additionalParameterTypes: Array> +// ): ConstructorAccessor? { +// val parameterTypes = arrayOfNulls?>(additionalParameterTypes.size + 2) +// parameterTypes[0] = String::class.java // enum class first field: field name +// parameterTypes[1] = Int::class.javaPrimitiveType // enum class second field: ordinal +// System.arraycopy(additionalParameterTypes, 0, parameterTypes, 2, additionalParameterTypes.size) +// enumClass.declaredConstructors.forEach { constructor -> +// if (compareParameterType(constructor.parameterTypes, parameterTypes)) { +// try { +// return reflectionFactory.newConstructorAccessor(constructor) +// } catch (ignored: IllegalArgumentException) { +// // skip illegal argument try next one +// } +// } +// } +// +// return reflectionFactory.newConstructorAccessor(enumClass.getDeclaredConstructor(*parameterTypes)) +// } +// +// fun compareParameterType(constructorParameterType: Array>, parameterTypes: Array?>): Boolean { +// if (constructorParameterType.size != parameterTypes.size) { +// return false +// } +// for (i in constructorParameterType.indices) { +// if (constructorParameterType[i] !== parameterTypes[i]) { +// if (constructorParameterType[i].isPrimitive && parameterTypes[i]!!.isPrimitive) { +// if (constructorParameterType[i].kotlin.javaPrimitiveType +// !== parameterTypes[i]!!.kotlin.javaPrimitiveType) { +// return false +// } +// } +// } +// } +// return true +// } +// +// @Throws(Exception::class) +// inline fun makeEnum( +// enumClass: Class, +// value: String, +// ordinal: Int, +// additionalTypes: Array>, +// additionalValues: Array +// ): T { +// val params = arrayOfNulls(additionalValues.size + 2) +// params[0] = value +// params[1] = Integer.valueOf(ordinal) +// System.arraycopy(additionalValues, 0, params, 2, additionalValues.size) +// return enumClass.cast(getConstructorAccessor(enumClass, additionalTypes)!!.newInstance(params)) +// } +// +// val reflectionFactory: ReflectionFactory = ReflectionFactory.getReflectionFactory() +//} diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt index ccd244e296f..895335c3502 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt @@ -29,6 +29,71 @@ package com.tencent.devops.common.webhook.enums object WebhookI18nConstants { + // 工蜂事件描述 const val TGIT_PUSH_EVENT_DESC = "bkTgitPushEventDesc" - + const val TGIT_ISSUE_CREATED_EVENT_DESC = "bkTgitIssueCreatedEventDesc" + const val TGIT_ISSUE_UPDATED_EVENT_DESC = "bkTgitIssueUpdatedEventDesc" + const val TGIT_ISSUE_CLOSED_EVENT_DESC = "bkTgitIssueClosedEventDesc" + const val TGIT_ISSUE_REOPENED_EVENT_DESC = "bkTgitIssueReopenedEventDesc" + const val TGIT_MR_CREATED_EVENT_DESC = "bkTgitMrCreatedEventDesc" + const val TGIT_MR_UPDATED_EVENT_DESC = "bkTgitMrUpdatedEventDesc" + const val TGIT_MR_CLOSED_EVENT_DESC = "bkTgitMrClosedEventDesc" + const val TGIT_MR_REOPENED_EVENT_DESC = "bkTgitMrReopenedEventDesc" + const val TGIT_MR_PUSH_UPDATED_EVENT_DESC = "bkTgitMrPushUpdatedEventDesc" + const val TGIT_MR_MERGED_EVENT_DESC = "bkTgitMrCreateEventDesc" + const val TGIT_NOTE_EVENT_DESC = "bkTgitNoteEventDesc" + const val TGIT_REVIEW_APPROVED_EVENT_DESC = "bkTgitReviewApprovedEventDesc" + const val TGIT_REVIEW_APPROVING_EVENT_DESC = "bkTgitReviewApprovingEventDesc" + const val TGIT_REVIEW_CHANGE_DENIED_EVENT_DESC = "bkTgitReviewChangeDeniedEventDesc" + const val TGIT_REVIEW_CHANGE_REQUIRED_EVENT_DESC = "bkTgitReviewChangeRequiredEventDesc" + const val TGIT_TAG_PUSH_EVENT_DESC = "bkTgitTagPushEventDesc" + // Github事件描述 + const val GITHUB_PUSH_EVENT_DESC = "bkGithubPushEventDesc" + const val GITHUB_CREATE_EVENT_DESC = "bkGithubCreateEventDesc" + const val GITHUB_PR_EVENT_DESC = "bkGithubPrEventDesc" + // P4事件描述 + const val P4_Change_EVENT_DESC = "bkP4CreateEventDesc" + const val P4_Shelve_EVENT_DESC = "bkP4ShelveEventDesc" + // SVN事件描述 + const val SVN_COMMIT_EVENT_DESC = "bkSvnShelveEventDesc" + // 手动触发 + const val MANUAL_START_EVENT_DESC = "bkManualStartEventDesc" + // 远程触发 + const val REMOTE_START_EVENT_DESC = "bkManualStartEventDesc" + // openApi触发 + const val SERVICE_START_EVENT_DESC = "bkManualStartEventDesc" + // 事件类型匹配 + const val EVENT_TYPE_MATCHED="bkRepoTriggerEventTypeMatched" + // 事件类型不匹配 + const val EVENT_TYPE_NOT_MATCH="bkRepoTriggerEventTypeNotMatch" + // 目标分支不匹配 + const val TARGET_BRANCH_NOT_MATCH = "bkRepoTriggerTargetBranchNotMatch" + // 目标分支被排除 + const val TARGET_BRANCH_IGNORED = "bkRepoTriggerTargetBranchIgnored" + // 源分支不匹配 + const val SOURCE_BRANCH_NOT_MATCH = "bkRepoTriggerSourceBranchNotMatch" + // 源分支被排除 + const val SOURCE_BRANCH_IGNORED = "bkRepoTriggerSourceBranchIgnored" + // 用户不匹配 + const val USER_NOT_MATCH = "bkRepoTriggerUserNotMatch" + // 用户被排除 + const val USER_IGNORED = "bkRepoTriggerUserIgnored" + // 路径不匹配 + const val PATH_NOT_MATCH = "bkRepoTriggerPathNotMatch" + // 路径被排除 + const val PATH_IGNORED = "bkRepoTriggerPathIgnored" + // Tag名称不匹配 + const val TAG_NAME_NOT_MATCH = "bkRepoTriggerTagNameNotMatch" + // Tag名称被排除 + const val TAG_NAME_IGNORED = "bkRepoTriggerTagNameIgnored" + // Tag来源分支不匹配 + const val TAG_SOURCE_BRANCH_NOT_MATCH = "bkRepoTriggerTagSourceBranchNotMatch" + // 评论内容不匹配 + const val NOTE_CONTENT_IGNORED = "bkRepoTriggerNoteContentNotMatch" + // 评论类型不匹配 + const val NOTE_ACTION_IGNORED = "bkRepoTriggerNoteActionNotMatch" + // 评审操作类型不匹配 + const val REVIEW_ACTION_IGNORED = "bkRepoTriggerReviewActionNotMatch" + // issues操作类型不匹配 + const val ISSUES_ACTION_IGNORED = "bkRepoTriggerNoteActionNotMatch" } diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitIssueEvent.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitIssueEvent.kt index a3f6702a61a..fd8fece88f8 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitIssueEvent.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitIssueEvent.kt @@ -39,6 +39,10 @@ data class GitIssueEvent( ) : GitEvent() { companion object { const val classType = "issue" + const val ACTION_CREATED = "open" + const val ACTION_UPDATED = "update" + const val ACTION_CLOSED = "close" + const val ACTION_REOPENED = "reopen" } } diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitMergeRequestEvent.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitMergeRequestEvent.kt index 53438d4d7cf..8ec0a48540d 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitMergeRequestEvent.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitMergeRequestEvent.kt @@ -39,6 +39,11 @@ data class GitMergeRequestEvent( ) : GitEvent() { companion object { const val classType = "merge_request" + const val ACTION_CREATED = "open" + const val ACTION_UPDATED = "update" + const val ACTION_CLOSED = "close" + const val ACTION_REOPENED = "reopen" + const val ACTION_MERGED = "merge" } } diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitReviewEvent.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitReviewEvent.kt index 8ff3a76a677..8da55f58949 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitReviewEvent.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitReviewEvent.kt @@ -55,10 +55,18 @@ data class GitReviewEvent( val commitId: String? = null, val state: String, @JsonProperty("restrict_type") - val restrictType: String? = null + val restrictType: String? = null, + @JsonProperty("created_at") + val createdAt: String, + @JsonProperty("updated_at") + val updatedAt: String, ) : GitEvent() { companion object { const val classType = "review" + const val ACTION_APPROVED = "approved" + const val ACTION_APPROVING = "approving" + const val ACTION_CHANGE_DENIED = "change_denied" + const val ACTION_CHANGE_REQUIRED = "change_required" } } diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitTagPushEvent.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitTagPushEvent.kt index ab9bb938179..ab861620d5c 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitTagPushEvent.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitTagPushEvent.kt @@ -28,6 +28,7 @@ package com.tencent.devops.common.webhook.pojo.code.git import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonProperty import com.tencent.devops.common.webhook.enums.code.tgit.TGitTagPushActionKind import com.tencent.devops.common.webhook.enums.code.tgit.TGitTagPushOperationKind @@ -46,6 +47,8 @@ data class GitTagPushEvent( val total_commits_count: Int, val operation_kind: String?, val create_from: String? = null, + @JsonProperty("push_timestamp") + val pushTimestamp: String?, val message: String? ) : GitEvent() { companion object { diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/svn/SvnCommitEvent.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/svn/SvnCommitEvent.kt index fa542d74ad4..6c3660497ea 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/svn/SvnCommitEvent.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/svn/SvnCommitEvent.kt @@ -29,6 +29,7 @@ package com.tencent.devops.common.webhook.pojo.code.svn import com.fasterxml.jackson.annotation.JsonIgnoreProperties import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent +import com.tencent.devops.common.webhook.pojo.code.git.GitCommitRepository @Suppress("ALL") @JsonIgnoreProperties(ignoreUnknown = true) @@ -40,5 +41,6 @@ data class SvnCommitEvent( val revision: Int, val paths: List, val files: List, - val commitTime: Long? + val commitTime: Long?, + val repository: GitCommitRepository ) : CodeWebhookEvent diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt index 591dadc1504..87f5a8ad93d 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt @@ -27,8 +27,13 @@ package com.tencent.devops.common.webhook.service.code.handler.github +import com.tencent.devops.common.api.pojo.I18Variable +import com.tencent.devops.common.api.util.DateTimeUtil +import com.tencent.devops.common.api.util.JsonUtil +import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GITHUB_WEBHOOK_CREATE_REF_NAME import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GITHUB_WEBHOOK_CREATE_REF_TYPE import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GITHUB_WEBHOOK_CREATE_USERNAME @@ -38,6 +43,7 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.GitHookTriggerHandler import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils +import java.time.LocalDateTime @CodeWebhookHandler class GithubCreateTriggerHandler : GitHookTriggerHandler { @@ -73,6 +79,28 @@ class GithubCreateTriggerHandler : GitHookTriggerHandler { return "" } + override fun getEventDesc(event: GithubCreateEvent): String { + val linkUrl = if (event.ref_type == "tag") { + "https://github.com/${event.repository.fullName}/releases/tag/${event.ref}" + } else { + "https://github.com/${event.repository.fullName}/tree/${event.ref}" + } + val i18Variable = I18Variable( + code = WebhookI18nConstants.GITHUB_CREATE_EVENT_DESC, + params = listOf( + getBranchName(event), + linkUrl, + getUsername(event), + DateTimeUtil.formatMilliTime(LocalDateTime.now().timestampmilli()) + ) + ) + return JsonUtil.toJson(i18Variable) + } + + override fun getExternalId(event: GithubCreateEvent): String { + return event.repository.id.toString() + } + override fun retrieveParams( event: GithubCreateEvent, projectId: String?, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt index 1b3a454ffba..3715fd39e7d 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt @@ -27,6 +27,10 @@ package com.tencent.devops.common.webhook.service.code.handler.github +import com.tencent.devops.common.api.pojo.I18Variable +import com.tencent.devops.common.api.util.DateTimeUtil +import com.tencent.devops.common.api.util.JsonUtil +import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_ACTION import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_BASE_REF @@ -45,6 +49,7 @@ import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_MR_TITLE import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_MR_URL import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_REPO_URL import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_MR_ASSIGNEE import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_MR_AUTHOR import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_MR_CREATE_TIME @@ -87,6 +92,7 @@ import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils import org.slf4j.LoggerFactory +import java.time.LocalDateTime @CodeWebhookHandler @SuppressWarnings("TooManyFunctions") @@ -128,6 +134,24 @@ class GithubPrTriggerHandler : GitHookTriggerHandler { return "" } + override fun getEventDesc(event: GithubPullRequestEvent): String { + val i18Variable = I18Variable( + code = WebhookI18nConstants.GITHUB_PR_EVENT_DESC, + params = listOf( + event.pullRequest.title, + event.pullRequest.url, + getUsername(event), + DateTimeUtil.formatMilliTime(event.pullRequest.updatedAt?.let { + DateTimeUtil.zoneDateToTimestamp(it) + } ?: LocalDateTime.now().timestampmilli())) + ) + return JsonUtil.toJson(i18Variable) + } + + override fun getExternalId(event: GithubPullRequestEvent): String { + return event.repository.id.toString() + } + override fun getEnv(event: GithubPullRequestEvent): Map { return mapOf(GITHUB_PR_NUMBER to event.number) } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt index 96e8d2f5021..af737cf50d5 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt @@ -27,6 +27,10 @@ package com.tencent.devops.common.webhook.service.code.handler.github +import com.tencent.devops.common.api.pojo.I18Variable +import com.tencent.devops.common.api.util.DateTimeUtil +import com.tencent.devops.common.api.util.JsonUtil +import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_ACTION import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_BEFORE_SHA @@ -37,6 +41,7 @@ import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_EVENT_URL import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_REF import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_REPO_URL import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.enums.code.github.GithubPushOperationKind import com.tencent.devops.common.webhook.enums.code.tgit.TGitPushActionType import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_BRANCH @@ -52,6 +57,7 @@ import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.pojo.code.git.GitCommit import com.tencent.devops.common.webhook.pojo.code.git.GitCommitAuthor import com.tencent.devops.common.webhook.pojo.code.git.GitPushEvent +import com.tencent.devops.common.webhook.pojo.code.github.GithubPullRequestEvent import com.tencent.devops.common.webhook.pojo.code.github.GithubPushEvent import com.tencent.devops.common.webhook.service.code.filter.BranchFilter import com.tencent.devops.common.webhook.service.code.filter.UserFilter @@ -62,6 +68,7 @@ import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils import org.slf4j.LoggerFactory +import java.time.LocalDateTime @CodeWebhookHandler @Suppress("TooManyFunctions") @@ -103,6 +110,28 @@ class GithubPushTriggerHandler : GitHookTriggerHandler { return event.headCommit?.message ?: "" } + override fun getEventDesc(event: GithubPushEvent): String { + val linkUrl = if (event.headCommit != null) { + "https://github.com/${event.repository.fullName}/commit/${event.headCommit?.id}" + } else { + "https://github.com/${event.repository.fullName}/commit/${getBranchName(event)}" + } + val i18Variable = I18Variable( + code = WebhookI18nConstants.GITHUB_PUSH_EVENT_DESC, + params = listOf( + getBranchName(event), + linkUrl, + getUsername(event), + DateTimeUtil.formatMilliTime(LocalDateTime.now().timestampmilli()) + ) + ) + return JsonUtil.toJson(i18Variable) + } + + override fun getExternalId(event: GithubPushEvent): String { + return event.repository.id.toString() + } + override fun preMatch(event: GithubPushEvent): WebhookMatchResult { if (event.commits.isEmpty()) { logger.info("Github web hook no commit") diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt index 121726aafb0..652a86eb3c6 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt @@ -27,9 +27,14 @@ package com.tencent.devops.common.webhook.service.code.handler.p4 +import com.tencent.devops.common.api.pojo.I18Variable +import com.tencent.devops.common.api.util.DateTimeUtil +import com.tencent.devops.common.api.util.JsonUtil +import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.PathFilterType import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.pojo.code.BK_REPO_P4_WEBHOOK_CHANGE import com.tencent.devops.common.webhook.pojo.code.PathFilterConfig import com.tencent.devops.common.webhook.pojo.code.WebHookParams @@ -43,6 +48,7 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilterRespon import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository +import java.time.LocalDateTime @CodeWebhookHandler @SuppressWarnings("TooManyFunctions") @@ -79,6 +85,23 @@ class P4ChangeTriggerHandler( override fun getMessage(event: P4ChangeEvent) = "" + override fun getEventDesc(event: P4ChangeEvent): String { + val i18Variable = I18Variable( + code = WebhookI18nConstants.P4_Change_EVENT_DESC, + params = listOf( + getRevision(event), + "", + getUsername(event), + DateTimeUtil.formatMilliTime(LocalDateTime.now().timestampmilli()) + ) + ) + return JsonUtil.toJson(i18Variable) + } + + override fun getExternalId(event: P4ChangeEvent): String { + return event.p4Port + } + override fun getWebhookFilters( event: P4ChangeEvent, projectId: String, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt index a71af276483..b0afd93cc86 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt @@ -27,10 +27,15 @@ package com.tencent.devops.common.webhook.service.code.handler.p4 +import com.tencent.devops.common.api.pojo.I18Variable +import com.tencent.devops.common.api.util.DateTimeUtil +import com.tencent.devops.common.api.util.JsonUtil +import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.client.Client import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.PathFilterType import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.pojo.code.BK_REPO_P4_WEBHOOK_CHANGE import com.tencent.devops.common.webhook.pojo.code.PathFilterConfig import com.tencent.devops.common.webhook.pojo.code.WebHookParams @@ -44,6 +49,7 @@ import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTrigger import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.api.ServiceP4Resource import com.tencent.devops.repository.pojo.Repository +import java.time.LocalDateTime @CodeWebhookHandler @SuppressWarnings("TooManyFunctions") @@ -80,6 +86,23 @@ class P4ShelveTriggerHandler( override fun getMessage(event: P4ShelveEvent) = "" + override fun getEventDesc(event: P4ShelveEvent): String { + val i18Variable = I18Variable( + code = WebhookI18nConstants.P4_Shelve_EVENT_DESC, + params = listOf( + getRevision(event), + "", + getUsername(event), + DateTimeUtil.formatMilliTime(LocalDateTime.now().timestampmilli()) + ) + ) + return JsonUtil.toJson(i18Variable) + } + + override fun getExternalId(event: P4ShelveEvent): String { + return event.p4Port + } + override fun getWebhookFilters( event: P4ShelveEvent, projectId: String, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt index 205166dab1a..ff4365897ab 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt @@ -27,9 +27,14 @@ package com.tencent.devops.common.webhook.service.code.handler.svn +import com.tencent.devops.common.api.pojo.I18Variable +import com.tencent.devops.common.api.util.DateTimeUtil +import com.tencent.devops.common.api.util.JsonUtil +import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.PathFilterType import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.pojo.code.BK_REPO_SVN_WEBHOOK_COMMIT_TIME import com.tencent.devops.common.webhook.pojo.code.BK_REPO_SVN_WEBHOOK_REVERSION import com.tencent.devops.common.webhook.pojo.code.BK_REPO_SVN_WEBHOOK_USERNAME @@ -43,6 +48,7 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository +import java.time.LocalDateTime @CodeWebhookHandler @SuppressWarnings("TooManyFunctions") @@ -79,6 +85,23 @@ class SvnCommitTriggerHandler : CodeWebhookTriggerHandler { return event.log } + override fun getEventDesc(event: SvnCommitEvent): String { + val i18Variable = I18Variable( + code = WebhookI18nConstants.SVN_COMMIT_EVENT_DESC, + params = listOf( + getBranchName(event), + "", + getUsername(event), + DateTimeUtil.formatMilliTime(LocalDateTime.now().timestampmilli()) + ) + ) + return JsonUtil.toJson(i18Variable) + } + + override fun getExternalId(event: SvnCommitEvent): String { + return event.rep_name + } + override fun getWebhookFilters( event: SvnCommitEvent, projectId: String, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt index 0dd395b6ca5..2891ff3645e 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt @@ -27,6 +27,8 @@ package com.tencent.devops.common.webhook.service.code.handler.tgit +import com.tencent.devops.common.api.pojo.I18Variable +import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_COMMIT_AUTHOR import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_EVENT @@ -36,6 +38,7 @@ import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_REPO_URL import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_SHA import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_SHA_SHORT import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_ISSUE_ACTION import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_ISSUE_DESCRIPTION import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_ISSUE_ID @@ -55,6 +58,7 @@ import com.tencent.devops.common.webhook.service.code.handler.GitHookTriggerHand import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils +import java.time.LocalDateTime @CodeWebhookHandler class TGitIssueTriggerHandler( @@ -93,6 +97,26 @@ class TGitIssueTriggerHandler( return event.objectAttributes.title } + override fun getEventDesc(event: GitIssueEvent): String { + val i18Variable = I18Variable( + code = getI18Code(event), + params = listOf( + "${event.objectAttributes.url}", + event.objectAttributes.iid, + getUsername(event) + ) + ) + return JsonUtil.toJson(i18Variable) + } + + override fun getExternalId(event: GitIssueEvent): String { + return event.objectAttributes.projectId.toString() + } + + override fun getAction(event: GitIssueEvent): String? { + return event.objectAttributes.action + } + override fun retrieveParams(event: GitIssueEvent, projectId: String?, repository: Repository?): Map { val startParams = mutableMapOf() with(event.objectAttributes) { @@ -139,4 +163,12 @@ class TGitIssueTriggerHandler( ) return listOf(actionFilter) } + + private fun getI18Code(event: GitIssueEvent) = when (getAction(event)) { + GitIssueEvent.ACTION_CREATED -> WebhookI18nConstants.TGIT_ISSUE_CREATED_EVENT_DESC + GitIssueEvent.ACTION_UPDATED -> WebhookI18nConstants.TGIT_ISSUE_UPDATED_EVENT_DESC + GitIssueEvent.ACTION_CLOSED -> WebhookI18nConstants.TGIT_ISSUE_CLOSED_EVENT_DESC + GitIssueEvent.ACTION_REOPENED -> WebhookI18nConstants.TGIT_ISSUE_REOPENED_EVENT_DESC + else -> "" + } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt index a2d105f6d86..da469ae2742 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt @@ -28,7 +28,9 @@ package com.tencent.devops.common.webhook.service.code.handler.tgit import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.util.DateTimeUtil +import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_ACTION import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_BASE_REF @@ -47,6 +49,7 @@ import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_MR_TITLE import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_MR_URL import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_REPO_URL import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.enums.code.tgit.TGitMrEventAction import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_MANUAL_UNLOCK import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_MR_LAST_COMMIT @@ -94,6 +97,8 @@ import com.tencent.devops.scm.utils.code.git.GitUtils import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter import java.util.Date @CodeWebhookHandler @@ -158,6 +163,22 @@ class TGitMrTriggerHandler( return event.object_attributes.id } + override fun getEventDesc(event: GitMergeRequestEvent): String { + val i18Variable = I18Variable( + code = getI18Code(event), + params = listOf( + "${event.object_attributes.url}", + event.object_attributes.iid.toString(), + getUsername(event) + ) + ) + return JsonUtil.toJson(i18Variable) + } + + override fun getExternalId(event: GitMergeRequestEvent): String { + return event.object_attributes.target_project_id.toString() + } + override fun getEnv(event: GitMergeRequestEvent): Map { return mapOf( GIT_MR_NUMBER to event.object_attributes.iid, @@ -410,4 +431,37 @@ class TGitMrTriggerHandler( mrRequestId = mrRequestId ) } + + private fun getI18Code(event: GitMergeRequestEvent) = with(getAction(event)) { + when { + this == GitMergeRequestEvent.ACTION_CLOSED -> { + WebhookI18nConstants.TGIT_MR_CLOSED_EVENT_DESC + } + + this == GitMergeRequestEvent.ACTION_CREATED -> { + WebhookI18nConstants.TGIT_MR_CREATED_EVENT_DESC + } + // MR源分支提交更新 + (this == GitMergeRequestEvent.ACTION_UPDATED && + event.object_attributes.extension_action == "push-update") -> { + WebhookI18nConstants.TGIT_MR_PUSH_UPDATED_EVENT_DESC + } + // MR更新 + this == GitMergeRequestEvent.ACTION_UPDATED -> { + WebhookI18nConstants.TGIT_MR_UPDATED_EVENT_DESC + } + + this == GitMergeRequestEvent.ACTION_REOPENED -> { + WebhookI18nConstants.TGIT_MR_REOPENED_EVENT_DESC + } + + this == GitMergeRequestEvent.ACTION_MERGED -> { + WebhookI18nConstants.TGIT_MR_MERGED_EVENT_DESC + } + + else -> { + "" + } + } + } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt index bdb016634ad..36f49fbe9a8 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt @@ -27,6 +27,8 @@ package com.tencent.devops.common.webhook.service.code.handler.tgit +import com.tencent.devops.common.api.pojo.I18Variable +import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_BEFORE_SHA import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_BEFORE_SHA_SHORT @@ -40,6 +42,7 @@ import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_REPO_URL import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_SHA import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_SHA_SHORT import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_ISSUE_DESCRIPTION import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_ISSUE_ID import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_ISSUE_IID @@ -117,6 +120,22 @@ class TGitNoteTriggerHandler( return event.objectAttributes.note } + override fun getEventDesc(event: GitNoteEvent): String { + val i18Variable = I18Variable( + code = WebhookI18nConstants.TGIT_NOTE_EVENT_DESC, + params = listOf( + event.objectAttributes.url, + event.objectAttributes.note, + getUsername(event) + ) + ) + return JsonUtil.toJson(i18Variable) + } + + override fun getExternalId(event: GitNoteEvent): String { + return event.objectAttributes.projectId.toString() + } + @SuppressWarnings("ComplexMethod", "LongMethod") override fun retrieveParams(event: GitNoteEvent, projectId: String?, repository: Repository?): Map { val startParams = mutableMapOf() diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt index 78ef7f0e1f2..0662ee9835a 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt @@ -31,7 +31,6 @@ import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.util.DateTimeUtil import com.tencent.devops.common.api.util.JsonUtil -import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_ACTION import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_BEFORE_SHA @@ -138,10 +137,9 @@ class TGitPushTriggerHandler( params = listOf( getBranchName(event), "${event.repository.homepage}/commit/${event.checkout_sha}", - event.user_name, - DateTimeUtil.formatMilliTime(event.pushTimestamp?.let { - DateTimeUtil.zoneDateToTimestamp(it) - } ?: LocalDateTime.now().timestampmilli())) + "${event.checkout_sha}", + event.user_name + ) ) return JsonUtil.toJson(i18Variable) } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt index fd59ad22348..f13ad6a006d 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt @@ -27,6 +27,10 @@ package com.tencent.devops.common.webhook.service.code.handler.tgit +import com.tencent.devops.common.api.pojo.I18Variable +import com.tencent.devops.common.api.util.DateTimeUtil +import com.tencent.devops.common.api.util.JsonUtil +import com.tencent.devops.common.api.util.timestamp import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_COMMIT_AUTHOR import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_EVENT @@ -36,6 +40,7 @@ import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_REPO_URL import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_SHA import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_SHA_SHORT import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_REVIEW_APPROVED_REVIEWERS import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_REVIEW_APPROVING_REVIEWERS import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_REVIEW_ID @@ -96,6 +101,22 @@ class TGitReviewTriggerHandler( return "" } + override fun getEventDesc(event: GitReviewEvent): String { + val i18Variable = I18Variable( + code = getI18Code(event), + params = listOf( + "${event.repository.homepage}/reviews/${event.iid}", + event.commitId ?: "", + getUsername(event) + ) + ) + return JsonUtil.toJson(i18Variable) + } + + override fun getExternalId(event: GitReviewEvent): String { + return event.projectId.toString() + } + @SuppressWarnings("ComplexMethod", "ComplexCondition") override fun retrieveParams(event: GitReviewEvent, projectId: String?, repository: Repository?): Map { val startParams = mutableMapOf() @@ -190,4 +211,12 @@ class TGitReviewTriggerHandler( return listOf(urlFilter, eventTypeFilter, crStateFilter, crTypeFilter) } } + + private fun getI18Code(event: GitReviewEvent) = when (event.reviewableType) { + GitReviewEvent.ACTION_APPROVED -> WebhookI18nConstants.TGIT_REVIEW_APPROVED_EVENT_DESC + GitReviewEvent.ACTION_APPROVING -> WebhookI18nConstants.TGIT_REVIEW_APPROVING_EVENT_DESC + GitReviewEvent.ACTION_CHANGE_DENIED -> WebhookI18nConstants.TGIT_REVIEW_CHANGE_DENIED_EVENT_DESC + GitReviewEvent.ACTION_CHANGE_REQUIRED -> WebhookI18nConstants.TGIT_REVIEW_CHANGE_REQUIRED_EVENT_DESC + else -> "" + } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt index a06987ce5e2..442e732c716 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt @@ -27,6 +27,8 @@ package com.tencent.devops.common.webhook.service.code.handler.tgit +import com.tencent.devops.common.api.pojo.I18Variable +import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_BEFORE_SHA import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_BEFORE_SHA_SHORT @@ -38,6 +40,7 @@ import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_REPO_URL import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_TAG_FROM import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_TAG_MESSAGE import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_PUSH_TOTAL_COMMIT import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_TAG_CREATE_FROM import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_TAG_NAME @@ -57,6 +60,7 @@ import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTrigger import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils +import java.time.LocalDateTime @CodeWebhookHandler class TGitTagPushTriggerHandler : CodeWebhookTriggerHandler { @@ -101,6 +105,23 @@ class TGitTagPushTriggerHandler : CodeWebhookTriggerHandler { } } + override fun getEventDesc(event: GitTagPushEvent): String { + val i18Variable = I18Variable( + code = WebhookI18nConstants.TGIT_TAG_PUSH_EVENT_DESC, + params = listOf( + "${event.create_from}", + "${event.repository.homepage}/-/tags/${getBranchName(event)}", + getBranchName(event), + getUsername(event) + ) + ) + return JsonUtil.toJson(i18Variable) + } + + override fun getExternalId(event: GitTagPushEvent): String { + return event.project_id.toString() + } + override fun retrieveParams( event: GitTagPushEvent, projectId: String?, diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/BuildId.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/BuildId.kt index 6dcc0eb0313..f0fa23644af 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/BuildId.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/BuildId.kt @@ -39,5 +39,7 @@ data class BuildId( @ApiModelProperty("项目ID") val projectId: String? = null, @ApiModelProperty("流水线ID") - val pipelineId: String? = null + val pipelineId: String? = null, + @ApiModelProperty("构建编号") + val num: Int? = null ) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt index e231232c3a7..326679480eb 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt @@ -1019,7 +1019,8 @@ class PipelineRuntimeService @Autowired constructor( id = context.buildId, executeCount = context.executeCount, projectId = context.projectId, - pipelineId = context.pipelineId + pipelineId = context.pipelineId, + num = context.buildNum ) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt index 910b9c4abd2..a3482667519 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt @@ -57,9 +57,11 @@ import com.tencent.devops.process.pojo.VmInfo import com.tencent.devops.process.pojo.pipeline.ModelDetail import com.tencent.devops.process.pojo.pipeline.ModelRecord import com.tencent.devops.process.pojo.pipeline.PipelineLatestBuild +import com.tencent.devops.process.pojo.trigger.PipelineTriggerType import com.tencent.devops.process.service.builds.PipelineBuildFacadeService import com.tencent.devops.process.service.builds.PipelineBuildMaintainFacadeService import com.tencent.devops.process.service.builds.PipelinePauseBuildFacadeService +import com.tencent.devops.process.service.trigger.PipelineTriggerEventService import org.springframework.beans.factory.annotation.Autowired @Suppress("ALL") @@ -70,7 +72,8 @@ class ServiceBuildResourceImpl @Autowired constructor( private val engineVMBuildService: EngineVMBuildService, private val pipelineBuildDetailService: PipelineBuildDetailService, private val pipelinePauseBuildFacadeService: PipelinePauseBuildFacadeService, - private val pipelineRuntimeService: PipelineRuntimeService + private val pipelineRuntimeService: PipelineRuntimeService, + private val pipelineTriggerEventService: PipelineTriggerEventService ) : ServiceBuildResource { override fun getPipelineIdFromBuildId(projectId: String, buildId: String): Result { if (buildId.isBlank()) { @@ -725,19 +728,27 @@ class ServiceBuildResourceImpl @Autowired constructor( ): Result { checkUserId(userId) checkParam(projectId, pipelineId) - return Result( - pipelineBuildFacadeService.buildManualStartup( - userId = userId, - startType = startType, - projectId = projectId, - pipelineId = pipelineId, - values = values, - channelCode = channelCode, - buildNo = buildNo, - checkPermission = ChannelCode.isNeedAuth(channelCode), - frequencyLimit = true - ) + val buildId = pipelineTriggerEventService.saveSpecificEvent( + projectId = projectId, + pipelineId = pipelineId, + requestParams = values, + userId = userId!!, + triggerType = PipelineTriggerType.SERVICE.name, + startAction = { + pipelineBuildFacadeService.buildManualStartup( + userId = userId, + startType = startType, + projectId = projectId, + pipelineId = pipelineId, + values = values, + channelCode = channelCode, + buildNo = buildNo, + checkPermission = ChannelCode.isNeedAuth(channelCode), + frequencyLimit = true + ) + } ) + return Result(buildId) } override fun buildRestart(userId: String, projectId: String, pipelineId: String, buildId: String): Result { diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt index b1f41a9973b..31ea9c3516d 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt @@ -50,6 +50,7 @@ import com.tencent.devops.process.service.PipelineRecentUseService import com.tencent.devops.process.service.builds.PipelineBuildFacadeService import com.tencent.devops.process.service.builds.PipelineBuildMaintainFacadeService import com.tencent.devops.process.service.builds.PipelinePauseBuildFacadeService +import com.tencent.devops.process.service.trigger.PipelineTriggerEventService import io.micrometer.core.annotation.Timed import org.springframework.beans.factory.annotation.Autowired import javax.ws.rs.core.Response @@ -60,7 +61,8 @@ class UserBuildResourceImpl @Autowired constructor( private val pipelineBuildMaintainFacadeService: PipelineBuildMaintainFacadeService, private val pipelineBuildFacadeService: PipelineBuildFacadeService, private val pipelinePauseBuildFacadeService: PipelinePauseBuildFacadeService, - private val pipelineRecentUseService: PipelineRecentUseService + private val pipelineRecentUseService: PipelineRecentUseService, + private val pipelineTriggerEventService: PipelineTriggerEventService ) : UserBuildResource { override fun manualStartupInfo( @@ -94,15 +96,23 @@ class UserBuildResourceImpl @Autowired constructor( triggerReviewers: List? ): Result { checkParam(userId, projectId, pipelineId) - val manualStartup = pipelineBuildFacadeService.buildManualStartup( - userId = userId, - startType = StartType.MANUAL, + val manualStartup = pipelineTriggerEventService.saveSpecificEvent( projectId = projectId, pipelineId = pipelineId, - values = values, - channelCode = ChannelCode.BS, - buildNo = buildNo, - triggerReviewers = triggerReviewers + requestParams = values, + userId = userId, + startAction = { + pipelineBuildFacadeService.buildManualStartup( + userId = userId, + startType = StartType.MANUAL, + projectId = projectId, + pipelineId = pipelineId, + values = values, + channelCode = ChannelCode.BS, + buildNo = buildNo, + triggerReviewers = triggerReviewers + ) + } ) pipelineRecentUseService.record(userId, projectId, pipelineId) return Result(manualStartup) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt index 92bffbbf527..a3f35cb2c96 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt @@ -48,7 +48,9 @@ import com.tencent.devops.process.engine.control.lock.PipelineRemoteAuthLock import com.tencent.devops.process.engine.service.PipelineRepositoryService import com.tencent.devops.process.pojo.BuildId import com.tencent.devops.process.pojo.PipelineRemoteToken +import com.tencent.devops.process.pojo.trigger.PipelineTriggerType import com.tencent.devops.process.service.builds.PipelineBuildFacadeService +import com.tencent.devops.process.service.trigger.PipelineTriggerEventService import com.tencent.devops.process.utils.PIPELINE_START_REMOTE_USER_ID import com.tencent.devops.process.utils.PIPELINE_START_TASK_ID import org.jooq.DSLContext @@ -67,7 +69,8 @@ class PipelineRemoteAuthService @Autowired constructor( private val client: Client, private val bkTag: BkTag, private val buildLogPrinter: BuildLogPrinter, - private val buildVariableService: BuildVariableService + private val buildVariableService: BuildVariableService, + private val pipelineTriggerEventService: PipelineTriggerEventService ) { fun generateAuth(pipelineId: String, projectId: String, userId: String): PipelineRemoteToken { @@ -127,15 +130,24 @@ class PipelineRemoteAuthService @Autowired constructor( 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()}") - val buildId = client.getGateway(ServiceBuildResource::class).manualStartupNew( - userId = userId!!, + val buildId = pipelineTriggerEventService.saveSpecificEvent( projectId = pipeline.projectId, pipelineId = pipeline.pipelineId, - values = vals.toMap(), - channelCode = ChannelCode.BS, - startType = StartType.REMOTE, - buildNo = null - ).data!! + requestParams = vals.toMap(), + userId = userId!!, + triggerType = PipelineTriggerType.REMOTE.name, + startAction = { + client.getGateway(ServiceBuildResource::class).manualStartupNew( + userId = userId!!, + projectId = pipeline.projectId, + pipelineId = pipeline.pipelineId, + values = vals.toMap(), + channelCode = ChannelCode.BS, + startType = StartType.REMOTE, + buildNo = null + ).data!! + } + ) // 在远程触发器job中打印sourcIp val taskId = buildVariableService.getVariable( projectId = pipeline.projectId, @@ -159,7 +171,8 @@ class PipelineRemoteAuthService @Autowired constructor( id = buildId.id, executeCount = 1, pipelineId = pipeline.pipelineId, - projectId = pipeline.projectId + projectId = pipeline.projectId, + num = buildId.num ) } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt index 97932152b53..bd4016e5eed 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt @@ -31,14 +31,20 @@ package com.tencent.devops.process.service.trigger import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.api.exception.ParamBlankException import com.tencent.devops.common.api.model.SQLPage +import com.tencent.devops.common.api.pojo.I18Variable +import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.PageUtil import com.tencent.devops.common.client.Client +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_TRIGGER_DETAIL_NOT_FOUND import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_TRIGGER_REPLAY_PIPELINE_NOT_EMPTY import com.tencent.devops.process.dao.PipelineTriggerEventDao +import com.tencent.devops.process.pojo.BuildId import com.tencent.devops.process.pojo.trigger.PipelineTriggerDetail import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventVo +import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus +import com.tencent.devops.process.pojo.trigger.PipelineTriggerType import com.tencent.devops.process.pojo.trigger.RepoTriggerEventVo import com.tencent.devops.process.webhook.listener.PipelineTriggerRequestService import com.tencent.devops.project.api.service.ServiceAllocIdResource @@ -47,6 +53,7 @@ import org.jooq.impl.DSL import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service +import java.time.LocalDateTime @Suppress("ALL") @Service @@ -75,6 +82,7 @@ class PipelineTriggerEventService @Autowired constructor( triggerEvent: PipelineTriggerEvent, triggerDetail: PipelineTriggerDetail ) { + logger.info("save pipeline trigger event|event[$triggerEvent]|detail[$triggerDetail]") triggerDetail.detailId = getDetailId() dslContext.transaction { configuration -> val transactionContext = DSL.using(configuration) @@ -243,4 +251,91 @@ class PipelineTriggerEventService @Autowired constructor( ) return true } + + /** + * 保存特殊触发事件 + * 远程/手动/openApi + */ + fun saveSpecificEvent( + projectId: String, + pipelineId: String, + userId: String, + requestParams: Map?, + triggerType: String = PipelineTriggerType.MANUAL.name, + startAction: () -> BuildId + ): BuildId { + var buildNum: String? = null + var status = PipelineTriggerStatus.SUCCEED.name + var buildId: String? = null + try { + val buildInfo = startAction.invoke() + buildNum = buildInfo.num.toString() + buildId = buildInfo.id + return buildInfo + } catch (ignored: Exception) { + status = PipelineTriggerStatus.FAILED.name + throw ignored + } finally { + saveManualStartEvent( + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + status = status, + requestParams = requestParams, + userId = userId, + buildNum = buildNum, + triggerType = triggerType + ) + } + } + + /** + * 保存手动触发事件 + */ + private fun saveManualStartEvent( + projectId: String, + pipelineId: String, + buildId: String?, + buildNum: String?, + userId: String, + status: String, + triggerType: String, + requestParams: Map? + ) { + val eventId = getEventId() + saveEvent( + triggerDetail = PipelineTriggerDetail( + eventId = eventId, + status = status, + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + buildNum = buildNum + ), + triggerEvent = PipelineTriggerEvent( + eventId = eventId, + projectId = projectId, + eventDesc = JsonUtil.toJson( + I18Variable( + code = getI18Code(triggerType), + params = listOf(userId) + ), + false + ), + triggerType = triggerType, + eventType = triggerType, + triggerUser = userId, + requestParams = requestParams, + eventTime = LocalDateTime.now(), + hookRequestId = null + ) + ) + } + + private fun getI18Code(triggerType: String) = when (triggerType) { + PipelineTriggerType.MANUAL.name -> WebhookI18nConstants.MANUAL_START_EVENT_DESC + PipelineTriggerType.REMOTE.name -> WebhookI18nConstants.REMOTE_START_EVENT_DESC + PipelineTriggerType.SERVICE.name -> WebhookI18nConstants.SERVICE_START_EVENT_DESC + else -> "" + } } diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index 4452df349c6..8fac930cfb7 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -358,4 +358,19 @@ bkQualityOut=Quality out bkBuildFinishedAndDenyPause=Build Finished And Deny Pause commonShutdownSuccessContent=【${%s}】- 【${%s}】#${%s} Execution succeed,consume time${%s}, trigger user: ${%s}。 commonShutdownFailureContent=【${%s}】- 【${%s}】#${%s} Execution failed,consume time${%s}, trigger user: ${%s}。 -bkTgitPushEventDesc=[{0}] commit [{1}] pushed by {2} {3} +bkTgitPushEventDesc=[{0}] Commit [{2}] pushed by {3} +bkTgitIssueOpenedEventDesc=Issue [!{1}] opened by {2} +bkTgitIssueUpdatedEventDesc=Issue [!{1}] updated by {2} +bkTgitIssueClosedEventDesc=Issue [!{1}] closed by {2} +bkTgitIssueReopenedEventDesc=Issue [!{1}] reopened by {2} +bkTgitMrCreatedEventDesc=Merge requests [!{1}] opened by {2} +bkTgitMrUpdatedEventDesc=Merge requests [!{1}] updated by {2} +bkTgitMrClosedEventDesc=Merge requests [!{1}] closed by {2} +bkTgitMrReopenedEventDesc=Merge requests [!{1}] reopened by {2} +bkTgitMrPushUpdatedEventDesc=Merge requests [!{1}] push updated by {2} +bkTgitTagPushEventDesc=[{0}]Tag [{2}] pushed by {3} +bkTgitNoteEventDesc=Note [{1}] submitted by {2} +bkTgitReviewApprovedEventDesc=Code review [{1}] approved by {2} +bkTgitReviewApprovingEventDesc=Code review [{1}] approving +bkTgitReviewChangeDeniedEventDesc=Code review [{1}] change denied by {2} +bkTgitReviewChangeRequiredEventDesc=Code review [{1}] change required by {2} diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index fb05e6cd8a7..9913702a824 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -358,4 +358,19 @@ bkQualityOut=质量红线(准出) bkBuildFinishedAndDenyPause=构建已结束,禁止暂停请求 commonShutdownSuccessContent=【${%s}】- 【${%s}】#${%s} 执行成功,耗时${%s}, 触发人: ${%s}。 commonShutdownFailureContent=【${%s}】- 【${%s}】#${%s} 执行失败,耗时${%s}, 触发人: ${%s}。 -bkTgitPushEventDesc=【{0}】提交【{1}】被{2}提交于 {3} \ No newline at end of file +bkTgitPushEventDesc=[{0}] 提交 [{2}] 由 {3} 推送 +bkTgitIssueCreatedEventDesc=议题 [!{1}] 由 {2} 创建 +bkTgitIssueUpdatedEventDesc=议题 [!{1}] 由 {2} 更新 +bkTgitIssueClosedEventDesc=议题 [!{1}] 由 {2} 关闭 +bkTgitIssueReopenedEventDesc=议题 [!{1}] 由 {2} 重新打开 +bkTgitMrCreatedEventDesc=合并请求 [!{1}] 由 {2} 创建 +bkTgitMrUpdatedEventDesc=合并请求 [!{1}] 由 {2} 更新 +bkTgitMrClosedEventDesc=合并请求 [!{1}] 由 {2} 关闭 +bkTgitMrReopenedEventDesc=合并请求 [!{1}] 由 {2} 重新打开 +bkTgitMrPushUpdatedEventDesc=合并请求 [!{1}] 由 {2} 在源分支提交代码触发 +bkTgitTagPushEventDesc=[{0}] 创建Tag [{2}] 由 {3} 推送 +bkTgitNoteEventDesc=评论 [{1}] 由 {2} 发表 +bkTgitReviewApprovedEventDesc=代码审查 [{1}] 由 {2} 评审通过 +bkTgitReviewApprovingEventDesc=代码审查 [{1}] 评审中 +bkTgitReviewChangeDeniedEventDesc=代码审查 [{1}] 被 {2} 拒绝 +bkTgitReviewChangeRequiredEventDesc=代码审查 [{1}] 由 {2} 要求修改 \ No newline at end of file From 06ecfc56dfcb8b2f6732f6449f512247c351b366 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 10 Aug 2023 13:15:25 +0800 Subject: [PATCH 013/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/common/api/util/EnumUtil.kt | 418 +++++++++--------- .../atom/CodeGitWebhookTriggerTaskAtom.kt | 1 - 2 files changed, 209 insertions(+), 210 deletions(-) diff --git a/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/util/EnumUtil.kt b/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/util/EnumUtil.kt index 94d5042a8b6..f30a88eb446 100644 --- a/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/util/EnumUtil.kt +++ b/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/util/EnumUtil.kt @@ -1,209 +1,209 @@ -///* -// * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. -// * -// * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. -// * -// * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. -// * -// * A copy of the MIT License is included in this file. -// * -// * -// * Terms of the MIT License: -// * --------------------------------------------------- -// * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -// * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the -// * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to -// * permit persons to whom the Software is furnished to do so, subject to the following conditions: -// * -// * The above copyright notice and this permission notice shall be included in all copies or substantial portions of -// * the Software. -// * -// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT -// * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -// * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// */ -// -//package com.tencent.devops.common.api.util -// -//import sun.reflect.ConstructorAccessor -//import sun.reflect.FieldAccessor -//import sun.reflect.ReflectionFactory -//import java.lang.reflect.AccessibleObject -//import java.lang.reflect.Field -//import java.lang.reflect.Modifier -//import kotlin.reflect.full.isSubclassOf -// -///** -// * 枚举工具类,用于动态修改枚举值和内容 -// * -// */ -//@Suppress("ALL") -//object EnumUtil { -// -// /** -// * 动态修改枚举,但动态范围仅限于后来使用枚举类的values或valueOf方法实例化出来的枚举值 -// * -// * 不支持动态替换:直接在代码中使用 MyEnum.APPLE.type 这种写法在编译期已经生成为常量,就无法实现动态替换了. -// * 支持动态替换: MyEnum.valueOf("APPLE") MyEnum.values() 这种可以实现动态读取到 -// * -// * @param 枚举的泛型 -// * @param enumType 要动态修改的枚举类 -// * @param enumName 枚举值名称 -// * @param additionalValues 枚举定义的其他字段的值,如果有,如果无传空数组 -// */ -// inline fun addEnum(enumType: Class, enumName: String, additionalValues: Array) { -// -// // 检查是否是枚举类型,如果不是则抛出异常 -// if (!Enum::class.java.isAssignableFrom(enumType)) { -// throw RuntimeException("class $enumType is not an instance of Enum") -// } -// // 1. Lookup "$VALUES" holder in enum class and get previous enum instances -// var valuesField: Field? = null -// val fields: Array = enumType.declaredFields -// for (field in fields) { -// if (field.name.contains("\$VALUES")) { -// valuesField = field -// break -// } -// } -// -// val additionalTypes = mutableListOf>() -// additionalValues.forEach { value -> -// when { -// // kotlin 中 List可变mutable与不可变immutable是两个不同的接口,需要区分对待 -// value::class.isSubclassOf(MutableList::class) -> additionalTypes.add(MutableList::class.java) -// // 赋值时注意其他Java对List的各种扩展子类,都转为List -// value::class.isSubclassOf(List::class) -> additionalTypes.add(List::class.java) -// // 其他场景暂时未覆盖完 -// else -> additionalTypes.add(value::class.java) -// } -// } -// -// AccessibleObject.setAccessible(arrayOf(valuesField), true) -// -// try { -// // 将先之前的枚举值保存下来 -// val previousValues = valuesField!![enumType] as Array -// -// val values: MutableList = mutableListOf() -// var ordinal = previousValues.size -// -// previousValues.forEachIndexed { idx, value -> -// // 如果是存在的枚举值,则服它替换旧值 -// if (value.toString() == enumName) { -// ordinal = idx -// } -// values.add(value) -// } -// -// // 构建新枚举值 -// val newValue: T = makeEnum( -// enumClass = enumType, -// value = enumName, -// ordinal = ordinal, -// additionalTypes = additionalTypes.toTypedArray(), -// additionalValues = additionalValues -// ) -// -// if (ordinal < previousValues.size) { -// values[ordinal] = newValue -// } else { -// values.add(newValue) -// } -// -// setFailSafeFieldValue(field = valuesField, target = null, value = values.toTypedArray()) -// -// cleanEnumCache(enumType) -// } catch (e: Exception) { -// println(e) -// e.printStackTrace() -// throw RuntimeException(e.message, e) -// } -// } -// -// @Throws(NoSuchFieldException::class, IllegalAccessException::class) -// fun setFailSafeFieldValue(field: Field, target: Any?, value: Any?) { -// field.isAccessible = true -// val modifiersField: Field = Field::class.java.getDeclaredField("modifiers") -// modifiersField.isAccessible = true -// var modifiers: Int = modifiersField.getInt(field) -// modifiers = modifiers and Modifier.FINAL.inv() -// modifiersField.setInt(field, modifiers) -// val fieldAccessor: FieldAccessor = reflectionFactory.newFieldAccessor(field, false) -// fieldAccessor.set(target, value) -// } -// -// @Throws(NoSuchFieldException::class, IllegalAccessException::class) -// inline fun blankField(enumClass: Class, fieldName: String) { -// for (field in Class::class.java.declaredFields) { -// if (field.name.contains(fieldName)) { -// setFailSafeFieldValue(field, enumClass, null) -// break -// } -// } -// } -// -// @Throws(NoSuchFieldException::class, IllegalAccessException::class) -// inline fun cleanEnumCache(enumClass: Class) { -// blankField(enumClass, "enumConstantDirectory") // OracleJDK & OpenJDK -// blankField(enumClass, "enumConstants") // IBM JDK -// } -// -// @Throws(NoSuchMethodException::class) -// inline fun getConstructorAccessor( -// enumClass: Class, -// additionalParameterTypes: Array> -// ): ConstructorAccessor? { -// val parameterTypes = arrayOfNulls?>(additionalParameterTypes.size + 2) -// parameterTypes[0] = String::class.java // enum class first field: field name -// parameterTypes[1] = Int::class.javaPrimitiveType // enum class second field: ordinal -// System.arraycopy(additionalParameterTypes, 0, parameterTypes, 2, additionalParameterTypes.size) -// enumClass.declaredConstructors.forEach { constructor -> -// if (compareParameterType(constructor.parameterTypes, parameterTypes)) { -// try { -// return reflectionFactory.newConstructorAccessor(constructor) -// } catch (ignored: IllegalArgumentException) { -// // skip illegal argument try next one -// } -// } -// } -// -// return reflectionFactory.newConstructorAccessor(enumClass.getDeclaredConstructor(*parameterTypes)) -// } -// -// fun compareParameterType(constructorParameterType: Array>, parameterTypes: Array?>): Boolean { -// if (constructorParameterType.size != parameterTypes.size) { -// return false -// } -// for (i in constructorParameterType.indices) { -// if (constructorParameterType[i] !== parameterTypes[i]) { -// if (constructorParameterType[i].isPrimitive && parameterTypes[i]!!.isPrimitive) { -// if (constructorParameterType[i].kotlin.javaPrimitiveType -// !== parameterTypes[i]!!.kotlin.javaPrimitiveType) { -// return false -// } -// } -// } -// } -// return true -// } -// -// @Throws(Exception::class) -// inline fun makeEnum( -// enumClass: Class, -// value: String, -// ordinal: Int, -// additionalTypes: Array>, -// additionalValues: Array -// ): T { -// val params = arrayOfNulls(additionalValues.size + 2) -// params[0] = value -// params[1] = Integer.valueOf(ordinal) -// System.arraycopy(additionalValues, 0, params, 2, additionalValues.size) -// return enumClass.cast(getConstructorAccessor(enumClass, additionalTypes)!!.newInstance(params)) -// } -// -// val reflectionFactory: ReflectionFactory = ReflectionFactory.getReflectionFactory() -//} +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.devops.common.api.util + +import sun.reflect.ConstructorAccessor +import sun.reflect.FieldAccessor +import sun.reflect.ReflectionFactory +import java.lang.reflect.AccessibleObject +import java.lang.reflect.Field +import java.lang.reflect.Modifier +import kotlin.reflect.full.isSubclassOf + +/** + * 枚举工具类,用于动态修改枚举值和内容 + * + */ +@Suppress("ALL") +object EnumUtil { + + /** + * 动态修改枚举,但动态范围仅限于后来使用枚举类的values或valueOf方法实例化出来的枚举值 + * + * 不支持动态替换:直接在代码中使用 MyEnum.APPLE.type 这种写法在编译期已经生成为常量,就无法实现动态替换了. + * 支持动态替换: MyEnum.valueOf("APPLE") MyEnum.values() 这种可以实现动态读取到 + * + * @param 枚举的泛型 + * @param enumType 要动态修改的枚举类 + * @param enumName 枚举值名称 + * @param additionalValues 枚举定义的其他字段的值,如果有,如果无传空数组 + */ + inline fun addEnum(enumType: Class, enumName: String, additionalValues: Array) { + + // 检查是否是枚举类型,如果不是则抛出异常 + if (!Enum::class.java.isAssignableFrom(enumType)) { + throw RuntimeException("class $enumType is not an instance of Enum") + } + // 1. Lookup "$VALUES" holder in enum class and get previous enum instances + var valuesField: Field? = null + val fields: Array = enumType.declaredFields + for (field in fields) { + if (field.name.contains("\$VALUES")) { + valuesField = field + break + } + } + + val additionalTypes = mutableListOf>() + additionalValues.forEach { value -> + when { + // kotlin 中 List可变mutable与不可变immutable是两个不同的接口,需要区分对待 + value::class.isSubclassOf(MutableList::class) -> additionalTypes.add(MutableList::class.java) + // 赋值时注意其他Java对List的各种扩展子类,都转为List + value::class.isSubclassOf(List::class) -> additionalTypes.add(List::class.java) + // 其他场景暂时未覆盖完 + else -> additionalTypes.add(value::class.java) + } + } + + AccessibleObject.setAccessible(arrayOf(valuesField), true) + + try { + // 将先之前的枚举值保存下来 + val previousValues = valuesField!![enumType] as Array + + val values: MutableList = mutableListOf() + var ordinal = previousValues.size + + previousValues.forEachIndexed { idx, value -> + // 如果是存在的枚举值,则服它替换旧值 + if (value.toString() == enumName) { + ordinal = idx + } + values.add(value) + } + + // 构建新枚举值 + val newValue: T = makeEnum( + enumClass = enumType, + value = enumName, + ordinal = ordinal, + additionalTypes = additionalTypes.toTypedArray(), + additionalValues = additionalValues + ) + + if (ordinal < previousValues.size) { + values[ordinal] = newValue + } else { + values.add(newValue) + } + + setFailSafeFieldValue(field = valuesField, target = null, value = values.toTypedArray()) + + cleanEnumCache(enumType) + } catch (e: Exception) { + println(e) + e.printStackTrace() + throw RuntimeException(e.message, e) + } + } + + @Throws(NoSuchFieldException::class, IllegalAccessException::class) + fun setFailSafeFieldValue(field: Field, target: Any?, value: Any?) { + field.isAccessible = true + val modifiersField: Field = Field::class.java.getDeclaredField("modifiers") + modifiersField.isAccessible = true + var modifiers: Int = modifiersField.getInt(field) + modifiers = modifiers and Modifier.FINAL.inv() + modifiersField.setInt(field, modifiers) + val fieldAccessor: FieldAccessor = reflectionFactory.newFieldAccessor(field, false) + fieldAccessor.set(target, value) + } + + @Throws(NoSuchFieldException::class, IllegalAccessException::class) + inline fun blankField(enumClass: Class, fieldName: String) { + for (field in Class::class.java.declaredFields) { + if (field.name.contains(fieldName)) { + setFailSafeFieldValue(field, enumClass, null) + break + } + } + } + + @Throws(NoSuchFieldException::class, IllegalAccessException::class) + inline fun cleanEnumCache(enumClass: Class) { + blankField(enumClass, "enumConstantDirectory") // OracleJDK & OpenJDK + blankField(enumClass, "enumConstants") // IBM JDK + } + + @Throws(NoSuchMethodException::class) + inline fun getConstructorAccessor( + enumClass: Class, + additionalParameterTypes: Array> + ): ConstructorAccessor? { + val parameterTypes = arrayOfNulls?>(additionalParameterTypes.size + 2) + parameterTypes[0] = String::class.java // enum class first field: field name + parameterTypes[1] = Int::class.javaPrimitiveType // enum class second field: ordinal + System.arraycopy(additionalParameterTypes, 0, parameterTypes, 2, additionalParameterTypes.size) + enumClass.declaredConstructors.forEach { constructor -> + if (compareParameterType(constructor.parameterTypes, parameterTypes)) { + try { + return reflectionFactory.newConstructorAccessor(constructor) + } catch (ignored: IllegalArgumentException) { + // skip illegal argument try next one + } + } + } + + return reflectionFactory.newConstructorAccessor(enumClass.getDeclaredConstructor(*parameterTypes)) + } + + fun compareParameterType(constructorParameterType: Array>, parameterTypes: Array?>): Boolean { + if (constructorParameterType.size != parameterTypes.size) { + return false + } + for (i in constructorParameterType.indices) { + if (constructorParameterType[i] !== parameterTypes[i]) { + if (constructorParameterType[i].isPrimitive && parameterTypes[i]!!.isPrimitive) { + if (constructorParameterType[i].kotlin.javaPrimitiveType + !== parameterTypes[i]!!.kotlin.javaPrimitiveType) { + return false + } + } + } + } + return true + } + + @Throws(Exception::class) + inline fun makeEnum( + enumClass: Class, + value: String, + ordinal: Int, + additionalTypes: Array>, + additionalValues: Array + ): T { + val params = arrayOfNulls(additionalValues.size + 2) + params[0] = value + params[1] = Integer.valueOf(ordinal) + System.arraycopy(additionalValues, 0, params, 2, additionalValues.size) + return enumClass.cast(getConstructorAccessor(enumClass, additionalTypes)!!.newInstance(params)) + } + + val reflectionFactory: ReflectionFactory = ReflectionFactory.getReflectionFactory() +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt index 888c4245b96..8506f35727f 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt @@ -32,7 +32,6 @@ import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.readValue import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.exception.ErrorCodeException -import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.webhook.atom.IWebhookAtomTask import com.tencent.devops.common.webhook.pojo.WebhookRequest import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay From be8347b86b41cd79a264c23a1383d679bd48778d Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 10 Aug 2023 13:41:55 +0800 Subject: [PATCH 014/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/api/user/UserPipelineTriggerEventResource.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt index 9bc9d640e7d..42da9b6caa8 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt @@ -122,10 +122,10 @@ interface UserPipelineTriggerEventResource { @ApiParam("触发用户", required = false) @QueryParam("triggerUser") triggerUser: String?, - @ApiParam("流水线ID", required = true) + @ApiParam("流水线ID", required = false) @QueryParam("pipelineId") pipelineId: String?, - @ApiParam("事件ID", required = true) + @ApiParam("事件ID", required = false) @QueryParam("eventId") eventId: Long?, @ApiParam("开始时间", required = false) From d0c0c87cba8e4d7c6693df0a73c38aa02367d00c Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 10 Aug 2023 13:52:17 +0800 Subject: [PATCH 015/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tencent/devops/common/web/utils/I18nUtil.kt | 4 +++- .../devops/process/pojo/trigger/RepoTriggerEventVo.kt | 2 +- .../service/trigger/PipelineTriggerEventService.kt | 11 +++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/backend/ci/core/common/common-web/src/main/kotlin/com/tencent/devops/common/web/utils/I18nUtil.kt b/src/backend/ci/core/common/common-web/src/main/kotlin/com/tencent/devops/common/web/utils/I18nUtil.kt index ca06335dc9f..84723fd8cd9 100644 --- a/src/backend/ci/core/common/common-web/src/main/kotlin/com/tencent/devops/common/web/utils/I18nUtil.kt +++ b/src/backend/ci/core/common/common-web/src/main/kotlin/com/tencent/devops/common/web/utils/I18nUtil.kt @@ -40,6 +40,7 @@ import com.tencent.devops.common.api.util.MessageUtil import com.tencent.devops.common.client.Client import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.common.service.config.CommonConfig +import com.tencent.devops.common.service.utils.CommonUtils import com.tencent.devops.common.service.utils.CookieUtil import com.tencent.devops.common.service.utils.SpringContextUtil import com.tencent.devops.common.web.service.ServiceLocaleResource @@ -222,8 +223,9 @@ object I18nUtil { } } - fun I18Variable.getCodeLanMessage(): String { + fun I18Variable.getCodeLanMessage(language: String? = CommonUtils.ZH_CN): String { return getCodeLanMessage( + language = language, messageCode = code, params = params.toTypedArray() ) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/RepoTriggerEventVo.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/RepoTriggerEventVo.kt index 1a6304f2693..26665410833 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/RepoTriggerEventVo.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/RepoTriggerEventVo.kt @@ -40,7 +40,7 @@ data class RepoTriggerEventVo( @ApiModelProperty("代码库ID", required = false) val repoHashId: String, @ApiModelProperty("事件描述") - val eventDesc: String, + var eventDesc: String, @ApiModelProperty("触发时间") val eventTime: Long, @ApiModelProperty("总流水线数") diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt index bd4016e5eed..16800894a10 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt @@ -35,6 +35,8 @@ import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.PageUtil import com.tencent.devops.common.client.Client +import com.tencent.devops.common.web.utils.I18nUtil +import com.tencent.devops.common.web.utils.I18nUtil.getCodeLanMessage import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_TRIGGER_DETAIL_NOT_FOUND import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_TRIGGER_REPLAY_PIPELINE_NOT_EMPTY @@ -147,11 +149,13 @@ class PipelineTriggerEventService @Autowired constructor( startTime: Long?, endTime: Long?, page: Int?, - pageSize: Int? + pageSize: Int?, + userId: String ): SQLPage { 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.countRepoTriggerEvent( dslContext = dslContext, projectId = projectId, @@ -177,7 +181,10 @@ class PipelineTriggerEventService @Autowired constructor( endTime = endTime, limit = sqlLimit.limit, offset = sqlLimit.offset - ) + ).map { + it.eventDesc = JsonUtil.to(it.eventDesc, I18Variable::class.java).getCodeLanMessage(language) + it + } return SQLPage(count = count, records = records) } From 7aa6827d176b67742c13b02d0b94afee56ee0f1b Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 10 Aug 2023 13:56:41 +0800 Subject: [PATCH 016/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/api/UserPipelineTriggerEventResourceImpl.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt index 8dba5829e37..2377942080c 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt @@ -115,7 +115,8 @@ class UserPipelineTriggerEventResourceImpl( startTime = startTime, endTime = endTime, page = page, - pageSize = pageSize + pageSize = pageSize, + userId = userId ) ) } From 958ad3c72d3fce6d840128a2c97b95402ebdc291 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 10 Aug 2023 14:06:07 +0800 Subject: [PATCH 017/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/service/trigger/PipelineTriggerEventService.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt index 16800894a10..e38a11969b0 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt @@ -182,7 +182,12 @@ class PipelineTriggerEventService @Autowired constructor( limit = sqlLimit.limit, offset = sqlLimit.offset ).map { - it.eventDesc = JsonUtil.to(it.eventDesc, I18Variable::class.java).getCodeLanMessage(language) + it.eventDesc = try { + JsonUtil.to(it.eventDesc, I18Variable::class.java).getCodeLanMessage(language) + } catch (ignored: Exception) { + logger.warn("Failed to resolve repo triggered event|sourceDesc[${it.eventDesc}]", ignored) + it.eventDesc + } it } return SQLPage(count = count, records = records) From c61c6cfca938181cd326fea445ccea521b734053 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 10 Aug 2023 14:06:50 +0800 Subject: [PATCH 018/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/service/trigger/PipelineTriggerEventService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt index e38a11969b0..967ab11c7d5 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt @@ -185,7 +185,7 @@ class PipelineTriggerEventService @Autowired constructor( it.eventDesc = try { JsonUtil.to(it.eventDesc, I18Variable::class.java).getCodeLanMessage(language) } catch (ignored: Exception) { - logger.warn("Failed to resolve repo triggered event|sourceDesc[${it.eventDesc}]", ignored) + logger.warn("Failed to resolve repo trigger event|sourceDesc[${it.eventDesc}]", ignored) it.eventDesc } it From f5bbd2549948d1c96086d1ba7c0587b98ccf9d13 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 10 Aug 2023 16:11:23 +0800 Subject: [PATCH 019/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webhook/pojo/code/git/GitReviewAttributes.kt | 2 +- .../code/handler/tgit/TGitReviewTriggerHandler.kt | 2 +- .../process/pojo/trigger/PipelineTriggerEventVo.kt | 2 +- .../api/UserPipelineTriggerEventResourceImpl.kt | 3 ++- .../service/trigger/PipelineTriggerEventService.kt | 14 ++++++++++++-- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitReviewAttributes.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitReviewAttributes.kt index 6c8c5316374..9cbc51b7c29 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitReviewAttributes.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitReviewAttributes.kt @@ -46,7 +46,7 @@ data class GitReviewAttributes( @JsonProperty("target_project_id") val targetProjectId: String, @JsonProperty("author_id") - val authorId: String, + val authorId: String?, @JsonProperty("assignee_id") val assigneeId: String?, val title: String, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt index f13ad6a006d..f71669213af 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt @@ -212,7 +212,7 @@ class TGitReviewTriggerHandler( } } - private fun getI18Code(event: GitReviewEvent) = when (event.reviewableType) { + private fun getI18Code(event: GitReviewEvent) = when (event.state) { GitReviewEvent.ACTION_APPROVED -> WebhookI18nConstants.TGIT_REVIEW_APPROVED_EVENT_DESC GitReviewEvent.ACTION_APPROVING -> WebhookI18nConstants.TGIT_REVIEW_APPROVING_EVENT_DESC GitReviewEvent.ACTION_CHANGE_DENIED -> WebhookI18nConstants.TGIT_REVIEW_CHANGE_DENIED_EVENT_DESC diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventVo.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventVo.kt index beb9eb11394..90f6e98391e 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventVo.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventVo.kt @@ -46,7 +46,7 @@ data class PipelineTriggerEventVo( @ApiModelProperty("触发人") val triggerUser: String, @ApiModelProperty("事件描述") - val eventDesc: String, + var eventDesc: String, @ApiModelProperty("事件时间") val eventTime: Long, @ApiModelProperty("触发状态") diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt index 2377942080c..3e7f0884138 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt @@ -135,7 +135,8 @@ class UserPipelineTriggerEventResourceImpl( eventId = eventId, pipelineId = pipelineId, page = page, - pageSize = pageSize + pageSize = pageSize, + userId = userId ) ) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt index 967ab11c7d5..a264b86cd53 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt @@ -198,7 +198,8 @@ class PipelineTriggerEventService @Autowired constructor( eventId: Long, pipelineId: String?, page: Int?, - pageSize: Int? + pageSize: Int?, + userId: String ): SQLPage { if (projectId.isBlank()) { throw ParamBlankException("Invalid projectId") @@ -206,6 +207,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 records = pipelineTriggerEventDao.listTriggerEvent( dslContext = dslContext, projectId = projectId, @@ -213,7 +215,15 @@ class PipelineTriggerEventService @Autowired constructor( pipelineId = pipelineId, limit = sqlLimit.limit, offset = sqlLimit.offset - ) + ).map { + it.eventDesc = try { + JsonUtil.to(it.eventDesc, I18Variable::class.java).getCodeLanMessage(language) + } catch (ignored: Exception) { + logger.warn("Failed to resolve repo trigger event|sourceDesc[${it.eventDesc}]", ignored) + it.eventDesc + } + it + } val count = pipelineTriggerEventDao.countTriggerEvent( dslContext = dslContext, projectId = projectId, From f9adb16c152953c2e9434408b2213015f5671212 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 10 Aug 2023 18:01:24 +0800 Subject: [PATCH 020/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webhook/pojo/code/git/GitPushEvent.kt | 1 + .../handler/tgit/TGitNoteTriggerHandler.kt | 2 +- .../handler/tgit/TGitPushTriggerHandler.kt | 2 +- .../i18n/process/message_en_US.properties | 32 +++++++++---------- .../i18n/process/message_zh_CN.properties | 32 +++++++++---------- 5 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitPushEvent.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitPushEvent.kt index d1416ef5124..fb008141f2b 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitPushEvent.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitPushEvent.kt @@ -55,6 +55,7 @@ data class GitPushEvent( ) : GitEvent() { companion object { const val classType = "push" + const val SHORT_COMMIT_ID_LENGTH = 8 } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt index 36f49fbe9a8..2172f4ab827 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt @@ -125,7 +125,7 @@ class TGitNoteTriggerHandler( code = WebhookI18nConstants.TGIT_NOTE_EVENT_DESC, params = listOf( event.objectAttributes.url, - event.objectAttributes.note, + event.objectAttributes.id.toString(), getUsername(event) ) ) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt index 0662ee9835a..fcb62c5cf95 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt @@ -137,7 +137,7 @@ class TGitPushTriggerHandler( params = listOf( getBranchName(event), "${event.repository.homepage}/commit/${event.checkout_sha}", - "${event.checkout_sha}", + "${event.checkout_sha}".substring(0, GitPushEvent.SHORT_COMMIT_ID_LENGTH), event.user_name ) ) diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index 8fac930cfb7..e2dbb517fa3 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -358,19 +358,19 @@ bkQualityOut=Quality out bkBuildFinishedAndDenyPause=Build Finished And Deny Pause commonShutdownSuccessContent=【${%s}】- 【${%s}】#${%s} Execution succeed,consume time${%s}, trigger user: ${%s}。 commonShutdownFailureContent=【${%s}】- 【${%s}】#${%s} Execution failed,consume time${%s}, trigger user: ${%s}。 -bkTgitPushEventDesc=[{0}] Commit [{2}] pushed by {3} -bkTgitIssueOpenedEventDesc=Issue [!{1}] opened by {2} -bkTgitIssueUpdatedEventDesc=Issue [!{1}] updated by {2} -bkTgitIssueClosedEventDesc=Issue [!{1}] closed by {2} -bkTgitIssueReopenedEventDesc=Issue [!{1}] reopened by {2} -bkTgitMrCreatedEventDesc=Merge requests [!{1}] opened by {2} -bkTgitMrUpdatedEventDesc=Merge requests [!{1}] updated by {2} -bkTgitMrClosedEventDesc=Merge requests [!{1}] closed by {2} -bkTgitMrReopenedEventDesc=Merge requests [!{1}] reopened by {2} -bkTgitMrPushUpdatedEventDesc=Merge requests [!{1}] push updated by {2} -bkTgitTagPushEventDesc=[{0}]Tag [{2}] pushed by {3} -bkTgitNoteEventDesc=Note [{1}] submitted by {2} -bkTgitReviewApprovedEventDesc=Code review [{1}] approved by {2} -bkTgitReviewApprovingEventDesc=Code review [{1}] approving -bkTgitReviewChangeDeniedEventDesc=Code review [{1}] change denied by {2} -bkTgitReviewChangeRequiredEventDesc=Code review [{1}] change required by {2} +bkTgitPushEventDesc=[{0}] Commit [{2}] pushed by {3} +bkTgitIssueOpenedEventDesc=Issue [!{1}] opened by {2} +bkTgitIssueUpdatedEventDesc=Issue [!{1}] updated by {2} +bkTgitIssueClosedEventDesc=Issue [!{1}] closed by {2} +bkTgitIssueReopenedEventDesc=Issue [!{1}] reopened by {2} +bkTgitMrCreatedEventDesc=Merge requests [!{1}] opened by {2} +bkTgitMrUpdatedEventDesc=Merge requests [!{1}] updated by {2} +bkTgitMrClosedEventDesc=Merge requests [!{1}] closed by {2} +bkTgitMrReopenedEventDesc=Merge requests [!{1}] reopened by {2} +bkTgitMrPushUpdatedEventDesc=Merge requests [!{1}] push updated by {2} +bkTgitTagPushEventDesc=[{0}]Tag [{2}] pushed by {3} +bkTgitNoteEventDesc=Note [{1}] submitted by {2} +bkTgitReviewApprovedEventDesc=Code review [{1}] approved by {2} +bkTgitReviewApprovingEventDesc=Code review [{1}] approving +bkTgitReviewChangeDeniedEventDesc=Code review [{1}] change denied by {2} +bkTgitReviewChangeRequiredEventDesc=Code review [{1}] change required by {2} diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 9913702a824..01d0c2ec0c0 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -358,19 +358,19 @@ bkQualityOut=质量红线(准出) bkBuildFinishedAndDenyPause=构建已结束,禁止暂停请求 commonShutdownSuccessContent=【${%s}】- 【${%s}】#${%s} 执行成功,耗时${%s}, 触发人: ${%s}。 commonShutdownFailureContent=【${%s}】- 【${%s}】#${%s} 执行失败,耗时${%s}, 触发人: ${%s}。 -bkTgitPushEventDesc=[{0}] 提交 [{2}] 由 {3} 推送 -bkTgitIssueCreatedEventDesc=议题 [!{1}] 由 {2} 创建 -bkTgitIssueUpdatedEventDesc=议题 [!{1}] 由 {2} 更新 -bkTgitIssueClosedEventDesc=议题 [!{1}] 由 {2} 关闭 -bkTgitIssueReopenedEventDesc=议题 [!{1}] 由 {2} 重新打开 -bkTgitMrCreatedEventDesc=合并请求 [!{1}] 由 {2} 创建 -bkTgitMrUpdatedEventDesc=合并请求 [!{1}] 由 {2} 更新 -bkTgitMrClosedEventDesc=合并请求 [!{1}] 由 {2} 关闭 -bkTgitMrReopenedEventDesc=合并请求 [!{1}] 由 {2} 重新打开 -bkTgitMrPushUpdatedEventDesc=合并请求 [!{1}] 由 {2} 在源分支提交代码触发 -bkTgitTagPushEventDesc=[{0}] 创建Tag [{2}] 由 {3} 推送 -bkTgitNoteEventDesc=评论 [{1}] 由 {2} 发表 -bkTgitReviewApprovedEventDesc=代码审查 [{1}] 由 {2} 评审通过 -bkTgitReviewApprovingEventDesc=代码审查 [{1}] 评审中 -bkTgitReviewChangeDeniedEventDesc=代码审查 [{1}] 被 {2} 拒绝 -bkTgitReviewChangeRequiredEventDesc=代码审查 [{1}] 由 {2} 要求修改 \ No newline at end of file +bkTgitPushEventDesc=[{0}] 提交 [{2}] 由 {3} 推送 +bkTgitIssueCreatedEventDesc=议题 [!{1}] 由 {2} 创建 +bkTgitIssueUpdatedEventDesc=议题 [!{1}] 由 {2} 更新 +bkTgitIssueClosedEventDesc=议题 [!{1}] 由 {2} 关闭 +bkTgitIssueReopenedEventDesc=议题 [!{1}] 由 {2} 重新打开 +bkTgitMrCreatedEventDesc=合并请求 [!{1}] 由 {2} 创建 +bkTgitMrUpdatedEventDesc=合并请求 [!{1}] 由 {2} 更新 +bkTgitMrClosedEventDesc=合并请求 [!{1}] 由 {2} 关闭 +bkTgitMrReopenedEventDesc=合并请求 [!{1}] 由 {2} 重新打开 +bkTgitMrPushUpdatedEventDesc=合并请求 [!{1}] 由 {2} 在源分支提交代码触发 +bkTgitTagPushEventDesc=[{0}] 创建Tag [{2}] 由 {3} 推送 +bkTgitNoteEventDesc=评论 [{1}] 由 {2} 发表 +bkTgitReviewApprovedEventDesc=代码审查 [{1}] 由 {2} 评审通过 +bkTgitReviewApprovingEventDesc=代码审查 [{1}] 评审中 +bkTgitReviewChangeDeniedEventDesc=代码审查 [{1}] 被 {2} 拒绝 +bkTgitReviewChangeRequiredEventDesc=代码审查 [{1}] 由 {2} 要求修改 \ No newline at end of file From 9d8e49fafe4db263acde70da50432acdc038ea1e Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 10 Aug 2023 18:01:24 +0800 Subject: [PATCH 021/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webhook/pojo/code/git/GitPushEvent.kt | 1 + .../handler/tgit/TGitNoteTriggerHandler.kt | 2 +- .../handler/tgit/TGitPushTriggerHandler.kt | 2 +- .../webhook/PipelineBuildWebhookService.kt | 3 +- .../i18n/process/message_en_US.properties | 32 +++++++++---------- .../i18n/process/message_zh_CN.properties | 32 +++++++++---------- 6 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitPushEvent.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitPushEvent.kt index d1416ef5124..fb008141f2b 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitPushEvent.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitPushEvent.kt @@ -55,6 +55,7 @@ data class GitPushEvent( ) : GitEvent() { companion object { const val classType = "push" + const val SHORT_COMMIT_ID_LENGTH = 8 } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt index 36f49fbe9a8..2172f4ab827 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt @@ -125,7 +125,7 @@ class TGitNoteTriggerHandler( code = WebhookI18nConstants.TGIT_NOTE_EVENT_DESC, params = listOf( event.objectAttributes.url, - event.objectAttributes.note, + event.objectAttributes.id.toString(), getUsername(event) ) ) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt index 0662ee9835a..fcb62c5cf95 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt @@ -137,7 +137,7 @@ class TGitPushTriggerHandler( params = listOf( getBranchName(event), "${event.repository.homepage}/commit/${event.checkout_sha}", - "${event.checkout_sha}", + "${event.checkout_sha}".substring(0, GitPushEvent.SHORT_COMMIT_ID_LENGTH), event.user_name ) ) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt index 84b1162f24d..6292233a42a 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt @@ -196,7 +196,8 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { logger.warn("[$pipelineId]| Fail to get the model") return false } - + // 触发事件保存流水线名称 + builder.pipelineName(pipelineInfo.pipelineName) val userId = pipelineInfo.lastModifyUser val variables = mutableMapOf() val container = model.stages[0].containers[0] as TriggerContainer diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index 8fac930cfb7..e2dbb517fa3 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -358,19 +358,19 @@ bkQualityOut=Quality out bkBuildFinishedAndDenyPause=Build Finished And Deny Pause commonShutdownSuccessContent=【${%s}】- 【${%s}】#${%s} Execution succeed,consume time${%s}, trigger user: ${%s}。 commonShutdownFailureContent=【${%s}】- 【${%s}】#${%s} Execution failed,consume time${%s}, trigger user: ${%s}。 -bkTgitPushEventDesc=[{0}] Commit [{2}] pushed by {3} -bkTgitIssueOpenedEventDesc=Issue [!{1}] opened by {2} -bkTgitIssueUpdatedEventDesc=Issue [!{1}] updated by {2} -bkTgitIssueClosedEventDesc=Issue [!{1}] closed by {2} -bkTgitIssueReopenedEventDesc=Issue [!{1}] reopened by {2} -bkTgitMrCreatedEventDesc=Merge requests [!{1}] opened by {2} -bkTgitMrUpdatedEventDesc=Merge requests [!{1}] updated by {2} -bkTgitMrClosedEventDesc=Merge requests [!{1}] closed by {2} -bkTgitMrReopenedEventDesc=Merge requests [!{1}] reopened by {2} -bkTgitMrPushUpdatedEventDesc=Merge requests [!{1}] push updated by {2} -bkTgitTagPushEventDesc=[{0}]Tag [{2}] pushed by {3} -bkTgitNoteEventDesc=Note [{1}] submitted by {2} -bkTgitReviewApprovedEventDesc=Code review [{1}] approved by {2} -bkTgitReviewApprovingEventDesc=Code review [{1}] approving -bkTgitReviewChangeDeniedEventDesc=Code review [{1}] change denied by {2} -bkTgitReviewChangeRequiredEventDesc=Code review [{1}] change required by {2} +bkTgitPushEventDesc=[{0}] Commit [{2}] pushed by {3} +bkTgitIssueOpenedEventDesc=Issue [!{1}] opened by {2} +bkTgitIssueUpdatedEventDesc=Issue [!{1}] updated by {2} +bkTgitIssueClosedEventDesc=Issue [!{1}] closed by {2} +bkTgitIssueReopenedEventDesc=Issue [!{1}] reopened by {2} +bkTgitMrCreatedEventDesc=Merge requests [!{1}] opened by {2} +bkTgitMrUpdatedEventDesc=Merge requests [!{1}] updated by {2} +bkTgitMrClosedEventDesc=Merge requests [!{1}] closed by {2} +bkTgitMrReopenedEventDesc=Merge requests [!{1}] reopened by {2} +bkTgitMrPushUpdatedEventDesc=Merge requests [!{1}] push updated by {2} +bkTgitTagPushEventDesc=[{0}]Tag [{2}] pushed by {3} +bkTgitNoteEventDesc=Note [{1}] submitted by {2} +bkTgitReviewApprovedEventDesc=Code review [{1}] approved by {2} +bkTgitReviewApprovingEventDesc=Code review [{1}] approving +bkTgitReviewChangeDeniedEventDesc=Code review [{1}] change denied by {2} +bkTgitReviewChangeRequiredEventDesc=Code review [{1}] change required by {2} diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 9913702a824..01d0c2ec0c0 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -358,19 +358,19 @@ bkQualityOut=质量红线(准出) bkBuildFinishedAndDenyPause=构建已结束,禁止暂停请求 commonShutdownSuccessContent=【${%s}】- 【${%s}】#${%s} 执行成功,耗时${%s}, 触发人: ${%s}。 commonShutdownFailureContent=【${%s}】- 【${%s}】#${%s} 执行失败,耗时${%s}, 触发人: ${%s}。 -bkTgitPushEventDesc=[{0}] 提交 [{2}] 由 {3} 推送 -bkTgitIssueCreatedEventDesc=议题 [!{1}] 由 {2} 创建 -bkTgitIssueUpdatedEventDesc=议题 [!{1}] 由 {2} 更新 -bkTgitIssueClosedEventDesc=议题 [!{1}] 由 {2} 关闭 -bkTgitIssueReopenedEventDesc=议题 [!{1}] 由 {2} 重新打开 -bkTgitMrCreatedEventDesc=合并请求 [!{1}] 由 {2} 创建 -bkTgitMrUpdatedEventDesc=合并请求 [!{1}] 由 {2} 更新 -bkTgitMrClosedEventDesc=合并请求 [!{1}] 由 {2} 关闭 -bkTgitMrReopenedEventDesc=合并请求 [!{1}] 由 {2} 重新打开 -bkTgitMrPushUpdatedEventDesc=合并请求 [!{1}] 由 {2} 在源分支提交代码触发 -bkTgitTagPushEventDesc=[{0}] 创建Tag [{2}] 由 {3} 推送 -bkTgitNoteEventDesc=评论 [{1}] 由 {2} 发表 -bkTgitReviewApprovedEventDesc=代码审查 [{1}] 由 {2} 评审通过 -bkTgitReviewApprovingEventDesc=代码审查 [{1}] 评审中 -bkTgitReviewChangeDeniedEventDesc=代码审查 [{1}] 被 {2} 拒绝 -bkTgitReviewChangeRequiredEventDesc=代码审查 [{1}] 由 {2} 要求修改 \ No newline at end of file +bkTgitPushEventDesc=[{0}] 提交 [{2}] 由 {3} 推送 +bkTgitIssueCreatedEventDesc=议题 [!{1}] 由 {2} 创建 +bkTgitIssueUpdatedEventDesc=议题 [!{1}] 由 {2} 更新 +bkTgitIssueClosedEventDesc=议题 [!{1}] 由 {2} 关闭 +bkTgitIssueReopenedEventDesc=议题 [!{1}] 由 {2} 重新打开 +bkTgitMrCreatedEventDesc=合并请求 [!{1}] 由 {2} 创建 +bkTgitMrUpdatedEventDesc=合并请求 [!{1}] 由 {2} 更新 +bkTgitMrClosedEventDesc=合并请求 [!{1}] 由 {2} 关闭 +bkTgitMrReopenedEventDesc=合并请求 [!{1}] 由 {2} 重新打开 +bkTgitMrPushUpdatedEventDesc=合并请求 [!{1}] 由 {2} 在源分支提交代码触发 +bkTgitTagPushEventDesc=[{0}] 创建Tag [{2}] 由 {3} 推送 +bkTgitNoteEventDesc=评论 [{1}] 由 {2} 发表 +bkTgitReviewApprovedEventDesc=代码审查 [{1}] 由 {2} 评审通过 +bkTgitReviewApprovingEventDesc=代码审查 [{1}] 评审中 +bkTgitReviewChangeDeniedEventDesc=代码审查 [{1}] 被 {2} 拒绝 +bkTgitReviewChangeRequiredEventDesc=代码审查 [{1}] 由 {2} 要求修改 \ No newline at end of file From b61928cd25035b11b1aa555c492d0fca09978830 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 11 Aug 2023 09:59:53 +0800 Subject: [PATCH 022/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../i18n/process/message_en_US.properties | 30 +++++++++---------- .../i18n/process/message_zh_CN.properties | 30 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index e2dbb517fa3..3532d1f402c 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -358,19 +358,19 @@ bkQualityOut=Quality out bkBuildFinishedAndDenyPause=Build Finished And Deny Pause commonShutdownSuccessContent=【${%s}】- 【${%s}】#${%s} Execution succeed,consume time${%s}, trigger user: ${%s}。 commonShutdownFailureContent=【${%s}】- 【${%s}】#${%s} Execution failed,consume time${%s}, trigger user: ${%s}。 -bkTgitPushEventDesc=[{0}] Commit [{2}] pushed by {3} -bkTgitIssueOpenedEventDesc=Issue [!{1}] opened by {2} -bkTgitIssueUpdatedEventDesc=Issue [!{1}] updated by {2} -bkTgitIssueClosedEventDesc=Issue [!{1}] closed by {2} -bkTgitIssueReopenedEventDesc=Issue [!{1}] reopened by {2} -bkTgitMrCreatedEventDesc=Merge requests [!{1}] opened by {2} -bkTgitMrUpdatedEventDesc=Merge requests [!{1}] updated by {2} -bkTgitMrClosedEventDesc=Merge requests [!{1}] closed by {2} -bkTgitMrReopenedEventDesc=Merge requests [!{1}] reopened by {2} -bkTgitMrPushUpdatedEventDesc=Merge requests [!{1}] push updated by {2} -bkTgitTagPushEventDesc=[{0}]Tag [{2}] pushed by {3} -bkTgitNoteEventDesc=Note [{1}] submitted by {2} -bkTgitReviewApprovedEventDesc=Code review [{1}] approved by {2} +bkTgitPushEventDesc=[{0}] Commit [{2}] pushed by {3} +bkTgitIssueOpenedEventDesc=Issue [!{1}] opened by {2} +bkTgitIssueUpdatedEventDesc=Issue [!{1}] updated by {2} +bkTgitIssueClosedEventDesc=Issue [!{1}] closed by {2} +bkTgitIssueReopenedEventDesc=Issue [!{1}] reopened by {2} +bkTgitMrCreatedEventDesc=Merge requests [!{1}] opened by {2} +bkTgitMrUpdatedEventDesc=Merge requests [!{1}] updated by {2} +bkTgitMrClosedEventDesc=Merge requests [!{1}] closed by {2} +bkTgitMrReopenedEventDesc=Merge requests [!{1}] reopened by {2} +bkTgitMrPushUpdatedEventDesc=Merge requests [!{1}] push updated by {2} +bkTgitTagPushEventDesc=[{0}]Tag [{2}] pushed by {3} +bkTgitNoteEventDesc=Note [{1}] submitted by {2} +bkTgitReviewApprovedEventDesc=Code review [{1}] approved by {2} bkTgitReviewApprovingEventDesc=Code review [{1}] approving -bkTgitReviewChangeDeniedEventDesc=Code review [{1}] change denied by {2} -bkTgitReviewChangeRequiredEventDesc=Code review [{1}] change required by {2} +bkTgitReviewChangeDeniedEventDesc=Code review [{1}] change denied by {2} +bkTgitReviewChangeRequiredEventDesc=Code review [{1}] change required by {2} diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 01d0c2ec0c0..9c74dc141df 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -358,19 +358,19 @@ bkQualityOut=质量红线(准出) bkBuildFinishedAndDenyPause=构建已结束,禁止暂停请求 commonShutdownSuccessContent=【${%s}】- 【${%s}】#${%s} 执行成功,耗时${%s}, 触发人: ${%s}。 commonShutdownFailureContent=【${%s}】- 【${%s}】#${%s} 执行失败,耗时${%s}, 触发人: ${%s}。 -bkTgitPushEventDesc=[{0}] 提交 [{2}] 由 {3} 推送 -bkTgitIssueCreatedEventDesc=议题 [!{1}] 由 {2} 创建 -bkTgitIssueUpdatedEventDesc=议题 [!{1}] 由 {2} 更新 -bkTgitIssueClosedEventDesc=议题 [!{1}] 由 {2} 关闭 -bkTgitIssueReopenedEventDesc=议题 [!{1}] 由 {2} 重新打开 -bkTgitMrCreatedEventDesc=合并请求 [!{1}] 由 {2} 创建 -bkTgitMrUpdatedEventDesc=合并请求 [!{1}] 由 {2} 更新 -bkTgitMrClosedEventDesc=合并请求 [!{1}] 由 {2} 关闭 -bkTgitMrReopenedEventDesc=合并请求 [!{1}] 由 {2} 重新打开 -bkTgitMrPushUpdatedEventDesc=合并请求 [!{1}] 由 {2} 在源分支提交代码触发 -bkTgitTagPushEventDesc=[{0}] 创建Tag [{2}] 由 {3} 推送 -bkTgitNoteEventDesc=评论 [{1}] 由 {2} 发表 -bkTgitReviewApprovedEventDesc=代码审查 [{1}] 由 {2} 评审通过 +bkTgitPushEventDesc=[{0}] 提交 [{2}] 由 {3} 推送 +bkTgitIssueCreatedEventDesc=议题 [!{1}] 由 {2} 创建 +bkTgitIssueUpdatedEventDesc=议题 [!{1}] 由 {2} 更新 +bkTgitIssueClosedEventDesc=议题 [!{1}] 由 {2} 关闭 +bkTgitIssueReopenedEventDesc=议题 [!{1}] 由 {2} 重新打开 +bkTgitMrCreatedEventDesc=合并请求 [!{1}] 由 {2} 创建 +bkTgitMrUpdatedEventDesc=合并请求 [!{1}] 由 {2} 更新 +bkTgitMrClosedEventDesc=合并请求 [!{1}] 由 {2} 关闭 +bkTgitMrReopenedEventDesc=合并请求 [!{1}] 由 {2} 重新打开 +bkTgitMrPushUpdatedEventDesc=合并请求 [!{1}] 由 {2} 在源分支提交代码触发 +bkTgitTagPushEventDesc=[{0}] 创建Tag [{2}] 由 {3} 推送 +bkTgitNoteEventDesc=评论 [{1}] 由 {2} 发表 +bkTgitReviewApprovedEventDesc=代码审查 [{1}] 由 {2} 评审通过 bkTgitReviewApprovingEventDesc=代码审查 [{1}] 评审中 -bkTgitReviewChangeDeniedEventDesc=代码审查 [{1}] 被 {2} 拒绝 -bkTgitReviewChangeRequiredEventDesc=代码审查 [{1}] 由 {2} 要求修改 \ No newline at end of file +bkTgitReviewChangeDeniedEventDesc=代码审查 [{1}] 被 {2} 拒绝 +bkTgitReviewChangeRequiredEventDesc=代码审查 [{1}] 由 {2} 要求修改 \ No newline at end of file From 2ecf0adb7ce73a2ec1a5f83301a3580d67ea152c Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 11 Aug 2023 12:00:05 +0800 Subject: [PATCH 023/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pojo/trigger/PipelineTriggerDetailBuilder.kt | 4 ++++ .../service/webhook/PipelineBuildWebhookService.kt | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetailBuilder.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetailBuilder.kt index aa177421a2f..3ec63a19676 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetailBuilder.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetailBuilder.kt @@ -82,6 +82,10 @@ class PipelineTriggerDetailBuilder { } } + fun buildNum(buildNum: String) = apply { + this.buildNum = buildNum + } + fun build(): PipelineTriggerDetail { return PipelineTriggerDetail( projectId = projectId, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt index 6292233a42a..a4aa7a07d78 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt @@ -33,6 +33,7 @@ import com.tencent.devops.common.client.Client import com.tencent.devops.common.log.pojo.message.LogMessage import com.tencent.devops.common.log.utils.BuildLogPrinter import com.tencent.devops.common.pipeline.container.TriggerContainer +import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.common.pipeline.enums.StartType import com.tencent.devops.common.pipeline.pojo.BuildParameters import com.tencent.devops.common.pipeline.pojo.element.trigger.WebHookTriggerElement @@ -40,6 +41,7 @@ import com.tencent.devops.common.webhook.service.code.loader.WebhookElementParam import com.tencent.devops.common.webhook.service.code.loader.WebhookStartParamsRegistrar import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher import com.tencent.devops.common.webhook.util.EventCacheUtil +import com.tencent.devops.process.api.service.ServiceBuildResource import com.tencent.devops.process.api.service.ServiceScmWebhookResource import com.tencent.devops.process.engine.service.PipelineRepositoryService import com.tencent.devops.process.engine.service.PipelineWebHookQueueService @@ -269,10 +271,18 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { matcher = matcher, repo = repo ) + val buildDetail = client.getGateway(ServiceBuildResource::class).getBuildDetail( + userId = userId, + buildId = buildId, + pipelineId = pipelineId, + projectId = projectId, + channelCode = ChannelCode.BS + ).data builder.buildId(buildId) .status(PipelineTriggerStatus.SUCCEED.name) .eventSource(eventSource = repo.repoHashId!!) .reason(PipelineTriggerReason.TRIGGER_SUCCESS.name) + .buildNum(buildDetail?.buildNum.toString()) } } catch (ignore: Exception) { logger.warn("$pipelineId|webhook trigger|(${element.name})|repo(${matcher.getRepoName()})", ignore) From 46a274b913601e7838d63a2ad39da2b05de7238a Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 11 Aug 2023 14:21:41 +0800 Subject: [PATCH 024/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/common/webhook/pojo/code/svn/SvnCommitEvent.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/svn/SvnCommitEvent.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/svn/SvnCommitEvent.kt index 6c3660497ea..198f2890b20 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/svn/SvnCommitEvent.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/svn/SvnCommitEvent.kt @@ -41,6 +41,5 @@ data class SvnCommitEvent( val revision: Int, val paths: List, val files: List, - val commitTime: Long?, - val repository: GitCommitRepository + val commitTime: Long? ) : CodeWebhookEvent From de37a540703bde270fafa3ac8767eb671e8ae043 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 11 Aug 2023 16:38:32 +0800 Subject: [PATCH 025/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trigger/PipelineTriggerEventService.kt | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt index a264b86cd53..6fc5711733c 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt @@ -35,6 +35,7 @@ import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.PageUtil import com.tencent.devops.common.client.Client +import com.tencent.devops.common.service.utils.HomeHostUtil import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.common.web.utils.I18nUtil.getCodeLanMessage import com.tencent.devops.common.webhook.enums.WebhookI18nConstants @@ -55,6 +56,7 @@ import org.jooq.impl.DSL import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service +import java.text.MessageFormat import java.time.LocalDateTime @Suppress("ALL") @@ -70,6 +72,8 @@ class PipelineTriggerEventService @Autowired constructor( private val logger = LoggerFactory.getLogger(PipelineTriggerEventService::class.java) private const val PIPELINE_TRIGGER_EVENT_BIZ_ID = "PIPELINE_TRIGGER_EVENT" private const val PIPELINE_TRIGGER_DETAIL_BIZ_ID = "PIPELINE_TRIGGER_DETAIL" + // 构建链接 + const val PIPELINE_BUILD_URL_PATTERN = "{1}" } fun getDetailId(): Long { @@ -216,12 +220,8 @@ class PipelineTriggerEventService @Autowired constructor( limit = sqlLimit.limit, offset = sqlLimit.offset ).map { - it.eventDesc = try { - JsonUtil.to(it.eventDesc, I18Variable::class.java).getCodeLanMessage(language) - } catch (ignored: Exception) { - logger.warn("Failed to resolve repo trigger event|sourceDesc[${it.eventDesc}]", ignored) - it.eventDesc - } + it.eventDesc = it.getI18nEventDesc(language) + it.buildNum = it.getBuildNumUrl() it } val count = pipelineTriggerEventDao.countTriggerEvent( @@ -360,4 +360,27 @@ class PipelineTriggerEventService @Autowired constructor( PipelineTriggerType.SERVICE.name -> WebhookI18nConstants.SERVICE_START_EVENT_DESC else -> "" } + + /** + * 获取国际化构建事件描述 + */ + private fun PipelineTriggerEventVo.getI18nEventDesc(language: String) = try { + JsonUtil.to(eventDesc, I18Variable::class.java).getCodeLanMessage(language) + } catch (ignored: Exception) { + logger.warn("Failed to resolve repo trigger event|sourceDesc[$eventDesc]", ignored) + eventDesc + } + + /** + * 获取构建链接 + */ + private fun PipelineTriggerEventVo.getBuildNumUrl(): String? { + return if (status == PipelineTriggerStatus.SUCCEED.name) { + val linkUrl = "${HomeHostUtil.innerServerHost()}/console" + + "/pipeline/$projectId/$pipelineId/detail/$buildId/executeDetail" + MessageFormat.format(PIPELINE_BUILD_URL_PATTERN, linkUrl, buildNum) + } else { + null + } + } } From cc042c2d61ff4630eec37ba96f99e3f03dd61a61 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 14 Aug 2023 18:16:34 +0800 Subject: [PATCH 026/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/api/op/OpScmWebhookResource.kt | 5 + .../process/pojo/webhook/PipelineWebhook.kt | 8 +- .../process/engine/dao/PipelineWebhookDao.kt | 51 ++++++++- .../api/op/OpScmWebhookResourceImpl.kt | 5 + .../engine/service/PipelineWebhookService.kt | 104 +++++++++++++++++- .../constant/RepositoryMessageCode.kt | 1 + .../repository/pojo/GithubRepository.kt | 4 +- .../repository/dao/RepositoryGithubDao.kt | 47 +++++++- .../repository/service/OPRepositoryService.kt | 77 ++++++++++++- .../code/CodeGithubRepositoryService.kt | 54 ++++++++- .../service/github/GithubService.kt | 21 ++++ .../service/github/IGithubService.kt | 3 + .../i18n/repository/message_en_US.properties | 1 + .../i18n/repository/message_zh_CN.properties | 1 + 14 files changed, 366 insertions(+), 16 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/op/OpScmWebhookResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/op/OpScmWebhookResource.kt index e6e283e296d..e5097221fed 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/op/OpScmWebhookResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/op/OpScmWebhookResource.kt @@ -25,4 +25,9 @@ interface OpScmWebhookResource { @QueryParam("scmType") scmType: String ): Result + + @ApiOperation("更新webhook 事件信息") + @PUT + @Path("/updateWebhookEventInfo") + fun updateWebhookEventInfo(): Result } diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhook.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhook.kt index 5b4968f00d2..5d2e202d48e 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhook.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhook.kt @@ -43,7 +43,7 @@ data class PipelineWebhook( @ApiModelProperty("代码库标识类型, ID 代码库HashId / NAME 别名", required = false) val repoType: RepositoryType?, @ApiModelProperty("代码库HashId,repoHashId 与 repoName 不能同时为空,如果两个都不为空就用repoName", required = false) - val repoHashId: String?, // repoHashId 与 repoName 不能同时为空,如果两个都不为空就用repoName + var repoHashId: String?, // repoHashId 与 repoName 不能同时为空,如果两个都不为空就用repoName @ApiModelProperty("代码库别名", required = false) val repoName: String?, @ApiModelProperty("代码库自增ID,唯一", required = false) @@ -51,5 +51,9 @@ data class PipelineWebhook( @ApiModelProperty("项目名称", required = false) var projectName: String? = null, @ApiModelProperty("拉取当前代码库所在的插件ID", required = false) - val taskId: String? = null + val taskId: String? = null, + @ApiModelProperty("事件类型", required = false) + var eventType: String? = null, + @ApiModelProperty("事件源外联Id", required = false) + var externalId: String? = null ) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt index 8e5f7ec7a0f..95f9a89dce1 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt @@ -55,7 +55,9 @@ class PipelineWebhookDao { REPO_HASH_ID, REPO_NAME, PROJECT_NAME, - TASK_ID + TASK_ID, + EVENT_TYPE, + EXTERNAL_ID ) .values( projectId, @@ -65,13 +67,17 @@ class PipelineWebhookDao { repoHashId, repoName, projectName, - taskId + taskId, + eventType, + externalId ) .onDuplicateKeyUpdate() .set(REPO_TYPE, repoType?.name) .set(REPO_HASH_ID, repoHashId) .set(REPO_NAME, repoName) .set(PROJECT_NAME, projectName) + .set(EXTERNAL_ID, externalId) + .set(EVENT_TYPE, eventType) .execute() } } @@ -225,6 +231,47 @@ class PipelineWebhookDao { }?.map { convert(it) } } + fun listWebhook( + dslContext: DSLContext, + repositoryType: String?, + offset: Int, + limit: Int + ):Result{ + return with(T_PIPELINE_WEBHOOK) { + val conditions = mutableListOf( + DELETE.eq(false) + ) + if (!repositoryType.isNullOrBlank()) { + conditions.add(REPOSITORY_TYPE.eq(repositoryType)) + } + dslContext.selectFrom(this) + .where(conditions) + .limit(offset, limit) + .fetch() + } + } + + fun updateWebhookEventInfo( + dslContext: DSLContext, + repoHashId:String?, + eventType: String, + externalId: String, + pipelineId: String, + projectId: String, + taskId: String + ) { + return with(T_PIPELINE_WEBHOOK) { + dslContext.update(this) + .set(REPO_HASH_ID, repoHashId) + .set(EVENT_TYPE, eventType) + .set(EXTERNAL_ID, externalId) + .where(PROJECT_ID.eq(projectId)) + .and(PIPELINE_ID.eq(pipelineId)) + .and(TASK_ID.eq(taskId)) + .execute() + } + } + companion object { private val logger = LoggerFactory.getLogger(PipelineWebhookDao::class.java) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/op/OpScmWebhookResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/op/OpScmWebhookResourceImpl.kt index a56f3c78539..0b678c022bf 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/op/OpScmWebhookResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/op/OpScmWebhookResourceImpl.kt @@ -14,4 +14,9 @@ class OpScmWebhookResourceImpl( pipelineWebhookService.updateWebhookSecret(ScmType.valueOf(scmType)) return Result(true) } + + override fun updateWebhookEventInfo(): Result { + pipelineWebhookService.updateWebhookEventInfo() + return Result(true) + } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index 6eb56fc1a4e..3e9f044f841 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -67,10 +67,21 @@ import com.tencent.devops.process.pojo.webhook.PipelineWebhook import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber import com.tencent.devops.process.service.scm.ScmProxyService import com.tencent.devops.repository.api.ServiceRepositoryResource +import com.tencent.devops.repository.pojo.CodeGitRepository +import com.tencent.devops.repository.pojo.CodeGitlabRepository +import com.tencent.devops.repository.pojo.CodeP4Repository +import com.tencent.devops.repository.pojo.CodeSvnRepository +import com.tencent.devops.repository.pojo.CodeTGitRepository +import com.tencent.devops.repository.pojo.GithubRepository +import com.tencent.devops.repository.pojo.Repository import org.jooq.DSLContext import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service +import java.util.concurrent.Executors +import java.util.concurrent.LinkedBlockingQueue +import java.util.concurrent.ThreadPoolExecutor +import java.util.concurrent.TimeUnit /** * 流水线webhook存储服务 @@ -167,7 +178,11 @@ class PipelineWebhookService @Autowired constructor( if (createPipelineFlag != null && createPipelineFlag) { // 新增流水线时,模版里配置的代码库是变量或者当前项目下不存在,不需创建webhook try { - scmProxyService.getRepo(pipelineWebhook.projectId, repositoryConfig) + val repo = scmProxyService.getRepo(pipelineWebhook.projectId, repositoryConfig) + // 补充代码库hashId + pipelineWebhook.repoHashId = repo.repoHashId + pipelineWebhook.eventType = codeEventType?.name ?: "" + pipelineWebhook.externalId = getExternalId(repo) } catch (e: Exception) { logger.info("skip save Webhook[$pipelineWebhook]: ${e.message}") continueFlag = false @@ -638,4 +653,91 @@ class PipelineWebhookService @Autowired constructor( logger.warn("$id|$pipelineId|update webhook secret exception ignore", t) } } + + fun updateWebhookEventInfo() { + val startTime = System.currentTimeMillis() + val threadPoolExecutor = ThreadPoolExecutor( + 1, + 1, + 0, + TimeUnit.SECONDS, + LinkedBlockingQueue(1), + Executors.defaultThreadFactory(), + ThreadPoolExecutor.AbortPolicy() + ) + threadPoolExecutor.submit { + logger.info("PipelineWebhookService:begin updateWebhookEventInfo threadPoolExecutor") + try { + updateWebhookEventInfoTask() + } catch (e: Exception) { + logger.warn("PipelineWebhookService:updateWebhookEventInfo failed | $e ") + } finally { + threadPoolExecutor.shutdown() + logger.info("PipelineWebhookService:finish updateWebhookEventInfo") + logger.info("updateWebhookEventInfo time cost: ${System.currentTimeMillis() - startTime}") + } + } + } + + private fun updateWebhookEventInfoTask(){ + var offset = 0 + val limit = 1000 + do { + val webhookList = pipelineWebhookDao.listWebhook( + dslContext = dslContext, + repositoryType = null, + limit = limit, + offset = offset + ) + val repoSize = webhookList.size + webhookList.forEach { + with(it){ + val repositoryInfo = scmProxyService.getRepo( + it.projectId, + RepositoryConfig( + repositoryHashId = it.repoHashId, + repositoryName = it.repoName, + repositoryType = RepositoryType.valueOf(it.repositoryType) + ) + ) + val model = getModel(it.projectId, it.pipelineId) + if (model == null) { + logger.info("$projectId|$pipelineId|model is null") + return@forEach + } + val triggerContainer = model.stages[0].containers[0] as TriggerContainer + val params = triggerContainer.params.associate { param -> + param.id to param.defaultValue.toString() + } + val elements = triggerContainer.elements.filterIsInstance() + elements.forEach elements@ { element -> + run { + val webhookElementParams = getElementRepositoryConfig(element, variable = params) + ?: return@elements + pipelineWebhookDao.updateWebhookEventInfo( + dslContext = dslContext, + eventType = webhookElementParams.eventType?.name ?: "", + externalId = getExternalId(repositoryInfo), + projectId = it.projectId, + pipelineId = it.pipelineId, + taskId = it.taskId, + repoHashId = repositoryInfo.repoHashId + ) + } + } + } + } + offset += limit + } while (repoSize == 1000) + } + + private fun getExternalId(repository: Repository?) = when (repository) { + is CodeGitRepository -> repository.gitProjectId + is CodeTGitRepository -> repository.gitProjectId + is GithubRepository -> repository.gitProjectId + is CodeGitlabRepository -> repository.gitProjectId + is CodeSvnRepository -> repository.url + is CodeP4Repository -> repository.url + else -> "" + }?.toString() ?: "" } diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/constant/RepositoryMessageCode.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/constant/RepositoryMessageCode.kt index 0ab420f088e..a095dc9d6cf 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/constant/RepositoryMessageCode.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/constant/RepositoryMessageCode.kt @@ -82,4 +82,5 @@ object RepositoryMessageCode { const val OPERATION_GET_TAG = "OperationGetTag" // 获取指定Tag const val OPERATION_LIST_BRANCHS = "OperationListBranchs" // 获取分支列表 const val OPERATION_LIST_TAGS = "OperationListTags" // 获取Tag列表 + const val OPERATION_GET_REPO = "OperationGetRepo" // 获取单个仓库信息 } diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/GithubRepository.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/GithubRepository.kt index 67ba564cca2..8a802f3ff3e 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/GithubRepository.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/GithubRepository.kt @@ -43,7 +43,9 @@ data class GithubRepository( @ApiModelProperty("项目id", required = true) override val projectId: String = "", @ApiModelProperty("仓库hash id", required = false) - override val repoHashId: String? + override val repoHashId: String?, + @ApiModelProperty("Git仓库ID", required = false) + val gitProjectId: Long? = null ) : Repository { companion object { const val classType = "github" diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryGithubDao.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryGithubDao.kt index 599967c514e..33908db06a9 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryGithubDao.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryGithubDao.kt @@ -27,6 +27,7 @@ package com.tencent.devops.repository.dao +import com.tencent.devops.model.repository.tables.TRepositoryCodeGit import com.tencent.devops.model.repository.tables.TRepositoryCodeGitlab import com.tencent.devops.model.repository.tables.TRepositoryGithub import com.tencent.devops.model.repository.tables.records.TRepositoryGithubRecord @@ -43,7 +44,8 @@ class RepositoryGithubDao { dslContext: DSLContext, repositoryId: Long, projectName: String, - userName: String + userName: String, + gitProjectId: Long? ) { val now = LocalDateTime.now() with(TRepositoryGithub.T_REPOSITORY_GITHUB) { @@ -53,14 +55,16 @@ class RepositoryGithubDao { PROJECT_NAME, USER_NAME, CREATED_TIME, - UPDATED_TIME + UPDATED_TIME, + GIT_PROJECT_ID ) .values( repositoryId, projectName, userName, now, - now + now, + gitProjectId ).execute() } } @@ -81,7 +85,8 @@ class RepositoryGithubDao { dslContext: DSLContext, repositoryId: Long, projectName: String, - userName: String + userName: String, + gitProjectId: Long ) { val now = LocalDateTime.now() with(TRepositoryGithub.T_REPOSITORY_GITHUB) { @@ -89,6 +94,7 @@ class RepositoryGithubDao { .set(PROJECT_NAME, projectName) .set(USER_NAME, userName) .set(UPDATED_TIME, now) + .set(GIT_PROJECT_ID, gitProjectId) .where(REPOSITORY_ID.eq(repositoryId)) .execute() } @@ -123,4 +129,37 @@ class RepositoryGithubDao { .fetch() } } + + /** + * 分页查询 + */ + fun getAllRepo( + dslContext: DSLContext, + limit: Int, + offset: Int + ): Result? { + with(TRepositoryGithub.T_REPOSITORY_GITHUB) { + return dslContext.selectFrom(this) + .orderBy(CREATED_TIME.desc()) + .limit(limit).offset(offset) + .fetch() + } + } + + fun updateGitProjectId( + dslContext: DSLContext, + id: Long, + gitProjectId: Long + ) { + with(TRepositoryGithub.T_REPOSITORY_GITHUB) { + val conditions = mutableListOf( + REPOSITORY_ID.eq(id), + GIT_PROJECT_ID.le(0) + ) + dslContext.update(this) + .set(GIT_PROJECT_ID, gitProjectId) + .where(conditions) + .execute() + } + } } diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/OPRepositoryService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/OPRepositoryService.kt index b09d53cdccb..33faa64095a 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/OPRepositoryService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/OPRepositoryService.kt @@ -33,8 +33,11 @@ import com.tencent.devops.model.repository.tables.records.TRepositoryRecord import com.tencent.devops.repository.dao.RepositoryCodeGitDao import com.tencent.devops.repository.dao.RepositoryCodeGitLabDao import com.tencent.devops.repository.dao.RepositoryDao +import com.tencent.devops.repository.dao.RepositoryGithubDao import com.tencent.devops.repository.pojo.CodeGitRepository import com.tencent.devops.repository.pojo.enums.RepoAuthType +import com.tencent.devops.repository.service.github.GithubService +import com.tencent.devops.repository.service.github.GithubTokenService import com.tencent.devops.repository.service.scm.IGitOauthService import com.tencent.devops.repository.service.scm.IScmOauthService import com.tencent.devops.repository.service.scm.IScmService @@ -55,9 +58,12 @@ class OPRepositoryService @Autowired constructor( private val dslContext: DSLContext, private val codeGitLabDao: RepositoryCodeGitLabDao, private val codeGitDao: RepositoryCodeGitDao, + private val codeGithubDao: RepositoryGithubDao, private val scmService: IScmService, private val scmOauthService: IScmOauthService, private val gitOauthService: IGitOauthService, + private val githubTokenService: GithubTokenService, + private val githubService: GithubService, private val credentialService: CredentialService ) { fun addHashId() { @@ -181,8 +187,7 @@ class OPRepositoryService @Autowired constructor( threadPoolExecutor.submit { logger.info("OPRepositoryService:begin updateGitProjectId threadPoolExecutor-----------") try { - updateGitLabProjectId() - updateCodeGitProjectId() + updateCodeGithubProjectId() } catch (e: Exception) { logger.warn("OpRepositoryService:updateGitProjectId failed | $e ") } finally { @@ -330,6 +335,74 @@ class OPRepositoryService @Autowired constructor( logger.info("OPRepositoryService:end updateCodeGitProjectId") } + fun updateCodeGithubProjectId() { + var offset = 0 + val limit = 100 + logger.info("OPRepositoryService:begin updateCodeGithubProjectId") + do { + val repoRecords = codeGithubDao.getAllRepo(dslContext, limit, offset) + val repoSize = repoRecords?.size + logger.info("repoSize:$repoSize") + val repositoryIds = repoRecords?.map { it.repositoryId } ?: ArrayList() + val repoMap = mutableMapOf() + repositoryDao.getRepoByIds( + repositoryIds = repositoryIds, + dslContext = dslContext + )?.forEach { it -> + run { + repoMap[it.repositoryId] = it + } + } + repoRecords?.forEach { + val repositoryId = it.repositoryId + // 基础信息 + val repositoryInfo = repoMap[repositoryId] + if (repositoryInfo == null) { + logger.warn("Invalid codeGithub repository info,repositoryId=[$repositoryId]") + codeGithubDao.updateGitProjectId( + dslContext = dslContext, + id = repositoryId, + gitProjectId = 0L + ) + return@forEach + } + // 仅处理未删除代码库信息 + if (repositoryInfo.isDeleted) { + logger.warn("Invalid codeGithub repository info,repository deleted,repositoryId=[$repositoryId]") + codeGithubDao.updateGitProjectId( + dslContext = dslContext, + id = repositoryId, + gitProjectId = 0L + ) + return@forEach + } + // 获取token + val token = githubTokenService.getAccessToken(it.userName)?.accessToken + if (token.isNullOrBlank()){ + logger.warn("Invalid codeGithub repository token,accessToken is blank|userId[${it.userName}]") + codeGithubDao.updateGitProjectId( + dslContext = dslContext, + id = repositoryId, + gitProjectId = 0L + ) + return@forEach + } + // 获取代码库信息 + val repositoryProjectInfo = githubService.getRepositoryInfo(token, it.projectName) + val gitProjectId = repositoryProjectInfo.id + codeGithubDao.updateGitProjectId( + dslContext = dslContext, + id = repositoryId, + gitProjectId = gitProjectId + ) + } + offset += limit + // 避免限流,增加一秒休眠时间 + Thread.sleep(1 * 1000) + } while (repoSize == 100) + logger.info("OPRepositoryService:end updateCodeGithubProjectId") + } + private fun getToken(isOauth: Boolean, it: Record, repositoryInfo: TRepositoryRecord): String? { return try { if (isOauth) { diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/code/CodeGithubRepositoryService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/code/CodeGithubRepositoryService.kt index e47dbe4690e..542bff971b7 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/code/CodeGithubRepositoryService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/code/CodeGithubRepositoryService.kt @@ -37,8 +37,11 @@ import com.tencent.devops.repository.dao.RepositoryGithubDao import com.tencent.devops.repository.pojo.GithubRepository import com.tencent.devops.repository.pojo.auth.RepoAuthInfo import com.tencent.devops.repository.pojo.enums.RepoAuthType +import com.tencent.devops.repository.service.github.GithubService +import com.tencent.devops.repository.service.github.GithubTokenService import org.jooq.DSLContext import org.jooq.impl.DSL +import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component @@ -46,7 +49,9 @@ import org.springframework.stereotype.Component class CodeGithubRepositoryService @Autowired constructor( private val repositoryDao: RepositoryDao, private val repositoryGithubDao: RepositoryGithubDao, - private val dslContext: DSLContext + private val dslContext: DSLContext, + private val githubService: GithubService, + private val githubTokenService: GithubTokenService ) : CodeRepositoryService { override fun repositoryType(): String { return GithubRepository::class.java.name @@ -65,7 +70,13 @@ class CodeGithubRepositoryService @Autowired constructor( url = repository.getFormatURL(), type = ScmType.GITHUB ) - repositoryGithubDao.create(transactionContext, repositoryId, repository.projectName, userId) + repositoryGithubDao.create( + dslContext = transactionContext, + repositoryId = repositoryId, + projectName = repository.projectName, + userName = userId, + gitProjectId = getProjectId(repository, userId) + ) } return repositoryId } @@ -87,6 +98,18 @@ class CodeGithubRepositoryService @Autowired constructor( ) } val repositoryId = HashUtil.decodeOtherIdToLong(repositoryHashId) + val sourceUrl = repositoryDao.get( + dslContext = dslContext, + projectId = projectId, + repositoryId = repositoryId + ).url + var gitProjectId = 0L + if (sourceUrl != repository.url) { + logger.info("repository url unMatch,need change gitProjectId,sourceUrl=[$sourceUrl] " + + "targetUrl=[${repository.url}]") + // Git项目ID + gitProjectId = getProjectId(repository,userId) + } dslContext.transaction { configuration -> val transactionContext = DSL.using(configuration) repositoryDao.edit( @@ -95,7 +118,13 @@ class CodeGithubRepositoryService @Autowired constructor( aliasName = repository.aliasName, url = repository.getFormatURL() ) - repositoryGithubDao.edit(dslContext, repositoryId, repository.projectName, repository.userName) + repositoryGithubDao.edit( + dslContext, + repositoryId, + repository.projectName, + repository.userName, + gitProjectId = gitProjectId + ) } } @@ -107,11 +136,28 @@ class CodeGithubRepositoryService @Autowired constructor( userName = repository.userId, projectName = record.projectName, projectId = repository.projectId, - repoHashId = HashUtil.encodeOtherLongId(repository.repositoryId) + repoHashId = HashUtil.encodeOtherLongId(repository.repositoryId), + gitProjectId = record.gitProjectId.toLong() ) } override fun getAuthInfo(repositoryIds: List): Map { return repositoryIds.associateWith { RepoAuthInfo(authType = RepoAuthType.OAUTH.name, credentialId = "") } } + + private fun getProjectId(repository: GithubRepository, userId: String): Long { + val accessToken = githubTokenService.getAccessToken(userId) + // github仓库基本信息 + val githubRepo = if (accessToken == null) { + logger.warn("The user[$userId] token invalid") + null + } else { + githubService.getRepositoryInfo(accessToken.accessToken, repository.projectName) + } + return githubRepo?.id ?: 0L + } + + companion object { + private val logger = LoggerFactory.getLogger(CodeGithubRepositoryService::class.java) + } } diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/GithubService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/GithubService.kt index bf76ae15af9..71375bb0b4b 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/GithubService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/GithubService.kt @@ -45,6 +45,7 @@ import com.tencent.devops.common.webhook.pojo.code.github.GithubWebhook import com.tencent.devops.process.api.service.ServiceScmWebhookResource import com.tencent.devops.repository.constant.RepositoryMessageCode.OPERATION_ADD_CHECK_RUNS import com.tencent.devops.repository.constant.RepositoryMessageCode.OPERATION_GET_BRANCH +import com.tencent.devops.repository.constant.RepositoryMessageCode.OPERATION_GET_REPO import com.tencent.devops.repository.constant.RepositoryMessageCode.OPERATION_GET_REPOS import com.tencent.devops.repository.constant.RepositoryMessageCode.OPERATION_GET_TAG import com.tencent.devops.repository.constant.RepositoryMessageCode.OPERATION_LIST_BRANCHS @@ -290,6 +291,26 @@ class GithubService @Autowired constructor( ) } + override fun getRepositoryInfo(token: String, projectName: String): GithubRepo { + logger.info("getRepositoryInfo| $projectName") + return RetryUtils.execute( + object : RetryUtils.Action { + override fun fail(e: Throwable): GithubRepo { + logger.warn("BKSystemMonitor|getRepositoryInfo fail| e=${e.message}", e) + throw e + } + override fun execute(): GithubRepo { + val path = "repos/$projectName" + val request = buildGet(token, path) + val operation = getMessageByLocale(OPERATION_GET_REPO) + val body = getBody(operation, request) + return objectMapper.readValue(body) + } + }, + 3, SLEEP_MILLS_FOR_RETRY_500 + ) + } + private fun buildPost(token: String, path: String, body: String): Request { return request(token, path) .post(RequestBody.create("application/json; charset=utf-8".toMediaTypeOrNull(), body)) diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/IGithubService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/IGithubService.kt index 20a3aa26619..da739205d9d 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/IGithubService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/IGithubService.kt @@ -31,6 +31,7 @@ import com.tencent.devops.repository.pojo.AuthorizeResult import com.tencent.devops.repository.pojo.GithubCheckRuns import com.tencent.devops.repository.pojo.GithubCheckRunsResponse import com.tencent.devops.repository.pojo.github.GithubBranch +import com.tencent.devops.repository.pojo.github.GithubRepo import com.tencent.devops.repository.pojo.github.GithubTag interface IGithubService { @@ -61,4 +62,6 @@ interface IGithubService { fun listBranches(token: String, projectName: String): List fun listTags(token: String, projectName: String): List + + fun getRepositoryInfo(token: String, projectName: String): GithubRepo } diff --git a/support-files/i18n/repository/message_en_US.properties b/support-files/i18n/repository/message_en_US.properties index 8909c849d9c..bb573e68759 100644 --- a/support-files/i18n/repository/message_en_US.properties +++ b/support-files/i18n/repository/message_en_US.properties @@ -32,3 +32,4 @@ OperationGetBranch=Gets the specified branch OperationGetTag=Gets the specified Tag OperationListBranchs=Get a list of branches OperationListTags=Get the list of Tags +OperationGetRepo=get repository info \ No newline at end of file diff --git a/support-files/i18n/repository/message_zh_CN.properties b/support-files/i18n/repository/message_zh_CN.properties index 99ef362b9f0..1e7c1de5b00 100644 --- a/support-files/i18n/repository/message_zh_CN.properties +++ b/support-files/i18n/repository/message_zh_CN.properties @@ -32,3 +32,4 @@ OperationGetBranch=获取指定分支 OperationGetTag=获取指定Tag OperationListBranchs=获取分支列表 OperationListTags=获取Tag列表 +OperationGetRepo=获取代码库信息 From b7dba10cd4c8992bcc67a077793eeca9e0d4c95a Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 15 Aug 2023 09:37:12 +0800 Subject: [PATCH 027/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sql/1001_ci_process_ddl_mysql.sql | 2 ++ .../sql/1001_ci_repository_ddl_mysql.sql | 1 + .../2010_ci_process-update_v1.10_mysql.sql | 19 +++++++++++++++++++ .../2010_ci_repository-update_v1.10_mysql.sql | 9 +++++++++ 4 files changed, 31 insertions(+) diff --git a/support-files/sql/1001_ci_process_ddl_mysql.sql b/support-files/sql/1001_ci_process_ddl_mysql.sql index d5df8981e1b..1036b36a5ab 100644 --- a/support-files/sql/1001_ci_process_ddl_mysql.sql +++ b/support-files/sql/1001_ci_process_ddl_mysql.sql @@ -638,6 +638,8 @@ CREATE TABLE IF NOT EXISTS `T_PIPELINE_WEBHOOK` ( `PROJECT_NAME` VARCHAR(128) DEFAULT NULL COMMENT '项目名称', `TASK_ID` VARCHAR(34) DEFAULT NULL COMMENT '任务id', `DELETE` BIT(1) DEFAULT 0 COMMENT '是否删除', + `EVENT_TYPE` varchar(32) DEFAULT NULL COMMENT '事件类型', + `EXTERNAL_ID` varchar(32) DEFAULT NULL COMMENT 'webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port', PRIMARY KEY (`ID`), UNIQUE KEY `UNI_INX_TPW_PROJECT_PIPELINE_TASK` (`PROJECT_ID`, `PIPELINE_ID`,`TASK_ID`), KEY `IDX_PROJECT_NAME_REPOSITORY_TYPE` (`PROJECT_NAME`, `REPOSITORY_TYPE`) diff --git a/support-files/sql/1001_ci_repository_ddl_mysql.sql b/support-files/sql/1001_ci_repository_ddl_mysql.sql index 16cc5b91759..0c69cccc263 100644 --- a/support-files/sql/1001_ci_repository_ddl_mysql.sql +++ b/support-files/sql/1001_ci_repository_ddl_mysql.sql @@ -105,6 +105,7 @@ CREATE TABLE IF NOT EXISTS `T_REPOSITORY_GITHUB` ( `USER_NAME` varchar(64) NOT NULL COMMENT '用户名称', `CREATED_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `UPDATED_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', + `GIT_PROJECT_ID` bigint(20) DEFAULT 0 COMMENT 'GIT项目ID', PRIMARY KEY (`REPOSITORY_ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='github代码库明细表'; diff --git a/support-files/sql/2002_v1.x/2010_ci_process-update_v1.10_mysql.sql b/support-files/sql/2002_v1.x/2010_ci_process-update_v1.10_mysql.sql index aec14e3d3fc..28f9d33f3f9 100644 --- a/support-files/sql/2002_v1.x/2010_ci_process-update_v1.10_mysql.sql +++ b/support-files/sql/2002_v1.x/2010_ci_process-update_v1.10_mysql.sql @@ -21,6 +21,25 @@ IF NOT EXISTS(SELECT 1 IDX_SEARCH_ID (`RESOURCE_TYPE`, `PROJECT_ID`, `RESOURCE_ID`); END IF; + + IF NOT EXISTS(SELECT 1 + FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = db + AND TABLE_NAME = 'T_PIPELINE_WEBHOOK' + AND COLUMN_NAME = 'EVENT_TYPE') THEN + ALTER TABLE `T_PIPELINE_WEBHOOK` + ADD COLUMN `EVENT_TYPE` varchar(32) DEFAULT null COMMENT '事件类型'; + END IF; + + IF NOT EXISTS(SELECT 1 + FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = db + AND TABLE_NAME = 'T_PIPELINE_WEBHOOK' + AND COLUMN_NAME = 'EXTERNAL_ID') THEN + ALTER TABLE `T_PIPELINE_WEBHOOK` + ADD COLUMN `EXTERNAL_ID` varchar(32) DEFAULT null COMMENT 'webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port'; + END IF; + COMMIT; END DELIMITER ; diff --git a/support-files/sql/2002_v1.x/2010_ci_repository-update_v1.10_mysql.sql b/support-files/sql/2002_v1.x/2010_ci_repository-update_v1.10_mysql.sql index 6e027f0a26a..243c21c2835 100644 --- a/support-files/sql/2002_v1.x/2010_ci_repository-update_v1.10_mysql.sql +++ b/support-files/sql/2002_v1.x/2010_ci_repository-update_v1.10_mysql.sql @@ -23,6 +23,15 @@ BEGIN alter table T_REPOSITORY_GITHUB_TOKEN add constraint USER_ID unique (USER_ID, TYPE); END IF; + IF NOT EXISTS(SELECT 1 + FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = db + AND TABLE_NAME = 'T_REPOSITORY_CODE_GITLAB' + AND COLUMN_NAME = 'GIT_PROJECT_ID') THEN + ALTER TABLE `T_REPOSITORY_CODE_GITLAB` + ADD COLUMN `GIT_PROJECT_ID` bigint(20) DEFAULT 0 COMMENT 'GIT项目ID'; + END IF; + COMMIT; END DELIMITER ; From d9ca3b70451958565de93cf457f56dbc56a5fd26 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 15 Aug 2023 09:39:54 +0800 Subject: [PATCH 028/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sql/2002_v1.x/2010_ci_repository-update_v1.10_mysql.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/support-files/sql/2002_v1.x/2010_ci_repository-update_v1.10_mysql.sql b/support-files/sql/2002_v1.x/2010_ci_repository-update_v1.10_mysql.sql index 243c21c2835..d08f577f143 100644 --- a/support-files/sql/2002_v1.x/2010_ci_repository-update_v1.10_mysql.sql +++ b/support-files/sql/2002_v1.x/2010_ci_repository-update_v1.10_mysql.sql @@ -26,9 +26,9 @@ BEGIN IF NOT EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = db - AND TABLE_NAME = 'T_REPOSITORY_CODE_GITLAB' + AND TABLE_NAME = 'T_REPOSITORY_GITHUB' AND COLUMN_NAME = 'GIT_PROJECT_ID') THEN - ALTER TABLE `T_REPOSITORY_CODE_GITLAB` + ALTER TABLE `T_REPOSITORY_GITHUB` ADD COLUMN `GIT_PROJECT_ID` bigint(20) DEFAULT 0 COMMENT 'GIT项目ID'; END IF; From 14c6e9aca836d60501f5c35310ac081adb56ee96 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 15 Aug 2023 11:49:09 +0800 Subject: [PATCH 029/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/service/PipelineWebhookService.kt | 2 - .../repository/pojo/GithubRepository.kt | 4 +- .../repository/dao/RepositoryGithubDao.kt | 14 +--- .../repository/service/OPRepositoryService.kt | 77 +------------------ .../code/CodeGithubRepositoryService.kt | 54 +------------ .../service/github/GithubService.kt | 21 ----- .../service/github/IGithubService.kt | 2 - 7 files changed, 11 insertions(+), 163 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index 3e9f044f841..b01d325493e 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -72,7 +72,6 @@ import com.tencent.devops.repository.pojo.CodeGitlabRepository import com.tencent.devops.repository.pojo.CodeP4Repository import com.tencent.devops.repository.pojo.CodeSvnRepository import com.tencent.devops.repository.pojo.CodeTGitRepository -import com.tencent.devops.repository.pojo.GithubRepository import com.tencent.devops.repository.pojo.Repository import org.jooq.DSLContext import org.slf4j.LoggerFactory @@ -734,7 +733,6 @@ class PipelineWebhookService @Autowired constructor( private fun getExternalId(repository: Repository?) = when (repository) { is CodeGitRepository -> repository.gitProjectId is CodeTGitRepository -> repository.gitProjectId - is GithubRepository -> repository.gitProjectId is CodeGitlabRepository -> repository.gitProjectId is CodeSvnRepository -> repository.url is CodeP4Repository -> repository.url diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/GithubRepository.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/GithubRepository.kt index 8a802f3ff3e..67ba564cca2 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/GithubRepository.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/GithubRepository.kt @@ -43,9 +43,7 @@ data class GithubRepository( @ApiModelProperty("项目id", required = true) override val projectId: String = "", @ApiModelProperty("仓库hash id", required = false) - override val repoHashId: String?, - @ApiModelProperty("Git仓库ID", required = false) - val gitProjectId: Long? = null + override val repoHashId: String? ) : Repository { companion object { const val classType = "github" diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryGithubDao.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryGithubDao.kt index 33908db06a9..41b1ddf8dc7 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryGithubDao.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryGithubDao.kt @@ -27,7 +27,6 @@ package com.tencent.devops.repository.dao -import com.tencent.devops.model.repository.tables.TRepositoryCodeGit import com.tencent.devops.model.repository.tables.TRepositoryCodeGitlab import com.tencent.devops.model.repository.tables.TRepositoryGithub import com.tencent.devops.model.repository.tables.records.TRepositoryGithubRecord @@ -44,8 +43,7 @@ class RepositoryGithubDao { dslContext: DSLContext, repositoryId: Long, projectName: String, - userName: String, - gitProjectId: Long? + userName: String ) { val now = LocalDateTime.now() with(TRepositoryGithub.T_REPOSITORY_GITHUB) { @@ -55,16 +53,14 @@ class RepositoryGithubDao { PROJECT_NAME, USER_NAME, CREATED_TIME, - UPDATED_TIME, - GIT_PROJECT_ID + UPDATED_TIME ) .values( repositoryId, projectName, userName, now, - now, - gitProjectId + now ).execute() } } @@ -85,8 +81,7 @@ class RepositoryGithubDao { dslContext: DSLContext, repositoryId: Long, projectName: String, - userName: String, - gitProjectId: Long + userName: String ) { val now = LocalDateTime.now() with(TRepositoryGithub.T_REPOSITORY_GITHUB) { @@ -94,7 +89,6 @@ class RepositoryGithubDao { .set(PROJECT_NAME, projectName) .set(USER_NAME, userName) .set(UPDATED_TIME, now) - .set(GIT_PROJECT_ID, gitProjectId) .where(REPOSITORY_ID.eq(repositoryId)) .execute() } diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/OPRepositoryService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/OPRepositoryService.kt index 33faa64095a..b09d53cdccb 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/OPRepositoryService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/OPRepositoryService.kt @@ -33,11 +33,8 @@ import com.tencent.devops.model.repository.tables.records.TRepositoryRecord import com.tencent.devops.repository.dao.RepositoryCodeGitDao import com.tencent.devops.repository.dao.RepositoryCodeGitLabDao import com.tencent.devops.repository.dao.RepositoryDao -import com.tencent.devops.repository.dao.RepositoryGithubDao import com.tencent.devops.repository.pojo.CodeGitRepository import com.tencent.devops.repository.pojo.enums.RepoAuthType -import com.tencent.devops.repository.service.github.GithubService -import com.tencent.devops.repository.service.github.GithubTokenService import com.tencent.devops.repository.service.scm.IGitOauthService import com.tencent.devops.repository.service.scm.IScmOauthService import com.tencent.devops.repository.service.scm.IScmService @@ -58,12 +55,9 @@ class OPRepositoryService @Autowired constructor( private val dslContext: DSLContext, private val codeGitLabDao: RepositoryCodeGitLabDao, private val codeGitDao: RepositoryCodeGitDao, - private val codeGithubDao: RepositoryGithubDao, private val scmService: IScmService, private val scmOauthService: IScmOauthService, private val gitOauthService: IGitOauthService, - private val githubTokenService: GithubTokenService, - private val githubService: GithubService, private val credentialService: CredentialService ) { fun addHashId() { @@ -187,7 +181,8 @@ class OPRepositoryService @Autowired constructor( threadPoolExecutor.submit { logger.info("OPRepositoryService:begin updateGitProjectId threadPoolExecutor-----------") try { - updateCodeGithubProjectId() + updateGitLabProjectId() + updateCodeGitProjectId() } catch (e: Exception) { logger.warn("OpRepositoryService:updateGitProjectId failed | $e ") } finally { @@ -335,74 +330,6 @@ class OPRepositoryService @Autowired constructor( logger.info("OPRepositoryService:end updateCodeGitProjectId") } - fun updateCodeGithubProjectId() { - var offset = 0 - val limit = 100 - logger.info("OPRepositoryService:begin updateCodeGithubProjectId") - do { - val repoRecords = codeGithubDao.getAllRepo(dslContext, limit, offset) - val repoSize = repoRecords?.size - logger.info("repoSize:$repoSize") - val repositoryIds = repoRecords?.map { it.repositoryId } ?: ArrayList() - val repoMap = mutableMapOf() - repositoryDao.getRepoByIds( - repositoryIds = repositoryIds, - dslContext = dslContext - )?.forEach { it -> - run { - repoMap[it.repositoryId] = it - } - } - repoRecords?.forEach { - val repositoryId = it.repositoryId - // 基础信息 - val repositoryInfo = repoMap[repositoryId] - if (repositoryInfo == null) { - logger.warn("Invalid codeGithub repository info,repositoryId=[$repositoryId]") - codeGithubDao.updateGitProjectId( - dslContext = dslContext, - id = repositoryId, - gitProjectId = 0L - ) - return@forEach - } - // 仅处理未删除代码库信息 - if (repositoryInfo.isDeleted) { - logger.warn("Invalid codeGithub repository info,repository deleted,repositoryId=[$repositoryId]") - codeGithubDao.updateGitProjectId( - dslContext = dslContext, - id = repositoryId, - gitProjectId = 0L - ) - return@forEach - } - // 获取token - val token = githubTokenService.getAccessToken(it.userName)?.accessToken - if (token.isNullOrBlank()){ - logger.warn("Invalid codeGithub repository token,accessToken is blank|userId[${it.userName}]") - codeGithubDao.updateGitProjectId( - dslContext = dslContext, - id = repositoryId, - gitProjectId = 0L - ) - return@forEach - } - // 获取代码库信息 - val repositoryProjectInfo = githubService.getRepositoryInfo(token, it.projectName) - val gitProjectId = repositoryProjectInfo.id - codeGithubDao.updateGitProjectId( - dslContext = dslContext, - id = repositoryId, - gitProjectId = gitProjectId - ) - } - offset += limit - // 避免限流,增加一秒休眠时间 - Thread.sleep(1 * 1000) - } while (repoSize == 100) - logger.info("OPRepositoryService:end updateCodeGithubProjectId") - } - private fun getToken(isOauth: Boolean, it: Record, repositoryInfo: TRepositoryRecord): String? { return try { if (isOauth) { diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/code/CodeGithubRepositoryService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/code/CodeGithubRepositoryService.kt index 542bff971b7..4552cb68008 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/code/CodeGithubRepositoryService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/code/CodeGithubRepositoryService.kt @@ -37,11 +37,8 @@ import com.tencent.devops.repository.dao.RepositoryGithubDao import com.tencent.devops.repository.pojo.GithubRepository import com.tencent.devops.repository.pojo.auth.RepoAuthInfo import com.tencent.devops.repository.pojo.enums.RepoAuthType -import com.tencent.devops.repository.service.github.GithubService -import com.tencent.devops.repository.service.github.GithubTokenService import org.jooq.DSLContext import org.jooq.impl.DSL -import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component @@ -49,9 +46,7 @@ import org.springframework.stereotype.Component class CodeGithubRepositoryService @Autowired constructor( private val repositoryDao: RepositoryDao, private val repositoryGithubDao: RepositoryGithubDao, - private val dslContext: DSLContext, - private val githubService: GithubService, - private val githubTokenService: GithubTokenService + private val dslContext: DSLContext ) : CodeRepositoryService { override fun repositoryType(): String { return GithubRepository::class.java.name @@ -70,13 +65,7 @@ class CodeGithubRepositoryService @Autowired constructor( url = repository.getFormatURL(), type = ScmType.GITHUB ) - repositoryGithubDao.create( - dslContext = transactionContext, - repositoryId = repositoryId, - projectName = repository.projectName, - userName = userId, - gitProjectId = getProjectId(repository, userId) - ) + repositoryGithubDao.create(transactionContext, repositoryId, repository.projectName, userId) } return repositoryId } @@ -98,18 +87,6 @@ class CodeGithubRepositoryService @Autowired constructor( ) } val repositoryId = HashUtil.decodeOtherIdToLong(repositoryHashId) - val sourceUrl = repositoryDao.get( - dslContext = dslContext, - projectId = projectId, - repositoryId = repositoryId - ).url - var gitProjectId = 0L - if (sourceUrl != repository.url) { - logger.info("repository url unMatch,need change gitProjectId,sourceUrl=[$sourceUrl] " + - "targetUrl=[${repository.url}]") - // Git项目ID - gitProjectId = getProjectId(repository,userId) - } dslContext.transaction { configuration -> val transactionContext = DSL.using(configuration) repositoryDao.edit( @@ -118,13 +95,7 @@ class CodeGithubRepositoryService @Autowired constructor( aliasName = repository.aliasName, url = repository.getFormatURL() ) - repositoryGithubDao.edit( - dslContext, - repositoryId, - repository.projectName, - repository.userName, - gitProjectId = gitProjectId - ) + repositoryGithubDao.edit(transactionContext, repositoryId, repository.projectName, userId) } } @@ -136,28 +107,11 @@ class CodeGithubRepositoryService @Autowired constructor( userName = repository.userId, projectName = record.projectName, projectId = repository.projectId, - repoHashId = HashUtil.encodeOtherLongId(repository.repositoryId), - gitProjectId = record.gitProjectId.toLong() + repoHashId = HashUtil.encodeOtherLongId(repository.repositoryId) ) } override fun getAuthInfo(repositoryIds: List): Map { return repositoryIds.associateWith { RepoAuthInfo(authType = RepoAuthType.OAUTH.name, credentialId = "") } } - - private fun getProjectId(repository: GithubRepository, userId: String): Long { - val accessToken = githubTokenService.getAccessToken(userId) - // github仓库基本信息 - val githubRepo = if (accessToken == null) { - logger.warn("The user[$userId] token invalid") - null - } else { - githubService.getRepositoryInfo(accessToken.accessToken, repository.projectName) - } - return githubRepo?.id ?: 0L - } - - companion object { - private val logger = LoggerFactory.getLogger(CodeGithubRepositoryService::class.java) - } } diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/GithubService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/GithubService.kt index 71375bb0b4b..bf76ae15af9 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/GithubService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/GithubService.kt @@ -45,7 +45,6 @@ import com.tencent.devops.common.webhook.pojo.code.github.GithubWebhook import com.tencent.devops.process.api.service.ServiceScmWebhookResource import com.tencent.devops.repository.constant.RepositoryMessageCode.OPERATION_ADD_CHECK_RUNS import com.tencent.devops.repository.constant.RepositoryMessageCode.OPERATION_GET_BRANCH -import com.tencent.devops.repository.constant.RepositoryMessageCode.OPERATION_GET_REPO import com.tencent.devops.repository.constant.RepositoryMessageCode.OPERATION_GET_REPOS import com.tencent.devops.repository.constant.RepositoryMessageCode.OPERATION_GET_TAG import com.tencent.devops.repository.constant.RepositoryMessageCode.OPERATION_LIST_BRANCHS @@ -291,26 +290,6 @@ class GithubService @Autowired constructor( ) } - override fun getRepositoryInfo(token: String, projectName: String): GithubRepo { - logger.info("getRepositoryInfo| $projectName") - return RetryUtils.execute( - object : RetryUtils.Action { - override fun fail(e: Throwable): GithubRepo { - logger.warn("BKSystemMonitor|getRepositoryInfo fail| e=${e.message}", e) - throw e - } - override fun execute(): GithubRepo { - val path = "repos/$projectName" - val request = buildGet(token, path) - val operation = getMessageByLocale(OPERATION_GET_REPO) - val body = getBody(operation, request) - return objectMapper.readValue(body) - } - }, - 3, SLEEP_MILLS_FOR_RETRY_500 - ) - } - private fun buildPost(token: String, path: String, body: String): Request { return request(token, path) .post(RequestBody.create("application/json; charset=utf-8".toMediaTypeOrNull(), body)) diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/IGithubService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/IGithubService.kt index da739205d9d..e9ca3d08bb6 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/IGithubService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/IGithubService.kt @@ -62,6 +62,4 @@ interface IGithubService { fun listBranches(token: String, projectName: String): List fun listTags(token: String, projectName: String): List - - fun getRepositoryInfo(token: String, projectName: String): GithubRepo } From 7b273c1d62ad3c7b6673c9a6668538c1510e72ca Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 15 Aug 2023 11:51:42 +0800 Subject: [PATCH 030/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/dao/RepositoryGithubDao.kt | 33 ------------------- .../service/github/IGithubService.kt | 1 - 2 files changed, 34 deletions(-) diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryGithubDao.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryGithubDao.kt index 41b1ddf8dc7..599967c514e 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryGithubDao.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryGithubDao.kt @@ -123,37 +123,4 @@ class RepositoryGithubDao { .fetch() } } - - /** - * 分页查询 - */ - fun getAllRepo( - dslContext: DSLContext, - limit: Int, - offset: Int - ): Result? { - with(TRepositoryGithub.T_REPOSITORY_GITHUB) { - return dslContext.selectFrom(this) - .orderBy(CREATED_TIME.desc()) - .limit(limit).offset(offset) - .fetch() - } - } - - fun updateGitProjectId( - dslContext: DSLContext, - id: Long, - gitProjectId: Long - ) { - with(TRepositoryGithub.T_REPOSITORY_GITHUB) { - val conditions = mutableListOf( - REPOSITORY_ID.eq(id), - GIT_PROJECT_ID.le(0) - ) - dslContext.update(this) - .set(GIT_PROJECT_ID, gitProjectId) - .where(conditions) - .execute() - } - } } diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/IGithubService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/IGithubService.kt index e9ca3d08bb6..20a3aa26619 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/IGithubService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/IGithubService.kt @@ -31,7 +31,6 @@ import com.tencent.devops.repository.pojo.AuthorizeResult import com.tencent.devops.repository.pojo.GithubCheckRuns import com.tencent.devops.repository.pojo.GithubCheckRunsResponse import com.tencent.devops.repository.pojo.github.GithubBranch -import com.tencent.devops.repository.pojo.github.GithubRepo import com.tencent.devops.repository.pojo.github.GithubTag interface IGithubService { From f3dafdf1a6031a6bd51a1129223a732cd7e4cda3 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 15 Aug 2023 11:53:05 +0800 Subject: [PATCH 031/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/service/code/CodeGithubRepositoryService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/code/CodeGithubRepositoryService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/code/CodeGithubRepositoryService.kt index 4552cb68008..e47dbe4690e 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/code/CodeGithubRepositoryService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/code/CodeGithubRepositoryService.kt @@ -95,7 +95,7 @@ class CodeGithubRepositoryService @Autowired constructor( aliasName = repository.aliasName, url = repository.getFormatURL() ) - repositoryGithubDao.edit(transactionContext, repositoryId, repository.projectName, userId) + repositoryGithubDao.edit(dslContext, repositoryId, repository.projectName, repository.userName) } } From 3538a9966dc2f8dcb42ddd2203849d986232cc64 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 15 Aug 2023 20:12:22 +0800 Subject: [PATCH 032/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/code/handler/tgit/TGitReviewTriggerHandler.kt | 2 +- support-files/i18n/process/message_en_US.properties | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt index f71669213af..cb551eca059 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt @@ -106,7 +106,7 @@ class TGitReviewTriggerHandler( code = getI18Code(event), params = listOf( "${event.repository.homepage}/reviews/${event.iid}", - event.commitId ?: "", + event.iid, getUsername(event) ) ) diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index 3532d1f402c..d397d2eab99 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -358,10 +358,10 @@ bkQualityOut=Quality out bkBuildFinishedAndDenyPause=Build Finished And Deny Pause commonShutdownSuccessContent=【${%s}】- 【${%s}】#${%s} Execution succeed,consume time${%s}, trigger user: ${%s}。 commonShutdownFailureContent=【${%s}】- 【${%s}】#${%s} Execution failed,consume time${%s}, trigger user: ${%s}。 -bkTgitPushEventDesc=[{0}] Commit [{2}] pushed by {3} -bkTgitIssueOpenedEventDesc=Issue [!{1}] opened by {2} -bkTgitIssueUpdatedEventDesc=Issue [!{1}] updated by {2} -bkTgitIssueClosedEventDesc=Issue [!{1}] closed by {2} +bkTgitPushEventDesc=[{0}] Commit [{2}] pushed by {3} +bkTgitIssueOpenedEventDesc=Issue [!{1}] opened by {2} +bkTgitIssueUpdatedEventDesc=Issue [!{1}] updated by {2} +bkTgitIssueClosedEventDesc=Issue [!{1}] closed by {2} bkTgitIssueReopenedEventDesc=Issue [!{1}] reopened by {2} bkTgitMrCreatedEventDesc=Merge requests [!{1}] opened by {2} bkTgitMrUpdatedEventDesc=Merge requests [!{1}] updated by {2} From adafbeab89330518f658adaac07a1f761b80f060 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 15 Aug 2023 20:15:07 +0800 Subject: [PATCH 033/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/repository/constant/RepositoryMessageCode.kt | 1 - support-files/sql/1001_ci_repository_ddl_mysql.sql | 1 - .../2002_v1.x/2010_ci_repository-update_v1.10_mysql.sql | 9 --------- 3 files changed, 11 deletions(-) diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/constant/RepositoryMessageCode.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/constant/RepositoryMessageCode.kt index a095dc9d6cf..0ab420f088e 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/constant/RepositoryMessageCode.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/constant/RepositoryMessageCode.kt @@ -82,5 +82,4 @@ object RepositoryMessageCode { const val OPERATION_GET_TAG = "OperationGetTag" // 获取指定Tag const val OPERATION_LIST_BRANCHS = "OperationListBranchs" // 获取分支列表 const val OPERATION_LIST_TAGS = "OperationListTags" // 获取Tag列表 - const val OPERATION_GET_REPO = "OperationGetRepo" // 获取单个仓库信息 } diff --git a/support-files/sql/1001_ci_repository_ddl_mysql.sql b/support-files/sql/1001_ci_repository_ddl_mysql.sql index 0c69cccc263..16cc5b91759 100644 --- a/support-files/sql/1001_ci_repository_ddl_mysql.sql +++ b/support-files/sql/1001_ci_repository_ddl_mysql.sql @@ -105,7 +105,6 @@ CREATE TABLE IF NOT EXISTS `T_REPOSITORY_GITHUB` ( `USER_NAME` varchar(64) NOT NULL COMMENT '用户名称', `CREATED_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `UPDATED_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', - `GIT_PROJECT_ID` bigint(20) DEFAULT 0 COMMENT 'GIT项目ID', PRIMARY KEY (`REPOSITORY_ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='github代码库明细表'; diff --git a/support-files/sql/2002_v1.x/2010_ci_repository-update_v1.10_mysql.sql b/support-files/sql/2002_v1.x/2010_ci_repository-update_v1.10_mysql.sql index d08f577f143..6e027f0a26a 100644 --- a/support-files/sql/2002_v1.x/2010_ci_repository-update_v1.10_mysql.sql +++ b/support-files/sql/2002_v1.x/2010_ci_repository-update_v1.10_mysql.sql @@ -23,15 +23,6 @@ BEGIN alter table T_REPOSITORY_GITHUB_TOKEN add constraint USER_ID unique (USER_ID, TYPE); END IF; - IF NOT EXISTS(SELECT 1 - FROM information_schema.COLUMNS - WHERE TABLE_SCHEMA = db - AND TABLE_NAME = 'T_REPOSITORY_GITHUB' - AND COLUMN_NAME = 'GIT_PROJECT_ID') THEN - ALTER TABLE `T_REPOSITORY_GITHUB` - ADD COLUMN `GIT_PROJECT_ID` bigint(20) DEFAULT 0 COMMENT 'GIT项目ID'; - END IF; - COMMIT; END DELIMITER ; From f556a3d5f2dcec5d188d208e68bde67f80e32f2e Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 15 Aug 2023 20:16:27 +0800 Subject: [PATCH 034/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- support-files/i18n/repository/message_en_US.properties | 3 +-- support-files/i18n/repository/message_zh_CN.properties | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/support-files/i18n/repository/message_en_US.properties b/support-files/i18n/repository/message_en_US.properties index bb573e68759..88cf762b8f9 100644 --- a/support-files/i18n/repository/message_en_US.properties +++ b/support-files/i18n/repository/message_en_US.properties @@ -31,5 +31,4 @@ OperationGetRepos=Get a list of repositories OperationGetBranch=Gets the specified branch OperationGetTag=Gets the specified Tag OperationListBranchs=Get a list of branches -OperationListTags=Get the list of Tags -OperationGetRepo=get repository info \ No newline at end of file +OperationListTags=Get the list of Tags \ No newline at end of file diff --git a/support-files/i18n/repository/message_zh_CN.properties b/support-files/i18n/repository/message_zh_CN.properties index 1e7c1de5b00..99ef362b9f0 100644 --- a/support-files/i18n/repository/message_zh_CN.properties +++ b/support-files/i18n/repository/message_zh_CN.properties @@ -32,4 +32,3 @@ OperationGetBranch=获取指定分支 OperationGetTag=获取指定Tag OperationListBranchs=获取分支列表 OperationListTags=获取Tag列表 -OperationGetRepo=获取代码库信息 From a2e8fc9fa062afa4db704dda5e7dd3b43528d499 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Mon, 21 Aug 2023 15:35:14 +0800 Subject: [PATCH 035/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pojo/trigger/PipelineTriggerType.kt | 9 + .../process/api/ServiceBuildResourceImpl.kt | 2 +- .../process/api/UserBuildResourceImpl.kt | 2 +- .../UserPipelineTriggerEventResourceImpl.kt | 2 +- .../service/PipelineRemoteAuthService.kt | 2 +- .../webhook/PipelineBuildWebhookService.kt | 2 +- .../trigger/PipelineTriggerEventService.kt | 30 ++- .../WebhookTriggerService.kt} | 101 ++++----- .../process/webhook/WebhookEventFactory.kt | 92 +++++++++ .../process/webhook/WebhookRequestService.kt | 138 +++++++++++++ .../atom/CodeGitWebhookTriggerTaskAtom.kt | 159 --------------- .../atom/CodeGithubWebHookTriggerTaskAtom.kt | 191 ------------------ .../atom/CodeGitlabWebHookTriggerTaskAtom.kt | 147 -------------- .../atom/CodeP4WebHookTriggerTaskAtom.kt | 145 ------------- .../atom/WebhookTriggerTaskAtomService.kt | 73 ------- .../listener/PipelineTriggerRequestService.kt | 99 --------- .../webhook/listener/WebhookEventListener.kt | 33 ++- .../parser/GithubWebhookEventParser.kt | 70 +++++++ .../GitlabWebhookEventParser.kt} | 45 +++-- .../webhook/parser/IWebhookEventParser.kt} | 17 +- .../webhook/parser/P4WebhookEventParser.kt | 56 +++++ .../webhook/parser/SvnWebhookEventParser.kt | 56 +++++ .../webhook/parser/TGitWebhookEventParser.kt | 64 ++++++ 23 files changed, 593 insertions(+), 942 deletions(-) rename src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/{service => }/trigger/PipelineTriggerEventService.kt (92%) rename src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/{webhook/atom/CodeSvnWebHookTriggerTaskAtom.kt => trigger/WebhookTriggerService.kt} (55%) create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookEventFactory.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt delete mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt delete mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGithubWebHookTriggerTaskAtom.kt delete mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitlabWebHookTriggerTaskAtom.kt delete mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeP4WebHookTriggerTaskAtom.kt delete mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/WebhookTriggerTaskAtomService.kt delete mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/PipelineTriggerRequestService.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/GithubWebhookEventParser.kt rename src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/{atom/CodeTGitWebhookTriggerTaskAtom.kt => parser/GitlabWebhookEventParser.kt} (56%) rename src/backend/ci/core/{common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/atom/IWebhookAtomTask.kt => process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/IWebhookEventParser.kt} (81%) create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/P4WebhookEventParser.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/SvnWebhookEventParser.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/TGitWebhookEventParser.kt diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt index 6630db6c5f6..fbe760bf5b6 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt @@ -27,6 +27,7 @@ package com.tencent.devops.process.pojo.trigger +import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.pojo.IdValue import com.tencent.devops.common.web.utils.I18nUtil import io.swagger.annotations.ApiModel @@ -81,5 +82,13 @@ enum class PipelineTriggerType { ) } } + + fun toScmType(triggerType: String): ScmType? { + return if (ScmType.values().map { it.name }.contains(triggerType)) { + ScmType.valueOf(triggerType) + } else { + null + } + } } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt index a3482667519..aba596becc1 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt @@ -61,7 +61,7 @@ import com.tencent.devops.process.pojo.trigger.PipelineTriggerType import com.tencent.devops.process.service.builds.PipelineBuildFacadeService import com.tencent.devops.process.service.builds.PipelineBuildMaintainFacadeService import com.tencent.devops.process.service.builds.PipelinePauseBuildFacadeService -import com.tencent.devops.process.service.trigger.PipelineTriggerEventService +import com.tencent.devops.process.trigger.PipelineTriggerEventService import org.springframework.beans.factory.annotation.Autowired @Suppress("ALL") diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt index 31ea9c3516d..023de098865 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt @@ -50,7 +50,7 @@ import com.tencent.devops.process.service.PipelineRecentUseService import com.tencent.devops.process.service.builds.PipelineBuildFacadeService import com.tencent.devops.process.service.builds.PipelineBuildMaintainFacadeService import com.tencent.devops.process.service.builds.PipelinePauseBuildFacadeService -import com.tencent.devops.process.service.trigger.PipelineTriggerEventService +import com.tencent.devops.process.trigger.PipelineTriggerEventService import io.micrometer.core.annotation.Timed import org.springframework.beans.factory.annotation.Autowired import javax.ws.rs.core.Response diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt index 3e7f0884138..aca6cf4c27d 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt @@ -38,7 +38,7 @@ import com.tencent.devops.process.api.user.UserPipelineTriggerEventResource import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventVo import com.tencent.devops.process.pojo.trigger.PipelineTriggerType import com.tencent.devops.process.pojo.trigger.RepoTriggerEventVo -import com.tencent.devops.process.service.trigger.PipelineTriggerEventService +import com.tencent.devops.process.trigger.PipelineTriggerEventService @RestResource class UserPipelineTriggerEventResourceImpl( diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt index a3f35cb2c96..f2cea5b1a4b 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt @@ -50,7 +50,7 @@ import com.tencent.devops.process.pojo.BuildId import com.tencent.devops.process.pojo.PipelineRemoteToken import com.tencent.devops.process.pojo.trigger.PipelineTriggerType import com.tencent.devops.process.service.builds.PipelineBuildFacadeService -import com.tencent.devops.process.service.trigger.PipelineTriggerEventService +import com.tencent.devops.process.trigger.PipelineTriggerEventService import com.tencent.devops.process.utils.PIPELINE_START_REMOTE_USER_ID import com.tencent.devops.process.utils.PIPELINE_START_TASK_ID import org.jooq.DSLContext diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt index a4aa7a07d78..d5803d9ae9f 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt @@ -57,7 +57,7 @@ import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber import com.tencent.devops.process.service.builds.PipelineBuildCommitService import com.tencent.devops.process.service.pipeline.PipelineBuildService -import com.tencent.devops.process.service.trigger.PipelineTriggerEventService +import com.tencent.devops.process.trigger.PipelineTriggerEventService import com.tencent.devops.process.utils.PIPELINE_START_TASK_ID import com.tencent.devops.process.utils.PipelineVarUtil import com.tencent.devops.repository.api.ServiceRepositoryResource diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt similarity index 92% rename from src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt rename to src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 6fc5711733c..0c2758b97fe 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -26,7 +26,7 @@ * */ -package com.tencent.devops.process.service.trigger +package com.tencent.devops.process.trigger import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.api.exception.ParamBlankException @@ -39,6 +39,8 @@ import com.tencent.devops.common.service.utils.HomeHostUtil import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.common.web.utils.I18nUtil.getCodeLanMessage import com.tencent.devops.common.webhook.enums.WebhookI18nConstants +import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay +import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_TRIGGER_DETAIL_NOT_FOUND import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_TRIGGER_REPLAY_PIPELINE_NOT_EMPTY import com.tencent.devops.process.dao.PipelineTriggerEventDao @@ -49,7 +51,7 @@ import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventVo import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.pojo.trigger.PipelineTriggerType import com.tencent.devops.process.pojo.trigger.RepoTriggerEventVo -import com.tencent.devops.process.webhook.listener.PipelineTriggerRequestService +import com.tencent.devops.process.webhook.WebhookRequestService import com.tencent.devops.project.api.service.ServiceAllocIdResource import org.jooq.DSLContext import org.jooq.impl.DSL @@ -65,7 +67,7 @@ class PipelineTriggerEventService @Autowired constructor( private val dslContext: DSLContext, private val client: Client, private val pipelineTriggerEventDao: PipelineTriggerEventDao, - private val pipelineTriggerRequestService: PipelineTriggerRequestService + private val webhookRequestService: WebhookRequestService ) { companion object { @@ -251,7 +253,7 @@ class PipelineTriggerEventService @Autowired constructor( errorCode = ERROR_TRIGGER_REPLAY_PIPELINE_NOT_EMPTY, params = arrayOf(detailId.toString()) ) - pipelineTriggerRequestService.handleReplayRequest( + replayAll( userId = userId, projectId = projectId, eventId = triggerDetail.eventId, @@ -263,14 +265,28 @@ class PipelineTriggerEventService @Autowired constructor( fun replayAll( userId: String, projectId: String, - eventId: Long + eventId: Long, + pipelineId: String? = null ): Boolean { logger.info("replay all pipeline trigger event|$userId|$projectId|$eventId") - pipelineTriggerRequestService.handleReplayRequest( - userId = userId, + val triggerEvent = pipelineTriggerEventDao.getTriggerEvent( + dslContext = dslContext, projectId = projectId, eventId = eventId + ) ?: throw ErrorCodeException( + errorCode = ProcessMessageCode.ERROR_TRIGGER_EVENT_NOT_FOUND, + params = arrayOf(eventId.toString()) + ) + val request = WebhookRequestReplay( + userId = userId, + projectId = projectId, + hookRequestId = triggerEvent.hookRequestId!! + ) + val scmType = PipelineTriggerType.toScmType(triggerEvent.triggerType) ?: throw ErrorCodeException( + errorCode = ProcessMessageCode.ERROR_TRIGGER_TYPE_REPLAY_NOT_SUPPORT, + params = arrayOf(triggerEvent.triggerType) ) + webhookRequestService.replay(scmType = scmType, request = request) return true } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeSvnWebHookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/WebhookTriggerService.kt similarity index 55% rename from src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeSvnWebHookTriggerTaskAtom.kt rename to src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/WebhookTriggerService.kt index 2a47894436c..f116d989549 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeSvnWebHookTriggerTaskAtom.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/WebhookTriggerService.kt @@ -26,20 +26,13 @@ * */ -package com.tencent.devops.process.webhook.atom +package com.tencent.devops.process.trigger -import com.fasterxml.jackson.databind.ObjectMapper import com.tencent.devops.common.api.enums.ScmType -import com.tencent.devops.common.api.exception.ErrorCodeException -import com.tencent.devops.common.webhook.atom.IWebhookAtomTask -import com.tencent.devops.common.webhook.pojo.WebhookRequest import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay -import com.tencent.devops.common.webhook.pojo.code.svn.SvnCommitEvent -import com.tencent.devops.process.constant.ProcessMessageCode +import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher import com.tencent.devops.process.engine.service.PipelineWebhookService -import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent -import com.tencent.devops.process.pojo.trigger.PipelineTriggerType import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService import org.slf4j.LoggerFactory @@ -47,68 +40,57 @@ import org.springframework.stereotype.Service import java.time.LocalDateTime @Service -class CodeSvnWebHookTriggerTaskAtom ( - private val objectMapper: ObjectMapper, - private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder, +class WebhookTriggerService( private val pipelineWebhookService: PipelineWebhookService, - private val pipelineBuildWebhookService: PipelineBuildWebhookService, - private val webhookTriggerTaskAtomService: WebhookTriggerTaskAtomService -) : IWebhookAtomTask { + private val pipelineBuildWebhookService: PipelineBuildWebhookService +) { + companion object { + private val logger = LoggerFactory.getLogger(WebhookTriggerService::class.java) + } - companion object { - private val logger = LoggerFactory.getLogger(CodeSvnWebHookTriggerTaskAtom::class.java) - } - - override fun request(request: WebhookRequest) { - logger.info("Trigger code svn build - ${request.body}") - - val event = getEvent(request = request) ?: return - - val matcher = scmWebhookMatcherBuilder.createSvnWebHookMatcher(event) - - val eventTime = LocalDateTime.now() - val requestId = webhookTriggerTaskAtomService.saveRepoWebhookRequest( - matcher = matcher, - request = request, - eventTime = eventTime, - scmType = ScmType.CODE_SVN - ) - val triggerEvent = PipelineTriggerEvent( - triggerType = PipelineTriggerType.CODE_SVN.name, + fun trigger( + scmType: ScmType, + matcher: ScmWebhookMatcher, + hookRequestId: Long, + eventTime: LocalDateTime + ) { + val preMatch = matcher.preMatch() + if (!preMatch.isMatch) { + logger.info("webhook trigger pre match|${preMatch.reason}") + return + } + val webhookEvent = PipelineTriggerEvent( + triggerType = scmType.name, eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), eventDesc = matcher.getEventDesc(), - hookRequestId = requestId, + hookRequestId = hookRequestId, eventTime = eventTime ) - val subscribers = pipelineWebhookService.getWebhookPipelines( name = matcher.getRepoName(), - repositoryType = ScmType.CODE_SVN.name + repositoryType = scmType.name ) pipelineBuildWebhookService.dispatchPipelineSubscribers( matcher = matcher, - triggerEvent = triggerEvent, + triggerEvent = webhookEvent, subscribers = subscribers ) } - override fun replay(request: WebhookRequestReplay) { - val repoWebhookRequest = webhookTriggerTaskAtomService.getRepoWebhookRequest( - requestId = request.hookRequestId - ) ?: throw ErrorCodeException( - errorCode = ProcessMessageCode.ERROR_WEBHOOK_REQUEST_NOT_FOUND, - params = arrayOf(request.hookRequestId.toString()) - ) - val event = getEvent( - request = WebhookRequest( - body = repoWebhookRequest.requestBody - ) - ) ?: return - val matcher = scmWebhookMatcherBuilder.createSvnWebHookMatcher(event) - val eventTime = LocalDateTime.now() + fun replay( + scmType: ScmType, + request: WebhookRequestReplay, + matcher: ScmWebhookMatcher, + eventTime: LocalDateTime + ) { + val preMatch = matcher.preMatch() + if (!preMatch.isMatch) { + logger.info("webhook replay trigger pre match|${preMatch.reason}") + return + } val triggerEvent = PipelineTriggerEvent( - triggerType = PipelineTriggerType.CODE_SVN.name, + triggerType = scmType.name, eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), eventDesc = matcher.getEventDesc(), @@ -125,7 +107,7 @@ class CodeSvnWebHookTriggerTaskAtom ( } ?: run { pipelineWebhookService.getWebhookPipelines( name = matcher.getRepoName(), - repositoryType = ScmType.CODE_SVN.name + repositoryType = scmType.name ) } pipelineBuildWebhookService.dispatchPipelineSubscribers( @@ -134,13 +116,4 @@ class CodeSvnWebHookTriggerTaskAtom ( subscribers = subscribers ) } - - private fun getEvent(request: WebhookRequest): SvnCommitEvent? { - return try { - objectMapper.readValue(request.body, SvnCommitEvent::class.java) - } catch (e: Exception) { - logger.warn("Fail to parse the svn web hook commit event", e) - return null - } - } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookEventFactory.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookEventFactory.kt new file mode 100644 index 00000000000..40b942361b7 --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookEventFactory.kt @@ -0,0 +1,92 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.webhook + +import com.fasterxml.jackson.databind.ObjectMapper +import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.api.exception.InvalidParamException +import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent +import com.tencent.devops.common.webhook.pojo.code.git.GitEvent +import com.tencent.devops.common.webhook.pojo.code.p4.P4Event +import com.tencent.devops.common.webhook.pojo.code.svn.SvnCommitEvent +import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher +import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder +import com.tencent.devops.process.webhook.parser.GitlabWebhookEventParser +import com.tencent.devops.process.webhook.parser.P4WebhookEventParser +import com.tencent.devops.process.webhook.parser.SvnWebhookEventParser +import com.tencent.devops.process.webhook.parser.TGitWebhookEventParser +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.stereotype.Service + +@Service +class WebhookEventFactory @Autowired constructor( + private val objectMapper: ObjectMapper, + private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder +) { + + fun parseEvent(scmType: ScmType, request: WebhookRequest): CodeWebhookEvent? { + val webhookEventParser = when (scmType) { + ScmType.CODE_GIT, ScmType.CODE_TGIT -> + TGitWebhookEventParser(objectMapper = objectMapper) + + ScmType.CODE_SVN -> + SvnWebhookEventParser(objectMapper = objectMapper) + + ScmType.CODE_P4 -> + P4WebhookEventParser(objectMapper = objectMapper) + + ScmType.CODE_GITLAB -> + GitlabWebhookEventParser(objectMapper = objectMapper) + + else -> + throw InvalidParamException("Unknown scm type($scmType)") + } + return webhookEventParser.parseEvent(request = request) + } + + fun createScmWebHookMatcher(scmType: ScmType, event: CodeWebhookEvent): ScmWebhookMatcher { + return when (scmType) { + ScmType.CODE_GIT, ScmType.CODE_TGIT -> + scmWebhookMatcherBuilder.createGitWebHookMatcher(event = event as GitEvent) + + ScmType.CODE_SVN -> + scmWebhookMatcherBuilder.createSvnWebHookMatcher(event = event as SvnCommitEvent) + + ScmType.CODE_P4 -> + scmWebhookMatcherBuilder.createP4WebHookMatcher(event = event as P4Event) + + ScmType.CODE_GITLAB -> + scmWebhookMatcherBuilder.createGitlabWebHookMatcher(event = event as GitEvent) + + else -> + throw InvalidParamException("Unknown scm type($scmType)") + } + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt new file mode 100644 index 00000000000..b0e96e62622 --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt @@ -0,0 +1,138 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.webhook + +import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.api.exception.ErrorCodeException +import com.tencent.devops.common.client.Client +import com.tencent.devops.common.pipeline.enums.ChannelCode +import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay +import com.tencent.devops.common.webhook.pojo.code.github.GithubCheckRunEvent +import com.tencent.devops.process.api.service.ServiceBuildResource +import com.tencent.devops.process.constant.ProcessMessageCode +import com.tencent.devops.process.trigger.WebhookTriggerService +import com.tencent.devops.repository.api.ServiceRepositoryWebhookResource +import com.tencent.devops.repository.pojo.RepositoryWebhookRequest +import org.slf4j.LoggerFactory +import java.time.LocalDateTime + +class WebhookRequestService( + private val client: Client, + private val webhookEventFactory: WebhookEventFactory, + private val webhookTriggerService: WebhookTriggerService +) { + + companion object { + private val logger = LoggerFactory.getLogger(WebhookRequestService::class.java) + } + + fun handleRequest(scmType: ScmType, request: WebhookRequest) { + val event = webhookEventFactory.parseEvent(scmType = scmType, request = request) ?: run { + logger.warn("Failed to parse webhook event") + return + } + if (event is GithubCheckRunEvent) { + githubRetry(event) + return + } + val matcher = webhookEventFactory.createScmWebHookMatcher(scmType = scmType, event = event) + + val eventTime = LocalDateTime.now() + val repositoryWebhookRequest = RepositoryWebhookRequest( + externalId = matcher.getExternalId(), + eventType = matcher.getEventType().name, + triggerUser = matcher.getUsername(), + eventMessage = matcher.getMessage() ?: "", + repositoryType = scmType.name, + requestHeader = request.headers, + requestParam = request.queryParams, + requestBody = request.body, + createTime = eventTime + ) + val hookRequestId = client.get(ServiceRepositoryWebhookResource::class).saveWebhookRequest( + repositoryWebhookRequest = repositoryWebhookRequest + ).data!! + webhookTriggerService.trigger( + scmType = scmType, + matcher = matcher, + hookRequestId = hookRequestId, + eventTime = eventTime + ) + } + + fun replay(scmType: ScmType, request: WebhookRequestReplay) { + val repoWebhookRequest = client.get(ServiceRepositoryWebhookResource::class).getWebhookRequest( + requestId = request.hookRequestId + ).data ?: throw ErrorCodeException( + errorCode = ProcessMessageCode.ERROR_WEBHOOK_REQUEST_NOT_FOUND, + params = arrayOf(request.hookRequestId.toString()) + ) + val webhookRequest = WebhookRequest( + headers = repoWebhookRequest.requestHeader, + body = repoWebhookRequest.requestBody + ) + val event = webhookEventFactory.parseEvent(scmType = scmType, request = webhookRequest) ?: run { + logger.warn("Failed to parse webhook event") + return + } + val matcher = webhookEventFactory.createScmWebHookMatcher(scmType = scmType, event = event) + + val eventTime = LocalDateTime.now() + webhookTriggerService.replay( + scmType = scmType, + request = request, + matcher = matcher, + eventTime = eventTime + ) + } + + private fun githubRetry(event: GithubCheckRunEvent) { + if (event.action != "rerequested") { + logger.info("Unsupported check run action:${event.action}") + return + } + if (event.checkRun.externalId == null) { + logger.info("github check run externalId is empty") + return + } + val buildInfo = event.checkRun.externalId!!.split("_") + if (buildInfo.size < 4) { + logger.info("the buildInfo of github check run is error") + return + } + client.get(ServiceBuildResource::class).retry( + userId = buildInfo[0], + projectId = buildInfo[1], + pipelineId = buildInfo[2], + buildId = buildInfo[3], + channelCode = ChannelCode.BS + ) + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt deleted file mode 100644 index 8506f35727f..00000000000 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitWebhookTriggerTaskAtom.kt +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.tencent.devops.process.webhook.atom - -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.module.kotlin.readValue -import com.tencent.devops.common.api.enums.ScmType -import com.tencent.devops.common.api.exception.ErrorCodeException -import com.tencent.devops.common.webhook.atom.IWebhookAtomTask -import com.tencent.devops.common.webhook.pojo.WebhookRequest -import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay -import com.tencent.devops.common.webhook.pojo.code.git.GitEvent -import com.tencent.devops.common.webhook.pojo.code.git.GitReviewEvent -import com.tencent.devops.process.constant.ProcessMessageCode -import com.tencent.devops.process.engine.service.PipelineWebhookService -import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder -import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent -import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber -import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.stereotype.Service -import java.time.LocalDateTime - -@Service -class CodeGitWebhookTriggerTaskAtom @Autowired constructor( - private val objectMapper: ObjectMapper, - private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder, - private val pipelineWebhookService: PipelineWebhookService, - private val pipelineBuildWebhookService: PipelineBuildWebhookService, - private val webhookTriggerTaskAtomService: WebhookTriggerTaskAtomService -) : IWebhookAtomTask { - - companion object { - private val logger = LoggerFactory.getLogger(CodeGitWebhookTriggerTaskAtom::class.java) - } - - override fun request(request: WebhookRequest) { - val eventType = request.headers?.get("X-Event") - val body = request.body - logger.info("Trigger code git build($body|$eventType)") - val event = getEvent(request = request) ?: return - val matcher = scmWebhookMatcherBuilder.createGitWebHookMatcher(event) - if (!matcher.preMatch().isMatch) { - return - } - - val eventTime = LocalDateTime.now() - val requestId = webhookTriggerTaskAtomService.saveRepoWebhookRequest( - matcher = matcher, - request = request, - eventTime = eventTime, - scmType = getScmType() - ) - val webhookEvent = PipelineTriggerEvent( - triggerType = getScmType().name, - eventType = matcher.getEventType().name, - triggerUser = matcher.getUsername(), - eventDesc = matcher.getEventDesc(), - hookRequestId = requestId, - eventTime = eventTime - ) - val subscribers = pipelineWebhookService.getWebhookPipelines( - name = matcher.getRepoName(), - repositoryType = getScmType().name - ) - pipelineBuildWebhookService.dispatchPipelineSubscribers( - matcher = matcher, - triggerEvent = webhookEvent, - subscribers = subscribers - ) - } - - override fun replay(request: WebhookRequestReplay) { - val repoWebhookRequest = webhookTriggerTaskAtomService.getRepoWebhookRequest( - requestId = request.hookRequestId - ) ?: throw ErrorCodeException( - errorCode = ProcessMessageCode.ERROR_WEBHOOK_REQUEST_NOT_FOUND, - params = arrayOf(request.hookRequestId.toString()) - ) - val event = getEvent( - request = WebhookRequest( - headers = repoWebhookRequest.requestHeader, - body = repoWebhookRequest.requestBody - ) - ) ?: return - val matcher = scmWebhookMatcherBuilder.createGitWebHookMatcher(event) - val eventTime = LocalDateTime.now() - val triggerEvent = PipelineTriggerEvent( - triggerType = getScmType().name, - eventType = matcher.getEventType().name, - triggerUser = matcher.getUsername(), - eventDesc = matcher.getEventDesc(), - hookRequestId = request.hookRequestId, - eventTime = eventTime - ) - val subscribers = request.pipelineId?.let { - listOf( - PipelineWebhookSubscriber( - projectId = request.projectId, - pipelineId = request.pipelineId!! - ) - ) - } ?: run { - pipelineWebhookService.getWebhookPipelines( - name = matcher.getRepoName(), - repositoryType = getScmType().name - ) - } - pipelineBuildWebhookService.dispatchPipelineSubscribers( - matcher = matcher, - triggerEvent = triggerEvent, - subscribers = subscribers - ) - } - - private fun getEvent(request: WebhookRequest): GitEvent? { - val eventType = request.headers?.get("X-Event") - val body = request.body - return try { - if (eventType == "Review Hook") { - objectMapper.readValue(body) - } else { - objectMapper.readValue(body) - } - } catch (e: Exception) { - logger.warn("Fail to parse the git web hook commit event", e) - return null - } - } - - fun getScmType() = ScmType.CODE_GIT -} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGithubWebHookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGithubWebHookTriggerTaskAtom.kt deleted file mode 100644 index 9564449fd9c..00000000000 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGithubWebHookTriggerTaskAtom.kt +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.tencent.devops.process.webhook.atom - -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.module.kotlin.readValue -import com.tencent.devops.common.api.enums.ScmType -import com.tencent.devops.common.api.exception.ErrorCodeException -import com.tencent.devops.common.client.Client -import com.tencent.devops.common.pipeline.enums.ChannelCode -import com.tencent.devops.common.webhook.atom.IWebhookAtomTask -import com.tencent.devops.common.webhook.pojo.WebhookRequest -import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay -import com.tencent.devops.common.webhook.pojo.code.github.GithubCheckRunEvent -import com.tencent.devops.common.webhook.pojo.code.github.GithubCreateEvent -import com.tencent.devops.common.webhook.pojo.code.github.GithubEvent -import com.tencent.devops.common.webhook.pojo.code.github.GithubPullRequestEvent -import com.tencent.devops.common.webhook.pojo.code.github.GithubPushEvent -import com.tencent.devops.process.api.service.ServiceBuildResource -import com.tencent.devops.process.constant.ProcessMessageCode -import com.tencent.devops.process.engine.service.PipelineWebhookService -import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder -import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent -import com.tencent.devops.process.pojo.trigger.PipelineTriggerType -import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber -import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service -import java.time.LocalDateTime - -@Service -class CodeGithubWebHookTriggerTaskAtom( - private val objectMapper: ObjectMapper, - private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder, - private val pipelineWebhookService: PipelineWebhookService, - private val pipelineBuildWebhookService: PipelineBuildWebhookService, - private val webhookTriggerTaskAtomService: WebhookTriggerTaskAtomService, - private val client: Client -) : IWebhookAtomTask { - - companion object { - private val logger = LoggerFactory.getLogger(CodeGithubWebHookTriggerTaskAtom::class.java) - } - - override fun request(request: WebhookRequest) { - val event = getEvent(request) ?: return - val matcher = scmWebhookMatcherBuilder.createGithubWebHookMatcher(event) - if (!matcher.preMatch().isMatch) { - return - } - if (event is GithubCheckRunEvent) { - retry(event) - return - } - val eventTime = LocalDateTime.now() - val requestId = webhookTriggerTaskAtomService.saveRepoWebhookRequest( - matcher = matcher, - request = request, - eventTime = eventTime, - scmType = ScmType.GITHUB - ) - val webhookEvent = PipelineTriggerEvent( - triggerType = PipelineTriggerType.GITHUB.name, - eventType = matcher.getEventType().name, - triggerUser = matcher.getUsername(), - eventDesc = matcher.getEventDesc(), - hookRequestId = requestId, - eventTime = eventTime - ) - val subscribers = pipelineWebhookService.getWebhookPipelines( - name = matcher.getRepoName(), - repositoryType = ScmType.CODE_GIT.name - ) - pipelineBuildWebhookService.dispatchPipelineSubscribers( - matcher = matcher, - triggerEvent = webhookEvent, - subscribers = subscribers - ) - } - - override fun replay(request: WebhookRequestReplay) { - val repoWebhookRequest = webhookTriggerTaskAtomService.getRepoWebhookRequest( - requestId = request.hookRequestId - ) ?: throw ErrorCodeException( - errorCode = ProcessMessageCode.ERROR_WEBHOOK_REQUEST_NOT_FOUND, - params = arrayOf(request.hookRequestId.toString()) - ) - val event = getEvent( - request = WebhookRequest( - headers = repoWebhookRequest.requestHeader, - body = repoWebhookRequest.requestBody - ) - ) ?: return - val matcher = scmWebhookMatcherBuilder.createGithubWebHookMatcher(event) - val eventTime = LocalDateTime.now() - val triggerEvent = PipelineTriggerEvent( - triggerType = PipelineTriggerType.GITHUB.name, - eventType = matcher.getEventType().name, - triggerUser = matcher.getUsername(), - eventDesc = matcher.getEventDesc(), - hookRequestId = request.hookRequestId, - eventTime = eventTime - ) - val subscribers = request.pipelineId?.let { - listOf( - PipelineWebhookSubscriber( - projectId = request.projectId, - pipelineId = request.pipelineId!! - ) - ) - } ?: run { - pipelineWebhookService.getWebhookPipelines( - name = matcher.getRepoName(), - repositoryType = ScmType.GITHUB.name - ) - } - pipelineBuildWebhookService.dispatchPipelineSubscribers( - matcher = matcher, - triggerEvent = triggerEvent, - subscribers = subscribers - ) - } - - private fun retry(event: GithubCheckRunEvent) { - if (event.action != "rerequested") { - logger.info("Unsupported check run action:${event.action}") - return - } - if (event.checkRun.externalId == null) { - logger.info("github check run externalId is empty") - return - } - val buildInfo = event.checkRun.externalId!!.split("_") - if (buildInfo.size < 4) { - logger.info("the buildInfo of github check run is error") - return - } - client.get(ServiceBuildResource::class).retry( - userId = buildInfo[0], - projectId = buildInfo[1], - pipelineId = buildInfo[2], - buildId = buildInfo[3], - channelCode = ChannelCode.BS - ) - } - - private fun getEvent(request: WebhookRequest): GithubEvent? { - val eventType = request.headers?.get("X-GitHub-Event") - val guid = request.headers?.get("X-Github-Delivery") - val signature = request.headers?.get("X-Hub-Signature") - val body = request.body - logger.info("Trigger code github build (event=$eventType, guid=$guid, signature=$signature, body=$body)") - - return when (eventType) { - GithubPushEvent.classType -> objectMapper.readValue(body) - GithubCreateEvent.classType -> objectMapper.readValue(body) - GithubPullRequestEvent.classType -> objectMapper.readValue(body) - GithubCheckRunEvent.classType -> objectMapper.readValue(body) - else -> { - logger.info("Github event($eventType) is ignored") - return null - } - } - } -} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitlabWebHookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitlabWebHookTriggerTaskAtom.kt deleted file mode 100644 index d642becfacb..00000000000 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeGitlabWebHookTriggerTaskAtom.kt +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.tencent.devops.process.webhook.atom - -import com.fasterxml.jackson.databind.ObjectMapper -import com.tencent.devops.common.api.enums.ScmType -import com.tencent.devops.common.api.exception.ErrorCodeException -import com.tencent.devops.common.webhook.atom.IWebhookAtomTask -import com.tencent.devops.common.webhook.pojo.WebhookRequest -import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay -import com.tencent.devops.common.webhook.pojo.code.git.GitEvent -import com.tencent.devops.process.constant.ProcessMessageCode -import com.tencent.devops.process.engine.service.PipelineWebhookService -import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder -import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent -import com.tencent.devops.process.pojo.trigger.PipelineTriggerType -import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber -import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.stereotype.Service -import java.time.LocalDateTime - -@Service -class CodeGitlabWebHookTriggerTaskAtom @Autowired constructor( - private val objectMapper: ObjectMapper, - private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder, - private val pipelineWebhookService: PipelineWebhookService, - private val pipelineBuildWebhookService: PipelineBuildWebhookService, - private val webhookTriggerTaskAtomService: WebhookTriggerTaskAtomService -) : IWebhookAtomTask { - - companion object { - private val logger = LoggerFactory.getLogger(CodeGitlabWebHookTriggerTaskAtom::class.java) - } - - override fun request(request: WebhookRequest) { - logger.info("Trigger gitlab build(${request.body})") - - val event = getEvent(request = request) ?: return - - val matcher = scmWebhookMatcherBuilder.createGitlabWebHookMatcher(event) - - val eventTime = LocalDateTime.now() - val requestId = webhookTriggerTaskAtomService.saveRepoWebhookRequest( - matcher = matcher, - request = request, - eventTime = eventTime, - scmType = ScmType.CODE_GITLAB - ) - val triggerEvent = PipelineTriggerEvent( - triggerType = PipelineTriggerType.CODE_GITLAB.name, - eventType = matcher.getEventType().name, - triggerUser = matcher.getUsername(), - eventDesc = matcher.getEventDesc(), - hookRequestId = requestId, - eventTime = eventTime - ) - val subscribers = pipelineWebhookService.getWebhookPipelines( - name = matcher.getRepoName(), - repositoryType = ScmType.CODE_GITLAB.name - ) - pipelineBuildWebhookService.dispatchPipelineSubscribers( - matcher = matcher, - triggerEvent = triggerEvent, - subscribers = subscribers - ) - } - - override fun replay(request: WebhookRequestReplay) { - val repoWebhookRequest = webhookTriggerTaskAtomService.getRepoWebhookRequest( - requestId = request.hookRequestId - ) ?: throw ErrorCodeException( - errorCode = ProcessMessageCode.ERROR_WEBHOOK_REQUEST_NOT_FOUND, - params = arrayOf(request.hookRequestId.toString()) - ) - val event = getEvent( - request = WebhookRequest( - headers = repoWebhookRequest.requestHeader, - body = repoWebhookRequest.requestBody - ) - ) ?: return - val matcher = scmWebhookMatcherBuilder.createGitWebHookMatcher(event) - val eventTime = LocalDateTime.now() - val triggerEvent = PipelineTriggerEvent( - triggerType = PipelineTriggerType.CODE_GITLAB.name, - eventType = matcher.getEventType().name, - triggerUser = matcher.getUsername(), - eventDesc = matcher.getEventDesc(), - hookRequestId = request.hookRequestId, - eventTime = eventTime - ) - val subscribers = request.pipelineId?.let { - listOf( - PipelineWebhookSubscriber( - projectId = request.projectId, - pipelineId = request.pipelineId!! - ) - ) - } ?: run { - pipelineWebhookService.getWebhookPipelines( - name = matcher.getRepoName(), - repositoryType = ScmType.CODE_GITLAB.name - ) - } - pipelineBuildWebhookService.dispatchPipelineSubscribers( - matcher = matcher, - triggerEvent = triggerEvent, - subscribers = subscribers - ) - } - - private fun getEvent(request: WebhookRequest): GitEvent? { - return try { - objectMapper.readValue(request.body, GitEvent::class.java) - } catch (e: Exception) { - logger.warn("Fail to parse the gitlab web hook commit event", e) - return null - } - } -} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeP4WebHookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeP4WebHookTriggerTaskAtom.kt deleted file mode 100644 index 8dee4ea0237..00000000000 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeP4WebHookTriggerTaskAtom.kt +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.tencent.devops.process.webhook.atom - -import com.fasterxml.jackson.databind.ObjectMapper -import com.tencent.devops.common.api.enums.ScmType -import com.tencent.devops.common.api.exception.ErrorCodeException -import com.tencent.devops.common.webhook.atom.IWebhookAtomTask -import com.tencent.devops.common.webhook.pojo.WebhookRequest -import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay -import com.tencent.devops.common.webhook.pojo.code.p4.P4Event -import com.tencent.devops.process.constant.ProcessMessageCode -import com.tencent.devops.process.engine.service.PipelineWebhookService -import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder -import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent -import com.tencent.devops.process.pojo.trigger.PipelineTriggerType -import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber -import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service -import java.time.LocalDateTime - -@Service -class CodeP4WebHookTriggerTaskAtom( - private val objectMapper: ObjectMapper, - private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder, - private val pipelineWebhookService: PipelineWebhookService, - private val pipelineBuildWebhookService: PipelineBuildWebhookService, - private val webhookTriggerTaskAtomService: WebhookTriggerTaskAtomService -) : IWebhookAtomTask { - - companion object { - private val logger = LoggerFactory.getLogger(CodeP4WebHookTriggerTaskAtom::class.java) - } - - override fun request(request: WebhookRequest) { - logger.info("Trigger p4 build(${request.body})") - - val event = getEvent(request = request) ?: return - - val matcher = scmWebhookMatcherBuilder.createP4WebHookMatcher(event) - val eventTime = LocalDateTime.now() - val requestId = webhookTriggerTaskAtomService.saveRepoWebhookRequest( - matcher = matcher, - request = request, - eventTime = eventTime, - scmType = ScmType.CODE_P4 - ) - val triggerEvent = PipelineTriggerEvent( - triggerType = PipelineTriggerType.CODE_P4.name, - eventType = matcher.getEventType().name, - triggerUser = matcher.getUsername(), - eventDesc = matcher.getEventDesc(), - hookRequestId = requestId, - eventTime = eventTime - ) - val subscribers = pipelineWebhookService.getWebhookPipelines( - name = matcher.getRepoName(), - repositoryType = ScmType.CODE_P4.name - ) - pipelineBuildWebhookService.dispatchPipelineSubscribers( - matcher = matcher, - triggerEvent = triggerEvent, - subscribers = subscribers - ) - } - - override fun replay(request: WebhookRequestReplay) { - val repoWebhookRequest = webhookTriggerTaskAtomService.getRepoWebhookRequest( - requestId = request.hookRequestId - ) ?: throw ErrorCodeException( - errorCode = ProcessMessageCode.ERROR_WEBHOOK_REQUEST_NOT_FOUND, - params = arrayOf(request.hookRequestId.toString()) - ) - val event = getEvent( - request = WebhookRequest( - headers = repoWebhookRequest.requestHeader, - body = repoWebhookRequest.requestBody - ) - ) ?: return - val matcher = scmWebhookMatcherBuilder.createP4WebHookMatcher(event) - val eventTime = LocalDateTime.now() - val triggerEvent = PipelineTriggerEvent( - triggerType = PipelineTriggerType.CODE_P4.name, - eventType = matcher.getEventType().name, - triggerUser = matcher.getUsername(), - eventDesc = matcher.getEventDesc(), - hookRequestId = request.hookRequestId, - eventTime = eventTime - ) - val subscribers = request.pipelineId?.let { - listOf( - PipelineWebhookSubscriber( - projectId = request.projectId, - pipelineId = request.pipelineId!! - ) - ) - } ?: run { - pipelineWebhookService.getWebhookPipelines( - name = matcher.getRepoName(), - repositoryType = ScmType.CODE_P4.name - ) - } - pipelineBuildWebhookService.dispatchPipelineSubscribers( - matcher = matcher, - triggerEvent = triggerEvent, - subscribers = subscribers - ) - } - - private fun getEvent(request: WebhookRequest): P4Event? { - return try { - objectMapper.readValue(request.body, P4Event::class.java) - } catch (e: Exception) { - logger.warn("Fail to parse the p4 web hook event", e) - return null - } - } -} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/WebhookTriggerTaskAtomService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/WebhookTriggerTaskAtomService.kt deleted file mode 100644 index 4fad4726ddc..00000000000 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/WebhookTriggerTaskAtomService.kt +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.tencent.devops.process.webhook.atom - -import com.tencent.devops.common.api.enums.ScmType -import com.tencent.devops.common.client.Client -import com.tencent.devops.common.webhook.pojo.WebhookRequest -import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher -import com.tencent.devops.repository.api.ServiceRepositoryWebhookResource -import com.tencent.devops.repository.pojo.RepositoryWebhookRequest -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.stereotype.Service -import java.time.LocalDateTime - -@Service -class WebhookTriggerTaskAtomService @Autowired constructor( - private val client: Client -) { - - fun saveRepoWebhookRequest( - matcher: ScmWebhookMatcher, - request: WebhookRequest, - eventTime: LocalDateTime, - scmType: ScmType - ): Long { - val repositoryWebhookRequest = RepositoryWebhookRequest( - externalId = matcher.getExternalId(), - eventType = matcher.getEventType().name, - triggerUser = matcher.getUsername(), - eventMessage = matcher.getMessage() ?: "", - repositoryType = scmType.name, - requestHeader = request.headers, - requestParam = request.queryParams, - requestBody = request.body, - createTime = eventTime - ) - return client.get(ServiceRepositoryWebhookResource::class).saveWebhookRequest( - repositoryWebhookRequest = repositoryWebhookRequest - ).data!! - } - - fun getRepoWebhookRequest( - requestId: Long - ): RepositoryWebhookRequest? { - return client.get(ServiceRepositoryWebhookResource::class).getWebhookRequest(requestId = requestId).data - } -} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/PipelineTriggerRequestService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/PipelineTriggerRequestService.kt deleted file mode 100644 index 8fc61e37efd..00000000000 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/PipelineTriggerRequestService.kt +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.tencent.devops.process.webhook.listener - -import com.tencent.devops.common.api.exception.ErrorCodeException -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGithubWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitlabWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeP4WebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeSVNWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeTGitWebHookTriggerElement -import com.tencent.devops.common.service.utils.SpringContextUtil -import com.tencent.devops.common.webhook.atom.IWebhookAtomTask -import com.tencent.devops.common.webhook.pojo.WebhookRequest -import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay -import com.tencent.devops.process.constant.ProcessMessageCode -import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_TRIGGER_TYPE_REPLAY_NOT_SUPPORT -import com.tencent.devops.process.dao.PipelineTriggerEventDao -import com.tencent.devops.process.pojo.trigger.PipelineTriggerType -import org.jooq.DSLContext -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.stereotype.Service - -@Service -class PipelineTriggerRequestService @Autowired constructor( - private val dslContext: DSLContext, - private val pipelineTriggerEventDao: PipelineTriggerEventDao -) { - - companion object { - private val logger = LoggerFactory.getLogger(PipelineTriggerRequestService::class.java) - private val triggerTypeToTaskAtom = mapOf( - PipelineTriggerType.CODE_GIT.name to CodeGitWebHookTriggerElement.taskAtom, - PipelineTriggerType.CODE_TGIT.name to CodeTGitWebHookTriggerElement.taskAtom, - PipelineTriggerType.CODE_P4.name to CodeP4WebHookTriggerElement.taskAtom, - PipelineTriggerType.CODE_GITLAB to CodeGitlabWebHookTriggerElement.taskAtom, - PipelineTriggerType.CODE_SVN to CodeSVNWebHookTriggerElement.taskAtom, - PipelineTriggerType.GITHUB to CodeGithubWebHookTriggerElement.taskAtom - ) - } - - fun handleRequest(taskAtom: String, request: WebhookRequest) { - SpringContextUtil.getBean(IWebhookAtomTask::class.java, taskAtom).request(request = request) - } - - fun handleReplayRequest( - userId: String, - projectId: String, - eventId: Long, - pipelineId: String? = null - ) { - val triggerEvent = pipelineTriggerEventDao.getTriggerEvent( - dslContext = dslContext, - projectId = projectId, - eventId = eventId - ) ?: throw ErrorCodeException( - errorCode = ProcessMessageCode.ERROR_TRIGGER_EVENT_NOT_FOUND, - params = arrayOf(eventId.toString()) - ) - val taskAtom = triggerTypeToTaskAtom[triggerEvent.triggerType] ?: throw ErrorCodeException( - errorCode = ERROR_TRIGGER_TYPE_REPLAY_NOT_SUPPORT, - params = arrayOf(triggerEvent.triggerType) - ) - val request = WebhookRequestReplay( - userId = userId, - projectId = projectId, - hookRequestId = triggerEvent.hookRequestId!!, - pipelineId = pipelineId - ) - SpringContextUtil.getBean(IWebhookAtomTask::class.java, taskAtom).replay(request = request) - } -} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt index 9667639d302..80f9ae1915c 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt @@ -27,14 +27,11 @@ package com.tencent.devops.process.webhook.listener -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGithubWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitlabWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeSVNWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeTGitWebHookTriggerElement +import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.service.trace.TraceTag import com.tencent.devops.common.webhook.pojo.WebhookRequest import com.tencent.devops.process.webhook.CodeWebhookEventDispatcher +import com.tencent.devops.process.webhook.WebhookRequestService import com.tencent.devops.process.webhook.pojo.event.commit.GitWebhookEvent import com.tencent.devops.process.webhook.pojo.event.commit.GithubWebhookEvent import com.tencent.devops.process.webhook.pojo.event.commit.GitlabWebhookEvent @@ -51,7 +48,7 @@ import org.springframework.stereotype.Component @Component class WebhookEventListener constructor( private val rabbitTemplate: RabbitTemplate, - private val pipelineTriggerRequestService: PipelineTriggerRequestService + private val webhookRequestService: WebhookRequestService ) { fun handleCommitEvent(event: ICodeWebhookEvent) { @@ -71,8 +68,8 @@ class WebhookEventListener constructor( val request = WebhookRequest( body = event.requestContent ) - pipelineTriggerRequestService.handleRequest( - taskAtom = CodeSVNWebHookTriggerElement.taskAtom, + webhookRequestService.handleRequest( + scmType = ScmType.CODE_SVN, request = request ) } @@ -83,8 +80,8 @@ class WebhookEventListener constructor( ), body = event.requestContent ) - pipelineTriggerRequestService.handleRequest( - taskAtom = CodeGitWebHookTriggerElement.taskAtom, + webhookRequestService.handleRequest( + scmType = ScmType.CODE_GIT, request = request ) } @@ -92,8 +89,8 @@ class WebhookEventListener constructor( val request = WebhookRequest( body = event.requestContent ) - pipelineTriggerRequestService.handleRequest( - taskAtom = CodeGitlabWebHookTriggerElement.taskAtom, + webhookRequestService.handleRequest( + scmType = ScmType.CODE_GITLAB, request = request ) } @@ -104,8 +101,8 @@ class WebhookEventListener constructor( ), body = event.requestContent ) - pipelineTriggerRequestService.handleRequest( - taskAtom = CodeTGitWebHookTriggerElement.taskAtom, + webhookRequestService.handleRequest( + scmType = ScmType.CODE_TGIT, request = request ) } @@ -113,8 +110,8 @@ class WebhookEventListener constructor( val request = WebhookRequest( body = event.requestContent ) - pipelineTriggerRequestService.handleRequest( - taskAtom = CodeGitlabWebHookTriggerElement.taskAtom, + webhookRequestService.handleRequest( + scmType = ScmType.CODE_P4, request = request ) } @@ -205,8 +202,8 @@ class WebhookEventListener constructor( body = thisGithubWebhook.body ) } - pipelineTriggerRequestService.handleRequest( - taskAtom = CodeGithubWebHookTriggerElement.taskAtom, + webhookRequestService.handleRequest( + scmType = ScmType.GITHUB, request = request ) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/GithubWebhookEventParser.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/GithubWebhookEventParser.kt new file mode 100644 index 00000000000..5904fa521d5 --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/GithubWebhookEventParser.kt @@ -0,0 +1,70 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.webhook.parser + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.kotlin.readValue +import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent +import com.tencent.devops.common.webhook.pojo.code.github.GithubCheckRunEvent +import com.tencent.devops.common.webhook.pojo.code.github.GithubCreateEvent +import com.tencent.devops.common.webhook.pojo.code.github.GithubPullRequestEvent +import com.tencent.devops.common.webhook.pojo.code.github.GithubPushEvent +import org.slf4j.LoggerFactory + +/** + * github webhook事件解析 + */ +class GithubWebhookEventParser( + private val objectMapper: ObjectMapper +) : IWebhookEventParser { + + companion object { + private val logger = LoggerFactory.getLogger(GithubWebhookEventParser::class.java) + } + + override fun parseEvent(request: WebhookRequest): CodeWebhookEvent? { + val eventType = request.headers?.get("X-GitHub-Event") + val guid = request.headers?.get("X-Github-Delivery") + val signature = request.headers?.get("X-Hub-Signature") + val body = request.body + logger.info("Trigger code github build (event=$eventType, guid=$guid, signature=$signature, body=$body)") + + return when (eventType) { + GithubPushEvent.classType -> objectMapper.readValue(body) + GithubCreateEvent.classType -> objectMapper.readValue(body) + GithubPullRequestEvent.classType -> objectMapper.readValue(body) + GithubCheckRunEvent.classType -> objectMapper.readValue(body) + else -> { + logger.info("Github event($eventType) is ignored") + return null + } + } + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeTGitWebhookTriggerTaskAtom.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/GitlabWebhookEventParser.kt similarity index 56% rename from src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeTGitWebhookTriggerTaskAtom.kt rename to src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/GitlabWebhookEventParser.kt index b11db27909e..987be3bba54 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/atom/CodeTGitWebhookTriggerTaskAtom.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/GitlabWebhookEventParser.kt @@ -26,30 +26,31 @@ * */ -package com.tencent.devops.process.webhook.atom +package com.tencent.devops.process.webhook.parser import com.fasterxml.jackson.databind.ObjectMapper -import com.tencent.devops.common.api.enums.ScmType -import com.tencent.devops.process.engine.service.PipelineWebhookService -import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder -import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.stereotype.Service +import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent +import com.tencent.devops.common.webhook.pojo.code.git.GitEvent +import org.slf4j.LoggerFactory -@Service -class CodeTGitWebhookTriggerTaskAtom @Autowired constructor( - private val objectMapper: ObjectMapper, - private val scmWebhookMatcherBuilder: ScmWebhookMatcherBuilder, - private val pipelineWebhookService: PipelineWebhookService, - private val pipelineBuildWebhookService: PipelineBuildWebhookService, - private val webhookTriggerTaskAtomService: WebhookTriggerTaskAtomService -) : CodeGitWebhookTriggerTaskAtom( - objectMapper = objectMapper, - scmWebhookMatcherBuilder = scmWebhookMatcherBuilder, - pipelineWebhookService = pipelineWebhookService, - pipelineBuildWebhookService = pipelineBuildWebhookService, - webhookTriggerTaskAtomService = webhookTriggerTaskAtomService -) { +/** + * gitlab webhook事件解析 + */ +class GitlabWebhookEventParser( + private val objectMapper: ObjectMapper +) : IWebhookEventParser { + + companion object { + private val logger = LoggerFactory.getLogger(GitlabWebhookEventParser::class.java) + } - override fun getScmType() = ScmType.CODE_TGIT + override fun parseEvent(request: WebhookRequest): CodeWebhookEvent? { + return try { + objectMapper.readValue(request.body, GitEvent::class.java) + } catch (e: Exception) { + logger.warn("Fail to parse the gitlab web hook commit event", e) + return null + } + } } diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/atom/IWebhookAtomTask.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/IWebhookEventParser.kt similarity index 81% rename from src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/atom/IWebhookAtomTask.kt rename to src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/IWebhookEventParser.kt index 4e3fc58be3d..74dccc37b5c 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/atom/IWebhookAtomTask.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/IWebhookEventParser.kt @@ -26,22 +26,15 @@ * */ -package com.tencent.devops.common.webhook.atom +package com.tencent.devops.process.webhook.parser -import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent -/** - * 触发器原子业务逻辑接口定义 - */ -interface IWebhookAtomTask { - /** - * webhook事件执行 - */ - fun request(request: WebhookRequest) +interface IWebhookEventParser { /** - * webhook事件重放 + * webhook 事件解析 */ - fun replay(request: WebhookRequestReplay) + fun parseEvent(request: WebhookRequest): CodeWebhookEvent? } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/P4WebhookEventParser.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/P4WebhookEventParser.kt new file mode 100644 index 00000000000..0d4a3e2c9f6 --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/P4WebhookEventParser.kt @@ -0,0 +1,56 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.webhook.parser + +import com.fasterxml.jackson.databind.ObjectMapper +import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent +import com.tencent.devops.common.webhook.pojo.code.p4.P4Event +import org.slf4j.LoggerFactory + +/** + * p4 webhook事件解析 + */ +class P4WebhookEventParser( + private val objectMapper: ObjectMapper +) : IWebhookEventParser { + + companion object { + private val logger = LoggerFactory.getLogger(P4WebhookEventParser::class.java) + } + + override fun parseEvent(request: WebhookRequest): CodeWebhookEvent? { + return try { + objectMapper.readValue(request.body, P4Event::class.java) + } catch (e: Exception) { + logger.warn("Fail to parse the p4 web hook event", e) + return null + } + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/SvnWebhookEventParser.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/SvnWebhookEventParser.kt new file mode 100644 index 00000000000..337d51a42af --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/SvnWebhookEventParser.kt @@ -0,0 +1,56 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.webhook.parser + +import com.fasterxml.jackson.databind.ObjectMapper +import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent +import com.tencent.devops.common.webhook.pojo.code.svn.SvnCommitEvent +import org.slf4j.LoggerFactory + +/** + * svn webhook事件解析 + */ +class SvnWebhookEventParser( + private val objectMapper: ObjectMapper +) : IWebhookEventParser { + + companion object { + private val logger = LoggerFactory.getLogger(SvnWebhookEventParser::class.java) + } + + override fun parseEvent(request: WebhookRequest): CodeWebhookEvent? { + return try { + objectMapper.readValue(request.body, SvnCommitEvent::class.java) + } catch (e: Exception) { + logger.warn("Fail to parse the svn web hook commit event", e) + return null + } + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/TGitWebhookEventParser.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/TGitWebhookEventParser.kt new file mode 100644 index 00000000000..cb1c6e01b4a --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/TGitWebhookEventParser.kt @@ -0,0 +1,64 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.webhook.parser + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.kotlin.readValue +import com.tencent.devops.common.webhook.pojo.WebhookRequest +import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent +import com.tencent.devops.common.webhook.pojo.code.git.GitEvent +import com.tencent.devops.common.webhook.pojo.code.git.GitReviewEvent +import org.slf4j.LoggerFactory + +/** + * 工蜂webhoook 事件解析 + */ +class TGitWebhookEventParser( + private val objectMapper: ObjectMapper +) : IWebhookEventParser { + + companion object { + private val logger = LoggerFactory.getLogger(TGitWebhookEventParser::class.java) + } + + override fun parseEvent(request: WebhookRequest): CodeWebhookEvent? { + val eventType = request.headers?.get("X-Event") + val body = request.body + return try { + if (eventType == "Review Hook") { + objectMapper.readValue(body) + } else { + objectMapper.readValue(body) + } + } catch (e: Exception) { + logger.warn("Fail to parse the git web hook commit event", e) + return null + } + } +} From c1d42a304175b7069dbf340ce29f767517a8184b Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 25 Aug 2023 18:04:56 +0800 Subject: [PATCH 036/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/tgit/TGitIssueTriggerHandler.kt | 21 ++++++++++++++++--- .../process/webhook/WebhookRequestService.kt | 2 ++ .../webhook/listener/WebhookEventListener.kt | 1 - 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt index c5049bd1f14..52907bfebb3 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt @@ -56,16 +56,15 @@ import com.tencent.devops.common.webhook.service.code.filter.ContainsFilter import com.tencent.devops.common.webhook.service.code.filter.EventTypeFilter import com.tencent.devops.common.webhook.service.code.filter.GitUrlFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter -import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler +import com.tencent.devops.common.webhook.service.code.handler.GitHookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils -import java.time.LocalDateTime @CodeWebhookHandler class TGitIssueTriggerHandler( private val eventCacheService: EventCacheService -) : CodeWebhookTriggerHandler { +) : GitHookTriggerHandler { override fun eventClass(): Class { return GitIssueEvent::class.java @@ -148,6 +147,22 @@ class TGitIssueTriggerHandler( return event.objectAttributes.action } + override fun getEventFilters( + event: GitIssueEvent, + projectId: String, + pipelineId: String, + repository: Repository, + webHookParams: WebHookParams + ): List { + val actionFilter = ContainsFilter( + pipelineId = pipelineId, + filterName = "issueAction", + triggerOn = event.objectAttributes.action ?: "", + included = WebhookUtils.convert(webHookParams.includeIssueAction) + ) + return listOf(actionFilter) + } + override fun retrieveParams(event: GitIssueEvent, projectId: String?, repository: Repository?): Map { val startParams = mutableMapOf() with(event.objectAttributes) { diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt index b0e96e62622..19e44425f45 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt @@ -41,8 +41,10 @@ import com.tencent.devops.process.trigger.WebhookTriggerService import com.tencent.devops.repository.api.ServiceRepositoryWebhookResource import com.tencent.devops.repository.pojo.RepositoryWebhookRequest import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service import java.time.LocalDateTime +@Service class WebhookRequestService( private val client: Client, private val webhookEventFactory: WebhookEventFactory, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt index 9d6eb4a2ca8..80f9ae1915c 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt @@ -47,7 +47,6 @@ import org.springframework.stereotype.Component @Component class WebhookEventListener constructor( - private val pipelineBuildWebhookService: PipelineBuildWebhookService, private val rabbitTemplate: RabbitTemplate, private val webhookRequestService: WebhookRequestService ) { From 247c741c9b920a3e2e8b4b1e6eeb52905ec8eba9 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Mon, 28 Aug 2023 11:35:31 +0800 Subject: [PATCH 037/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/event/dispatcher/pipeline/mq/MQ.kt | 5 ++ .../trigger/PipelineTriggerEventService.kt | 21 ++++--- .../process/trigger/WebhookTriggerService.kt | 59 ++++++++++--------- .../process/webhook/WebhookMQConfiguration.kt | 44 ++++++++++++++ .../process/webhook/WebhookRequestService.kt | 49 +++++++-------- .../webhook/listener/WebhookEventListener.kt | 5 ++ .../pojo/event/WebhookRequestReplayEvent.kt} | 16 ++--- 7 files changed, 127 insertions(+), 72 deletions(-) rename src/backend/ci/core/{common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequestReplay.kt => process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/WebhookRequestReplayEvent.kt} (83%) diff --git a/src/backend/ci/core/common/common-event/src/main/kotlin/com/tencent/devops/common/event/dispatcher/pipeline/mq/MQ.kt b/src/backend/ci/core/common/common-event/src/main/kotlin/com/tencent/devops/common/event/dispatcher/pipeline/mq/MQ.kt index ee1021d9d25..8d83cea826d 100644 --- a/src/backend/ci/core/common/common-event/src/main/kotlin/com/tencent/devops/common/event/dispatcher/pipeline/mq/MQ.kt +++ b/src/backend/ci/core/common/common-event/src/main/kotlin/com/tencent/devops/common/event/dispatcher/pipeline/mq/MQ.kt @@ -206,6 +206,11 @@ object MQ { const val ROUTE_P4_BUILD_REQUEST_EVENT = "r.engine.pipeline.hook.p4.event" const val QUEUE_P4_BUILD_REQUEST_EVENT = "q.engine.pipeline.hook.p4.event" + // 代码库webhook重放请求 + const val EXCHANGE_REPLAY_BUILD_REQUEST_EVENT = "e.engine.pipeline.hook.replay.event" + const val ROUTE_REPLAY_BUILD_REQUEST_EVENT = "r.engine.pipeline.hook.replay.event" + const val QUEUE_REPLAY_BUILD_REQUEST_EVENT = "q.engine.pipeline.hook.replay.event" + // 广播清理文件 const val EXCHANGE_BKJOB_CLEAR_JOB_TMP_FANOUT = "e.bkjob.clear.file.fanout" const val ROUTE_BKJOB_CLEAR_JOB_TMP_EVENT = "r.bkjob.clear.file" diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 0c2758b97fe..bcd3cbac8fe 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -35,11 +35,11 @@ import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.PageUtil import com.tencent.devops.common.client.Client +import com.tencent.devops.common.event.dispatcher.trace.TraceEventDispatcher import com.tencent.devops.common.service.utils.HomeHostUtil import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.common.web.utils.I18nUtil.getCodeLanMessage import com.tencent.devops.common.webhook.enums.WebhookI18nConstants -import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_TRIGGER_DETAIL_NOT_FOUND import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_TRIGGER_REPLAY_PIPELINE_NOT_EMPTY @@ -51,7 +51,7 @@ import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventVo import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.pojo.trigger.PipelineTriggerType import com.tencent.devops.process.pojo.trigger.RepoTriggerEventVo -import com.tencent.devops.process.webhook.WebhookRequestService +import com.tencent.devops.process.webhook.pojo.event.WebhookRequestReplayEvent import com.tencent.devops.project.api.service.ServiceAllocIdResource import org.jooq.DSLContext import org.jooq.impl.DSL @@ -67,7 +67,7 @@ class PipelineTriggerEventService @Autowired constructor( private val dslContext: DSLContext, private val client: Client, private val pipelineTriggerEventDao: PipelineTriggerEventDao, - private val webhookRequestService: WebhookRequestService + private val traceEventDispatcher: TraceEventDispatcher ) { companion object { @@ -277,16 +277,19 @@ class PipelineTriggerEventService @Autowired constructor( errorCode = ProcessMessageCode.ERROR_TRIGGER_EVENT_NOT_FOUND, params = arrayOf(eventId.toString()) ) - val request = WebhookRequestReplay( - userId = userId, - projectId = projectId, - hookRequestId = triggerEvent.hookRequestId!! - ) val scmType = PipelineTriggerType.toScmType(triggerEvent.triggerType) ?: throw ErrorCodeException( errorCode = ProcessMessageCode.ERROR_TRIGGER_TYPE_REPLAY_NOT_SUPPORT, params = arrayOf(triggerEvent.triggerType) ) - webhookRequestService.replay(scmType = scmType, request = request) + traceEventDispatcher.dispatch( + WebhookRequestReplayEvent( + userId = userId, + projectId = projectId, + hookRequestId = triggerEvent.hookRequestId!!, + scmType = scmType, + pipelineId = pipelineId + ) + ) return true } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/WebhookTriggerService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/WebhookTriggerService.kt index f116d989549..fecd547f868 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/WebhookTriggerService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/WebhookTriggerService.kt @@ -29,12 +29,12 @@ package com.tencent.devops.process.trigger import com.tencent.devops.common.api.enums.ScmType -import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher import com.tencent.devops.process.engine.service.PipelineWebhookService import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService +import com.tencent.devops.process.webhook.pojo.event.WebhookRequestReplayEvent import org.slf4j.LoggerFactory import org.springframework.stereotype.Service import java.time.LocalDateTime @@ -44,9 +44,9 @@ class WebhookTriggerService( private val pipelineWebhookService: PipelineWebhookService, private val pipelineBuildWebhookService: PipelineBuildWebhookService ) { - companion object { - private val logger = LoggerFactory.getLogger(WebhookTriggerService::class.java) - } + companion object { + private val logger = LoggerFactory.getLogger(WebhookTriggerService::class.java) + } fun trigger( scmType: ScmType, @@ -79,8 +79,7 @@ class WebhookTriggerService( } fun replay( - scmType: ScmType, - request: WebhookRequestReplay, + replayEvent: WebhookRequestReplayEvent, matcher: ScmWebhookMatcher, eventTime: LocalDateTime ) { @@ -89,31 +88,33 @@ class WebhookTriggerService( logger.info("webhook replay trigger pre match|${preMatch.reason}") return } - val triggerEvent = PipelineTriggerEvent( - triggerType = scmType.name, - eventType = matcher.getEventType().name, - triggerUser = matcher.getUsername(), - eventDesc = matcher.getEventDesc(), - hookRequestId = request.hookRequestId, - eventTime = eventTime - ) - val subscribers = request.pipelineId?.let { - listOf( - PipelineWebhookSubscriber( - projectId = request.projectId, - pipelineId = request.pipelineId!! - ) + with(replayEvent) { + val triggerEvent = PipelineTriggerEvent( + triggerType = scmType.name, + eventType = matcher.getEventType().name, + triggerUser = matcher.getUsername(), + eventDesc = matcher.getEventDesc(), + hookRequestId = hookRequestId, + eventTime = eventTime ) - } ?: run { - pipelineWebhookService.getWebhookPipelines( - name = matcher.getRepoName(), - repositoryType = scmType.name + val subscribers = pipelineId?.let { + listOf( + PipelineWebhookSubscriber( + projectId = projectId, + pipelineId = pipelineId + ) + ) + } ?: run { + pipelineWebhookService.getWebhookPipelines( + name = matcher.getRepoName(), + repositoryType = scmType.name + ) + } + pipelineBuildWebhookService.dispatchPipelineSubscribers( + matcher = matcher, + triggerEvent = triggerEvent, + subscribers = subscribers ) } - pipelineBuildWebhookService.dispatchPipelineSubscribers( - matcher = matcher, - triggerEvent = triggerEvent, - subscribers = subscribers - ) } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookMQConfiguration.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookMQConfiguration.kt index 12ec72b0c91..d49eb0f3113 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookMQConfiguration.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookMQConfiguration.kt @@ -337,6 +337,50 @@ class WebhookMQConfiguration @Autowired constructor() { ) } + // replay 消息队列配置 + @Bean + fun replayEventExchange(): DirectExchange { + val directExchange = DirectExchange(MQ.EXCHANGE_REPLAY_BUILD_REQUEST_EVENT, true, false) + directExchange.isDelayed = true + return directExchange + } + + @Bean + fun replayEventQueue(): Queue { + return Queue(MQ.QUEUE_REPLAY_BUILD_REQUEST_EVENT, true) + } + + @Bean + fun replayEventBind( + @Autowired replayEventQueue: Queue, + @Autowired replayEventExchange: DirectExchange + ): Binding { + return BindingBuilder.bind(replayEventQueue).to(replayEventExchange).with(MQ.ROUTE_REPLAY_BUILD_REQUEST_EVENT) + } + + @Bean + fun replayEventListener( + @Autowired connectionFactory: ConnectionFactory, + @Autowired replayEventQueue: Queue, + @Autowired rabbitAdmin: RabbitAdmin, + @Autowired webhookEventListener: WebhookEventListener, + @Autowired messageConverter: Jackson2JsonMessageConverter + ): SimpleMessageListenerContainer { + logger.info("Start webhook replay event listener") + val adapter = MessageListenerAdapter(webhookEventListener, WebhookEventListener::handleReplayRequest.name) + adapter.setMessageConverter(messageConverter) + return Tools.createSimpleMessageListenerContainerByAdapter( + connectionFactory = connectionFactory, + queue = replayEventQueue, + rabbitAdmin = rabbitAdmin, + adapter = adapter, + startConsumerMinInterval = 1, + consecutiveActiveTrigger = 1, + concurrency = 10, + maxConcurrency = 20 + ) + } + companion object { private val logger = LoggerFactory.getLogger(WebhookMQConfiguration::class.java) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt index 19e44425f45..363d999e47b 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt @@ -33,11 +33,11 @@ import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.client.Client import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.common.webhook.pojo.WebhookRequest -import com.tencent.devops.common.webhook.pojo.WebhookRequestReplay import com.tencent.devops.common.webhook.pojo.code.github.GithubCheckRunEvent import com.tencent.devops.process.api.service.ServiceBuildResource import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.trigger.WebhookTriggerService +import com.tencent.devops.process.webhook.pojo.event.WebhookRequestReplayEvent import com.tencent.devops.repository.api.ServiceRepositoryWebhookResource import com.tencent.devops.repository.pojo.RepositoryWebhookRequest import org.slf4j.LoggerFactory @@ -89,30 +89,31 @@ class WebhookRequestService( ) } - fun replay(scmType: ScmType, request: WebhookRequestReplay) { - val repoWebhookRequest = client.get(ServiceRepositoryWebhookResource::class).getWebhookRequest( - requestId = request.hookRequestId - ).data ?: throw ErrorCodeException( - errorCode = ProcessMessageCode.ERROR_WEBHOOK_REQUEST_NOT_FOUND, - params = arrayOf(request.hookRequestId.toString()) - ) - val webhookRequest = WebhookRequest( - headers = repoWebhookRequest.requestHeader, - body = repoWebhookRequest.requestBody - ) - val event = webhookEventFactory.parseEvent(scmType = scmType, request = webhookRequest) ?: run { - logger.warn("Failed to parse webhook event") - return - } - val matcher = webhookEventFactory.createScmWebHookMatcher(scmType = scmType, event = event) + fun replay(replayEvent: WebhookRequestReplayEvent) { + with(replayEvent) { + val repoWebhookRequest = client.get(ServiceRepositoryWebhookResource::class).getWebhookRequest( + requestId = hookRequestId + ).data ?: throw ErrorCodeException( + errorCode = ProcessMessageCode.ERROR_WEBHOOK_REQUEST_NOT_FOUND, + params = arrayOf(hookRequestId.toString()) + ) + val webhookRequest = WebhookRequest( + headers = repoWebhookRequest.requestHeader, + body = repoWebhookRequest.requestBody + ) + val event = webhookEventFactory.parseEvent(scmType = scmType, request = webhookRequest) ?: run { + logger.warn("Failed to parse webhook event") + return + } + val matcher = webhookEventFactory.createScmWebHookMatcher(scmType = scmType, event = event) - val eventTime = LocalDateTime.now() - webhookTriggerService.replay( - scmType = scmType, - request = request, - matcher = matcher, - eventTime = eventTime - ) + val eventTime = LocalDateTime.now() + webhookTriggerService.replay( + replayEvent = replayEvent, + matcher = matcher, + eventTime = eventTime + ) + } } private fun githubRetry(event: GithubCheckRunEvent) { diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt index 80f9ae1915c..f27ff38ac28 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt @@ -32,6 +32,7 @@ import com.tencent.devops.common.service.trace.TraceTag import com.tencent.devops.common.webhook.pojo.WebhookRequest import com.tencent.devops.process.webhook.CodeWebhookEventDispatcher import com.tencent.devops.process.webhook.WebhookRequestService +import com.tencent.devops.process.webhook.pojo.event.WebhookRequestReplayEvent import com.tencent.devops.process.webhook.pojo.event.commit.GitWebhookEvent import com.tencent.devops.process.webhook.pojo.event.commit.GithubWebhookEvent import com.tencent.devops.process.webhook.pojo.event.commit.GitlabWebhookEvent @@ -226,6 +227,10 @@ class WebhookEventListener constructor( } } + fun handleReplayRequest(replayEvent: WebhookRequestReplayEvent) { + webhookRequestService.replay(replayEvent = replayEvent) + } + companion object { private val logger = LoggerFactory.getLogger(WebhookEventListener::class.java) private const val DELAY_MILLS = 3 * 1000 diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequestReplay.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/WebhookRequestReplayEvent.kt similarity index 83% rename from src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequestReplay.kt rename to src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/WebhookRequestReplayEvent.kt index 81be3f33ff4..136f67ff689 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequestReplay.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/WebhookRequestReplayEvent.kt @@ -26,19 +26,15 @@ * */ -package com.tencent.devops.common.webhook.pojo +package com.tencent.devops.process.webhook.pojo.event -import io.swagger.annotations.ApiModel -import io.swagger.annotations.ApiModelProperty +import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.event.pojo.trace.ITraceEvent -@ApiModel -class WebhookRequestReplay( - @ApiModelProperty("用户ID") +data class WebhookRequestReplayEvent( val userId: String, - @ApiModelProperty("项目ID") val projectId: String, - @ApiModelProperty("webhook请求ID") val hookRequestId: Long, - @ApiModelProperty("重试流水线ID") + val scmType: ScmType, val pipelineId: String? = null -) +): ITraceEvent() From c86bf7204c59eae60590ea2f8f90f5abf07f1fc1 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Mon, 28 Aug 2023 12:21:42 +0800 Subject: [PATCH 038/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/engine/EventDispatcherConfiguration.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/EventDispatcherConfiguration.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/EventDispatcherConfiguration.kt index 9e8cc18660b..a5b733a3892 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/EventDispatcherConfiguration.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/EventDispatcherConfiguration.kt @@ -28,6 +28,7 @@ package com.tencent.devops.process.engine import com.tencent.devops.common.event.dispatcher.pipeline.mq.MQEventDispatcher +import com.tencent.devops.common.event.dispatcher.trace.TraceEventDispatcher import org.springframework.amqp.rabbit.core.RabbitTemplate import org.springframework.boot.autoconfigure.AutoConfigureOrder import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication @@ -48,4 +49,7 @@ class EventDispatcherConfiguration { @Bean fun pipelineEventDispatcher(rabbitTemplate: RabbitTemplate) = MQEventDispatcher(rabbitTemplate) + + @Bean + fun traceEventDispatcher(rabbitTemplate: RabbitTemplate) = TraceEventDispatcher(rabbitTemplate) } From 9dcf69ae7d41af61e4dc311ff714eccd475d01f4 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 28 Aug 2023 18:15:22 +0800 Subject: [PATCH 039/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tencent/devops/process/webhook/WebhookEventFactory.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookEventFactory.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookEventFactory.kt index 40b942361b7..7b3bdc71ee4 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookEventFactory.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookEventFactory.kt @@ -34,10 +34,12 @@ import com.tencent.devops.common.api.exception.InvalidParamException import com.tencent.devops.common.webhook.pojo.WebhookRequest import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent import com.tencent.devops.common.webhook.pojo.code.git.GitEvent +import com.tencent.devops.common.webhook.pojo.code.github.GithubEvent import com.tencent.devops.common.webhook.pojo.code.p4.P4Event import com.tencent.devops.common.webhook.pojo.code.svn.SvnCommitEvent import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher import com.tencent.devops.process.engine.service.code.ScmWebhookMatcherBuilder +import com.tencent.devops.process.webhook.parser.GithubWebhookEventParser import com.tencent.devops.process.webhook.parser.GitlabWebhookEventParser import com.tencent.devops.process.webhook.parser.P4WebhookEventParser import com.tencent.devops.process.webhook.parser.SvnWebhookEventParser @@ -65,6 +67,9 @@ class WebhookEventFactory @Autowired constructor( ScmType.CODE_GITLAB -> GitlabWebhookEventParser(objectMapper = objectMapper) + ScmType.GITHUB -> + GithubWebhookEventParser(objectMapper = objectMapper) + else -> throw InvalidParamException("Unknown scm type($scmType)") } @@ -85,6 +90,9 @@ class WebhookEventFactory @Autowired constructor( ScmType.CODE_GITLAB -> scmWebhookMatcherBuilder.createGitlabWebHookMatcher(event = event as GitEvent) + ScmType.GITHUB -> + scmWebhookMatcherBuilder.createGithubWebHookMatcher(event = event as GithubEvent) + else -> throw InvalidParamException("Unknown scm type($scmType)") } From cbbdd886878f67ba6930deb803c5037ee8d2b323 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 29 Aug 2023 09:57:12 +0800 Subject: [PATCH 040/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/code/filter/BranchFilter.kt | 4 +-- .../service/code/filter/PathPrefixFilter.kt | 4 +-- .../service/code/filter/PathRegexFilter.kt | 4 +-- .../webhook/service/code/filter/UserFilter.kt | 4 +-- .../code/matcher/AbstractScmWebhookMatcher.kt | 2 ++ .../service/code/matcher/ScmWebhookMatcher.kt | 4 ++- .../webhook/PipelineBuildWebhookService.kt | 34 +++++++++++++++++++ 7 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/BranchFilter.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/BranchFilter.kt index f5ecc47140c..aa7f4d4fa78 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/BranchFilter.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/BranchFilter.kt @@ -37,9 +37,9 @@ class BranchFilter( private val includedBranches: List, private val excludedBranches: List, // 包含过滤失败原因 - private val includedFailedReason: String, + private val includedFailedReason: String = "", // 排除过滤失败原因 - private val excludedFailedReason: String + private val excludedFailedReason: String = "" ) : WebhookFilter { companion object { diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathPrefixFilter.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathPrefixFilter.kt index 318e64756c3..98cd6857d4b 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathPrefixFilter.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathPrefixFilter.kt @@ -33,9 +33,9 @@ class PathPrefixFilter( private val includedPaths: List, private val excludedPaths: List, // 包含过滤失败原因 - private val includedFailedReason: String, + private val includedFailedReason: String = "", // 排除过滤失败原因 - private val excludedFailedReason: String, + private val excludedFailedReason: String = "", ) : BasePathFilter( pipelineId = pipelineId, triggerOnPath = triggerOnPath, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathRegexFilter.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathRegexFilter.kt index 5e66c3d309c..9d4b642ed06 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathRegexFilter.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathRegexFilter.kt @@ -35,9 +35,9 @@ class PathRegexFilter( private val includedPaths: List, private val excludedPaths: List, // 包含过滤失败原因 - private val includedFailedReason: String, + private val includedFailedReason: String = "", // 排除过滤失败原因 - private val excludedFailedReason: String, + private val excludedFailedReason: String = "", private val caseSensitive: Boolean ) : BasePathFilter( pipelineId = pipelineId, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/UserFilter.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/UserFilter.kt index 3b7da07a8d0..411fde2799b 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/UserFilter.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/UserFilter.kt @@ -35,9 +35,9 @@ class UserFilter( private val includedUsers: List, private val excludedUsers: List, // 包含过滤失败原因 - private val includedFailedReason: String, + private val includedFailedReason: String = "", // 排除过滤失败原因 - private val excludedFailedReason: String + private val excludedFailedReason: String = "" ) : WebhookFilter { companion object { diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt index 25c3a3d1e57..3f61642ce0e 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt @@ -92,6 +92,8 @@ abstract class AbstractScmWebhookMatcher( return eventHandler.getExternalId(event) } + override fun getSourceEvent() = event as CodeWebhookEvent + override fun retrieveParams(projectId: String?, repository: Repository?): Map { return eventHandler.retrieveParams( event = event, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt index 2aa4cd5bf37..7dbeb8a9a68 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt @@ -27,9 +27,9 @@ package com.tencent.devops.common.webhook.service.code.matcher -import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeType +import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.repository.pojo.Repository @@ -105,6 +105,8 @@ interface ScmWebhookMatcher { return emptyList() } + fun getSourceEvent(): CodeWebhookEvent + companion object { private val logger = LoggerFactory.getLogger(ScmWebhookMatcher::class.java) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt index d5803d9ae9f..1c39061ad1d 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt @@ -30,6 +30,9 @@ package com.tencent.devops.process.service.webhook import com.fasterxml.jackson.databind.ObjectMapper import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.client.Client +import com.tencent.devops.common.event.dispatcher.pipeline.PipelineEventDispatcher +import com.tencent.devops.common.event.enums.ActionType +import com.tencent.devops.common.event.pojo.pipeline.PipelineBuildQueueBroadCastEvent import com.tencent.devops.common.log.pojo.message.LogMessage import com.tencent.devops.common.log.utils.BuildLogPrinter import com.tencent.devops.common.pipeline.container.TriggerContainer @@ -37,6 +40,7 @@ import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.common.pipeline.enums.StartType import com.tencent.devops.common.pipeline.pojo.BuildParameters import com.tencent.devops.common.pipeline.pojo.element.trigger.WebHookTriggerElement +import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent import com.tencent.devops.common.webhook.service.code.loader.WebhookElementParamsRegistrar import com.tencent.devops.common.webhook.service.code.loader.WebhookStartParamsRegistrar import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher @@ -82,6 +86,7 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { pipelineBuildCommitService = applicationContext.getBean(PipelineBuildCommitService::class.java) webhookBuildParameterService = applicationContext.getBean(WebhookBuildParameterService::class.java) pipelineTriggerEventService = applicationContext.getBean(PipelineTriggerEventService::class.java) + pipelineEventDispatcher = applicationContext.getBean(PipelineEventDispatcher::class.java) } companion object { @@ -98,6 +103,7 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { lateinit var pipelineBuildCommitService: PipelineBuildCommitService lateinit var webhookBuildParameterService: WebhookBuildParameterService lateinit var pipelineTriggerEventService: PipelineTriggerEventService + lateinit var pipelineEventDispatcher: PipelineEventDispatcher private val logger = LoggerFactory.getLogger(PipelineBuildWebhookService::class.java) } @@ -283,6 +289,14 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { .eventSource(eventSource = repo.repoHashId!!) .reason(PipelineTriggerReason.TRIGGER_SUCCESS.name) .buildNum(buildDetail?.buildNum.toString()) + // 回写检查 + dispatchPipelineBuildEvent( + userId = userId, + projectId = projectId, + pipelineId = pipelineId, + buildId = buildId, + event = matcher.getSourceEvent() + ) } } catch (ignore: Exception) { logger.warn("$pipelineId|webhook trigger|(${element.name})|repo(${matcher.getRepoName()})", ignore) @@ -392,5 +406,25 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { } } + private fun dispatchPipelineBuildEvent( + event: CodeWebhookEvent, + projectId: String, + pipelineId: String, + buildId: String, + userId:String + ) { + pipelineEventDispatcher.dispatch( + PipelineBuildQueueBroadCastEvent( + source = "startQueue", + projectId = projectId, + pipelineId = pipelineId, + userId = userId, + buildId = buildId, + actionType = ActionType.START, + triggerType = StartType.WEB_HOOK.name + ) + ) + } + abstract fun checkPermission(userId: String, projectId: String, pipelineId: String) } From 85fd5c25d192719c7371121d307640626c900410 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 29 Aug 2023 15:15:47 +0800 Subject: [PATCH 041/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/code/matcher/AbstractScmWebhookMatcher.kt | 3 --- .../webhook/service/code/matcher/ScmWebhookMatcher.kt | 2 -- .../service/webhook/PipelineBuildWebhookService.kt | 8 ++++---- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt index 3f61642ce0e..813f906aa9a 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt @@ -27,7 +27,6 @@ package com.tencent.devops.common.webhook.service.code.matcher -import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent import com.tencent.devops.common.webhook.service.code.loader.CodeWebhookHandlerRegistrar @@ -92,8 +91,6 @@ abstract class AbstractScmWebhookMatcher( return eventHandler.getExternalId(event) } - override fun getSourceEvent() = event as CodeWebhookEvent - override fun retrieveParams(projectId: String?, repository: Repository?): Map { return eventHandler.retrieveParams( event = event, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt index 7dbeb8a9a68..87231b73df9 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt @@ -105,8 +105,6 @@ interface ScmWebhookMatcher { return emptyList() } - fun getSourceEvent(): CodeWebhookEvent - companion object { private val logger = LoggerFactory.getLogger(ScmWebhookMatcher::class.java) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt index 1c39061ad1d..e008113f86c 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt @@ -40,7 +40,6 @@ import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.common.pipeline.enums.StartType import com.tencent.devops.common.pipeline.pojo.BuildParameters import com.tencent.devops.common.pipeline.pojo.element.trigger.WebHookTriggerElement -import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent import com.tencent.devops.common.webhook.service.code.loader.WebhookElementParamsRegistrar import com.tencent.devops.common.webhook.service.code.loader.WebhookStartParamsRegistrar import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher @@ -68,6 +67,8 @@ import com.tencent.devops.repository.api.ServiceRepositoryResource import org.slf4j.LoggerFactory import org.springframework.context.ApplicationContext import org.springframework.context.ApplicationContextAware +import java.sql.Timestamp +import java.time.format.DateTimeFormatter @Suppress("ALL") abstract class PipelineBuildWebhookService : ApplicationContextAware { @@ -294,8 +295,7 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { userId = userId, projectId = projectId, pipelineId = pipelineId, - buildId = buildId, - event = matcher.getSourceEvent() + buildId = buildId ) } } catch (ignore: Exception) { @@ -407,12 +407,12 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { } private fun dispatchPipelineBuildEvent( - event: CodeWebhookEvent, projectId: String, pipelineId: String, buildId: String, userId:String ) { + logger.info("dispatch pipeline build event|${projectId}|${pipelineId}|${buildId}") pipelineEventDispatcher.dispatch( PipelineBuildQueueBroadCastEvent( source = "startQueue", From bd35130af70613a056dca82bfd0f7095381d2e0b Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 30 Aug 2023 17:17:52 +0800 Subject: [PATCH 042/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webhook/PipelineBuildWebhookService.kt | 34 ------------------- 1 file changed, 34 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt index e008113f86c..d5803d9ae9f 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt @@ -30,9 +30,6 @@ package com.tencent.devops.process.service.webhook import com.fasterxml.jackson.databind.ObjectMapper import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.client.Client -import com.tencent.devops.common.event.dispatcher.pipeline.PipelineEventDispatcher -import com.tencent.devops.common.event.enums.ActionType -import com.tencent.devops.common.event.pojo.pipeline.PipelineBuildQueueBroadCastEvent import com.tencent.devops.common.log.pojo.message.LogMessage import com.tencent.devops.common.log.utils.BuildLogPrinter import com.tencent.devops.common.pipeline.container.TriggerContainer @@ -67,8 +64,6 @@ import com.tencent.devops.repository.api.ServiceRepositoryResource import org.slf4j.LoggerFactory import org.springframework.context.ApplicationContext import org.springframework.context.ApplicationContextAware -import java.sql.Timestamp -import java.time.format.DateTimeFormatter @Suppress("ALL") abstract class PipelineBuildWebhookService : ApplicationContextAware { @@ -87,7 +82,6 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { pipelineBuildCommitService = applicationContext.getBean(PipelineBuildCommitService::class.java) webhookBuildParameterService = applicationContext.getBean(WebhookBuildParameterService::class.java) pipelineTriggerEventService = applicationContext.getBean(PipelineTriggerEventService::class.java) - pipelineEventDispatcher = applicationContext.getBean(PipelineEventDispatcher::class.java) } companion object { @@ -104,7 +98,6 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { lateinit var pipelineBuildCommitService: PipelineBuildCommitService lateinit var webhookBuildParameterService: WebhookBuildParameterService lateinit var pipelineTriggerEventService: PipelineTriggerEventService - lateinit var pipelineEventDispatcher: PipelineEventDispatcher private val logger = LoggerFactory.getLogger(PipelineBuildWebhookService::class.java) } @@ -290,13 +283,6 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { .eventSource(eventSource = repo.repoHashId!!) .reason(PipelineTriggerReason.TRIGGER_SUCCESS.name) .buildNum(buildDetail?.buildNum.toString()) - // 回写检查 - dispatchPipelineBuildEvent( - userId = userId, - projectId = projectId, - pipelineId = pipelineId, - buildId = buildId - ) } } catch (ignore: Exception) { logger.warn("$pipelineId|webhook trigger|(${element.name})|repo(${matcher.getRepoName()})", ignore) @@ -406,25 +392,5 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { } } - private fun dispatchPipelineBuildEvent( - projectId: String, - pipelineId: String, - buildId: String, - userId:String - ) { - logger.info("dispatch pipeline build event|${projectId}|${pipelineId}|${buildId}") - pipelineEventDispatcher.dispatch( - PipelineBuildQueueBroadCastEvent( - source = "startQueue", - projectId = projectId, - pipelineId = pipelineId, - userId = userId, - buildId = buildId, - actionType = ActionType.START, - triggerType = StartType.WEB_HOOK.name - ) - ) - } - abstract fun checkPermission(userId: String, projectId: String, pipelineId: String) } From 8334729bfc7d88d1a01a88cd631f9d493d0fa5a5 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 1 Sep 2023 17:46:51 +0800 Subject: [PATCH 043/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/common/api/pojo/I18Variable.kt | 5 +- .../element/trigger/enums/CodeEventType.kt | 65 +++++++++++++++++++ .../webhook/enums/WebhookI18nConstants.kt | 47 ++++++++++---- .../service/code/filter/ContainsFilter.kt | 19 +++++- .../service/code/filter/RegexContainFilter.kt | 38 +++++++---- .../github/GithubCreateTriggerHandler.kt | 10 +-- .../handler/github/GithubPrTriggerHandler.kt | 39 ++++++----- .../github/GithubPushTriggerHandler.kt | 35 +++++----- .../code/handler/p4/P4ChangeTriggerHandler.kt | 26 ++++---- .../code/handler/p4/P4ShelveTriggerHandler.kt | 22 ++++--- .../handler/svn/SvnCommitTriggerHandler.kt | 34 ++++++---- .../handler/tgit/TGitIssueTriggerHandler.kt | 16 +++-- .../code/handler/tgit/TGitMrTriggerHandler.kt | 50 +++++++++----- .../handler/tgit/TGitNoteTriggerHandler.kt | 18 +++-- .../handler/tgit/TGitPushTriggerHandler.kt | 40 ++++++++---- .../handler/tgit/TGitReviewTriggerHandler.kt | 14 ++-- .../handler/tgit/TGitTagPushTriggerHandler.kt | 40 +++++++----- .../user/UserPipelineTriggerEventResource.kt | 9 ++- .../UserPipelineTriggerEventResourceImpl.kt | 11 +++- .../pojo/event/WebhookRequestReplayEvent.kt | 3 + .../i18n/process/message_en_US.properties | 42 ++++++++++++ .../i18n/process/message_zh_CN.properties | 44 ++++++++++++- 22 files changed, 462 insertions(+), 165 deletions(-) diff --git a/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/pojo/I18Variable.kt b/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/pojo/I18Variable.kt index 1a1cb16b3b8..a3d3fe471b3 100644 --- a/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/pojo/I18Variable.kt +++ b/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/pojo/I18Variable.kt @@ -28,6 +28,7 @@ package com.tencent.devops.common.api.pojo +import com.tencent.devops.common.api.util.JsonUtil import io.swagger.annotations.ApiModel import io.swagger.annotations.ApiModelProperty @@ -39,4 +40,6 @@ data class I18Variable( val params: List, @ApiModelProperty("默认信息") val defaultMessage: String? = null -) +){ + fun toJsonStr() = JsonUtil.toJson(this,false) +} \ No newline at end of file diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/enums/CodeEventType.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/enums/CodeEventType.kt index c6020b6b9d5..7304da83ad2 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/enums/CodeEventType.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/enums/CodeEventType.kt @@ -27,6 +27,8 @@ package com.tencent.devops.common.pipeline.pojo.element.trigger.enums +import com.tencent.devops.common.api.enums.ScmType + enum class CodeEventType { // git event PUSH, @@ -62,5 +64,68 @@ enum class CodeEventType { companion object { const val MESSAGE_CODE_PREFIX = "EVENT_TYPE" + + /** + * 工蜂事件类型 + */ + val CODE_GIT_EVENTS = listOf( + PUSH, + MERGE_REQUEST, + MERGE_REQUEST_ACCEPT, + TAG_PUSH, + NOTE, + REVIEW, + ISSUES + ) + + /** + * Github事件类型 + */ + val CODE_GITHUB_EVENTS = listOf( + PUSH, + MERGE_REQUEST, + MERGE_REQUEST_ACCEPT, + CREATE + ) + + val CODE_P4_EVENTS = listOf( + CHANGE_COMMIT, + CHANGE_SUBMIT, + CHANGE_CONTENT, + SHELVE_COMMIT, + SHELVE_SUBMIT + ) + + val CODE_GITLAB_EVENTS = listOf( + PUSH, + MERGE_REQUEST, + MERGE_REQUEST_ACCEPT, + TAG_PUSH + ) + + val CODE_TGIT_EVENTS = listOf( + PUSH, + MERGE_REQUEST, + MERGE_REQUEST_ACCEPT, + TAG_PUSH, + NOTE, + ISSUES + ) + + val CODE_SVN_EVENTS = listOf( + POST_COMMIT, + PRE_COMMIT, + LOCK_COMMIT + ) + + fun getEventsByScmType(scmType: ScmType?):List = when(scmType){ + ScmType.CODE_GIT -> CODE_GIT_EVENTS + ScmType.CODE_TGIT -> CODE_TGIT_EVENTS + ScmType.GITHUB -> CODE_GITHUB_EVENTS + ScmType.CODE_GITLAB -> CODE_GITLAB_EVENTS + ScmType.CODE_SVN -> CODE_SVN_EVENTS + ScmType.CODE_P4 -> CODE_P4_EVENTS + else -> values().toList() + } } } diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt index 895335c3502..77ece950196 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt @@ -47,53 +47,76 @@ object WebhookI18nConstants { const val TGIT_REVIEW_CHANGE_DENIED_EVENT_DESC = "bkTgitReviewChangeDeniedEventDesc" const val TGIT_REVIEW_CHANGE_REQUIRED_EVENT_DESC = "bkTgitReviewChangeRequiredEventDesc" const val TGIT_TAG_PUSH_EVENT_DESC = "bkTgitTagPushEventDesc" + // Github事件描述 const val GITHUB_PUSH_EVENT_DESC = "bkGithubPushEventDesc" - const val GITHUB_CREATE_EVENT_DESC = "bkGithubCreateEventDesc" + const val GITHUB_CREATE_TAG_EVENT_DESC = "bkGithubCreateTagEventDesc" + const val GITHUB_CREATE_BRANCH_EVENT_DESC = "bkGithubCreateBranchEventDesc" const val GITHUB_PR_EVENT_DESC = "bkGithubPrEventDesc" + // P4事件描述 - const val P4_Change_EVENT_DESC = "bkP4CreateEventDesc" - const val P4_Shelve_EVENT_DESC = "bkP4ShelveEventDesc" + const val P4_EVENT_DESC = "bkP4EventDesc" + // SVN事件描述 - const val SVN_COMMIT_EVENT_DESC = "bkSvnShelveEventDesc" + const val SVN_COMMIT_EVENT_DESC = "bkSvnCommitEventDesc" + // 手动触发 const val MANUAL_START_EVENT_DESC = "bkManualStartEventDesc" + // 远程触发 - const val REMOTE_START_EVENT_DESC = "bkManualStartEventDesc" + const val REMOTE_START_EVENT_DESC = "bkRemoteStartEventDesc" + // openApi触发 - const val SERVICE_START_EVENT_DESC = "bkManualStartEventDesc" + const val SERVICE_START_EVENT_DESC = "bkServiceStartEventDesc" + // 事件类型匹配 - const val EVENT_TYPE_MATCHED="bkRepoTriggerEventTypeMatched" + const val EVENT_TYPE_MATCHED = "bkRepoTriggerEventTypeMatched" + // 事件类型不匹配 - const val EVENT_TYPE_NOT_MATCH="bkRepoTriggerEventTypeNotMatch" + const val EVENT_TYPE_NOT_MATCH = "bkRepoTriggerEventTypeNotMatch" + // 目标分支不匹配 const val TARGET_BRANCH_NOT_MATCH = "bkRepoTriggerTargetBranchNotMatch" + // 目标分支被排除 const val TARGET_BRANCH_IGNORED = "bkRepoTriggerTargetBranchIgnored" + // 源分支不匹配 const val SOURCE_BRANCH_NOT_MATCH = "bkRepoTriggerSourceBranchNotMatch" + // 源分支被排除 const val SOURCE_BRANCH_IGNORED = "bkRepoTriggerSourceBranchIgnored" + // 用户不匹配 const val USER_NOT_MATCH = "bkRepoTriggerUserNotMatch" + // 用户被排除 const val USER_IGNORED = "bkRepoTriggerUserIgnored" + // 路径不匹配 const val PATH_NOT_MATCH = "bkRepoTriggerPathNotMatch" + // 路径被排除 const val PATH_IGNORED = "bkRepoTriggerPathIgnored" + // Tag名称不匹配 const val TAG_NAME_NOT_MATCH = "bkRepoTriggerTagNameNotMatch" + // Tag名称被排除 const val TAG_NAME_IGNORED = "bkRepoTriggerTagNameIgnored" + // Tag来源分支不匹配 const val TAG_SOURCE_BRANCH_NOT_MATCH = "bkRepoTriggerTagSourceBranchNotMatch" + // 评论内容不匹配 - const val NOTE_CONTENT_IGNORED = "bkRepoTriggerNoteContentNotMatch" + const val NOTE_CONTENT_NOT_MATCH = "bkRepoTriggerNoteContentNotMatch" + // 评论类型不匹配 - const val NOTE_ACTION_IGNORED = "bkRepoTriggerNoteActionNotMatch" + const val NOTE_ACTION_NOT_MATCH = "bkRepoTriggerNoteActionNotMatch" + // 评审操作类型不匹配 - const val REVIEW_ACTION_IGNORED = "bkRepoTriggerReviewActionNotMatch" + const val REVIEW_ACTION_NOT_MATCH = "bkRepoTriggerReviewActionNotMatch" + // issues操作类型不匹配 - const val ISSUES_ACTION_IGNORED = "bkRepoTriggerNoteActionNotMatch" + const val ISSUES_ACTION_NOT_MATCH = "bkRepoTriggerIssueActionNotMatch" } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/ContainsFilter.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/ContainsFilter.kt index 75c7822d73d..4a2aade9166 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/ContainsFilter.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/ContainsFilter.kt @@ -37,7 +37,8 @@ class ContainsFilter( // 过滤器名字 private val filterName: String, private val triggerOn: String, - private val included: List + private val included: List, + private val failedReason: String = "" ) : WebhookFilter { companion object { @@ -46,6 +47,20 @@ class ContainsFilter( override fun doFilter(response: WebhookFilterResponse): Boolean { logger.info("$pipelineId|triggerOn:$triggerOn|included:$included|$filterName filter") - return included.isEmpty() || included.contains(triggerOn) + + return buildFilterFailedReason( + action = { + included.isEmpty() || included.contains(triggerOn) + }, + response = response + ) + } + + private fun buildFilterFailedReason(action: () -> Boolean, response: WebhookFilterResponse): Boolean { + val filterResult = action.invoke() + if (!filterResult && failedReason.isNotBlank()) { + response.failedReason = failedReason + } + return filterResult } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/RegexContainFilter.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/RegexContainFilter.kt index da00ab5e892..888d6b7befd 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/RegexContainFilter.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/RegexContainFilter.kt @@ -39,7 +39,8 @@ class RegexContainFilter( // 过滤器名字 private val filterName: String, private val triggerOn: String, - private val included: List + private val included: List, + private val failedReason: String = "" ) : WebhookFilter { companion object { @@ -48,18 +49,31 @@ class RegexContainFilter( override fun doFilter(response: WebhookFilterResponse): Boolean { logger.info("$pipelineId|triggerOn:$triggerOn|included:$included|$filterName filter") - if (included.isEmpty()) { - return true - } - included.forEach { - try { - if (Pattern.compile(it).matcher(triggerOn).find()) { - return true + return buildFilterFailedReason( + action = { + if (included.isEmpty()) { + true + } + included.forEach { + try { + if (Pattern.compile(it).matcher(triggerOn).find()) { + true + } + } catch (e: PatternSyntaxException) { + logger.warn("($it) syntax error :$e ") + } } - } catch (e: PatternSyntaxException) { - logger.warn("($it) syntax error :$e ") - } + false + }, + response = response + ) + } + + private fun buildFilterFailedReason(action: () -> Boolean, response: WebhookFilterResponse): Boolean { + val filterResult = action.invoke() + if (!filterResult && failedReason.isNotBlank()) { + response.failedReason = failedReason } - return false + return filterResult } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt index f9ab513b1ef..23bc82db501 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt @@ -29,7 +29,6 @@ package com.tencent.devops.common.webhook.service.code.handler.github import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.util.DateTimeUtil -import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler @@ -80,21 +79,22 @@ class GithubCreateTriggerHandler : GitHookTriggerHandler { } override fun getEventDesc(event: GithubCreateEvent): String { + var i18Code = WebhookI18nConstants.GITHUB_CREATE_TAG_EVENT_DESC val linkUrl = if (event.ref_type == "tag") { "https://github.com/${event.repository.fullName}/releases/tag/${event.ref}" } else { + i18Code = WebhookI18nConstants.GITHUB_CREATE_BRANCH_EVENT_DESC "https://github.com/${event.repository.fullName}/tree/${event.ref}" } - val i18Variable = I18Variable( - code = WebhookI18nConstants.GITHUB_CREATE_EVENT_DESC, + return I18Variable( + code = i18Code, params = listOf( getBranchName(event), linkUrl, getUsername(event), DateTimeUtil.formatMilliTime(LocalDateTime.now().timestampmilli()) ) - ) - return JsonUtil.toJson(i18Variable) + ).toJsonStr() } override fun getExternalId(event: GithubCreateEvent): String { diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt index be569c3be01..13e6c373203 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt @@ -28,9 +28,6 @@ package com.tencent.devops.common.webhook.service.code.handler.github import com.tencent.devops.common.api.pojo.I18Variable -import com.tencent.devops.common.api.util.DateTimeUtil -import com.tencent.devops.common.api.util.JsonUtil -import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_ACTION import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_BASE_REF @@ -135,17 +132,15 @@ class GithubPrTriggerHandler : GitHookTriggerHandler { } override fun getEventDesc(event: GithubPullRequestEvent): String { - val i18Variable = I18Variable( + return I18Variable( code = WebhookI18nConstants.GITHUB_PR_EVENT_DESC, params = listOf( - event.pullRequest.title, - event.pullRequest.url, + event.pullRequest.htmlUrl, + event.pullRequest.number.toString(), getUsername(event), - DateTimeUtil.formatMilliTime(event.pullRequest.updatedAt?.let { - DateTimeUtil.zoneDateToTimestamp(it) - } ?: LocalDateTime.now().timestampmilli())) - ) - return JsonUtil.toJson(i18Variable) + event.action + ) + ).toJsonStr() } override fun getExternalId(event: GithubPullRequestEvent): String { @@ -186,17 +181,29 @@ class GithubPrTriggerHandler : GitHookTriggerHandler { triggerOnUser = userId, includedUsers = WebhookUtils.convert(includeUsers), excludedUsers = WebhookUtils.convert(excludeUsers), - includedFailedReason = "on.push.users trigger user($userId) not match", - excludedFailedReason = "on.push.users-ignore trigger user($userId) match" + includedFailedReason = I18Variable( + code = WebhookI18nConstants.USER_NOT_MATCH, + params = listOf(getUsername(event)) + ).toJsonStr(), + excludedFailedReason = I18Variable( + code = WebhookI18nConstants.USER_IGNORED, + params = listOf(getUsername(event)) + ).toJsonStr() ) val targetBranch = getBranchName(event) val targetBranchFilter = BranchFilter( pipelineId = pipelineId, - triggerOnBranchName = getBranchName(event), + triggerOnBranchName = targetBranch, includedBranches = WebhookUtils.convert(branchName), excludedBranches = WebhookUtils.convert(excludeBranchName), - includedFailedReason = "on.mr.target-branches target branch($targetBranch) not match", - excludedFailedReason = "on.mr.target-branches-ignore target branch($targetBranch) match" + includedFailedReason = I18Variable( + code = WebhookI18nConstants.TARGET_BRANCH_NOT_MATCH, + params = listOf(targetBranch) + ).toJsonStr(), + excludedFailedReason = I18Variable( + code = WebhookI18nConstants.TARGET_BRANCH_IGNORED, + params = listOf(targetBranch) + ).toJsonStr() ) return listOf(userFilter, targetBranchFilter) } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt index af737cf50d5..6c72d2ae3ba 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt @@ -28,9 +28,6 @@ package com.tencent.devops.common.webhook.service.code.handler.github import com.tencent.devops.common.api.pojo.I18Variable -import com.tencent.devops.common.api.util.DateTimeUtil -import com.tencent.devops.common.api.util.JsonUtil -import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_ACTION import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_BEFORE_SHA @@ -57,7 +54,6 @@ import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.pojo.code.git.GitCommit import com.tencent.devops.common.webhook.pojo.code.git.GitCommitAuthor import com.tencent.devops.common.webhook.pojo.code.git.GitPushEvent -import com.tencent.devops.common.webhook.pojo.code.github.GithubPullRequestEvent import com.tencent.devops.common.webhook.pojo.code.github.GithubPushEvent import com.tencent.devops.common.webhook.service.code.filter.BranchFilter import com.tencent.devops.common.webhook.service.code.filter.UserFilter @@ -68,7 +64,6 @@ import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils import org.slf4j.LoggerFactory -import java.time.LocalDateTime @CodeWebhookHandler @Suppress("TooManyFunctions") @@ -116,16 +111,14 @@ class GithubPushTriggerHandler : GitHookTriggerHandler { } else { "https://github.com/${event.repository.fullName}/commit/${getBranchName(event)}" } - val i18Variable = I18Variable( + return I18Variable( code = WebhookI18nConstants.GITHUB_PUSH_EVENT_DESC, params = listOf( getBranchName(event), linkUrl, - getUsername(event), - DateTimeUtil.formatMilliTime(LocalDateTime.now().timestampmilli()) + getUsername(event) ) - ) - return JsonUtil.toJson(i18Variable) + ).toJsonStr() } override fun getExternalId(event: GithubPushEvent): String { @@ -154,17 +147,29 @@ class GithubPushTriggerHandler : GitHookTriggerHandler { triggerOnUser = userId, includedUsers = WebhookUtils.convert(includeUsers), excludedUsers = WebhookUtils.convert(excludeUsers), - includedFailedReason = "on.push.users trigger user($userId) not match", - excludedFailedReason = "on.push.users-ignore trigger user($userId) match" + includedFailedReason = I18Variable( + code = WebhookI18nConstants.USER_NOT_MATCH, + params = listOf(userId) + ).toJsonStr(), + excludedFailedReason = I18Variable( + code = WebhookI18nConstants.USER_IGNORED, + params = listOf(userId) + ).toJsonStr() ) val triggerOnBranchName = getBranchName(event) val branchFilter = BranchFilter( pipelineId = pipelineId, - triggerOnBranchName = getBranchName(event), + triggerOnBranchName = triggerOnBranchName, includedBranches = WebhookUtils.convert(branchName), excludedBranches = WebhookUtils.convert(excludeBranchName), - includedFailedReason = "on.push.branches branch($triggerOnBranchName) not match", - excludedFailedReason = "on.push.branches-ignore branch($triggerOnBranchName) match" + includedFailedReason = I18Variable( + code = WebhookI18nConstants.TARGET_BRANCH_NOT_MATCH, + params = listOf(triggerOnBranchName) + ).toJsonStr(), + excludedFailedReason = I18Variable( + code = WebhookI18nConstants.TARGET_BRANCH_IGNORED, + params = listOf(triggerOnBranchName) + ).toJsonStr() ) return listOf(userFilter, branchFilter) } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt index 2876cf8785d..a04af62bc68 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt @@ -28,9 +28,6 @@ package com.tencent.devops.common.webhook.service.code.handler.p4 import com.tencent.devops.common.api.pojo.I18Variable -import com.tencent.devops.common.api.util.DateTimeUtil -import com.tencent.devops.common.api.util.JsonUtil -import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.PathFilterType import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler @@ -48,7 +45,6 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilterRespon import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository -import java.time.LocalDateTime @CodeWebhookHandler @SuppressWarnings("TooManyFunctions") @@ -86,16 +82,14 @@ class P4ChangeTriggerHandler( override fun getMessage(event: P4ChangeEvent) = event.description override fun getEventDesc(event: P4ChangeEvent): String { - val i18Variable = I18Variable( - code = WebhookI18nConstants.P4_Change_EVENT_DESC, + return I18Variable( + code = WebhookI18nConstants.P4_EVENT_DESC, params = listOf( getRevision(event), - "", - getUsername(event), - DateTimeUtil.formatMilliTime(LocalDateTime.now().timestampmilli()) + event.eventType, + getUsername(event) ) - ) - return JsonUtil.toJson(i18Variable) + ).toJsonStr() } override fun getExternalId(event: P4ChangeEvent): String { @@ -164,8 +158,14 @@ class P4ChangeTriggerHandler( includedPaths = WebhookUtils.convert(includePaths), excludedPaths = WebhookUtils.convert(excludePaths), caseSensitive = caseSensitive, - includedFailedReason = "on.change-commit.paths change path($includePaths) not match", - excludedFailedReason = "on.change-commit.paths-ignore change path($excludePaths) match" + includedFailedReason = I18Variable( + code = WebhookI18nConstants.PATH_NOT_MATCH, + params = listOf() + ).toJsonStr(), + excludedFailedReason = I18Variable( + code = WebhookI18nConstants.PATH_IGNORED, + params = listOf() + ).toJsonStr() ) ).doFilter(response) } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt index 6ae0cb15fc6..39967bda35b 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt @@ -87,16 +87,14 @@ class P4ShelveTriggerHandler( override fun getMessage(event: P4ShelveEvent) = event.description override fun getEventDesc(event: P4ShelveEvent): String { - val i18Variable = I18Variable( - code = WebhookI18nConstants.P4_Shelve_EVENT_DESC, + return I18Variable( + code = WebhookI18nConstants.P4_EVENT_DESC, params = listOf( getRevision(event), - "", - getUsername(event), - DateTimeUtil.formatMilliTime(LocalDateTime.now().timestampmilli()) + event.eventType, + getUsername(event) ) - ) - return JsonUtil.toJson(i18Variable) + ).toJsonStr() } override fun getExternalId(event: P4ShelveEvent): String { @@ -161,8 +159,14 @@ class P4ShelveTriggerHandler( includedPaths = WebhookUtils.convert(includePaths), excludedPaths = WebhookUtils.convert(excludePaths), caseSensitive = caseSensitive, - includedFailedReason = "on.shelve-commit.paths change path($includePaths) not match", - excludedFailedReason = "on.shelve-commit.paths-ignore change path($excludePaths) match" + includedFailedReason = I18Variable( + code = WebhookI18nConstants.PATH_NOT_MATCH, + params = listOf() + ).toJsonStr(), + excludedFailedReason = I18Variable( + code = WebhookI18nConstants.PATH_IGNORED, + params = listOf() + ).toJsonStr() ) ).doFilter(response) } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt index ff4365897ab..681e76df2cf 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt @@ -28,9 +28,6 @@ package com.tencent.devops.common.webhook.service.code.handler.svn import com.tencent.devops.common.api.pojo.I18Variable -import com.tencent.devops.common.api.util.DateTimeUtil -import com.tencent.devops.common.api.util.JsonUtil -import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.PathFilterType import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler @@ -86,16 +83,13 @@ class SvnCommitTriggerHandler : CodeWebhookTriggerHandler { } override fun getEventDesc(event: SvnCommitEvent): String { - val i18Variable = I18Variable( + return I18Variable( code = WebhookI18nConstants.SVN_COMMIT_EVENT_DESC, params = listOf( - getBranchName(event), - "", - getUsername(event), - DateTimeUtil.formatMilliTime(LocalDateTime.now().timestampmilli()) + getRevision(event), + getUsername(event) ) - ) - return JsonUtil.toJson(i18Variable) + ).toJsonStr() } override fun getExternalId(event: SvnCommitEvent): String { @@ -121,8 +115,14 @@ class SvnCommitTriggerHandler : CodeWebhookTriggerHandler { triggerOnUser = userId, includedUsers = WebhookUtils.convert(includeUsers), excludedUsers = WebhookUtils.convert(excludeUsers), - includedFailedReason = "on.post-commit.users trigger user($userId) not match", - excludedFailedReason = "on.post-commit.users-ignore trigger user($userId) match" + includedFailedReason = I18Variable( + code = WebhookI18nConstants.USER_NOT_MATCH, + params = listOf(userId) + ).toJsonStr(), + excludedFailedReason = I18Variable( + code = WebhookI18nConstants.USER_IGNORED, + params = listOf(userId) + ).toJsonStr() ) val projectRelativePath = WebhookUtils.getRelativePath(repository.url) val pathFilter = PathFilterFactory.newPathFilter( @@ -137,8 +137,14 @@ class SvnCommitTriggerHandler : CodeWebhookTriggerHandler { ) }, includedPaths = getIncludePaths(projectRelativePath), - includedFailedReason = "on.post-commit.paths change path($includePaths) not match", - excludedFailedReason = "on.post-commit.paths-ignore change path($excludePaths) match" + includedFailedReason = I18Variable( + code = WebhookI18nConstants.PATH_NOT_MATCH, + params = listOf() + ).toJsonStr(), + excludedFailedReason = I18Variable( + code = WebhookI18nConstants.PATH_IGNORED, + params = listOf() + ).toJsonStr() ) ) return listOf(projectNameFilter, userFilter, pathFilter) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt index 52907bfebb3..1c4c05dd76c 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt @@ -28,7 +28,6 @@ package com.tencent.devops.common.webhook.service.code.handler.tgit import com.tencent.devops.common.api.pojo.I18Variable -import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_COMMIT_AUTHOR import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_EVENT @@ -128,15 +127,14 @@ class TGitIssueTriggerHandler( } override fun getEventDesc(event: GitIssueEvent): String { - val i18Variable = I18Variable( + return I18Variable( code = getI18Code(event), params = listOf( "${event.objectAttributes.url}", event.objectAttributes.iid, getUsername(event) ) - ) - return JsonUtil.toJson(i18Variable) + ).toJsonStr() } override fun getExternalId(event: GitIssueEvent): String { @@ -158,7 +156,15 @@ class TGitIssueTriggerHandler( pipelineId = pipelineId, filterName = "issueAction", triggerOn = event.objectAttributes.action ?: "", - included = WebhookUtils.convert(webHookParams.includeIssueAction) + included = WebhookUtils.convert(webHookParams.includeIssueAction), + failedReason = I18Variable( + code = WebhookI18nConstants.ISSUES_ACTION_NOT_MATCH, + params = listOf( + "${event.objectAttributes.url}", + event.objectAttributes.iid, + getUsername(event) + ) + ).toJsonStr() ) return listOf(actionFilter) } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt index 191d547d9ab..aafcc48a9d0 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt @@ -30,7 +30,6 @@ package com.tencent.devops.common.webhook.service.code.handler.tgit import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.util.DateTimeUtil -import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_ACTION import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_BASE_REF @@ -97,8 +96,6 @@ import com.tencent.devops.scm.utils.code.git.GitUtils import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired -import java.time.LocalDateTime -import java.time.format.DateTimeFormatter import java.util.Date @CodeWebhookHandler @@ -164,15 +161,14 @@ class TGitMrTriggerHandler( } override fun getEventDesc(event: GitMergeRequestEvent): String { - val i18Variable = I18Variable( + return I18Variable( code = getI18Code(event), params = listOf( "${event.object_attributes.url}", event.object_attributes.iid.toString(), getUsername(event) ) - ) - return JsonUtil.toJson(i18Variable) + ).toJsonStr() } override fun getExternalId(event: GitMergeRequestEvent): String { @@ -213,17 +209,29 @@ class TGitMrTriggerHandler( triggerOnUser = getUsername(event), includedUsers = convert(includeUsers), excludedUsers = convert(excludeUsers), - includedFailedReason = "on.mr.users trigger user($userId) not match", - excludedFailedReason = "on.mr.users-ignore trigger user($userId) match" + includedFailedReason = I18Variable( + code = WebhookI18nConstants.USER_NOT_MATCH, + params = listOf(userId) + ).toJsonStr(), + excludedFailedReason = I18Variable( + code = WebhookI18nConstants.USER_IGNORED, + params = listOf(userId) + ).toJsonStr() ) val targetBranch = getBranchName(event) val targetBranchFilter = BranchFilter( pipelineId = pipelineId, - triggerOnBranchName = getBranchName(event), + triggerOnBranchName = targetBranch, includedBranches = convert(branchName), excludedBranches = convert(excludeBranchName), - includedFailedReason = "on.mr.target-branches target branch($targetBranch) not match", - excludedFailedReason = "on.mr.target-branches-ignore target branch($targetBranch) match" + includedFailedReason = I18Variable( + code = WebhookI18nConstants.TARGET_BRANCH_NOT_MATCH, + params = listOf(targetBranch) + ).toJsonStr(), + excludedFailedReason = I18Variable( + code = WebhookI18nConstants.TARGET_BRANCH_IGNORED, + params = listOf(targetBranch) + ).toJsonStr() ) val sourceBranch = getBranch(event.object_attributes.source_branch) val sourceBranchFilter = BranchFilter( @@ -231,8 +239,14 @@ class TGitMrTriggerHandler( triggerOnBranchName = sourceBranch, includedBranches = convert(includeSourceBranchName), excludedBranches = convert(excludeSourceBranchName), - includedFailedReason = "on.mr.source-branches source branch($sourceBranch) not match", - excludedFailedReason = "on.mr.source-branches-ignore source branch($sourceBranch) match" + includedFailedReason = I18Variable( + code = WebhookI18nConstants.SOURCE_BRANCH_NOT_MATCH, + params = listOf(sourceBranch) + ).toJsonStr(), + excludedFailedReason = I18Variable( + code = WebhookI18nConstants.SOURCE_BRANCH_IGNORED, + params = listOf(sourceBranch) + ).toJsonStr() ) val skipCiFilter = SkipCiFilter( pipelineId = pipelineId, @@ -268,8 +282,14 @@ class TGitMrTriggerHandler( triggerOnPath = changeFiles, includedPaths = convert(includePaths), excludedPaths = convert(excludePaths), - includedFailedReason = "on.mr.paths change path($includePaths) not match", - excludedFailedReason = "on.mr.paths-ignore change path($excludePaths) match" + includedFailedReason = I18Variable( + code = WebhookI18nConstants.PATH_NOT_MATCH, + params = listOf() + ).toJsonStr(), + excludedFailedReason = I18Variable( + code = WebhookI18nConstants.PATH_IGNORED, + params = listOf() + ).toJsonStr() ) ).doFilter(response) } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt index 74052ee42b1..5c48ffe3430 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt @@ -28,7 +28,6 @@ package com.tencent.devops.common.webhook.service.code.handler.tgit import com.tencent.devops.common.api.pojo.I18Variable -import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_BEFORE_SHA import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_BEFORE_SHA_SHORT @@ -141,13 +140,21 @@ class TGitNoteTriggerHandler( pipelineId = pipelineId, filterName = "noteTypeAction", triggerOn = event.objectAttributes.noteableType, - included = WebhookUtils.convert(includeNoteTypes) + included = WebhookUtils.convert(includeNoteTypes), + failedReason = I18Variable( + code = WebhookI18nConstants.NOTE_ACTION_NOT_MATCH, + params = listOf() + ).toJsonStr() ) val commentActionFilter = RegexContainFilter( pipelineId = pipelineId, filterName = "noteCommentAction", triggerOn = event.objectAttributes.note, - included = WebhookUtils.convert(includeNoteComment) + included = WebhookUtils.convert(includeNoteComment), + failedReason = I18Variable( + code = WebhookI18nConstants.NOTE_CONTENT_NOT_MATCH, + params = listOf() + ).toJsonStr() ) return listOf(urlFilter, eventTypeFilter, typeActionFilter, commentActionFilter) } @@ -158,15 +165,14 @@ class TGitNoteTriggerHandler( } override fun getEventDesc(event: GitNoteEvent): String { - val i18Variable = I18Variable( + return I18Variable( code = WebhookI18nConstants.TGIT_NOTE_EVENT_DESC, params = listOf( event.objectAttributes.url, event.objectAttributes.id.toString(), getUsername(event) ) - ) - return JsonUtil.toJson(i18Variable) + ).toJsonStr() } override fun getExternalId(event: GitNoteEvent): String { diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt index fcb62c5cf95..98f8e0ee275 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt @@ -30,7 +30,6 @@ package com.tencent.devops.common.webhook.service.code.handler.tgit import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.util.DateTimeUtil -import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_ACTION import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_BEFORE_SHA @@ -41,6 +40,7 @@ import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_EVENT_URL import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_REF import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_REPO_URL import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.enums.WebhookI18nConstants.TGIT_PUSH_EVENT_DESC import com.tencent.devops.common.webhook.enums.code.tgit.TGitPushActionType import com.tencent.devops.common.webhook.enums.code.tgit.TGitPushOperationKind @@ -78,7 +78,6 @@ import com.tencent.devops.scm.utils.code.git.GitUtils import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired -import java.time.LocalDateTime import java.util.Date @CodeWebhookHandler @@ -132,7 +131,7 @@ class TGitPushTriggerHandler( } override fun getEventDesc(event: GitPushEvent): String { - val i18Variable = I18Variable( + return I18Variable( code = TGIT_PUSH_EVENT_DESC, params = listOf( getBranchName(event), @@ -140,8 +139,7 @@ class TGitPushTriggerHandler( "${event.checkout_sha}".substring(0, GitPushEvent.SHORT_COMMIT_ID_LENGTH), event.user_name ) - ) - return JsonUtil.toJson(i18Variable) + ).toJsonStr() } override fun getExternalId(event: GitPushEvent): String { @@ -178,17 +176,29 @@ class TGitPushTriggerHandler( triggerOnUser = userId, includedUsers = convert(includeUsers), excludedUsers = convert(excludeUsers), - includedFailedReason = "on.push.users trigger user($userId) not match", - excludedFailedReason = "on.push.users-ignore trigger user($userId) match" + includedFailedReason = I18Variable( + code = WebhookI18nConstants.USER_NOT_MATCH, + params = listOf(userId) + ).toJsonStr(), + excludedFailedReason = I18Variable( + code = WebhookI18nConstants.USER_IGNORED, + params = listOf(userId) + ).toJsonStr() ) val triggerOnBranchName = getBranchName(event) val branchFilter = BranchFilter( pipelineId = pipelineId, - triggerOnBranchName = getBranchName(event), + triggerOnBranchName = triggerOnBranchName, includedBranches = convert(branchName), excludedBranches = convert(excludeBranchName), - includedFailedReason = "on.push.branches branch($triggerOnBranchName) not match", - excludedFailedReason = "on.push.branches-ignore branch($triggerOnBranchName) match" + includedFailedReason = I18Variable( + code = WebhookI18nConstants.SOURCE_BRANCH_NOT_MATCH, + params = listOf(triggerOnBranchName) + ).toJsonStr(), + excludedFailedReason = I18Variable( + code = WebhookI18nConstants.SOURCE_BRANCH_IGNORED, + params = listOf(triggerOnBranchName) + ).toJsonStr() ) val skipCiFilter = SkipCiFilter( pipelineId = pipelineId, @@ -225,8 +235,14 @@ class TGitPushTriggerHandler( triggerOnPath = eventPaths.toList(), includedPaths = convert(includePaths), excludedPaths = convert(excludePaths), - includedFailedReason = "on.push.paths change path($includePaths) not match", - excludedFailedReason = "on.push.paths-ignore change path($excludePaths) match" + includedFailedReason = I18Variable( + code = WebhookI18nConstants.PATH_NOT_MATCH, + params = listOf() + ).toJsonStr(), + excludedFailedReason = I18Variable( + code = WebhookI18nConstants.PATH_IGNORED, + params = listOf() + ).toJsonStr() ) ).doFilter(response) } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt index e9df0131960..0f0454c9897 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt @@ -28,9 +28,6 @@ package com.tencent.devops.common.webhook.service.code.handler.tgit import com.tencent.devops.common.api.pojo.I18Variable -import com.tencent.devops.common.api.util.DateTimeUtil -import com.tencent.devops.common.api.util.JsonUtil -import com.tencent.devops.common.api.util.timestamp import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_COMMIT_AUTHOR import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_EVENT @@ -102,15 +99,14 @@ class TGitReviewTriggerHandler( } override fun getEventDesc(event: GitReviewEvent): String { - val i18Variable = I18Variable( + return I18Variable( code = getI18Code(event), params = listOf( "${event.repository.homepage}/reviews/${event.iid}", event.iid, getUsername(event) ) - ) - return JsonUtil.toJson(i18Variable) + ).toJsonStr() } override fun getExternalId(event: GitReviewEvent): String { @@ -227,7 +223,11 @@ class TGitReviewTriggerHandler( pipelineId = pipelineId, filterName = "crState", triggerOn = event.state, - included = WebhookUtils.convert(includeCrState) + included = WebhookUtils.convert(includeCrState), + failedReason = I18Variable( + code = WebhookI18nConstants.REVIEW_ACTION_NOT_MATCH, + params = listOf() + ).toJsonStr() ) val crTypeFilter = ContainsFilter( pipelineId = pipelineId, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt index b996c452620..a2e24b59315 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt @@ -28,7 +28,6 @@ package com.tencent.devops.common.webhook.service.code.handler.tgit import com.tencent.devops.common.api.pojo.I18Variable -import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_BEFORE_SHA import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_BEFORE_SHA_SHORT @@ -60,7 +59,6 @@ import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTrigger import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils -import java.time.LocalDateTime @CodeWebhookHandler class TGitTagPushTriggerHandler : CodeWebhookTriggerHandler { @@ -102,7 +100,7 @@ class TGitTagPushTriggerHandler : CodeWebhookTriggerHandler { } override fun getEventDesc(event: GitTagPushEvent): String { - val i18Variable = I18Variable( + return I18Variable( code = WebhookI18nConstants.TGIT_TAG_PUSH_EVENT_DESC, params = listOf( "${event.create_from}", @@ -110,8 +108,7 @@ class TGitTagPushTriggerHandler : CodeWebhookTriggerHandler { getBranchName(event), getUsername(event) ) - ) - return JsonUtil.toJson(i18Variable) + ).toJsonStr() } override fun getExternalId(event: GitTagPushEvent): String { @@ -177,8 +174,14 @@ class TGitTagPushTriggerHandler : CodeWebhookTriggerHandler { triggerOnBranchName = eventTag, includedBranches = WebhookUtils.convert(tagName), excludedBranches = WebhookUtils.convert(excludeTagName), - includedFailedReason = "on.tag.tags tag($eventTag) not match", - excludedFailedReason = "on.tag.tags-ignore tag($eventTag) match" + includedFailedReason = I18Variable( + code = WebhookI18nConstants.TAG_NAME_NOT_MATCH, + params = listOf(eventTag) + ).toJsonStr(), + excludedFailedReason = I18Variable( + code = WebhookI18nConstants.TAG_NAME_IGNORED, + params = listOf(eventTag) + ).toJsonStr() ) val userId = getUsername(event) val userFilter = UserFilter( @@ -186,20 +189,25 @@ class TGitTagPushTriggerHandler : CodeWebhookTriggerHandler { triggerOnUser = getUsername(event), includedUsers = WebhookUtils.convert(includeUsers), excludedUsers = WebhookUtils.convert(excludeUsers), - includedFailedReason = "on.tag.users trigger user($userId) not match", - excludedFailedReason = "on.tag.users-ignore trigger user($userId) match" + includedFailedReason = I18Variable( + code = WebhookI18nConstants.USER_NOT_MATCH, + params = listOf(userId) + ).toJsonStr(), + excludedFailedReason = I18Variable( + code = WebhookI18nConstants.USER_IGNORED, + params = listOf(userId) + ).toJsonStr() ) - val fromBranch = event.create_from + val fromBranch = event.create_from ?: "" val fromBranchFilter = BranchFilter( pipelineId = pipelineId, - triggerOnBranchName = event.create_from ?: "", + triggerOnBranchName = fromBranch, includedBranches = WebhookUtils.convert(fromBranches), excludedBranches = emptyList(), - includedFailedReason = if (fromBranch.isNullOrBlank()) { - "on.tag.from-branches client push tag not support from-branches" - } else { - "on.tag.from-branches tag from branch($fromBranch) not match" - }, + includedFailedReason = I18Variable( + code = WebhookI18nConstants.TAG_SOURCE_BRANCH_NOT_MATCH, + params = listOf(fromBranch) + ).toJsonStr(), excludedFailedReason = "" ) return listOf(urlFilter, eventTypeFilter, branchFilter, userFilter, fromBranchFilter) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt index 42da9b6caa8..cb8c169242f 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt @@ -30,6 +30,7 @@ package com.tencent.devops.process.api.user import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID_DEFAULT_VALUE +import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.model.SQLPage import com.tencent.devops.common.api.pojo.IdValue import com.tencent.devops.common.api.pojo.Result @@ -62,7 +63,13 @@ interface UserPipelineTriggerEventResource { @ApiOperation("获取事件类型") @GET @Path("listEventType") - fun listEventType(): Result> + fun listEventType( + @ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, + @ApiParam("代码库类型,为空则返回所有事件类型", required = true) + scmType: ScmType? + ): Result> @ApiOperation("获取流水线触发事件列表") @GET diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt index aca6cf4c27d..2f428c26028 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt @@ -28,6 +28,7 @@ package com.tencent.devops.process.api +import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.model.SQLPage import com.tencent.devops.common.api.pojo.IdValue import com.tencent.devops.common.api.pojo.Result @@ -49,13 +50,17 @@ class UserPipelineTriggerEventResourceImpl( return Result(PipelineTriggerType.toMap()) } - override fun listEventType(): Result> { - val eventTypes = CodeEventType.values().map { + override fun listEventType( + userId: String, + scmType: ScmType? + ): Result> { + val eventTypes = CodeEventType.getEventsByScmType(scmType).map { IdValue( id = it.name, value = I18nUtil.getCodeLanMessage( messageCode = "${CodeEventType.MESSAGE_CODE_PREFIX}_${it.name}", - defaultMessage = it.name + defaultMessage = it.name, + language = I18nUtil.getLanguage(userId) ) ) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/WebhookRequestReplayEvent.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/WebhookRequestReplayEvent.kt index 136f67ff689..81e5f44500f 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/WebhookRequestReplayEvent.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/WebhookRequestReplayEvent.kt @@ -29,8 +29,11 @@ package com.tencent.devops.process.webhook.pojo.event import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.event.annotation.Event +import com.tencent.devops.common.event.dispatcher.pipeline.mq.MQ import com.tencent.devops.common.event.pojo.trace.ITraceEvent +@Event(exchange = MQ.EXCHANGE_REPLAY_BUILD_REQUEST_EVENT, routeKey = MQ.ROUTE_REPLAY_BUILD_REQUEST_EVENT) data class WebhookRequestReplayEvent( val userId: String, val projectId: String, diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index 038fcd4f147..e8a6ab4cf78 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -375,3 +375,45 @@ bkTgitReviewApprovedEventDesc=Code review [{1} bkTgitReviewApprovingEventDesc=Code review [{1}] approving bkTgitReviewChangeDeniedEventDesc=Code review [{1}] change denied by {2} bkTgitReviewChangeRequiredEventDesc=Code review [{1}] change required by {2} +bkGithubPushEventDesc=[{0}] Commit [{2}] pushed by {2} +bkGithubCreateBranchEventDesc=Branch [{1}] created by {2} +bkGithubCreateTagEventDesc=Tag [{1}] pushed by {2} +bkGithubPrEventDesc=Pull request [!{1}] by {2} {3} +bkP4EventDesc=Change [{0}] {1} by {2} +bkSvnCommitEventDesc=Commit [{0}] pushed by {1} +bkManualStartEventDesc=Manually triggered by {0} +bkRemoteStartEventDesc=Remote api triggered by {0} +bkServiceStartEventDesc={0} Pipeline invocation triggered by [{2}] 调用 +bkRepoTriggerEventTypeNotMatch=Event type mismatch +bkRepoTriggerTargetBranchNotMatch=Target branch [{0}] of merge request does not match +bkRepoTriggerTargetBranchIgnored=Target branch [{0}] of merge request has been excluded +bkRepoTriggerSourceBranchNotMatch=Source branch [{0}] of merge request does not match +bkRepoTriggerSourceBranchIgnored=Source branch [{0}] of merge request has been excluded +bkRepoTriggerUserNotMatch=Trigger user [{0}] does not match +bkRepoTriggerUserIgnored=Trigger user [{0}] has been excluded +bkRepoTriggerPathNotMatch=Path does not match +bkRepoTriggerPathIgnored=Path has been excluded +bkRepoTriggerTagNameNotMatch=Tag [{0}] does not match +bkRepoTriggerTagNameIgnored=Tag [{0}] has been excluded +bkRepoTriggerTagSourceBranchNotMatch=Tag source branch does not match +bkRepoTriggerNoteContentNotMatch=Note does not match +bkRepoTriggerNoteActionNotMatch=Note type does not match +bkRepoTriggerReviewActionNotMatch=Code review type does not match +bkRepoTriggerIssueActionNotMatch=Issue action does not match +EVENT_TYPE_PUSH=Push +EVENT_TYPE_TAG_PUSH=Tag Push +EVENT_TYPE_MERGE_REQUEST=Merge Request +EVENT_TYPE_MERGE_REQUEST_ACCEPT=Merge Request Accept +EVENT_TYPE_ISSUES=Issue +EVENT_TYPE_NOTE=Note +EVENT_TYPE_REVIEW=Review +EVENT_TYPE_CREATE=Create Tag or Branch +EVENT_TYPE_PULL_REQUEST=Pull Request +EVENT_TYPE_POST_COMMIT=Post Commit +EVENT_TYPE_LOCK_COMMIT=Lock +EVENT_TYPE_PRE_COMMIT=Pre Commit +EVENT_TYPE_CHANGE_COMMIT=Change-Commit +EVENT_TYPE_CHANGE_CONTENT=Change-Content +EVENT_TYPE_CHANGE_SUBMIT=Change-Submit +EVENT_TYPE_SHELVE_COMMIT=Shelve-Commit +EVENT_TYPE_SHELVE_SUBMIT=Shelve-Submit \ No newline at end of file diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 747b3cc9936..3e8e9e57f36 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -374,4 +374,46 @@ bkTgitNoteEventDesc=评论 [{1}] 由 {1}] 由 {2} 评审通过 bkTgitReviewApprovingEventDesc=代码审查 [{1}] 评审中 bkTgitReviewChangeDeniedEventDesc=代码审查 [{1}] 被 {2} 拒绝 -bkTgitReviewChangeRequiredEventDesc=代码审查 [{1}] 由 {2} 要求修改 \ No newline at end of file +bkTgitReviewChangeRequiredEventDesc=代码审查 [{1}] 由 {2} 要求修改 +bkGithubPushEventDesc=[master] 提交 [{1}] 由 {2} 推送 +bkGithubCreateBranchEventDesc=Branch [{1}] 由 {2} 创建 +bkGithubCreateTagEventDesc=Tag [{1}] 由 {2} 推送 +bkGithubPrEventDesc=Pull request [{1}] 由 {2} {3} +bkP4EventDesc=Change {0} {1} 由 {2} +bkSvnCommitEventDesc=提交 [{0}] 由 {1} 推送 +bkManualStartEventDesc={0} 手动触发 +bkRemoteStartEventDesc={0} 远程触发 +bkServiceStartEventDesc={0} 触发的流水线 [{2}] 调用 +bkRepoTriggerEventTypeNotMatch=事件类型不满足触发条件 +bkRepoTriggerTargetBranchNotMatch=MR目标分支[{0}]不满足触发条件 +bkRepoTriggerTargetBranchIgnored=MR目标分支[{0}]被排除 +bkRepoTriggerSourceBranchNotMatch=MR源分支[{0}]不满足触发条件 +bkRepoTriggerSourceBranchIgnored=MR源分支[{0}]被排除 +bkRepoTriggerUserNotMatch=触发人[{0}]不匹配 +bkRepoTriggerUserIgnored=触发人[{0}]被排除 +bkRepoTriggerPathNotMatch=路径不满足触发条件 +bkRepoTriggerPathIgnored=路径被排除 +bkRepoTriggerTagNameNotMatch=Tag 名称[{0}]不满足触发条件 +bkRepoTriggerTagNameIgnored=Tag 名称[{0}]不满足触发条件 +bkRepoTriggerTagSourceBranchNotMatch=Tag 来源分支不满足触发条件 +bkRepoTriggerNoteContentNotMatch=评论内容不满足触发条件 +bkRepoTriggerNoteActionNotMatch=评论类型[{0}]不满足触发条件 +bkRepoTriggerReviewActionNotMatch=评审类型[{0}]不满足触发条件 +bkRepoTriggerIssueActionNotMatch=Issue 动作[{0}]不满足触发条件 +EVENT_TYPE_PUSH=推送事件 +EVENT_TYPE_TAG_PUSH=Tag 推送事件 +EVENT_TYPE_MERGE_REQUEST=合并请求事件 +EVENT_TYPE_MERGE_REQUEST_ACCEPT=合并请求已合并事件 +EVENT_TYPE_ISSUES=议题事件 +EVENT_TYPE_NOTE=评论事件 +EVENT_TYPE_REVIEW=评审事件 +EVENT_TYPE_CREATE=创建 Tag/Branch 事件 +EVENT_TYPE_PULL_REQUEST=拉取请求事件 +EVENT_TYPE_POST_COMMIT=提交后置事件 +EVENT_TYPE_LOCK_COMMIT=锁定事件 +EVENT_TYPE_PRE_COMMIT=提交前置事件 +EVENT_TYPE_CHANGE_COMMIT=Change-Commit +EVENT_TYPE_CHANGE_CONTENT=Change-Content +EVENT_TYPE_CHANGE_SUBMIT=Change-Submit +EVENT_TYPE_SHELVE_COMMIT=Shelve-Commit +EVENT_TYPE_SHELVE_SUBMIT=Shelve-Submit \ No newline at end of file From 566404ca4f1178f5cfccd317c07f25f0760d029e Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 4 Sep 2023 09:43:44 +0800 Subject: [PATCH 044/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webhook/PipelineBuildWebhookService.kt | 2 +- .../trigger/PipelineTriggerEventService.kt | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt index d5803d9ae9f..be6bfd05012 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt @@ -294,7 +294,7 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { ) if (!matchResult.reason.isNullOrBlank()) { builder.eventSource(eventSource = repo.repoHashId!!) - .reasonDetail("${element.name}-${matchResult.reason}") + .reasonDetail("${matchResult.reason}") } } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index bcd3cbac8fe..0ee541b6e67 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -28,6 +28,7 @@ package com.tencent.devops.process.trigger +import com.fasterxml.jackson.core.type.TypeReference import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.api.exception.ParamBlankException import com.tencent.devops.common.api.model.SQLPage @@ -222,7 +223,7 @@ class PipelineTriggerEventService @Autowired constructor( limit = sqlLimit.limit, offset = sqlLimit.offset ).map { - it.eventDesc = it.getI18nEventDesc(language) + it.eventDesc = it.getI18nEventDetailDesc(language) it.buildNum = it.getBuildNumUrl() it } @@ -390,6 +391,19 @@ class PipelineTriggerEventService @Autowired constructor( eventDesc } + /** + * 获取国际化构建事件详情描述 + */ + private fun PipelineTriggerEventVo.getI18nEventDetailDesc(language: String) = try { + val detailDescList = JsonUtil.to( + json = eventDesc, + typeReference = object : TypeReference>() {}) + detailDescList.joinToString(separator = "\n") { it.getCodeLanMessage(language) } + } catch (ignored: Exception) { + logger.warn("Failed to resolve repo trigger event|sourceDesc[$eventDesc]", ignored) + eventDesc + } + /** * 获取构建链接 */ From 59d86168eb20131329b3ad618bd0cb790240866a Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 4 Sep 2023 11:51:14 +0800 Subject: [PATCH 045/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/code/filter/RegexContainFilter.kt | 31 +++++++++++-------- .../trigger/PipelineTriggerEventService.kt | 24 +++++++++----- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/RegexContainFilter.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/RegexContainFilter.kt index 888d6b7befd..9576c7889f1 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/RegexContainFilter.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/RegexContainFilter.kt @@ -51,24 +51,29 @@ class RegexContainFilter( logger.info("$pipelineId|triggerOn:$triggerOn|included:$included|$filterName filter") return buildFilterFailedReason( action = { - if (included.isEmpty()) { - true - } - included.forEach { - try { - if (Pattern.compile(it).matcher(triggerOn).find()) { - true - } - } catch (e: PatternSyntaxException) { - logger.warn("($it) syntax error :$e ") - } - } - false + filterAction() }, response = response ) } + @SuppressWarnings("ReturnCount") + private fun filterAction(): Boolean { + if (included.isEmpty()) { + return true + } + included.forEach { + try { + if (Pattern.compile(it).matcher(triggerOn).find()) { + return true + } + } catch (e: PatternSyntaxException) { + logger.warn("($it) syntax error :$e ") + } + } + return false + } + private fun buildFilterFailedReason(action: () -> Boolean, response: WebhookFilterResponse): Boolean { val filterResult = action.invoke() if (!filterResult && failedReason.isNotBlank()) { diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 0ee541b6e67..02a278d72aa 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -223,8 +223,9 @@ class PipelineTriggerEventService @Autowired constructor( limit = sqlLimit.limit, offset = sqlLimit.offset ).map { - it.eventDesc = it.getI18nEventDetailDesc(language) + it.eventDesc = it.getI18nEventDesc(language) it.buildNum = it.getBuildNumUrl() + it.reasonDetailList = it.getI18nReasonDetailDesc(language) it } val count = pipelineTriggerEventDao.countTriggerEvent( @@ -394,14 +395,21 @@ class PipelineTriggerEventService @Autowired constructor( /** * 获取国际化构建事件详情描述 */ - private fun PipelineTriggerEventVo.getI18nEventDetailDesc(language: String) = try { - val detailDescList = JsonUtil.to( - json = eventDesc, - typeReference = object : TypeReference>() {}) - detailDescList.joinToString(separator = "\n") { it.getCodeLanMessage(language) } + private fun PipelineTriggerEventVo.getI18nReasonDetailDesc(language: String): List = try { + logger.info("get pipeline trigger event detail desc,source[$eventDesc]") + if (reasonDetailList.isNullOrEmpty()) { + listOf() + } else { + reasonDetailList!!.map { + JsonUtil.to( + json = it, + typeReference = object : TypeReference() {} + ).getCodeLanMessage(language) + } + } } catch (ignored: Exception) { - logger.warn("Failed to resolve repo trigger event|sourceDesc[$eventDesc]", ignored) - eventDesc + logger.warn("Failed to resolve repo trigger event detail|source[$eventDesc]", ignored) + listOf() } /** From 3cd38d6da103e57b381ad106f6a76771600171a9 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 5 Sep 2023 09:51:53 +0800 Subject: [PATCH 046/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/api/user/UserPipelineTriggerEventResource.kt | 2 +- support-files/i18n/process/message_zh_CN.properties | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt index cb8c169242f..5931120c1fb 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt @@ -67,7 +67,7 @@ interface UserPipelineTriggerEventResource { @ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE) @HeaderParam(AUTH_HEADER_USER_ID) userId: String, - @ApiParam("代码库类型,为空则返回所有事件类型", required = true) + @QueryParam("代码库类型,为空则返回所有事件类型") scmType: ScmType? ): Result> diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 3e8e9e57f36..8355a5d5fba 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -394,12 +394,12 @@ bkRepoTriggerUserIgnored=触发人[{0}]被排除 bkRepoTriggerPathNotMatch=路径不满足触发条件 bkRepoTriggerPathIgnored=路径被排除 bkRepoTriggerTagNameNotMatch=Tag 名称[{0}]不满足触发条件 -bkRepoTriggerTagNameIgnored=Tag 名称[{0}]不满足触发条件 +bkRepoTriggerTagNameIgnored=Tag 名称[{0}]被排除 bkRepoTriggerTagSourceBranchNotMatch=Tag 来源分支不满足触发条件 bkRepoTriggerNoteContentNotMatch=评论内容不满足触发条件 -bkRepoTriggerNoteActionNotMatch=评论类型[{0}]不满足触发条件 -bkRepoTriggerReviewActionNotMatch=评审类型[{0}]不满足触发条件 -bkRepoTriggerIssueActionNotMatch=Issue 动作[{0}]不满足触发条件 +bkRepoTriggerNoteActionNotMatch=评论类型不满足触发条件 +bkRepoTriggerReviewActionNotMatch=评审类型不满足触发条件 +bkRepoTriggerIssueActionNotMatch=Issue 动作不满足触发条件 EVENT_TYPE_PUSH=推送事件 EVENT_TYPE_TAG_PUSH=Tag 推送事件 EVENT_TYPE_MERGE_REQUEST=合并请求事件 From 183c7e0c08302182ab389a322528518ebb7f964e Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 6 Sep 2023 10:30:50 +0800 Subject: [PATCH 047/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/pojo/trigger/PipelineTriggerDetailBuilder.kt | 7 ++++++- support-files/i18n/process/message_en_US.properties | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetailBuilder.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetailBuilder.kt index 3ec63a19676..18d0f5ad156 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetailBuilder.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetailBuilder.kt @@ -96,7 +96,12 @@ class PipelineTriggerDetailBuilder { buildId = buildId, buildNum = buildNum, reason = reason, - reasonDetailList = reasonDetailList + reasonDetailList = if (status == PipelineTriggerStatus.SUCCEED.name) { + // 当流水线存在多个触发器关联同一代码库,其中有一个触发器触发成功,则不保存其他触发器触发失败信息 + listOf() + } else { + reasonDetailList + } ) } } diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index e8a6ab4cf78..c1ad7f22bdf 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -359,10 +359,10 @@ commonShutdownSuccessContent=【${%s}】- 【${%s}】#${%s} Execution succeed, commonShutdownFailureContent=【${%s}】- 【${%s}】#${%s} Execution failed,consume time${%s}, trigger user: ${%s}。 bkBeforePosition=Check-in- Control points can only be executed if the conditions are met. bkAfterPosition=Check-out - Subsequent plugins can only be executed if the conditions are met. -bkTgitPushEventDesc=[{0}] Commit [{2}] pushed by {3} -bkTgitIssueOpenedEventDesc=Issue [!{1}] opened by {2} -bkTgitIssueUpdatedEventDesc=Issue [!{1}] updated by {2} -bkTgitIssueClosedEventDesc=Issue [!{1}] closed by {2} +bkTgitPushEventDesc=[{0}] Commit [{2}] pushed by {3} +bkTgitIssueOpenedEventDesc=Issue [!{1}] opened by {2} +bkTgitIssueUpdatedEventDesc=Issue [!{1}] updated by {2} +bkTgitIssueClosedEventDesc=Issue [!{1}] closed by {2} bkTgitIssueReopenedEventDesc=Issue [!{1}] reopened by {2} bkTgitMrCreatedEventDesc=Merge requests [!{1}] opened by {2} bkTgitMrUpdatedEventDesc=Merge requests [!{1}] updated by {2} From 92ccded4303dfbb565cba09ed0693f08cc04183f Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 6 Sep 2023 11:23:07 +0800 Subject: [PATCH 048/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/pojo/trigger/PipelineTriggerDetailBuilder.kt | 7 +------ .../process/service/webhook/PipelineBuildWebhookService.kt | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetailBuilder.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetailBuilder.kt index 18d0f5ad156..3ec63a19676 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetailBuilder.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerDetailBuilder.kt @@ -96,12 +96,7 @@ class PipelineTriggerDetailBuilder { buildId = buildId, buildNum = buildNum, reason = reason, - reasonDetailList = if (status == PipelineTriggerStatus.SUCCEED.name) { - // 当流水线存在多个触发器关联同一代码库,其中有一个触发器触发成功,则不保存其他触发器触发失败信息 - listOf() - } else { - reasonDetailList - } + reasonDetailList = reasonDetailList ) } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt index be6bfd05012..1dc4912bd89 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt @@ -294,7 +294,7 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { ) if (!matchResult.reason.isNullOrBlank()) { builder.eventSource(eventSource = repo.repoHashId!!) - .reasonDetail("${matchResult.reason}") + .reasonDetail("|${element.name}|${matchResult.reason}") } } } From f18432db9b774390aeb7a424121e305a80c16378 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 6 Sep 2023 11:50:12 +0800 Subject: [PATCH 049/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trigger/PipelineTriggerReasonDetail.kt | 44 +++++++++++++++++++ .../webhook/PipelineBuildWebhookService.kt | 10 ++++- .../trigger/PipelineTriggerEventService.kt | 9 +++- 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerReasonDetail.kt diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerReasonDetail.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerReasonDetail.kt new file mode 100644 index 00000000000..08916fcbb0f --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerReasonDetail.kt @@ -0,0 +1,44 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.pojo.trigger + +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty + +@ApiModel("流水线触发原因详情") +data class PipelineTriggerReasonDetail( + @ApiModelProperty("触发插件ID") + val elementId: String?, + @ApiModelProperty("触发插件Code") + val elementAtomCode: String, + @ApiModelProperty("触发插件名称") + val elementName: String, + @ApiModelProperty("触发原因,JSON字符串,便于国际化") + val reasonMsg: String +) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt index 1dc4912bd89..1022c4d6ea5 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt @@ -53,6 +53,7 @@ import com.tencent.devops.process.pojo.code.WebhookCommit import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent import com.tencent.devops.process.pojo.trigger.PipelineTriggerDetailBuilder import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason +import com.tencent.devops.process.pojo.trigger.PipelineTriggerReasonDetail import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber import com.tencent.devops.process.service.builds.PipelineBuildCommitService @@ -294,7 +295,14 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { ) if (!matchResult.reason.isNullOrBlank()) { builder.eventSource(eventSource = repo.repoHashId!!) - .reasonDetail("|${element.name}|${matchResult.reason}") + .reasonDetail(JsonUtil.toJson( + PipelineTriggerReasonDetail( + elementId = element.id, + elementName = element.name, + elementAtomCode = element.getAtomCode(), + reasonMsg = matchResult.reason!! + ) + )) } } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 02a278d72aa..3811006d12c 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -49,6 +49,7 @@ import com.tencent.devops.process.pojo.BuildId import com.tencent.devops.process.pojo.trigger.PipelineTriggerDetail import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventVo +import com.tencent.devops.process.pojo.trigger.PipelineTriggerReasonDetail import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.pojo.trigger.PipelineTriggerType import com.tencent.devops.process.pojo.trigger.RepoTriggerEventVo @@ -401,10 +402,14 @@ class PipelineTriggerEventService @Autowired constructor( listOf() } else { reasonDetailList!!.map { - JsonUtil.to( - json = it, + val reasonDetail = JsonUtil.to(it, PipelineTriggerReasonDetail::class.java) + // 国际化触发失败原因 + val i18nReason = JsonUtil.to( + json = reasonDetail.reasonMsg, typeReference = object : TypeReference() {} ).getCodeLanMessage(language) + // 详情格式: |{{触发器名称}}|{{国际化后的触发失败原因}} + "|${reasonDetail.elementName}|${i18nReason}" } } } catch (ignored: Exception) { From 795e59a287a9c255e3ca3fc66bca8b67200ea906 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 6 Sep 2023 14:18:07 +0800 Subject: [PATCH 050/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/trigger/PipelineTriggerEventService.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 3811006d12c..5a92b5e01b3 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -408,8 +408,8 @@ class PipelineTriggerEventService @Autowired constructor( json = reasonDetail.reasonMsg, typeReference = object : TypeReference() {} ).getCodeLanMessage(language) - // 详情格式: |{{触发器名称}}|{{国际化后的触发失败原因}} - "|${reasonDetail.elementName}|${i18nReason}" + // 详情格式: {{触发器名称}}|{{国际化后的触发失败原因}} + "${reasonDetail.elementName} | $i18nReason" } } } catch (ignored: Exception) { From 6e13fb1a7804864d079ed2f594dc15d267d8f8b1 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 14 Sep 2023 14:46:18 +0800 Subject: [PATCH 051/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/api/user/UserPipelineTriggerEventResource.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt index 5931120c1fb..682f6914686 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt @@ -67,7 +67,8 @@ interface UserPipelineTriggerEventResource { @ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE) @HeaderParam(AUTH_HEADER_USER_ID) userId: String, - @QueryParam("代码库类型,为空则返回所有事件类型") + @ApiParam("代码库类型,为空则返回所有事件类型", required = false) + @QueryParam("scmType") scmType: ScmType? ): Result> From 13c3f3dceee7502d309e20f1d3ddb8f8d4d85294 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 20 Sep 2023 11:39:09 +0800 Subject: [PATCH 052/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tencent/devops/common/api/pojo/I18Variable.kt | 4 ++-- .../pipeline/pojo/element/trigger/enums/CodeEventType.kt | 2 +- .../tencent/devops/common/webhook/pojo/WebhookRequest.kt | 6 +++--- .../devops/common/webhook/pojo/code/git/GitReviewEvent.kt | 2 +- .../devops/common/webhook/pojo/code/svn/SvnCommitEvent.kt | 1 - .../common/webhook/service/code/filter/PathPrefixFilter.kt | 2 +- .../common/webhook/service/code/filter/PathStreamFilter.kt | 2 +- .../service/code/handler/CodeWebhookTriggerHandler.kt | 1 - .../service/code/handler/github/GithubPrTriggerHandler.kt | 1 - .../service/code/handler/p4/P4ShelveTriggerHandler.kt | 4 ---- .../service/code/handler/svn/SvnCommitTriggerHandler.kt | 1 - .../webhook/service/code/matcher/ScmWebhookMatcher.kt | 1 - .../process/api/user/UserPipelineTriggerEventResource.kt | 2 +- .../devops/process/pojo/trigger/PipelineTriggerEvent.kt | 2 +- .../tencent/devops/process/engine/dao/PipelineWebhookDao.kt | 4 ++-- .../process/api/UserPipelineTriggerEventResourceImpl.kt | 3 ++- .../devops/process/engine/service/PipelineWebhookService.kt | 6 +++--- .../devops/process/trigger/PipelineTriggerEventService.kt | 2 +- .../devops/process/webhook/listener/WebhookEventListener.kt | 2 +- .../process/webhook/pojo/event/WebhookRequestReplayEvent.kt | 2 +- .../devops/repository/pojo/RepositoryWebhookRequest.kt | 2 +- 21 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/pojo/I18Variable.kt b/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/pojo/I18Variable.kt index a3d3fe471b3..2af7d8e2c08 100644 --- a/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/pojo/I18Variable.kt +++ b/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/pojo/I18Variable.kt @@ -40,6 +40,6 @@ data class I18Variable( val params: List, @ApiModelProperty("默认信息") val defaultMessage: String? = null -){ - fun toJsonStr() = JsonUtil.toJson(this,false) +) { + fun toJsonStr() = JsonUtil.toJson(this, false) } \ No newline at end of file diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/enums/CodeEventType.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/enums/CodeEventType.kt index 7304da83ad2..83cf199cc26 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/enums/CodeEventType.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/enums/CodeEventType.kt @@ -118,7 +118,7 @@ enum class CodeEventType { LOCK_COMMIT ) - fun getEventsByScmType(scmType: ScmType?):List = when(scmType){ + fun getEventsByScmType(scmType: ScmType?): List = when (scmType) { ScmType.CODE_GIT -> CODE_GIT_EVENTS ScmType.CODE_TGIT -> CODE_TGIT_EVENTS ScmType.GITHUB -> CODE_GITHUB_EVENTS diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequest.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequest.kt index a0e9d7a60c3..281289b675c 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequest.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/WebhookRequest.kt @@ -29,7 +29,7 @@ package com.tencent.devops.common.webhook.pojo data class WebhookRequest( - val headers: Map? = null, - val queryParams: Map? = null, - val body: String + val headers: Map? = null, + val queryParams: Map? = null, + val body: String ) diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitReviewEvent.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitReviewEvent.kt index 8da55f58949..802cc7284d3 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitReviewEvent.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitReviewEvent.kt @@ -59,7 +59,7 @@ data class GitReviewEvent( @JsonProperty("created_at") val createdAt: String, @JsonProperty("updated_at") - val updatedAt: String, + val updatedAt: String ) : GitEvent() { companion object { const val classType = "review" diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/svn/SvnCommitEvent.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/svn/SvnCommitEvent.kt index 198f2890b20..fa542d74ad4 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/svn/SvnCommitEvent.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/svn/SvnCommitEvent.kt @@ -29,7 +29,6 @@ package com.tencent.devops.common.webhook.pojo.code.svn import com.fasterxml.jackson.annotation.JsonIgnoreProperties import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent -import com.tencent.devops.common.webhook.pojo.code.git.GitCommitRepository @Suppress("ALL") @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathPrefixFilter.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathPrefixFilter.kt index 98cd6857d4b..2cc1c6e0e0e 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathPrefixFilter.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathPrefixFilter.kt @@ -35,7 +35,7 @@ class PathPrefixFilter( // 包含过滤失败原因 private val includedFailedReason: String = "", // 排除过滤失败原因 - private val excludedFailedReason: String = "", + private val excludedFailedReason: String = "" ) : BasePathFilter( pipelineId = pipelineId, triggerOnPath = triggerOnPath, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathStreamFilter.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathStreamFilter.kt index 77e5d97fe60..3d6c101ba40 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathStreamFilter.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathStreamFilter.kt @@ -16,7 +16,7 @@ class PathStreamFilter( // 包含过滤失败原因 private val includedFailedReason: String = "", // 排除过滤失败原因 - private val excludedFailedReason: String = "", + private val excludedFailedReason: String = "" ) : BasePathFilter( pipelineId = pipelineId, triggerOnPath = triggerOnPath, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt index 0eef601bb25..e84118bc7a4 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt @@ -27,7 +27,6 @@ package com.tencent.devops.common.webhook.service.code.handler -import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent import com.tencent.devops.common.webhook.pojo.code.WebHookParams diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt index 13e6c373203..abd224e6ea7 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt @@ -89,7 +89,6 @@ import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils import org.slf4j.LoggerFactory -import java.time.LocalDateTime @CodeWebhookHandler @SuppressWarnings("TooManyFunctions") diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt index 39967bda35b..b95ce6f8d74 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt @@ -28,9 +28,6 @@ package com.tencent.devops.common.webhook.service.code.handler.p4 import com.tencent.devops.common.api.pojo.I18Variable -import com.tencent.devops.common.api.util.DateTimeUtil -import com.tencent.devops.common.api.util.JsonUtil -import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.client.Client import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.PathFilterType @@ -49,7 +46,6 @@ import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTrigger import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.api.ServiceP4Resource import com.tencent.devops.repository.pojo.Repository -import java.time.LocalDateTime @CodeWebhookHandler @SuppressWarnings("TooManyFunctions") diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt index 681e76df2cf..c13f1b29601 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt @@ -45,7 +45,6 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository -import java.time.LocalDateTime @CodeWebhookHandler @SuppressWarnings("TooManyFunctions") diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt index 87231b73df9..718fbae741e 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt @@ -29,7 +29,6 @@ package com.tencent.devops.common.webhook.service.code.matcher import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeType -import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.repository.pojo.Repository diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt index 682f6914686..eb7b67fb1a2 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt @@ -171,7 +171,7 @@ interface UserPipelineTriggerEventResource { page: Int?, @ApiParam("每页多少条", required = false, defaultValue = "20") @QueryParam("pageSize") - pageSize: Int?, + pageSize: Int? ): Result> @ApiOperation("重新触发") diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt index fc3f1c921cb..16177d9a348 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt @@ -53,5 +53,5 @@ data class PipelineTriggerEvent( @ApiModelProperty("事件请求参数, 记录手动/openapi/定时/远程触发启动参数") val requestParams: Map? = null, @ApiModelProperty("触发事件") - val eventTime: LocalDateTime, + val eventTime: LocalDateTime ) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt index 95f9a89dce1..87b76c3d109 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt @@ -236,7 +236,7 @@ class PipelineWebhookDao { repositoryType: String?, offset: Int, limit: Int - ):Result{ + ): Result { return with(T_PIPELINE_WEBHOOK) { val conditions = mutableListOf( DELETE.eq(false) @@ -253,7 +253,7 @@ class PipelineWebhookDao { fun updateWebhookEventInfo( dslContext: DSLContext, - repoHashId:String?, + repoHashId: String?, eventType: String, externalId: String, pipelineId: String, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt index 2f428c26028..c317d01858a 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt @@ -148,7 +148,8 @@ class UserPipelineTriggerEventResourceImpl( override fun replay( userId: String, - projectId: String, detailId: Long + projectId: String, + detailId: Long ): Result { return Result( pipelineTriggerEventService.replay( diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index b01d325493e..1f65639ea38 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -678,7 +678,7 @@ class PipelineWebhookService @Autowired constructor( } } - private fun updateWebhookEventInfoTask(){ + private fun updateWebhookEventInfoTask() { var offset = 0 val limit = 1000 do { @@ -690,7 +690,7 @@ class PipelineWebhookService @Autowired constructor( ) val repoSize = webhookList.size webhookList.forEach { - with(it){ + with(it) { val repositoryInfo = scmProxyService.getRepo( it.projectId, RepositoryConfig( @@ -709,7 +709,7 @@ class PipelineWebhookService @Autowired constructor( param.id to param.defaultValue.toString() } val elements = triggerContainer.elements.filterIsInstance() - elements.forEach elements@ { element -> + elements.forEach elements@{ element -> run { val webhookElementParams = getElementRepositoryConfig(element, variable = params) ?: return@elements diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 5a92b5e01b3..09322caeccc 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -252,7 +252,7 @@ class PipelineTriggerEventService @Autowired constructor( errorCode = ERROR_TRIGGER_DETAIL_NOT_FOUND, params = arrayOf(detailId.toString()) ) - val pipelineId = triggerDetail.pipelineId ?: throw ErrorCodeException( + val pipelineId = triggerDetail.pipelineId ?: throw ErrorCodeException( errorCode = ERROR_TRIGGER_REPLAY_PIPELINE_NOT_EMPTY, params = arrayOf(detailId.toString()) ) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt index f27ff38ac28..0b84f8750c5 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt @@ -77,7 +77,7 @@ class WebhookEventListener constructor( CommitEventType.GIT -> { val request = WebhookRequest( headers = mapOf( - "X-Event" to event.event!!, + "X-Event" to event.event!! ), body = event.requestContent ) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/WebhookRequestReplayEvent.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/WebhookRequestReplayEvent.kt index 81e5f44500f..1b063e65f73 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/WebhookRequestReplayEvent.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/WebhookRequestReplayEvent.kt @@ -40,4 +40,4 @@ data class WebhookRequestReplayEvent( val hookRequestId: Long, val scmType: ScmType, val pipelineId: String? = null -): ITraceEvent() +) : ITraceEvent() diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepositoryWebhookRequest.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepositoryWebhookRequest.kt index 84abaaf63e7..47474beac97 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepositoryWebhookRequest.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepositoryWebhookRequest.kt @@ -21,7 +21,7 @@ data class RepositoryWebhookRequest( @ApiModelProperty("请求头") val requestHeader: Map? = null, @ApiModelProperty("请求参数") - val requestParam:Map? = null, + val requestParam: Map? = null, @ApiModelProperty("请求体") val requestBody: String, @ApiModelProperty("事件时间") From 92926cb9dbf9f07df0639500b6de53ab31eaceac Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 20 Sep 2023 11:58:30 +0800 Subject: [PATCH 053/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/webhook/listener/WebhookEventListener.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt index 0b84f8750c5..a07298e70c0 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt @@ -98,7 +98,7 @@ class WebhookEventListener constructor( CommitEventType.TGIT -> { val request = WebhookRequest( headers = mapOf( - "X-Event" to event.event!!, + "X-Event" to event.event!! ), body = event.requestContent ) From f7314c0ea433e889cb2c282ac2957916b982df4a Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 20 Sep 2023 15:35:53 +0800 Subject: [PATCH 054/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/common/webhook/enums/WebhookI18nConstants.kt | 1 + .../devops/common/webhook/pojo/code/git/GitReviewEvent.kt | 1 + .../service/code/handler/tgit/TGitIssueTriggerHandler.kt | 6 +++++- .../service/code/handler/tgit/TGitReviewTriggerHandler.kt | 1 + support-files/i18n/process/message_en_US.properties | 1 + support-files/i18n/process/message_zh_CN.properties | 1 + .../sql/5001_init_dml/5001_ci_project-init_dml_mysql.sql | 1 + 7 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt index 77ece950196..92471ad4ddc 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt @@ -46,6 +46,7 @@ object WebhookI18nConstants { const val TGIT_REVIEW_APPROVING_EVENT_DESC = "bkTgitReviewApprovingEventDesc" const val TGIT_REVIEW_CHANGE_DENIED_EVENT_DESC = "bkTgitReviewChangeDeniedEventDesc" const val TGIT_REVIEW_CHANGE_REQUIRED_EVENT_DESC = "bkTgitReviewChangeRequiredEventDesc" + const val TGIT_REVIEW_CREATED_EVENT_DESC = "bkTgitReviewCreatedEventDesc" const val TGIT_TAG_PUSH_EVENT_DESC = "bkTgitTagPushEventDesc" // Github事件描述 diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitReviewEvent.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitReviewEvent.kt index 802cc7284d3..99d61480f9d 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitReviewEvent.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/pojo/code/git/GitReviewEvent.kt @@ -67,6 +67,7 @@ data class GitReviewEvent( const val ACTION_APPROVING = "approving" const val ACTION_CHANGE_DENIED = "change_denied" const val ACTION_CHANGE_REQUIRED = "change_required" + const val ACTION_EMPTY = "empty" } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt index 1c4c05dd76c..47a23365f96 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt @@ -116,7 +116,11 @@ class TGitIssueTriggerHandler( pipelineId = pipelineId, filterName = "issueAction", triggerOn = event.objectAttributes.action ?: "", - included = WebhookUtils.convert(includeIssueAction) + included = WebhookUtils.convert(includeIssueAction), + failedReason = I18Variable( + code = WebhookI18nConstants.ISSUES_ACTION_NOT_MATCH, + params = listOf() + ).toJsonStr() ) return listOf(urlFilter, eventTypeFilter, actionFilter) } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt index 0f0454c9897..13fe5c6452d 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt @@ -244,6 +244,7 @@ class TGitReviewTriggerHandler( GitReviewEvent.ACTION_APPROVING -> WebhookI18nConstants.TGIT_REVIEW_APPROVING_EVENT_DESC GitReviewEvent.ACTION_CHANGE_DENIED -> WebhookI18nConstants.TGIT_REVIEW_CHANGE_DENIED_EVENT_DESC GitReviewEvent.ACTION_CHANGE_REQUIRED -> WebhookI18nConstants.TGIT_REVIEW_CHANGE_REQUIRED_EVENT_DESC + GitReviewEvent.ACTION_EMPTY -> WebhookI18nConstants.TGIT_REVIEW_CREATED_EVENT_DESC else -> "" } } diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index c1ad7f22bdf..dc56e57c85b 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -371,6 +371,7 @@ bkTgitMrReopenedEventDesc=Merge requests [!{1} bkTgitMrPushUpdatedEventDesc=Merge requests [!{1}] push updated by {2} bkTgitTagPushEventDesc=[{0}]Tag [{2}] pushed by {3} bkTgitNoteEventDesc=Note [{1}] submitted by {2} +bkTgitReviewCreatedEventDesc=Code review [{1}] created by {2} bkTgitReviewApprovedEventDesc=Code review [{1}] approved by {2} bkTgitReviewApprovingEventDesc=Code review [{1}] approving bkTgitReviewChangeDeniedEventDesc=Code review [{1}] change denied by {2} diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 8355a5d5fba..8c7ee500e24 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -371,6 +371,7 @@ bkTgitMrReopenedEventDesc=合并请求 [!{1}] bkTgitMrPushUpdatedEventDesc=合并请求 [!{1}] 由 {2} 在源分支提交代码触发 bkTgitTagPushEventDesc=[{0}] 创建Tag [{2}] 由 {3} 推送 bkTgitNoteEventDesc=评论 [{1}] 由 {2} 发表 +bkTgitReviewCreatedEventDesc=代码审查 [{1}] 由 {2} 创建 bkTgitReviewApprovedEventDesc=代码审查 [{1}] 由 {2} 评审通过 bkTgitReviewApprovingEventDesc=代码审查 [{1}] 评审中 bkTgitReviewChangeDeniedEventDesc=代码审查 [{1}] 被 {2} 拒绝 diff --git a/support-files/sql/5001_init_dml/5001_ci_project-init_dml_mysql.sql b/support-files/sql/5001_init_dml/5001_ci_project-init_dml_mysql.sql index 379794436a7..f5df44fbc91 100755 --- a/support-files/sql/5001_init_dml/5001_ci_project-init_dml_mysql.sql +++ b/support-files/sql/5001_init_dml/5001_ci_project-init_dml_mysql.sql @@ -50,6 +50,7 @@ REPLACE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ( REPLACE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ('ATOM_MONITOR_DATA_DAILY', 1, 100, '插件每日监控数据ID管理'); INSERT IGNORE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ('PIPELINE_WEBHOOK_EVENT', 1, 2000, '流水线webhook事件'); INSERT IGNORE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ('PIPELINE_TRIGGER_EVENT', 1, 2000, '流水线触发事件'); +INSERT IGNORE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ('PIPELINE_TRIGGER_DETAIL', 1, 2000, '流水线触发详情'); REPLACE INTO `T_I18N_MESSAGE` (`ID`, `MODULE_CODE`, `LANGUAGE`, `KEY`, `VALUE`, `CREATOR`, `MODIFIER`, `UPDATE_TIME`, `CREATE_TIME`) VALUES('12cfe76hgu9cn4047bfd4e6ddd0aaada', 'STORE', 'zh_CN', 'reason.e20897c838564d61b5af1a8c9c1d26d2.content', '只是试用下', 'system', 'system', '2023-06-26 10:59:20.561', '2023-06-26 10:59:47'); REPLACE INTO `T_I18N_MESSAGE` (`ID`, `MODULE_CODE`, `LANGUAGE`, `KEY`, `VALUE`, `CREATOR`, `MODIFIER`, `UPDATE_TIME`, `CREATE_TIME`) VALUES('13312a05cxt1468088bdb71637sc14ds', 'STORE', 'en_US', 'reason.e20897c838564d61b5af1a8c9c1d26d2.content', 'Just trying it out.', 'system', 'system', '2023-06-26 10:59:20.561', '2023-06-26 10:59:47'); From 25fc21088a64194104cd59bb9d87c5e88bca3253 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 21 Sep 2023 17:31:16 +0800 Subject: [PATCH 055/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tencent/devops/common/webhook/enums/WebhookI18nConstants.kt | 2 +- support-files/i18n/process/message_en_US.properties | 1 + support-files/i18n/process/message_zh_CN.properties | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt index 92471ad4ddc..40d7993a8e1 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt @@ -40,7 +40,7 @@ object WebhookI18nConstants { const val TGIT_MR_CLOSED_EVENT_DESC = "bkTgitMrClosedEventDesc" const val TGIT_MR_REOPENED_EVENT_DESC = "bkTgitMrReopenedEventDesc" const val TGIT_MR_PUSH_UPDATED_EVENT_DESC = "bkTgitMrPushUpdatedEventDesc" - const val TGIT_MR_MERGED_EVENT_DESC = "bkTgitMrCreateEventDesc" + const val TGIT_MR_MERGED_EVENT_DESC = "bkTgitMrMergedEventDesc" const val TGIT_NOTE_EVENT_DESC = "bkTgitNoteEventDesc" const val TGIT_REVIEW_APPROVED_EVENT_DESC = "bkTgitReviewApprovedEventDesc" const val TGIT_REVIEW_APPROVING_EVENT_DESC = "bkTgitReviewApprovingEventDesc" diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index dc56e57c85b..2146c875696 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -369,6 +369,7 @@ bkTgitMrUpdatedEventDesc=Merge requests [!{1}] bkTgitMrClosedEventDesc=Merge requests [!{1}] closed by {2} bkTgitMrReopenedEventDesc=Merge requests [!{1}] reopened by {2} bkTgitMrPushUpdatedEventDesc=Merge requests [!{1}] push updated by {2} +bkTgitMrMergedEventDesc=Merge requests [!{1}] merged by {2} bkTgitTagPushEventDesc=[{0}]Tag [{2}] pushed by {3} bkTgitNoteEventDesc=Note [{1}] submitted by {2} bkTgitReviewCreatedEventDesc=Code review [{1}] created by {2} diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 8c7ee500e24..17ba958cb47 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -369,6 +369,7 @@ bkTgitMrUpdatedEventDesc=合并请求 [!{1}] bkTgitMrClosedEventDesc=合并请求 [!{1}] 由 {2} 关闭 bkTgitMrReopenedEventDesc=合并请求 [!{1}] 由 {2} 重新打开 bkTgitMrPushUpdatedEventDesc=合并请求 [!{1}] 由 {2} 在源分支提交代码触发 +bkTgitMrMergedEventDesc=合并请求 [!{1}] 由 {2} 合并 bkTgitTagPushEventDesc=[{0}] 创建Tag [{2}] 由 {3} 推送 bkTgitNoteEventDesc=评论 [{1}] 由 {2} 发表 bkTgitReviewCreatedEventDesc=代码审查 [{1}] 由 {2} 创建 From e9dd7ff7dd446a213b0c021bcb0da8b6d83809c0 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 26 Sep 2023 14:48:18 +0800 Subject: [PATCH 056/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../code/handler/github/GithubPushTriggerHandler.kt | 8 ++++++++ .../service/code/handler/p4/P4ChangeTriggerHandler.kt | 9 ++++++++- .../service/code/handler/p4/P4ShelveTriggerHandler.kt | 10 +++++++++- .../code/handler/tgit/TGitTagPushTriggerHandler.kt | 8 +++++++- support-files/i18n/process/message_en_US.properties | 2 +- support-files/i18n/process/message_zh_CN.properties | 2 +- 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt index 6c72d2ae3ba..c7bda4991a8 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt @@ -53,6 +53,7 @@ import com.tencent.devops.common.webhook.pojo.code.DELETE_EVENT import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.pojo.code.git.GitCommit import com.tencent.devops.common.webhook.pojo.code.git.GitCommitAuthor +import com.tencent.devops.common.webhook.pojo.code.git.GitEvent import com.tencent.devops.common.webhook.pojo.code.git.GitPushEvent import com.tencent.devops.common.webhook.pojo.code.github.GithubPushEvent import com.tencent.devops.common.webhook.service.code.filter.BranchFilter @@ -111,11 +112,18 @@ class GithubPushTriggerHandler : GitHookTriggerHandler { } else { "https://github.com/${event.repository.fullName}/commit/${getBranchName(event)}" } + val revision = getRevision(event) + val commitId = if (revision.isNotBlank()) { + revision.substring(0, GitPushEvent.SHORT_COMMIT_ID_LENGTH) + } else { + revision + } return I18Variable( code = WebhookI18nConstants.GITHUB_PUSH_EVENT_DESC, params = listOf( getBranchName(event), linkUrl, + commitId, getUsername(event) ) ).toJsonStr() diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt index a04af62bc68..a3a52bb8f3a 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt @@ -86,7 +86,7 @@ class P4ChangeTriggerHandler( code = WebhookI18nConstants.P4_EVENT_DESC, params = listOf( getRevision(event), - event.eventType, + getFormatEventType(event), getUsername(event) ) ).toJsonStr() @@ -183,4 +183,11 @@ class P4ChangeTriggerHandler( startParams[BK_REPO_P4_WEBHOOK_CHANGE] = event.change return startParams } + + private fun getFormatEventType(event: P4ChangeEvent) = when (event.eventType) { + CodeEventType.CHANGE_COMMIT.name -> P4ChangeEvent.CHANGE_COMMIT + CodeEventType.CHANGE_SUBMIT.name -> P4ChangeEvent.CHANGE_SUBMIT + CodeEventType.CHANGE_CONTENT.name -> P4ChangeEvent.CHANGE_CONTENT + else -> event.eventType + } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt index b95ce6f8d74..5fbf4d1b601 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt @@ -36,6 +36,7 @@ import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.pojo.code.BK_REPO_P4_WEBHOOK_CHANGE import com.tencent.devops.common.webhook.pojo.code.PathFilterConfig import com.tencent.devops.common.webhook.pojo.code.WebHookParams +import com.tencent.devops.common.webhook.pojo.code.p4.P4ChangeEvent import com.tencent.devops.common.webhook.pojo.code.p4.P4ShelveEvent import com.tencent.devops.common.webhook.service.code.filter.EventTypeFilter import com.tencent.devops.common.webhook.service.code.filter.P4PortFilter @@ -87,7 +88,7 @@ class P4ShelveTriggerHandler( code = WebhookI18nConstants.P4_EVENT_DESC, params = listOf( getRevision(event), - event.eventType, + getFormatEventType(event), getUsername(event) ) ).toJsonStr() @@ -180,4 +181,11 @@ class P4ShelveTriggerHandler( startParams[BK_REPO_P4_WEBHOOK_CHANGE] = event.change return startParams } + + private fun getFormatEventType(event: P4ShelveEvent) = when (event.eventType) { + CodeEventType.SHELVE_COMMIT.name -> P4ShelveEvent.SHELVE_COMMIT + CodeEventType.SHELVE_SUBMIT.name -> P4ShelveEvent.SHELVE_SUBMIT + CodeEventType.SHELVE_DELETE.name -> P4ShelveEvent.SHELVE_DELETE + else -> event.eventType + } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt index a2e24b59315..b45fc9c58f3 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt @@ -48,6 +48,7 @@ import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_TAG_USERN import com.tencent.devops.common.webhook.pojo.code.CI_BRANCH import com.tencent.devops.common.webhook.pojo.code.DELETE_EVENT import com.tencent.devops.common.webhook.pojo.code.WebHookParams +import com.tencent.devops.common.webhook.pojo.code.git.GitPushEvent import com.tencent.devops.common.webhook.pojo.code.git.GitTagPushEvent import com.tencent.devops.common.webhook.pojo.code.git.isDeleteTag import com.tencent.devops.common.webhook.service.code.filter.BranchFilter @@ -100,10 +101,15 @@ class TGitTagPushTriggerHandler : CodeWebhookTriggerHandler { } override fun getEventDesc(event: GitTagPushEvent): String { + val createFrom = if (event.create_from.isNullOrBlank()) { + event.checkout_sha?.substring(0, GitPushEvent.SHORT_COMMIT_ID_LENGTH) + } else { + event.create_from + } return I18Variable( code = WebhookI18nConstants.TGIT_TAG_PUSH_EVENT_DESC, params = listOf( - "${event.create_from}", + "$createFrom", "${event.repository.homepage}/-/tags/${getBranchName(event)}", getBranchName(event), getUsername(event) diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index 2146c875696..0cc97c37b71 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -377,7 +377,7 @@ bkTgitReviewApprovedEventDesc=Code review [{1} bkTgitReviewApprovingEventDesc=Code review [{1}] approving bkTgitReviewChangeDeniedEventDesc=Code review [{1}] change denied by {2} bkTgitReviewChangeRequiredEventDesc=Code review [{1}] change required by {2} -bkGithubPushEventDesc=[{0}] Commit [{2}] pushed by {2} +bkGithubPushEventDesc=[{0}] Commit [{2}] pushed by {3} bkGithubCreateBranchEventDesc=Branch [{1}] created by {2} bkGithubCreateTagEventDesc=Tag [{1}] pushed by {2} bkGithubPrEventDesc=Pull request [!{1}] by {2} {3} diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 17ba958cb47..41ba3b7e7d2 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -377,7 +377,7 @@ bkTgitReviewApprovedEventDesc=代码审查 [{1}{1}] 评审中 bkTgitReviewChangeDeniedEventDesc=代码审查 [{1}] 被 {2} 拒绝 bkTgitReviewChangeRequiredEventDesc=代码审查 [{1}] 由 {2} 要求修改 -bkGithubPushEventDesc=[master] 提交 [{1}] 由 {2} 推送 +bkGithubPushEventDesc=[{0}] 提交 [{2}] 由 {3} 推送 bkGithubCreateBranchEventDesc=Branch [{1}] 由 {2} 创建 bkGithubCreateTagEventDesc=Tag [{1}] 由 {2} 推送 bkGithubPrEventDesc=Pull request [{1}] 由 {2} {3} From 7e305f329479b9b774c2eaefcc2d159c79593067 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 26 Sep 2023 16:27:18 +0800 Subject: [PATCH 057/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/code/handler/github/GithubPushTriggerHandler.kt | 1 - .../webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt | 1 - 2 files changed, 2 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt index c7bda4991a8..5d31becdac4 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt @@ -53,7 +53,6 @@ import com.tencent.devops.common.webhook.pojo.code.DELETE_EVENT import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.pojo.code.git.GitCommit import com.tencent.devops.common.webhook.pojo.code.git.GitCommitAuthor -import com.tencent.devops.common.webhook.pojo.code.git.GitEvent import com.tencent.devops.common.webhook.pojo.code.git.GitPushEvent import com.tencent.devops.common.webhook.pojo.code.github.GithubPushEvent import com.tencent.devops.common.webhook.service.code.filter.BranchFilter diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt index 5fbf4d1b601..76394692c8c 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt @@ -36,7 +36,6 @@ import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.pojo.code.BK_REPO_P4_WEBHOOK_CHANGE import com.tencent.devops.common.webhook.pojo.code.PathFilterConfig import com.tencent.devops.common.webhook.pojo.code.WebHookParams -import com.tencent.devops.common.webhook.pojo.code.p4.P4ChangeEvent import com.tencent.devops.common.webhook.pojo.code.p4.P4ShelveEvent import com.tencent.devops.common.webhook.service.code.filter.EventTypeFilter import com.tencent.devops.common.webhook.service.code.filter.P4PortFilter From 0cb52b5539f68ed059f4d9d7ba7f53132ded7596 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 26 Sep 2023 16:37:26 +0800 Subject: [PATCH 058/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/code/handler/p4/P4ChangeTriggerHandler.kt | 4 ++-- .../service/code/handler/p4/P4ShelveTriggerHandler.kt | 4 ++-- .../process/api/user/UserPipelineTriggerEventResource.kt | 3 +++ .../process/api/UserPipelineTriggerEventResourceImpl.kt | 2 ++ .../tencent/devops/process/dao/PipelineTriggerEventDao.kt | 8 ++++++++ .../devops/process/trigger/PipelineTriggerEventService.kt | 3 +++ support-files/i18n/process/message_en_US.properties | 2 +- support-files/i18n/process/message_zh_CN.properties | 2 +- 8 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt index a3a52bb8f3a..10ac34ee469 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt @@ -86,8 +86,8 @@ class P4ChangeTriggerHandler( code = WebhookI18nConstants.P4_EVENT_DESC, params = listOf( getRevision(event), - getFormatEventType(event), - getUsername(event) + getUsername(event), + getFormatEventType(event) ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt index 76394692c8c..531d94b63c7 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt @@ -87,8 +87,8 @@ class P4ShelveTriggerHandler( code = WebhookI18nConstants.P4_EVENT_DESC, params = listOf( getRevision(event), - getFormatEventType(event), - getUsername(event) + getUsername(event), + getFormatEventType(event) ) ).toJsonStr() } diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt index eb7b67fb1a2..6f32c8cadcb 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt @@ -136,6 +136,9 @@ interface UserPipelineTriggerEventResource { @ApiParam("事件ID", required = false) @QueryParam("eventId") eventId: Long?, + @ApiParam("流水线名称", required = false) + @QueryParam("pipelineName") + pipelineName: String?, @ApiParam("开始时间", required = false) @QueryParam("startTime") startTime: Long?, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt index c317d01858a..272c980c063 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt @@ -103,6 +103,7 @@ class UserPipelineTriggerEventResourceImpl( triggerUser: String?, pipelineId: String?, eventId: Long?, + pipelineName:String?, startTime: Long?, endTime: Long?, page: Int?, @@ -117,6 +118,7 @@ class UserPipelineTriggerEventResourceImpl( triggerUser = triggerUser, pipelineId = pipelineId, eventId = eventId, + pipelineName = pipelineName, startTime = startTime, endTime = endTime, page = page, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index f351ce2c89d..881ee8cd57d 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -243,6 +243,7 @@ class PipelineTriggerEventDao { projectId: String, eventSource: String? = null, eventId: Long? = null, + pipelineName: String? = null, eventType: String? = null, triggerType: String? = null, triggerUser: String? = null, @@ -260,6 +261,7 @@ class PipelineTriggerEventDao { projectId = projectId, eventSource = eventSource, eventId = eventId, + pipelineName = pipelineName, eventType = eventType, triggerUser = triggerUser, triggerType = triggerType, @@ -300,6 +302,7 @@ class PipelineTriggerEventDao { projectId: String, eventSource: String? = null, eventId: Long? = null, + pipelineName: String? = null, eventType: String? = null, triggerType: String? = null, triggerUser: String? = null, @@ -315,6 +318,7 @@ class PipelineTriggerEventDao { projectId = projectId, eventSource = eventSource, eventId = eventId, + pipelineName = pipelineName, eventType = eventType, triggerUser = triggerUser, triggerType = triggerType, @@ -362,6 +366,7 @@ class PipelineTriggerEventDao { t1: TPipelineTriggerEvent, t2: TPipelineTriggerDetail, projectId: String, + pipelineName: String? = null, eventSource: String? = null, eventId: Long? = null, eventType: String? = null, @@ -397,6 +402,9 @@ class PipelineTriggerEventDao { if (endTime != null && endTime > 0) { conditions.add(t1.EVENT_TIME.le(Timestamp(endTime).toLocalDateTime())) } + if (!pipelineName.isNullOrBlank()) { + conditions.add(t2.PIPELINE_NAME.like("%$pipelineName%")) + } return conditions } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 09322caeccc..9252fb6e1df 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -154,6 +154,7 @@ class PipelineTriggerEventService @Autowired constructor( triggerUser: String?, pipelineId: String?, eventId: Long?, + pipelineName:String?, startTime: Long?, endTime: Long?, page: Int?, @@ -173,6 +174,7 @@ class PipelineTriggerEventService @Autowired constructor( triggerUser = triggerUser, pipelineId = pipelineId, eventId = eventId, + pipelineName = pipelineName, startTime = startTime, endTime = endTime ) @@ -185,6 +187,7 @@ class PipelineTriggerEventService @Autowired constructor( triggerUser = triggerUser, pipelineId = pipelineId, eventId = eventId, + pipelineName = pipelineName, startTime = startTime, endTime = endTime, limit = sqlLimit.limit, diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index 0cc97c37b71..58f5b47643c 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -381,7 +381,7 @@ bkGithubPushEventDesc=[{0}] Commit [{2}] pushe bkGithubCreateBranchEventDesc=Branch [{1}] created by {2} bkGithubCreateTagEventDesc=Tag [{1}] pushed by {2} bkGithubPrEventDesc=Pull request [!{1}] by {2} {3} -bkP4EventDesc=Change [{0}] {1} by {2} +bkP4EventDesc=Change [{0}] by {1} {2} bkSvnCommitEventDesc=Commit [{0}] pushed by {1} bkManualStartEventDesc=Manually triggered by {0} bkRemoteStartEventDesc=Remote api triggered by {0} diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 41ba3b7e7d2..667862566c7 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -381,7 +381,7 @@ bkGithubPushEventDesc=[{0}] 提交 [{2}] 由 < bkGithubCreateBranchEventDesc=Branch [{1}] 由 {2} 创建 bkGithubCreateTagEventDesc=Tag [{1}] 由 {2} 推送 bkGithubPrEventDesc=Pull request [{1}] 由 {2} {3} -bkP4EventDesc=Change {0} {1} 由 {2} +bkP4EventDesc=Change {0} 由 {1} {2} bkSvnCommitEventDesc=提交 [{0}] 由 {1} 推送 bkManualStartEventDesc={0} 手动触发 bkRemoteStartEventDesc={0} 远程触发 From 17ef9ebdcc936b56a3b516eed7b227489cd28361 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 27 Sep 2023 14:17:12 +0800 Subject: [PATCH 059/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/api/UserPipelineTriggerEventResourceImpl.kt | 2 +- .../devops/process/trigger/PipelineTriggerEventService.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt index 272c980c063..f95eb1df693 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt @@ -103,7 +103,7 @@ class UserPipelineTriggerEventResourceImpl( triggerUser: String?, pipelineId: String?, eventId: Long?, - pipelineName:String?, + pipelineName: String?, startTime: Long?, endTime: Long?, page: Int?, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 9252fb6e1df..6e3b1e865df 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -154,7 +154,7 @@ class PipelineTriggerEventService @Autowired constructor( triggerUser: String?, pipelineId: String?, eventId: Long?, - pipelineName:String?, + pipelineName: String?, startTime: Long?, endTime: Long?, page: Int?, From 38f169750ae645952a4a35bb1f9ed6113e55bf91 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 28 Sep 2023 11:20:25 +0800 Subject: [PATCH 060/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/webhook/parser/GitlabWebhookEventParser.kt | 1 + .../devops/process/webhook/parser/P4WebhookEventParser.kt | 1 + .../devops/process/webhook/parser/SvnWebhookEventParser.kt | 1 + .../devops/process/webhook/parser/TGitWebhookEventParser.kt | 1 + 4 files changed, 4 insertions(+) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/GitlabWebhookEventParser.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/GitlabWebhookEventParser.kt index 987be3bba54..0db1917c33a 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/GitlabWebhookEventParser.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/GitlabWebhookEventParser.kt @@ -46,6 +46,7 @@ class GitlabWebhookEventParser( } override fun parseEvent(request: WebhookRequest): CodeWebhookEvent? { + logger.info("Trigger gitlab build(${request.body})") return try { objectMapper.readValue(request.body, GitEvent::class.java) } catch (e: Exception) { diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/P4WebhookEventParser.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/P4WebhookEventParser.kt index 0d4a3e2c9f6..937f826fba9 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/P4WebhookEventParser.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/P4WebhookEventParser.kt @@ -46,6 +46,7 @@ class P4WebhookEventParser( } override fun parseEvent(request: WebhookRequest): CodeWebhookEvent? { + logger.info("Trigger p4 build(${request.body})") return try { objectMapper.readValue(request.body, P4Event::class.java) } catch (e: Exception) { diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/SvnWebhookEventParser.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/SvnWebhookEventParser.kt index 337d51a42af..8d11dffb08d 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/SvnWebhookEventParser.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/SvnWebhookEventParser.kt @@ -46,6 +46,7 @@ class SvnWebhookEventParser( } override fun parseEvent(request: WebhookRequest): CodeWebhookEvent? { + logger.info("Trigger code svn build - ${request.body}") return try { objectMapper.readValue(request.body, SvnCommitEvent::class.java) } catch (e: Exception) { diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/TGitWebhookEventParser.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/TGitWebhookEventParser.kt index cb1c6e01b4a..3f70e117aaf 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/TGitWebhookEventParser.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/parser/TGitWebhookEventParser.kt @@ -50,6 +50,7 @@ class TGitWebhookEventParser( override fun parseEvent(request: WebhookRequest): CodeWebhookEvent? { val eventType = request.headers?.get("X-Event") val body = request.body + logger.info("Trigger code git build($body|$eventType)") return try { if (eventType == "Review Hook") { objectMapper.readValue(body) From 0df50e4308f0ddb6b9f8022b4ed214c8f71505cd Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Sat, 7 Oct 2023 17:12:00 +0800 Subject: [PATCH 061/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../code/handler/tgit/TGitTagPushTriggerHandler.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt index b45fc9c58f3..2a4cc2d5096 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt @@ -48,7 +48,6 @@ import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_TAG_USERN import com.tencent.devops.common.webhook.pojo.code.CI_BRANCH import com.tencent.devops.common.webhook.pojo.code.DELETE_EVENT import com.tencent.devops.common.webhook.pojo.code.WebHookParams -import com.tencent.devops.common.webhook.pojo.code.git.GitPushEvent import com.tencent.devops.common.webhook.pojo.code.git.GitTagPushEvent import com.tencent.devops.common.webhook.pojo.code.git.isDeleteTag import com.tencent.devops.common.webhook.service.code.filter.BranchFilter @@ -101,10 +100,14 @@ class TGitTagPushTriggerHandler : CodeWebhookTriggerHandler { } override fun getEventDesc(event: GitTagPushEvent): String { - val createFrom = if (event.create_from.isNullOrBlank()) { - event.checkout_sha?.substring(0, GitPushEvent.SHORT_COMMIT_ID_LENGTH) - } else { - event.create_from + val createFrom = when { + event.create_from.isNullOrBlank() || event.checkout_sha == event.create_from -> { + GitUtils.getShortSha(event.checkout_sha) + } + + else -> { + event.create_from + } } return I18Variable( code = WebhookI18nConstants.TGIT_TAG_PUSH_EVENT_DESC, From 1c5e1e128c83d2f7bedf964cb45497b5540abb09 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Mon, 9 Oct 2023 11:51:19 +0800 Subject: [PATCH 062/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 删除webhook构建日志代码 --- docs/overview/db/devops_ci_process.md | 39 ----- .../v3/ApigwPipelineWebhookResourceV3.kt | 36 ----- .../v3/ApigwPipelineWebhookResourceV3Impl.kt | 29 ---- .../api/service/ServiceScmWebhookResource.kt | 27 ---- .../api/user/UserScmWebhookResource.kt | 27 ---- .../pojo/webhook/PipelineWebhookBuildLog.kt | 76 --------- .../api/ServiceScmWebhookResourceImpl.kt | 29 +--- .../process/api/UserScmWebhookResourceImpl.kt | 29 +--- .../dao/PipelineWebhookBuildLogDetailDao.kt | 148 ------------------ .../service/PipelineWebhookBuildLogContext.kt | 105 ------------- .../service/PipelineWebhookBuildLogService.kt | 54 ------- .../PipelineWebhookBuildLogServiceImpl.kt | 50 ------ .../sql/1001_ci_process_ddl_mysql.sql | 30 ---- support-files/templates/#etc#ci#common.yml | 3 - 14 files changed, 2 insertions(+), 680 deletions(-) delete mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhookBuildLog.kt delete mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookBuildLogDetailDao.kt delete mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookBuildLogContext.kt delete mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookBuildLogService.kt delete mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookBuildLogServiceImpl.kt diff --git a/docs/overview/db/devops_ci_process.md b/docs/overview/db/devops_ci_process.md index dbba2a8cdf4..354bf30c323 100644 --- a/docs/overview/db/devops_ci_process.md +++ b/docs/overview/db/devops_ci_process.md @@ -50,8 +50,6 @@ | [T_PIPELINE_VIEW_USER_LAST_VIEW](#T_PIPELINE_VIEW_USER_LAST_VIEW) | | | [T_PIPELINE_VIEW_USER_SETTINGS](#T_PIPELINE_VIEW_USER_SETTINGS) | | | [T_PIPELINE_WEBHOOK](#T_PIPELINE_WEBHOOK) | | -| [T_PIPELINE_WEBHOOK_BUILD_LOG](#T_PIPELINE_WEBHOOK_BUILD_LOG) | | -| [T_PIPELINE_WEBHOOK_BUILD_LOG_DETAIL](#T_PIPELINE_WEBHOOK_BUILD_LOG_DETAIL) | | | [T_PIPELINE_WEBHOOK_QUEUE](#T_PIPELINE_WEBHOOK_QUEUE) | | | [T_PROJECT_PIPELINE_CALLBACK](#T_PROJECT_PIPELINE_CALLBACK) | | | [T_PROJECT_PIPELINE_CALLBACK_HISTORY](#T_PROJECT_PIPELINE_CALLBACK_HISTORY) | | @@ -849,43 +847,6 @@ | 9 | TASK_ID | varchar | 34 | 0 | Y | N | | 任务id | | 10 | DELETE | bit | 1 | 0 | Y | N | b'0' | 是否删除 | -**表名:** T_PIPELINE_WEBHOOK_BUILD_LOG - -**说明:** - -**数据列:** - -| 序号 | 名称 | 数据类型 | 长度 | 小数位 | 允许空值 | 主键 | 默认值 | 说明 | -| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | -| 1 | ID | bigint | 20 | 0 | N | Y | | 主键ID | -| 2 | CODE_TYPE | varchar | 32 | 0 | N | N | | 代码库类型 | -| 3 | REPO_NAME | varchar | 128 | 0 | N | N | | 代码库别名 | -| 4 | COMMIT_ID | varchar | 64 | 0 | N | N | | 代码提交ID | -| 5 | REQUEST_CONTENT | text | 65535 | 0 | Y | N | | 事件内容 | -| 6 | CREATED_TIME | datetime | 19 | 0 | N | Y | CURRENT_TIMESTAMP | 创建时间 | -| 7 | RECEIVED_TIME | datetime | 19 | 0 | N | N | | 接收时间 | -| 8 | FINISHED_TIME | datetime | 19 | 0 | N | N | | 完成时间 | - -**表名:** T_PIPELINE_WEBHOOK_BUILD_LOG_DETAIL - -**说明:** - -**数据列:** - -| 序号 | 名称 | 数据类型 | 长度 | 小数位 | 允许空值 | 主键 | 默认值 | 说明 | -| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | -| 1 | ID | bigint | 20 | 0 | N | Y | | 主键ID | -| 2 | LOG_ID | bigint | 20 | 0 | N | N | | | -| 3 | CODE_TYPE | varchar | 32 | 0 | N | N | | 代码库类型 | -| 4 | REPO_NAME | varchar | 128 | 0 | N | N | | 代码库别名 | -| 5 | COMMIT_ID | varchar | 64 | 0 | N | N | | 代码提交ID | -| 6 | PROJECT_ID | varchar | 32 | 0 | N | N | | 项目ID | -| 7 | PIPELINE_ID | varchar | 34 | 0 | N | N | | 流水线ID | -| 8 | TASK_ID | varchar | 34 | 0 | N | N | | 任务id | -| 9 | TASK_NAME | varchar | 128 | 0 | Y | N | | 任务名称 | -| 10 | SUCCESS | bit | 1 | 0 | Y | N | b'0' | 是否成功 | -| 11 | TRIGGER_RESULT | text | 65535 | 0 | Y | N | | 触发结果 | -| 12 | CREATED_TIME | datetime | 19 | 0 | N | Y | CURRENT_TIMESTAMP | 创建时间 | **表名:** T_PIPELINE_WEBHOOK_QUEUE diff --git a/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v3/ApigwPipelineWebhookResourceV3.kt b/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v3/ApigwPipelineWebhookResourceV3.kt index 33cd7be80a0..8fea657eb82 100644 --- a/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v3/ApigwPipelineWebhookResourceV3.kt +++ b/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v3/ApigwPipelineWebhookResourceV3.kt @@ -30,10 +30,8 @@ package com.tencent.devops.openapi.api.apigw.v3 import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_APP_CODE import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_APP_CODE_DEFAULT_VALUE import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_USER_ID -import com.tencent.devops.common.api.model.SQLPage import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.process.pojo.webhook.PipelineWebhook -import com.tencent.devops.process.pojo.webhook.PipelineWebhookBuildLogDetail import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation import io.swagger.annotations.ApiParam @@ -76,38 +74,4 @@ interface ApigwPipelineWebhookResourceV3 { @QueryParam("pageSize") pageSize: Int? ): Result> - - @ApiOperation( - "获取流水线的webhook构建日志列表", - tags = ["v3_user_pipeline_webhook_build_log", "v3_app_pipeline_webhook_build_log"] - ) - @GET - @Path("/buildLog") - fun listPipelineWebhookBuildLog( - @ApiParam(value = "appCode", required = true, defaultValue = AUTH_HEADER_DEVOPS_APP_CODE_DEFAULT_VALUE) - @HeaderParam(AUTH_HEADER_DEVOPS_APP_CODE) - appCode: String?, - @ApiParam(value = "apigw Type", required = true) - @PathParam("apigwType") - apigwType: String?, - @ApiParam("userId", required = true) - @HeaderParam(AUTH_HEADER_DEVOPS_USER_ID) - userId: String, - @PathParam("projectId") - projectId: String, - @PathParam("pipelineId") - pipelineId: String, - @ApiParam("仓库名", required = false) - @QueryParam("repoName") - repoName: String?, - @ApiParam("commitId", required = false) - @QueryParam("commitId") - commitId: String?, - @ApiParam("页码", required = false) - @QueryParam("page") - page: Int?, - @ApiParam("每页大小", required = false) - @QueryParam("pageSize") - pageSize: Int? - ): Result?> } diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwPipelineWebhookResourceV3Impl.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwPipelineWebhookResourceV3Impl.kt index 41f125d4539..ea816c84d8b 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwPipelineWebhookResourceV3Impl.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwPipelineWebhookResourceV3Impl.kt @@ -27,14 +27,12 @@ package com.tencent.devops.openapi.resources.apigw.v3 -import com.tencent.devops.common.api.model.SQLPage import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.common.client.Client import com.tencent.devops.common.web.RestResource import com.tencent.devops.openapi.api.apigw.v3.ApigwPipelineWebhookResourceV3 import com.tencent.devops.process.api.service.ServiceScmWebhookResource import com.tencent.devops.process.pojo.webhook.PipelineWebhook -import com.tencent.devops.process.pojo.webhook.PipelineWebhookBuildLogDetail import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -63,33 +61,6 @@ class ApigwPipelineWebhookResourceV3Impl @Autowired constructor( ) } - override fun listPipelineWebhookBuildLog( - appCode: String?, - apigwType: String?, - userId: String, - projectId: String, - pipelineId: String, - repoName: String?, - commitId: String?, - page: Int?, - pageSize: Int? - ): Result?> { - logger.info( - "OPENAPI_PIPELINE_WEBHOOK_V3|$userId|list pipeline webhook build log|$projectId|$pipelineId" + - "|$repoName|$commitId|$page|$pageSize" - ) - return client.get(ServiceScmWebhookResource::class) - .listPipelineWebhookBuildLog( - userId = userId, - projectId = projectId, - pipelineId = pipelineId, - repoName = repoName, - commitId = commitId, - page = page, - pageSize = pageSize - ) - } - companion object { private val logger = LoggerFactory.getLogger(ApigwPipelineWebhookResourceV3Impl::class.java) } diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceScmWebhookResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceScmWebhookResource.kt index 1cb6201711e..0f56119adf9 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceScmWebhookResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceScmWebhookResource.kt @@ -29,12 +29,10 @@ package com.tencent.devops.process.api.service import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_PROJECT_ID import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID -import com.tencent.devops.common.api.model.SQLPage import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.common.webhook.pojo.code.github.GithubWebhook import com.tencent.devops.process.pojo.code.WebhookCommit import com.tencent.devops.process.pojo.webhook.PipelineWebhook -import com.tencent.devops.process.pojo.webhook.PipelineWebhookBuildLogDetail import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation import io.swagger.annotations.ApiParam @@ -88,29 +86,4 @@ interface ServiceScmWebhookResource { @QueryParam("pageSize") pageSize: Int? ): Result> - - @ApiOperation("获取流水线的webhook构建日志列表") - @GET - @Path("/{projectId}/{pipelineId}/buildLog") - @Suppress("ALL") - fun listPipelineWebhookBuildLog( - @HeaderParam(AUTH_HEADER_USER_ID) - userId: String, - @PathParam("projectId") - projectId: String, - @PathParam("pipelineId") - pipelineId: String, - @ApiParam("仓库名", required = false) - @QueryParam("repoName") - repoName: String?, - @ApiParam("commitId", required = false) - @QueryParam("commitId") - commitId: String?, - @ApiParam("页码", required = false) - @QueryParam("page") - page: Int?, - @ApiParam("每页大小", required = false) - @QueryParam("pageSize") - pageSize: Int? - ): Result?> } diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserScmWebhookResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserScmWebhookResource.kt index 7d055f011b4..19fa90526e0 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserScmWebhookResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserScmWebhookResource.kt @@ -28,10 +28,8 @@ package com.tencent.devops.process.api.user import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID -import com.tencent.devops.common.api.model.SQLPage import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.process.pojo.webhook.PipelineWebhook -import com.tencent.devops.process.pojo.webhook.PipelineWebhookBuildLogDetail import com.tencent.devops.process.pojo.webhook.WebhookEventType import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation @@ -83,29 +81,4 @@ interface UserScmWebhookResource { @QueryParam("pageSize") pageSize: Int? ): Result> - - @ApiOperation("获取流水线的webhook构建日志列表") - @GET - @Path("/{projectId}/{pipelineId}/buildLog") - @Suppress("ALL") - fun listPipelineWebhookBuildLog( - @HeaderParam(AUTH_HEADER_USER_ID) - userId: String, - @PathParam("projectId") - projectId: String, - @PathParam("pipelineId") - pipelineId: String, - @ApiParam("仓库名", required = false) - @QueryParam("repoName") - repoName: String?, - @ApiParam("commitId", required = false) - @QueryParam("commitId") - commitId: String?, - @ApiParam("页码", required = false) - @QueryParam("page") - page: Int?, - @ApiParam("每页大小", required = false) - @QueryParam("pageSize") - pageSize: Int? - ): Result?> } diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhookBuildLog.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhookBuildLog.kt deleted file mode 100644 index f2cc63365f0..00000000000 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhookBuildLog.kt +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package com.tencent.devops.process.pojo.webhook - -import io.swagger.annotations.ApiModel -import io.swagger.annotations.ApiModelProperty - -@ApiModel("流水线webhook-触发日志") -data class PipelineWebhookBuildLog( - val id: Long? = null, - @ApiModelProperty("代码库类型", required = true) - val codeType: String, - @ApiModelProperty("仓库名", required = true) - val repoName: String? = null, - @ApiModelProperty("commitId", required = true) - val commitId: String? = null, - @ApiModelProperty("事件内容", required = true) - val requestContent: String, - @ApiModelProperty("接受请求时间", required = true) - val receivedTime: Long, - @ApiModelProperty("完成时间", required = true) - var finishedTime: Long? = null, - val createdTime: Long, - @ApiModelProperty("触发构建日志详情", required = true) - val detail: MutableList = mutableListOf() -) - -@ApiModel("流水线webhook-触发日志明细") -data class PipelineWebhookBuildLogDetail( - val id: Long? = null, - val logId: Long? = null, - @ApiModelProperty("代码库类型", required = true) - val codeType: String, - @ApiModelProperty("仓库名", required = true) - val repoName: String, - @ApiModelProperty("commitId", required = true) - val commitId: String, - @ApiModelProperty("项目ID", required = true) - val projectId: String, - @ApiModelProperty("流水线ID", required = true) - val pipelineId: String, - @ApiModelProperty("插件ID", required = true) - val taskId: String, - @ApiModelProperty("插件名", required = true) - val taskName: String, - @ApiModelProperty("是否成功触发", required = true) - val success: Boolean, - @ApiModelProperty("触发结果,如果触发成功就是buildId,触发不成功就是不成功原因", required = true) - val triggerResult: String?, - val createdTime: Long -) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceScmWebhookResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceScmWebhookResourceImpl.kt index 5e126a76aea..45075f00109 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceScmWebhookResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceScmWebhookResourceImpl.kt @@ -27,16 +27,13 @@ package com.tencent.devops.process.api -import com.tencent.devops.common.api.model.SQLPage import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.common.web.RestResource import com.tencent.devops.common.webhook.pojo.code.github.GithubWebhook import com.tencent.devops.process.api.service.ServiceScmWebhookResource -import com.tencent.devops.process.engine.service.PipelineWebhookBuildLogService import com.tencent.devops.process.engine.service.PipelineWebhookService import com.tencent.devops.process.pojo.code.WebhookCommit import com.tencent.devops.process.pojo.webhook.PipelineWebhook -import com.tencent.devops.process.pojo.webhook.PipelineWebhookBuildLogDetail import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService import com.tencent.devops.process.webhook.CodeWebhookEventDispatcher import com.tencent.devops.process.webhook.pojo.event.commit.GithubWebhookEvent @@ -47,8 +44,7 @@ import org.springframework.beans.factory.annotation.Autowired class ServiceScmWebhookResourceImpl @Autowired constructor( private val pipelineBuildWebhookService: PipelineBuildWebhookService, private val rabbitTemplate: RabbitTemplate, - private val pipelineWebhookService: PipelineWebhookService, - private val pipelineWebhookBuildLogService: PipelineWebhookBuildLogService + private val pipelineWebhookService: PipelineWebhookService ) : ServiceScmWebhookResource { override fun webHookCodeGithubCommit(webhook: GithubWebhook): Result { return Result(CodeWebhookEventDispatcher.dispatchGithubEvent( @@ -78,27 +74,4 @@ class ServiceScmWebhookResourceImpl @Autowired constructor( ) ) } - - override fun listPipelineWebhookBuildLog( - userId: String, - projectId: String, - pipelineId: String, - repoName: String?, - commitId: String?, - page: Int?, - pageSize: Int? - ): Result?> { - return Result( - pipelineWebhookBuildLogService.listWebhookBuildLogDetail( - userId = userId, - projectId = projectId, - pipelineId = pipelineId, - repoName = repoName, - commitId = commitId, - page = page, - pageSize = pageSize - - ) - ) - } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserScmWebhookResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserScmWebhookResourceImpl.kt index c9a36036f35..cc9596919e1 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserScmWebhookResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserScmWebhookResourceImpl.kt @@ -28,22 +28,18 @@ package com.tencent.devops.process.api import com.tencent.devops.common.api.enums.ScmType -import com.tencent.devops.common.api.model.SQLPage import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.web.RestResource import com.tencent.devops.process.api.user.UserScmWebhookResource -import com.tencent.devops.process.engine.service.PipelineWebhookBuildLogService import com.tencent.devops.process.engine.service.PipelineWebhookService import com.tencent.devops.process.pojo.webhook.PipelineWebhook -import com.tencent.devops.process.pojo.webhook.PipelineWebhookBuildLogDetail import com.tencent.devops.process.pojo.webhook.WebhookEventType import org.springframework.beans.factory.annotation.Autowired @RestResource class UserScmWebhookResourceImpl @Autowired constructor( - private val pipelineWebhookService: PipelineWebhookService, - private val pipelineWebhookBuildLogService: PipelineWebhookBuildLogService + private val pipelineWebhookService: PipelineWebhookService ) : UserScmWebhookResource { override fun updateProjectNameAndTaskId(): Result { @@ -97,27 +93,4 @@ class UserScmWebhookResourceImpl @Autowired constructor( ) ) } - - override fun listPipelineWebhookBuildLog( - userId: String, - projectId: String, - pipelineId: String, - repoName: String?, - commitId: String?, - page: Int?, - pageSize: Int? - ): Result?> { - return Result( - pipelineWebhookBuildLogService.listWebhookBuildLogDetail( - userId = userId, - projectId = projectId, - pipelineId = pipelineId, - repoName = repoName, - commitId = commitId, - page = page, - pageSize = pageSize - - ) - ) - } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookBuildLogDetailDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookBuildLogDetailDao.kt deleted file mode 100644 index f1610de3a67..00000000000 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookBuildLogDetailDao.kt +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package com.tencent.devops.process.engine.dao - -import com.tencent.devops.common.api.util.timestampmilli -import com.tencent.devops.model.process.Tables.T_PIPELINE_WEBHOOK_BUILD_LOG_DETAIL -import com.tencent.devops.model.process.tables.records.TPipelineWebhookBuildLogDetailRecord -import com.tencent.devops.process.pojo.webhook.PipelineWebhookBuildLogDetail -import org.jooq.DSLContext -import org.springframework.stereotype.Repository -import java.sql.Timestamp - -@Repository -@Suppress("ALL") -class PipelineWebhookBuildLogDetailDao { - - fun save( - dslContext: DSLContext, - logId: Long, - webhookBuildLogDetails: List - ) { - if (webhookBuildLogDetails.isEmpty()) { - return - } - webhookBuildLogDetails.map { - with(T_PIPELINE_WEBHOOK_BUILD_LOG_DETAIL) { - dslContext.insertInto( - this, - LOG_ID, - CODE_TYPE, - REPO_NAME, - COMMIT_ID, - PROJECT_ID, - PIPELINE_ID, - TASK_ID, - TASK_NAME, - SUCCESS, - TRIGGER_RESULT, - CREATED_TIME, - ID - ).values( - logId, - it.codeType, - it.repoName, - it.commitId, - it.projectId, - it.pipelineId, - it.taskId, - it.taskName, - it.success, - it.triggerResult, - Timestamp(it.createdTime).toLocalDateTime(), - it.id - ).execute() - } - } - } - - fun listByPage( - dslContext: DSLContext, - projectId: String, - pipelineId: String, - repoName: String?, - commitId: String?, - offset: Int, - limit: Int - ): List { - return with(T_PIPELINE_WEBHOOK_BUILD_LOG_DETAIL) { - val where = dslContext.selectFrom(this) - .where(PIPELINE_ID.eq(pipelineId)) - .and(PROJECT_ID.eq(projectId)) - if (commitId != null) { - where.and(COMMIT_ID.eq(commitId)) - } - if (repoName != null) { - where.and(REPO_NAME.eq(repoName)) - } - where.orderBy(CREATED_TIME.desc()) - .limit(offset, limit).fetch() - }.map { convert(it) } - } - - fun countByPage( - dslContext: DSLContext, - projectId: String, - pipelineId: String, - repoName: String?, - commitId: String? - ): Long { - return with(T_PIPELINE_WEBHOOK_BUILD_LOG_DETAIL) { - val where = dslContext.selectCount() - .from(this) - .where(PIPELINE_ID.eq(pipelineId)) - .and(PROJECT_ID.eq(projectId)) - if (commitId != null) { - where.and(COMMIT_ID.eq(commitId)) - } - if (repoName != null) { - where.and(REPO_NAME.eq(repoName)) - } - where.fetchOne(0, Long::class.java)!! - } - } - - fun convert(record: TPipelineWebhookBuildLogDetailRecord): PipelineWebhookBuildLogDetail { - return with(record) { - PipelineWebhookBuildLogDetail( - id = id, - logId = logId, - codeType = codeType, - repoName = repoName, - commitId = commitId, - projectId = projectId, - pipelineId = pipelineId, - taskId = taskId, - taskName = taskName, - success = success, - triggerResult = triggerResult, - createdTime = createdTime.timestampmilli() - ) - } - } -} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookBuildLogContext.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookBuildLogContext.kt deleted file mode 100644 index 06ea5f04a0c..00000000000 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookBuildLogContext.kt +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package com.tencent.devops.process.engine.service - -import com.tencent.devops.common.api.util.timestampmilli -import com.tencent.devops.process.pojo.webhook.PipelineWebhookBuildLog -import com.tencent.devops.process.pojo.webhook.PipelineWebhookBuildLogDetail -import java.time.LocalDateTime - -object PipelineWebhookBuildLogContext { - private val currentTriggerLog = ThreadLocal() - - fun initTriggerLog( - codeType: String, - requestContent: String - ) { - currentTriggerLog.set( - PipelineWebhookBuildLog( - codeType = codeType, - requestContent = requestContent, - receivedTime = LocalDateTime.now().timestampmilli(), - createdTime = LocalDateTime.now().timestampmilli() - ) - ) - } - - fun addRepoInfo( - repoName: String, - commitId: String - ) { - val triggerLog = with(currentTriggerLog.get()) { - PipelineWebhookBuildLog( - id = id, - codeType = codeType, - requestContent = requestContent, - receivedTime = receivedTime, - createdTime = createdTime, - repoName = repoName, - commitId = commitId - ) - } - currentTriggerLog.set(triggerLog) - } - - @Suppress("ALL") - fun addLogBuildInfo( - projectId: String, - pipelineId: String, - taskId: String, - taskName: String, - success: Boolean, - triggerResult: String?, - id: Long? = null - ) { - val webhookLog = currentTriggerLog.get() - webhookLog.detail.add( - PipelineWebhookBuildLogDetail( - codeType = webhookLog.codeType, - repoName = webhookLog.repoName!!, - commitId = webhookLog.commitId!!, - projectId = projectId, - pipelineId = pipelineId, - taskId = taskId, - taskName = taskName, - success = success, - triggerResult = triggerResult, - createdTime = LocalDateTime.now().timestampmilli(), - id = id - ) - ) - } - - fun get(): PipelineWebhookBuildLog { - return currentTriggerLog.get() - } - - fun remove() { - currentTriggerLog.remove() - } -} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookBuildLogService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookBuildLogService.kt deleted file mode 100644 index a98b63f8869..00000000000 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookBuildLogService.kt +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package com.tencent.devops.process.engine.service - -import com.tencent.devops.common.api.model.SQLPage -import com.tencent.devops.process.pojo.webhook.PipelineWebhookBuildLog -import com.tencent.devops.process.pojo.webhook.PipelineWebhookBuildLogDetail - -interface PipelineWebhookBuildLogService { - - /** - * 保存webhook构建日志 - */ - fun saveWebhookBuildLog(webhookBuildLog: PipelineWebhookBuildLog) - - /** - * 查询webhook构建日志明细 - */ - @Suppress("ALL") - fun listWebhookBuildLogDetail( - userId: String, - projectId: String, - pipelineId: String, - repoName: String?, - commitId: String?, - page: Int?, - pageSize: Int? - ): SQLPage? -} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookBuildLogServiceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookBuildLogServiceImpl.kt deleted file mode 100644 index 27ad3d005d8..00000000000 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookBuildLogServiceImpl.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package com.tencent.devops.process.engine.service - -import com.tencent.devops.common.api.model.SQLPage -import com.tencent.devops.process.pojo.webhook.PipelineWebhookBuildLog -import com.tencent.devops.process.pojo.webhook.PipelineWebhookBuildLogDetail -import org.springframework.stereotype.Service - -@Service -class PipelineWebhookBuildLogServiceImpl : PipelineWebhookBuildLogService { - override fun saveWebhookBuildLog(webhookBuildLog: PipelineWebhookBuildLog) = Unit - - override fun listWebhookBuildLogDetail( - userId: String, - projectId: String, - pipelineId: String, - repoName: String?, - commitId: String?, - page: Int?, - pageSize: Int? - ): SQLPage? { - return null - } -} diff --git a/support-files/sql/1001_ci_process_ddl_mysql.sql b/support-files/sql/1001_ci_process_ddl_mysql.sql index 1036b36a5ab..8cebd539254 100644 --- a/support-files/sql/1001_ci_process_ddl_mysql.sql +++ b/support-files/sql/1001_ci_process_ddl_mysql.sql @@ -906,36 +906,6 @@ CREATE TABLE IF NOT EXISTS `T_PIPELINE_ATOM_REPLACE_HISTORY` ( KEY `INX_TPARH_ITEM_ID` (`ITEM_ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='流水线插件替换历史信息表'; -CREATE TABLE IF NOT EXISTS `T_PIPELINE_WEBHOOK_BUILD_LOG` ( - `ID` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID', - `CODE_TYPE` VARCHAR(32) NOT NULL COMMENT '代码库类型', - `REPO_NAME` VARCHAR(128) NOT NULL COMMENT '代码库别名', - `COMMIT_ID` VARCHAR(64) NOT NULL COMMENT '代码提交ID', - `REQUEST_CONTENT` TEXT COMMENT '事件内容', - `CREATED_TIME` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `RECEIVED_TIME` DATETIME NOT NULL COMMENT '接收时间', - `FINISHED_TIME` DATETIME NOT NULL COMMENT '完成时间', - PRIMARY KEY (`ID`,`CREATED_TIME`), - KEY `IDX_REPO_NAME_COMMIT_ID`(`REPO_NAME`, `COMMIT_ID`) -)ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COMMENT=''; - -CREATE TABLE IF NOT EXISTS `T_PIPELINE_WEBHOOK_BUILD_LOG_DETAIL` ( - `ID` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID', - `LOG_ID` BIGINT(20) NOT NULL COMMENT '', - `CODE_TYPE` VARCHAR(32) NOT NULL COMMENT '代码库类型', - `REPO_NAME` VARCHAR(128) NOT NULL COMMENT '代码库别名', - `COMMIT_ID` VARCHAR(64) NOT NULL COMMENT '代码提交ID', - `PROJECT_ID` varchar(32) NOT NULL COMMENT '项目ID', - `PIPELINE_ID` varchar(34) NOT NULL COMMENT '流水线ID', - `TASK_ID` VARCHAR(34) NOT NULL COMMENT '任务id', - `TASK_NAME` VARCHAR(128) COMMENT '任务名称', - `SUCCESS` BIT(1) DEFAULT b'0' COMMENT '是否成功', - `TRIGGER_RESULT` TEXT COMMENT '触发结果', - `CREATED_TIME` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - PRIMARY KEY (`ID`,`CREATED_TIME`), - KEY `IDX_PIPELINE_ID_COMMIT_ID`(`PIPELINE_ID`,`COMMIT_ID`) -)ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COMMENT=''; - CREATE TABLE IF NOT EXISTS `T_PIPELINE_RESOURCE_VERSION` ( `PROJECT_ID` varchar(64) COLLATE utf8mb4_bin NOT NULL DEFAULT '' COMMENT '项目ID', `PIPELINE_ID` varchar(34) NOT NULL COMMENT '流水线ID', diff --git a/support-files/templates/#etc#ci#common.yml b/support-files/templates/#etc#ci#common.yml index d996a1c3f18..bacb151c855 100644 --- a/support-files/templates/#etc#ci#common.yml +++ b/support-files/templates/#etc#ci#common.yml @@ -132,9 +132,6 @@ spring: - index: 23 name: T_PIPELINE_VIEW_USER_SETTINGS databaseShardingStrategy: SHARDING - - index: 24 - name: T_PIPELINE_WEBHOOK_BUILD_LOG_DETAIL - databaseShardingStrategy: SHARDING - index: 25 name: T_PIPELINE_WEBHOOK_QUEUE databaseShardingStrategy: SHARDING From a9dc73b834f301d526a4d00539fac322ac8345e5 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 10 Oct 2023 14:49:26 +0800 Subject: [PATCH 063/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/user/UserPipelineTriggerEventResource.kt | 9 ++++++++- .../process/pojo/trigger/PipelineTriggerType.kt | 12 +++++++++--- .../api/UserPipelineTriggerEventResourceImpl.kt | 12 ++++++++++-- support-files/i18n/process/message_en_US.properties | 13 ++++++++++++- support-files/i18n/process/message_zh_CN.properties | 13 ++++++++++++- 5 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt index 6f32c8cadcb..9e34348f877 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt @@ -58,7 +58,14 @@ interface UserPipelineTriggerEventResource { @ApiOperation("获取触发类型") @GET @Path("listTriggerType") - fun listTriggerType(): Result> + fun listTriggerType( + @ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, + @ApiParam("代码库类型,为空则返回所有事件类型", required = false) + @QueryParam("scmType") + scmType: ScmType? + ): Result> @ApiOperation("获取事件类型") @GET diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt index fbe760bf5b6..e4c941dd7cd 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt @@ -71,13 +71,19 @@ enum class PipelineTriggerType { companion object { - fun toMap(): List { - return PipelineTriggerType.values().map { + fun toMap( + scmType: ScmType?, + userId: String + ): List { + return PipelineTriggerType.values().filter { + scmType == null || scmType.name == it.name + }.map { IdValue( id = it.name, value = I18nUtil.getCodeLanMessage( messageCode = "TRIGGER_TYPE_${it.name}", - defaultMessage = it.name + defaultMessage = it.name, + language = I18nUtil.getLanguage(userId) ) ) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt index f95eb1df693..e77f05dd19f 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt @@ -46,8 +46,16 @@ class UserPipelineTriggerEventResourceImpl( private val pipelineTriggerEventService: PipelineTriggerEventService ) : UserPipelineTriggerEventResource { - override fun listTriggerType(): Result> { - return Result(PipelineTriggerType.toMap()) + override fun listTriggerType( + userId: String, + scmType: ScmType? + ): Result> { + return Result( + PipelineTriggerType.toMap( + userId = userId, + scmType = scmType + ) + ) } override fun listEventType( diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index 58f5b47643c..24b22f97d91 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -418,4 +418,15 @@ EVENT_TYPE_CHANGE_COMMIT=Change-Commit EVENT_TYPE_CHANGE_CONTENT=Change-Content EVENT_TYPE_CHANGE_SUBMIT=Change-Submit EVENT_TYPE_SHELVE_COMMIT=Shelve-Commit -EVENT_TYPE_SHELVE_SUBMIT=Shelve-Submit \ No newline at end of file +EVENT_TYPE_SHELVE_SUBMIT=Shelve-Submit +TRIGGER_TYPE_CODE_SVN=SVN +TRIGGER_TYPE_CODE_GIT=GIT +TRIGGER_TYPE_CODE_GITLAB=Gitlab +TRIGGER_TYPE_GITHUB=Github +TRIGGER_TYPE_CODE_TGIT=TGIT +TRIGGER_TYPE_CODE_P4=P4 +TRIGGER_TYPE_MANUAL=Manual Trigger +TRIGGER_TYPE_TIME_TRIGGER=Time Trigger +TRIGGER_TYPE_SERVICE=Service Trigger +TRIGGER_TYPE_PIPELINE=Pipeline Trigger +TRIGGER_TYPE_REMOTE=Remote Trigger diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 667862566c7..d1c8ddc6eb8 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -418,4 +418,15 @@ EVENT_TYPE_CHANGE_COMMIT=Change-Commit EVENT_TYPE_CHANGE_CONTENT=Change-Content EVENT_TYPE_CHANGE_SUBMIT=Change-Submit EVENT_TYPE_SHELVE_COMMIT=Shelve-Commit -EVENT_TYPE_SHELVE_SUBMIT=Shelve-Submit \ No newline at end of file +EVENT_TYPE_SHELVE_SUBMIT=Shelve-Submit +TRIGGER_TYPE_CODE_SVN=SVN 代码库 +TRIGGER_TYPE_CODE_GIT=GIT 代码库 +TRIGGER_TYPE_CODE_GITLAB=Gitlab 代码库 +TRIGGER_TYPE_GITHUB=Github 代码库 +TRIGGER_TYPE_CODE_TGIT=TGIT 代码库 +TRIGGER_TYPE_CODE_P4=P4 代码库 +TRIGGER_TYPE_MANUAL=手动触发 +TRIGGER_TYPE_TIME_TRIGGER=定时触发 +TRIGGER_TYPE_SERVICE=服务触发 +TRIGGER_TYPE_PIPELINE=流水线触发 +TRIGGER_TYPE_REMOTE=远程触发 From 77d6639e25c0fa978a2c43fa10a5766ef8cbd966 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 11 Oct 2023 14:47:23 +0800 Subject: [PATCH 064/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../code/handler/tgit/TGitReviewTriggerHandler.kt | 11 ++++++++--- .../process/engine/service/PipelineWebhookService.kt | 8 ++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt index 13fe5c6452d..e2c4155a501 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt @@ -99,12 +99,17 @@ class TGitReviewTriggerHandler( } override fun getEventDesc(event: GitReviewEvent): String { + val (state, username) = if (event.reviewer != null) { + event.reviewer!!.state to event.reviewer!!.reviewer.name + } else { + event.state to getUsername(event) + } return I18Variable( - code = getI18Code(event), + code = getI18Code(state), params = listOf( "${event.repository.homepage}/reviews/${event.iid}", event.iid, - getUsername(event) + username ) ).toJsonStr() } @@ -239,7 +244,7 @@ class TGitReviewTriggerHandler( } } - private fun getI18Code(event: GitReviewEvent) = when (event.state) { + private fun getI18Code(state: String) = when (state) { GitReviewEvent.ACTION_APPROVED -> WebhookI18nConstants.TGIT_REVIEW_APPROVED_EVENT_DESC GitReviewEvent.ACTION_APPROVING -> WebhookI18nConstants.TGIT_REVIEW_APPROVING_EVENT_DESC GitReviewEvent.ACTION_CHANGE_DENIED -> WebhookI18nConstants.TGIT_REVIEW_CHANGE_DENIED_EVENT_DESC diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index 1f65639ea38..ff0c2ed7168 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -67,12 +67,7 @@ import com.tencent.devops.process.pojo.webhook.PipelineWebhook import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber import com.tencent.devops.process.service.scm.ScmProxyService import com.tencent.devops.repository.api.ServiceRepositoryResource -import com.tencent.devops.repository.pojo.CodeGitRepository -import com.tencent.devops.repository.pojo.CodeGitlabRepository -import com.tencent.devops.repository.pojo.CodeP4Repository -import com.tencent.devops.repository.pojo.CodeSvnRepository -import com.tencent.devops.repository.pojo.CodeTGitRepository -import com.tencent.devops.repository.pojo.Repository +import com.tencent.devops.repository.pojo.* import org.jooq.DSLContext import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -736,6 +731,7 @@ class PipelineWebhookService @Autowired constructor( is CodeGitlabRepository -> repository.gitProjectId is CodeSvnRepository -> repository.url is CodeP4Repository -> repository.url + is GithubRepository -> repository.gitProjectId else -> "" }?.toString() ?: "" } From e0e4814eb735ef2b6bda8bc39122f754ced4546a Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 11 Oct 2023 15:25:59 +0800 Subject: [PATCH 065/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/service/PipelineWebhookService.kt | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index ff0c2ed7168..3e5e4121fba 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -686,14 +686,19 @@ class PipelineWebhookService @Autowired constructor( val repoSize = webhookList.size webhookList.forEach { with(it) { - val repositoryInfo = scmProxyService.getRepo( - it.projectId, - RepositoryConfig( - repositoryHashId = it.repoHashId, - repositoryName = it.repoName, - repositoryType = RepositoryType.valueOf(it.repositoryType) + val repositoryInfo = try { + scmProxyService.getRepo( + it.projectId, + RepositoryConfig( + repositoryHashId = it.repoHashId, + repositoryName = it.repoName, + repositoryType = RepositoryType.valueOf(it.repositoryType) + ) ) - ) + } catch (ignored: Exception) { + logger.warn("fail to get repository info", ignored) + null + } val model = getModel(it.projectId, it.pipelineId) if (model == null) { logger.info("$projectId|$pipelineId|model is null") @@ -715,7 +720,7 @@ class PipelineWebhookService @Autowired constructor( projectId = it.projectId, pipelineId = it.pipelineId, taskId = it.taskId, - repoHashId = repositoryInfo.repoHashId + repoHashId = repositoryInfo?.repoHashId ) } } From 7f51458a6a445e9837379949f4bc3792e5385cc3 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 11 Oct 2023 15:39:23 +0800 Subject: [PATCH 066/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/engine/service/PipelineWebhookService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index 3e5e4121fba..cb6b5912d42 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -692,7 +692,7 @@ class PipelineWebhookService @Autowired constructor( RepositoryConfig( repositoryHashId = it.repoHashId, repositoryName = it.repoName, - repositoryType = RepositoryType.valueOf(it.repositoryType) + repositoryType = RepositoryType.valueOf(it.repoType) ) ) } catch (ignored: Exception) { From 4be19ed70afa64dd37bd688e6a780c19ba20b3cb Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 12 Oct 2023 15:19:45 +0800 Subject: [PATCH 067/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 刷新webhook eventSource和eventType字段 --- .../process/pojo/webhook/PipelineWebhook.kt | 2 + .../process/engine/dao/PipelineWebhookDao.kt | 10 +- .../process/service/scm/ScmProxyService.kt | 24 +++-- .../engine/service/PipelineWebhookService.kt | 91 ++++++++++--------- 4 files changed, 71 insertions(+), 56 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhook.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhook.kt index 5d2e202d48e..b337afedd1c 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhook.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhook.kt @@ -54,6 +54,8 @@ data class PipelineWebhook( val taskId: String? = null, @ApiModelProperty("事件类型", required = false) var eventType: String? = null, + @ApiModelProperty("事件源,代码库hashId", required = false) + var eventSource: String? = null, @ApiModelProperty("事件源外联Id", required = false) var externalId: String? = null ) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt index 87b76c3d109..b3ba4243102 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt @@ -57,6 +57,7 @@ class PipelineWebhookDao { PROJECT_NAME, TASK_ID, EVENT_TYPE, + EVENT_SOURCE, EXTERNAL_ID ) .values( @@ -69,6 +70,7 @@ class PipelineWebhookDao { projectName, taskId, eventType, + eventSource, externalId ) .onDuplicateKeyUpdate() @@ -76,8 +78,9 @@ class PipelineWebhookDao { .set(REPO_HASH_ID, repoHashId) .set(REPO_NAME, repoName) .set(PROJECT_NAME, projectName) - .set(EXTERNAL_ID, externalId) .set(EVENT_TYPE, eventType) + .set(EVENT_SOURCE, eventSource) + .set(EXTERNAL_ID, externalId) .execute() } } @@ -246,6 +249,7 @@ class PipelineWebhookDao { } dslContext.selectFrom(this) .where(conditions) + .orderBy(PROJECT_ID.desc()) .limit(offset, limit) .fetch() } @@ -253,7 +257,7 @@ class PipelineWebhookDao { fun updateWebhookEventInfo( dslContext: DSLContext, - repoHashId: String?, + eventSource: String?, eventType: String, externalId: String, pipelineId: String, @@ -262,7 +266,7 @@ class PipelineWebhookDao { ) { return with(T_PIPELINE_WEBHOOK) { dslContext.update(this) - .set(REPO_HASH_ID, repoHashId) + .set(EVENT_SOURCE, eventSource) .set(EVENT_TYPE, eventType) .set(EXTERNAL_ID, externalId) .where(PROJECT_ID.eq(projectId)) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/scm/ScmProxyService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/scm/ScmProxyService.kt index 6f7ea35c927..52268e7edf2 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/scm/ScmProxyService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/scm/ScmProxyService.kt @@ -450,7 +450,11 @@ class ScmProxyService @Autowired constructor(private val client: Client) { return repo } - fun addGitlabWebhook(projectId: String, repositoryConfig: RepositoryConfig, codeEventType: CodeEventType?): String { + fun addGitlabWebhook( + projectId: String, + repositoryConfig: RepositoryConfig, + codeEventType: CodeEventType? + ): Repository { checkRepoID(repositoryConfig) val repo = getRepo(projectId, repositoryConfig) as? CodeGitlabRepository ?: throw ErrorCodeException(errorCode = GITLAB_INVALID) @@ -466,10 +470,10 @@ class ScmProxyService @Autowired constructor(private val client: Client) { userName = repo.userName, event = convertEvent(codeEventType) ) - return repo.projectName + return repo } - fun addSvnWebhook(projectId: String, repositoryConfig: RepositoryConfig): String { + fun addSvnWebhook(projectId: String, repositoryConfig: RepositoryConfig): Repository { checkRepoID(repositoryConfig) val repo = getRepo(projectId, repositoryConfig) as? CodeSvnRepository ?: throw ErrorCodeException(errorCode = ProcessMessageCode.SVN_INVALID) @@ -485,10 +489,14 @@ class ScmProxyService @Autowired constructor(private val client: Client) { userName = credential.username, event = null ) - return repo.projectName + return repo } - fun addTGitWebhook(projectId: String, repositoryConfig: RepositoryConfig, codeEventType: CodeEventType?): String { + fun addTGitWebhook( + projectId: String, + repositoryConfig: RepositoryConfig, + codeEventType: CodeEventType? + ): Repository { checkRepoID(repositoryConfig) val repo = getRepo(projectId, repositoryConfig) as? CodeTGitRepository ?: throw ErrorCodeException(defaultMessage = "TGit", errorCode = ProcessMessageCode.TGIT_INVALID) @@ -519,7 +527,7 @@ class ScmProxyService @Autowired constructor(private val client: Client) { event = convertEvent(codeEventType) ) } - return repo.projectName + return repo } private fun convertEvent(codeEventType: CodeEventType?): String? { @@ -540,7 +548,7 @@ class ScmProxyService @Autowired constructor(private val client: Client) { projectId: String, repositoryConfig: RepositoryConfig, codeEventType: CodeEventType? - ): String { + ): Repository { checkRepoID(repositoryConfig) val repo = getRepo(projectId, repositoryConfig) as? CodeP4Repository ?: throw ErrorCodeException(errorCode = ProcessMessageCode.P4_INVALID) @@ -556,7 +564,7 @@ class ScmProxyService @Autowired constructor(private val client: Client) { userName = credential.username, event = codeEventType?.name ) - return repo.projectName + return repo } fun addGithubCheckRuns( diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index 3e5e4121fba..90a93de1bbf 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -28,6 +28,7 @@ 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 @@ -67,15 +68,18 @@ import com.tencent.devops.process.pojo.webhook.PipelineWebhook import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber import com.tencent.devops.process.service.scm.ScmProxyService import com.tencent.devops.repository.api.ServiceRepositoryResource -import com.tencent.devops.repository.pojo.* +import com.tencent.devops.repository.pojo.CodeGitRepository +import com.tencent.devops.repository.pojo.CodeGitlabRepository +import com.tencent.devops.repository.pojo.CodeP4Repository +import com.tencent.devops.repository.pojo.CodeSvnRepository +import com.tencent.devops.repository.pojo.CodeTGitRepository +import com.tencent.devops.repository.pojo.GithubRepository +import com.tencent.devops.repository.pojo.Repository import org.jooq.DSLContext import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service import java.util.concurrent.Executors -import java.util.concurrent.LinkedBlockingQueue -import java.util.concurrent.ThreadPoolExecutor -import java.util.concurrent.TimeUnit /** * 流水线webhook存储服务 @@ -173,10 +177,6 @@ class PipelineWebhookService @Autowired constructor( // 新增流水线时,模版里配置的代码库是变量或者当前项目下不存在,不需创建webhook try { val repo = scmProxyService.getRepo(pipelineWebhook.projectId, repositoryConfig) - // 补充代码库hashId - pipelineWebhook.repoHashId = repo.repoHashId - pipelineWebhook.eventType = codeEventType?.name ?: "" - pipelineWebhook.externalId = getExternalId(repo) } catch (e: Exception) { logger.info("skip save Webhook[$pipelineWebhook]: ${e.message}") continueFlag = false @@ -184,15 +184,17 @@ class PipelineWebhookService @Autowired constructor( } if (continueFlag) { - val projectName = registerWebhook( + val repository = registerWebhook( pipelineWebhook = pipelineWebhook, repositoryConfig = repositoryConfig, codeEventType = codeEventType, version = version ) - logger.info("add $projectName webhook to [$pipelineWebhook]") - if (!projectName.isNullOrBlank()) { - pipelineWebhook.projectName = getProjectName(projectName) + if (repository != null) { + pipelineWebhook.eventSource = repository.repoHashId + pipelineWebhook.eventType = codeEventType?.name ?: "" + pipelineWebhook.externalId = getExternalId(repository) + pipelineWebhook.projectName = getProjectName(repository.projectName) pipelineWebhookDao.save( dslContext = dslContext, pipelineWebhook = pipelineWebhook @@ -206,7 +208,7 @@ class PipelineWebhookService @Autowired constructor( repositoryConfig: RepositoryConfig, codeEventType: CodeEventType?, version: String - ): String? { + ): Repository? { // 防止同一个仓库注册多个相同事件的webhook val redisLock = RedisLock( redisOperation = redisOperation, @@ -221,18 +223,17 @@ class PipelineWebhookService @Autowired constructor( projectId = pipelineWebhook.projectId, repositoryConfig = repositoryConfig, codeEventType = codeEventType - ).projectName + ) ScmType.CODE_SVN -> scmProxyService.addSvnWebhook(pipelineWebhook.projectId, repositoryConfig) ScmType.CODE_GITLAB -> scmProxyService.addGitlabWebhook(pipelineWebhook.projectId, repositoryConfig, codeEventType) ScmType.GITHUB -> { - val repo = client.get(ServiceRepositoryResource::class).get( + client.get(ServiceRepositoryResource::class).get( pipelineWebhook.projectId, repositoryConfig.getURLEncodeRepositoryId(), repositoryConfig.repositoryType ).data!! - repo.projectName } ScmType.CODE_TGIT -> { scmProxyService.addTGitWebhook(pipelineWebhook.projectId, repositoryConfig, codeEventType) @@ -244,7 +245,7 @@ class PipelineWebhookService @Autowired constructor( repositoryConfig.getURLEncodeRepositoryId(), repositoryConfig.repositoryType ).data!! - repo.projectName + repo } else { scmProxyService.addP4Webhook( projectId = pipelineWebhook.projectId, @@ -526,7 +527,7 @@ class PipelineWebhookService @Autowired constructor( WebhookElementParams( repositoryConfig = realRepositoryConfig, scmType = ScmType.GITHUB, - eventType = null + eventType = element.eventType ) is CodeGitlabWebHookTriggerElement -> WebhookElementParams( @@ -538,7 +539,7 @@ class PipelineWebhookService @Autowired constructor( WebhookElementParams( repositoryConfig = realRepositoryConfig, scmType = ScmType.CODE_SVN, - eventType = null + eventType = CodeEventType.POST_COMMIT ) is CodeTGitWebHookTriggerElement -> WebhookElementParams( @@ -650,15 +651,7 @@ class PipelineWebhookService @Autowired constructor( fun updateWebhookEventInfo() { val startTime = System.currentTimeMillis() - val threadPoolExecutor = ThreadPoolExecutor( - 1, - 1, - 0, - TimeUnit.SECONDS, - LinkedBlockingQueue(1), - Executors.defaultThreadFactory(), - ThreadPoolExecutor.AbortPolicy() - ) + val threadPoolExecutor = Executors.newSingleThreadExecutor() threadPoolExecutor.submit { logger.info("PipelineWebhookService:begin updateWebhookEventInfo threadPoolExecutor") try { @@ -667,8 +660,7 @@ class PipelineWebhookService @Autowired constructor( logger.warn("PipelineWebhookService:updateWebhookEventInfo failed | $e ") } finally { threadPoolExecutor.shutdown() - logger.info("PipelineWebhookService:finish updateWebhookEventInfo") - logger.info("updateWebhookEventInfo time cost: ${System.currentTimeMillis() - startTime}") + logger.info("updateWebhookEventInfo finish cost: ${System.currentTimeMillis() - startTime}") } } } @@ -676,6 +668,9 @@ class PipelineWebhookService @Autowired constructor( private fun updateWebhookEventInfoTask() { var offset = 0 val limit = 1000 + val repoCache = CacheBuilder.newBuilder() + .maximumSize(1000) + .build() do { val webhookList = pipelineWebhookDao.listWebhook( dslContext = dslContext, @@ -686,18 +681,24 @@ class PipelineWebhookService @Autowired constructor( val repoSize = webhookList.size webhookList.forEach { with(it) { - val repositoryInfo = try { - scmProxyService.getRepo( - it.projectId, - RepositoryConfig( - repositoryHashId = it.repoHashId, - repositoryName = it.repoName, - repositoryType = RepositoryType.valueOf(it.repositoryType) - ) + val repositoryConfig = RepositoryConfig( + repositoryHashId = it.repoHashId, + repositoryName = it.repoName, + repositoryType = RepositoryType.valueOf(it.repositoryType) + ) + val repository = repoCache.get("${it.projectId}_${repositoryConfig.getRepositoryId()}") { + try { + scmProxyService.getRepo(projectId = it.projectId, repositoryConfig = repositoryConfig) + } catch (ignored: Exception) { + logger.warn("fail to get repository info", ignored) + null + } + } + if (repository != null && it.projectName != repository.projectName) { + logger.info( + "webhook projectName different from repo projectName|" + + "webhook:${it.projectName}|repo:${repository.projectName}" ) - } catch (ignored: Exception) { - logger.warn("fail to get repository info", ignored) - null } val model = getModel(it.projectId, it.pipelineId) if (model == null) { @@ -716,11 +717,11 @@ class PipelineWebhookService @Autowired constructor( pipelineWebhookDao.updateWebhookEventInfo( dslContext = dslContext, eventType = webhookElementParams.eventType?.name ?: "", - externalId = getExternalId(repositoryInfo), + externalId = getExternalId(repository), projectId = it.projectId, pipelineId = it.pipelineId, taskId = it.taskId, - repoHashId = repositoryInfo?.repoHashId + eventSource = repository?.repoHashId ) } } @@ -734,8 +735,8 @@ class PipelineWebhookService @Autowired constructor( is CodeGitRepository -> repository.gitProjectId is CodeTGitRepository -> repository.gitProjectId is CodeGitlabRepository -> repository.gitProjectId - is CodeSvnRepository -> repository.url - is CodeP4Repository -> repository.url + is CodeSvnRepository -> repository.projectName + is CodeP4Repository -> repository.projectName is GithubRepository -> repository.gitProjectId else -> "" }?.toString() ?: "" From 040b20e43fc83354fd5cdf392295e4f335054d27 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 12 Oct 2023 15:52:49 +0800 Subject: [PATCH 068/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 刷新webhook eventSource和eventType字段 --- .../devops/process/engine/service/PipelineWebhookService.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index 90a93de1bbf..c79ccc2dbe0 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -656,8 +656,8 @@ class PipelineWebhookService @Autowired constructor( logger.info("PipelineWebhookService:begin updateWebhookEventInfo threadPoolExecutor") try { updateWebhookEventInfoTask() - } catch (e: Exception) { - logger.warn("PipelineWebhookService:updateWebhookEventInfo failed | $e ") + } catch (ignored: Exception) { + logger.warn("PipelineWebhookService:updateWebhookEventInfo failed", ignored) } finally { threadPoolExecutor.shutdown() logger.info("updateWebhookEventInfo finish cost: ${System.currentTimeMillis() - startTime}") @@ -684,7 +684,7 @@ class PipelineWebhookService @Autowired constructor( val repositoryConfig = RepositoryConfig( repositoryHashId = it.repoHashId, repositoryName = it.repoName, - repositoryType = RepositoryType.valueOf(it.repositoryType) + repositoryType = RepositoryType.valueOf(it.repoType) ) val repository = repoCache.get("${it.projectId}_${repositoryConfig.getRepositoryId()}") { try { From abd4f92485580a78748825fec8926d25cd7875bb Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 16 Oct 2023 18:13:51 +0800 Subject: [PATCH 069/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/pojo/trigger/PipelineTriggerType.kt | 4 +++- .../api/UserPipelineTriggerEventResourceImpl.kt | 1 + .../process/trigger/PipelineTriggerEventService.kt | 11 ++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt index e4c941dd7cd..11e66816f14 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt @@ -70,6 +70,8 @@ enum class PipelineTriggerType { REMOTE; companion object { + // 通用触发类型 + private val commonTriggerTypes = listOf(MANUAL, TIME_TRIGGER, REMOTE) fun toMap( scmType: ScmType?, @@ -77,7 +79,7 @@ enum class PipelineTriggerType { ): List { return PipelineTriggerType.values().filter { scmType == null || scmType.name == it.name - }.map { + }.plus(commonTriggerTypes).map { IdValue( id = it.name, value = I18nUtil.getCodeLanMessage( diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt index e77f05dd19f..94951c183da 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt @@ -89,6 +89,7 @@ class UserPipelineTriggerEventResourceImpl( ): Result> { return Result( pipelineTriggerEventService.listTriggerEvent( + userId = userId, projectId = projectId, pipelineId = pipelineId, eventType = eventType, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 6e3b1e865df..20021bf42fe 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -108,6 +108,7 @@ class PipelineTriggerEventService @Autowired constructor( } fun listTriggerEvent( + userId: String, projectId: String, pipelineId: String, eventType: String?, @@ -142,7 +143,15 @@ class PipelineTriggerEventService @Autowired constructor( endTime = endTime, 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 + } return SQLPage(count = count, records = records) } From 41dfbb7254664e02d29c8a99cfa66b1beecb178b Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 17 Oct 2023 10:30:10 +0800 Subject: [PATCH 070/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v4/ApigwPipelineWebhookResourceV4.kt | 36 ------------------- .../v4/ApigwPipelineWebhookResourceV4Impl.kt | 29 --------------- 2 files changed, 65 deletions(-) diff --git a/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v4/ApigwPipelineWebhookResourceV4.kt b/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v4/ApigwPipelineWebhookResourceV4.kt index d3672728efa..ae41614eae3 100644 --- a/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v4/ApigwPipelineWebhookResourceV4.kt +++ b/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v4/ApigwPipelineWebhookResourceV4.kt @@ -30,10 +30,8 @@ package com.tencent.devops.openapi.api.apigw.v4 import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_APP_CODE import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_APP_CODE_DEFAULT_VALUE import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_USER_ID -import com.tencent.devops.common.api.model.SQLPage import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.process.pojo.webhook.PipelineWebhook -import com.tencent.devops.process.pojo.webhook.PipelineWebhookBuildLogDetail import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation import io.swagger.annotations.ApiParam @@ -77,38 +75,4 @@ interface ApigwPipelineWebhookResourceV4 { @QueryParam("pageSize") pageSize: Int? ): Result> - - @ApiOperation( - "获取流水线的webhook构建日志列表", - tags = ["v4_user_pipeline_webhook_build_log", "v4_app_pipeline_webhook_build_log"] - ) - @GET - @Path("/pipeline_webhook_build_log_detail") - fun listPipelineWebhookBuildLog( - @ApiParam(value = "appCode", required = true, defaultValue = AUTH_HEADER_DEVOPS_APP_CODE_DEFAULT_VALUE) - @HeaderParam(AUTH_HEADER_DEVOPS_APP_CODE) - appCode: String?, - @ApiParam(value = "apigw Type", required = true) - @PathParam("apigwType") - apigwType: String?, - @ApiParam("userId", required = true) - @HeaderParam(AUTH_HEADER_DEVOPS_USER_ID) - userId: String, - @PathParam("projectId") - projectId: String, - @QueryParam("pipelineId") - pipelineId: String, - @ApiParam("仓库名", required = false) - @QueryParam("repoName") - repoName: String?, - @ApiParam("commitId", required = false) - @QueryParam("commitId") - commitId: String?, - @ApiParam("页码", required = false) - @QueryParam("page") - page: Int?, - @ApiParam("每页大小", required = false) - @QueryParam("pageSize") - pageSize: Int? - ): Result?> } diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwPipelineWebhookResourceV4Impl.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwPipelineWebhookResourceV4Impl.kt index dfd9811f751..252df956732 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwPipelineWebhookResourceV4Impl.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwPipelineWebhookResourceV4Impl.kt @@ -27,14 +27,12 @@ package com.tencent.devops.openapi.resources.apigw.v4 -import com.tencent.devops.common.api.model.SQLPage import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.common.client.Client import com.tencent.devops.common.web.RestResource import com.tencent.devops.openapi.api.apigw.v4.ApigwPipelineWebhookResourceV4 import com.tencent.devops.process.api.service.ServiceScmWebhookResource import com.tencent.devops.process.pojo.webhook.PipelineWebhook -import com.tencent.devops.process.pojo.webhook.PipelineWebhookBuildLogDetail import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -63,33 +61,6 @@ class ApigwPipelineWebhookResourceV4Impl @Autowired constructor( ) } - override fun listPipelineWebhookBuildLog( - appCode: String?, - apigwType: String?, - userId: String, - projectId: String, - pipelineId: String, - repoName: String?, - commitId: String?, - page: Int?, - pageSize: Int? - ): Result?> { - logger.info( - "OPENAPI_PIPELINE_WEBHOOK_V4|$userId|list pipeline webhook build log|$projectId|$pipelineId" + - "|$repoName|$commitId|$page|$pageSize" - ) - return client.get(ServiceScmWebhookResource::class) - .listPipelineWebhookBuildLog( - userId = userId, - projectId = projectId, - pipelineId = pipelineId, - repoName = repoName, - commitId = commitId, - page = page, - pageSize = pageSize - ) - } - companion object { private val logger = LoggerFactory.getLogger(ApigwPipelineWebhookResourceV4Impl::class.java) } From d0a2ce66d1da557bbf0e15718c3cafda61979029 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Sat, 21 Oct 2023 19:53:27 +0800 Subject: [PATCH 071/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/engine/dao/PipelineWebhookDao.kt | 23 ++--- .../engine/service/PipelineWebhookService.kt | 95 +++++++++++-------- 2 files changed, 65 insertions(+), 53 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt index b3ba4243102..85b09b3d27c 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt @@ -234,24 +234,21 @@ class PipelineWebhookDao { }?.map { convert(it) } } - fun listWebhook( + fun listPipelines( dslContext: DSLContext, - repositoryType: String?, offset: Int, limit: Int - ): Result { + ): List { return with(T_PIPELINE_WEBHOOK) { - val conditions = mutableListOf( - DELETE.eq(false) - ) - if (!repositoryType.isNullOrBlank()) { - conditions.add(REPOSITORY_TYPE.eq(repositoryType)) - } - dslContext.selectFrom(this) - .where(conditions) - .orderBy(PROJECT_ID.desc()) + dslContext.select(PROJECT_ID, PIPELINE_ID).from(this) + .where(DELETE.eq(false)) .limit(offset, limit) - .fetch() + .fetch().map { + PipelineWebhookSubscriber( + projectId = it.value1(), + pipelineId = it.value2() + ) + } } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index c79ccc2dbe0..73a6eb9c28f 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -671,64 +671,79 @@ class PipelineWebhookService @Autowired constructor( val repoCache = CacheBuilder.newBuilder() .maximumSize(1000) .build() + // 上一个更新的项目ID + var preProjectId: String? = null do { - val webhookList = pipelineWebhookDao.listWebhook( + val pipelines = pipelineWebhookDao.listPipelines( dslContext = dslContext, - repositoryType = null, limit = limit, offset = offset ) - val repoSize = webhookList.size - webhookList.forEach { - with(it) { - val repositoryConfig = RepositoryConfig( - repositoryHashId = it.repoHashId, - repositoryName = it.repoName, - repositoryType = RepositoryType.valueOf(it.repoType) - ) - val repository = repoCache.get("${it.projectId}_${repositoryConfig.getRepositoryId()}") { + pipelines.forEach { (projectId, pipelineId) -> + // 更改项目,清空代码库缓存 + if (preProjectId != null && preProjectId != projectId) { + repoCache.cleanUp() + } + preProjectId = projectId + val model = getModel(projectId, pipelineId) + if (model == null) { + logger.info("$projectId|$pipelineId|model is null") + return@forEach + } + val triggerContainer = model.stages[0].containers[0] as TriggerContainer + val params = triggerContainer.params.associate { param -> + param.id to param.defaultValue.toString() + } + val elementMap = + triggerContainer.elements.filterIsInstance().associateBy { it.id } + val pipelineWebhooks = pipelineWebhookDao.listWebhook( + dslContext = dslContext, + projectId = projectId, + pipelineId = pipelineId, + limit = limit, + offset = 0 + ) + pipelineWebhooks?.forEach webhook@{ webhook -> + if (webhook.taskId.isNullOrBlank()) return@webhook + val element = elementMap[webhook.taskId] ?: return@webhook + val webhookElementParams = getElementRepositoryConfig(element, variable = params) + ?: return@webhook + val elementRepositoryConfig = webhookElementParams.repositoryConfig + val webhookRepositoryConfig = getRepositoryConfig(webhook, params) + if (elementRepositoryConfig.getRepositoryId() != webhookRepositoryConfig.getRepositoryId()) { + logger.info( + "webhook repository config different from element repository config|" + + "webhook:${webhookRepositoryConfig}|element:${elementRepositoryConfig}" + ) + return@webhook + } + val repository = repoCache.get("${projectId}_${elementRepositoryConfig.getRepositoryId()}") { try { - scmProxyService.getRepo(projectId = it.projectId, repositoryConfig = repositoryConfig) + scmProxyService.getRepo(projectId = projectId, repositoryConfig = elementRepositoryConfig) } catch (ignored: Exception) { logger.warn("fail to get repository info", ignored) null } } - if (repository != null && it.projectName != repository.projectName) { + if (repository != null && webhook.projectName != repository.projectName) { logger.info( "webhook projectName different from repo projectName|" + - "webhook:${it.projectName}|repo:${repository.projectName}" + "webhook:${webhook.projectName}|repo:${repository.projectName}" ) } - val model = getModel(it.projectId, it.pipelineId) - if (model == null) { - logger.info("$projectId|$pipelineId|model is null") - return@forEach - } - val triggerContainer = model.stages[0].containers[0] as TriggerContainer - val params = triggerContainer.params.associate { param -> - param.id to param.defaultValue.toString() - } - val elements = triggerContainer.elements.filterIsInstance() - elements.forEach elements@{ element -> - run { - val webhookElementParams = getElementRepositoryConfig(element, variable = params) - ?: return@elements - pipelineWebhookDao.updateWebhookEventInfo( - dslContext = dslContext, - eventType = webhookElementParams.eventType?.name ?: "", - externalId = getExternalId(repository), - projectId = it.projectId, - pipelineId = it.pipelineId, - taskId = it.taskId, - eventSource = repository?.repoHashId - ) - } - } + pipelineWebhookDao.updateWebhookEventInfo( + dslContext = dslContext, + eventType = webhookElementParams.eventType?.name ?: "", + externalId = getExternalId(repository), + projectId = projectId, + pipelineId = pipelineId, + taskId = webhook.taskId!!, + eventSource = repository?.repoHashId + ) } } offset += limit - } while (repoSize == 1000) + } while (pipelines.size == 1000) } private fun getExternalId(repository: Repository?) = when (repository) { From eb58ece26c4951da748db8c4f7ccc59f21769fc5 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Sat, 21 Oct 2023 20:28:45 +0800 Subject: [PATCH 072/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/service/PipelineWebhookService.kt | 74 ++++++++++--------- .../2010_ci_process-update_v1.10_mysql.sql | 19 ----- .../2020_ci_process-update_v2.0_mysql.sql | 28 +++++++ 3 files changed, 69 insertions(+), 52 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index 73a6eb9c28f..f338c0f31ae 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -704,42 +704,50 @@ class PipelineWebhookService @Autowired constructor( offset = 0 ) pipelineWebhooks?.forEach webhook@{ webhook -> - if (webhook.taskId.isNullOrBlank()) return@webhook - val element = elementMap[webhook.taskId] ?: return@webhook - val webhookElementParams = getElementRepositoryConfig(element, variable = params) - ?: return@webhook - val elementRepositoryConfig = webhookElementParams.repositoryConfig - val webhookRepositoryConfig = getRepositoryConfig(webhook, params) - if (elementRepositoryConfig.getRepositoryId() != webhookRepositoryConfig.getRepositoryId()) { - logger.info( - "webhook repository config different from element repository config|" + - "webhook:${webhookRepositoryConfig}|element:${elementRepositoryConfig}" - ) - return@webhook - } - val repository = repoCache.get("${projectId}_${elementRepositoryConfig.getRepositoryId()}") { - try { - scmProxyService.getRepo(projectId = projectId, repositoryConfig = elementRepositoryConfig) - } catch (ignored: Exception) { - logger.warn("fail to get repository info", ignored) - null + try { + if (webhook.taskId.isNullOrBlank()) return@webhook + val element = elementMap[webhook.taskId] ?: return@webhook + val webhookElementParams = getElementRepositoryConfig(element, variable = params) + ?: return@webhook + val elementRepositoryConfig = webhookElementParams.repositoryConfig + val webhookRepositoryConfig = getRepositoryConfig(webhook, params) + if (elementRepositoryConfig.getRepositoryId() != webhookRepositoryConfig.getRepositoryId()) { + logger.info( + "webhook repository config different from element repository config|" + + "webhook:${webhookRepositoryConfig}|element:${elementRepositoryConfig}" + ) + return@webhook } - } - if (repository != null && webhook.projectName != repository.projectName) { - logger.info( - "webhook projectName different from repo projectName|" + - "webhook:${webhook.projectName}|repo:${repository.projectName}" + val repository = + repoCache.get("${projectId}_${elementRepositoryConfig.getRepositoryId()}") { + try { + scmProxyService.getRepo( + projectId = projectId, + repositoryConfig = elementRepositoryConfig + ) + } catch (ignored: Exception) { + logger.warn("fail to get repository info", ignored) + null + } + } + if (repository != null && webhook.projectName != repository.projectName) { + logger.info( + "webhook projectName different from repo projectName|" + + "webhook:${webhook.projectName}|repo:${repository.projectName}" + ) + } + pipelineWebhookDao.updateWebhookEventInfo( + dslContext = dslContext, + eventType = webhookElementParams.eventType?.name ?: "", + externalId = getExternalId(repository), + projectId = projectId, + pipelineId = pipelineId, + taskId = webhook.taskId!!, + eventSource = repository?.repoHashId ) + } catch (ignored: Exception) { + logger.info("update webhook event info error|${webhook}", ignored) } - pipelineWebhookDao.updateWebhookEventInfo( - dslContext = dslContext, - eventType = webhookElementParams.eventType?.name ?: "", - externalId = getExternalId(repository), - projectId = projectId, - pipelineId = pipelineId, - taskId = webhook.taskId!!, - eventSource = repository?.repoHashId - ) } } offset += limit diff --git a/support-files/sql/2002_v1.x/2010_ci_process-update_v1.10_mysql.sql b/support-files/sql/2002_v1.x/2010_ci_process-update_v1.10_mysql.sql index 28f9d33f3f9..aec14e3d3fc 100644 --- a/support-files/sql/2002_v1.x/2010_ci_process-update_v1.10_mysql.sql +++ b/support-files/sql/2002_v1.x/2010_ci_process-update_v1.10_mysql.sql @@ -21,25 +21,6 @@ IF NOT EXISTS(SELECT 1 IDX_SEARCH_ID (`RESOURCE_TYPE`, `PROJECT_ID`, `RESOURCE_ID`); END IF; - - IF NOT EXISTS(SELECT 1 - FROM information_schema.COLUMNS - WHERE TABLE_SCHEMA = db - AND TABLE_NAME = 'T_PIPELINE_WEBHOOK' - AND COLUMN_NAME = 'EVENT_TYPE') THEN - ALTER TABLE `T_PIPELINE_WEBHOOK` - ADD COLUMN `EVENT_TYPE` varchar(32) DEFAULT null COMMENT '事件类型'; - END IF; - - IF NOT EXISTS(SELECT 1 - FROM information_schema.COLUMNS - WHERE TABLE_SCHEMA = db - AND TABLE_NAME = 'T_PIPELINE_WEBHOOK' - AND COLUMN_NAME = 'EXTERNAL_ID') THEN - ALTER TABLE `T_PIPELINE_WEBHOOK` - ADD COLUMN `EXTERNAL_ID` varchar(32) DEFAULT null COMMENT 'webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port'; - END IF; - COMMIT; END DELIMITER ; diff --git a/support-files/sql/2003_v2.x/2020_ci_process-update_v2.0_mysql.sql b/support-files/sql/2003_v2.x/2020_ci_process-update_v2.0_mysql.sql index 06f21a34930..3c80658d9a4 100644 --- a/support-files/sql/2003_v2.x/2020_ci_process-update_v2.0_mysql.sql +++ b/support-files/sql/2003_v2.x/2020_ci_process-update_v2.0_mysql.sql @@ -33,6 +33,34 @@ BEGIN ADD CONSTRAINT TASK_EXECUTE_COUNT UNIQUE (`PROJECT_ID`,`BUILD_ID`,`TASK_ID`,`EXECUTE_COUNT`); END IF; + IF NOT EXISTS(SELECT 1 + FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = db + AND TABLE_NAME = 'T_PIPELINE_WEBHOOK' + AND COLUMN_NAME = 'EVENT_TYPE') THEN + ALTER TABLE `T_PIPELINE_WEBHOOK` + ADD COLUMN `EVENT_TYPE` varchar(32) DEFAULT null COMMENT '事件类型'; + END IF; + + IF NOT EXISTS(SELECT 1 + FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = db + AND TABLE_NAME = 'T_PIPELINE_WEBHOOK' + AND COLUMN_NAME = 'EXTERNAL_ID') THEN + ALTER TABLE `T_PIPELINE_WEBHOOK` + ADD COLUMN `EXTERNAL_ID` varchar(32) DEFAULT null COMMENT 'webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port'; + END IF; + + IF NOT EXISTS(SELECT 1 + FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = db + AND TABLE_NAME = 'T_PIPELINE_WEBHOOK' + AND COLUMN_NAME = 'REPOSITORY_HASH_ID') THEN + ALTER TABLE `T_PIPELINE_WEBHOOK` + ADD COLUMN `REPOSITORY_HASH_ID` varchar(64) null comment '代码库hashId'; + END IF; + + COMMIT; END DELIMITER ; From 11db4d9343071608a5c1d0e6d57ff666dbb4760d Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Sat, 21 Oct 2023 20:42:51 +0800 Subject: [PATCH 073/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/pojo/webhook/PipelineWebhook.kt | 6 +++--- .../devops/process/engine/dao/PipelineWebhookDao.kt | 10 +++++----- .../process/engine/service/PipelineWebhookService.kt | 4 ++-- support-files/sql/1001_ci_process_ddl_mysql.sql | 1 + 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhook.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhook.kt index b337afedd1c..609b2d58ec9 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhook.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhook.kt @@ -42,7 +42,7 @@ data class PipelineWebhook( val repositoryType: ScmType, @ApiModelProperty("代码库标识类型, ID 代码库HashId / NAME 别名", required = false) val repoType: RepositoryType?, - @ApiModelProperty("代码库HashId,repoHashId 与 repoName 不能同时为空,如果两个都不为空就用repoName", required = false) + @ApiModelProperty("插件配置的代码库HashId,repoHashId与repoName 不能同时为空,如果两个都不为空就用repoName", required = false) var repoHashId: String?, // repoHashId 与 repoName 不能同时为空,如果两个都不为空就用repoName @ApiModelProperty("代码库别名", required = false) val repoName: String?, @@ -54,8 +54,8 @@ data class PipelineWebhook( val taskId: String? = null, @ApiModelProperty("事件类型", required = false) var eventType: String? = null, - @ApiModelProperty("事件源,代码库hashId", required = false) - var eventSource: String? = null, + @ApiModelProperty("代码库hashId,插件配置解析后的代码库ID", required = false) + var repositoryHashId: String? = null, @ApiModelProperty("事件源外联Id", required = false) var externalId: String? = null ) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt index 85b09b3d27c..83e04a25cd4 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt @@ -57,7 +57,7 @@ class PipelineWebhookDao { PROJECT_NAME, TASK_ID, EVENT_TYPE, - EVENT_SOURCE, + REPOSITORY_HASH_ID, EXTERNAL_ID ) .values( @@ -70,7 +70,7 @@ class PipelineWebhookDao { projectName, taskId, eventType, - eventSource, + repositoryHashId, externalId ) .onDuplicateKeyUpdate() @@ -79,7 +79,7 @@ class PipelineWebhookDao { .set(REPO_NAME, repoName) .set(PROJECT_NAME, projectName) .set(EVENT_TYPE, eventType) - .set(EVENT_SOURCE, eventSource) + .set(REPOSITORY_HASH_ID, repositoryHashId) .set(EXTERNAL_ID, externalId) .execute() } @@ -254,7 +254,7 @@ class PipelineWebhookDao { fun updateWebhookEventInfo( dslContext: DSLContext, - eventSource: String?, + repositoryHashId: String?, eventType: String, externalId: String, pipelineId: String, @@ -263,7 +263,7 @@ class PipelineWebhookDao { ) { return with(T_PIPELINE_WEBHOOK) { dslContext.update(this) - .set(EVENT_SOURCE, eventSource) + .set(REPOSITORY_HASH_ID, repositoryHashId) .set(EVENT_TYPE, eventType) .set(EXTERNAL_ID, externalId) .where(PROJECT_ID.eq(projectId)) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index f338c0f31ae..749741478fa 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -191,7 +191,7 @@ class PipelineWebhookService @Autowired constructor( version = version ) if (repository != null) { - pipelineWebhook.eventSource = repository.repoHashId + pipelineWebhook.repositoryHashId = repository.repoHashId pipelineWebhook.eventType = codeEventType?.name ?: "" pipelineWebhook.externalId = getExternalId(repository) pipelineWebhook.projectName = getProjectName(repository.projectName) @@ -743,7 +743,7 @@ class PipelineWebhookService @Autowired constructor( projectId = projectId, pipelineId = pipelineId, taskId = webhook.taskId!!, - eventSource = repository?.repoHashId + repositoryHashId = repository?.repoHashId ) } catch (ignored: Exception) { logger.info("update webhook event info error|${webhook}", ignored) diff --git a/support-files/sql/1001_ci_process_ddl_mysql.sql b/support-files/sql/1001_ci_process_ddl_mysql.sql index 8cebd539254..25e9020b6c6 100644 --- a/support-files/sql/1001_ci_process_ddl_mysql.sql +++ b/support-files/sql/1001_ci_process_ddl_mysql.sql @@ -640,6 +640,7 @@ CREATE TABLE IF NOT EXISTS `T_PIPELINE_WEBHOOK` ( `DELETE` BIT(1) DEFAULT 0 COMMENT '是否删除', `EVENT_TYPE` varchar(32) DEFAULT NULL COMMENT '事件类型', `EXTERNAL_ID` varchar(32) DEFAULT NULL COMMENT 'webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port', + `REPOSITORY_HASH_ID` varchar(64) null comment '代码库hashId'; PRIMARY KEY (`ID`), UNIQUE KEY `UNI_INX_TPW_PROJECT_PIPELINE_TASK` (`PROJECT_ID`, `PIPELINE_ID`,`TASK_ID`), KEY `IDX_PROJECT_NAME_REPOSITORY_TYPE` (`PROJECT_NAME`, `REPOSITORY_TYPE`) From 8d9d73240b1262da276834f318ac686e42e66a4b Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Sat, 21 Oct 2023 21:16:10 +0800 Subject: [PATCH 074/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sql/5001_init_dml/5001_ci_project-init_dml_mysql.sql | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/support-files/sql/5001_init_dml/5001_ci_project-init_dml_mysql.sql b/support-files/sql/5001_init_dml/5001_ci_project-init_dml_mysql.sql index f5df44fbc91..2019dfcdac6 100755 --- a/support-files/sql/5001_init_dml/5001_ci_project-init_dml_mysql.sql +++ b/support-files/sql/5001_init_dml/5001_ci_project-init_dml_mysql.sql @@ -48,9 +48,8 @@ REPLACE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ( REPLACE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ('T_ATOM_INDEX_STATISTICS_DAILY', 1, 100, '插件每日指标数据ID管理'); REPLACE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ('AUTH_RESOURCE', 1, 100, '权限资源'); REPLACE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ('ATOM_MONITOR_DATA_DAILY', 1, 100, '插件每日监控数据ID管理'); -INSERT IGNORE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ('PIPELINE_WEBHOOK_EVENT', 1, 2000, '流水线webhook事件'); -INSERT IGNORE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ('PIPELINE_TRIGGER_EVENT', 1, 2000, '流水线触发事件'); -INSERT IGNORE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ('PIPELINE_TRIGGER_DETAIL', 1, 2000, '流水线触发详情'); +REPLACE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ('PIPELINE_TRIGGER_EVENT', 1, 2000, '流水线触发事件'); +REPLACE INTO `T_LEAF_ALLOC`(`BIZ_TAG`, `MAX_ID`, `STEP`, `DESCRIPTION`) VALUES ('PIPELINE_TRIGGER_DETAIL', 1, 2000, '流水线触发详情'); REPLACE INTO `T_I18N_MESSAGE` (`ID`, `MODULE_CODE`, `LANGUAGE`, `KEY`, `VALUE`, `CREATOR`, `MODIFIER`, `UPDATE_TIME`, `CREATE_TIME`) VALUES('12cfe76hgu9cn4047bfd4e6ddd0aaada', 'STORE', 'zh_CN', 'reason.e20897c838564d61b5af1a8c9c1d26d2.content', '只是试用下', 'system', 'system', '2023-06-26 10:59:20.561', '2023-06-26 10:59:47'); REPLACE INTO `T_I18N_MESSAGE` (`ID`, `MODULE_CODE`, `LANGUAGE`, `KEY`, `VALUE`, `CREATOR`, `MODIFIER`, `UPDATE_TIME`, `CREATE_TIME`) VALUES('13312a05cxt1468088bdb71637sc14ds', 'STORE', 'en_US', 'reason.e20897c838564d61b5af1a8c9c1d26d2.content', 'Just trying it out.', 'system', 'system', '2023-06-26 10:59:20.561', '2023-06-26 10:59:47'); From e214965294cd308326e4a7216bea4eff6b941177 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Sat, 21 Oct 2023 21:27:50 +0800 Subject: [PATCH 075/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/engine/service/PipelineWebhookService.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index 749741478fa..8114629f579 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -714,7 +714,7 @@ class PipelineWebhookService @Autowired constructor( if (elementRepositoryConfig.getRepositoryId() != webhookRepositoryConfig.getRepositoryId()) { logger.info( "webhook repository config different from element repository config|" + - "webhook:${webhookRepositoryConfig}|element:${elementRepositoryConfig}" + "webhook:$webhookRepositoryConfig|element:$elementRepositoryConfig" ) return@webhook } @@ -746,7 +746,7 @@ class PipelineWebhookService @Autowired constructor( repositoryHashId = repository?.repoHashId ) } catch (ignored: Exception) { - logger.info("update webhook event info error|${webhook}", ignored) + logger.info("update webhook event info error|$webhook", ignored) } } } From e950af874dda17830c69c96b58ec6a57a3296f63 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Sat, 21 Oct 2023 21:31:00 +0800 Subject: [PATCH 076/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- support-files/sql/1001_ci_process_ddl_mysql.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support-files/sql/1001_ci_process_ddl_mysql.sql b/support-files/sql/1001_ci_process_ddl_mysql.sql index 1b793f8fccd..1af5e2a6be1 100644 --- a/support-files/sql/1001_ci_process_ddl_mysql.sql +++ b/support-files/sql/1001_ci_process_ddl_mysql.sql @@ -642,7 +642,7 @@ CREATE TABLE IF NOT EXISTS `T_PIPELINE_WEBHOOK` ( `DELETE` BIT(1) DEFAULT 0 COMMENT '是否删除', `EVENT_TYPE` varchar(32) DEFAULT NULL COMMENT '事件类型', `EXTERNAL_ID` varchar(32) DEFAULT NULL COMMENT 'webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port', - `REPOSITORY_HASH_ID` varchar(64) null comment '代码库hashId'; + `REPOSITORY_HASH_ID` varchar(64) null comment '代码库hashId', PRIMARY KEY (`ID`), UNIQUE KEY `UNI_INX_TPW_PROJECT_PIPELINE_TASK` (`PROJECT_ID`, `PIPELINE_ID`,`TASK_ID`), KEY `IDX_PROJECT_NAME_REPOSITORY_TYPE` (`PROJECT_NAME`, `REPOSITORY_TYPE`) From 8cc764cde081061d67c99d0c4896c518983920a6 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Sat, 21 Oct 2023 21:52:12 +0800 Subject: [PATCH 077/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/pipeline/pojo/element/Element.kt | 5 - .../trigger/CodeGitGenericWebHookTrigger.kt | 101 ------------------ .../CodeGithubWebHookTriggerElement.kt | 2 + .../CodeGitlabWebHookTriggerElement.kt | 2 + .../trigger/CodeP4WebHookTriggerElement.kt | 2 + .../trigger/CodeSVNWebHookTriggerElement.kt | 2 + .../trigger/CodeTGitWebHookTriggerElement.kt | 2 + .../pipeline/utils/RepositoryConfigUtils.kt | 28 ----- .../pipeline/enums/EnvControlTaskTypeTest.kt | 2 - .../misc/dao/process/ProcessDataMigrateDao.kt | 27 ----- 10 files changed, 10 insertions(+), 163 deletions(-) delete mode 100644 src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitGenericWebHookTrigger.kt diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/Element.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/Element.kt index 0f38d87f1af..e4d19faa845 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/Element.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/Element.kt @@ -45,7 +45,6 @@ import com.tencent.devops.common.pipeline.pojo.element.market.MarketCheckImageEl import com.tencent.devops.common.pipeline.pojo.element.matrix.MatrixStatusElement import com.tencent.devops.common.pipeline.pojo.element.quality.QualityGateInElement import com.tencent.devops.common.pipeline.pojo.element.quality.QualityGateOutElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitGenericWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGithubWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitlabWebHookTriggerElement @@ -89,10 +88,6 @@ import io.swagger.annotations.ApiModelProperty JsonSubTypes.Type(value = QualityGateInElement::class, name = QualityGateInElement.classType), JsonSubTypes.Type(value = QualityGateOutElement::class, name = QualityGateOutElement.classType), JsonSubTypes.Type(value = CodeTGitWebHookTriggerElement::class, name = CodeTGitWebHookTriggerElement.classType), - JsonSubTypes.Type( - value = CodeGitGenericWebHookTriggerElement::class, - name = CodeGitGenericWebHookTriggerElement.classType - ), JsonSubTypes.Type(value = CodeP4WebHookTriggerElement::class, name = CodeP4WebHookTriggerElement.classType) ) @Suppress("ALL") diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitGenericWebHookTrigger.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitGenericWebHookTrigger.kt deleted file mode 100644 index 49abec0a545..00000000000 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitGenericWebHookTrigger.kt +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package com.tencent.devops.common.pipeline.pojo.element.trigger - -import com.tencent.devops.common.api.enums.RepositoryTypeNew -import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType -import io.swagger.annotations.ApiModel -import io.swagger.annotations.ApiModelProperty - -@ApiModel("Git通用事件触发", description = CodeGitGenericWebHookTriggerElement.classType) -data class CodeGitGenericWebHookTriggerElement( - @ApiModelProperty("任务名称", required = true) - override val name: String = "TGit变更触发", - @ApiModelProperty("id", required = false) - override var id: String? = null, - @ApiModelProperty("状态", required = false) - override var status: String? = null, - @ApiModelProperty("数据", required = true) - val data: CodeGitGenericWebHookTriggerData -) : WebHookTriggerElement(name, id, status) { - companion object { - const val classType = "codeGitGenericWebHookTrigger" - } - - override fun getClassType() = classType -} - -data class CodeGitGenericWebHookTriggerData( - @ApiModelProperty("Git通用事件触发数据", required = true) - val input: CodeGitGenericWebHookTriggerInput -) - -data class CodeGitGenericWebHookTriggerInput( - @ApiModelProperty("代码库类型", required = true) - val scmType: String, - @ApiModelProperty("代码库类型") - val repositoryType: RepositoryTypeNew? = null, - @ApiModelProperty("仓库ID", required = true) - val repositoryHashId: String?, - @ApiModelProperty("代码库名") - val repositoryName: String? = null, - @ApiModelProperty("代码库链接", required = true) - val repositoryUrl: String, - @ApiModelProperty("凭证ID", required = false) - val credentialId: String? = null, - @ApiModelProperty("凭证ID", required = false) - val token: String? = null, - @ApiModelProperty("触发事件", required = true) - val eventType: String = CodeEventType.PUSH.name, - @ApiModelProperty("hook地址,目前只对codecc开放", required = false) - var hookUrl: String? = null, - @ApiModelProperty("分支", required = false) - val branchName: String?, - @ApiModelProperty("用于排除的分支名", required = false) - val excludeBranchName: String?, - @ApiModelProperty("用于包含的路径", required = false) - val includePaths: String?, - @ApiModelProperty("相对路径", required = true) - val relativePath: String?, - @ApiModelProperty("用于排除的路径", required = false) - val excludePaths: String?, - @ApiModelProperty("用于排除的user id", required = false) - val excludeUsers: List?, - @ApiModelProperty("用户白名单", required = false) - val includeUsers: List?, - @ApiModelProperty("是否为block", required = false) - val block: Boolean?, - @ApiModelProperty("tag名称", required = false) - val tagName: String? = null, - @ApiModelProperty("用于排除的tag名称", required = false) - val excludeTagName: String? = null, - @ApiModelProperty("用于排除的源分支名称", required = false) - val excludeSourceBranchName: String? = null, - @ApiModelProperty("用于包含的源分支名称", required = false) - val includeSourceBranchName: String? = null -) diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt index c01b3075e81..bf648a0ba60 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt @@ -63,6 +63,8 @@ data class CodeGithubWebHookTriggerElement( override fun getClassType() = classType + override fun getTaskAtom() = taskAtom + override fun findFirstTaskIdByStartType(startType: StartType): String { return if (startType.name == StartType.WEB_HOOK.name) { this.id!! diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt index baacd99fe62..642eaceabe4 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt @@ -86,6 +86,8 @@ data class CodeGitlabWebHookTriggerElement( override fun getClassType() = classType + override fun getTaskAtom() = taskAtom + override fun findFirstTaskIdByStartType(startType: StartType): String { return if (startType.name == StartType.WEB_HOOK.name) { this.id!! diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt index e32775e87c9..3c247a3917a 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt @@ -51,6 +51,8 @@ data class CodeP4WebHookTriggerElement( override fun getClassType() = classType + override fun getTaskAtom() = taskAtom + override fun findFirstTaskIdByStartType(startType: StartType): String { return if (startType.name == StartType.WEB_HOOK.name) { this.id!! diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt index 27a89db06f0..8206107b4c1 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt @@ -65,6 +65,8 @@ data class CodeSVNWebHookTriggerElement( override fun getClassType() = classType + override fun getTaskAtom() = taskAtom + override fun findFirstTaskIdByStartType(startType: StartType): String { return if (startType.name == StartType.WEB_HOOK.name) { this.id!! diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt index 27efbe580fc..c72220db6c1 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt @@ -52,6 +52,8 @@ data class CodeTGitWebHookTriggerElement( override fun getClassType() = classType + override fun getTaskAtom() = taskAtom + override fun findFirstTaskIdByStartType(startType: StartType): String { return if (startType.name == StartType.WEB_HOOK.name) { this.id!! diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/utils/RepositoryConfigUtils.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/utils/RepositoryConfigUtils.kt index db6a41d50d2..11524943f51 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/utils/RepositoryConfigUtils.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/utils/RepositoryConfigUtils.kt @@ -29,7 +29,6 @@ package com.tencent.devops.common.pipeline.utils import com.tencent.devops.common.api.enums.RepositoryConfig import com.tencent.devops.common.api.enums.RepositoryType -import com.tencent.devops.common.api.enums.RepositoryTypeNew import com.tencent.devops.common.api.exception.InvalidParamException import com.tencent.devops.common.api.util.EnvUtils import com.tencent.devops.common.pipeline.pojo.element.Element @@ -37,7 +36,6 @@ import com.tencent.devops.common.pipeline.pojo.element.agent.CodeGitElement import com.tencent.devops.common.pipeline.pojo.element.agent.CodeGitlabElement import com.tencent.devops.common.pipeline.pojo.element.agent.CodeSvnElement import com.tencent.devops.common.pipeline.pojo.element.agent.GithubElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitGenericWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGithubWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitlabWebHookTriggerElement @@ -95,32 +93,6 @@ object RepositoryConfigUtils { repositoryName = element.data.input.repositoryName, repositoryType = element.data.input.repositoryType ?: RepositoryType.ID ) - is CodeGitGenericWebHookTriggerElement -> { - with(element.data.input) { - when (repositoryType) { - RepositoryTypeNew.URL -> - RepositoryConfig( - repositoryHashId = null, - repositoryName = repositoryUrl, - repositoryType = RepositoryType.NAME - ) - RepositoryTypeNew.ID -> - RepositoryConfig( - repositoryHashId = repositoryHashId, - repositoryName = repositoryName, - repositoryType = RepositoryType.ID - ) - RepositoryTypeNew.NAME -> - RepositoryConfig( - repositoryHashId = repositoryHashId, - repositoryName = repositoryName, - repositoryType = RepositoryType.NAME - ) - else -> - throw InvalidParamException("Unknown repositoryType -> $element") - } - } - } is CodeP4WebHookTriggerElement -> RepositoryConfig( repositoryHashId = element.data.input.repositoryHashId, repositoryName = element.data.input.repositoryName, diff --git a/src/backend/ci/core/common/common-pipeline/src/test/kotlin/com/tencent/devops/common/pipeline/enums/EnvControlTaskTypeTest.kt b/src/backend/ci/core/common/common-pipeline/src/test/kotlin/com/tencent/devops/common/pipeline/enums/EnvControlTaskTypeTest.kt index 4b2538a3478..cadb56ee2bc 100644 --- a/src/backend/ci/core/common/common-pipeline/src/test/kotlin/com/tencent/devops/common/pipeline/enums/EnvControlTaskTypeTest.kt +++ b/src/backend/ci/core/common/common-pipeline/src/test/kotlin/com/tencent/devops/common/pipeline/enums/EnvControlTaskTypeTest.kt @@ -41,7 +41,6 @@ import com.tencent.devops.common.pipeline.pojo.element.market.MarketCheckImageEl import com.tencent.devops.common.pipeline.pojo.element.matrix.MatrixStatusElement import com.tencent.devops.common.pipeline.pojo.element.quality.QualityGateInElement import com.tencent.devops.common.pipeline.pojo.element.quality.QualityGateOutElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitGenericWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGithubWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitlabWebHookTriggerElement @@ -68,7 +67,6 @@ class EnvControlTaskTypeTest { assertEquals(EnvControlTaskType.parse(""), actualNull) assertEquals(EnvControlTaskType.parse("nullActual"), actualNull) assertEquals(EnvControlTaskType.parse("Other"), actualNull) - assertEquals(EnvControlTaskType.parse(CodeGitGenericWebHookTriggerElement.classType), actualNull) assertEquals(EnvControlTaskType.parse(CodeP4WebHookTriggerElement.classType), actualNull) assertEquals(EnvControlTaskType.parse(MatrixStatusElement.classType), actualNull) assertEquals(EnvControlTaskType.parse(CodeGitWebHookTriggerElement.classType), actualNull) diff --git a/src/backend/ci/core/misc/biz-misc/src/main/kotlin/com/tencent/devops/misc/dao/process/ProcessDataMigrateDao.kt b/src/backend/ci/core/misc/biz-misc/src/main/kotlin/com/tencent/devops/misc/dao/process/ProcessDataMigrateDao.kt index f94d8038f1a..71e603f388f 100644 --- a/src/backend/ci/core/misc/biz-misc/src/main/kotlin/com/tencent/devops/misc/dao/process/ProcessDataMigrateDao.kt +++ b/src/backend/ci/core/misc/biz-misc/src/main/kotlin/com/tencent/devops/misc/dao/process/ProcessDataMigrateDao.kt @@ -58,7 +58,6 @@ import com.tencent.devops.model.process.tables.TPipelineViewGroup import com.tencent.devops.model.process.tables.TPipelineViewTop import com.tencent.devops.model.process.tables.TPipelineViewUserLastView import com.tencent.devops.model.process.tables.TPipelineViewUserSettings -import com.tencent.devops.model.process.tables.TPipelineWebhookBuildLogDetail import com.tencent.devops.model.process.tables.TPipelineWebhookBuildParameter import com.tencent.devops.model.process.tables.TPipelineWebhookQueue import com.tencent.devops.model.process.tables.TProjectPipelineCallback @@ -97,7 +96,6 @@ import com.tencent.devops.model.process.tables.records.TPipelineViewRecord import com.tencent.devops.model.process.tables.records.TPipelineViewTopRecord import com.tencent.devops.model.process.tables.records.TPipelineViewUserLastViewRecord import com.tencent.devops.model.process.tables.records.TPipelineViewUserSettingsRecord -import com.tencent.devops.model.process.tables.records.TPipelineWebhookBuildLogDetailRecord import com.tencent.devops.model.process.tables.records.TPipelineWebhookBuildParameterRecord import com.tencent.devops.model.process.tables.records.TPipelineWebhookQueueRecord import com.tencent.devops.model.process.tables.records.TProjectPipelineCallbackHistoryRecord @@ -653,31 +651,6 @@ class ProcessDataMigrateDao { } } - fun getPipelineWebhookBuildLogDetailRecords( - dslContext: DSLContext, - projectId: String, - pipelineId: String, - limit: Int, - offset: Int - ): List { - with(TPipelineWebhookBuildLogDetail.T_PIPELINE_WEBHOOK_BUILD_LOG_DETAIL) { - return dslContext.selectFrom(this) - .where(PROJECT_ID.eq(projectId).and(PIPELINE_ID.eq(pipelineId))) - .orderBy(ID.asc()) - .limit(limit).offset(offset).fetchInto(TPipelineWebhookBuildLogDetailRecord::class.java) - } - } - - fun migratePipelineWebhookBuildLogDetailData( - migratingShardingDslContext: DSLContext, - webhookBuildLogDetailRecords: List - ) { - with(TPipelineWebhookBuildLogDetail.T_PIPELINE_WEBHOOK_BUILD_LOG_DETAIL) { - val insertRecords = webhookBuildLogDetailRecords.map { migratingShardingDslContext.newRecord(this, it) } - migratingShardingDslContext.batchInsert(insertRecords).execute() - } - } - fun getPipelineWebhookQueueRecords( dslContext: DSLContext, projectId: String, From abb49f0fc74ba3ce1815e9ffcc33e2a6ce2a4777 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Mon, 23 Oct 2023 12:01:30 +0800 Subject: [PATCH 078/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../misc/task/MigratePipelineDataTask.kt | 34 ------------------- 1 file changed, 34 deletions(-) diff --git a/src/backend/ci/core/misc/biz-misc/src/main/kotlin/com/tencent/devops/misc/task/MigratePipelineDataTask.kt b/src/backend/ci/core/misc/biz-misc/src/main/kotlin/com/tencent/devops/misc/task/MigratePipelineDataTask.kt index b2075ea7642..87aa5c3afb7 100644 --- a/src/backend/ci/core/misc/biz-misc/src/main/kotlin/com/tencent/devops/misc/task/MigratePipelineDataTask.kt +++ b/src/backend/ci/core/misc/biz-misc/src/main/kotlin/com/tencent/devops/misc/task/MigratePipelineDataTask.kt @@ -166,14 +166,6 @@ class MigratePipelineDataTask constructor( migratingShardingDslContext = migratingShardingDslContext, processDataMigrateDao = processDbMigrateDao ) - // 3.14、迁移T_PIPELINE_WEBHOOK_BUILD_LOG_DETAIL表数据 - migratePipelineWebhookBuildLogDetailData( - projectId = projectId, - pipelineId = pipelineId, - dslContext = dslContext, - migratingShardingDslContext = migratingShardingDslContext, - processDataMigrateDao = processDbMigrateDao - ) // 3.15、迁移T_PIPELINE_WEBHOOK_QUEUE表数据 migratePipelineWebhookQueueData( projectId = projectId, @@ -597,32 +589,6 @@ class MigratePipelineDataTask constructor( } while (pipelineSettingVersionRecords.size == SHORT_PAGE_SIZE) } - private fun migratePipelineWebhookBuildLogDetailData( - projectId: String, - pipelineId: String, - dslContext: DSLContext, - migratingShardingDslContext: DSLContext, - processDataMigrateDao: ProcessDataMigrateDao - ) { - var offset = 0 - do { - val webhookBuildLogDetailRecords = processDataMigrateDao.getPipelineWebhookBuildLogDetailRecords( - dslContext = dslContext, - projectId = projectId, - pipelineId = pipelineId, - limit = SHORT_PAGE_SIZE, - offset = offset - ) - if (webhookBuildLogDetailRecords.isNotEmpty()) { - processDataMigrateDao.migratePipelineWebhookBuildLogDetailData( - migratingShardingDslContext = migratingShardingDslContext, - webhookBuildLogDetailRecords = webhookBuildLogDetailRecords - ) - } - offset += SHORT_PAGE_SIZE - } while (webhookBuildLogDetailRecords.size == SHORT_PAGE_SIZE) - } - private fun migratePipelineWebhookQueueData( projectId: String, pipelineId: String, From 9b3443614867032ae11d2e97d883efb0e4d078aa Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Mon, 23 Oct 2023 14:33:51 +0800 Subject: [PATCH 079/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/misc/dao/process/ProcessDataDeleteDao.kt | 9 --------- .../service/process/ProcessMigrationDataDeleteService.kt | 1 - 2 files changed, 10 deletions(-) diff --git a/src/backend/ci/core/misc/biz-misc/src/main/kotlin/com/tencent/devops/misc/dao/process/ProcessDataDeleteDao.kt b/src/backend/ci/core/misc/biz-misc/src/main/kotlin/com/tencent/devops/misc/dao/process/ProcessDataDeleteDao.kt index 5c5ef7a0b62..fe2ad9291ed 100644 --- a/src/backend/ci/core/misc/biz-misc/src/main/kotlin/com/tencent/devops/misc/dao/process/ProcessDataDeleteDao.kt +++ b/src/backend/ci/core/misc/biz-misc/src/main/kotlin/com/tencent/devops/misc/dao/process/ProcessDataDeleteDao.kt @@ -58,7 +58,6 @@ import com.tencent.devops.model.process.tables.TPipelineViewGroup import com.tencent.devops.model.process.tables.TPipelineViewTop import com.tencent.devops.model.process.tables.TPipelineViewUserLastView import com.tencent.devops.model.process.tables.TPipelineViewUserSettings -import com.tencent.devops.model.process.tables.TPipelineWebhookBuildLogDetail import com.tencent.devops.model.process.tables.TPipelineWebhookBuildParameter import com.tencent.devops.model.process.tables.TPipelineWebhookQueue import com.tencent.devops.model.process.tables.TProjectPipelineCallback @@ -257,14 +256,6 @@ class ProcessDataDeleteDao { } } - fun deletePipelineWebhookBuildLogDetail(dslContext: DSLContext, projectId: String, pipelineId: String) { - with(TPipelineWebhookBuildLogDetail.T_PIPELINE_WEBHOOK_BUILD_LOG_DETAIL) { - dslContext.deleteFrom(this) - .where(PROJECT_ID.eq(projectId).and(PIPELINE_ID.eq(pipelineId))) - .execute() - } - } - fun deletePipelineWebhookQueue(dslContext: DSLContext, projectId: String, buildIds: List) { with(TPipelineWebhookQueue.T_PIPELINE_WEBHOOK_QUEUE) { dslContext.deleteFrom(this) diff --git a/src/backend/ci/core/misc/biz-misc/src/main/kotlin/com/tencent/devops/misc/service/process/ProcessMigrationDataDeleteService.kt b/src/backend/ci/core/misc/biz-misc/src/main/kotlin/com/tencent/devops/misc/service/process/ProcessMigrationDataDeleteService.kt index d134281dd0e..811fcc85ccf 100644 --- a/src/backend/ci/core/misc/biz-misc/src/main/kotlin/com/tencent/devops/misc/service/process/ProcessMigrationDataDeleteService.kt +++ b/src/backend/ci/core/misc/biz-misc/src/main/kotlin/com/tencent/devops/misc/service/process/ProcessMigrationDataDeleteService.kt @@ -177,7 +177,6 @@ class ProcessMigrationDataDeleteService @Autowired constructor( processDataDeleteDao.deletePipelineBuildContainer(dslContext, projectId, pipelineId) processDataDeleteDao.deletePipelineBuildStage(dslContext, projectId, pipelineId) processDataDeleteDao.deletePipelineFavor(dslContext, projectId, pipelineId) - processDataDeleteDao.deletePipelineWebhookBuildLogDetail(dslContext, projectId, pipelineId) offset += DEFAULT_PAGE_SIZE } while (historyInfoRecords?.size == DEFAULT_PAGE_SIZE) } From 9d3d68240f6750969daf04ea691898f4d2b23d5d Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 23 Oct 2023 16:48:09 +0800 Subject: [PATCH 080/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webhook/enums/WebhookI18nConstants.kt | 3 + .../code/handler/CodeWebhookTriggerHandler.kt | 3 +- .../github/GithubCreateTriggerHandler.kt | 9 ++- .../handler/github/GithubPrTriggerHandler.kt | 12 +++- .../github/GithubPushTriggerHandler.kt | 12 +++- .../code/handler/p4/P4ChangeTriggerHandler.kt | 12 +++- .../code/handler/p4/P4ShelveTriggerHandler.kt | 12 +++- .../handler/svn/SvnCommitTriggerHandler.kt | 12 +++- .../handler/tgit/TGitIssueTriggerHandler.kt | 12 +++- .../code/handler/tgit/TGitMrTriggerHandler.kt | 12 +++- .../handler/tgit/TGitNoteTriggerHandler.kt | 12 +++- .../handler/tgit/TGitPushTriggerHandler.kt | 12 +++- .../handler/tgit/TGitReviewTriggerHandler.kt | 14 ++++- .../handler/tgit/TGitTagPushTriggerHandler.kt | 12 +++- .../code/matcher/AbstractScmWebhookMatcher.kt | 5 +- .../service/code/matcher/ScmWebhookMatcher.kt | 3 +- .../pojo/trigger/PipelineEventReplayInfo.kt | 58 +++++++++++++++++++ .../process/trigger/WebhookTriggerService.kt | 5 +- .../i18n/process/message_en_US.properties | 27 ++++++++- .../i18n/process/message_zh_CN.properties | 25 ++++++++ .../sql/1001_ci_process_ddl_mysql.sql | 2 +- 21 files changed, 230 insertions(+), 44 deletions(-) create mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineEventReplayInfo.kt diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt index 40d7993a8e1..0e403133bfe 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt @@ -120,4 +120,7 @@ object WebhookI18nConstants { // issues操作类型不匹配 const val ISSUES_ACTION_NOT_MATCH = "bkRepoTriggerIssueActionNotMatch" + + // 事件回放匹配码后缀 + const val EVENT_REPLAY_SUFFIX = "Replay" } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt index e84118bc7a4..8837455c10d 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt @@ -34,6 +34,7 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilterChain import com.tencent.devops.common.webhook.service.code.filter.WebhookFilterResponse import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.pojo.WebhookCommit @@ -75,7 +76,7 @@ interface CodeWebhookTriggerHandler { /** * 获取事件说明,根据不同的事件组织事件说明 */ - fun getEventDesc(event: T): String = "" + fun getEventDesc(event: T, replayInfo: PipelineEventReplayInfo? = null): String = "" /** * 获取webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt index 23bc82db501..46225088f34 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt @@ -40,6 +40,7 @@ import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.pojo.code.github.GithubCreateEvent import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.GitHookTriggerHandler +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils import java.time.LocalDateTime @@ -78,7 +79,7 @@ class GithubCreateTriggerHandler : GitHookTriggerHandler { return event.ref } - override fun getEventDesc(event: GithubCreateEvent): String { + override fun getEventDesc(event: GithubCreateEvent, replayInfo: PipelineEventReplayInfo?): String { var i18Code = WebhookI18nConstants.GITHUB_CREATE_TAG_EVENT_DESC val linkUrl = if (event.ref_type == "tag") { "https://github.com/${event.repository.fullName}/releases/tag/${event.ref}" @@ -86,12 +87,14 @@ class GithubCreateTriggerHandler : GitHookTriggerHandler { i18Code = WebhookI18nConstants.GITHUB_CREATE_BRANCH_EVENT_DESC "https://github.com/${event.repository.fullName}/tree/${event.ref}" } + // 事件重放 + val (username, code) = PipelineEventReplayInfo.getTriggerInfo(replayInfo, getUsername(event), i18Code) return I18Variable( - code = i18Code, + code = code, params = listOf( getBranchName(event), linkUrl, - getUsername(event), + username, DateTimeUtil.formatMilliTime(LocalDateTime.now().timestampmilli()) ) ).toJsonStr() diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt index abd224e6ea7..c999267941c 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt @@ -86,6 +86,7 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.GitHookTriggerHandler import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils import org.slf4j.LoggerFactory @@ -130,13 +131,18 @@ class GithubPrTriggerHandler : GitHookTriggerHandler { return event.pullRequest.title } - override fun getEventDesc(event: GithubPullRequestEvent): String { + override fun getEventDesc(event: GithubPullRequestEvent, replayInfo: PipelineEventReplayInfo?): String { + val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( + replayInfo, + getUsername(event), + WebhookI18nConstants.GITHUB_PR_EVENT_DESC + ) return I18Variable( - code = WebhookI18nConstants.GITHUB_PR_EVENT_DESC, + code = i18Code, params = listOf( event.pullRequest.htmlUrl, event.pullRequest.number.toString(), - getUsername(event), + username, event.action ) ).toJsonStr() diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt index 5d31becdac4..7014ca3019e 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt @@ -61,6 +61,7 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.GitHookTriggerHandler import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils import org.slf4j.LoggerFactory @@ -105,7 +106,7 @@ class GithubPushTriggerHandler : GitHookTriggerHandler { return event.headCommit?.message ?: "" } - override fun getEventDesc(event: GithubPushEvent): String { + override fun getEventDesc(event: GithubPushEvent, replayInfo: PipelineEventReplayInfo?): String { val linkUrl = if (event.headCommit != null) { "https://github.com/${event.repository.fullName}/commit/${event.headCommit?.id}" } else { @@ -117,13 +118,18 @@ class GithubPushTriggerHandler : GitHookTriggerHandler { } else { revision } + val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( + replayInfo, + getUsername(event), + WebhookI18nConstants.GITHUB_PUSH_EVENT_DESC + ) return I18Variable( - code = WebhookI18nConstants.GITHUB_PUSH_EVENT_DESC, + code = i18Code, params = listOf( getBranchName(event), linkUrl, commitId, - getUsername(event) + username ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt index c8cf3cdf531..c6bdc8e4482 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt @@ -44,6 +44,7 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilterResponse import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.process.utils.PIPELINE_BUILD_MSG import com.tencent.devops.repository.pojo.Repository @@ -82,12 +83,17 @@ class P4ChangeTriggerHandler( override fun getMessage(event: P4ChangeEvent) = event.description - override fun getEventDesc(event: P4ChangeEvent): String { + override fun getEventDesc(event: P4ChangeEvent, replayInfo: PipelineEventReplayInfo?): String { + val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( + replayInfo, + getUsername(event), + WebhookI18nConstants.P4_EVENT_DESC + ) return I18Variable( - code = WebhookI18nConstants.P4_EVENT_DESC, + code = i18Code, params = listOf( getRevision(event), - getUsername(event), + username, getFormatEventType(event) ) ).toJsonStr() diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt index d98c126bc07..f27a65e7180 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt @@ -45,6 +45,7 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilterResponse import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.process.utils.PIPELINE_BUILD_MSG import com.tencent.devops.repository.api.ServiceP4Resource import com.tencent.devops.repository.pojo.Repository @@ -85,12 +86,17 @@ class P4ShelveTriggerHandler( override fun getMessage(event: P4ShelveEvent) = event.description - override fun getEventDesc(event: P4ShelveEvent): String { + override fun getEventDesc(event: P4ShelveEvent, replayInfo: PipelineEventReplayInfo?): String { + val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( + replayInfo, + getUsername(event), + WebhookI18nConstants.P4_EVENT_DESC + ) return I18Variable( - code = WebhookI18nConstants.P4_EVENT_DESC, + code = i18Code, params = listOf( getRevision(event), - getUsername(event), + username, getFormatEventType(event) ) ).toJsonStr() diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt index c13f1b29601..805ad08d390 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt @@ -44,6 +44,7 @@ import com.tencent.devops.common.webhook.service.code.filter.UserFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository @CodeWebhookHandler @@ -81,12 +82,17 @@ class SvnCommitTriggerHandler : CodeWebhookTriggerHandler { return event.log } - override fun getEventDesc(event: SvnCommitEvent): String { + override fun getEventDesc(event: SvnCommitEvent, replayInfo: PipelineEventReplayInfo?): String { + val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( + replayInfo, + getUsername(event), + WebhookI18nConstants.SVN_COMMIT_EVENT_DESC + ) return I18Variable( - code = WebhookI18nConstants.SVN_COMMIT_EVENT_DESC, + code = i18Code, params = listOf( getRevision(event), - getUsername(event) + username ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt index 47a23365f96..406aac7efca 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt @@ -57,6 +57,7 @@ import com.tencent.devops.common.webhook.service.code.filter.GitUrlFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.GitHookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils @@ -130,13 +131,18 @@ class TGitIssueTriggerHandler( return event.objectAttributes.title } - override fun getEventDesc(event: GitIssueEvent): String { + override fun getEventDesc(event: GitIssueEvent, replayInfo: PipelineEventReplayInfo?): String { + val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( + replayInfo, + getUsername(event), + getI18Code(event) + ) return I18Variable( - code = getI18Code(event), + code = i18Code, params = listOf( "${event.objectAttributes.url}", event.objectAttributes.iid, - getUsername(event) + username ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt index aafcc48a9d0..9a0083a9c57 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt @@ -89,6 +89,7 @@ import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.common.webhook.util.WebhookUtils.convert import com.tencent.devops.common.webhook.util.WebhookUtils.getBranch import com.tencent.devops.process.engine.service.code.filter.CommitMessageFilter +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.CodeGitlabRepository import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.pojo.WebhookCommit @@ -160,13 +161,18 @@ class TGitMrTriggerHandler( return event.object_attributes.id } - override fun getEventDesc(event: GitMergeRequestEvent): String { + override fun getEventDesc(event: GitMergeRequestEvent, replayInfo: PipelineEventReplayInfo?): String { + val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( + replayInfo, + getUsername(event), + getI18Code(event) + ) return I18Variable( - code = getI18Code(event), + code = i18Code, params = listOf( "${event.object_attributes.url}", event.object_attributes.iid.toString(), - getUsername(event) + username ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt index 5c48ffe3430..7388142ca8c 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt @@ -80,6 +80,7 @@ import com.tencent.devops.common.webhook.service.code.filter.RegexContainFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.CodeGitlabRepository import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils @@ -164,13 +165,18 @@ class TGitNoteTriggerHandler( return event.objectAttributes.note } - override fun getEventDesc(event: GitNoteEvent): String { + override fun getEventDesc(event: GitNoteEvent, replayInfo: PipelineEventReplayInfo?): String { + val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( + replayInfo, + getUsername(event), + WebhookI18nConstants.TGIT_NOTE_EVENT_DESC + ) return I18Variable( - code = WebhookI18nConstants.TGIT_NOTE_EVENT_DESC, + code = i18Code, params = listOf( event.objectAttributes.url, event.objectAttributes.id.toString(), - getUsername(event) + username ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt index 98f8e0ee275..e72dec3d7cc 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt @@ -72,6 +72,7 @@ import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.common.webhook.util.WebhookUtils.convert import com.tencent.devops.process.engine.service.code.filter.CommitMessageFilter +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.pojo.WebhookCommit import com.tencent.devops.scm.utils.code.git.GitUtils @@ -130,14 +131,19 @@ class TGitPushTriggerHandler( } } - override fun getEventDesc(event: GitPushEvent): String { + override fun getEventDesc(event: GitPushEvent, replayInfo: PipelineEventReplayInfo?): String { + val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( + replayInfo, + getUsername(event), + TGIT_PUSH_EVENT_DESC + ) return I18Variable( - code = TGIT_PUSH_EVENT_DESC, + code = i18Code, params = listOf( getBranchName(event), "${event.repository.homepage}/commit/${event.checkout_sha}", "${event.checkout_sha}".substring(0, GitPushEvent.SHORT_COMMIT_ID_LENGTH), - event.user_name + username ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt index e2c4155a501..c2f821d0f30 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt @@ -58,6 +58,7 @@ import com.tencent.devops.common.webhook.service.code.filter.GitUrlFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils @@ -98,14 +99,21 @@ class TGitReviewTriggerHandler( return "" } - override fun getEventDesc(event: GitReviewEvent): String { - val (state, username) = if (event.reviewer != null) { + override fun getEventDesc(event: GitReviewEvent, replayInfo: PipelineEventReplayInfo?): String { + // 评审状态 to 事件人 + val (state, eventUser) = if (event.reviewer != null) { event.reviewer!!.state to event.reviewer!!.reviewer.name } else { event.state to getUsername(event) } + // 最终触发人 to 文案code + val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( + replayInfo, + eventUser, + getI18Code(state) + ) return I18Variable( - code = getI18Code(state), + code = i18Code, params = listOf( "${event.repository.homepage}/reviews/${event.iid}", event.iid, diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt index 2a4cc2d5096..c15c4a12a01 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt @@ -57,6 +57,7 @@ import com.tencent.devops.common.webhook.service.code.filter.UserFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils @@ -99,7 +100,7 @@ class TGitTagPushTriggerHandler : CodeWebhookTriggerHandler { return event.ref.replace("refs/tags/", "") } - override fun getEventDesc(event: GitTagPushEvent): String { + override fun getEventDesc(event: GitTagPushEvent, replayInfo: PipelineEventReplayInfo?): String { val createFrom = when { event.create_from.isNullOrBlank() || event.checkout_sha == event.create_from -> { GitUtils.getShortSha(event.checkout_sha) @@ -109,13 +110,18 @@ class TGitTagPushTriggerHandler : CodeWebhookTriggerHandler { event.create_from } } + val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( + replayInfo, + getUsername(event), + WebhookI18nConstants.TGIT_TAG_PUSH_EVENT_DESC + ) return I18Variable( - code = WebhookI18nConstants.TGIT_TAG_PUSH_EVENT_DESC, + code = i18Code, params = listOf( "$createFrom", "${event.repository.homepage}/-/tags/${getBranchName(event)}", getBranchName(event), - getUsername(event) + username ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt index 813f906aa9a..8d7c381f474 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt @@ -31,6 +31,7 @@ import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventTy import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent import com.tencent.devops.common.webhook.service.code.loader.CodeWebhookHandlerRegistrar import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository @Suppress("TooManyFunctions") @@ -83,8 +84,8 @@ abstract class AbstractScmWebhookMatcher( return eventHandler.getMessage(event) } - override fun getEventDesc(): String { - return eventHandler.getEventDesc(event) + override fun getEventDesc(replayInfo: PipelineEventReplayInfo?): String { + return eventHandler.getEventDesc(event, replayInfo) } override fun getExternalId(): String { diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt index 718fbae741e..ef0f522d598 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt @@ -31,6 +31,7 @@ import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventTy import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeType import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.pojo.WebhookCommit import org.slf4j.LoggerFactory @@ -75,7 +76,7 @@ interface ScmWebhookMatcher { /** * 获取事件描述,根据不同的事件组织事件说明 */ - fun getEventDesc(): String = "" + fun getEventDesc(replayInfo: PipelineEventReplayInfo? = null): String = "" /** * 获取webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineEventReplayInfo.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineEventReplayInfo.kt new file mode 100644 index 00000000000..193b1242a43 --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineEventReplayInfo.kt @@ -0,0 +1,58 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.pojo.trigger + +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty + +@ApiModel("流水线事件重放操作信息") +data class PipelineEventReplayInfo( + @ApiModelProperty("触发人") + val userId: String +){ + companion object{ + /** + * 获取触发信息 + * 若为[重放事件]时,触发人为[回放者],且事件描述采用重放相关文案code + * 反之返回默认用户和触发文案code + */ + fun getTriggerInfo( + replayInfo: PipelineEventReplayInfo?, + defaultUserId: String, + defaultI18Code: String + ): Pair { + return if (replayInfo != null) { + replayInfo.userId to "$defaultI18Code${WebhookI18nConstants.EVENT_REPLAY_SUFFIX}" + } else { + defaultUserId to defaultI18Code + } + } + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/WebhookTriggerService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/WebhookTriggerService.kt index fecd547f868..f0a162de3a6 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/WebhookTriggerService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/WebhookTriggerService.kt @@ -31,6 +31,7 @@ package com.tencent.devops.process.trigger import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher import com.tencent.devops.process.engine.service.PipelineWebhookService +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService @@ -92,8 +93,8 @@ class WebhookTriggerService( val triggerEvent = PipelineTriggerEvent( triggerType = scmType.name, eventType = matcher.getEventType().name, - triggerUser = matcher.getUsername(), - eventDesc = matcher.getEventDesc(), + triggerUser = userId, + eventDesc = matcher.getEventDesc(PipelineEventReplayInfo(userId)), hookRequestId = hookRequestId, eventTime = eventTime ) diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index 24b22f97d91..c001650ed36 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -385,7 +385,32 @@ bkP4EventDesc=Change [{0}] by {1} {2} bkSvnCommitEventDesc=Commit [{0}] pushed by {1} bkManualStartEventDesc=Manually triggered by {0} bkRemoteStartEventDesc=Remote api triggered by {0} -bkServiceStartEventDesc={0} Pipeline invocation triggered by [{2}] 调用 +bkServiceStartEventDesc={0} Pipeline invocation triggered by [{2}] invoke +# event replay +bkTgitPushEventDescReplay=[{0}] Commit [{2}] replayed by {3} +bkTgitIssueOpenedEventDescReplay=Issue [!{1}] replayed by {2} +bkTgitIssueUpdatedEventDescReplay=Issue [!{1}] replayed by {2} +bkTgitIssueClosedEventDescReplay=Issue [!{1}] replayed by {2} +bkTgitIssueReopenedEventDescReplay=Issue [!{1}] replayed by {2} +bkTgitMrCreatedEventDescReplay=Merge requests [!{1}] replayed by {2} +bkTgitMrUpdatedEventDescReplay=Merge requests [!{1}] replayed by {2} +bkTgitMrClosedEventDescReplay=Merge requests [!{1}] replayed by {2} +bkTgitMrReopenedEventDescReplay=Merge requests [!{1}] replayed by {2} +bkTgitMrPushUpdatedEventDescReplay=Merge requests [!{1}] replayed by {2} +bkTgitMrMergedEventDescReplay=Merge requests [!{1}] replayed by {2} +bkTgitTagPushEventDescReplay=[{0}]Tag [{2}] replayed by {3} +bkTgitNoteEventDescReplay=Note [{1}] replayed by {2} +bkTgitReviewCreatedEventDescReplay=Code review [{1}] replayed by {2} +bkTgitReviewApprovedEventDescReplay=Code review [{1}] replayed by {2} +bkTgitReviewApprovingEventDescReplay=Code review [{1}] approving +bkTgitReviewChangeDeniedEventDescReplay=Code review [{1}] replayed by {2} +bkTgitReviewChangeRequiredEventDescReplay=Code review [{1}] replayed by {2} +bkGithubPushEventDescReplay=[{0}] Commit [{2}] replayed {3} +bkGithubCreateBranchEventDescReplay=Branch [{1}] replayed {2} +bkGithubCreateTagEventDescReplay=Tag [{1}] replayed {2} +bkGithubPrEventDescReplay=Pull request [!{1}] by {2} replayed +bkP4EventDescReplay=Change [{0}] by {1} replayed +bkSvnCommitEventDescReplay=Commit [{0}] replayed by {1} bkRepoTriggerEventTypeNotMatch=Event type mismatch bkRepoTriggerTargetBranchNotMatch=Target branch [{0}] of merge request does not match bkRepoTriggerTargetBranchIgnored=Target branch [{0}] of merge request has been excluded diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index d1c8ddc6eb8..ed2c6e20474 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -386,6 +386,31 @@ bkSvnCommitEventDesc=提交 [{0}] 由 {1} bkManualStartEventDesc={0} 手动触发 bkRemoteStartEventDesc={0} 远程触发 bkServiceStartEventDesc={0} 触发的流水线 [{2}] 调用 +# 重放事件 +bkTgitPushEventDescReplay=[{0}] 提交 [{2}] 由 {3} 重放 +bkTgitIssueCreatedEventDescReplay=议题 [!{1}] 由 {2} 重放 +bkTgitIssueUpdatedEventDescReplay=议题 [!{1}] 由 {2} 重放 +bkTgitIssueClosedEventDescReplay=议题 [!{1}] 由 {2} 重放 +bkTgitIssueReopenedEventDescReplay=议题 [!{1}] 由 {2} 重放 +bkTgitMrCreatedEventDescReplay=合并请求 [!{1}] 由 {2} 重放 +bkTgitMrUpdatedEventDescReplay=合并请求 [!{1}] 由 {2} 重放 +bkTgitMrClosedEventDescReplay=合并请求 [!{1}] 由 {2} 重放 +bkTgitMrReopenedEventDescReplay=合并请求 [!{1}] 由 {2} 重放 +bkTgitMrPushUpdatedEventDescReplay=合并请求 [!{1}] 由 {2} 重放 +bkTgitMrMergedEventDescReplay=合并请求 [!{1}] 由 {2} 重放 +bkTgitTagPushEventDescReplay=[{0}] 创建Tag [{2}] 由 {3} 重放 +bkTgitNoteEventDescReplay=评论 [{1}] 由 {2} 重放 +bkTgitReviewCreatedEventDescReplay=代码审查 [{1}] 由 {2} 重放 +bkTgitReviewApprovedEventDescReplay=代码审查 [{1}] 由 {2} 重放 +bkTgitReviewApprovingEventDescReplay=代码审查 [{1}] 评审中 +bkTgitReviewChangeDeniedEventDescReplay=代码审查 [{1}] 由 {2} 重放 +bkTgitReviewChangeRequiredEventDescReplay=代码审查 [{1}] 由 {2} 重放 +bkGithubPushEventDescReplay=[{0}] 提交 [{2}] 由 {3} 重放 +bkGithubCreateBranchEventDescReplay=Branch [{1}] 由 {2} 重放 +bkGithubCreateTagEventDescReplay=Tag [{1}] 由 {2} 重放 +bkGithubPrEventDescReplay=Pull request [{1}] 由 {2} {3} +bkP4EventDescReplay=Change {0} 由 {1} 重放 +bkSvnCommitEventDescReplay=提交 [{0}] 由 {1} 重放 bkRepoTriggerEventTypeNotMatch=事件类型不满足触发条件 bkRepoTriggerTargetBranchNotMatch=MR目标分支[{0}]不满足触发条件 bkRepoTriggerTargetBranchIgnored=MR目标分支[{0}]被排除 diff --git a/support-files/sql/1001_ci_process_ddl_mysql.sql b/support-files/sql/1001_ci_process_ddl_mysql.sql index 98ddcc139fb..bcb614c5088 100644 --- a/support-files/sql/1001_ci_process_ddl_mysql.sql +++ b/support-files/sql/1001_ci_process_ddl_mysql.sql @@ -1176,7 +1176,7 @@ CREATE TABLE IF NOT EXISTS `T_PIPELINE_TRIGGER_DETAIL` `EVENT_ID` bigint(20) NOT NULL COMMENT '事件ID', `STATUS` varchar(100) DEFAULT NULL COMMENT '状态(success or failure)', `PIPELINE_ID` varchar(100) DEFAULT NULL COMMENT '流水线ID', - `PIPELINE_NAME` varchar(100) DEFAULT NULL COMMENT '流水线名称', + `PIPELINE_NAME` varchar(255) DEFAULT NULL COMMENT '流水线名称', `VERSION` int DEFAULT NULL COMMENT '流水线版本号', `BUILD_ID` varchar(100) DEFAULT NULL COMMENT '构建ID', `BUILD_NUM` varchar(100) DEFAULT NULL COMMENT '构建编号', From 80ac17b2417d79c4b32507857d527d8a029235c2 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 23 Oct 2023 20:04:10 +0800 Subject: [PATCH 081/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/pojo/trigger/PipelineEventReplayInfo.kt | 4 ++-- .../devops/process/engine/service/PipelineWebhookService.kt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineEventReplayInfo.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineEventReplayInfo.kt index 193b1242a43..8731bf4fe4c 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineEventReplayInfo.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineEventReplayInfo.kt @@ -36,8 +36,8 @@ import io.swagger.annotations.ApiModelProperty data class PipelineEventReplayInfo( @ApiModelProperty("触发人") val userId: String -){ - companion object{ +) { + companion object { /** * 获取触发信息 * 若为[重放事件]时,触发人为[回放者],且事件描述采用重放相关文案code diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index 749741478fa..8114629f579 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -714,7 +714,7 @@ class PipelineWebhookService @Autowired constructor( if (elementRepositoryConfig.getRepositoryId() != webhookRepositoryConfig.getRepositoryId()) { logger.info( "webhook repository config different from element repository config|" + - "webhook:${webhookRepositoryConfig}|element:${elementRepositoryConfig}" + "webhook:$webhookRepositoryConfig|element:$elementRepositoryConfig" ) return@webhook } @@ -746,7 +746,7 @@ class PipelineWebhookService @Autowired constructor( repositoryHashId = repository?.repoHashId ) } catch (ignored: Exception) { - logger.info("update webhook event info error|${webhook}", ignored) + logger.info("update webhook event info error|$webhook", ignored) } } } From 23e4931ca75fe9b5d73225887deaaa0f4bc0f9b0 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Mon, 23 Oct 2023 21:04:25 +0800 Subject: [PATCH 082/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E5=BC=80=E5=90=AFPAC=E6=A8=A1=E5=BC=8F=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E6=94=AF=E6=8C=81=E8=87=AA=E5=8A=A8=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E4=BB=A3=E7=A0=81=E5=BA=93YAML=E5=8F=98=E6=9B=B4?= =?UTF-8?q?=E5=88=B0=E8=93=9D=E7=9B=BE=20#8130?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trigger/CodeGitWebHookTriggerElement.kt | 3 --- .../trigger/CodeGithubWebHookTriggerElement.kt | 3 --- .../trigger/CodeGitlabWebHookTriggerElement.kt | 3 --- .../trigger/CodeP4WebHookTriggerElement.kt | 3 --- .../trigger/CodeSVNWebHookTriggerElement.kt | 3 --- .../trigger/CodeTGitWebHookTriggerElement.kt | 3 --- .../engine/service/PipelineWebhookService.kt | 15 +++++++-------- 7 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitWebHookTriggerElement.kt index 9b9e53e1ab4..fd31ed72a56 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitWebHookTriggerElement.kt @@ -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!! diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt index bf648a0ba60..3eb1827f1a0 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt @@ -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!! diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt index 642eaceabe4..22e323e58aa 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt @@ -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!! diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt index 3c247a3917a..fe96c9dad04 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt @@ -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!! diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt index 8206107b4c1..aeecec816f6 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt @@ -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!! diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt index c72220db6c1..28390e432a4 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt @@ -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!! diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index 8114629f579..b7d0928f0b5 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -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 @@ -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 /** @@ -668,9 +668,7 @@ class PipelineWebhookService @Autowired constructor( private fun updateWebhookEventInfoTask() { var offset = 0 val limit = 1000 - val repoCache = CacheBuilder.newBuilder() - .maximumSize(1000) - .build() + val repoCache = mutableMapOf>() // 上一个更新的项目ID var preProjectId: String? = null do { @@ -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) @@ -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, @@ -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|" + From 03a0e280c083b0e5480f099a21c0e6424def203d Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Tue, 24 Oct 2023 09:26:59 +0800 Subject: [PATCH 083/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E5=BC=80=E5=90=AFPAC=E6=A8=A1=E5=BC=8F=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E6=94=AF=E6=8C=81=E8=87=AA=E5=8A=A8=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E4=BB=A3=E7=A0=81=E5=BA=93YAML=E5=8F=98=E6=9B=B4?= =?UTF-8?q?=E5=88=B0=E8=93=9D=E7=9B=BE=20#8130?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/service/PipelineWebhookService.kt | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index b7d0928f0b5..1f63441d4c5 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -709,6 +709,7 @@ class PipelineWebhookService @Autowired constructor( ?: return@webhook val elementRepositoryConfig = webhookElementParams.repositoryConfig val webhookRepositoryConfig = getRepositoryConfig(webhook, params) + // 插件的配置与表中数据不一致,如保存流水线时,注册webhook失败,就会导致数据不一致,不更新 if (elementRepositoryConfig.getRepositoryId() != webhookRepositoryConfig.getRepositoryId()) { logger.info( "webhook repository config different from element repository config|" + @@ -716,19 +717,30 @@ class PipelineWebhookService @Autowired constructor( ) return@webhook } - val repository = repoCache.putIfAbsent( - "${projectId}_${elementRepositoryConfig.getRepositoryId()}", Optional.ofNullable( - try { - scmProxyService.getRepo( - projectId = projectId, - repositoryConfig = elementRepositoryConfig - ) - } catch (ignored: Exception) { - logger.warn("fail to get repository info", ignored) - null - } - ) - )?.get() + // 缓存代码库信息,避免频繁调用代码库信息接口 + val repoCacheKey = "${projectId}_${elementRepositoryConfig.getRepositoryId()}" + val repositoryOptional = repoCache[repoCacheKey] + val repository = if (repositoryOptional == null) { + val repo = try { + scmProxyService.getRepo( + projectId = projectId, + repositoryConfig = elementRepositoryConfig + ) + } catch (ignored: Exception) { + logger.warn("fail to get repository info", ignored) + null + } + repoCache[repoCacheKey] = Optional.ofNullable(repo) + repo + } else { + if (repositoryOptional.isPresent) { + repositoryOptional.get() + } else { + return@webhook + } + } + + // 历史原因,git的projectName有三个,如aaa/bbb/ccc,只读取了bbb,统计数据量 if (repository != null && webhook.projectName != repository.projectName) { logger.info( "webhook projectName different from repo projectName|" + From 73631ca021a1c44a968a905b66e68fbbc2cd848c Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Wed, 25 Oct 2023 15:41:33 +0800 Subject: [PATCH 084/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/service/PipelineWebhookService.kt | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index 1f63441d4c5..bf29497b039 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -715,29 +715,28 @@ class PipelineWebhookService @Autowired constructor( "webhook repository config different from element repository config|" + "webhook:$webhookRepositoryConfig|element:$elementRepositoryConfig" ) - return@webhook } // 缓存代码库信息,避免频繁调用代码库信息接口 - val repoCacheKey = "${projectId}_${elementRepositoryConfig.getRepositoryId()}" - val repositoryOptional = repoCache[repoCacheKey] - val repository = if (repositoryOptional == null) { + val repoCacheKey = "${projectId}_${webhookRepositoryConfig.getRepositoryId()}" + val repositoryOptional = repoCache[repoCacheKey] ?: run { val repo = try { scmProxyService.getRepo( projectId = projectId, - repositoryConfig = elementRepositoryConfig + repositoryConfig = webhookRepositoryConfig ) } catch (ignored: Exception) { - logger.warn("fail to get repository info", ignored) + logger.warn( + "$projectId|$pipelineId|${webhookRepositoryConfig.getRepositoryId()}|" + + "fail to get repository info", ignored + ) null } - repoCache[repoCacheKey] = Optional.ofNullable(repo) - repo + Optional.ofNullable(repo) + } + val repository = if (repositoryOptional.isPresent) { + repositoryOptional.get() } else { - if (repositoryOptional.isPresent) { - repositoryOptional.get() - } else { - return@webhook - } + null } // 历史原因,git的projectName有三个,如aaa/bbb/ccc,只读取了bbb,统计数据量 From 3694d70f1445ffaba5a2419f7f30969d7143c877 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 26 Oct 2023 16:11:19 +0800 Subject: [PATCH 085/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../code/handler/github/GithubIssueTriggerHandler.kt | 5 +++-- .../code/handler/github/GithubReviewTriggerHandler.kt | 5 +++-- .../handler/github/comment/GithubCommentTriggerHandler.kt | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubIssueTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubIssueTriggerHandler.kt index 4348b9717a3..ce84a5840c0 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubIssueTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubIssueTriggerHandler.kt @@ -47,6 +47,7 @@ import com.tencent.devops.common.webhook.service.code.filter.GitUrlFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository @@ -87,8 +88,8 @@ class GithubIssueTriggerHandler : CodeWebhookTriggerHandler { return event.issue.title } - override fun preMatch(event: GithubIssuesEvent): ScmWebhookMatcher.MatchResult { - return ScmWebhookMatcher.MatchResult(true) + override fun preMatch(event: GithubIssuesEvent): WebhookMatchResult { + return WebhookMatchResult(true) } override fun getWebhookFilters( diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubReviewTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubReviewTriggerHandler.kt index bbfc9dece7c..06b36f96595 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubReviewTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubReviewTriggerHandler.kt @@ -49,6 +49,7 @@ import com.tencent.devops.common.webhook.service.code.filter.GitUrlFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository import org.slf4j.LoggerFactory @@ -93,11 +94,11 @@ class GithubReviewTriggerHandler @Autowired constructor( return event.pullRequest.title } - override fun preMatch(event: GithubReviewEvent): ScmWebhookMatcher.MatchResult { + override fun preMatch(event: GithubReviewEvent): WebhookMatchResult { // Review事件仅提交操作才触发,评审通过、拒绝、要求修改 val result = (event.action == "submitted" || event.action == "dismissed") && event.review.state != GithubReviewState.COMMENTED.value - return ScmWebhookMatcher.MatchResult(result) + return WebhookMatchResult(result) } override fun getWebhookFilters( diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/comment/GithubCommentTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/comment/GithubCommentTriggerHandler.kt index 400a6d1afce..872b153674c 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/comment/GithubCommentTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/comment/GithubCommentTriggerHandler.kt @@ -47,7 +47,7 @@ import com.tencent.devops.common.webhook.service.code.filter.GitUrlFilter import com.tencent.devops.common.webhook.service.code.filter.RegexContainFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler -import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher +import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository @@ -86,8 +86,8 @@ interface GithubCommentTriggerHandler : CodeWebhookTrigg return event.comment.body } - override fun preMatch(event: T): ScmWebhookMatcher.MatchResult { - return ScmWebhookMatcher.MatchResult(true) + override fun preMatch(event: T): WebhookMatchResult { + return WebhookMatchResult(true) } override fun getWebhookFilters( From 43d22855c294d31cf849bdefd2bcbbd05cb10700 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 26 Oct 2023 16:57:22 +0800 Subject: [PATCH 086/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/code/handler/github/GithubIssueTriggerHandler.kt | 1 - .../service/code/handler/github/GithubReviewTriggerHandler.kt | 1 - 2 files changed, 2 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubIssueTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubIssueTriggerHandler.kt index ce84a5840c0..33d95b37edd 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubIssueTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubIssueTriggerHandler.kt @@ -46,7 +46,6 @@ import com.tencent.devops.common.webhook.service.code.filter.EventTypeFilter import com.tencent.devops.common.webhook.service.code.filter.GitUrlFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler -import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubReviewTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubReviewTriggerHandler.kt index 06b36f96595..3b7bd703814 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubReviewTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubReviewTriggerHandler.kt @@ -48,7 +48,6 @@ import com.tencent.devops.common.webhook.service.code.filter.EventTypeFilter import com.tencent.devops.common.webhook.service.code.filter.GitUrlFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler -import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.repository.pojo.Repository From db9c33f90077222e729a467d804bd775846b1eec Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 26 Oct 2023 18:00:25 +0800 Subject: [PATCH 087/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/GithubIssueTriggerHandler.kt | 42 ++++++++++++++++++- .../github/GithubReviewTriggerHandler.kt | 40 +++++++++++++++++- .../comment/GithubCommentTriggerHandler.kt | 37 +++++++++++++++- .../GithubCommitCommentTriggerHandler.kt | 13 ++++++ .../GithubIssueCommentTriggerHandler.kt | 13 ++++++ .../GithubReviewCommentTriggerHandler.kt | 13 ++++++ .../parser/GithubWebhookEventParser.kt | 10 +++++ 7 files changed, 164 insertions(+), 4 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubIssueTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubIssueTriggerHandler.kt index 33d95b37edd..d8d152f6d78 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubIssueTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubIssueTriggerHandler.kt @@ -27,9 +27,11 @@ package com.tencent.devops.common.webhook.service.code.handler.github +import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_EVENT_URL import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_ISSUE_ACTION import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_ISSUE_DESCRIPTION import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_ISSUE_ID @@ -40,6 +42,7 @@ import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_ISSUE_TIT import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_ISSUE_URL import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.pojo.code.github.GithubBaseInfo +import com.tencent.devops.common.webhook.pojo.code.github.GithubIssuesAction import com.tencent.devops.common.webhook.pojo.code.github.GithubIssuesEvent import com.tencent.devops.common.webhook.service.code.filter.ContainsFilter import com.tencent.devops.common.webhook.service.code.filter.EventTypeFilter @@ -48,6 +51,7 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository @CodeWebhookHandler @@ -87,6 +91,26 @@ class GithubIssueTriggerHandler : CodeWebhookTriggerHandler { return event.issue.title } + override fun getExternalId(event: GithubIssuesEvent): String { + return event.repository.id.toString() + } + + override fun getEventDesc(event: GithubIssuesEvent, replayInfo: PipelineEventReplayInfo?): String { + val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( + replayInfo, + getUsername(event), + getI18Code(event) + ) + return I18Variable( + code = i18Code, + params = listOf( + buildIssuesUrl(event), + event.issue.number.toString(), + username + ) + ).toJsonStr() + } + override fun preMatch(event: GithubIssuesEvent): WebhookMatchResult { return WebhookMatchResult(true) } @@ -114,7 +138,11 @@ class GithubIssueTriggerHandler : CodeWebhookTriggerHandler { pipelineId = pipelineId, filterName = "issueAction", triggerOn = event.convertAction(), - included = WebhookUtils.convert(includeIssueAction) + included = WebhookUtils.convert(includeIssueAction), + failedReason = I18Variable( + code = WebhookI18nConstants.ISSUES_ACTION_NOT_MATCH, + params = listOf() + ).toJsonStr() ) return listOf(urlFilter, eventTypeFilter, actionFilter) } @@ -139,4 +167,16 @@ class GithubIssueTriggerHandler : CodeWebhookTriggerHandler { } return startParams } + + private fun getI18Code(event: GithubIssuesEvent) = when (event.action) { + GithubIssuesAction.OPENED.value -> WebhookI18nConstants.TGIT_ISSUE_CREATED_EVENT_DESC + GithubIssuesAction.EDITED.value -> WebhookI18nConstants.TGIT_ISSUE_UPDATED_EVENT_DESC + GithubIssuesAction.CLOSED.value -> WebhookI18nConstants.TGIT_ISSUE_CLOSED_EVENT_DESC + GithubIssuesAction.REOPENED.value -> WebhookI18nConstants.TGIT_ISSUE_REOPENED_EVENT_DESC + else -> "" + } + + private fun buildIssuesUrl(event: GithubIssuesEvent) = with(event) { + issue.htmlUrl ?: "${GithubBaseInfo.GITHUB_HOME_PAGE_URL}/${repository.fullName}/issues/${issue.number}" + } } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubReviewTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubReviewTriggerHandler.kt index 3b7bd703814..b76fb84c066 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubReviewTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubReviewTriggerHandler.kt @@ -27,8 +27,10 @@ package com.tencent.devops.common.webhook.service.code.handler.github +import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_REVIEW_APPROVING_REVIEWERS import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_REVIEW_ID import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_REVIEW_IID @@ -50,6 +52,7 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -93,6 +96,26 @@ class GithubReviewTriggerHandler @Autowired constructor( return event.pullRequest.title } + override fun getExternalId(event: GithubReviewEvent): String { + return event.repository.id.toString() + } + + override fun getEventDesc(event: GithubReviewEvent, replayInfo: PipelineEventReplayInfo?): String { + val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( + replayInfo, + getUsername(event), + getI18Code(event) + ) + return I18Variable( + code = i18Code, + params = listOf( + buildReviewUrl(event), + event.pullRequest.number.toString(), + username + ) + ).toJsonStr() + } + override fun preMatch(event: GithubReviewEvent): WebhookMatchResult { // Review事件仅提交操作才触发,评审通过、拒绝、要求修改 val result = (event.action == "submitted" || event.action == "dismissed") && @@ -133,7 +156,11 @@ class GithubReviewTriggerHandler @Autowired constructor( pipelineId = pipelineId, filterName = "crState", triggerOn = event.convertState(), - included = WebhookUtils.convert(includeCrState) + included = WebhookUtils.convert(includeCrState), + failedReason = I18Variable( + code = WebhookI18nConstants.REVIEW_ACTION_NOT_MATCH, + params = listOf() + ).toJsonStr() ) return listOf(urlFilter, eventTypeFilter, crStateFilter) } @@ -169,6 +196,17 @@ class GithubReviewTriggerHandler @Autowired constructor( return startParams } + private fun getI18Code(event: GithubReviewEvent) = when (event.review.state) { + GithubReviewState.APPROVED.value -> WebhookI18nConstants.TGIT_REVIEW_APPROVED_EVENT_DESC + GithubReviewState.CHANGES_REQUESTED.value -> WebhookI18nConstants.TGIT_REVIEW_CHANGE_REQUIRED_EVENT_DESC + GithubReviewState.DISMISSED.value -> WebhookI18nConstants.TGIT_REVIEW_CHANGE_DENIED_EVENT_DESC + else -> "" + } + + private fun buildReviewUrl(event: GithubReviewEvent) = with(event) { + review.htmlUrl ?: "${GithubBaseInfo.GITHUB_HOME_PAGE_URL}/${repository.fullName}/pull/${pullRequest.number}" + } + companion object { private val logger = LoggerFactory.getLogger(GithubReviewTriggerHandler::class.java) } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/comment/GithubCommentTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/comment/GithubCommentTriggerHandler.kt index 872b153674c..ad5766f0efa 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/comment/GithubCommentTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/comment/GithubCommentTriggerHandler.kt @@ -27,7 +27,9 @@ package com.tencent.devops.common.webhook.service.code.handler.github.comment +import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_NOTE_AUTHOR_ID import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_NOTE_COMMENT import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GIT_WEBHOOK_NOTE_CREATED_AT @@ -49,6 +51,7 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils +import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository /** @@ -86,6 +89,26 @@ interface GithubCommentTriggerHandler : CodeWebhookTrigg return event.comment.body } + override fun getExternalId(event: T): String { + return event.repository.id.toString() + } + + override fun getEventDesc(event: T, replayInfo: PipelineEventReplayInfo?): String { + val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( + replayInfo, + getUsername(event), + WebhookI18nConstants.TGIT_NOTE_EVENT_DESC + ) + return I18Variable( + code = i18Code, + params = listOf( + buildCommentUrl(event), + event.comment.id.toString(), + username + ) + ).toJsonStr() + } + override fun preMatch(event: T): WebhookMatchResult { return WebhookMatchResult(true) } @@ -113,13 +136,21 @@ interface GithubCommentTriggerHandler : CodeWebhookTrigg pipelineId = pipelineId, filterName = "noteTypeAction", triggerOn = event.getCommentType(), - included = WebhookUtils.convert(includeNoteTypes) + included = WebhookUtils.convert(includeNoteTypes), + failedReason = I18Variable( + code = WebhookI18nConstants.NOTE_ACTION_NOT_MATCH, + params = listOf() + ).toJsonStr() ) val commentActionFilter = RegexContainFilter( pipelineId = pipelineId, filterName = "noteCommentAction", triggerOn = event.comment.body, - included = WebhookUtils.convert(includeNoteComment) + included = WebhookUtils.convert(includeNoteComment), + failedReason = I18Variable( + code = WebhookI18nConstants.NOTE_CONTENT_NOT_MATCH, + params = listOf() + ).toJsonStr() ) return listOf(urlFilter, eventTypeFilter, typeActionFilter, commentActionFilter) } @@ -153,4 +184,6 @@ interface GithubCommentTriggerHandler : CodeWebhookTrigg * Github 评论事件关联参数,根据具体事件类型进行填充 */ fun getCommentParam(event: T): Map + + fun buildCommentUrl(event: T): String } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/comment/GithubCommitCommentTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/comment/GithubCommitCommentTriggerHandler.kt index 607358634a5..eef2f1b345c 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/comment/GithubCommitCommentTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/comment/GithubCommitCommentTriggerHandler.kt @@ -31,6 +31,7 @@ import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_COMMIT_AUTHOR import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_SHA import com.tencent.devops.common.pipeline.utils.PIPELINE_GIT_SHA_SHORT import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler +import com.tencent.devops.common.webhook.pojo.code.github.GithubBaseInfo import com.tencent.devops.common.webhook.pojo.code.github.GithubCommitCommentEvent @CodeWebhookHandler @@ -53,4 +54,16 @@ class GithubCommitCommentTriggerHandler : GithubCommentTriggerHandler objectMapper.readValue(body) GithubPullRequestEvent.classType -> objectMapper.readValue(body) GithubCheckRunEvent.classType -> objectMapper.readValue(body) + GithubCommitCommentEvent.classType -> objectMapper.readValue(body) + GithubIssueCommentEvent.classType -> objectMapper.readValue(body) + GithubReviewCommentEvent.classType -> objectMapper.readValue(body) + GithubIssuesEvent.classType -> objectMapper.readValue(body) + GithubReviewEvent.classType -> objectMapper.readValue(body) else -> { logger.info("Github event($eventType) is ignored") return null From 4158736138a49a1cd6d5d749041a77813dfb062c Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 26 Oct 2023 18:00:51 +0800 Subject: [PATCH 088/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/UserPipelineTriggerEventResource.kt | 3 +++ .../pojo/trigger/PipelineTriggerType.kt | 17 ++++++++++++++--- .../UserPipelineTriggerEventResourceImpl.kt | 2 ++ .../process/dao/PipelineTriggerEventDao.kt | 12 +++++++++++- .../trigger/PipelineTriggerEventService.kt | 19 +++++++++++++++++-- .../i18n/process/message_en_US.properties | 3 +++ .../i18n/process/message_zh_CN.properties | 3 +++ 7 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt index 9e34348f877..4231fd04dbc 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserPipelineTriggerEventResource.kt @@ -176,6 +176,9 @@ interface UserPipelineTriggerEventResource { @ApiParam("流水线ID", required = false) @QueryParam("pipelineId") pipelineId: String?, + @ApiParam("流水线名", required = false) + @QueryParam("pipelineName") + pipelineName: String?, @ApiParam("第几页", required = false, defaultValue = "1") @QueryParam("page") page: Int?, diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt index 11e66816f14..c02a960df24 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt @@ -33,19 +33,25 @@ import com.tencent.devops.common.web.utils.I18nUtil import io.swagger.annotations.ApiModel import io.swagger.annotations.ApiModelProperty +@Suppress("IMPLICIT_CAST_TO_ANY") @ApiModel("流水线触发类型") enum class PipelineTriggerType { // WEB_HOOK 触发 @ApiModelProperty("SVN 代码库") CODE_SVN, + @ApiModelProperty("GIT 代码库") CODE_GIT, + @ApiModelProperty("Gitlab 代码库") CODE_GITLAB, + @ApiModelProperty("Github 代码库") GITHUB, + @ApiModelProperty("TGIT 代码库") CODE_TGIT, + @ApiModelProperty("P4 代码库") CODE_P4, @@ -77,9 +83,14 @@ enum class PipelineTriggerType { scmType: ScmType?, userId: String ): List { - return PipelineTriggerType.values().filter { - scmType == null || scmType.name == it.name - }.plus(commonTriggerTypes).map { + val triggerTypes = if (scmType == null) { + PipelineTriggerType.values().toList() + } else { + PipelineTriggerType.values().filter { + scmType.name == it.name + }.plus(commonTriggerTypes) + } + return triggerTypes.map { IdValue( id = it.name, value = I18nUtil.getCodeLanMessage( diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt index 94951c183da..6e7d26bfd4e 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt @@ -142,6 +142,7 @@ class UserPipelineTriggerEventResourceImpl( projectId: String, eventId: Long, pipelineId: String?, + pipelineName: String?, page: Int?, pageSize: Int? ): Result> { @@ -150,6 +151,7 @@ class UserPipelineTriggerEventResourceImpl( projectId = projectId, eventId = eventId, pipelineId = pipelineId, + pipelineName = pipelineName, page = page, pageSize = pageSize, userId = userId diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index 881ee8cd57d..c2b54f75708 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -132,6 +132,7 @@ class PipelineTriggerEventDao { triggerType: String? = null, triggerUser: String? = null, pipelineId: String? = null, + pipelineName: String? = null, startTime: Long? = null, endTime: Long? = null, limit: Int, @@ -148,6 +149,7 @@ class PipelineTriggerEventDao { triggerUser = triggerUser, triggerType = triggerType, pipelineId = pipelineId, + pipelineName = pipelineName, startTime = startTime, endTime = endTime ) @@ -204,6 +206,7 @@ class PipelineTriggerEventDao { triggerType: String? = null, triggerUser: String? = null, pipelineId: String? = null, + pipelineName: String? = null, startTime: Long? = null, endTime: Long? = null ): Long { @@ -218,6 +221,7 @@ class PipelineTriggerEventDao { triggerUser = triggerUser, triggerType = triggerType, pipelineId = pipelineId, + pipelineName = pipelineName, startTime = startTime, endTime = endTime ) @@ -269,13 +273,19 @@ class PipelineTriggerEventDao { startTime = startTime, endTime = endTime ) + // 总数 + val totalCondition = if (pipelineName.isNullOrBlank()) { + count() + } else { + count(`when`(t2.PIPELINE_NAME.like("%$pipelineName%"), 1)) + }.`as`("total") return dslContext.select( t1.PROJECT_ID, t1.EVENT_ID, t1.EVENT_SOURCE, t1.EVENT_DESC, t1.EVENT_TIME, - count().`as`("total"), + totalCondition, count(`when`(t2.STATUS.eq(PipelineTriggerStatus.SUCCEED.name), 1)).`as`("success ") ).from(t1).leftJoin(t2) .on(t1.EVENT_ID.eq(t2.EVENT_ID)).and(t1.PROJECT_ID.eq(t2.PROJECT_ID)) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 20021bf42fe..b239f14723a 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -49,6 +49,7 @@ import com.tencent.devops.process.pojo.BuildId import com.tencent.devops.process.pojo.trigger.PipelineTriggerDetail import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventVo +import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason import com.tencent.devops.process.pojo.trigger.PipelineTriggerReasonDetail import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.pojo.trigger.PipelineTriggerType @@ -77,7 +78,7 @@ class PipelineTriggerEventService @Autowired constructor( private const val PIPELINE_TRIGGER_EVENT_BIZ_ID = "PIPELINE_TRIGGER_EVENT" private const val PIPELINE_TRIGGER_DETAIL_BIZ_ID = "PIPELINE_TRIGGER_DETAIL" // 构建链接 - const val PIPELINE_BUILD_URL_PATTERN = "{1}" + const val PIPELINE_BUILD_URL_PATTERN = "#{1}" } fun getDetailId(): Long { @@ -217,6 +218,7 @@ class PipelineTriggerEventService @Autowired constructor( projectId: String, eventId: Long, pipelineId: String?, + pipelineName: String?, page: Int?, pageSize: Int?, userId: String @@ -233,19 +235,22 @@ class PipelineTriggerEventService @Autowired constructor( projectId = projectId, eventId = eventId, pipelineId = pipelineId, + pipelineName = pipelineName, 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 } val count = pipelineTriggerEventDao.countTriggerEvent( dslContext = dslContext, projectId = projectId, eventId = eventId, - pipelineId = pipelineId + pipelineId = pipelineId, + pipelineName = pipelineName ) return SQLPage(count = count, records = records) } @@ -429,6 +434,16 @@ class PipelineTriggerEventService @Autowired constructor( listOf() } + private fun PipelineTriggerEventVo.getI18nReason(language: String):String = getCodeLanMessage( + messageCode = if (this.reason.isNullOrBlank()) { + PipelineTriggerReason.TRIGGER_SUCCESS.name + } else { + this.reason!! + }, + language = language, + defaultMessage = this.reason + ) + /** * 获取构建链接 */ diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index c001650ed36..754401aaa6b 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -455,3 +455,6 @@ TRIGGER_TYPE_TIME_TRIGGER=Time Trigger TRIGGER_TYPE_SERVICE=Service Trigger TRIGGER_TYPE_PIPELINE=Pipeline Trigger TRIGGER_TYPE_REMOTE=Remote Trigger +TRIGGER_SUCCESS=Trigger success +TRIGGER_FAILED=Trigger failed +TRIGGER_NOT_MATCH=Trigger not match diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index ed2c6e20474..ce4991c734e 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -455,3 +455,6 @@ TRIGGER_TYPE_TIME_TRIGGER=定时触发 TRIGGER_TYPE_SERVICE=服务触发 TRIGGER_TYPE_PIPELINE=流水线触发 TRIGGER_TYPE_REMOTE=远程触发 +TRIGGER_SUCCESS=触发成功 +TRIGGER_FAILED=触发失败 +TRIGGER_NOT_MATCH=触发器不匹配 From 821a92adb75b01f289ca549a84acf8a069aa9911 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 26 Oct 2023 18:06:05 +0800 Subject: [PATCH 089/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/trigger/PipelineTriggerEventService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index b239f14723a..c1b3f462e4c 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -434,7 +434,7 @@ class PipelineTriggerEventService @Autowired constructor( listOf() } - private fun PipelineTriggerEventVo.getI18nReason(language: String):String = getCodeLanMessage( + private fun PipelineTriggerEventVo.getI18nReason(language: String): String = getCodeLanMessage( messageCode = if (this.reason.isNullOrBlank()) { PipelineTriggerReason.TRIGGER_SUCCESS.name } else { From b5acd8c9164dc858d4760ec08cb41e7f687553e7 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 27 Oct 2023 09:08:25 +0800 Subject: [PATCH 090/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/tencent/devops/common/api/pojo/I18Variable.kt | 2 +- .../devops/process/service/PipelineRemoteAuthService.kt | 3 ++- .../devops/process/webhook/listener/WebhookEventListener.kt | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/pojo/I18Variable.kt b/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/pojo/I18Variable.kt index 2af7d8e2c08..687bb6ea39d 100644 --- a/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/pojo/I18Variable.kt +++ b/src/backend/ci/core/common/common-api/src/main/kotlin/com/tencent/devops/common/api/pojo/I18Variable.kt @@ -42,4 +42,4 @@ data class I18Variable( val defaultMessage: String? = null ) { fun toJsonStr() = JsonUtil.toJson(this, false) -} \ No newline at end of file +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt index f2cea5b1a4b..cb2efe6f4ed 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt @@ -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, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt index a07298e70c0..fd01dcf9eb7 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt @@ -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()) { From 6a76e6b1b56127d6211367c584f10e1f0660ea50 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 27 Oct 2023 10:04:32 +0800 Subject: [PATCH 091/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pojo/trigger/PipelineTriggerEventVo.kt | 6 ++- .../trigger/PipelineTriggerEventService.kt | 45 ++++++++++++------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventVo.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventVo.kt index 90f6e98391e..edefbcdb43c 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventVo.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventVo.kt @@ -61,6 +61,8 @@ data class PipelineTriggerEventVo( var buildNum: String? = null, @ApiModelProperty("原因") var reason: String? = null, - @ApiModelProperty("原因详情", required = false) - var reasonDetailList: List? = null + @ApiModelProperty("失败原因详情", required = false) + var reasonDetailList: List? = null, + @ApiModelProperty("失败原因", required = false) + var failReason: String = "" ) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index c1b3f462e4c..b55ee1cb097 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -123,6 +123,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, @@ -145,13 +146,7 @@ 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 + fillEventDetailParam(it, language) } return SQLPage(count = count, records = records) } @@ -239,11 +234,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, @@ -434,14 +425,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 ) /** @@ -456,4 +447,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 + } + } } From 6714f72e63ce97279e4526b23c3b568280ba5274 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 27 Oct 2023 10:49:44 +0800 Subject: [PATCH 092/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/trigger/PipelineTriggerEventService.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index b55ee1cb097..a8568129f47 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -146,7 +146,9 @@ class PipelineTriggerEventService @Autowired constructor( limit = sqlLimit.limit, offset = sqlLimit.offset ).map { - fillEventDetailParam(it, language) + it.eventDesc = it.getI18nEventDesc(language) + it.reason = getI18nReason(it.reason,language) + it } return SQLPage(count = count, records = records) } From f0ca8d4a8afbcb202aa53b4f48bd026d530a1502 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Fri, 27 Oct 2023 15:27:59 +0800 Subject: [PATCH 093/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pojo/trigger/PipelineTriggerEvent.kt | 8 ++- ...ubscriber.kt => WebhookTriggerPipeline.kt} | 2 +- .../engine/EventDispatcherConfiguration.kt | 4 -- .../process/engine/dao/PipelineWebhookDao.kt | 66 +++++++++++++++++-- .../process/dao/PipelineTriggerEventDao.kt | 45 +++++++++---- .../engine/service/PipelineWebhookService.kt | 34 +++++++++- .../webhook/PipelineBuildWebhookService.kt | 14 ++-- .../trigger/PipelineTriggerEventService.kt | 54 ++++++++++++--- .../process/trigger/WebhookTriggerService.kt | 59 ++++++++--------- .../webhook/CodeWebhookEventDispatcher.kt | 23 +++++++ .../process/webhook/WebhookMQConfiguration.kt | 2 +- .../process/webhook/WebhookRequestService.kt | 43 +++++++----- .../webhook/listener/WebhookEventListener.kt | 42 +++++++++++- .../ReplayWebhookEvent.kt} | 19 ++++-- .../api/ServiceRepositoryWebhookResource.kt | 4 +- .../pojo/RepositoryWebhookRequest.kt | 4 +- .../devops/repository/dao/RepositoryDao.kt | 2 +- .../dao/RepositoryWebhookRequestDao.kt | 8 ++- .../ServiceRepositoryWebhookResourceImpl.kt | 7 +- .../service/RepositoryWebhookService.kt | 6 +- .../sql/1001_ci_process_ddl_mysql.sql | 12 ++-- .../sql/1001_ci_repository_ddl_mysql.sql | 2 +- 22 files changed, 339 insertions(+), 121 deletions(-) rename src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/{PipelineWebhookSubscriber.kt => WebhookTriggerPipeline.kt} (97%) rename src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/{WebhookRequestReplayEvent.kt => commit/ReplayWebhookEvent.kt} (80%) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt index 16177d9a348..207d7ffe7ab 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt @@ -34,6 +34,8 @@ import java.time.LocalDateTime @ApiModel("流水线触发事件") data class PipelineTriggerEvent( + @ApiModelProperty("请求ID") + val requestId: String, @ApiModelProperty("项目ID") var projectId: String? = null, @ApiModelProperty("事件ID") @@ -48,10 +50,10 @@ data class PipelineTriggerEvent( val triggerUser: String, @ApiModelProperty("事件描述") val eventDesc: String, - @ApiModelProperty("webhook事件请求ID") - val hookRequestId: Long?, + @ApiModelProperty("重放事件ID") + val replayEventId: Long? = null, @ApiModelProperty("事件请求参数, 记录手动/openapi/定时/远程触发启动参数") val requestParams: Map? = null, @ApiModelProperty("触发事件") - val eventTime: LocalDateTime + val createTime: LocalDateTime ) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhookSubscriber.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/WebhookTriggerPipeline.kt similarity index 97% rename from src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhookSubscriber.kt rename to src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/WebhookTriggerPipeline.kt index 29a4a3bd4f9..4c5a6530126 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/PipelineWebhookSubscriber.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/webhook/WebhookTriggerPipeline.kt @@ -28,7 +28,7 @@ package com.tencent.devops.process.pojo.webhook -data class PipelineWebhookSubscriber( +data class WebhookTriggerPipeline( val projectId: String, val pipelineId: String, val version: Int? = null diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/EventDispatcherConfiguration.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/EventDispatcherConfiguration.kt index a5b733a3892..9e8cc18660b 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/EventDispatcherConfiguration.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/EventDispatcherConfiguration.kt @@ -28,7 +28,6 @@ package com.tencent.devops.process.engine import com.tencent.devops.common.event.dispatcher.pipeline.mq.MQEventDispatcher -import com.tencent.devops.common.event.dispatcher.trace.TraceEventDispatcher import org.springframework.amqp.rabbit.core.RabbitTemplate import org.springframework.boot.autoconfigure.AutoConfigureOrder import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication @@ -49,7 +48,4 @@ class EventDispatcherConfiguration { @Bean fun pipelineEventDispatcher(rabbitTemplate: RabbitTemplate) = MQEventDispatcher(rabbitTemplate) - - @Bean - fun traceEventDispatcher(rabbitTemplate: RabbitTemplate) = TraceEventDispatcher(rabbitTemplate) } diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt index 83e04a25cd4..5f6a3a73ff2 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt @@ -32,7 +32,7 @@ import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.model.process.Tables.T_PIPELINE_WEBHOOK import com.tencent.devops.model.process.tables.records.TPipelineWebhookRecord import com.tencent.devops.process.pojo.webhook.PipelineWebhook -import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber +import com.tencent.devops.process.pojo.webhook.WebhookTriggerPipeline import org.jooq.DSLContext import org.jooq.Result import org.slf4j.LoggerFactory @@ -160,7 +160,7 @@ class PipelineWebhookDao { dslContext: DSLContext, projectName: String, repositoryType: String - ): List? { + ): List? { with(T_PIPELINE_WEBHOOK) { return dslContext.select(PROJECT_ID, PIPELINE_ID).from(this) .where(PROJECT_NAME.eq(projectName)) @@ -168,7 +168,7 @@ class PipelineWebhookDao { .and(DELETE.eq(false)) .groupBy(PROJECT_ID, PIPELINE_ID) .fetch().map { - PipelineWebhookSubscriber( + WebhookTriggerPipeline( projectId = it.value1(), pipelineId = it.value2() ) @@ -176,6 +176,62 @@ class PipelineWebhookDao { } } + fun listTriggerPipeline( + dslContext: DSLContext, + projectId: String, + repositoryHashId: String, + eventType: String + ): List? { + with(T_PIPELINE_WEBHOOK) { + return dslContext.select(PROJECT_ID, PIPELINE_ID).from(this) + .where(PROJECT_ID.eq(projectId)) + .and(REPOSITORY_HASH_ID.eq(repositoryHashId)) + .and(EVENT_TYPE.eq(eventType)) + .and(DELETE.eq(false)) + .groupBy(PROJECT_ID, PIPELINE_ID) + .fetch().map { + WebhookTriggerPipeline( + projectId = it.value1(), + pipelineId = it.value2() + ) + } + } + } + + fun listWebhookPipeline( + dslContext: DSLContext, + projectId: String, + pipelineId: String, + repositoryType: String, + eventType: String + ): List { + with(T_PIPELINE_WEBHOOK) { + return dslContext.selectFrom(this) + .where(PROJECT_ID.eq(projectId)) + .and(PIPELINE_ID.eq(pipelineId)) + .and(REPOSITORY_TYPE.eq(repositoryType)) + .and(EVENT_TYPE.eq(eventType)) + .and(DELETE.eq(false)) + .fetch().map { convert(it) } + } + } + + fun listWebhookPipeline( + dslContext: DSLContext, + projectName: String, + repositoryType: String, + eventType: String + ): List? { + with(T_PIPELINE_WEBHOOK) { + return dslContext.selectFrom(this) + .where(PROJECT_NAME.eq(projectName)) + .and(REPOSITORY_TYPE.eq(repositoryType)) + .and(EVENT_TYPE.eq(eventType)) + .and(DELETE.eq(false)) + .fetch().map { convert(it) } + } + } + fun updateProjectNameAndTaskId( dslContext: DSLContext, projectId: String, @@ -238,13 +294,13 @@ class PipelineWebhookDao { dslContext: DSLContext, offset: Int, limit: Int - ): List { + ): List { return with(T_PIPELINE_WEBHOOK) { dslContext.select(PROJECT_ID, PIPELINE_ID).from(this) .where(DELETE.eq(false)) .limit(offset, limit) .fetch().map { - PipelineWebhookSubscriber( + WebhookTriggerPipeline( projectId = it.value1(), pipelineId = it.value2() ) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index c2b54f75708..862b34ee97a 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -63,6 +63,7 @@ class PipelineTriggerEventDao { with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { dslContext.insertInto( this, + REQUEST_ID, PROJECT_ID, EVENT_ID, TRIGGER_TYPE, @@ -70,10 +71,11 @@ class PipelineTriggerEventDao { EVENT_TYPE, TRIGGER_USER, EVENT_DESC, - HOOK_REQUEST_ID, + REPLAY_EVENT_ID, REQUEST_PARAMS, - EVENT_TIME + CREATE_TIME ).values( + triggerEvent.requestId, triggerEvent.projectId, triggerEvent.eventId, triggerEvent.triggerType, @@ -81,9 +83,9 @@ class PipelineTriggerEventDao { triggerEvent.eventType, triggerEvent.triggerUser, JsonUtil.toJson(triggerEvent.eventDesc), - triggerEvent.hookRequestId, + triggerEvent.replayEventId, triggerEvent.requestParams?.let { JsonUtil.toJson(it) }, - triggerEvent.eventTime + triggerEvent.createTime ).onDuplicateKeyIgnore().execute() } } @@ -162,7 +164,7 @@ class PipelineTriggerEventDao { t1.EVENT_TYPE, t1.TRIGGER_USER, t1.EVENT_DESC, - t1.EVENT_TIME, + t1.CREATE_TIME, t2.STATUS, t2.PIPELINE_ID, t2.PIPELINE_NAME, @@ -173,7 +175,7 @@ class PipelineTriggerEventDao { ).from(t1).leftJoin(t2) .on(t1.EVENT_ID.eq(t2.EVENT_ID)).and(t1.PROJECT_ID.eq(t2.PROJECT_ID)) .where(conditions) - .orderBy(t1.EVENT_TIME.desc()).limit(limit) + .orderBy(t1.CREATE_TIME.desc()).limit(limit) .offset(offset) .fetch().map { PipelineTriggerEventVo( @@ -284,14 +286,14 @@ class PipelineTriggerEventDao { t1.EVENT_ID, t1.EVENT_SOURCE, t1.EVENT_DESC, - t1.EVENT_TIME, + t1.CREATE_TIME, totalCondition, count(`when`(t2.STATUS.eq(PipelineTriggerStatus.SUCCEED.name), 1)).`as`("success ") ).from(t1).leftJoin(t2) .on(t1.EVENT_ID.eq(t2.EVENT_ID)).and(t1.PROJECT_ID.eq(t2.PROJECT_ID)) .where(conditions) - .groupBy(t1.PROJECT_ID, t1.EVENT_ID, t1.EVENT_SOURCE, t1.EVENT_DESC, t1.EVENT_TIME) - .orderBy(t1.EVENT_TIME.desc()) + .groupBy(t1.PROJECT_ID, t1.EVENT_ID, t1.EVENT_SOURCE, t1.EVENT_DESC, t1.CREATE_TIME) + .orderBy(t1.CREATE_TIME.desc()) .limit(limit) .offset(offset) .fetch().map { @@ -358,6 +360,22 @@ class PipelineTriggerEventDao { return record?.let { convertEvent(it) } } + fun getEventByRequestId( + dslContext: DSLContext, + projectId: String, + requestId: String, + eventSource: String + ): PipelineTriggerEvent? { + val record = with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { + dslContext.selectFrom(this) + .where(PROJECT_ID.eq(projectId)) + .and(REQUEST_ID.eq(requestId)) + .and(EVENT_SOURCE.eq(eventSource)) + .fetchOne() + } + return record?.let { convertEvent(it) } + } + fun getTriggerDetail( dslContext: DSLContext, projectId: String, @@ -407,10 +425,10 @@ class PipelineTriggerEventDao { conditions.add(t2.PIPELINE_ID.eq(pipelineId)) } if (startTime != null && startTime > 0) { - conditions.add(t1.EVENT_TIME.ge(Timestamp(startTime).toLocalDateTime())) + conditions.add(t1.CREATE_TIME.ge(Timestamp(startTime).toLocalDateTime())) } if (endTime != null && endTime > 0) { - conditions.add(t1.EVENT_TIME.le(Timestamp(endTime).toLocalDateTime())) + conditions.add(t1.CREATE_TIME.le(Timestamp(endTime).toLocalDateTime())) } if (!pipelineName.isNullOrBlank()) { conditions.add(t2.PIPELINE_NAME.like("%$pipelineName%")) @@ -421,6 +439,7 @@ class PipelineTriggerEventDao { fun convertEvent(record: TPipelineTriggerEventRecord): PipelineTriggerEvent { return with(record) { PipelineTriggerEvent( + requestId = requestId, projectId = projectId, eventId = eventId, eventSource = eventSource, @@ -428,13 +447,13 @@ class PipelineTriggerEventDao { triggerUser = triggerUser, eventType = eventType, eventDesc = JsonUtil.to(eventDesc, I18Variable::class.java).getCodeLanMessage(), - hookRequestId = hookRequestId, + replayEventId = replayEventId, requestParams = requestParams?.let { JsonUtil.to( it, object : TypeReference>() {}) }, - eventTime = eventTime + createTime = createTime ) } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index bf29497b039..1cabcd80645 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -64,7 +64,7 @@ import com.tencent.devops.process.engine.pojo.WebhookElementParams import com.tencent.devops.process.permission.PipelinePermissionService import com.tencent.devops.process.pojo.PipelineNotifyTemplateEnum import com.tencent.devops.process.pojo.webhook.PipelineWebhook -import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber +import com.tencent.devops.process.pojo.webhook.WebhookTriggerPipeline import com.tencent.devops.process.service.scm.ScmProxyService import com.tencent.devops.repository.api.ServiceRepositoryResource import com.tencent.devops.repository.pojo.CodeGitRepository @@ -293,7 +293,7 @@ class PipelineWebhookService @Autowired constructor( } } - fun getWebhookPipelines(name: String, repositoryType: String): List { + fun getTriggerPipelines(name: String, repositoryType: String): List { return pipelineWebhookDao.getByProjectNameAndType( dslContext = dslContext, projectName = getProjectName(name), @@ -301,6 +301,32 @@ class PipelineWebhookService @Autowired constructor( ) ?: emptyList() } + fun listTriggerPipeline( + projectId: String, + repositoryHashId: String, + eventType: String + ): List { + return pipelineWebhookDao.listTriggerPipeline( + dslContext = dslContext, + projectId = projectId, + repositoryHashId = repositoryHashId, + eventType = eventType + ) ?: emptyList() + } + + fun listPipelineWebhook( + name: String, + repositoryType: String, + eventType: String + ): List { + return pipelineWebhookDao.listWebhookPipeline( + dslContext = dslContext, + projectName = getProjectName(name), + repositoryType = repositoryType, + eventType = eventType + ) ?: emptyList() + } + fun getProjectName(projectName: String): String { // 如果项目名是三层的,比如a/b/c,那对应的rep_name是b val repoSplit = projectName.split("/") @@ -731,7 +757,9 @@ class PipelineWebhookService @Autowired constructor( ) null } - Optional.ofNullable(repo) + val optional = Optional.ofNullable(repo) + repoCache[repoCacheKey] = optional + optional } val repository = if (repositoryOptional.isPresent) { repositoryOptional.get() diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt index 1022c4d6ea5..8fc0ce5b8c7 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/webhook/PipelineBuildWebhookService.kt @@ -55,7 +55,7 @@ import com.tencent.devops.process.pojo.trigger.PipelineTriggerDetailBuilder import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason import com.tencent.devops.process.pojo.trigger.PipelineTriggerReasonDetail import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus -import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber +import com.tencent.devops.process.pojo.webhook.WebhookTriggerPipeline import com.tencent.devops.process.service.builds.PipelineBuildCommitService import com.tencent.devops.process.service.pipeline.PipelineBuildService import com.tencent.devops.process.trigger.PipelineTriggerEventService @@ -102,15 +102,15 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { private val logger = LoggerFactory.getLogger(PipelineBuildWebhookService::class.java) } - fun dispatchPipelineSubscribers( + fun dispatchTriggerPipelines( matcher: ScmWebhookMatcher, triggerEvent: PipelineTriggerEvent, - subscribers: List + triggerPipelines: List ): Boolean { try { logger.info("dispatch pipeline webhook subscriber|repo(${matcher.getRepoName()})") - if (subscribers.isEmpty()) { + if (triggerPipelines.isEmpty()) { gitWebhookUnlockDispatcher.dispatchUnlockHookLockEvent(matcher) return false } @@ -118,7 +118,7 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { EventCacheUtil.initEventCache() // 代码库触发的事件ID,一个代码库会触发多条流水线,但应该只有一条触发事件 val repoEventIdMap = mutableMapOf() - subscribers.forEach outside@{ subscriber -> + triggerPipelines.forEach outside@{ subscriber -> val projectId = subscriber.projectId val pipelineId = subscriber.pipelineId try { @@ -172,7 +172,9 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware { triggerEvent.eventSource = builder.getEventSource() triggerEvent.projectId = projectId val eventId = repoEventIdMap[builder.getEventSource()] ?: run { - val eventId = pipelineTriggerEventService.getEventId() + val eventId = pipelineTriggerEventService.getEventId( + projectId = projectId, requestId = triggerEvent.requestId, eventSource = triggerEvent.eventSource!! + ) repoEventIdMap[builder.getEventSource()!!] = eventId eventId } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index c1b3f462e4c..7d6b3923e36 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -36,7 +36,7 @@ import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.PageUtil import com.tencent.devops.common.client.Client -import com.tencent.devops.common.event.dispatcher.trace.TraceEventDispatcher +import com.tencent.devops.common.service.trace.TraceTag import com.tencent.devops.common.service.utils.HomeHostUtil import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.common.web.utils.I18nUtil.getCodeLanMessage @@ -54,11 +54,14 @@ import com.tencent.devops.process.pojo.trigger.PipelineTriggerReasonDetail import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.pojo.trigger.PipelineTriggerType import com.tencent.devops.process.pojo.trigger.RepoTriggerEventVo -import com.tencent.devops.process.webhook.pojo.event.WebhookRequestReplayEvent +import com.tencent.devops.process.webhook.CodeWebhookEventDispatcher +import com.tencent.devops.process.webhook.pojo.event.commit.ReplayWebhookEvent import com.tencent.devops.project.api.service.ServiceAllocIdResource import org.jooq.DSLContext import org.jooq.impl.DSL 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.stereotype.Service import java.text.MessageFormat @@ -70,7 +73,7 @@ class PipelineTriggerEventService @Autowired constructor( private val dslContext: DSLContext, private val client: Client, private val pipelineTriggerEventDao: PipelineTriggerEventDao, - private val traceEventDispatcher: TraceEventDispatcher + private val rabbitTemplate: RabbitTemplate ) { companion object { @@ -89,6 +92,15 @@ class PipelineTriggerEventService @Autowired constructor( return client.get(ServiceAllocIdResource::class).generateSegmentId(PIPELINE_TRIGGER_EVENT_BIZ_ID).data ?: 0 } + fun getEventId(projectId: String, requestId: String, eventSource: String): Long { + return pipelineTriggerEventDao.getEventByRequestId( + dslContext = dslContext, + projectId = projectId, + requestId = requestId, + eventSource = eventSource + )?.eventId ?: getEventId() + } + fun saveEvent( triggerEvent: PipelineTriggerEvent, triggerDetail: PipelineTriggerDetail @@ -301,11 +313,36 @@ class PipelineTriggerEventService @Autowired constructor( errorCode = ProcessMessageCode.ERROR_TRIGGER_TYPE_REPLAY_NOT_SUPPORT, params = arrayOf(triggerEvent.triggerType) ) - traceEventDispatcher.dispatch( - WebhookRequestReplayEvent( + // 保存重放事件 + val requestId = MDC.get(TraceTag.BIZID) + val replayEventId = getEventId() + val replayTriggerEvent = with(triggerEvent) { + PipelineTriggerEvent( + requestId = requestId, + projectId = projectId, + eventId = replayEventId, + triggerType = triggerType, + eventSource = eventSource, + eventType = eventType, + triggerUser = userId, + // TODO 事件重放文案 + eventDesc = "$userId replay $eventId", + replayEventId = eventId, + requestParams = requestParams, + createTime = LocalDateTime.now() + ) + } + pipelineTriggerEventDao.save( + dslContext = dslContext, + triggerEvent = replayTriggerEvent + ) + CodeWebhookEventDispatcher.dispatchReplayEvent( + rabbitTemplate = rabbitTemplate, + event = ReplayWebhookEvent( userId = userId, projectId = projectId, - hookRequestId = triggerEvent.hookRequestId!!, + eventId = replayEventId, + replayRequestId = triggerEvent.requestId, scmType = scmType, pipelineId = pipelineId ) @@ -364,6 +401,7 @@ class PipelineTriggerEventService @Autowired constructor( requestParams: Map? ) { val eventId = getEventId() + val requestId = MDC.get(TraceTag.BIZID) saveEvent( triggerDetail = PipelineTriggerDetail( eventId = eventId, @@ -387,8 +425,8 @@ class PipelineTriggerEventService @Autowired constructor( eventType = triggerType, triggerUser = userId, requestParams = requestParams, - eventTime = LocalDateTime.now(), - hookRequestId = null + createTime = LocalDateTime.now(), + requestId = requestId ) ) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/WebhookTriggerService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/WebhookTriggerService.kt index f0a162de3a6..7b10a80a809 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/WebhookTriggerService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/WebhookTriggerService.kt @@ -31,11 +31,10 @@ package com.tencent.devops.process.trigger import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.webhook.service.code.matcher.ScmWebhookMatcher import com.tencent.devops.process.engine.service.PipelineWebhookService -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent -import com.tencent.devops.process.pojo.webhook.PipelineWebhookSubscriber +import com.tencent.devops.process.pojo.webhook.WebhookTriggerPipeline import com.tencent.devops.process.service.webhook.PipelineBuildWebhookService -import com.tencent.devops.process.webhook.pojo.event.WebhookRequestReplayEvent +import com.tencent.devops.process.webhook.pojo.event.commit.ReplayWebhookEvent import org.slf4j.LoggerFactory import org.springframework.stereotype.Service import java.time.LocalDateTime @@ -52,7 +51,7 @@ class WebhookTriggerService( fun trigger( scmType: ScmType, matcher: ScmWebhookMatcher, - hookRequestId: Long, + requestId: String, eventTime: LocalDateTime ) { val preMatch = matcher.preMatch() @@ -60,62 +59,56 @@ class WebhookTriggerService( logger.info("webhook trigger pre match|${preMatch.reason}") return } - val webhookEvent = PipelineTriggerEvent( + val triggerEvent = PipelineTriggerEvent( + requestId = requestId, triggerType = scmType.name, eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), eventDesc = matcher.getEventDesc(), - hookRequestId = hookRequestId, - eventTime = eventTime + createTime = eventTime ) - val subscribers = pipelineWebhookService.getWebhookPipelines( + val triggerPipelines = pipelineWebhookService.getTriggerPipelines( name = matcher.getRepoName(), repositoryType = scmType.name ) - pipelineBuildWebhookService.dispatchPipelineSubscribers( + pipelineBuildWebhookService.dispatchTriggerPipelines( matcher = matcher, - triggerEvent = webhookEvent, - subscribers = subscribers + triggerEvent = triggerEvent, + triggerPipelines = triggerPipelines ) } fun replay( - replayEvent: WebhookRequestReplayEvent, - matcher: ScmWebhookMatcher, - eventTime: LocalDateTime + replayEvent: ReplayWebhookEvent, + triggerEvent: PipelineTriggerEvent, + matcher: ScmWebhookMatcher ) { val preMatch = matcher.preMatch() if (!preMatch.isMatch) { logger.info("webhook replay trigger pre match|${preMatch.reason}") return } - with(replayEvent) { - val triggerEvent = PipelineTriggerEvent( - triggerType = scmType.name, - eventType = matcher.getEventType().name, - triggerUser = userId, - eventDesc = matcher.getEventDesc(PipelineEventReplayInfo(userId)), - hookRequestId = hookRequestId, - eventTime = eventTime - ) - val subscribers = pipelineId?.let { + + val triggerPipelines = with(replayEvent) { + pipelineId?.let { listOf( - PipelineWebhookSubscriber( + WebhookTriggerPipeline( projectId = projectId, pipelineId = pipelineId ) ) } ?: run { - pipelineWebhookService.getWebhookPipelines( - name = matcher.getRepoName(), - repositoryType = scmType.name + pipelineWebhookService.listTriggerPipeline( + projectId = projectId, + repositoryHashId = triggerEvent.eventSource!!, + eventType = triggerEvent.eventType ) } - pipelineBuildWebhookService.dispatchPipelineSubscribers( - matcher = matcher, - triggerEvent = triggerEvent, - subscribers = subscribers - ) } + pipelineBuildWebhookService.dispatchTriggerPipelines( + matcher = matcher, + triggerEvent = triggerEvent, + triggerPipelines = triggerPipelines + ) } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/CodeWebhookEventDispatcher.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/CodeWebhookEventDispatcher.kt index 8aaae61e898..b53d3c3a0f1 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/CodeWebhookEventDispatcher.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/CodeWebhookEventDispatcher.kt @@ -30,6 +30,7 @@ package com.tencent.devops.process.webhook import com.tencent.devops.common.event.annotation.Event import com.tencent.devops.process.webhook.pojo.event.commit.GithubWebhookEvent import com.tencent.devops.process.webhook.pojo.event.commit.ICodeWebhookEvent +import com.tencent.devops.process.webhook.pojo.event.commit.ReplayWebhookEvent import org.slf4j.LoggerFactory import org.springframework.amqp.rabbit.core.RabbitTemplate @@ -83,5 +84,27 @@ object CodeWebhookEventDispatcher { return result } + fun dispatchReplayEvent(rabbitTemplate: RabbitTemplate, event: ReplayWebhookEvent): Boolean { + logger.debug("Webhook comming [replay|$event]") + var result = false + try { + logger.info("Dispatch the replay webhook event by MQ") + val eventType = event::class.java.annotations.find { s -> s is Event } as Event + rabbitTemplate.convertAndSend(eventType.exchange, eventType.routeKey, event) { message -> + // 事件中的变量指定 + if (event.delayMills > 0) { + message.messageProperties.setHeader("x-delay", event.delayMills) + } else if (eventType.delayMills > 0) { // 事件类型固化默认值 + message.messageProperties.setHeader("x-delay", eventType.delayMills) + } + message + } + result = true + } catch (e: Throwable) { + logger.error("Fail to dispatch the event($event) by MQ", e) + } + return result + } + private val logger = LoggerFactory.getLogger(CodeWebhookEventDispatcher::class.java) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookMQConfiguration.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookMQConfiguration.kt index d49eb0f3113..5e5bbc4e275 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookMQConfiguration.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookMQConfiguration.kt @@ -367,7 +367,7 @@ class WebhookMQConfiguration @Autowired constructor() { @Autowired messageConverter: Jackson2JsonMessageConverter ): SimpleMessageListenerContainer { logger.info("Start webhook replay event listener") - val adapter = MessageListenerAdapter(webhookEventListener, WebhookEventListener::handleReplayRequest.name) + val adapter = MessageListenerAdapter(webhookEventListener, WebhookEventListener::handleReplayEvent.name) adapter.setMessageConverter(messageConverter) return Tools.createSimpleMessageListenerContainerByAdapter( connectionFactory = connectionFactory, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt index 363d999e47b..bb7ce05b698 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt @@ -29,18 +29,20 @@ package com.tencent.devops.process.webhook import com.tencent.devops.common.api.enums.ScmType -import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.client.Client import com.tencent.devops.common.pipeline.enums.ChannelCode +import com.tencent.devops.common.service.trace.TraceTag import com.tencent.devops.common.webhook.pojo.WebhookRequest import com.tencent.devops.common.webhook.pojo.code.github.GithubCheckRunEvent import com.tencent.devops.process.api.service.ServiceBuildResource -import com.tencent.devops.process.constant.ProcessMessageCode +import com.tencent.devops.process.dao.PipelineTriggerEventDao import com.tencent.devops.process.trigger.WebhookTriggerService -import com.tencent.devops.process.webhook.pojo.event.WebhookRequestReplayEvent +import com.tencent.devops.process.webhook.pojo.event.commit.ReplayWebhookEvent import com.tencent.devops.repository.api.ServiceRepositoryWebhookResource import com.tencent.devops.repository.pojo.RepositoryWebhookRequest +import org.jooq.DSLContext import org.slf4j.LoggerFactory +import org.slf4j.MDC import org.springframework.stereotype.Service import java.time.LocalDateTime @@ -48,7 +50,9 @@ import java.time.LocalDateTime class WebhookRequestService( private val client: Client, private val webhookEventFactory: WebhookEventFactory, - private val webhookTriggerService: WebhookTriggerService + private val webhookTriggerService: WebhookTriggerService, + private val dslContext: DSLContext, + private val pipelineTriggerEventDao: PipelineTriggerEventDao, ) { companion object { @@ -67,7 +71,9 @@ class WebhookRequestService( val matcher = webhookEventFactory.createScmWebHookMatcher(scmType = scmType, event = event) val eventTime = LocalDateTime.now() + val requestId = MDC.get(TraceTag.BIZID) val repositoryWebhookRequest = RepositoryWebhookRequest( + requestId = requestId, externalId = matcher.getExternalId(), eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), @@ -78,25 +84,33 @@ class WebhookRequestService( requestBody = request.body, createTime = eventTime ) - val hookRequestId = client.get(ServiceRepositoryWebhookResource::class).saveWebhookRequest( + client.get(ServiceRepositoryWebhookResource::class).saveWebhookRequest( repositoryWebhookRequest = repositoryWebhookRequest ).data!! webhookTriggerService.trigger( scmType = scmType, matcher = matcher, - hookRequestId = hookRequestId, + requestId = requestId, eventTime = eventTime ) } - fun replay(replayEvent: WebhookRequestReplayEvent) { + fun handleReplay(replayEvent: ReplayWebhookEvent) { with(replayEvent) { + val triggerEvent = pipelineTriggerEventDao.getTriggerEvent( + dslContext = dslContext, + projectId = projectId, + eventId = eventId + ) ?: run { + logger.info("replay trigger event not found|$eventId") + return + } val repoWebhookRequest = client.get(ServiceRepositoryWebhookResource::class).getWebhookRequest( - requestId = hookRequestId - ).data ?: throw ErrorCodeException( - errorCode = ProcessMessageCode.ERROR_WEBHOOK_REQUEST_NOT_FOUND, - params = arrayOf(hookRequestId.toString()) - ) + requestId = replayRequestId + ).data ?: run { + logger.info("replay webhook request not found|$replayRequestId") + return + } val webhookRequest = WebhookRequest( headers = repoWebhookRequest.requestHeader, body = repoWebhookRequest.requestBody @@ -107,11 +121,10 @@ class WebhookRequestService( } val matcher = webhookEventFactory.createScmWebHookMatcher(scmType = scmType, event = event) - val eventTime = LocalDateTime.now() webhookTriggerService.replay( replayEvent = replayEvent, - matcher = matcher, - eventTime = eventTime + triggerEvent = triggerEvent, + matcher = matcher ) } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt index a07298e70c0..f3f0f3dc339 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt @@ -32,12 +32,12 @@ import com.tencent.devops.common.service.trace.TraceTag import com.tencent.devops.common.webhook.pojo.WebhookRequest import com.tencent.devops.process.webhook.CodeWebhookEventDispatcher import com.tencent.devops.process.webhook.WebhookRequestService -import com.tencent.devops.process.webhook.pojo.event.WebhookRequestReplayEvent import com.tencent.devops.process.webhook.pojo.event.commit.GitWebhookEvent import com.tencent.devops.process.webhook.pojo.event.commit.GithubWebhookEvent import com.tencent.devops.process.webhook.pojo.event.commit.GitlabWebhookEvent import com.tencent.devops.process.webhook.pojo.event.commit.ICodeWebhookEvent import com.tencent.devops.process.webhook.pojo.event.commit.P4WebhookEvent +import com.tencent.devops.process.webhook.pojo.event.commit.ReplayWebhookEvent import com.tencent.devops.process.webhook.pojo.event.commit.SvnWebhookEvent import com.tencent.devops.process.webhook.pojo.event.commit.TGitWebhookEvent import com.tencent.devops.process.webhook.pojo.event.commit.enum.CommitEventType @@ -227,8 +227,44 @@ class WebhookEventListener constructor( } } - fun handleReplayRequest(replayEvent: WebhookRequestReplayEvent) { - webhookRequestService.replay(replayEvent = replayEvent) + fun handleReplayEvent(replayEvent: ReplayWebhookEvent) { + val traceId = MDC.get(TraceTag.BIZID) + if (traceId.isNullOrEmpty()) { + if (!replayEvent.traceId.isNullOrEmpty()) { + MDC.put(TraceTag.BIZID, replayEvent.traceId) + } else { + MDC.put(TraceTag.BIZID, TraceTag.buildBiz()) + } + } + logger.info("Receive ReplayWebhookEvent from MQ [replay|${replayEvent}]") + var result = false + try { + webhookRequestService.handleReplay(replayEvent = replayEvent) + result = true + } catch (ignore: Throwable) { + logger.warn("Fail to handle the Github event [${replayEvent.retryTime}]", ignore) + } finally { + if (!result && replayEvent.retryTime >= 0) { + logger.warn("Retry to handle the Github event [${replayEvent.retryTime}]") + with(replayEvent) { + CodeWebhookEventDispatcher.dispatchReplayEvent( + rabbitTemplate = rabbitTemplate, + event = ReplayWebhookEvent( + userId = userId, + projectId = projectId, + eventId = eventId, + replayRequestId = replayRequestId, + scmType = scmType, + pipelineId = pipelineId, + retryTime = retryTime - 1, + delayMills = DELAY_MILLS + ) + ) + } + + } + MDC.remove(TraceTag.BIZID) + } } companion object { diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/WebhookRequestReplayEvent.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/commit/ReplayWebhookEvent.kt similarity index 80% rename from src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/WebhookRequestReplayEvent.kt rename to src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/commit/ReplayWebhookEvent.kt index 1b063e65f73..53490a87a44 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/WebhookRequestReplayEvent.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/pojo/event/commit/ReplayWebhookEvent.kt @@ -26,18 +26,25 @@ * */ -package com.tencent.devops.process.webhook.pojo.event +package com.tencent.devops.process.webhook.pojo.event.commit import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.event.annotation.Event import com.tencent.devops.common.event.dispatcher.pipeline.mq.MQ -import com.tencent.devops.common.event.pojo.trace.ITraceEvent +import com.tencent.devops.common.service.trace.TraceTag +import org.slf4j.MDC @Event(exchange = MQ.EXCHANGE_REPLAY_BUILD_REQUEST_EVENT, routeKey = MQ.ROUTE_REPLAY_BUILD_REQUEST_EVENT) -data class WebhookRequestReplayEvent( +data class ReplayWebhookEvent( val userId: String, val projectId: String, - val hookRequestId: Long, + // 事件重放生成的事件ID + val eventId: Long, + // 重放的请求ID + val replayRequestId: String, val scmType: ScmType, - val pipelineId: String? = null -) : ITraceEvent() + val pipelineId: String? = null, + var retryTime: Int = 3, + var delayMills: Int = 0, + var traceId: String? = MDC.get(TraceTag.BIZID) +) diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryWebhookResource.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryWebhookResource.kt index 44899531dfa..9b77de0be79 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryWebhookResource.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryWebhookResource.kt @@ -52,7 +52,7 @@ interface ServiceRepositoryWebhookResource { fun saveWebhookRequest( @ApiParam(value = "代码库触发事件", required = true) repositoryWebhookRequest: RepositoryWebhookRequest - ): Result + ): Result @ApiOperation("获取代码库事件请求") @GET @@ -60,6 +60,6 @@ interface ServiceRepositoryWebhookResource { fun getWebhookRequest( @ApiParam(value = "事件ID", required = true) @PathParam("requestId") - requestId: Long + requestId: String ): Result } diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepositoryWebhookRequest.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepositoryWebhookRequest.kt index 47474beac97..c9e0e15d196 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepositoryWebhookRequest.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/RepositoryWebhookRequest.kt @@ -6,8 +6,8 @@ import java.time.LocalDateTime @ApiModel("代码库webhook请求") data class RepositoryWebhookRequest( - @ApiModelProperty("事件Id,网关traceId") - var requestId: Long? = null, + @ApiModelProperty("请求ID") + var requestId: String, @ApiModelProperty("事件源,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port") val externalId: String, @ApiModelProperty("事件类型") diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryDao.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryDao.kt index d165d5f829b..7934a54871f 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryDao.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryDao.kt @@ -293,7 +293,7 @@ class RepositoryDao { query.and(PROJECT_ID.eq(projectId)) } return query.and(IS_DELETED.eq(false)).fetchOne() ?: throw NotFoundException( - I18nUtil.getCodeLanMessage(messageCode = GIT_NOT_FOUND) + I18nUtil.getCodeLanMessage(messageCode = GIT_NOT_FOUND, params = arrayOf(repositoryId.toString())) ) } } diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryWebhookRequestDao.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryWebhookRequestDao.kt index 09b89cff78b..36eb84644ca 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryWebhookRequestDao.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryWebhookRequestDao.kt @@ -38,10 +38,11 @@ import org.springframework.stereotype.Repository @Suppress("ALL") @Repository class RepositoryWebhookRequestDao { - fun saveWebhookRequest(dslContext: DSLContext, webhookRequest: RepositoryWebhookRequest): Long { + fun saveWebhookRequest(dslContext: DSLContext, webhookRequest: RepositoryWebhookRequest) { return with(TRepositoryWebhookRequest.T_REPOSITORY_WEBHOOK_REQUEST) { dslContext.insertInto( this, + REQUEST_ID, EXTERNAL_ID, REPOSITORY_TYPE, EVENT_TYPE, @@ -52,6 +53,7 @@ class RepositoryWebhookRequestDao { REQUEST_BODY, CREATE_TIME ).values( + webhookRequest.requestId, webhookRequest.externalId, webhookRequest.repositoryType, webhookRequest.eventType, @@ -61,13 +63,13 @@ class RepositoryWebhookRequestDao { webhookRequest.requestParam?.let { JsonUtil.toJson(it) }, webhookRequest.requestBody, webhookRequest.createTime - ).returning(REQUEST_ID).fetchOne()?.requestId ?: 1 + ).execute() } } fun get( dslContext: DSLContext, - requestId: Long + requestId: String ): RepositoryWebhookRequest? { val record = with(TRepositoryWebhookRequest.T_REPOSITORY_WEBHOOK_REQUEST) { dslContext.selectFrom(this) diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceRepositoryWebhookResourceImpl.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceRepositoryWebhookResourceImpl.kt index 64bc9bfc9bc..35b2930f43e 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceRepositoryWebhookResourceImpl.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceRepositoryWebhookResourceImpl.kt @@ -40,11 +40,12 @@ class ServiceRepositoryWebhookResourceImpl @Autowired constructor( val repositoryWebhookService: RepositoryWebhookService ) : ServiceRepositoryWebhookResource { - override fun saveWebhookRequest(repositoryWebhookRequest: RepositoryWebhookRequest): Result { - return Result(repositoryWebhookService.saveWebhookRequest(repositoryWebhookRequest)) + override fun saveWebhookRequest(repositoryWebhookRequest: RepositoryWebhookRequest): Result { + repositoryWebhookService.saveWebhookRequest(repositoryWebhookRequest) + return Result(true) } - override fun getWebhookRequest(requestId: Long): Result { + override fun getWebhookRequest(requestId: String): Result { return Result(repositoryWebhookService.getWebhookRequest(requestId = requestId)) } } diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepositoryWebhookService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepositoryWebhookService.kt index c7d6ffdfbf9..7da2fc78609 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepositoryWebhookService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepositoryWebhookService.kt @@ -13,7 +13,7 @@ class RepositoryWebhookService @Autowired constructor( val repositoryWebhookRequestDao: RepositoryWebhookRequestDao, val dslContext: DSLContext ) { - fun saveWebhookRequest(repositoryWebhookRequest: RepositoryWebhookRequest): Long { + fun saveWebhookRequest(repositoryWebhookRequest: RepositoryWebhookRequest) { with(repositoryWebhookRequest) { if (externalId.isBlank()) { throw ParamBlankException("Invalid eventSource") @@ -24,14 +24,14 @@ class RepositoryWebhookService @Autowired constructor( if (eventType.isBlank()) { throw ParamBlankException("Invalid eventType") } - return repositoryWebhookRequestDao.saveWebhookRequest( + repositoryWebhookRequestDao.saveWebhookRequest( dslContext = dslContext, webhookRequest = repositoryWebhookRequest ) } } - fun getWebhookRequest(requestId: Long): RepositoryWebhookRequest? { + fun getWebhookRequest(requestId: String): RepositoryWebhookRequest? { return repositoryWebhookRequestDao.get( dslContext = dslContext, requestId = requestId diff --git a/support-files/sql/1001_ci_process_ddl_mysql.sql b/support-files/sql/1001_ci_process_ddl_mysql.sql index 43459f78407..e472290621b 100644 --- a/support-files/sql/1001_ci_process_ddl_mysql.sql +++ b/support-files/sql/1001_ci_process_ddl_mysql.sql @@ -1152,18 +1152,20 @@ CREATE TABLE IF NOT EXISTS `T_PIPELINE_BUILD_RECORD_TASK` ( CREATE TABLE IF NOT EXISTS `T_PIPELINE_TRIGGER_EVENT` ( + `REQUEST_ID` varchar(64) NOT NULL COMMENT '请求ID', `PROJECT_ID` varchar(64) NOT NULL COMMENT '项目ID', `EVENT_ID` bigint(20) NOT NULL COMMENT '事件ID', `TRIGGER_TYPE` varchar(64) NOT NULL COMMENT '触发类型', - `EVENT_SOURCE` varchar(255) NOT NULL COMMENT '触发源', + `EVENT_SOURCE` varchar(255) NOT NULL COMMENT '触发源,代码库hashId/触发人/远程ip', `EVENT_TYPE` varchar(64) NOT NULL COMMENT '事件类型', `TRIGGER_USER` varchar(100) NOT NULL COMMENT '触发用户', `EVENT_DESC` text NOT NULL COMMENT '事件描述', - `HOOK_REQUEST_ID` bigint(20) NULL COMMENT 'WEBHOOK请求ID', + `REPLAY_EVENT_ID` bigint(20) NULL COMMENT '重放事件ID', `REQUEST_PARAMS` text DEFAULT NULL COMMENT '请求参数', - `EVENT_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '事件时间', - PRIMARY KEY (`EVENT_ID`, `EVENT_TIME`), - INDEX IDX_PROJECT_ID_EVENT_ID (`PROJECT_ID`, `EVENT_ID`) + `CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '事件时间', + PRIMARY KEY (`EVENT_ID`, `CREATE_TIME`), + unique UNIQ_REQUEST(`REQUEST_ID`, `EVENT_SOURCE`), + INDEX IDX_EVENT (`PROJECT_ID`, `EVENT_SOURCE`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT ='流水线触发事件表'; -- ---------------------------- diff --git a/support-files/sql/1001_ci_repository_ddl_mysql.sql b/support-files/sql/1001_ci_repository_ddl_mysql.sql index 2236155e2ca..c8ad08a3768 100644 --- a/support-files/sql/1001_ci_repository_ddl_mysql.sql +++ b/support-files/sql/1001_ci_repository_ddl_mysql.sql @@ -197,7 +197,7 @@ CREATE TABLE IF NOT EXISTS `T_REPOSITORY_TGIT_TOKEN` CREATE TABLE IF NOT EXISTS `T_REPOSITORY_WEBHOOK_REQUEST` ( - `REQUEST_ID` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '请求ID', + `REQUEST_ID` varchar(64) NOT NULL COMMENT '请求ID', `EXTERNAL_ID` varchar(255) DEFAULT NULL COMMENT '代码库平台ID', `REPOSITORY_TYPE` varchar(32) DEFAULT NULL COMMENT '触发类型', `EVENT_TYPE` varchar(255) DEFAULT NULL COMMENT '事件类型', From 1dad9745294927124d06e4977e4db6ffdb8fa3d2 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Fri, 27 Oct 2023 15:38:13 +0800 Subject: [PATCH 094/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/engine/dao/PipelineWebhookDao.kt | 18 ------------------ .../engine/service/PipelineWebhookService.kt | 5 ++++- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt index 5f6a3a73ff2..aa9ca2c3340 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt @@ -198,24 +198,6 @@ class PipelineWebhookDao { } } - fun listWebhookPipeline( - dslContext: DSLContext, - projectId: String, - pipelineId: String, - repositoryType: String, - eventType: String - ): List { - with(T_PIPELINE_WEBHOOK) { - return dslContext.selectFrom(this) - .where(PROJECT_ID.eq(projectId)) - .and(PIPELINE_ID.eq(pipelineId)) - .and(REPOSITORY_TYPE.eq(repositoryType)) - .and(EVENT_TYPE.eq(eventType)) - .and(DELETE.eq(false)) - .fetch().map { convert(it) } - } - } - fun listWebhookPipeline( dslContext: DSLContext, projectName: String, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index 1cabcd80645..765d0927a6f 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -732,7 +732,10 @@ class PipelineWebhookService @Autowired constructor( if (webhook.taskId.isNullOrBlank()) return@webhook val element = elementMap[webhook.taskId] ?: return@webhook val webhookElementParams = getElementRepositoryConfig(element, variable = params) - ?: return@webhook + ?: run{ + logger.info("webhook not find match element|${webhook.id}") + return@webhook + } val elementRepositoryConfig = webhookElementParams.repositoryConfig val webhookRepositoryConfig = getRepositoryConfig(webhook, params) // 插件的配置与表中数据不一致,如保存流水线时,注册webhook失败,就会导致数据不一致,不更新 From cbf53cc2747b7dda7b2288f309904f27912ad397 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Fri, 27 Oct 2023 17:29:04 +0800 Subject: [PATCH 095/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/engine/service/PipelineWebhookService.kt | 2 +- .../devops/process/trigger/PipelineTriggerEventService.kt | 2 +- .../tencent/devops/process/webhook/WebhookRequestService.kt | 2 +- .../devops/process/webhook/listener/WebhookEventListener.kt | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index 765d0927a6f..90a1304aacc 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -732,7 +732,7 @@ class PipelineWebhookService @Autowired constructor( if (webhook.taskId.isNullOrBlank()) return@webhook val element = elementMap[webhook.taskId] ?: return@webhook val webhookElementParams = getElementRepositoryConfig(element, variable = params) - ?: run{ + ?: run { logger.info("webhook not find match element|${webhook.id}") return@webhook } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 662454cdd33..6977e28b424 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -159,7 +159,7 @@ class PipelineTriggerEventService @Autowired constructor( offset = sqlLimit.offset ).map { it.eventDesc = it.getI18nEventDesc(language) - it.reason = getI18nReason(it.reason,language) + it.reason = getI18nReason(it.reason, language) it } return SQLPage(count = count, records = records) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt index bb7ce05b698..ccb51348e45 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt @@ -52,7 +52,7 @@ class WebhookRequestService( private val webhookEventFactory: WebhookEventFactory, private val webhookTriggerService: WebhookTriggerService, private val dslContext: DSLContext, - private val pipelineTriggerEventDao: PipelineTriggerEventDao, + private val pipelineTriggerEventDao: PipelineTriggerEventDao ) { companion object { diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt index a0e6b1bc5b7..269eed9608c 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/listener/WebhookEventListener.kt @@ -237,7 +237,7 @@ class WebhookEventListener constructor( MDC.put(TraceTag.BIZID, TraceTag.buildBiz()) } } - logger.info("Receive ReplayWebhookEvent from MQ [replay|${replayEvent}]") + logger.info("Receive ReplayWebhookEvent from MQ [replay|$replayEvent]") var result = false try { webhookRequestService.handleReplay(replayEvent = replayEvent) @@ -262,7 +262,6 @@ class WebhookEventListener constructor( ) ) } - } MDC.remove(TraceTag.BIZID) } From d56ddc06b933e6f49416ddb14f58c0f210c969b1 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 27 Oct 2023 18:03:33 +0800 Subject: [PATCH 096/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webhook/enums/WebhookI18nConstants.kt | 2 +- .../code/handler/CodeWebhookTriggerHandler.kt | 3 +- .../github/GithubCreateTriggerHandler.kt | 22 +++---- .../github/GithubIssueTriggerHandler.kt | 12 +--- .../handler/github/GithubPrTriggerHandler.kt | 12 +--- .../github/GithubPushTriggerHandler.kt | 12 +--- .../github/GithubReviewTriggerHandler.kt | 12 +--- .../comment/GithubCommentTriggerHandler.kt | 12 +--- .../code/handler/p4/P4ChangeTriggerHandler.kt | 12 +--- .../code/handler/p4/P4ShelveTriggerHandler.kt | 12 +--- .../handler/svn/SvnCommitTriggerHandler.kt | 12 +--- .../handler/tgit/TGitIssueTriggerHandler.kt | 12 +--- .../code/handler/tgit/TGitMrTriggerHandler.kt | 12 +--- .../handler/tgit/TGitNoteTriggerHandler.kt | 12 +--- .../handler/tgit/TGitPushTriggerHandler.kt | 12 +--- .../handler/tgit/TGitReviewTriggerHandler.kt | 13 +---- .../handler/tgit/TGitTagPushTriggerHandler.kt | 12 +--- .../code/matcher/AbstractScmWebhookMatcher.kt | 5 +- .../service/code/matcher/ScmWebhookMatcher.kt | 3 +- .../pojo/trigger/PipelineEventReplayInfo.kt | 58 ------------------- .../trigger/PipelineTriggerEventService.kt | 7 ++- .../i18n/process/message_en_US.properties | 26 +-------- .../i18n/process/message_zh_CN.properties | 26 +-------- 23 files changed, 62 insertions(+), 259 deletions(-) delete mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineEventReplayInfo.kt diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt index 0e403133bfe..f73aa9f5f13 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt @@ -122,5 +122,5 @@ object WebhookI18nConstants { const val ISSUES_ACTION_NOT_MATCH = "bkRepoTriggerIssueActionNotMatch" // 事件回放匹配码后缀 - const val EVENT_REPLAY_SUFFIX = "Replay" + const val EVENT_REPLAY_DESC = "bkEventReplayDesc" } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt index 8837455c10d..e84118bc7a4 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/CodeWebhookTriggerHandler.kt @@ -34,7 +34,6 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilterChain import com.tencent.devops.common.webhook.service.code.filter.WebhookFilterResponse import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.pojo.WebhookCommit @@ -76,7 +75,7 @@ interface CodeWebhookTriggerHandler { /** * 获取事件说明,根据不同的事件组织事件说明 */ - fun getEventDesc(event: T, replayInfo: PipelineEventReplayInfo? = null): String = "" + fun getEventDesc(event: T): String = "" /** * 获取webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt index 46225088f34..a665d5e1147 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt @@ -28,8 +28,6 @@ package com.tencent.devops.common.webhook.service.code.handler.github import com.tencent.devops.common.api.pojo.I18Variable -import com.tencent.devops.common.api.util.DateTimeUtil -import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.webhook.annotation.CodeWebhookHandler import com.tencent.devops.common.webhook.enums.WebhookI18nConstants @@ -40,10 +38,8 @@ import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.pojo.code.github.GithubCreateEvent import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.GitHookTriggerHandler -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils -import java.time.LocalDateTime @CodeWebhookHandler class GithubCreateTriggerHandler : GitHookTriggerHandler { @@ -79,23 +75,21 @@ class GithubCreateTriggerHandler : GitHookTriggerHandler { return event.ref } - override fun getEventDesc(event: GithubCreateEvent, replayInfo: PipelineEventReplayInfo?): String { - var i18Code = WebhookI18nConstants.GITHUB_CREATE_TAG_EVENT_DESC - val linkUrl = if (event.ref_type == "tag") { - "https://github.com/${event.repository.fullName}/releases/tag/${event.ref}" + override fun getEventDesc(event: GithubCreateEvent): String { + val (i18Code, linkUrl) = if (event.ref_type == "tag") { + WebhookI18nConstants.GITHUB_CREATE_TAG_EVENT_DESC to + "https://github.com/${event.repository.fullName}/releases/tag/${event.ref}" } else { - i18Code = WebhookI18nConstants.GITHUB_CREATE_BRANCH_EVENT_DESC - "https://github.com/${event.repository.fullName}/tree/${event.ref}" + WebhookI18nConstants.GITHUB_CREATE_BRANCH_EVENT_DESC to + "https://github.com/${event.repository.fullName}/tree/${event.ref}" } // 事件重放 - val (username, code) = PipelineEventReplayInfo.getTriggerInfo(replayInfo, getUsername(event), i18Code) return I18Variable( - code = code, + code = i18Code, params = listOf( getBranchName(event), linkUrl, - username, - DateTimeUtil.formatMilliTime(LocalDateTime.now().timestampmilli()) + getUsername(event) ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubIssueTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubIssueTriggerHandler.kt index d8d152f6d78..4ca7f4c772a 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubIssueTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubIssueTriggerHandler.kt @@ -51,7 +51,6 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository @CodeWebhookHandler @@ -95,18 +94,13 @@ class GithubIssueTriggerHandler : CodeWebhookTriggerHandler { return event.repository.id.toString() } - override fun getEventDesc(event: GithubIssuesEvent, replayInfo: PipelineEventReplayInfo?): String { - val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( - replayInfo, - getUsername(event), - getI18Code(event) - ) + override fun getEventDesc(event: GithubIssuesEvent): String { return I18Variable( - code = i18Code, + code = getI18Code(event), params = listOf( buildIssuesUrl(event), event.issue.number.toString(), - username + getUsername(event) ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt index c999267941c..abd224e6ea7 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPrTriggerHandler.kt @@ -86,7 +86,6 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.GitHookTriggerHandler import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils import org.slf4j.LoggerFactory @@ -131,18 +130,13 @@ class GithubPrTriggerHandler : GitHookTriggerHandler { return event.pullRequest.title } - override fun getEventDesc(event: GithubPullRequestEvent, replayInfo: PipelineEventReplayInfo?): String { - val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( - replayInfo, - getUsername(event), - WebhookI18nConstants.GITHUB_PR_EVENT_DESC - ) + override fun getEventDesc(event: GithubPullRequestEvent): String { return I18Variable( - code = i18Code, + code = WebhookI18nConstants.GITHUB_PR_EVENT_DESC, params = listOf( event.pullRequest.htmlUrl, event.pullRequest.number.toString(), - username, + getUsername(event), event.action ) ).toJsonStr() diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt index 7014ca3019e..5d31becdac4 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt @@ -61,7 +61,6 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.GitHookTriggerHandler import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils import org.slf4j.LoggerFactory @@ -106,7 +105,7 @@ class GithubPushTriggerHandler : GitHookTriggerHandler { return event.headCommit?.message ?: "" } - override fun getEventDesc(event: GithubPushEvent, replayInfo: PipelineEventReplayInfo?): String { + override fun getEventDesc(event: GithubPushEvent): String { val linkUrl = if (event.headCommit != null) { "https://github.com/${event.repository.fullName}/commit/${event.headCommit?.id}" } else { @@ -118,18 +117,13 @@ class GithubPushTriggerHandler : GitHookTriggerHandler { } else { revision } - val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( - replayInfo, - getUsername(event), - WebhookI18nConstants.GITHUB_PUSH_EVENT_DESC - ) return I18Variable( - code = i18Code, + code = WebhookI18nConstants.GITHUB_PUSH_EVENT_DESC, params = listOf( getBranchName(event), linkUrl, commitId, - username + getUsername(event) ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubReviewTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubReviewTriggerHandler.kt index b76fb84c066..293b2f95f0f 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubReviewTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubReviewTriggerHandler.kt @@ -52,7 +52,6 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -100,18 +99,13 @@ class GithubReviewTriggerHandler @Autowired constructor( return event.repository.id.toString() } - override fun getEventDesc(event: GithubReviewEvent, replayInfo: PipelineEventReplayInfo?): String { - val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( - replayInfo, - getUsername(event), - getI18Code(event) - ) + override fun getEventDesc(event: GithubReviewEvent): String { return I18Variable( - code = i18Code, + code = getI18Code(event), params = listOf( buildReviewUrl(event), event.pullRequest.number.toString(), - username + getUsername(event) ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/comment/GithubCommentTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/comment/GithubCommentTriggerHandler.kt index ad5766f0efa..b591c6cdff2 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/comment/GithubCommentTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/comment/GithubCommentTriggerHandler.kt @@ -51,7 +51,6 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository /** @@ -93,18 +92,13 @@ interface GithubCommentTriggerHandler : CodeWebhookTrigg return event.repository.id.toString() } - override fun getEventDesc(event: T, replayInfo: PipelineEventReplayInfo?): String { - val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( - replayInfo, - getUsername(event), - WebhookI18nConstants.TGIT_NOTE_EVENT_DESC - ) + override fun getEventDesc(event: T): String { return I18Variable( - code = i18Code, + code = WebhookI18nConstants.TGIT_NOTE_EVENT_DESC, params = listOf( buildCommentUrl(event), event.comment.id.toString(), - username + getUsername(event) ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt index c6bdc8e4482..c8cf3cdf531 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ChangeTriggerHandler.kt @@ -44,7 +44,6 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilterResponse import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.process.utils.PIPELINE_BUILD_MSG import com.tencent.devops.repository.pojo.Repository @@ -83,17 +82,12 @@ class P4ChangeTriggerHandler( override fun getMessage(event: P4ChangeEvent) = event.description - override fun getEventDesc(event: P4ChangeEvent, replayInfo: PipelineEventReplayInfo?): String { - val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( - replayInfo, - getUsername(event), - WebhookI18nConstants.P4_EVENT_DESC - ) + override fun getEventDesc(event: P4ChangeEvent): String { return I18Variable( - code = i18Code, + code = WebhookI18nConstants.P4_EVENT_DESC, params = listOf( getRevision(event), - username, + getUsername(event), getFormatEventType(event) ) ).toJsonStr() diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt index f27a65e7180..d98c126bc07 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/p4/P4ShelveTriggerHandler.kt @@ -45,7 +45,6 @@ import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilterResponse import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.process.utils.PIPELINE_BUILD_MSG import com.tencent.devops.repository.api.ServiceP4Resource import com.tencent.devops.repository.pojo.Repository @@ -86,17 +85,12 @@ class P4ShelveTriggerHandler( override fun getMessage(event: P4ShelveEvent) = event.description - override fun getEventDesc(event: P4ShelveEvent, replayInfo: PipelineEventReplayInfo?): String { - val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( - replayInfo, - getUsername(event), - WebhookI18nConstants.P4_EVENT_DESC - ) + override fun getEventDesc(event: P4ShelveEvent): String { return I18Variable( - code = i18Code, + code = WebhookI18nConstants.P4_EVENT_DESC, params = listOf( getRevision(event), - username, + getUsername(event), getFormatEventType(event) ) ).toJsonStr() diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt index 805ad08d390..c13f1b29601 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/svn/SvnCommitTriggerHandler.kt @@ -44,7 +44,6 @@ import com.tencent.devops.common.webhook.service.code.filter.UserFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository @CodeWebhookHandler @@ -82,17 +81,12 @@ class SvnCommitTriggerHandler : CodeWebhookTriggerHandler { return event.log } - override fun getEventDesc(event: SvnCommitEvent, replayInfo: PipelineEventReplayInfo?): String { - val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( - replayInfo, - getUsername(event), - WebhookI18nConstants.SVN_COMMIT_EVENT_DESC - ) + override fun getEventDesc(event: SvnCommitEvent): String { return I18Variable( - code = i18Code, + code = WebhookI18nConstants.SVN_COMMIT_EVENT_DESC, params = listOf( getRevision(event), - username + getUsername(event) ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt index 406aac7efca..a835d735e30 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt @@ -57,7 +57,6 @@ import com.tencent.devops.common.webhook.service.code.filter.GitUrlFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.GitHookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils @@ -131,18 +130,13 @@ class TGitIssueTriggerHandler( return event.objectAttributes.title } - override fun getEventDesc(event: GitIssueEvent, replayInfo: PipelineEventReplayInfo?): String { - val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( - replayInfo, - getUsername(event), - getI18Code(event) - ) + override fun getEventDesc(event: GitIssueEvent): String { return I18Variable( - code = i18Code, + code = getI18Code(event), params = listOf( "${event.objectAttributes.url}", event.objectAttributes.iid, - username + getUsername(event) ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt index da37974784e..81fb646970e 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitMrTriggerHandler.kt @@ -89,7 +89,6 @@ import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.common.webhook.util.WebhookUtils.convert import com.tencent.devops.common.webhook.util.WebhookUtils.getBranch import com.tencent.devops.process.engine.service.code.filter.CommitMessageFilter -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.CodeGitlabRepository import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.pojo.WebhookCommit @@ -161,18 +160,13 @@ class TGitMrTriggerHandler( return event.object_attributes.id } - override fun getEventDesc(event: GitMergeRequestEvent, replayInfo: PipelineEventReplayInfo?): String { - val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( - replayInfo, - getUsername(event), - getI18Code(event) - ) + override fun getEventDesc(event: GitMergeRequestEvent): String { return I18Variable( - code = i18Code, + code = getI18Code(event), params = listOf( "${event.object_attributes.url}", event.object_attributes.iid.toString(), - username + getUsername(event) ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt index 7388142ca8c..5c48ffe3430 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitNoteTriggerHandler.kt @@ -80,7 +80,6 @@ import com.tencent.devops.common.webhook.service.code.filter.RegexContainFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.CodeGitlabRepository import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils @@ -165,18 +164,13 @@ class TGitNoteTriggerHandler( return event.objectAttributes.note } - override fun getEventDesc(event: GitNoteEvent, replayInfo: PipelineEventReplayInfo?): String { - val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( - replayInfo, - getUsername(event), - WebhookI18nConstants.TGIT_NOTE_EVENT_DESC - ) + override fun getEventDesc(event: GitNoteEvent): String { return I18Variable( - code = i18Code, + code = WebhookI18nConstants.TGIT_NOTE_EVENT_DESC, params = listOf( event.objectAttributes.url, event.objectAttributes.id.toString(), - username + getUsername(event) ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt index e72dec3d7cc..bb5999fb04b 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitPushTriggerHandler.kt @@ -72,7 +72,6 @@ import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult import com.tencent.devops.common.webhook.util.WebhookUtils import com.tencent.devops.common.webhook.util.WebhookUtils.convert import com.tencent.devops.process.engine.service.code.filter.CommitMessageFilter -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.pojo.WebhookCommit import com.tencent.devops.scm.utils.code.git.GitUtils @@ -131,19 +130,14 @@ class TGitPushTriggerHandler( } } - override fun getEventDesc(event: GitPushEvent, replayInfo: PipelineEventReplayInfo?): String { - val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( - replayInfo, - getUsername(event), - TGIT_PUSH_EVENT_DESC - ) + override fun getEventDesc(event: GitPushEvent): String { return I18Variable( - code = i18Code, + code = TGIT_PUSH_EVENT_DESC, params = listOf( getBranchName(event), "${event.repository.homepage}/commit/${event.checkout_sha}", "${event.checkout_sha}".substring(0, GitPushEvent.SHORT_COMMIT_ID_LENGTH), - username + getUsername(event) ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt index c2f821d0f30..6ae82d59615 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitReviewTriggerHandler.kt @@ -58,7 +58,6 @@ import com.tencent.devops.common.webhook.service.code.filter.GitUrlFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils @@ -99,25 +98,19 @@ class TGitReviewTriggerHandler( return "" } - override fun getEventDesc(event: GitReviewEvent, replayInfo: PipelineEventReplayInfo?): String { + override fun getEventDesc(event: GitReviewEvent): String { // 评审状态 to 事件人 val (state, eventUser) = if (event.reviewer != null) { event.reviewer!!.state to event.reviewer!!.reviewer.name } else { event.state to getUsername(event) } - // 最终触发人 to 文案code - val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( - replayInfo, - eventUser, - getI18Code(state) - ) return I18Variable( - code = i18Code, + code = getI18Code(state), params = listOf( "${event.repository.homepage}/reviews/${event.iid}", event.iid, - username + eventUser ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt index c15c4a12a01..2a4cc2d5096 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitTagPushTriggerHandler.kt @@ -57,7 +57,6 @@ import com.tencent.devops.common.webhook.service.code.filter.UserFilter import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.CodeWebhookTriggerHandler import com.tencent.devops.common.webhook.util.WebhookUtils -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.utils.code.git.GitUtils @@ -100,7 +99,7 @@ class TGitTagPushTriggerHandler : CodeWebhookTriggerHandler { return event.ref.replace("refs/tags/", "") } - override fun getEventDesc(event: GitTagPushEvent, replayInfo: PipelineEventReplayInfo?): String { + override fun getEventDesc(event: GitTagPushEvent): String { val createFrom = when { event.create_from.isNullOrBlank() || event.checkout_sha == event.create_from -> { GitUtils.getShortSha(event.checkout_sha) @@ -110,18 +109,13 @@ class TGitTagPushTriggerHandler : CodeWebhookTriggerHandler { event.create_from } } - val (username, i18Code) = PipelineEventReplayInfo.getTriggerInfo( - replayInfo, - getUsername(event), - WebhookI18nConstants.TGIT_TAG_PUSH_EVENT_DESC - ) return I18Variable( - code = i18Code, + code = WebhookI18nConstants.TGIT_TAG_PUSH_EVENT_DESC, params = listOf( "$createFrom", "${event.repository.homepage}/-/tags/${getBranchName(event)}", getBranchName(event), - username + getUsername(event) ) ).toJsonStr() } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt index 8d7c381f474..813f906aa9a 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/AbstractScmWebhookMatcher.kt @@ -31,7 +31,6 @@ import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventTy import com.tencent.devops.common.webhook.pojo.code.CodeWebhookEvent import com.tencent.devops.common.webhook.service.code.loader.CodeWebhookHandlerRegistrar import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository @Suppress("TooManyFunctions") @@ -84,8 +83,8 @@ abstract class AbstractScmWebhookMatcher( return eventHandler.getMessage(event) } - override fun getEventDesc(replayInfo: PipelineEventReplayInfo?): String { - return eventHandler.getEventDesc(event, replayInfo) + override fun getEventDesc(): String { + return eventHandler.getEventDesc(event) } override fun getExternalId(): String { diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt index ef0f522d598..718fbae741e 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/matcher/ScmWebhookMatcher.kt @@ -31,7 +31,6 @@ import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventTy import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeType import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.service.code.pojo.WebhookMatchResult -import com.tencent.devops.process.pojo.trigger.PipelineEventReplayInfo import com.tencent.devops.repository.pojo.Repository import com.tencent.devops.scm.pojo.WebhookCommit import org.slf4j.LoggerFactory @@ -76,7 +75,7 @@ interface ScmWebhookMatcher { /** * 获取事件描述,根据不同的事件组织事件说明 */ - fun getEventDesc(replayInfo: PipelineEventReplayInfo? = null): String = "" + fun getEventDesc(): String = "" /** * 获取webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineEventReplayInfo.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineEventReplayInfo.kt deleted file mode 100644 index 8731bf4fe4c..00000000000 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineEventReplayInfo.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -package com.tencent.devops.process.pojo.trigger - -import com.tencent.devops.common.webhook.enums.WebhookI18nConstants -import io.swagger.annotations.ApiModel -import io.swagger.annotations.ApiModelProperty - -@ApiModel("流水线事件重放操作信息") -data class PipelineEventReplayInfo( - @ApiModelProperty("触发人") - val userId: String -) { - companion object { - /** - * 获取触发信息 - * 若为[重放事件]时,触发人为[回放者],且事件描述采用重放相关文案code - * 反之返回默认用户和触发文案code - */ - fun getTriggerInfo( - replayInfo: PipelineEventReplayInfo?, - defaultUserId: String, - defaultI18Code: String - ): Pair { - return if (replayInfo != null) { - replayInfo.userId to "$defaultI18Code${WebhookI18nConstants.EVENT_REPLAY_SUFFIX}" - } else { - defaultUserId to defaultI18Code - } - } - } -} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 6977e28b424..0820a4e0175 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -41,6 +41,7 @@ import com.tencent.devops.common.service.utils.HomeHostUtil import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.common.web.utils.I18nUtil.getCodeLanMessage import com.tencent.devops.common.webhook.enums.WebhookI18nConstants +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants.EVENT_REPLAY_DESC import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_TRIGGER_DETAIL_NOT_FOUND import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_TRIGGER_REPLAY_PIPELINE_NOT_EMPTY @@ -318,8 +319,10 @@ class PipelineTriggerEventService @Autowired constructor( eventSource = eventSource, eventType = eventType, triggerUser = userId, - // TODO 事件重放文案 - eventDesc = "$userId replay $eventId", + eventDesc = I18Variable( + code = EVENT_REPLAY_DESC, + params = listOf(eventId.toString(), userId) + ).toJsonStr(), replayEventId = eventId, requestParams = requestParams, createTime = LocalDateTime.now() diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index 754401aaa6b..8876041c1e7 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -386,31 +386,7 @@ bkSvnCommitEventDesc=Commit [{0}] pushed by {1}{0} bkRemoteStartEventDesc=Remote api triggered by {0} bkServiceStartEventDesc={0} Pipeline invocation triggered by [{2}] invoke -# event replay -bkTgitPushEventDescReplay=[{0}] Commit [{2}] replayed by {3} -bkTgitIssueOpenedEventDescReplay=Issue [!{1}] replayed by {2} -bkTgitIssueUpdatedEventDescReplay=Issue [!{1}] replayed by {2} -bkTgitIssueClosedEventDescReplay=Issue [!{1}] replayed by {2} -bkTgitIssueReopenedEventDescReplay=Issue [!{1}] replayed by {2} -bkTgitMrCreatedEventDescReplay=Merge requests [!{1}] replayed by {2} -bkTgitMrUpdatedEventDescReplay=Merge requests [!{1}] replayed by {2} -bkTgitMrClosedEventDescReplay=Merge requests [!{1}] replayed by {2} -bkTgitMrReopenedEventDescReplay=Merge requests [!{1}] replayed by {2} -bkTgitMrPushUpdatedEventDescReplay=Merge requests [!{1}] replayed by {2} -bkTgitMrMergedEventDescReplay=Merge requests [!{1}] replayed by {2} -bkTgitTagPushEventDescReplay=[{0}]Tag [{2}] replayed by {3} -bkTgitNoteEventDescReplay=Note [{1}] replayed by {2} -bkTgitReviewCreatedEventDescReplay=Code review [{1}] replayed by {2} -bkTgitReviewApprovedEventDescReplay=Code review [{1}] replayed by {2} -bkTgitReviewApprovingEventDescReplay=Code review [{1}] approving -bkTgitReviewChangeDeniedEventDescReplay=Code review [{1}] replayed by {2} -bkTgitReviewChangeRequiredEventDescReplay=Code review [{1}] replayed by {2} -bkGithubPushEventDescReplay=[{0}] Commit [{2}] replayed {3} -bkGithubCreateBranchEventDescReplay=Branch [{1}] replayed {2} -bkGithubCreateTagEventDescReplay=Tag [{1}] replayed {2} -bkGithubPrEventDescReplay=Pull request [!{1}] by {2} replayed -bkP4EventDescReplay=Change [{0}] by {1} replayed -bkSvnCommitEventDescReplay=Commit [{0}] replayed by {1} +bkEventReplayDesc=Event [{0}] replayed by {1} bkRepoTriggerEventTypeNotMatch=Event type mismatch bkRepoTriggerTargetBranchNotMatch=Target branch [{0}] of merge request does not match bkRepoTriggerTargetBranchIgnored=Target branch [{0}] of merge request has been excluded diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index ce4991c734e..06ccb0dcca4 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -386,31 +386,7 @@ bkSvnCommitEventDesc=提交 [{0}] 由 {1} bkManualStartEventDesc={0} 手动触发 bkRemoteStartEventDesc={0} 远程触发 bkServiceStartEventDesc={0} 触发的流水线 [{2}] 调用 -# 重放事件 -bkTgitPushEventDescReplay=[{0}] 提交 [{2}] 由 {3} 重放 -bkTgitIssueCreatedEventDescReplay=议题 [!{1}] 由 {2} 重放 -bkTgitIssueUpdatedEventDescReplay=议题 [!{1}] 由 {2} 重放 -bkTgitIssueClosedEventDescReplay=议题 [!{1}] 由 {2} 重放 -bkTgitIssueReopenedEventDescReplay=议题 [!{1}] 由 {2} 重放 -bkTgitMrCreatedEventDescReplay=合并请求 [!{1}] 由 {2} 重放 -bkTgitMrUpdatedEventDescReplay=合并请求 [!{1}] 由 {2} 重放 -bkTgitMrClosedEventDescReplay=合并请求 [!{1}] 由 {2} 重放 -bkTgitMrReopenedEventDescReplay=合并请求 [!{1}] 由 {2} 重放 -bkTgitMrPushUpdatedEventDescReplay=合并请求 [!{1}] 由 {2} 重放 -bkTgitMrMergedEventDescReplay=合并请求 [!{1}] 由 {2} 重放 -bkTgitTagPushEventDescReplay=[{0}] 创建Tag [{2}] 由 {3} 重放 -bkTgitNoteEventDescReplay=评论 [{1}] 由 {2} 重放 -bkTgitReviewCreatedEventDescReplay=代码审查 [{1}] 由 {2} 重放 -bkTgitReviewApprovedEventDescReplay=代码审查 [{1}] 由 {2} 重放 -bkTgitReviewApprovingEventDescReplay=代码审查 [{1}] 评审中 -bkTgitReviewChangeDeniedEventDescReplay=代码审查 [{1}] 由 {2} 重放 -bkTgitReviewChangeRequiredEventDescReplay=代码审查 [{1}] 由 {2} 重放 -bkGithubPushEventDescReplay=[{0}] 提交 [{2}] 由 {3} 重放 -bkGithubCreateBranchEventDescReplay=Branch [{1}] 由 {2} 重放 -bkGithubCreateTagEventDescReplay=Tag [{1}] 由 {2} 重放 -bkGithubPrEventDescReplay=Pull request [{1}] 由 {2} {3} -bkP4EventDescReplay=Change {0} 由 {1} 重放 -bkSvnCommitEventDescReplay=提交 [{0}] 由 {1} 重放 +bkEventReplayDesc=事件 [{0}] 由 {1} 重放 bkRepoTriggerEventTypeNotMatch=事件类型不满足触发条件 bkRepoTriggerTargetBranchNotMatch=MR目标分支[{0}]不满足触发条件 bkRepoTriggerTargetBranchIgnored=MR目标分支[{0}]被排除 From 6493faa4aac09dd891adb359ab7b7e24373d89ae Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 27 Oct 2023 18:06:57 +0800 Subject: [PATCH 097/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/code/handler/tgit/TGitIssueTriggerHandler.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt index a835d735e30..47a23365f96 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/tgit/TGitIssueTriggerHandler.kt @@ -132,7 +132,7 @@ class TGitIssueTriggerHandler( override fun getEventDesc(event: GitIssueEvent): String { return I18Variable( - code = getI18Code(event), + code = getI18Code(event), params = listOf( "${event.objectAttributes.url}", event.objectAttributes.iid, From 03d6cc1a4d8d7d925ffceafcf191a9b976dfe369 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Sat, 28 Oct 2023 10:51:23 +0800 Subject: [PATCH 098/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/pojo/trigger/PipelineTriggerEvent.kt | 2 +- .../api/UserPipelineTriggerEventResourceImpl.kt | 2 +- .../process/api/external/ExternalScmResourceImpl.kt | 9 +++++++-- .../devops/process/dao/PipelineTriggerEventDao.kt | 12 ++++++------ .../engine/service/PipelineWebhookService.kt | 11 +++++++++-- .../process/trigger/PipelineTriggerEventService.kt | 13 +++++++------ support-files/sql/1001_ci_process_ddl_mysql.sql | 2 +- 7 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt index 207d7ffe7ab..2668c0bb4db 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt @@ -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? = null, @ApiModelProperty("触发事件") diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt index 6e7d26bfd4e..821c977d656 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserPipelineTriggerEventResourceImpl.kt @@ -88,7 +88,7 @@ class UserPipelineTriggerEventResourceImpl( pageSize: Int? ): Result> { return Result( - pipelineTriggerEventService.listTriggerEvent( + pipelineTriggerEventService.listPipelineTriggerEvent( userId = userId, projectId = projectId, pipelineId = pipelineId, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/external/ExternalScmResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/external/ExternalScmResourceImpl.kt index 164adc938c2..ec7bdb5a043 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/external/ExternalScmResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/external/ExternalScmResourceImpl.kt @@ -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 @@ -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 @@ -60,8 +62,9 @@ class ExternalScmResourceImpl @Autowired constructor( secret: String?, traceId: String, body: String - ) = - Result( + ): Result { + logger.info("traceId: ${MDC.get(TraceTag.BIZID)}") + return Result( CodeWebhookEventDispatcher.dispatchEvent( rabbitTemplate = rabbitTemplate, event = GitWebhookEvent( @@ -71,6 +74,8 @@ class ExternalScmResourceImpl @Autowired constructor( ) ) ) + } + override fun webHookGitlabCommit(event: String) = Result(CodeWebhookEventDispatcher.dispatchEvent(rabbitTemplate, GitlabWebhookEvent(requestContent = event))) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index 862b34ee97a..a2c3c0b7951 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -71,7 +71,7 @@ class PipelineTriggerEventDao { EVENT_TYPE, TRIGGER_USER, EVENT_DESC, - REPLAY_EVENT_ID, + REPLAY_REQUEST_ID, REQUEST_PARAMS, CREATE_TIME ).values( @@ -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() @@ -126,7 +126,7 @@ class PipelineTriggerEventDao { } } - fun listTriggerEvent( + fun listTriggerDetail( dslContext: DSLContext, projectId: String, eventId: Long? = null, @@ -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) @@ -200,7 +200,7 @@ class PipelineTriggerEventDao { } } - fun countTriggerEvent( + fun countTriggerDetail( dslContext: DSLContext, projectId: String, eventId: Long? = null, @@ -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, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index 90a1304aacc..21af9fdc25e 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -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|" + @@ -777,6 +777,13 @@ 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 ?: "", @@ -784,7 +791,7 @@ class PipelineWebhookService @Autowired constructor( projectId = projectId, pipelineId = pipelineId, taskId = webhook.taskId!!, - repositoryHashId = repository?.repoHashId + repositoryHashId = repositoryHashId ) } catch (ignored: Exception) { logger.info("update webhook event info error|$webhook", ignored) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 0820a4e0175..5482a05a0f6 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -121,7 +121,7 @@ class PipelineTriggerEventService @Autowired constructor( } } - fun listTriggerEvent( + fun listPipelineTriggerEvent( userId: String, projectId: String, pipelineId: String, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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() ) diff --git a/support-files/sql/1001_ci_process_ddl_mysql.sql b/support-files/sql/1001_ci_process_ddl_mysql.sql index e472290621b..a4962b2bce1 100644 --- a/support-files/sql/1001_ci_process_ddl_mysql.sql +++ b/support-files/sql/1001_ci_process_ddl_mysql.sql @@ -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`), From d7c5c4a5bdb71ff8686eaf0686b8d1f54f008cd4 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Sat, 28 Oct 2023 11:06:46 +0800 Subject: [PATCH 099/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/api/external/ExternalScmResourceImpl.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/external/ExternalScmResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/external/ExternalScmResourceImpl.kt index ec7bdb5a043..a3f3b15be55 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/external/ExternalScmResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/external/ExternalScmResourceImpl.kt @@ -76,7 +76,6 @@ class ExternalScmResourceImpl @Autowired constructor( ) } - override fun webHookGitlabCommit(event: String) = Result(CodeWebhookEventDispatcher.dispatchEvent(rabbitTemplate, GitlabWebhookEvent(requestContent = event))) From 9081f971745d12ee53da91d1c679a919d0074fe1 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Sat, 28 Oct 2023 19:09:28 +0800 Subject: [PATCH 100/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tencent/devops/process/dao/PipelineTriggerEventDao.kt | 2 +- .../devops/process/trigger/PipelineTriggerEventService.kt | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index a2c3c0b7951..ae731aa4ef5 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -227,7 +227,7 @@ class PipelineTriggerEventDao { startTime = startTime, endTime = endTime ) - return dslContext.selectCount().from(t1).leftJoin(t2) + return dslContext.selectCount().from(t2).leftJoin(t1) .on(t1.EVENT_ID.eq(t2.EVENT_ID)).and(t1.PROJECT_ID.eq(t2.PROJECT_ID)) .where(conditions) .fetchOne(0, Long::class.java)!! diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 5482a05a0f6..9382a788832 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -106,7 +106,6 @@ class PipelineTriggerEventService @Autowired constructor( triggerEvent: PipelineTriggerEvent, triggerDetail: PipelineTriggerDetail ) { - logger.info("save pipeline trigger event|event[$triggerEvent]|detail[$triggerDetail]") triggerDetail.detailId = getDetailId() dslContext.transaction { configuration -> val transactionContext = DSL.using(configuration) @@ -310,9 +309,11 @@ class PipelineTriggerEventService @Autowired constructor( // 保存重放事件 val requestId = MDC.get(TraceTag.BIZID) val replayEventId = getEventId() + // 如果重试的事件也由重试产生,则应该记录最开始的请求ID + val replayRequestId = triggerEvent.replayRequestId ?: triggerEvent.requestId val replayTriggerEvent = with(triggerEvent) { PipelineTriggerEvent( - requestId = requestId, + requestId = MDC.get(TraceTag.BIZID), projectId = projectId, eventId = replayEventId, triggerType = triggerType, @@ -323,8 +324,7 @@ class PipelineTriggerEventService @Autowired constructor( code = EVENT_REPLAY_DESC, params = listOf(eventId.toString(), userId) ).toJsonStr(), - // 如果重试的事件也由重试产生,则应该记录最开始的请求ID - replayRequestId = triggerEvent.replayRequestId ?: triggerEvent.requestId, + replayRequestId = replayRequestId, requestParams = requestParams, createTime = LocalDateTime.now() ) From 0367047d842bf9e23bdd631721108671125fb201 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 1 Nov 2023 18:22:59 +0800 Subject: [PATCH 101/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/dao/PipelineTriggerEventDao.kt | 273 +++++++++++++----- 1 file changed, 195 insertions(+), 78 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index ae731aa4ef5..d1806d516ef 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -34,7 +34,9 @@ import com.tencent.devops.common.api.util.timestamp import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.web.utils.I18nUtil.getCodeLanMessage import com.tencent.devops.model.process.tables.TPipelineTriggerDetail +import com.tencent.devops.model.process.tables.TPipelineTriggerDetail.T_PIPELINE_TRIGGER_DETAIL import com.tencent.devops.model.process.tables.TPipelineTriggerEvent +import com.tencent.devops.model.process.tables.TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT import com.tencent.devops.model.process.tables.records.TPipelineTriggerDetailRecord import com.tencent.devops.model.process.tables.records.TPipelineTriggerEventRecord import com.tencent.devops.process.pojo.trigger.PipelineTriggerDetail @@ -45,7 +47,6 @@ import com.tencent.devops.process.pojo.trigger.RepoTriggerEventVo import org.jooq.Condition import org.jooq.DSLContext import org.jooq.Result -import org.jooq.impl.DSL import org.jooq.impl.DSL.count import org.jooq.impl.DSL.`when` import org.springframework.stereotype.Repository @@ -60,7 +61,7 @@ class PipelineTriggerEventDao { dslContext: DSLContext, triggerEvent: PipelineTriggerEvent ) { - with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { + with(T_PIPELINE_TRIGGER_EVENT) { dslContext.insertInto( this, REQUEST_ID, @@ -94,7 +95,7 @@ class PipelineTriggerEventDao { dslContext: DSLContext, triggerDetail: PipelineTriggerDetail ) { - with(TPipelineTriggerDetail.T_PIPELINE_TRIGGER_DETAIL) { + with(T_PIPELINE_TRIGGER_DETAIL) { dslContext.insertInto( this, DETAIL_ID, @@ -140,8 +141,8 @@ class PipelineTriggerEventDao { limit: Int, offset: Int ): List { - val t1 = TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT.`as`("t1") - val t2 = TPipelineTriggerDetail.T_PIPELINE_TRIGGER_DETAIL.`as`("t2") + val t1 = T_PIPELINE_TRIGGER_EVENT.`as`("t1") + val t2 = T_PIPELINE_TRIGGER_DETAIL.`as`("t2") val conditions = buildConditions( t1 = t1, t2 = t2, @@ -212,8 +213,8 @@ class PipelineTriggerEventDao { startTime: Long? = null, endTime: Long? = null ): Long { - val t1 = TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT.`as`("t1") - val t2 = TPipelineTriggerDetail.T_PIPELINE_TRIGGER_DETAIL.`as`("t2") + val t1 = T_PIPELINE_TRIGGER_EVENT.`as`("t1") + val t2 = T_PIPELINE_TRIGGER_DETAIL.`as`("t2") val conditions = buildConditions( t1 = t1, t2 = t2, @@ -237,7 +238,7 @@ class PipelineTriggerEventDao { dslContext: DSLContext, eventIds: List ): Result { - return with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { + return with(T_PIPELINE_TRIGGER_EVENT) { dslContext.selectFrom(this) .where(EVENT_ID.`in`(eventIds)) .fetch() @@ -259,43 +260,65 @@ class PipelineTriggerEventDao { limit: Int, offset: Int ): List { - val t1 = TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT.`as`("t1") - val t2 = TPipelineTriggerDetail.T_PIPELINE_TRIGGER_DETAIL.`as`("t2") - val conditions = buildConditions( - t1 = t1, - t2 = t2, + val buildDetailCondition = buildDetailCondition( + T_PIPELINE_TRIGGER_DETAIL, + projectId = projectId, + pipelineName = pipelineName, + pipelineId = pipelineId, + eventId = eventId + ) + val buildEventCondition = buildEventCondition( + T_PIPELINE_TRIGGER_EVENT, projectId = projectId, eventSource = eventSource, eventId = eventId, - pipelineName = pipelineName, eventType = eventType, triggerUser = triggerUser, triggerType = triggerType, - pipelineId = pipelineId, startTime = startTime, endTime = endTime ) - // 总数 - val totalCondition = if (pipelineName.isNullOrBlank()) { - count() - } else { - count(`when`(t2.PIPELINE_NAME.like("%$pipelineName%"), 1)) - }.`as`("total") + // 事件信息 + val eventInfo = with(T_PIPELINE_TRIGGER_EVENT) { + dslContext.select( + PROJECT_ID, + EVENT_ID, + EVENT_SOURCE, + EVENT_DESC, + CREATE_TIME + ) + .from(this) + .where(buildEventCondition) + .orderBy(CREATE_TIME.desc()) + .limit(limit) + .offset(offset) + } + // 详情信息 + val detailInfo = with(T_PIPELINE_TRIGGER_DETAIL) { + dslContext.select( + EVENT_ID, + PROJECT_ID, + count().`as`("total"), + count(`when`(STATUS.eq(PipelineTriggerStatus.SUCCEED.name), 1)).`as`("success") + ) + .from(T_PIPELINE_TRIGGER_DETAIL) + .where(buildDetailCondition) + .groupBy(PROJECT_ID, EVENT_ID) + } return dslContext.select( - t1.PROJECT_ID, - t1.EVENT_ID, - t1.EVENT_SOURCE, - t1.EVENT_DESC, - t1.CREATE_TIME, - totalCondition, - count(`when`(t2.STATUS.eq(PipelineTriggerStatus.SUCCEED.name), 1)).`as`("success ") - ).from(t1).leftJoin(t2) - .on(t1.EVENT_ID.eq(t2.EVENT_ID)).and(t1.PROJECT_ID.eq(t2.PROJECT_ID)) - .where(conditions) - .groupBy(t1.PROJECT_ID, t1.EVENT_ID, t1.EVENT_SOURCE, t1.EVENT_DESC, t1.CREATE_TIME) - .orderBy(t1.CREATE_TIME.desc()) - .limit(limit) - .offset(offset) + T_PIPELINE_TRIGGER_EVENT.PROJECT_ID, + T_PIPELINE_TRIGGER_EVENT.EVENT_ID, + T_PIPELINE_TRIGGER_EVENT.EVENT_SOURCE, + T_PIPELINE_TRIGGER_EVENT.EVENT_DESC, + T_PIPELINE_TRIGGER_EVENT.CREATE_TIME, + detailInfo.field("total", Int::class.java), + detailInfo.field("success", Int::class.java) + ) + .from(eventInfo) + .leftJoin(detailInfo) + .on(T_PIPELINE_TRIGGER_EVENT.EVENT_ID.eq(T_PIPELINE_TRIGGER_DETAIL.EVENT_ID) + .and(T_PIPELINE_TRIGGER_EVENT.PROJECT_ID.eq(T_PIPELINE_TRIGGER_DETAIL.PROJECT_ID))) + .where(detailInfo.field("total", Int::class.java)?.gt(0)) .fetch().map { RepoTriggerEventVo( projectId = it.value1(), @@ -322,27 +345,61 @@ class PipelineTriggerEventDao { startTime: Long? = null, endTime: Long? = null ): Long { - val t1 = TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT.`as`("t1") - val t2 = TPipelineTriggerDetail.T_PIPELINE_TRIGGER_DETAIL.`as`("t2") - val conditions = buildConditions( - t1 = t1, - t2 = t2, + val buildDetailCondition = buildDetailCondition( + T_PIPELINE_TRIGGER_DETAIL, + projectId = projectId, + pipelineName = pipelineName, + pipelineId = pipelineId, + eventId = eventId + ) + val buildEventCondition = buildEventCondition( + T_PIPELINE_TRIGGER_EVENT, projectId = projectId, eventSource = eventSource, eventId = eventId, - pipelineName = pipelineName, eventType = eventType, triggerUser = triggerUser, triggerType = triggerType, - pipelineId = pipelineId, startTime = startTime, endTime = endTime ) - return dslContext.select(DSL.countDistinct(t1.PROJECT_ID, t1.EVENT_ID)) - .from(t1) - .leftJoin(t2) - .on(t1.EVENT_ID.eq(t2.EVENT_ID)).and(t1.PROJECT_ID.eq(t2.PROJECT_ID)) - .where(conditions) + // 事件信息 + val eventInfo = with(T_PIPELINE_TRIGGER_EVENT) { + dslContext.select( + PROJECT_ID, + EVENT_ID, + EVENT_SOURCE, + EVENT_DESC, + CREATE_TIME + ) + .from(this) + .where(buildEventCondition) + .orderBy(CREATE_TIME.desc()) + } + // 详情信息 + val detailInfo = with(T_PIPELINE_TRIGGER_DETAIL) { + dslContext.select( + EVENT_ID, + PROJECT_ID, + count().`as`("total") + ) + .from(this) + .where(buildDetailCondition) + .groupBy(PROJECT_ID, EVENT_ID) + } + return dslContext.selectCount() + .from(eventInfo) + .leftJoin(detailInfo) + .on( + eventInfo.field(T_PIPELINE_TRIGGER_EVENT.PROJECT_ID)?.eq( + detailInfo.field(T_PIPELINE_TRIGGER_DETAIL.PROJECT_ID) + )?.and( + eventInfo.field(T_PIPELINE_TRIGGER_EVENT.EVENT_ID)?.eq( + detailInfo.field(T_PIPELINE_TRIGGER_DETAIL.EVENT_ID) + ) + ) + ) + .where(detailInfo.field("total", Int::class.java)?.gt(0)) .fetchOne(0, Long::class.java)!! } @@ -351,7 +408,7 @@ class PipelineTriggerEventDao { projectId: String, eventId: Long ): PipelineTriggerEvent? { - val record = with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { + val record = with(T_PIPELINE_TRIGGER_EVENT) { dslContext.selectFrom(this) .where(EVENT_ID.eq(eventId)) .and(PROJECT_ID.eq(projectId)) @@ -366,7 +423,7 @@ class PipelineTriggerEventDao { requestId: String, eventSource: String ): PipelineTriggerEvent? { - val record = with(TPipelineTriggerEvent.T_PIPELINE_TRIGGER_EVENT) { + val record = with(T_PIPELINE_TRIGGER_EVENT) { dslContext.selectFrom(this) .where(PROJECT_ID.eq(projectId)) .and(REQUEST_ID.eq(requestId)) @@ -381,7 +438,7 @@ class PipelineTriggerEventDao { projectId: String, detailId: Long ): PipelineTriggerDetail? { - val record = with(TPipelineTriggerDetail.T_PIPELINE_TRIGGER_DETAIL) { + val record = with(T_PIPELINE_TRIGGER_DETAIL) { dslContext.selectFrom(this) .where(DETAIL_ID.eq(detailId)) .and(PROJECT_ID.eq(projectId)) @@ -390,6 +447,72 @@ class PipelineTriggerEventDao { return record?.let { convertDetail(it) } } + private fun buildDetailCondition( + t2: TPipelineTriggerDetail, + eventId: Long? = null, + pipelineName: String? = null, + projectId: String, + pipelineId: String? = null + ): List { + val conditions = mutableListOf() + with(t2) { + if (eventId != null) { + conditions.add(EVENT_ID.eq(eventId)) + } + if (!pipelineName.isNullOrBlank()) { + conditions.add(PIPELINE_NAME.like("%$pipelineName%")) + } + if (projectId.isNotBlank()) { + conditions.add(PROJECT_ID.eq(projectId)) + } + if (!pipelineId.isNullOrBlank()) { + conditions.add(PIPELINE_ID.eq(pipelineId)) + } + } + return conditions + } + + private fun buildEventCondition( + t1: TPipelineTriggerEvent, + eventId: Long? = null, + eventSource: String? = null, + projectId: String, + eventType: String?, + triggerUser: String? = null, + triggerType: String? = null, + startTime: Long? = null, + endTime: Long? = null + ): List { + val conditions = mutableListOf() + with(t1) { + if (eventId != null) { + conditions.add(EVENT_ID.eq(eventId)) + } + if (!eventSource.isNullOrBlank()) { + conditions.add(EVENT_SOURCE.eq(eventSource)) + } + if (projectId.isNotBlank()) { + conditions.add(PROJECT_ID.eq(projectId)) + } + if (!eventType.isNullOrBlank()) { + conditions.add(EVENT_TYPE.eq(eventType)) + } + if (!triggerUser.isNullOrBlank()) { + conditions.add(TRIGGER_USER.eq(triggerUser)) + } + if (!triggerType.isNullOrBlank()) { + conditions.add(TRIGGER_TYPE.eq(triggerType)) + } + if (startTime != null) { + conditions.add(CREATE_TIME.ge(Timestamp(startTime).toLocalDateTime())) + } + if (endTime != null) { + conditions.add(CREATE_TIME.le(Timestamp(endTime).toLocalDateTime())) + } + } + return conditions + } + private fun buildConditions( t1: TPipelineTriggerEvent, t2: TPipelineTriggerDetail, @@ -405,34 +528,28 @@ class PipelineTriggerEventDao { endTime: Long? = null ): List { val conditions = mutableListOf() - conditions.add(t1.PROJECT_ID.eq(projectId)) - if (!eventSource.isNullOrBlank()) { - conditions.add(t1.EVENT_SOURCE.eq(eventSource)) - } - if (eventId != null) { - conditions.add(t1.EVENT_ID.eq(eventId)) - } - if (!eventType.isNullOrBlank()) { - conditions.add(t1.EVENT_TYPE.eq(eventType)) - } - if (!triggerUser.isNullOrBlank()) { - conditions.add(t1.TRIGGER_USER.eq(triggerUser)) - } - if (!triggerType.isNullOrBlank()) { - conditions.add(t1.TRIGGER_TYPE.eq(triggerType)) - } - if (!pipelineId.isNullOrBlank()) { - conditions.add(t2.PIPELINE_ID.eq(pipelineId)) - } - if (startTime != null && startTime > 0) { - conditions.add(t1.CREATE_TIME.ge(Timestamp(startTime).toLocalDateTime())) - } - if (endTime != null && endTime > 0) { - conditions.add(t1.CREATE_TIME.le(Timestamp(endTime).toLocalDateTime())) - } - if (!pipelineName.isNullOrBlank()) { - conditions.add(t2.PIPELINE_NAME.like("%$pipelineName%")) - } + conditions.addAll( + buildEventCondition( + t1, + eventId = eventId, + eventSource = eventSource, + projectId = projectId, + eventType = eventType, + triggerType = triggerType, + triggerUser = triggerUser, + startTime = startTime, + endTime = endTime + ) + ) + conditions.addAll( + buildDetailCondition( + t2, + eventId = eventId, + projectId = projectId, + pipelineName = pipelineName, + pipelineId = pipelineId + ) + ) return conditions } From 71742994f824f2fe41dea1ac84d79d31b348745f Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 2 Nov 2023 09:10:44 +0800 Subject: [PATCH 102/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/dao/PipelineTriggerEventDao.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index d1806d516ef..4024f090f1c 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -306,11 +306,11 @@ class PipelineTriggerEventDao { .groupBy(PROJECT_ID, EVENT_ID) } return dslContext.select( - T_PIPELINE_TRIGGER_EVENT.PROJECT_ID, - T_PIPELINE_TRIGGER_EVENT.EVENT_ID, - T_PIPELINE_TRIGGER_EVENT.EVENT_SOURCE, - T_PIPELINE_TRIGGER_EVENT.EVENT_DESC, - T_PIPELINE_TRIGGER_EVENT.CREATE_TIME, + eventInfo.field(T_PIPELINE_TRIGGER_EVENT.PROJECT_ID), + eventInfo.field(T_PIPELINE_TRIGGER_EVENT.EVENT_ID), + eventInfo.field(T_PIPELINE_TRIGGER_EVENT.EVENT_SOURCE), + eventInfo.field(T_PIPELINE_TRIGGER_EVENT.EVENT_DESC), + eventInfo.field(T_PIPELINE_TRIGGER_EVENT.CREATE_TIME), detailInfo.field("total", Int::class.java), detailInfo.field("success", Int::class.java) ) From 3dd321ac1a6de48b1724e30960f2cb48646f6396 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 2 Nov 2023 09:20:18 +0800 Subject: [PATCH 103/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/dao/PipelineTriggerEventDao.kt | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index 4024f090f1c..5be24956797 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -305,31 +305,35 @@ class PipelineTriggerEventDao { .where(buildDetailCondition) .groupBy(PROJECT_ID, EVENT_ID) } - return dslContext.select( - eventInfo.field(T_PIPELINE_TRIGGER_EVENT.PROJECT_ID), - eventInfo.field(T_PIPELINE_TRIGGER_EVENT.EVENT_ID), - eventInfo.field(T_PIPELINE_TRIGGER_EVENT.EVENT_SOURCE), - eventInfo.field(T_PIPELINE_TRIGGER_EVENT.EVENT_DESC), - eventInfo.field(T_PIPELINE_TRIGGER_EVENT.CREATE_TIME), - detailInfo.field("total", Int::class.java), - detailInfo.field("success", Int::class.java) - ) - .from(eventInfo) - .leftJoin(detailInfo) - .on(T_PIPELINE_TRIGGER_EVENT.EVENT_ID.eq(T_PIPELINE_TRIGGER_DETAIL.EVENT_ID) - .and(T_PIPELINE_TRIGGER_EVENT.PROJECT_ID.eq(T_PIPELINE_TRIGGER_DETAIL.PROJECT_ID))) - .where(detailInfo.field("total", Int::class.java)?.gt(0)) - .fetch().map { - RepoTriggerEventVo( - projectId = it.value1(), - eventId = it.value2(), - repoHashId = it.value3(), - eventDesc = it.value4(), - eventTime = it.value5().timestampmilli(), - total = it.value6(), - success = it.value7() + return with(T_PIPELINE_TRIGGER_EVENT) { + dslContext.select( + eventInfo.field(PROJECT_ID), + eventInfo.field(EVENT_ID), + eventInfo.field(EVENT_SOURCE), + eventInfo.field(EVENT_DESC), + eventInfo.field(CREATE_TIME), + detailInfo.field("total", Int::class.java), + detailInfo.field("success", Int::class.java) + ) + .from(eventInfo) + .leftJoin(detailInfo) + .on( + eventInfo.field(EVENT_ID)?.eq(detailInfo.field(T_PIPELINE_TRIGGER_DETAIL.EVENT_ID)) + ?.and(eventInfo.field(PROJECT_ID)?.eq(detailInfo.field(T_PIPELINE_TRIGGER_DETAIL.PROJECT_ID))) ) - } + .where(detailInfo.field("total", Int::class.java)?.gt(0)) + .fetch().map { + RepoTriggerEventVo( + projectId = it.value1(), + eventId = it.value2(), + repoHashId = it.value3(), + eventDesc = it.value4(), + eventTime = it.value5().timestampmilli(), + total = it.value6(), + success = it.value7() + ) + } + } } fun countRepoTriggerEvent( From ec5c4f03af13cdf249e4f954d41d9878aff18a17 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 6 Nov 2023 10:07:13 +0800 Subject: [PATCH 104/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pojo/trigger/RepoTriggerEventDetail.kt | 44 +++ .../process/dao/PipelineTriggerEventDao.kt | 276 +++++++++--------- .../trigger/PipelineTriggerEventService.kt | 112 +++++-- 3 files changed, 269 insertions(+), 163 deletions(-) create mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/RepoTriggerEventDetail.kt diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/RepoTriggerEventDetail.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/RepoTriggerEventDetail.kt new file mode 100644 index 00000000000..ef62458a716 --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/RepoTriggerEventDetail.kt @@ -0,0 +1,44 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.pojo.trigger + +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty + +@ApiModel("代码库webhook事件记录") +data class RepoTriggerEventDetail( + @ApiModelProperty("项目ID") + val projectId: String, + @ApiModelProperty("事件ID") + val eventId: Long, + @ApiModelProperty("总流水线数") + val total: Int, + @ApiModelProperty("成功的流水线数") + val success: Int +) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index 5be24956797..e05fc80ca43 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -28,6 +28,7 @@ package com.tencent.devops.process.dao import com.fasterxml.jackson.core.type.TypeReference +import com.sun.jna.platform.win32.WinBase.SYSTEM_INFO.PI import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.timestamp @@ -43,7 +44,7 @@ import com.tencent.devops.process.pojo.trigger.PipelineTriggerDetail import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventVo import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus -import com.tencent.devops.process.pojo.trigger.RepoTriggerEventVo +import com.tencent.devops.process.pojo.trigger.RepoTriggerEventDetail import org.jooq.Condition import org.jooq.DSLContext import org.jooq.Result @@ -245,166 +246,175 @@ class PipelineTriggerEventDao { } } - fun listRepoTriggerEvent( + fun getEventIdsByEvent( dslContext: DSLContext, - projectId: String, - eventSource: String? = null, eventId: Long? = null, - pipelineName: String? = null, + eventSource: String? = null, + projectId: String, eventType: String? = null, triggerType: String? = null, triggerUser: String? = null, - pipelineId: String? = null, startTime: Long? = null, endTime: Long? = null, - limit: Int, - offset: Int - ): List { - val buildDetailCondition = buildDetailCondition( - T_PIPELINE_TRIGGER_DETAIL, - projectId = projectId, - pipelineName = pipelineName, - pipelineId = pipelineId, - eventId = eventId - ) - val buildEventCondition = buildEventCondition( - T_PIPELINE_TRIGGER_EVENT, - projectId = projectId, - eventSource = eventSource, - eventId = eventId, - eventType = eventType, - triggerUser = triggerUser, - triggerType = triggerType, - startTime = startTime, - endTime = endTime - ) - // 事件信息 - val eventInfo = with(T_PIPELINE_TRIGGER_EVENT) { - dslContext.select( - PROJECT_ID, - EVENT_ID, - EVENT_SOURCE, - EVENT_DESC, - CREATE_TIME - ) - .from(this) - .where(buildEventCondition) - .orderBy(CREATE_TIME.desc()) - .limit(limit) - .offset(offset) - } - // 详情信息 - val detailInfo = with(T_PIPELINE_TRIGGER_DETAIL) { - dslContext.select( - EVENT_ID, - PROJECT_ID, - count().`as`("total"), - count(`when`(STATUS.eq(PipelineTriggerStatus.SUCCEED.name), 1)).`as`("success") - ) - .from(T_PIPELINE_TRIGGER_DETAIL) - .where(buildDetailCondition) - .groupBy(PROJECT_ID, EVENT_ID) - } + limit: Int? = null, + offset: Int? = null + ): Set { return with(T_PIPELINE_TRIGGER_EVENT) { - dslContext.select( - eventInfo.field(PROJECT_ID), - eventInfo.field(EVENT_ID), - eventInfo.field(EVENT_SOURCE), - eventInfo.field(EVENT_DESC), - eventInfo.field(CREATE_TIME), - detailInfo.field("total", Int::class.java), - detailInfo.field("success", Int::class.java) - ) - .from(eventInfo) - .leftJoin(detailInfo) - .on( - eventInfo.field(EVENT_ID)?.eq(detailInfo.field(T_PIPELINE_TRIGGER_DETAIL.EVENT_ID)) - ?.and(eventInfo.field(PROJECT_ID)?.eq(detailInfo.field(T_PIPELINE_TRIGGER_DETAIL.PROJECT_ID))) - ) - .where(detailInfo.field("total", Int::class.java)?.gt(0)) - .fetch().map { - RepoTriggerEventVo( - projectId = it.value1(), - eventId = it.value2(), - repoHashId = it.value3(), - eventDesc = it.value4(), - eventTime = it.value5().timestampmilli(), - total = it.value6(), - success = it.value7() + val step = dslContext + .selectFrom(this) + .where( + buildEventCondition( + this, + projectId = projectId, + eventSource = eventSource, + eventId = eventId, + eventType = eventType, + triggerUser = triggerUser, + triggerType = triggerType, + startTime = startTime, + endTime = endTime ) - } + ) + .orderBy(CREATE_TIME.desc()) + if (limit != null) { + step.limit(limit) + } + if (offset != null) { + step.offset(offset) + } + step.fetch(EVENT_ID).toSet() } } - fun countRepoTriggerEvent( + fun getCountByEvent( dslContext: DSLContext, - projectId: String, - eventSource: String? = null, eventId: Long? = null, - pipelineName: String? = null, + eventSource: String? = null, + projectId: String, eventType: String? = null, triggerType: String? = null, triggerUser: String? = null, - pipelineId: String? = null, startTime: Long? = null, endTime: Long? = null ): Long { - val buildDetailCondition = buildDetailCondition( - T_PIPELINE_TRIGGER_DETAIL, - projectId = projectId, - pipelineName = pipelineName, - pipelineId = pipelineId, - eventId = eventId - ) - val buildEventCondition = buildEventCondition( - T_PIPELINE_TRIGGER_EVENT, - projectId = projectId, - eventSource = eventSource, - eventId = eventId, - eventType = eventType, - triggerUser = triggerUser, - triggerType = triggerType, - startTime = startTime, - endTime = endTime - ) - // 事件信息 - val eventInfo = with(T_PIPELINE_TRIGGER_EVENT) { - dslContext.select( - PROJECT_ID, - EVENT_ID, - EVENT_SOURCE, - EVENT_DESC, - CREATE_TIME - ) + return with(T_PIPELINE_TRIGGER_EVENT) { + dslContext.selectCount() .from(this) - .where(buildEventCondition) + .where( + buildEventCondition( + this, + projectId = projectId, + eventSource = eventSource, + eventId = eventId, + eventType = eventType, + triggerUser = triggerUser, + triggerType = triggerType, + startTime = startTime, + endTime = endTime + ) + ).fetchOne(0, Long::class.java)!! + } + } + + fun getCountByDetail( + dslContext: DSLContext, + eventIds: Set, + projectId: String, + pipelineName: String, + pipelineId: String? + ): Long { + return with(T_PIPELINE_TRIGGER_DETAIL) { + dslContext.selectCount() + .from(this) + .where( + PROJECT_ID.eq(projectId).and( + EVENT_ID.`in`(eventIds) + ).and( + PIPELINE_NAME.like("%$pipelineName%") + ).and( + PIPELINE_ID.eq(pipelineId) + ) + ).fetchOne(0, Long::class.java)!! + } + } + + fun getDetailEventIds( + dslContext: DSLContext, + baseEventIds: Set, + pipelineName: String, + pipelineId: String?, + limit: Int, + offset: Int + ): Set { + return with(T_PIPELINE_TRIGGER_DETAIL) { + val conditions = mutableListOf() + if (baseEventIds.isNotEmpty()) { + conditions.add(EVENT_ID.`in`(baseEventIds)) + } + if (pipelineName.isNotBlank()) { + conditions.add(PIPELINE_NAME.like("%$pipelineName%")) + } + if (!pipelineId.isNullOrBlank()) { + conditions.add(PIPELINE_ID.eq(pipelineId)) + } + return dslContext.selectFrom(this) + .where(conditions) + .orderBy(CREATE_TIME.desc()) + .limit(limit) + .offset(offset) + .fetch(EVENT_ID) + .toSet() + } + } + + fun listRepoTriggerEvent( + dslContext: DSLContext, + eventIds: Set + ): List { + return with(T_PIPELINE_TRIGGER_EVENT) { + dslContext.selectFrom(this) + .where(EVENT_ID.`in`(eventIds)) .orderBy(CREATE_TIME.desc()) + .fetch() } - // 详情信息 - val detailInfo = with(T_PIPELINE_TRIGGER_DETAIL) { + } + + fun listRepoTriggerDetail( + dslContext: DSLContext, + projectId: String, + eventIds: Set, + pipelineName: String?, + pipelineId: String? + ): List { + return with(T_PIPELINE_TRIGGER_DETAIL) { + val conditions = mutableListOf( + EVENT_ID.`in`(eventIds), + PROJECT_ID.eq(PROJECT_ID) + ) + if (!pipelineName.isNullOrBlank()) { + conditions.add(PIPELINE_NAME.like("%$pipelineName%")) + } + if (!pipelineId.isNullOrBlank()) { + conditions.add(PIPELINE_ID.eq(pipelineId)) + } dslContext.select( - EVENT_ID, PROJECT_ID, - count().`as`("total") + EVENT_ID, + count().`as`("total"), + count(`when`(STATUS.eq(PipelineTriggerStatus.SUCCEED.name), 1)) ) .from(this) - .where(buildDetailCondition) - .groupBy(PROJECT_ID, EVENT_ID) - } - return dslContext.selectCount() - .from(eventInfo) - .leftJoin(detailInfo) - .on( - eventInfo.field(T_PIPELINE_TRIGGER_EVENT.PROJECT_ID)?.eq( - detailInfo.field(T_PIPELINE_TRIGGER_DETAIL.PROJECT_ID) - )?.and( - eventInfo.field(T_PIPELINE_TRIGGER_EVENT.EVENT_ID)?.eq( - detailInfo.field(T_PIPELINE_TRIGGER_DETAIL.EVENT_ID) + .where(conditions) + .orderBy(PIPELINE_NAME) + .fetch().map { + RepoTriggerEventDetail( + projectId = it.value1(), + eventId = it.value2(), + total = it.value3(), + success = it.value4() ) - ) - ) - .where(detailInfo.field("total", Int::class.java)?.gt(0)) - .fetchOne(0, Long::class.java)!! + } + } } fun getTriggerEvent( diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 9382a788832..4c056f57ccb 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -35,6 +35,7 @@ import com.tencent.devops.common.api.model.SQLPage import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.PageUtil +import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.client.Client import com.tencent.devops.common.service.trace.TraceTag import com.tencent.devops.common.service.utils.HomeHostUtil @@ -184,41 +185,92 @@ 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.countRepoTriggerEvent( + // 事件ID to 总数 + val (eventIds, count) = if (pipelineName.isNullOrBlank() || pipelineId.isNullOrBlank()) { + val eventIds = pipelineTriggerEventDao.getEventIdsByEvent( + dslContext = dslContext, + projectId = projectId, + eventSource = repoHashId, + eventId = eventId, + eventType = eventType, + triggerUser = triggerUser, + triggerType = triggerType, + startTime = startTime, + endTime = endTime, + limit = sqlLimit.limit, + offset = sqlLimit.offset + ) + val count = pipelineTriggerEventDao.getCountByEvent( + dslContext = dslContext, + eventId = eventId, + projectId = projectId, + eventSource = repoHashId, + eventType = eventType, + triggerType = triggerType, + triggerUser = triggerUser, + startTime = startTime, + endTime = endTime + ) + eventIds to count + } else { + // 满足事件要求的EventIds + val baseEventIds = pipelineTriggerEventDao.getEventIdsByEvent( + dslContext = dslContext, + projectId = projectId, + eventSource = repoHashId, + eventId = eventId, + eventType = eventType, + triggerUser = triggerUser, + triggerType = triggerType, + startTime = startTime, + endTime = endTime + ) + // 根据pipelineName进行EventId二次筛选 + val eventIds = pipelineTriggerEventDao.getDetailEventIds( + dslContext = dslContext, + baseEventIds = baseEventIds, + pipelineName = pipelineName, + pipelineId = pipelineId, + limit = sqlLimit.limit, + offset = sqlLimit.offset + ) + val count = pipelineTriggerEventDao.getCountByDetail( + dslContext = dslContext, + eventIds = baseEventIds, + projectId = projectId, + pipelineName = pipelineName, + pipelineId = pipelineId + ) + eventIds to count + } + // 事件信息 + val triggerEvent = pipelineTriggerEventDao.listRepoTriggerEvent( dslContext = dslContext, - projectId = projectId, - eventSource = repoHashId, - eventType = eventType, - triggerType = triggerType, - triggerUser = triggerUser, - pipelineId = pipelineId, - eventId = eventId, - pipelineName = pipelineName, - startTime = startTime, - endTime = endTime + eventIds = eventIds ) - val records = pipelineTriggerEventDao.listRepoTriggerEvent( + // 触发详情记录(总数,成功数) + val eventDetailsMap = pipelineTriggerEventDao.listRepoTriggerDetail( dslContext = dslContext, projectId = projectId, - eventSource = repoHashId, - eventType = eventType, - triggerType = triggerType, - triggerUser = triggerUser, - pipelineId = pipelineId, - eventId = eventId, + eventIds = eventIds, pipelineName = pipelineName, - startTime = startTime, - endTime = endTime, - limit = sqlLimit.limit, - offset = sqlLimit.offset - ).map { - it.eventDesc = try { - JsonUtil.to(it.eventDesc, I18Variable::class.java).getCodeLanMessage(language) - } catch (ignored: Exception) { - logger.warn("Failed to resolve repo trigger event|sourceDesc[${it.eventDesc}]", ignored) - it.eventDesc - } - it + pipelineId = pipelineId + ).associateBy { it.eventId } + val records = triggerEvent.map { + RepoTriggerEventVo( + projectId = it.projectId, + eventId = it.eventId, + repoHashId = it.eventSource, + eventDesc = try { + JsonUtil.to(it.eventDesc, I18Variable::class.java).getCodeLanMessage(language) + } catch (ignored: Exception) { + logger.warn("Failed to resolve repo trigger event|sourceDesc[${it.eventDesc}]", ignored) + it.eventDesc + }, + eventTime = it.createTime.timestampmilli(), + total = eventDetailsMap[it.eventId]?.total ?: 0, + success = eventDetailsMap[it.eventId]?.success ?: 0 + ) } return SQLPage(count = count, records = records) } From 7b2f1f9fc465b1ba75604dab1e99d3647c11b665 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 6 Nov 2023 10:19:21 +0800 Subject: [PATCH 105/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tencent/devops/process/dao/PipelineTriggerEventDao.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index e05fc80ca43..43969fc686e 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -28,7 +28,6 @@ package com.tencent.devops.process.dao import com.fasterxml.jackson.core.type.TypeReference -import com.sun.jna.platform.win32.WinBase.SYSTEM_INFO.PI import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.timestamp From 0b01faafb79582d7f54702dd0694129ffef52abf Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 6 Nov 2023 10:33:04 +0800 Subject: [PATCH 106/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tencent/devops/process/dao/PipelineTriggerEventDao.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index 43969fc686e..b30332c648f 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -404,7 +404,7 @@ class PipelineTriggerEventDao { ) .from(this) .where(conditions) - .orderBy(PIPELINE_NAME) + .groupBy(PROJECT_ID, EVENT_ID) .fetch().map { RepoTriggerEventDetail( projectId = it.value1(), From 18db56c4ea340917734b65ba56a83c0de8f8e8e7 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 6 Nov 2023 15:41:18 +0800 Subject: [PATCH 107/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/dao/PipelineTriggerEventDao.kt | 99 ++++++++++++------- .../trigger/PipelineTriggerEventService.kt | 18 ++-- 2 files changed, 72 insertions(+), 45 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index b30332c648f..7f4e5c4a0b6 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -48,6 +48,7 @@ import org.jooq.Condition import org.jooq.DSLContext import org.jooq.Result import org.jooq.impl.DSL.count +import org.jooq.impl.DSL.countDistinct import org.jooq.impl.DSL.`when` import org.springframework.stereotype.Repository import java.sql.Timestamp @@ -317,53 +318,79 @@ class PipelineTriggerEventDao { fun getCountByDetail( dslContext: DSLContext, - eventIds: Set, - projectId: String, pipelineName: String, - pipelineId: String? + pipelineId: String?, + eventId: Long? = null, + eventSource: String? = null, + projectId: String, + eventType: String? = null, + triggerType: String? = null, + triggerUser: String? = null, + startTime: Long? = null, + endTime: Long? = null ): Long { - return with(T_PIPELINE_TRIGGER_DETAIL) { - dslContext.selectCount() - .from(this) - .where( - PROJECT_ID.eq(projectId).and( - EVENT_ID.`in`(eventIds) - ).and( - PIPELINE_NAME.like("%$pipelineName%") - ).and( - PIPELINE_ID.eq(pipelineId) - ) - ).fetchOne(0, Long::class.java)!! - } + val t1 = T_PIPELINE_TRIGGER_EVENT.`as`("t1") + val t2 = T_PIPELINE_TRIGGER_DETAIL.`as`("t2") + val conditions = buildConditions( + t1 = t1, + t2 = t2, + projectId = projectId, + eventSource = eventSource, + eventId = eventId, + eventType = eventType, + triggerUser = triggerUser, + triggerType = triggerType, + pipelineId = pipelineId, + pipelineName = pipelineName, + startTime = startTime, + endTime = endTime + ) + return dslContext.select(countDistinct(t2.EVENT_ID)) + .from(t2).leftJoin(t1) + .on(t1.EVENT_ID.eq(t2.EVENT_ID)).and(t1.PROJECT_ID.eq(t2.PROJECT_ID)) + .where(conditions) + .fetchOne(0, Long::class.java)!! } fun getDetailEventIds( dslContext: DSLContext, - baseEventIds: Set, pipelineName: String, pipelineId: String?, + eventId: Long? = null, + eventSource: String? = null, + projectId: String, + eventType: String? = null, + triggerType: String? = null, + triggerUser: String? = null, + startTime: Long? = null, + endTime: Long? = null, limit: Int, offset: Int ): Set { - return with(T_PIPELINE_TRIGGER_DETAIL) { - val conditions = mutableListOf() - if (baseEventIds.isNotEmpty()) { - conditions.add(EVENT_ID.`in`(baseEventIds)) - } - if (pipelineName.isNotBlank()) { - conditions.add(PIPELINE_NAME.like("%$pipelineName%")) - } - if (!pipelineId.isNullOrBlank()) { - conditions.add(PIPELINE_ID.eq(pipelineId)) - } - return dslContext.selectFrom(this) - .where(conditions) - .orderBy(CREATE_TIME.desc()) - .limit(limit) - .offset(offset) - .fetch(EVENT_ID) - .toSet() - } + val t1 = T_PIPELINE_TRIGGER_EVENT.`as`("t1") + val t2 = T_PIPELINE_TRIGGER_DETAIL.`as`("t2") + val conditions = buildConditions( + t1 = t1, + t2 = t2, + projectId = projectId, + eventSource = eventSource, + eventId = eventId, + eventType = eventType, + triggerUser = triggerUser, + triggerType = triggerType, + pipelineId = pipelineId, + pipelineName = pipelineName, + startTime = startTime, + endTime = endTime + ) + return dslContext.select() + .from(t2).leftJoin(t1) + .on(t1.EVENT_ID.eq(t2.EVENT_ID)).and(t1.PROJECT_ID.eq(t2.PROJECT_ID)) + .where(conditions) + .limit(limit) + .offset(offset) + .fetch(t2.EVENT_ID) + .toSet() } fun listRepoTriggerEvent( diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 4c056f57ccb..00ed0d3dd4a 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -213,8 +213,7 @@ class PipelineTriggerEventService @Autowired constructor( ) eventIds to count } else { - // 满足事件要求的EventIds - val baseEventIds = pipelineTriggerEventDao.getEventIdsByEvent( + val eventIds = pipelineTriggerEventDao.getDetailEventIds( dslContext = dslContext, projectId = projectId, eventSource = repoHashId, @@ -223,12 +222,7 @@ class PipelineTriggerEventService @Autowired constructor( triggerUser = triggerUser, triggerType = triggerType, startTime = startTime, - endTime = endTime - ) - // 根据pipelineName进行EventId二次筛选 - val eventIds = pipelineTriggerEventDao.getDetailEventIds( - dslContext = dslContext, - baseEventIds = baseEventIds, + endTime = endTime, pipelineName = pipelineName, pipelineId = pipelineId, limit = sqlLimit.limit, @@ -236,8 +230,14 @@ class PipelineTriggerEventService @Autowired constructor( ) val count = pipelineTriggerEventDao.getCountByDetail( dslContext = dslContext, - eventIds = baseEventIds, projectId = projectId, + eventSource = repoHashId, + eventId = eventId, + eventType = eventType, + triggerUser = triggerUser, + triggerType = triggerType, + startTime = startTime, + endTime = endTime, pipelineName = pipelineName, pipelineId = pipelineId ) From 75905f2fd1c08923f4d75c009d4c220b953844bc Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 6 Nov 2023 16:25:45 +0800 Subject: [PATCH 108/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/trigger/PipelineTriggerEventService.kt | 2 +- support-files/i18n/process/message_en_US.properties | 2 +- support-files/i18n/process/message_zh_CN.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 00ed0d3dd4a..c26f14ffdad 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -391,7 +391,7 @@ class PipelineTriggerEventService @Autowired constructor( userId = userId, projectId = projectId, eventId = replayEventId, - replayRequestId = triggerEvent.requestId, + replayRequestId = replayRequestId, scmType = scmType, pipelineId = pipelineId ) diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index 8876041c1e7..c86ada5367f 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -386,7 +386,7 @@ bkSvnCommitEventDesc=Commit [{0}] pushed by {1}{0} bkRemoteStartEventDesc=Remote api triggered by {0} bkServiceStartEventDesc={0} Pipeline invocation triggered by [{2}] invoke -bkEventReplayDesc=Event [{0}] replayed by {1} +bkEventReplayDesc=Event [{0}] replayed by {1} bkRepoTriggerEventTypeNotMatch=Event type mismatch bkRepoTriggerTargetBranchNotMatch=Target branch [{0}] of merge request does not match bkRepoTriggerTargetBranchIgnored=Target branch [{0}] of merge request has been excluded diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 06ccb0dcca4..63c43aa1375 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -386,7 +386,7 @@ bkSvnCommitEventDesc=提交 [{0}] 由 {1} bkManualStartEventDesc={0} 手动触发 bkRemoteStartEventDesc={0} 远程触发 bkServiceStartEventDesc={0} 触发的流水线 [{2}] 调用 -bkEventReplayDesc=事件 [{0}] 由 {1} 重放 +bkEventReplayDesc=事件 [{0}] 由 {1} 重放 bkRepoTriggerEventTypeNotMatch=事件类型不满足触发条件 bkRepoTriggerTargetBranchNotMatch=MR目标分支[{0}]不满足触发条件 bkRepoTriggerTargetBranchIgnored=MR目标分支[{0}]被排除 From 1ef0492b56fc3669123b25534a39d2a40f88c55e Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 7 Nov 2023 11:30:53 +0800 Subject: [PATCH 109/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/dao/PipelineTriggerEventDao.kt | 10 +++++----- .../process/trigger/PipelineTriggerEventService.kt | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt index 7f4e5c4a0b6..934d49657e6 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/dao/PipelineTriggerEventDao.kt @@ -318,7 +318,7 @@ class PipelineTriggerEventDao { fun getCountByDetail( dslContext: DSLContext, - pipelineName: String, + pipelineName: String?, pipelineId: String?, eventId: Long? = null, eventSource: String? = null, @@ -354,7 +354,7 @@ class PipelineTriggerEventDao { fun getDetailEventIds( dslContext: DSLContext, - pipelineName: String, + pipelineName: String?, pipelineId: String?, eventId: Long? = null, eventSource: String? = null, @@ -383,14 +383,14 @@ class PipelineTriggerEventDao { startTime = startTime, endTime = endTime ) - return dslContext.select() + return dslContext.select(t2.EVENT_ID) .from(t2).leftJoin(t1) .on(t1.EVENT_ID.eq(t2.EVENT_ID)).and(t1.PROJECT_ID.eq(t2.PROJECT_ID)) .where(conditions) + .orderBy(t2.CREATE_TIME.desc()) .limit(limit) .offset(offset) - .fetch(t2.EVENT_ID) - .toSet() + .fetch().distinct().map { it.value1() }.toSet() } fun listRepoTriggerEvent( diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index c26f14ffdad..871d9dc2061 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -186,7 +186,7 @@ class PipelineTriggerEventService @Autowired constructor( val sqlLimit = PageUtil.convertPageSizeToSQLMAXLimit(pageNotNull, pageSizeNotNull) val language = I18nUtil.getLanguage(userId) // 事件ID to 总数 - val (eventIds, count) = if (pipelineName.isNullOrBlank() || pipelineId.isNullOrBlank()) { + val (eventIds, count) = if (pipelineName.isNullOrBlank() && pipelineId.isNullOrBlank()) { val eventIds = pipelineTriggerEventDao.getEventIdsByEvent( dslContext = dslContext, projectId = projectId, From 02c5cf133acf2892d316b1544524a470f0e2756b Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 8 Nov 2023 10:57:52 +0800 Subject: [PATCH 110/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- support-files/sql/1001_ci_process_ddl_mysql.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support-files/sql/1001_ci_process_ddl_mysql.sql b/support-files/sql/1001_ci_process_ddl_mysql.sql index a4962b2bce1..94431ceec4f 100644 --- a/support-files/sql/1001_ci_process_ddl_mysql.sql +++ b/support-files/sql/1001_ci_process_ddl_mysql.sql @@ -1187,7 +1187,7 @@ CREATE TABLE IF NOT EXISTS `T_PIPELINE_TRIGGER_DETAIL` `REASON_DETAIL` text DEFAULT NULL COMMENT '原因详情', `CREATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', PRIMARY KEY (`DETAIL_ID`, `CREATE_TIME`), - INDEX IDX_PROJECT_ID_EVENT_ID (`PROJECT_ID`, `EVENT_ID`) + INDEX IDX_PROJECT_ID_EVENT_ID (`PROJECT_ID`, `EVENT_ID`, `PIPELINE_NAME`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT ='流水线触发事件明细表'; SET FOREIGN_KEY_CHECKS = 1; From 919932e0de34f385c3412c1a0509a2f7a70cce9c Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 9 Nov 2023 17:43:24 +0800 Subject: [PATCH 111/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/overview/db/devops_ci_process.md | 46 +++++++++++++++++++ .../github/GithubCreateTriggerHandler.kt | 5 +- .../github/GithubPushTriggerHandler.kt | 5 +- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/docs/overview/db/devops_ci_process.md b/docs/overview/db/devops_ci_process.md index 354bf30c323..500da903438 100644 --- a/docs/overview/db/devops_ci_process.md +++ b/docs/overview/db/devops_ci_process.md @@ -58,6 +58,8 @@ | [T_TEMPLATE_INSTANCE_BASE](#T_TEMPLATE_INSTANCE_BASE) | 模板实列化基本信息表 | | [T_TEMPLATE_INSTANCE_ITEM](#T_TEMPLATE_INSTANCE_ITEM) | 模板实列化项信息表 | | [T_TEMPLATE_PIPELINE](#T_TEMPLATE_PIPELINE) | 流水线模板-实例映射表 | +| [T_PIPELINE_TRIGGER_EVENT](#T_PIPELINE_TRIGGER_EVENT) | 流水线触发事件表 | +| [T_PIPELINE_TRIGGER_DETAIL](#T_PIPELINE_TRIGGER_DETAIL) | 流水线触发事件明细表 | **表名:** T_AUDIT_RESOURCE @@ -846,6 +848,9 @@ | 8 | PROJECT_NAME | varchar | 128 | 0 | Y | N | | 项目名称 | | 9 | TASK_ID | varchar | 34 | 0 | Y | N | | 任务id | | 10 | DELETE | bit | 1 | 0 | Y | N | b'0' | 是否删除 | +| 11 | EXTERNAL_ID | varchar | 255 | 0 | Y | N | | webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port | +| 12 | EVENT_TYPE | varchar | 32 | 0 | Y | N | | 事件类型 | +| 13 | REPOSITORY_HASH_ID | varchar | 64 | 0 | Y | N | | 代码库hashId | **表名:** T_PIPELINE_WEBHOOK_QUEUE @@ -1016,3 +1021,44 @@ | 12 | BUILD_NO | text | 65535 | 0 | Y | N | | 构建号 | | 13 | PARAM | mediumtext | 16777215 | 0 | Y | N | | 参数 | | 14 | DELETED | bit | 1 | 0 | Y | N | b'0' | 流水线已被软删除 | + +**表名:** T_PIPELINE_TRIGGER_EVENT + +**说明:** 流水线触发事件表 + +**数据列:** + +| 序号 | 名称 | 数据类型 | 长度 | 小数位 | 允许空值 | 主键 | 默认值 | 说明 | +| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | +| 1 | REQUEST_ID | varchar | 64 | 0 | N | N | | 请求ID | +| 2 | PROJECT_ID | varchar | 64 | 0 | N | Y | | 项目ID | +| 3 | EVENT_ID | bigint | 20 | 0 | N | Y | | 事件ID | +| 4 | TRIGGER_TYPE | varchar | 32 | 0 | N | N | | 触发类型 | +| 5 | EVENT_SOURCE | varchar | 20 | 0 | N | N | | 触发源,代码库hashId/触发人/远程ip | +| 6 | EVENT_TYPE | varchar | 64 | 0 | N | N | | 事件类型 | +| 7 | TRIGGER_USER | varchar | 100 | 0 | N | N | | 触发用户 | +| 8 | EVENT_DESC | text | | 0 | N | N | | 事件描述 | +| 9 | REPLAY_REQUEST_ID | varchar | 64 | 0 | Y | N | | 重放请求ID | +| 10 | REQUEST_PARAMS | text | | 0 | N | N | | 请求参数 | +| 11 | CREATE_TIME | timestamp | | 0 | N | Y | | 事件时间 | + +**表名:** T_PIPELINE_TRIGGER_DETAIL + +**说明:** 流水线触发事件明细表 + +**数据列:** + +| 序号 | 名称 | 数据类型 | 长度 | 小数位 | 允许空值 | 主键 | 默认值 | 说明 | +| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | +| 1 | DETAIL_ID | varchar | 64 | 0 | N | Y | | 事件明细ID | +| 2 | PROJECT_ID | varchar | 64 | 0 | N | N | | 项目ID | +| 3 | EVENT_ID | bigint | 20 | 0 | N | N | | 事件ID | +| 4 | STATUS | varchar | 32 | 0 | Y | N | | 状态(success or failure) | +| 5 | PIPELINE_ID | varchar | 20 | 0 | Y | N | | 流水线ID | +| 6 | PIPELINE_NAME | varchar | 64 | 0 | Y | N | | 流水线名称 | +| 7 | VERSION | varchar | 100 | 0 | Y | N | | 流水线版本号 | +| 8 | BUILD_ID | text | | 0 | Y | N | | 构建ID | +| 9 | BUILD_NUM | varchar | 64 | 0 | Y | N | | 构建编号 | +| 10 | REASON | text | | 0 | Y | N | | 失败原因 | +| 11 | REASON_DETAIL | timestamp | | 0 | Y | N | | 原因详情 | +| 12 | CREATE_TIME | timestamp | | 0 | Y | Y | | 创建时间 | \ No newline at end of file diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt index a665d5e1147..5662194f712 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt @@ -35,6 +35,7 @@ import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GITHUB_WEBHOOK_CREATE import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GITHUB_WEBHOOK_CREATE_REF_TYPE import com.tencent.devops.common.webhook.pojo.code.BK_REPO_GITHUB_WEBHOOK_CREATE_USERNAME import com.tencent.devops.common.webhook.pojo.code.WebHookParams +import com.tencent.devops.common.webhook.pojo.code.github.GithubBaseInfo import com.tencent.devops.common.webhook.pojo.code.github.GithubCreateEvent import com.tencent.devops.common.webhook.service.code.filter.WebhookFilter import com.tencent.devops.common.webhook.service.code.handler.GitHookTriggerHandler @@ -78,10 +79,10 @@ class GithubCreateTriggerHandler : GitHookTriggerHandler { override fun getEventDesc(event: GithubCreateEvent): String { val (i18Code, linkUrl) = if (event.ref_type == "tag") { WebhookI18nConstants.GITHUB_CREATE_TAG_EVENT_DESC to - "https://github.com/${event.repository.fullName}/releases/tag/${event.ref}" + "${GithubBaseInfo.GITHUB_HOME_PAGE_URL}/${event.repository.fullName}/releases/tag/${event.ref}" } else { WebhookI18nConstants.GITHUB_CREATE_BRANCH_EVENT_DESC to - "https://github.com/${event.repository.fullName}/tree/${event.ref}" + "${GithubBaseInfo.GITHUB_HOME_PAGE_URL}/${event.repository.fullName}/tree/${event.ref}" } // 事件重放 return I18Variable( diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt index 5d31becdac4..c9b0bd43930 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubPushTriggerHandler.kt @@ -54,6 +54,7 @@ import com.tencent.devops.common.webhook.pojo.code.WebHookParams import com.tencent.devops.common.webhook.pojo.code.git.GitCommit import com.tencent.devops.common.webhook.pojo.code.git.GitCommitAuthor import com.tencent.devops.common.webhook.pojo.code.git.GitPushEvent +import com.tencent.devops.common.webhook.pojo.code.github.GithubBaseInfo import com.tencent.devops.common.webhook.pojo.code.github.GithubPushEvent import com.tencent.devops.common.webhook.service.code.filter.BranchFilter import com.tencent.devops.common.webhook.service.code.filter.UserFilter @@ -107,9 +108,9 @@ class GithubPushTriggerHandler : GitHookTriggerHandler { override fun getEventDesc(event: GithubPushEvent): String { val linkUrl = if (event.headCommit != null) { - "https://github.com/${event.repository.fullName}/commit/${event.headCommit?.id}" + "${GithubBaseInfo.GITHUB_HOME_PAGE_URL}/${event.repository.fullName}/commit/${event.headCommit?.id}" } else { - "https://github.com/${event.repository.fullName}/commit/${getBranchName(event)}" + "${GithubBaseInfo.GITHUB_HOME_PAGE_URL}/${event.repository.fullName}/commit/${getBranchName(event)}" } val revision = getRevision(event) val commitId = if (revision.isNotBlank()) { From 264adea2ac8637ce3bd338efb6e9860a21a4d611 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 9 Nov 2023 17:59:24 +0800 Subject: [PATCH 112/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webhook/enums/WebhookI18nConstants.kt | 2 +- support-files/i18n/message_en_US.properties | 31 +++++++++++++++++++ support-files/i18n/message_zh_CN.properties | 31 +++++++++++++++++++ .../i18n/process/message_en_US.properties | 31 ------------------- .../i18n/process/message_zh_CN.properties | 31 ------------------- 5 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt index f73aa9f5f13..c005fcd6381 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt @@ -121,6 +121,6 @@ object WebhookI18nConstants { // issues操作类型不匹配 const val ISSUES_ACTION_NOT_MATCH = "bkRepoTriggerIssueActionNotMatch" - // 事件回放匹配码后缀 + // 事件回放 const val EVENT_REPLAY_DESC = "bkEventReplayDesc" } diff --git a/support-files/i18n/message_en_US.properties b/support-files/i18n/message_en_US.properties index ffa7e6b9a6f..b2a4e95c302 100644 --- a/support-files/i18n/message_en_US.properties +++ b/support-files/i18n/message_en_US.properties @@ -425,3 +425,34 @@ BUILD_ENV_TYPE_WINDOWS=Build-Windows BUILD_ENV_TYPE_MACOS=Build-MacOS BUILD_ENV_TYPE_BUILDLESS=Buildles BUILD_ENV_TYPE_BUILD_TRIGGER=BuildTrigger +EVENT_TYPE_PUSH=Push +EVENT_TYPE_TAG_PUSH=Tag Push +EVENT_TYPE_MERGE_REQUEST=Merge Request +EVENT_TYPE_MERGE_REQUEST_ACCEPT=Merge Request Accept +EVENT_TYPE_ISSUES=Issue +EVENT_TYPE_NOTE=Note +EVENT_TYPE_REVIEW=Review +EVENT_TYPE_CREATE=Create Tag or Branch +EVENT_TYPE_PULL_REQUEST=Pull Request +EVENT_TYPE_POST_COMMIT=Post Commit +EVENT_TYPE_LOCK_COMMIT=Lock +EVENT_TYPE_PRE_COMMIT=Pre Commit +EVENT_TYPE_CHANGE_COMMIT=Change-Commit +EVENT_TYPE_CHANGE_CONTENT=Change-Content +EVENT_TYPE_CHANGE_SUBMIT=Change-Submit +EVENT_TYPE_SHELVE_COMMIT=Shelve-Commit +EVENT_TYPE_SHELVE_SUBMIT=Shelve-Submit +TRIGGER_TYPE_CODE_SVN=SVN +TRIGGER_TYPE_CODE_GIT=GIT +TRIGGER_TYPE_CODE_GITLAB=Gitlab +TRIGGER_TYPE_GITHUB=Github +TRIGGER_TYPE_CODE_TGIT=TGIT +TRIGGER_TYPE_CODE_P4=P4 +TRIGGER_TYPE_MANUAL=Manual Trigger +TRIGGER_TYPE_TIME_TRIGGER=Time Trigger +TRIGGER_TYPE_SERVICE=Service Trigger +TRIGGER_TYPE_PIPELINE=Pipeline Trigger +TRIGGER_TYPE_REMOTE=Remote Trigger +TRIGGER_SUCCESS=Trigger success +TRIGGER_FAILED=Trigger failed +TRIGGER_NOT_MATCH=Trigger not match diff --git a/support-files/i18n/message_zh_CN.properties b/support-files/i18n/message_zh_CN.properties index dd5fba1847f..27139a4849e 100644 --- a/support-files/i18n/message_zh_CN.properties +++ b/support-files/i18n/message_zh_CN.properties @@ -425,3 +425,34 @@ BUILD_ENV_TYPE_WINDOWS=构建环境-Windows BUILD_ENV_TYPE_MACOS=构建环境-MacOS BUILD_ENV_TYPE_BUILDLESS=无编译环境 BUILD_ENV_TYPE_BUILD_TRIGGER=构建触发 +EVENT_TYPE_PUSH=推送事件 +EVENT_TYPE_TAG_PUSH=Tag 推送事件 +EVENT_TYPE_MERGE_REQUEST=合并请求事件 +EVENT_TYPE_MERGE_REQUEST_ACCEPT=合并请求已合并事件 +EVENT_TYPE_ISSUES=议题事件 +EVENT_TYPE_NOTE=评论事件 +EVENT_TYPE_REVIEW=评审事件 +EVENT_TYPE_CREATE=创建 Tag/Branch 事件 +EVENT_TYPE_PULL_REQUEST=拉取请求事件 +EVENT_TYPE_POST_COMMIT=提交后置事件 +EVENT_TYPE_LOCK_COMMIT=锁定事件 +EVENT_TYPE_PRE_COMMIT=提交前置事件 +EVENT_TYPE_CHANGE_COMMIT=Change-Commit +EVENT_TYPE_CHANGE_CONTENT=Change-Content +EVENT_TYPE_CHANGE_SUBMIT=Change-Submit +EVENT_TYPE_SHELVE_COMMIT=Shelve-Commit +EVENT_TYPE_SHELVE_SUBMIT=Shelve-Submit +TRIGGER_TYPE_CODE_SVN=SVN 代码库 +TRIGGER_TYPE_CODE_GIT=GIT 代码库 +TRIGGER_TYPE_CODE_GITLAB=Gitlab 代码库 +TRIGGER_TYPE_GITHUB=Github 代码库 +TRIGGER_TYPE_CODE_TGIT=TGIT 代码库 +TRIGGER_TYPE_CODE_P4=P4 代码库 +TRIGGER_TYPE_MANUAL=手动触发 +TRIGGER_TYPE_TIME_TRIGGER=定时触发 +TRIGGER_TYPE_SERVICE=服务触发 +TRIGGER_TYPE_PIPELINE=流水线触发 +TRIGGER_TYPE_REMOTE=远程触发 +TRIGGER_SUCCESS=触发成功 +TRIGGER_FAILED=触发失败 +TRIGGER_NOT_MATCH=触发器不匹配 diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index c86ada5367f..2255afaa2d2 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -403,34 +403,3 @@ bkRepoTriggerNoteContentNotMatch=Note does not match bkRepoTriggerNoteActionNotMatch=Note type does not match bkRepoTriggerReviewActionNotMatch=Code review type does not match bkRepoTriggerIssueActionNotMatch=Issue action does not match -EVENT_TYPE_PUSH=Push -EVENT_TYPE_TAG_PUSH=Tag Push -EVENT_TYPE_MERGE_REQUEST=Merge Request -EVENT_TYPE_MERGE_REQUEST_ACCEPT=Merge Request Accept -EVENT_TYPE_ISSUES=Issue -EVENT_TYPE_NOTE=Note -EVENT_TYPE_REVIEW=Review -EVENT_TYPE_CREATE=Create Tag or Branch -EVENT_TYPE_PULL_REQUEST=Pull Request -EVENT_TYPE_POST_COMMIT=Post Commit -EVENT_TYPE_LOCK_COMMIT=Lock -EVENT_TYPE_PRE_COMMIT=Pre Commit -EVENT_TYPE_CHANGE_COMMIT=Change-Commit -EVENT_TYPE_CHANGE_CONTENT=Change-Content -EVENT_TYPE_CHANGE_SUBMIT=Change-Submit -EVENT_TYPE_SHELVE_COMMIT=Shelve-Commit -EVENT_TYPE_SHELVE_SUBMIT=Shelve-Submit -TRIGGER_TYPE_CODE_SVN=SVN -TRIGGER_TYPE_CODE_GIT=GIT -TRIGGER_TYPE_CODE_GITLAB=Gitlab -TRIGGER_TYPE_GITHUB=Github -TRIGGER_TYPE_CODE_TGIT=TGIT -TRIGGER_TYPE_CODE_P4=P4 -TRIGGER_TYPE_MANUAL=Manual Trigger -TRIGGER_TYPE_TIME_TRIGGER=Time Trigger -TRIGGER_TYPE_SERVICE=Service Trigger -TRIGGER_TYPE_PIPELINE=Pipeline Trigger -TRIGGER_TYPE_REMOTE=Remote Trigger -TRIGGER_SUCCESS=Trigger success -TRIGGER_FAILED=Trigger failed -TRIGGER_NOT_MATCH=Trigger not match diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 63c43aa1375..ecfd9829190 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -403,34 +403,3 @@ bkRepoTriggerNoteContentNotMatch=评论内容不满足触发条件 bkRepoTriggerNoteActionNotMatch=评论类型不满足触发条件 bkRepoTriggerReviewActionNotMatch=评审类型不满足触发条件 bkRepoTriggerIssueActionNotMatch=Issue 动作不满足触发条件 -EVENT_TYPE_PUSH=推送事件 -EVENT_TYPE_TAG_PUSH=Tag 推送事件 -EVENT_TYPE_MERGE_REQUEST=合并请求事件 -EVENT_TYPE_MERGE_REQUEST_ACCEPT=合并请求已合并事件 -EVENT_TYPE_ISSUES=议题事件 -EVENT_TYPE_NOTE=评论事件 -EVENT_TYPE_REVIEW=评审事件 -EVENT_TYPE_CREATE=创建 Tag/Branch 事件 -EVENT_TYPE_PULL_REQUEST=拉取请求事件 -EVENT_TYPE_POST_COMMIT=提交后置事件 -EVENT_TYPE_LOCK_COMMIT=锁定事件 -EVENT_TYPE_PRE_COMMIT=提交前置事件 -EVENT_TYPE_CHANGE_COMMIT=Change-Commit -EVENT_TYPE_CHANGE_CONTENT=Change-Content -EVENT_TYPE_CHANGE_SUBMIT=Change-Submit -EVENT_TYPE_SHELVE_COMMIT=Shelve-Commit -EVENT_TYPE_SHELVE_SUBMIT=Shelve-Submit -TRIGGER_TYPE_CODE_SVN=SVN 代码库 -TRIGGER_TYPE_CODE_GIT=GIT 代码库 -TRIGGER_TYPE_CODE_GITLAB=Gitlab 代码库 -TRIGGER_TYPE_GITHUB=Github 代码库 -TRIGGER_TYPE_CODE_TGIT=TGIT 代码库 -TRIGGER_TYPE_CODE_P4=P4 代码库 -TRIGGER_TYPE_MANUAL=手动触发 -TRIGGER_TYPE_TIME_TRIGGER=定时触发 -TRIGGER_TYPE_SERVICE=服务触发 -TRIGGER_TYPE_PIPELINE=流水线触发 -TRIGGER_TYPE_REMOTE=远程触发 -TRIGGER_SUCCESS=触发成功 -TRIGGER_FAILED=触发失败 -TRIGGER_NOT_MATCH=触发器不匹配 From dd0d59836ee547e127cf06923e6300698da81e7a Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 13 Nov 2023 14:14:41 +0800 Subject: [PATCH 113/143] =?UTF-8?q?feat=EF=BC=9A=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4=E5=BA=A6=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3=E7=A0=81=E5=BA=93?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webhook/enums/WebhookI18nConstants.kt | 6 +++ .../apigw/v3/ApigwBuildResourceV3Impl.kt | 3 +- .../apigw/v4/ApigwBuildResourceV4Impl.kt | 3 +- .../api/service/ServiceBuildResource.kt | 5 +- .../process/api/ServiceBuildResourceImpl.kt | 4 +- .../process/api/UserBuildResourceImpl.kt | 1 + .../service/PipelineRemoteAuthService.kt | 29 ++++-------- .../service/SubPipelineStartUpService.kt | 47 +++++++++++++++---- .../builds/PipelineBuildFacadeService.kt | 47 ++++++++++++++----- .../trigger/PipelineTriggerEventService.kt | 42 +++++++++++++---- .../service/image/ImageReleaseService.kt | 3 +- .../impl/AtomIndexTriggerCalServiceImpl.kt | 3 +- .../impl/StoreIndexPipelineServiceImpl.kt | 3 +- .../i18n/process/message_en_US.properties | 4 +- .../i18n/process/message_zh_CN.properties | 4 +- 15 files changed, 145 insertions(+), 59 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt index c005fcd6381..dc7bb8965c7 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt @@ -70,6 +70,12 @@ object WebhookI18nConstants { // openApi触发 const val SERVICE_START_EVENT_DESC = "bkServiceStartEventDesc" + // 流水线触发 + const val PIPELINE_START_EVENT_DESC = "bkPipelineStartEventDesc" + + // 定时触发 + const val TIMING_START_EVENT_DESC = "bkTimingStartEventDesc" + // 事件类型匹配 const val EVENT_TYPE_MATCHED = "bkRepoTriggerEventTypeMatched" diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt index 5e668490b1c..2ac277c9b68 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt @@ -142,7 +142,8 @@ class ApigwBuildResourceV3Impl @Autowired constructor( values = values ?: emptyMap(), buildNo = buildNo, channelCode = apiGatewayUtil.getChannelCode(), - startType = StartType.SERVICE + startType = StartType.SERVICE, + triggerEventSource = userId ) } diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt index 975e2a9b24c..a8858a6e2ae 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt @@ -179,7 +179,8 @@ class ApigwBuildResourceV4Impl @Autowired constructor( values = values ?: emptyMap(), buildNo = buildNo, channelCode = apiGatewayUtil.getChannelCode(), - startType = StartType.SERVICE + startType = StartType.SERVICE, + triggerEventSource = userId ) } diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceBuildResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceBuildResource.kt index b2228fad4ec..39bc52d2e33 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceBuildResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceBuildResource.kt @@ -806,7 +806,10 @@ interface ServiceBuildResource { buildNo: Int? = null, @ApiParam("启动类型", required = false) @QueryParam("startType") - startType: StartType + startType: StartType, + @ApiParam("触发事件源", required = false) + @QueryParam("triggerEventSource") + triggerEventSource: String? = "" ): Result @ApiOperation("取消并发起新构建") diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt index 6286c7d542e..0fc17f4235d 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt @@ -732,7 +732,8 @@ class ServiceBuildResourceImpl @Autowired constructor( values: Map, channelCode: ChannelCode, buildNo: Int?, - startType: StartType + startType: StartType, + triggerEventSource: String? ): Result { checkUserId(userId) checkParam(projectId, pipelineId) @@ -741,6 +742,7 @@ class ServiceBuildResourceImpl @Autowired constructor( pipelineId = pipelineId, requestParams = values, userId = userId!!, + eventSource = triggerEventSource ?: "", triggerType = PipelineTriggerType.SERVICE.name, startAction = { pipelineBuildFacadeService.buildManualStartup( diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt index 023de098865..de70276379f 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt @@ -101,6 +101,7 @@ class UserBuildResourceImpl @Autowired constructor( pipelineId = pipelineId, requestParams = values, userId = userId, + eventSource = userId, startAction = { pipelineBuildFacadeService.buildManualStartup( userId = userId, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt index cb2efe6f4ed..af624b03653 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt @@ -48,9 +48,7 @@ import com.tencent.devops.process.engine.control.lock.PipelineRemoteAuthLock import com.tencent.devops.process.engine.service.PipelineRepositoryService import com.tencent.devops.process.pojo.BuildId import com.tencent.devops.process.pojo.PipelineRemoteToken -import com.tencent.devops.process.pojo.trigger.PipelineTriggerType import com.tencent.devops.process.service.builds.PipelineBuildFacadeService -import com.tencent.devops.process.trigger.PipelineTriggerEventService import com.tencent.devops.process.utils.PIPELINE_START_REMOTE_USER_ID import com.tencent.devops.process.utils.PIPELINE_START_TASK_ID import org.jooq.DSLContext @@ -69,8 +67,7 @@ class PipelineRemoteAuthService @Autowired constructor( private val client: Client, private val bkTag: BkTag, private val buildLogPrinter: BuildLogPrinter, - private val buildVariableService: BuildVariableService, - private val pipelineTriggerEventService: PipelineTriggerEventService + private val buildVariableService: BuildVariableService ) { fun generateAuth(pipelineId: String, projectId: String, userId: String): PipelineRemoteToken { @@ -131,24 +128,16 @@ class PipelineRemoteAuthService @Autowired constructor( return bkTag.invokeByTag(projectConsulTag) { logger.info("start call service api ${pipeline.projectId} ${pipeline.pipelineId}, " + "$projectConsulTag ${bkTag.getFinalTag()}") - val buildId = pipelineTriggerEventService.saveSpecificEvent( + val buildId = client.getGateway(ServiceBuildResource::class).manualStartupNew( + userId = userId!!, projectId = pipeline.projectId, pipelineId = pipeline.pipelineId, - requestParams = vals.toMap(), - userId = userId!!, - triggerType = PipelineTriggerType.REMOTE.name, - startAction = { - client.getGateway(ServiceBuildResource::class).manualStartupNew( - userId = userId!!, - projectId = pipeline.projectId, - pipelineId = pipeline.pipelineId, - values = vals.toMap(), - channelCode = ChannelCode.BS, - startType = StartType.REMOTE, - buildNo = null - ).data!! - } - ) + values = vals.toMap(), + channelCode = ChannelCode.BS, + startType = StartType.REMOTE, + buildNo = null, + triggerEventSource = sourceIp + ).data!! // 在远程触发器job中打印sourcIp val taskId = buildVariableService.getVariable( projectId = pipeline.projectId, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt index a9f371c0adf..401f15fb5c4 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt @@ -29,8 +29,10 @@ package com.tencent.devops.process.service import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.api.exception.OperationException +import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.common.api.util.EnvUtils +import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.auth.api.AuthPermission import com.tencent.devops.common.pipeline.container.TriggerContainer import com.tencent.devops.common.pipeline.enums.BuildFormPropertyType @@ -42,6 +44,7 @@ import com.tencent.devops.common.pipeline.pojo.element.SubPipelineCallElement import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildAtomElement import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildLessAtomElement import com.tencent.devops.common.web.utils.I18nUtil +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_SUB_PIPELINE_NOT_ALLOWED_CIRCULAR_CALL import com.tencent.devops.process.engine.compatibility.BuildParametersCompatibilityTransformer @@ -54,8 +57,10 @@ import com.tencent.devops.process.pojo.pipeline.ProjectBuildId import com.tencent.devops.process.pojo.pipeline.StartUpInfo import com.tencent.devops.process.pojo.pipeline.SubPipelineStartUpInfo import com.tencent.devops.process.pojo.pipeline.SubPipelineStatus +import com.tencent.devops.process.pojo.trigger.PipelineTriggerType import com.tencent.devops.process.service.builds.PipelineBuildFacadeService import com.tencent.devops.process.service.pipeline.PipelineBuildService +import com.tencent.devops.process.trigger.PipelineTriggerEventService import com.tencent.devops.process.utils.PIPELINE_START_CHANNEL import com.tencent.devops.process.utils.PIPELINE_START_PARENT_BUILD_ID import com.tencent.devops.process.utils.PIPELINE_START_PARENT_BUILD_TASK_ID @@ -82,7 +87,8 @@ class SubPipelineStartUpService @Autowired constructor( private val subPipelineStatusService: SubPipelineStatusService, private val pipelineTaskService: PipelineTaskService, private val buildParamCompatibilityTransformer: BuildParametersCompatibilityTransformer, - private val pipelinePermissionService: PipelinePermissionService + private val pipelinePermissionService: PipelinePermissionService, + private val pipelineTriggerEventService: PipelineTriggerEventService ) { companion object { @@ -245,15 +251,36 @@ class SubPipelineStartUpService @Autowired constructor( checkPermission(userId = parentPipelineInfo.lastModifyUser, projectId = projectId, pipelineId = pipelineId) // 子流水线的调用不受频率限制 - val subBuildId = pipelineBuildService.startPipeline( - userId = readyToBuildPipelineInfo.lastModifyUser, - pipeline = readyToBuildPipelineInfo, - startType = StartType.PIPELINE, - pipelineParamMap = params, - channelCode = channelCode, - isMobile = isMobile, - model = model, - frequencyLimit = false + val subBuildId = pipelineTriggerEventService.saveSpecificEvent( + projectId = projectId, + pipelineId = pipelineId, + requestParams = parameters, + userId = userId!!, + eventSource = parentPipelineId, + eventDesc = JsonUtil.toJson( + I18Variable( + code = WebhookI18nConstants.PIPELINE_START_EVENT_DESC, + params = listOf( + userId, + "/console/pipeline/$parentProjectId/$parentPipelineId/detail/$parentBuildId", + parentPipelineInfo.pipelineName + ) + ), + false + ), + triggerType = PipelineTriggerType.PIPELINE.name, + startAction = { + pipelineBuildService.startPipeline( + userId = readyToBuildPipelineInfo.lastModifyUser, + pipeline = readyToBuildPipelineInfo, + startType = StartType.PIPELINE, + pipelineParamMap = params, + channelCode = channelCode, + isMobile = isMobile, + model = model, + frequencyLimit = false + ) + } ).id // 更新父流水线关联子流水线构建id pipelineTaskService.updateSubBuildId( diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt index b62b9a51f3e..35c9097d048 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt @@ -33,9 +33,11 @@ import com.tencent.devops.common.api.exception.ParamBlankException import com.tencent.devops.common.api.model.SQLPage import com.tencent.devops.common.api.pojo.BuildHistoryPage import com.tencent.devops.common.api.pojo.ErrorType +import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.pojo.IdValue import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.common.api.pojo.SimpleResult +import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.MessageUtil import com.tencent.devops.common.api.util.PageUtil import com.tencent.devops.common.auth.api.AuthPermission @@ -63,6 +65,7 @@ import com.tencent.devops.common.pipeline.utils.BuildStatusSwitcher import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.common.service.utils.HomeHostUtil import com.tencent.devops.common.web.utils.I18nUtil +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.constant.ProcessMessageCode.BK_BUILD_HISTORY import com.tencent.devops.process.constant.ProcessMessageCode.BK_BUILD_STATUS @@ -113,10 +116,12 @@ import com.tencent.devops.process.pojo.VmInfo import com.tencent.devops.process.pojo.pipeline.ModelDetail import com.tencent.devops.process.pojo.pipeline.ModelRecord import com.tencent.devops.process.pojo.pipeline.PipelineLatestBuild +import com.tencent.devops.process.pojo.trigger.PipelineTriggerType import com.tencent.devops.process.service.BuildVariableService import com.tencent.devops.process.service.ParamFacadeService import com.tencent.devops.process.service.PipelineTaskPauseService import com.tencent.devops.process.service.pipeline.PipelineBuildService +import com.tencent.devops.process.trigger.PipelineTriggerEventService import com.tencent.devops.process.util.TaskUtils import com.tencent.devops.process.utils.PIPELINE_BUILD_MSG import com.tencent.devops.process.utils.PIPELINE_NAME @@ -163,7 +168,8 @@ class PipelineBuildFacadeService( private val buildParamCompatibilityTransformer: BuildParametersCompatibilityTransformer, private val pipelineRedisService: PipelineRedisService, private val pipelineRetryFacadeService: PipelineRetryFacadeService, - private val webhookBuildParameterService: WebhookBuildParameterService + private val webhookBuildParameterService: WebhookBuildParameterService, + private val pipelineTriggerEventService: PipelineTriggerEventService ) { @Value("\${pipeline.build.cancel.intervalLimitTime:60}") @@ -696,16 +702,35 @@ class PipelineBuildFacadeService( val paramPamp = buildParamCompatibilityTransformer.parseTriggerParam(triggerContainer.params, parameters) - return pipelineBuildService.startPipeline( - userId = userId, - pipeline = pipeline, - startType = StartType.TIME_TRIGGER, - pipelineParamMap = paramPamp, - channelCode = pipeline.channelCode, - isMobile = false, - model = model, - signPipelineVersion = null, - frequencyLimit = false + return pipelineTriggerEventService.saveSpecificEvent( + projectId = projectId, + pipelineId = pipelineId, + requestParams = parameters, + userId = userId!!, + eventSource = pipeline.lastModifyUser, + eventDesc = JsonUtil.toJson( + I18Variable( + code = WebhookI18nConstants.TIMING_START_EVENT_DESC, + params = listOf( + pipeline.lastModifyUser + ) + ), + false + ), + triggerType = PipelineTriggerType.TIME_TRIGGER.name, + startAction = { + pipelineBuildService.startPipeline( + userId = userId, + pipeline = pipeline, + startType = StartType.TIME_TRIGGER, + pipelineParamMap = paramPamp, + channelCode = pipeline.channelCode, + isMobile = false, + model = model, + signPipelineVersion = null, + frequencyLimit = false + ) + } ).id } finally { logger.info("Timer| It take(${System.currentTimeMillis() - startEpoch})ms to start pipeline($pipelineId)") diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 871d9dc2061..c7e8071131c 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -37,12 +37,14 @@ import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.PageUtil import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.client.Client +import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.common.service.trace.TraceTag import com.tencent.devops.common.service.utils.HomeHostUtil import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.common.web.utils.I18nUtil.getCodeLanMessage import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.enums.WebhookI18nConstants.EVENT_REPLAY_DESC +import com.tencent.devops.process.api.service.ServicePipelineResource import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_TRIGGER_DETAIL_NOT_FOUND import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_TRIGGER_REPLAY_PIPELINE_NOT_EMPTY @@ -407,6 +409,8 @@ class PipelineTriggerEventService @Autowired constructor( projectId: String, pipelineId: String, userId: String, + eventSource: String, + eventDesc: String? = null, requestParams: Map?, triggerType: String = PipelineTriggerType.MANUAL.name, startAction: () -> BuildId @@ -414,6 +418,11 @@ class PipelineTriggerEventService @Autowired constructor( var buildNum: String? = null var status = PipelineTriggerStatus.SUCCEED.name var buildId: String? = null + val pipelineInfo = client.get(ServicePipelineResource::class).getPipelineInfo( + projectId = projectId, + pipelineId = pipelineId, + channelCode = ChannelCode.BS + ).data try { val buildInfo = startAction.invoke() buildNum = buildInfo.num.toString() @@ -426,6 +435,9 @@ class PipelineTriggerEventService @Autowired constructor( saveManualStartEvent( projectId = projectId, pipelineId = pipelineId, + pipelineName = pipelineInfo?.pipelineName ?: "", + eventSource = eventSource, + eventDesc = eventDesc, buildId = buildId, status = status, requestParams = requestParams, @@ -442,15 +454,30 @@ class PipelineTriggerEventService @Autowired constructor( private fun saveManualStartEvent( projectId: String, pipelineId: String, + pipelineName: String, + eventSource: String, buildId: String?, buildNum: String?, userId: String, status: String, triggerType: String, - requestParams: Map? + requestParams: Map?, + eventDesc: String? = null ) { val eventId = getEventId() val requestId = MDC.get(TraceTag.BIZID) + // 事件描述 + val targetEventDesc = if (eventDesc.isNullOrBlank()) { + JsonUtil.toJson( + I18Variable( + code = getI18Code(triggerType), + params = listOf(eventSource) + ), + false + ) + } else { + eventDesc + } saveEvent( triggerDetail = PipelineTriggerDetail( eventId = eventId, @@ -458,18 +485,14 @@ class PipelineTriggerEventService @Autowired constructor( projectId = projectId, pipelineId = pipelineId, buildId = buildId, - buildNum = buildNum + buildNum = buildNum, + pipelineName = pipelineName ), triggerEvent = PipelineTriggerEvent( eventId = eventId, projectId = projectId, - eventDesc = JsonUtil.toJson( - I18Variable( - code = getI18Code(triggerType), - params = listOf(userId) - ), - false - ), + eventDesc = targetEventDesc, + eventSource = eventSource, triggerType = triggerType, eventType = triggerType, triggerUser = userId, @@ -484,6 +507,7 @@ class PipelineTriggerEventService @Autowired constructor( PipelineTriggerType.MANUAL.name -> WebhookI18nConstants.MANUAL_START_EVENT_DESC PipelineTriggerType.REMOTE.name -> WebhookI18nConstants.REMOTE_START_EVENT_DESC PipelineTriggerType.SERVICE.name -> WebhookI18nConstants.SERVICE_START_EVENT_DESC + PipelineTriggerType.PIPELINE.name -> WebhookI18nConstants.PIPELINE_START_EVENT_DESC else -> "" } diff --git a/src/backend/ci/core/store/biz-store-image/src/main/kotlin/com/tencent/devops/store/service/image/ImageReleaseService.kt b/src/backend/ci/core/store/biz-store-image/src/main/kotlin/com/tencent/devops/store/service/image/ImageReleaseService.kt index 6ada8ad3c09..f800008e8bb 100644 --- a/src/backend/ci/core/store/biz-store-image/src/main/kotlin/com/tencent/devops/store/service/image/ImageReleaseService.kt +++ b/src/backend/ci/core/store/biz-store-image/src/main/kotlin/com/tencent/devops/store/service/image/ImageReleaseService.kt @@ -720,7 +720,8 @@ abstract class ImageReleaseService { pipelineId = imagePipelineRelRecord.pipelineId, values = startParams, channelCode = ChannelCode.AM, - startType = StartType.SERVICE + startType = StartType.SERVICE, + triggerEventSource = userId ).data logger.info("the buildIdObj is:$buildIdObj") if (null != buildIdObj) { diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/atom/impl/AtomIndexTriggerCalServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/atom/impl/AtomIndexTriggerCalServiceImpl.kt index 5d1c3044977..37781cb589b 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/atom/impl/AtomIndexTriggerCalServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/atom/impl/AtomIndexTriggerCalServiceImpl.kt @@ -142,7 +142,8 @@ class AtomIndexTriggerCalServiceImpl @Autowired constructor( pipelineId = pipelineId, values = mapOf(KEY_INDEX_CODE to indexCode), channelCode = ChannelCode.AM, - startType = StartType.SERVICE + startType = StartType.SERVICE, + triggerEventSource = userId ) } } diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/common/impl/StoreIndexPipelineServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/common/impl/StoreIndexPipelineServiceImpl.kt index 8f282e39677..633f29e2d93 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/common/impl/StoreIndexPipelineServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/common/impl/StoreIndexPipelineServiceImpl.kt @@ -170,7 +170,8 @@ class StoreIndexPipelineServiceImpl @Autowired constructor( pipelineId = pipelineId, values = mapOf(KEY_INDEX_CODE to storeIndexPipelineInitRequest.indexCode), channelCode = ChannelCode.AM, - startType = StartType.SERVICE + startType = StartType.SERVICE, + triggerEventSource = userId ) logger.info("manualStartupNew result is:$buildId") } diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index 2255afaa2d2..f50d96e610a 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -385,7 +385,9 @@ bkP4EventDesc=Change [{0}] by {1} {2} bkSvnCommitEventDesc=Commit [{0}] pushed by {1} bkManualStartEventDesc=Manually triggered by {0} bkRemoteStartEventDesc=Remote api triggered by {0} -bkServiceStartEventDesc={0} Pipeline invocation triggered by [{2}] invoke +bkServiceStartEventDesc=Pipeline invocation triggered by {0} invoke +bkPipelinetartEventDesc=Pipeline invocation [!{2}] triggered by {0} invoke +bkTimingStartEventDesc=Timer triggered by {0} bkEventReplayDesc=Event [{0}] replayed by {1} bkRepoTriggerEventTypeNotMatch=Event type mismatch bkRepoTriggerTargetBranchNotMatch=Target branch [{0}] of merge request does not match diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index ecfd9829190..93b314077a5 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -385,7 +385,9 @@ bkP4EventDesc=Change {0} 由 {1} {2} bkSvnCommitEventDesc=提交 [{0}] 由 {1} 推送 bkManualStartEventDesc={0} 手动触发 bkRemoteStartEventDesc={0} 远程触发 -bkServiceStartEventDesc={0} 触发的流水线 [{2}] 调用 +bkServiceStartEventDesc={0} 触发的流水线调用 +bkPipelinetartEventDesc={0} 触发的流水线[!{2}]调用 +bkTimingStartEventDesc={0} 定时触发 bkEventReplayDesc=事件 [{0}] 由 {1} 重放 bkRepoTriggerEventTypeNotMatch=事件类型不满足触发条件 bkRepoTriggerTargetBranchNotMatch=MR目标分支[{0}]不满足触发条件 From 953a5a19ec0cdb119b1313dfc1b971a9c489f868 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 13 Nov 2023 15:10:07 +0800 Subject: [PATCH 114/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- support-files/i18n/process/message_en_US.properties | 2 +- support-files/i18n/process/message_zh_CN.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index f50d96e610a..7a5118afca4 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -386,7 +386,7 @@ bkSvnCommitEventDesc=Commit [{0}] pushed by {1}{0} bkRemoteStartEventDesc=Remote api triggered by {0} bkServiceStartEventDesc=Pipeline invocation triggered by {0} invoke -bkPipelinetartEventDesc=Pipeline invocation [!{2}] triggered by {0} invoke +bkPipelinetartEventDesc=Pipeline invocation [{2}] triggered by {0} invoke bkTimingStartEventDesc=Timer triggered by {0} bkEventReplayDesc=Event [{0}] replayed by {1} bkRepoTriggerEventTypeNotMatch=Event type mismatch diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 93b314077a5..83e5a933a07 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -386,7 +386,7 @@ bkSvnCommitEventDesc=提交 [{0}] 由 {1} bkManualStartEventDesc={0} 手动触发 bkRemoteStartEventDesc={0} 远程触发 bkServiceStartEventDesc={0} 触发的流水线调用 -bkPipelinetartEventDesc={0} 触发的流水线[!{2}]调用 +bkPipelinetartEventDesc={0} 触发的流水线 [{2}] 调用 bkTimingStartEventDesc={0} 定时触发 bkEventReplayDesc=事件 [{0}] 由 {1} 重放 bkRepoTriggerEventTypeNotMatch=事件类型不满足触发条件 From bc30ba6625721cfd4e5030d87ab9832e9d979e0f Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 14 Nov 2023 11:15:59 +0800 Subject: [PATCH 115/143] =?UTF-8?q?feat=EF=BC=9A=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4=E5=BA=A6=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3=E7=A0=81=E5=BA=93?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apigw/v3/ApigwBuildResourceV3Impl.kt | 39 +++++++- .../apigw/v4/ApigwBuildResourceV4Impl.kt | 39 +++++++- .../api/service/ServiceBuildResource.kt | 5 +- .../service/ServiceTriggerEventResource.kt | 53 ++++++++++ .../pojo/trigger/PipelineSpecificEvent.kt | 52 ++++++++++ .../process/api/ServiceBuildResourceImpl.kt | 21 +--- .../api/ServiceTriggerEventResourceImpl.kt | 57 +++++++++++ .../process/api/UserBuildResourceImpl.kt | 65 ++++++++---- .../service/PipelineRemoteAuthService.kt | 39 +++++++- .../service/SubPipelineStartUpService.kt | 99 ++++++++++++------- .../builds/PipelineBuildFacadeService.kt | 79 ++++++++------- .../trigger/PipelineTriggerEventService.kt | 46 ++++----- .../service/image/ImageReleaseService.kt | 3 +- .../impl/AtomIndexTriggerCalServiceImpl.kt | 3 +- .../impl/StoreIndexPipelineServiceImpl.kt | 3 +- 15 files changed, 451 insertions(+), 152 deletions(-) create mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceTriggerEventResource.kt create mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineSpecificEvent.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt index 2ac277c9b68..46c80d0f787 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt @@ -35,12 +35,14 @@ import com.tencent.devops.common.web.RestResource import com.tencent.devops.openapi.api.apigw.v3.ApigwBuildResourceV3 import com.tencent.devops.openapi.utils.ApiGatewayUtil import com.tencent.devops.process.api.service.ServiceBuildResource +import com.tencent.devops.process.api.service.ServiceTriggerEventResource import com.tencent.devops.process.pojo.BuildHistory import com.tencent.devops.process.pojo.BuildHistoryWithVars import com.tencent.devops.process.pojo.BuildId import com.tencent.devops.process.pojo.BuildManualStartupInfo import com.tencent.devops.process.pojo.BuildTaskPauseInfo import com.tencent.devops.process.pojo.pipeline.ModelDetail +import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -135,16 +137,23 @@ class ApigwBuildResourceV3Impl @Autowired constructor( buildNo: Int? ): Result { logger.info("OPENAPI_BUILD_V3|$userId|start|$projectId|$pipelineId|$values|$buildNo") - return client.get(ServiceBuildResource::class).manualStartupNew( + val buildId = client.get(ServiceBuildResource::class).manualStartupNew( userId = userId, projectId = projectId, pipelineId = pipelineId, values = values ?: emptyMap(), buildNo = buildNo, channelCode = apiGatewayUtil.getChannelCode(), - startType = StartType.SERVICE, - triggerEventSource = userId + startType = StartType.SERVICE ) + saveTriggerEvent( + userId = userId, + projectId = projectId, + pipelineId = pipelineId, + values = values, + buildId = buildId.data + ) + return buildId } override fun stop( @@ -283,6 +292,30 @@ class ApigwBuildResourceV3Impl @Autowired constructor( ) } + private fun saveTriggerEvent( + userId: String, + projectId: String, + pipelineId: String, + values: Map?, + buildId: BuildId? + ) { + try { + client.get(ServiceTriggerEventResource::class).saveSpecificEvent( + specificEvent = PipelineSpecificEvent( + projectId = projectId, + pipelineId = pipelineId, + requestParams = values, + userId = userId, + eventSource = userId, + triggerType = StartType.SERVICE.name, + buildInfo = buildId + ) + ) + } catch (ignored: Exception) { + logger.warn("OPENAPI_BUILD_V3|fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) + } + } + companion object { private val logger = LoggerFactory.getLogger(ApigwBuildResourceV3Impl::class.java) } diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt index a8858a6e2ae..1ffbcf150a7 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt @@ -41,6 +41,7 @@ import com.tencent.devops.openapi.api.apigw.v4.ApigwBuildResourceV4 import com.tencent.devops.openapi.service.IndexService import com.tencent.devops.openapi.utils.ApiGatewayUtil import com.tencent.devops.process.api.service.ServiceBuildResource +import com.tencent.devops.process.api.service.ServiceTriggerEventResource import com.tencent.devops.process.pojo.BuildHistory import com.tencent.devops.process.pojo.BuildHistoryRemark import com.tencent.devops.process.pojo.BuildHistoryWithVars @@ -49,6 +50,7 @@ import com.tencent.devops.process.pojo.BuildManualStartupInfo import com.tencent.devops.process.pojo.BuildTaskPauseInfo import com.tencent.devops.process.pojo.ReviewParam import com.tencent.devops.process.pojo.pipeline.ModelRecord +import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -172,16 +174,23 @@ class ApigwBuildResourceV4Impl @Autowired constructor( buildNo: Int? ): Result { logger.info("OPENAPI_BUILD_V4|$userId|start|$projectId|$pipelineId|$values|$buildNo") - return client.get(ServiceBuildResource::class).manualStartupNew( + val buildId = client.get(ServiceBuildResource::class).manualStartupNew( userId = userId, projectId = projectId, pipelineId = pipelineId, values = values ?: emptyMap(), buildNo = buildNo, channelCode = apiGatewayUtil.getChannelCode(), - startType = StartType.SERVICE, - triggerEventSource = userId + startType = StartType.SERVICE ) + saveTriggerEvent( + userId = userId, + projectId = projectId, + pipelineId = pipelineId, + values = values, + buildId = buildId.data + ) + return buildId } override fun stop( @@ -429,6 +438,30 @@ class ApigwBuildResourceV4Impl @Autowired constructor( ?: throw ParamBlankException("Invalid buildNumber") } + private fun saveTriggerEvent( + userId: String, + projectId: String, + pipelineId: String, + values: Map?, + buildId: BuildId? + ) { + try { + client.get(ServiceTriggerEventResource::class).saveSpecificEvent( + specificEvent = PipelineSpecificEvent( + projectId = projectId, + pipelineId = pipelineId, + requestParams = values, + userId = userId, + eventSource = userId, + triggerType = StartType.SERVICE.name, + buildInfo = buildId + ) + ) + } catch (ignored: Exception) { + logger.warn("OPENAPI_BUILD_V4|fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) + } + } + companion object { private val logger = LoggerFactory.getLogger(ApigwBuildResourceV4Impl::class.java) } diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceBuildResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceBuildResource.kt index 39bc52d2e33..b2228fad4ec 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceBuildResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceBuildResource.kt @@ -806,10 +806,7 @@ interface ServiceBuildResource { buildNo: Int? = null, @ApiParam("启动类型", required = false) @QueryParam("startType") - startType: StartType, - @ApiParam("触发事件源", required = false) - @QueryParam("triggerEventSource") - triggerEventSource: String? = "" + startType: StartType ): Result @ApiOperation("取消并发起新构建") diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceTriggerEventResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceTriggerEventResource.kt new file mode 100644 index 00000000000..20a43ee77b4 --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceTriggerEventResource.kt @@ -0,0 +1,53 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.devops.process.api.service + +import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent +import io.swagger.annotations.Api +import io.swagger.annotations.ApiOperation +import io.swagger.annotations.ApiParam +import javax.ws.rs.Consumes +import javax.ws.rs.POST +import javax.ws.rs.Path +import javax.ws.rs.Produces +import javax.ws.rs.core.MediaType + +@Api(tags = ["SERVICE_TRIGGER_EVENT"], description = "服务-触发事件") +@Path("/service/trigger/event") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +interface ServiceTriggerEventResource { + + @ApiOperation("保存特殊触发事件") + @Path("projects/{projectId}/{pipelineId}/saveSpecificEvent") + @POST + fun saveSpecificEvent( + @ApiParam("触发参数", required = true) + specificEvent: PipelineSpecificEvent + ): Boolean +} diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineSpecificEvent.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineSpecificEvent.kt new file mode 100644 index 00000000000..2b64e705207 --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineSpecificEvent.kt @@ -0,0 +1,52 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +package com.tencent.devops.process.pojo.trigger + +import com.tencent.devops.process.pojo.BuildId +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty + +@ApiModel("流水线特殊触发事件") +data class PipelineSpecificEvent( + @ApiModelProperty("项目Id") + val projectId: String, + @ApiModelProperty("流水线Id") + val pipelineId: String, + @ApiModelProperty("用户信息") + val userId: String, + @ApiModelProperty("事件源") + val eventSource: String, + @ApiModelProperty("事件描述") + val eventDesc: String? = null, + @ApiModelProperty("请求参数") + val requestParams: Map?, + @ApiModelProperty("触发类型") + val triggerType: String = PipelineTriggerType.MANUAL.name, + @ApiModelProperty("构建信息") + val buildInfo: BuildId? +) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt index 0fc17f4235d..a4fdf1aeb71 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceBuildResourceImpl.kt @@ -41,7 +41,6 @@ import com.tencent.devops.common.pipeline.pojo.StageReviewRequest import com.tencent.devops.common.web.RestResource import com.tencent.devops.process.api.service.ServiceBuildResource import com.tencent.devops.process.engine.service.PipelineBuildDetailService -import com.tencent.devops.process.engine.service.PipelineContainerService import com.tencent.devops.process.engine.service.PipelineRuntimeService import com.tencent.devops.process.engine.service.vmbuild.EngineVMBuildService import com.tencent.devops.process.pojo.BuildBasicInfo @@ -58,11 +57,9 @@ import com.tencent.devops.process.pojo.VmInfo import com.tencent.devops.process.pojo.pipeline.ModelDetail import com.tencent.devops.process.pojo.pipeline.ModelRecord import com.tencent.devops.process.pojo.pipeline.PipelineLatestBuild -import com.tencent.devops.process.pojo.trigger.PipelineTriggerType import com.tencent.devops.process.service.builds.PipelineBuildFacadeService import com.tencent.devops.process.service.builds.PipelineBuildMaintainFacadeService import com.tencent.devops.process.service.builds.PipelinePauseBuildFacadeService -import com.tencent.devops.process.trigger.PipelineTriggerEventService import org.springframework.beans.factory.annotation.Autowired @Suppress("ALL") @@ -73,9 +70,7 @@ class ServiceBuildResourceImpl @Autowired constructor( private val engineVMBuildService: EngineVMBuildService, private val pipelineBuildDetailService: PipelineBuildDetailService, private val pipelinePauseBuildFacadeService: PipelinePauseBuildFacadeService, - private val pipelineRuntimeService: PipelineRuntimeService, - private val pipelineContainerService: PipelineContainerService, - private val pipelineTriggerEventService: PipelineTriggerEventService + private val pipelineRuntimeService: PipelineRuntimeService ) : ServiceBuildResource { override fun getPipelineIdFromBuildId(projectId: String, buildId: String): Result { if (buildId.isBlank()) { @@ -732,19 +727,11 @@ class ServiceBuildResourceImpl @Autowired constructor( values: Map, channelCode: ChannelCode, buildNo: Int?, - startType: StartType, - triggerEventSource: String? + startType: StartType ): Result { checkUserId(userId) checkParam(projectId, pipelineId) - val buildId = pipelineTriggerEventService.saveSpecificEvent( - projectId = projectId, - pipelineId = pipelineId, - requestParams = values, - userId = userId!!, - eventSource = triggerEventSource ?: "", - triggerType = PipelineTriggerType.SERVICE.name, - startAction = { + return Result( pipelineBuildFacadeService.buildManualStartup( userId = userId, startType = startType, @@ -756,9 +743,7 @@ class ServiceBuildResourceImpl @Autowired constructor( checkPermission = ChannelCode.isNeedAuth(channelCode), frequencyLimit = true ) - } ) - return Result(buildId) } override fun buildRestart(userId: String, projectId: String, pipelineId: String, buildId: String): Result { diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt new file mode 100644 index 00000000000..f18c4fc647f --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt @@ -0,0 +1,57 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.devops.process.api + +import com.tencent.devops.common.web.RestResource +import com.tencent.devops.process.api.service.ServiceTriggerEventResource +import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerType +import com.tencent.devops.process.trigger.PipelineTriggerEventService +import org.springframework.beans.factory.annotation.Autowired + +@Suppress("ALL") +@RestResource +class ServiceTriggerEventResourceImpl @Autowired constructor( + private val pipelineTriggerEventService: PipelineTriggerEventService +) : ServiceTriggerEventResource { + override fun saveSpecificEvent(specificEvent: PipelineSpecificEvent): Boolean { + with(specificEvent) { + pipelineTriggerEventService.saveSpecificEvent( + projectId = projectId, + pipelineId = pipelineId, + requestParams = requestParams, + userId = userId, + eventSource = eventSource, + eventDesc = eventDesc, + triggerType = PipelineTriggerType.PIPELINE.name, + buildInfo = buildInfo + ) + } + return true + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt index de70276379f..a72fac05145 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt @@ -31,6 +31,7 @@ import com.tencent.devops.common.api.exception.ParamBlankException import com.tencent.devops.common.api.pojo.BuildHistoryPage import com.tencent.devops.common.api.pojo.IdValue import com.tencent.devops.common.api.pojo.Result +import com.tencent.devops.common.client.Client import com.tencent.devops.common.pipeline.enums.BuildStatus import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.common.pipeline.enums.StartType @@ -38,6 +39,7 @@ import com.tencent.devops.common.pipeline.pojo.BuildParameters import com.tencent.devops.common.pipeline.pojo.StageReviewRequest import com.tencent.devops.common.pipeline.pojo.element.Element import com.tencent.devops.common.web.RestResource +import com.tencent.devops.process.api.service.ServiceTriggerEventResource import com.tencent.devops.process.api.user.UserBuildResource import com.tencent.devops.process.pojo.BuildHistory import com.tencent.devops.process.pojo.BuildHistoryRemark @@ -46,12 +48,13 @@ import com.tencent.devops.process.pojo.BuildManualStartupInfo import com.tencent.devops.process.pojo.ReviewParam import com.tencent.devops.process.pojo.pipeline.ModelDetail import com.tencent.devops.process.pojo.pipeline.ModelRecord +import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent import com.tencent.devops.process.service.PipelineRecentUseService import com.tencent.devops.process.service.builds.PipelineBuildFacadeService import com.tencent.devops.process.service.builds.PipelineBuildMaintainFacadeService import com.tencent.devops.process.service.builds.PipelinePauseBuildFacadeService -import com.tencent.devops.process.trigger.PipelineTriggerEventService import io.micrometer.core.annotation.Timed +import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import javax.ws.rs.core.Response @@ -62,7 +65,7 @@ class UserBuildResourceImpl @Autowired constructor( private val pipelineBuildFacadeService: PipelineBuildFacadeService, private val pipelinePauseBuildFacadeService: PipelinePauseBuildFacadeService, private val pipelineRecentUseService: PipelineRecentUseService, - private val pipelineTriggerEventService: PipelineTriggerEventService + private val client: Client ) : UserBuildResource { override fun manualStartupInfo( @@ -96,26 +99,24 @@ class UserBuildResourceImpl @Autowired constructor( triggerReviewers: List? ): Result { checkParam(userId, projectId, pipelineId) - val manualStartup = pipelineTriggerEventService.saveSpecificEvent( + val manualStartup = pipelineBuildFacadeService.buildManualStartup( + userId = userId, + startType = StartType.MANUAL, projectId = projectId, pipelineId = pipelineId, - requestParams = values, - userId = userId, - eventSource = userId, - startAction = { - pipelineBuildFacadeService.buildManualStartup( - userId = userId, - startType = StartType.MANUAL, - projectId = projectId, - pipelineId = pipelineId, - values = values, - channelCode = ChannelCode.BS, - buildNo = buildNo, - triggerReviewers = triggerReviewers - ) - } + values = values, + channelCode = ChannelCode.BS, + buildNo = buildNo, + triggerReviewers = triggerReviewers ) pipelineRecentUseService.record(userId, projectId, pipelineId) + saveTriggerEvent( + userId = userId, + projectId = projectId, + pipelineId = pipelineId, + values = values, + buildId = manualStartup + ) return Result(manualStartup) } @@ -546,4 +547,32 @@ class UserBuildResourceImpl @Autowired constructor( throw ParamBlankException("Invalid projectId") } } + + private fun saveTriggerEvent( + userId: String, + projectId: String, + pipelineId: String, + values: Map?, + buildId: BuildId? + ) { + try { + client.get(ServiceTriggerEventResource::class).saveSpecificEvent( + specificEvent = PipelineSpecificEvent( + projectId = projectId, + pipelineId = pipelineId, + requestParams = values, + userId = userId, + eventSource = userId, + triggerType = StartType.MANUAL.name, + buildInfo = buildId + ) + ) + } catch (ignored: Exception) { + logger.warn("fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) + } + } + + companion object{ + private val logger = LoggerFactory.getLogger(UserBuildResourceImpl::class.java) + } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt index af624b03653..089fffd70df 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt @@ -40,6 +40,7 @@ import com.tencent.devops.common.service.BkTag import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.model.process.tables.records.TPipelineRemoteAuthRecord import com.tencent.devops.process.api.service.ServiceBuildResource +import com.tencent.devops.process.api.service.ServiceTriggerEventResource import com.tencent.devops.process.constant.ProcessMessageCode.BK_REMOTE_CALL_SOURCE_IP import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_GENERATE_REMOTE_TRIGGER_TOKEN_FAILED import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_NO_MATCHING_PIPELINE @@ -48,6 +49,7 @@ import com.tencent.devops.process.engine.control.lock.PipelineRemoteAuthLock import com.tencent.devops.process.engine.service.PipelineRepositoryService import com.tencent.devops.process.pojo.BuildId import com.tencent.devops.process.pojo.PipelineRemoteToken +import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent import com.tencent.devops.process.service.builds.PipelineBuildFacadeService import com.tencent.devops.process.utils.PIPELINE_START_REMOTE_USER_ID import com.tencent.devops.process.utils.PIPELINE_START_TASK_ID @@ -119,7 +121,6 @@ class PipelineRemoteAuthService @Autowired constructor( if (!startUser.isNullOrBlank()) { vals[PIPELINE_START_REMOTE_USER_ID] = startUser } - logger.info("Start the pipeline remotely of $userId ${pipeline.pipelineId} of project ${pipeline.projectId}") // #5779 为兼容多集群的场景。流水线的启动需要路由到项目对应的集群。此处携带X-DEVOPS-PROJECT-ID头重新请求网关,由网关路由到项目对应的集群 /* #7095 因Bktag设置了router_tag 默认为本集群,导致网关不会根据X-DEVOPS-PROJECT-ID路由。故直接根据项目获取router @@ -135,9 +136,16 @@ class PipelineRemoteAuthService @Autowired constructor( values = vals.toMap(), channelCode = ChannelCode.BS, startType = StartType.REMOTE, - buildNo = null, - triggerEventSource = sourceIp + buildNo = null ).data!! + saveTriggerEvent( + userId = userId, + projectId = pipeline.projectId, + pipelineId = pipeline.pipelineId, + eventSource = sourceIp ?: "", + values = vals.toMap(), + buildId = buildId + ) // 在远程触发器job中打印sourcIp val taskId = buildVariableService.getVariable( projectId = pipeline.projectId, @@ -167,6 +175,31 @@ class PipelineRemoteAuthService @Autowired constructor( } } + private fun saveTriggerEvent( + userId: String, + eventSource: String, + projectId: String, + pipelineId: String, + values: Map?, + buildId: BuildId? + ) { + try { + client.get(ServiceTriggerEventResource::class).saveSpecificEvent( + specificEvent = PipelineSpecificEvent( + projectId = projectId, + pipelineId = pipelineId, + requestParams = values, + userId = userId, + eventSource = eventSource, + triggerType = StartType.REMOTE.name, + buildInfo = buildId + ) + ) + } catch (ignored: Exception) { + logger.warn("fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) + } + } + companion object { private val logger = LoggerFactory.getLogger(PipelineRemoteAuthService::class.java) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt index 401f15fb5c4..e5181fd5a9c 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt @@ -34,6 +34,7 @@ import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.common.api.util.EnvUtils import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.auth.api.AuthPermission +import com.tencent.devops.common.client.Client import com.tencent.devops.common.pipeline.container.TriggerContainer import com.tencent.devops.common.pipeline.enums.BuildFormPropertyType import com.tencent.devops.common.pipeline.enums.ChannelCode @@ -45,6 +46,7 @@ import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildAtomEle import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildLessAtomElement import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.common.webhook.enums.WebhookI18nConstants +import com.tencent.devops.process.api.service.ServiceTriggerEventResource import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_SUB_PIPELINE_NOT_ALLOWED_CIRCULAR_CALL import com.tencent.devops.process.engine.compatibility.BuildParametersCompatibilityTransformer @@ -52,12 +54,13 @@ import com.tencent.devops.process.engine.service.PipelineRepositoryService import com.tencent.devops.process.engine.service.PipelineRuntimeService import com.tencent.devops.process.engine.service.PipelineTaskService import com.tencent.devops.process.permission.PipelinePermissionService +import com.tencent.devops.process.pojo.BuildId import com.tencent.devops.process.pojo.PipelineId import com.tencent.devops.process.pojo.pipeline.ProjectBuildId import com.tencent.devops.process.pojo.pipeline.StartUpInfo import com.tencent.devops.process.pojo.pipeline.SubPipelineStartUpInfo import com.tencent.devops.process.pojo.pipeline.SubPipelineStatus -import com.tencent.devops.process.pojo.trigger.PipelineTriggerType +import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent import com.tencent.devops.process.service.builds.PipelineBuildFacadeService import com.tencent.devops.process.service.pipeline.PipelineBuildService import com.tencent.devops.process.trigger.PipelineTriggerEventService @@ -88,7 +91,7 @@ class SubPipelineStartUpService @Autowired constructor( private val pipelineTaskService: PipelineTaskService, private val buildParamCompatibilityTransformer: BuildParametersCompatibilityTransformer, private val pipelinePermissionService: PipelinePermissionService, - private val pipelineTriggerEventService: PipelineTriggerEventService + private val client: Client ) { companion object { @@ -249,48 +252,37 @@ class SubPipelineStartUpService @Autowired constructor( } // 校验父流水线最后修改人是否有子流水线执行权限 checkPermission(userId = parentPipelineInfo.lastModifyUser, projectId = projectId, pipelineId = pipelineId) - // 子流水线的调用不受频率限制 - val subBuildId = pipelineTriggerEventService.saveSpecificEvent( + val subBuildId = pipelineBuildService.startPipeline( + userId = readyToBuildPipelineInfo.lastModifyUser, + pipeline = readyToBuildPipelineInfo, + startType = StartType.PIPELINE, + pipelineParamMap = params, + channelCode = channelCode, + isMobile = isMobile, + model = model, + frequencyLimit = false + ) + saveTriggerEvent( + userId = userId, projectId = projectId, pipelineId = pipelineId, - requestParams = parameters, - userId = userId!!, - eventSource = parentPipelineId, - eventDesc = JsonUtil.toJson( - I18Variable( - code = WebhookI18nConstants.PIPELINE_START_EVENT_DESC, - params = listOf( - userId, - "/console/pipeline/$parentProjectId/$parentPipelineId/detail/$parentBuildId", - parentPipelineInfo.pipelineName - ) - ), - false - ), - triggerType = PipelineTriggerType.PIPELINE.name, - startAction = { - pipelineBuildService.startPipeline( - userId = readyToBuildPipelineInfo.lastModifyUser, - pipeline = readyToBuildPipelineInfo, - startType = StartType.PIPELINE, - pipelineParamMap = params, - channelCode = channelCode, - isMobile = isMobile, - model = model, - frequencyLimit = false - ) - } - ).id + values = params.mapValues { it.value.value.toString() }, + buildId = subBuildId, + parentProjectId = parentProjectId, + parentPipelineId = parentPipelineId, + parentBuildId = parentBuildId, + parentPipelineName = parentPipelineInfo.pipelineName + ) // 更新父流水线关联子流水线构建id pipelineTaskService.updateSubBuildId( projectId = parentProjectId, buildId = parentBuildId, taskId = parentTaskId, - subBuildId = subBuildId, + subBuildId = subBuildId.id, subProjectId = readyToBuildPipelineInfo.projectId ) - return subBuildId + return subBuildId.id } finally { logger.info("It take(${System.currentTimeMillis() - startEpoch})ms to start sub-pipeline($pipelineId)") } @@ -513,4 +505,43 @@ class SubPipelineStartUpService @Autowired constructor( fun getSubPipelineStatus(projectId: String, buildId: String): Result { return Result(subPipelineStatusService.getSubPipelineStatus(projectId, buildId)) } + + private fun saveTriggerEvent( + userId: String, + projectId: String, + pipelineId: String, + values: Map?, + buildId: BuildId?, + parentProjectId: String, + parentPipelineId: String, + parentBuildId: String, + parentPipelineName: String + ) { + try { + client.get(ServiceTriggerEventResource::class).saveSpecificEvent( + specificEvent = PipelineSpecificEvent( + projectId = projectId, + pipelineId = pipelineId, + requestParams = values, + userId = userId, + eventSource = parentPipelineId, + triggerType = StartType.PIPELINE.name, + buildInfo = buildId, + eventDesc = JsonUtil.toJson( + I18Variable( + code = WebhookI18nConstants.PIPELINE_START_EVENT_DESC, + params = listOf( + userId, + "/console/pipeline/$parentProjectId/$parentPipelineId/detail/$parentBuildId", + parentPipelineName + ) + ), + false + ) + ) + ) + } catch (ignored: Exception) { + logger.warn("OPENAPI_BUILD_V4|fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) + } + } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt index 35c9097d048..b4ebc2510e4 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt @@ -33,14 +33,13 @@ import com.tencent.devops.common.api.exception.ParamBlankException import com.tencent.devops.common.api.model.SQLPage import com.tencent.devops.common.api.pojo.BuildHistoryPage import com.tencent.devops.common.api.pojo.ErrorType -import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.pojo.IdValue import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.common.api.pojo.SimpleResult -import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.MessageUtil import com.tencent.devops.common.api.util.PageUtil import com.tencent.devops.common.auth.api.AuthPermission +import com.tencent.devops.common.client.Client import com.tencent.devops.common.event.dispatcher.pipeline.PipelineEventDispatcher import com.tencent.devops.common.event.enums.ActionType import com.tencent.devops.common.log.pojo.message.LogMessage @@ -65,7 +64,7 @@ import com.tencent.devops.common.pipeline.utils.BuildStatusSwitcher import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.common.service.utils.HomeHostUtil import com.tencent.devops.common.web.utils.I18nUtil -import com.tencent.devops.common.webhook.enums.WebhookI18nConstants +import com.tencent.devops.process.api.service.ServiceTriggerEventResource import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.constant.ProcessMessageCode.BK_BUILD_HISTORY import com.tencent.devops.process.constant.ProcessMessageCode.BK_BUILD_STATUS @@ -116,7 +115,7 @@ import com.tencent.devops.process.pojo.VmInfo import com.tencent.devops.process.pojo.pipeline.ModelDetail import com.tencent.devops.process.pojo.pipeline.ModelRecord import com.tencent.devops.process.pojo.pipeline.PipelineLatestBuild -import com.tencent.devops.process.pojo.trigger.PipelineTriggerType +import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent import com.tencent.devops.process.service.BuildVariableService import com.tencent.devops.process.service.ParamFacadeService import com.tencent.devops.process.service.PipelineTaskPauseService @@ -169,7 +168,7 @@ class PipelineBuildFacadeService( private val pipelineRedisService: PipelineRedisService, private val pipelineRetryFacadeService: PipelineRetryFacadeService, private val webhookBuildParameterService: WebhookBuildParameterService, - private val pipelineTriggerEventService: PipelineTriggerEventService + private val client: Client ) { @Value("\${pipeline.build.cancel.intervalLimitTime:60}") @@ -701,37 +700,25 @@ class PipelineBuildFacadeService( val triggerContainer = model.stages[0].containers[0] as TriggerContainer val paramPamp = buildParamCompatibilityTransformer.parseTriggerParam(triggerContainer.params, parameters) - - return pipelineTriggerEventService.saveSpecificEvent( + val buildId = pipelineBuildService.startPipeline( + userId = userId, + pipeline = pipeline, + startType = StartType.TIME_TRIGGER, + pipelineParamMap = paramPamp, + channelCode = pipeline.channelCode, + isMobile = false, + model = model, + signPipelineVersion = null, + frequencyLimit = false + ) + saveTriggerEvent( + userId = userId, projectId = projectId, pipelineId = pipelineId, - requestParams = parameters, - userId = userId!!, - eventSource = pipeline.lastModifyUser, - eventDesc = JsonUtil.toJson( - I18Variable( - code = WebhookI18nConstants.TIMING_START_EVENT_DESC, - params = listOf( - pipeline.lastModifyUser - ) - ), - false - ), - triggerType = PipelineTriggerType.TIME_TRIGGER.name, - startAction = { - pipelineBuildService.startPipeline( - userId = userId, - pipeline = pipeline, - startType = StartType.TIME_TRIGGER, - pipelineParamMap = paramPamp, - channelCode = pipeline.channelCode, - isMobile = false, - model = model, - signPipelineVersion = null, - frequencyLimit = false - ) - } - ).id + values = paramPamp.mapValues { it.value.value.toString() }, + buildId = buildId + ) + return buildId.id } finally { logger.info("Timer| It take(${System.currentTimeMillis() - startEpoch})ms to start pipeline($pipelineId)") } @@ -2513,4 +2500,28 @@ class PipelineBuildFacadeService( checkManualReviewParamOut(item.valueType, item, value) } } + + private fun saveTriggerEvent( + userId: String, + projectId: String, + pipelineId: String, + values: Map?, + buildId: BuildId? + ) { + try { + client.get(ServiceTriggerEventResource::class).saveSpecificEvent( + specificEvent = PipelineSpecificEvent( + projectId = projectId, + pipelineId = pipelineId, + requestParams = values, + userId = userId, + eventSource = userId, + triggerType = StartType.TIME_TRIGGER.name, + buildInfo = buildId + ) + ) + } catch (ignored: Exception) { + logger.warn("fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) + } + } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index c7e8071131c..4a212ba077d 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -367,7 +367,7 @@ class PipelineTriggerEventService @Autowired constructor( val replayRequestId = triggerEvent.replayRequestId ?: triggerEvent.requestId val replayTriggerEvent = with(triggerEvent) { PipelineTriggerEvent( - requestId = MDC.get(TraceTag.BIZID), + requestId = requestId, projectId = projectId, eventId = replayEventId, triggerType = triggerType, @@ -413,39 +413,27 @@ class PipelineTriggerEventService @Autowired constructor( eventDesc: String? = null, requestParams: Map?, triggerType: String = PipelineTriggerType.MANUAL.name, - startAction: () -> BuildId - ): BuildId { - var buildNum: String? = null - var status = PipelineTriggerStatus.SUCCEED.name - var buildId: String? = null + buildInfo: BuildId? + ) { + logger.info("start save specific event|$projectId|$pipelineId|$userId|$triggerType") val pipelineInfo = client.get(ServicePipelineResource::class).getPipelineInfo( projectId = projectId, pipelineId = pipelineId, channelCode = ChannelCode.BS ).data - try { - val buildInfo = startAction.invoke() - buildNum = buildInfo.num.toString() - buildId = buildInfo.id - return buildInfo - } catch (ignored: Exception) { - status = PipelineTriggerStatus.FAILED.name - throw ignored - } finally { - saveManualStartEvent( - projectId = projectId, - pipelineId = pipelineId, - pipelineName = pipelineInfo?.pipelineName ?: "", - eventSource = eventSource, - eventDesc = eventDesc, - buildId = buildId, - status = status, - requestParams = requestParams, - userId = userId, - buildNum = buildNum, - triggerType = triggerType - ) - } + saveManualStartEvent( + projectId = projectId, + pipelineId = pipelineId, + pipelineName = pipelineInfo?.pipelineName ?: "", + eventSource = eventSource, + eventDesc = eventDesc, + buildId = buildInfo?.id ?: "", + status = PipelineTriggerStatus.SUCCEED.name, + requestParams = requestParams, + userId = userId, + buildNum = buildInfo?.num.toString(), + triggerType = triggerType + ) } /** diff --git a/src/backend/ci/core/store/biz-store-image/src/main/kotlin/com/tencent/devops/store/service/image/ImageReleaseService.kt b/src/backend/ci/core/store/biz-store-image/src/main/kotlin/com/tencent/devops/store/service/image/ImageReleaseService.kt index f800008e8bb..6ada8ad3c09 100644 --- a/src/backend/ci/core/store/biz-store-image/src/main/kotlin/com/tencent/devops/store/service/image/ImageReleaseService.kt +++ b/src/backend/ci/core/store/biz-store-image/src/main/kotlin/com/tencent/devops/store/service/image/ImageReleaseService.kt @@ -720,8 +720,7 @@ abstract class ImageReleaseService { pipelineId = imagePipelineRelRecord.pipelineId, values = startParams, channelCode = ChannelCode.AM, - startType = StartType.SERVICE, - triggerEventSource = userId + startType = StartType.SERVICE ).data logger.info("the buildIdObj is:$buildIdObj") if (null != buildIdObj) { diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/atom/impl/AtomIndexTriggerCalServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/atom/impl/AtomIndexTriggerCalServiceImpl.kt index 37781cb589b..5d1c3044977 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/atom/impl/AtomIndexTriggerCalServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/atom/impl/AtomIndexTriggerCalServiceImpl.kt @@ -142,8 +142,7 @@ class AtomIndexTriggerCalServiceImpl @Autowired constructor( pipelineId = pipelineId, values = mapOf(KEY_INDEX_CODE to indexCode), channelCode = ChannelCode.AM, - startType = StartType.SERVICE, - triggerEventSource = userId + startType = StartType.SERVICE ) } } diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/common/impl/StoreIndexPipelineServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/common/impl/StoreIndexPipelineServiceImpl.kt index 633f29e2d93..8f282e39677 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/common/impl/StoreIndexPipelineServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/common/impl/StoreIndexPipelineServiceImpl.kt @@ -170,8 +170,7 @@ class StoreIndexPipelineServiceImpl @Autowired constructor( pipelineId = pipelineId, values = mapOf(KEY_INDEX_CODE to storeIndexPipelineInitRequest.indexCode), channelCode = ChannelCode.AM, - startType = StartType.SERVICE, - triggerEventSource = userId + startType = StartType.SERVICE ) logger.info("manualStartupNew result is:$buildId") } From dfe84b799d4d68665ab8b31fe153d372572e4b38 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 14 Nov 2023 11:15:59 +0800 Subject: [PATCH 116/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/service/builds/PipelineBuildFacadeService.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt index b4ebc2510e4..26d88614a67 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt @@ -120,7 +120,6 @@ import com.tencent.devops.process.service.BuildVariableService import com.tencent.devops.process.service.ParamFacadeService import com.tencent.devops.process.service.PipelineTaskPauseService import com.tencent.devops.process.service.pipeline.PipelineBuildService -import com.tencent.devops.process.trigger.PipelineTriggerEventService import com.tencent.devops.process.util.TaskUtils import com.tencent.devops.process.utils.PIPELINE_BUILD_MSG import com.tencent.devops.process.utils.PIPELINE_NAME From e86157c22847cfe384aa70f140774e24a37afec6 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 14 Nov 2023 14:10:08 +0800 Subject: [PATCH 117/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apigw/v3/ApigwBuildResourceV3Impl.kt | 71 +++++++++------ .../apigw/v4/ApigwBuildResourceV4Impl.kt | 71 +++++++++------ .../pojo/trigger/PipelineSpecificEvent.kt | 6 +- .../pojo/trigger/PipelineTriggerEvent.kt | 2 +- .../api/ServiceTriggerEventResourceImpl.kt | 4 +- .../process/api/UserBuildResourceImpl.kt | 68 ++++++++------ .../service/PipelineRemoteAuthService.kt | 66 +++++++++----- .../service/SubPipelineStartUpService.kt | 91 +++++++++++-------- .../builds/PipelineBuildFacadeService.kt | 70 ++++++++------ .../trigger/PipelineTriggerEventService.kt | 15 ++- 10 files changed, 289 insertions(+), 175 deletions(-) diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt index 46c80d0f787..f2d10afaa97 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt @@ -43,6 +43,7 @@ import com.tencent.devops.process.pojo.BuildManualStartupInfo import com.tencent.devops.process.pojo.BuildTaskPauseInfo import com.tencent.devops.process.pojo.pipeline.ModelDetail import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -137,23 +138,24 @@ class ApigwBuildResourceV3Impl @Autowired constructor( buildNo: Int? ): Result { logger.info("OPENAPI_BUILD_V3|$userId|start|$projectId|$pipelineId|$values|$buildNo") - val buildId = client.get(ServiceBuildResource::class).manualStartupNew( - userId = userId, - projectId = projectId, - pipelineId = pipelineId, - values = values ?: emptyMap(), - buildNo = buildNo, - channelCode = apiGatewayUtil.getChannelCode(), - startType = StartType.SERVICE - ) - saveTriggerEvent( + val buildId = saveTriggerEvent( userId = userId, projectId = projectId, pipelineId = pipelineId, values = values, - buildId = buildId.data + action = { + client.get(ServiceBuildResource::class).manualStartupNew( + userId = userId, + projectId = projectId, + pipelineId = pipelineId, + values = values ?: emptyMap(), + buildNo = buildNo, + channelCode = apiGatewayUtil.getChannelCode(), + startType = StartType.SERVICE + ).data + } ) - return buildId + return Result(buildId) } override fun stop( @@ -297,23 +299,40 @@ class ApigwBuildResourceV3Impl @Autowired constructor( projectId: String, pipelineId: String, values: Map?, - buildId: BuildId? - ) { + action: () -> BuildId? + ): BuildId { + var buildId: BuildId? = null + var status = PipelineTriggerStatus.SUCCEED.name + var failReason = "" try { - client.get(ServiceTriggerEventResource::class).saveSpecificEvent( - specificEvent = PipelineSpecificEvent( - projectId = projectId, - pipelineId = pipelineId, - requestParams = values, - userId = userId, - eventSource = userId, - triggerType = StartType.SERVICE.name, - buildInfo = buildId - ) - ) + buildId = action.invoke() } catch (ignored: Exception) { - logger.warn("OPENAPI_BUILD_V3|fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) + status = PipelineTriggerStatus.FAILED.name + failReason = ignored.message.toString() + throw ignored + } finally { + try { + client.get(ServiceTriggerEventResource::class).saveSpecificEvent( + specificEvent = PipelineSpecificEvent( + projectId = projectId, + pipelineId = pipelineId, + requestParams = values, + userId = userId, + eventSource = userId, + triggerType = StartType.SERVICE.name, + buildInfo = buildId, + failReason = failReason, + status = status + ) + ) + } catch (ignored: Exception) { + logger.warn( + "OPENAPI_BUILD_V3|fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", + ignored + ) + } } + return buildId!! } companion object { diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt index 1ffbcf150a7..4256d842713 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt @@ -51,6 +51,7 @@ import com.tencent.devops.process.pojo.BuildTaskPauseInfo import com.tencent.devops.process.pojo.ReviewParam import com.tencent.devops.process.pojo.pipeline.ModelRecord import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -174,23 +175,24 @@ class ApigwBuildResourceV4Impl @Autowired constructor( buildNo: Int? ): Result { logger.info("OPENAPI_BUILD_V4|$userId|start|$projectId|$pipelineId|$values|$buildNo") - val buildId = client.get(ServiceBuildResource::class).manualStartupNew( - userId = userId, - projectId = projectId, - pipelineId = pipelineId, - values = values ?: emptyMap(), - buildNo = buildNo, - channelCode = apiGatewayUtil.getChannelCode(), - startType = StartType.SERVICE - ) - saveTriggerEvent( + val buildId = saveTriggerEvent( userId = userId, projectId = projectId, pipelineId = pipelineId, values = values, - buildId = buildId.data + action = { + client.get(ServiceBuildResource::class).manualStartupNew( + userId = userId, + projectId = projectId, + pipelineId = pipelineId, + values = values ?: emptyMap(), + buildNo = buildNo, + channelCode = apiGatewayUtil.getChannelCode(), + startType = StartType.SERVICE + ).data + } ) - return buildId + return Result(buildId) } override fun stop( @@ -443,23 +445,40 @@ class ApigwBuildResourceV4Impl @Autowired constructor( projectId: String, pipelineId: String, values: Map?, - buildId: BuildId? - ) { + action: () -> BuildId? + ): BuildId { + var buildId: BuildId? = null + var status = PipelineTriggerStatus.SUCCEED.name + var failReason = "" try { - client.get(ServiceTriggerEventResource::class).saveSpecificEvent( - specificEvent = PipelineSpecificEvent( - projectId = projectId, - pipelineId = pipelineId, - requestParams = values, - userId = userId, - eventSource = userId, - triggerType = StartType.SERVICE.name, - buildInfo = buildId - ) - ) + buildId = action.invoke() } catch (ignored: Exception) { - logger.warn("OPENAPI_BUILD_V4|fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) + status = PipelineTriggerStatus.FAILED.name + failReason = ignored.message.toString() + throw ignored + } finally { + try { + client.get(ServiceTriggerEventResource::class).saveSpecificEvent( + specificEvent = PipelineSpecificEvent( + projectId = projectId, + pipelineId = pipelineId, + requestParams = values, + userId = userId, + eventSource = userId, + triggerType = StartType.SERVICE.name, + buildInfo = buildId, + failReason = failReason, + status = status + ) + ) + } catch (ignored: Exception) { + logger.warn( + "OPENAPI_BUILD_V4|fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", + ignored + ) + } } + return buildId!! } companion object { diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineSpecificEvent.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineSpecificEvent.kt index 2b64e705207..2ebb505fa7d 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineSpecificEvent.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineSpecificEvent.kt @@ -48,5 +48,9 @@ data class PipelineSpecificEvent( @ApiModelProperty("触发类型") val triggerType: String = PipelineTriggerType.MANUAL.name, @ApiModelProperty("构建信息") - val buildInfo: BuildId? + val buildInfo: BuildId?, + @ApiModelProperty("构建状态") + val status: String, + @ApiModelProperty("失败信息") + val failReason: String ) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt index 2668c0bb4db..66097b779e3 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEvent.kt @@ -54,6 +54,6 @@ data class PipelineTriggerEvent( val replayRequestId: String? = null, @ApiModelProperty("事件请求参数, 记录手动/openapi/定时/远程触发启动参数") val requestParams: Map? = null, - @ApiModelProperty("触发事件") + @ApiModelProperty("触发时间") val createTime: LocalDateTime ) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt index f18c4fc647f..983554025be 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt @@ -49,7 +49,9 @@ class ServiceTriggerEventResourceImpl @Autowired constructor( eventSource = eventSource, eventDesc = eventDesc, triggerType = PipelineTriggerType.PIPELINE.name, - buildInfo = buildInfo + buildInfo = buildInfo, + status = status, + failReason = failReason ) } return true diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt index a72fac05145..99d4d97ea70 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt @@ -49,6 +49,7 @@ import com.tencent.devops.process.pojo.ReviewParam import com.tencent.devops.process.pojo.pipeline.ModelDetail import com.tencent.devops.process.pojo.pipeline.ModelRecord import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.service.PipelineRecentUseService import com.tencent.devops.process.service.builds.PipelineBuildFacadeService import com.tencent.devops.process.service.builds.PipelineBuildMaintainFacadeService @@ -99,24 +100,25 @@ class UserBuildResourceImpl @Autowired constructor( triggerReviewers: List? ): Result { checkParam(userId, projectId, pipelineId) - val manualStartup = pipelineBuildFacadeService.buildManualStartup( + val manualStartup = saveTriggerEvent( userId = userId, - startType = StartType.MANUAL, projectId = projectId, pipelineId = pipelineId, values = values, - channelCode = ChannelCode.BS, - buildNo = buildNo, - triggerReviewers = triggerReviewers + action = { + pipelineBuildFacadeService.buildManualStartup( + userId = userId, + startType = StartType.MANUAL, + projectId = projectId, + pipelineId = pipelineId, + values = values, + channelCode = ChannelCode.BS, + buildNo = buildNo, + triggerReviewers = triggerReviewers + ) + } ) pipelineRecentUseService.record(userId, projectId, pipelineId) - saveTriggerEvent( - userId = userId, - projectId = projectId, - pipelineId = pipelineId, - values = values, - buildId = manualStartup - ) return Result(manualStartup) } @@ -553,23 +555,37 @@ class UserBuildResourceImpl @Autowired constructor( projectId: String, pipelineId: String, values: Map?, - buildId: BuildId? - ) { + action: () -> BuildId? + ): BuildId { + var buildId: BuildId? = null + var status = PipelineTriggerStatus.SUCCEED.name + var failReason = "" try { - client.get(ServiceTriggerEventResource::class).saveSpecificEvent( - specificEvent = PipelineSpecificEvent( - projectId = projectId, - pipelineId = pipelineId, - requestParams = values, - userId = userId, - eventSource = userId, - triggerType = StartType.MANUAL.name, - buildInfo = buildId - ) - ) + buildId = action.invoke() } catch (ignored: Exception) { - logger.warn("fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) + status = PipelineTriggerStatus.FAILED.name + failReason = ignored.message.toString() + throw ignored + } finally { + try { + client.get(ServiceTriggerEventResource::class).saveSpecificEvent( + specificEvent = PipelineSpecificEvent( + projectId = projectId, + pipelineId = pipelineId, + requestParams = values, + userId = userId, + eventSource = userId, + triggerType = StartType.MANUAL.name, + buildInfo = buildId, + failReason = failReason, + status = status + ) + ) + } catch (ignored: Exception) { + logger.warn("fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) + } } + return buildId!! } companion object{ diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt index 089fffd70df..6b6ee796a2e 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt @@ -50,6 +50,7 @@ import com.tencent.devops.process.engine.service.PipelineRepositoryService import com.tencent.devops.process.pojo.BuildId import com.tencent.devops.process.pojo.PipelineRemoteToken import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.service.builds.PipelineBuildFacadeService import com.tencent.devops.process.utils.PIPELINE_START_REMOTE_USER_ID import com.tencent.devops.process.utils.PIPELINE_START_TASK_ID @@ -129,22 +130,23 @@ class PipelineRemoteAuthService @Autowired constructor( return bkTag.invokeByTag(projectConsulTag) { logger.info("start call service api ${pipeline.projectId} ${pipeline.pipelineId}, " + "$projectConsulTag ${bkTag.getFinalTag()}") - val buildId = client.getGateway(ServiceBuildResource::class).manualStartupNew( + val buildId = saveTriggerEvent( userId = userId!!, projectId = pipeline.projectId, pipelineId = pipeline.pipelineId, - values = vals.toMap(), - channelCode = ChannelCode.BS, - startType = StartType.REMOTE, - buildNo = null - ).data!! - saveTriggerEvent( - userId = userId, - projectId = pipeline.projectId, - pipelineId = pipeline.pipelineId, eventSource = sourceIp ?: "", values = vals.toMap(), - buildId = buildId + action = { + client.getGateway(ServiceBuildResource::class).manualStartupNew( + userId = userId!!, + projectId = pipeline.projectId, + pipelineId = pipeline.pipelineId, + values = vals.toMap(), + channelCode = ChannelCode.BS, + startType = StartType.REMOTE, + buildNo = null + ).data!! + } ) // 在远程触发器job中打印sourcIp val taskId = buildVariableService.getVariable( @@ -181,23 +183,37 @@ class PipelineRemoteAuthService @Autowired constructor( projectId: String, pipelineId: String, values: Map?, - buildId: BuildId? - ) { + action: () -> BuildId? + ) :BuildId { + var buildId: BuildId? = null + var status = PipelineTriggerStatus.SUCCEED.name + var failReason = "" try { - client.get(ServiceTriggerEventResource::class).saveSpecificEvent( - specificEvent = PipelineSpecificEvent( - projectId = projectId, - pipelineId = pipelineId, - requestParams = values, - userId = userId, - eventSource = eventSource, - triggerType = StartType.REMOTE.name, - buildInfo = buildId - ) - ) + buildId = action.invoke() } catch (ignored: Exception) { - logger.warn("fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) + status = PipelineTriggerStatus.FAILED.name + failReason = ignored.message.toString() + throw ignored + } finally { + try { + client.get(ServiceTriggerEventResource::class).saveSpecificEvent( + specificEvent = PipelineSpecificEvent( + projectId = projectId, + pipelineId = pipelineId, + requestParams = values, + userId = userId, + eventSource = eventSource, + triggerType = StartType.REMOTE.name, + buildInfo = buildId, + failReason = failReason, + status = status + ) + ) + } catch (ignored: Exception) { + logger.warn("fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) + } } + return buildId!! } companion object { diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt index e5181fd5a9c..d5df41a88b1 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt @@ -46,6 +46,7 @@ import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildAtomEle import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildLessAtomElement import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.common.webhook.enums.WebhookI18nConstants +import com.tencent.devops.process.api.UserBuildResourceImpl import com.tencent.devops.process.api.service.ServiceTriggerEventResource import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_SUB_PIPELINE_NOT_ALLOWED_CIRCULAR_CALL @@ -61,6 +62,7 @@ import com.tencent.devops.process.pojo.pipeline.StartUpInfo import com.tencent.devops.process.pojo.pipeline.SubPipelineStartUpInfo import com.tencent.devops.process.pojo.pipeline.SubPipelineStatus import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.service.builds.PipelineBuildFacadeService import com.tencent.devops.process.service.pipeline.PipelineBuildService import com.tencent.devops.process.trigger.PipelineTriggerEventService @@ -253,26 +255,27 @@ class SubPipelineStartUpService @Autowired constructor( // 校验父流水线最后修改人是否有子流水线执行权限 checkPermission(userId = parentPipelineInfo.lastModifyUser, projectId = projectId, pipelineId = pipelineId) // 子流水线的调用不受频率限制 - val subBuildId = pipelineBuildService.startPipeline( - userId = readyToBuildPipelineInfo.lastModifyUser, - pipeline = readyToBuildPipelineInfo, - startType = StartType.PIPELINE, - pipelineParamMap = params, - channelCode = channelCode, - isMobile = isMobile, - model = model, - frequencyLimit = false - ) - saveTriggerEvent( + val subBuildId = saveTriggerEvent( userId = userId, projectId = projectId, pipelineId = pipelineId, values = params.mapValues { it.value.value.toString() }, - buildId = subBuildId, parentProjectId = parentProjectId, parentPipelineId = parentPipelineId, parentBuildId = parentBuildId, - parentPipelineName = parentPipelineInfo.pipelineName + parentPipelineName = parentPipelineInfo.pipelineName, + action = { + pipelineBuildService.startPipeline( + userId = readyToBuildPipelineInfo.lastModifyUser, + pipeline = readyToBuildPipelineInfo, + startType = StartType.PIPELINE, + pipelineParamMap = params, + channelCode = channelCode, + isMobile = isMobile, + model = model, + frequencyLimit = false + ) + } ) // 更新父流水线关联子流水线构建id pipelineTaskService.updateSubBuildId( @@ -511,37 +514,51 @@ class SubPipelineStartUpService @Autowired constructor( projectId: String, pipelineId: String, values: Map?, - buildId: BuildId?, parentProjectId: String, parentPipelineId: String, parentBuildId: String, - parentPipelineName: String - ) { + parentPipelineName: String, + action: () -> BuildId? + ): BuildId { + var buildId: BuildId? = null + var status = PipelineTriggerStatus.SUCCEED.name + var failReason = "" try { - client.get(ServiceTriggerEventResource::class).saveSpecificEvent( - specificEvent = PipelineSpecificEvent( - projectId = projectId, - pipelineId = pipelineId, - requestParams = values, - userId = userId, - eventSource = parentPipelineId, - triggerType = StartType.PIPELINE.name, - buildInfo = buildId, - eventDesc = JsonUtil.toJson( - I18Variable( - code = WebhookI18nConstants.PIPELINE_START_EVENT_DESC, - params = listOf( - userId, - "/console/pipeline/$parentProjectId/$parentPipelineId/detail/$parentBuildId", - parentPipelineName - ) + buildId = action.invoke() + } catch (ignored: Exception) { + status = PipelineTriggerStatus.FAILED.name + failReason = ignored.message.toString() + throw ignored + } finally { + try { + client.get(ServiceTriggerEventResource::class).saveSpecificEvent( + specificEvent = PipelineSpecificEvent( + projectId = projectId, + pipelineId = pipelineId, + requestParams = values, + userId = userId, + eventSource = parentPipelineId, + triggerType = StartType.PIPELINE.name, + buildInfo = buildId, + eventDesc = JsonUtil.toJson( + I18Variable( + code = WebhookI18nConstants.PIPELINE_START_EVENT_DESC, + params = listOf( + userId, + "/console/pipeline/$parentProjectId/$parentPipelineId/detail/$parentBuildId", + parentPipelineName + ) + ), + false ), - false + failReason = failReason, + status = status ) ) - ) - } catch (ignored: Exception) { - logger.warn("OPENAPI_BUILD_V4|fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) + } catch (ignored: Exception) { + logger.warn("fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) + } } + return buildId!! } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt index 26d88614a67..35716238cc8 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt @@ -116,6 +116,7 @@ import com.tencent.devops.process.pojo.pipeline.ModelDetail import com.tencent.devops.process.pojo.pipeline.ModelRecord import com.tencent.devops.process.pojo.pipeline.PipelineLatestBuild import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.service.BuildVariableService import com.tencent.devops.process.service.ParamFacadeService import com.tencent.devops.process.service.PipelineTaskPauseService @@ -699,23 +700,24 @@ class PipelineBuildFacadeService( val triggerContainer = model.stages[0].containers[0] as TriggerContainer val paramPamp = buildParamCompatibilityTransformer.parseTriggerParam(triggerContainer.params, parameters) - val buildId = pipelineBuildService.startPipeline( - userId = userId, - pipeline = pipeline, - startType = StartType.TIME_TRIGGER, - pipelineParamMap = paramPamp, - channelCode = pipeline.channelCode, - isMobile = false, - model = model, - signPipelineVersion = null, - frequencyLimit = false - ) - saveTriggerEvent( + val buildId = saveTriggerEvent( userId = userId, projectId = projectId, pipelineId = pipelineId, values = paramPamp.mapValues { it.value.value.toString() }, - buildId = buildId + action = { + pipelineBuildService.startPipeline( + userId = userId, + pipeline = pipeline, + startType = StartType.TIME_TRIGGER, + pipelineParamMap = paramPamp, + channelCode = pipeline.channelCode, + isMobile = false, + model = model, + signPipelineVersion = null, + frequencyLimit = false + ) + } ) return buildId.id } finally { @@ -2505,22 +2507,36 @@ class PipelineBuildFacadeService( projectId: String, pipelineId: String, values: Map?, - buildId: BuildId? - ) { + action: () -> BuildId + ): BuildId { + var buildId: BuildId? = null + var status = PipelineTriggerStatus.SUCCEED.name + var failReason = "" try { - client.get(ServiceTriggerEventResource::class).saveSpecificEvent( - specificEvent = PipelineSpecificEvent( - projectId = projectId, - pipelineId = pipelineId, - requestParams = values, - userId = userId, - eventSource = userId, - triggerType = StartType.TIME_TRIGGER.name, - buildInfo = buildId - ) - ) + buildId = action.invoke() } catch (ignored: Exception) { - logger.warn("fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) + status = PipelineTriggerStatus.FAILED.name + failReason = ignored.message.toString() + throw ignored + } finally { + try { + client.get(ServiceTriggerEventResource::class).saveSpecificEvent( + specificEvent = PipelineSpecificEvent( + projectId = projectId, + pipelineId = pipelineId, + requestParams = values, + userId = userId, + eventSource = userId, + triggerType = StartType.TIME_TRIGGER.name, + buildInfo = buildId, + failReason = failReason, + status = status + ) + ) + } catch (ignored: Exception) { + logger.warn("fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) + } } + return buildId!! } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 4a212ba077d..3ffe5048f21 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -413,7 +413,9 @@ class PipelineTriggerEventService @Autowired constructor( eventDesc: String? = null, requestParams: Map?, triggerType: String = PipelineTriggerType.MANUAL.name, - buildInfo: BuildId? + buildInfo: BuildId?, + status: String = PipelineTriggerStatus.SUCCEED.name, + failReason: String? = null ) { logger.info("start save specific event|$projectId|$pipelineId|$userId|$triggerType") val pipelineInfo = client.get(ServicePipelineResource::class).getPipelineInfo( @@ -428,11 +430,12 @@ class PipelineTriggerEventService @Autowired constructor( eventSource = eventSource, eventDesc = eventDesc, buildId = buildInfo?.id ?: "", - status = PipelineTriggerStatus.SUCCEED.name, + status = status, requestParams = requestParams, userId = userId, buildNum = buildInfo?.num.toString(), - triggerType = triggerType + triggerType = triggerType, + failReason = failReason ) } @@ -450,7 +453,8 @@ class PipelineTriggerEventService @Autowired constructor( status: String, triggerType: String, requestParams: Map?, - eventDesc: String? = null + eventDesc: String? = null, + failReason: String? ) { val eventId = getEventId() val requestId = MDC.get(TraceTag.BIZID) @@ -474,7 +478,8 @@ class PipelineTriggerEventService @Autowired constructor( pipelineId = pipelineId, buildId = buildId, buildNum = buildNum, - pipelineName = pipelineName + pipelineName = pipelineName, + reason = failReason ), triggerEvent = PipelineTriggerEvent( eventId = eventId, From a92e2dee896a4cf5850ea26c7543764f6263631c Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 14 Nov 2023 16:09:46 +0800 Subject: [PATCH 118/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tencent/devops/process/api/UserBuildResourceImpl.kt | 2 +- .../tencent/devops/process/service/PipelineRemoteAuthService.kt | 2 +- .../tencent/devops/process/service/SubPipelineStartUpService.kt | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt index 99d4d97ea70..9cfab62c9af 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt @@ -588,7 +588,7 @@ class UserBuildResourceImpl @Autowired constructor( return buildId!! } - companion object{ + companion object { private val logger = LoggerFactory.getLogger(UserBuildResourceImpl::class.java) } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt index 6b6ee796a2e..ed75ba6e469 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt @@ -184,7 +184,7 @@ class PipelineRemoteAuthService @Autowired constructor( pipelineId: String, values: Map?, action: () -> BuildId? - ) :BuildId { + ): BuildId { var buildId: BuildId? = null var status = PipelineTriggerStatus.SUCCEED.name var failReason = "" diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt index d5df41a88b1..aa20e2ee1e8 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt @@ -46,7 +46,6 @@ import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildAtomEle import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildLessAtomElement import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.common.webhook.enums.WebhookI18nConstants -import com.tencent.devops.process.api.UserBuildResourceImpl import com.tencent.devops.process.api.service.ServiceTriggerEventResource import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_SUB_PIPELINE_NOT_ALLOWED_CIRCULAR_CALL @@ -65,7 +64,6 @@ import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.service.builds.PipelineBuildFacadeService import com.tencent.devops.process.service.pipeline.PipelineBuildService -import com.tencent.devops.process.trigger.PipelineTriggerEventService import com.tencent.devops.process.utils.PIPELINE_START_CHANNEL import com.tencent.devops.process.utils.PIPELINE_START_PARENT_BUILD_ID import com.tencent.devops.process.utils.PIPELINE_START_PARENT_BUILD_TASK_ID From ef904a15a8825c91f78707bbd310167c10a6af45 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 14 Nov 2023 16:27:27 +0800 Subject: [PATCH 119/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../code/filter/PathRegexFilterTest.kt | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/test/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathRegexFilterTest.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/test/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathRegexFilterTest.kt index 272f49abbf6..024db5177d6 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/test/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathRegexFilterTest.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/test/kotlin/com/tencent/devops/common/webhook/service/code/filter/PathRegexFilterTest.kt @@ -313,7 +313,7 @@ class PathRegexFilterTest { caseSensitive = true ) Assertions.assertTrue(pathRegexFilter.doFilter(response)) - response.getParam()[MATCH_PATHS]?.let { + response.params[MATCH_PATHS]?.let { Assertions.assertTrue( it.split(",").toSet().containsAll( setOf( @@ -332,7 +332,7 @@ class PathRegexFilterTest { caseSensitive = true ) Assertions.assertTrue(pathRegexFilter.doFilter(response)) - response.getParam()[MATCH_PATHS]?.let { + response.params[MATCH_PATHS]?.let { Assertions.assertTrue( it.split(",").toSet().containsAll( setOf( @@ -350,7 +350,7 @@ class PathRegexFilterTest { caseSensitive = true ) Assertions.assertTrue(pathRegexFilter.doFilter(response)) - response.getParam()[MATCH_PATHS]?.let { + response.params[MATCH_PATHS]?.let { Assertions.assertTrue( it.split(",").toSet().containsAll( setOf( @@ -368,7 +368,7 @@ class PathRegexFilterTest { caseSensitive = true ) Assertions.assertTrue(pathRegexFilter.doFilter(response)) - response.getParam()[MATCH_PATHS]?.let { + response.params[MATCH_PATHS]?.let { Assertions.assertTrue( it.split(",").toSet().containsAll( setOf( @@ -386,7 +386,7 @@ class PathRegexFilterTest { caseSensitive = true ) Assertions.assertTrue(pathRegexFilter.doFilter(response)) - response.getParam()[MATCH_PATHS]?.let { + response.params[MATCH_PATHS]?.let { Assertions.assertTrue( it.split(",").toSet().containsAll( setOf( @@ -404,7 +404,7 @@ class PathRegexFilterTest { caseSensitive = true ) Assertions.assertTrue(pathRegexFilter.doFilter(response)) - response.getParam()[MATCH_PATHS]?.let { + response.params[MATCH_PATHS]?.let { Assertions.assertTrue( it.split(",").toSet().containsAll( setOf( @@ -422,7 +422,7 @@ class PathRegexFilterTest { caseSensitive = true ) Assertions.assertTrue(pathRegexFilter.doFilter(response)) - response.getParam()[MATCH_PATHS]?.let { + response.params[MATCH_PATHS]?.let { Assertions.assertTrue( it.split(",").toSet().containsAll( setOf( @@ -448,7 +448,7 @@ class PathRegexFilterTest { caseSensitive = true ) Assertions.assertTrue(pathRegexFilter.doFilter(response)) - response.getParam()[MATCH_PATHS]?.let { + response.params[MATCH_PATHS]?.let { Assertions.assertTrue( it.split(",").toSet().containsAll( setOf( @@ -476,7 +476,7 @@ class PathRegexFilterTest { caseSensitive = true ) Assertions.assertTrue(pathRegexFilter.doFilter(response)) - response.getParam()[MATCH_PATHS]?.let { + response.params[MATCH_PATHS]?.let { Assertions.assertTrue( it.split(",").toSet().containsAll( setOf( @@ -498,7 +498,7 @@ class PathRegexFilterTest { caseSensitive = true ) Assertions.assertTrue(pathRegexFilter.doFilter(response)) - response.getParam()[MATCH_PATHS]?.let { + response.params[MATCH_PATHS]?.let { Assertions.assertTrue( it.split(",").toSet().containsAll( setOf( @@ -519,7 +519,7 @@ class PathRegexFilterTest { caseSensitive = true ) Assertions.assertTrue(pathRegexFilter.doFilter(response)) - response.getParam()[MATCH_PATHS]?.let { + response.params[MATCH_PATHS]?.let { Assertions.assertTrue( it.split(",").toSet().containsAll( setOf( @@ -540,7 +540,7 @@ class PathRegexFilterTest { caseSensitive = true ) Assertions.assertTrue(pathRegexFilter.doFilter(response)) - response.getParam()[MATCH_PATHS]?.let { + response.params[MATCH_PATHS]?.let { Assertions.assertTrue( it.split(",").toSet().containsAll( setOf( From 06b464165c367b55c1d140cd4ea8f928061d9cc6 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Tue, 14 Nov 2023 18:31:52 +0800 Subject: [PATCH 120/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/api/ServiceTriggerEventResourceImpl.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt index 983554025be..311af05ae41 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt @@ -30,7 +30,6 @@ package com.tencent.devops.process.api import com.tencent.devops.common.web.RestResource import com.tencent.devops.process.api.service.ServiceTriggerEventResource import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent -import com.tencent.devops.process.pojo.trigger.PipelineTriggerType import com.tencent.devops.process.trigger.PipelineTriggerEventService import org.springframework.beans.factory.annotation.Autowired @@ -48,7 +47,7 @@ class ServiceTriggerEventResourceImpl @Autowired constructor( userId = userId, eventSource = eventSource, eventDesc = eventDesc, - triggerType = PipelineTriggerType.PIPELINE.name, + triggerType = triggerType, buildInfo = buildInfo, status = status, failReason = failReason From bb2228e6631042bf69d7d47a9701533cd74a8150 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 15 Nov 2023 10:41:37 +0800 Subject: [PATCH 121/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apigw/v3/ApigwBuildResourceV3Impl.kt | 7 +++--- .../apigw/v4/ApigwBuildResourceV4Impl.kt | 7 +++--- .../pojo/trigger/PipelineSpecificEvent.kt | 4 ++-- .../api/ServiceTriggerEventResourceImpl.kt | 2 +- .../process/api/UserBuildResourceImpl.kt | 7 +++--- .../service/PipelineRemoteAuthService.kt | 22 +++++++++++++++---- .../service/SubPipelineStartUpService.kt | 7 +++--- .../builds/PipelineBuildFacadeService.kt | 7 +++--- .../trigger/PipelineTriggerEventService.kt | 9 ++++---- .../i18n/process/message_en_US.properties | 2 +- .../i18n/process/message_zh_CN.properties | 2 +- 11 files changed, 48 insertions(+), 28 deletions(-) diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt index f2d10afaa97..468db0c092b 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt @@ -43,6 +43,7 @@ import com.tencent.devops.process.pojo.BuildManualStartupInfo import com.tencent.devops.process.pojo.BuildTaskPauseInfo import com.tencent.devops.process.pojo.pipeline.ModelDetail import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -303,12 +304,12 @@ class ApigwBuildResourceV3Impl @Autowired constructor( ): BuildId { var buildId: BuildId? = null var status = PipelineTriggerStatus.SUCCEED.name - var failReason = "" + var reason: String = PipelineTriggerReason.TRIGGER_SUCCESS.name try { buildId = action.invoke() } catch (ignored: Exception) { status = PipelineTriggerStatus.FAILED.name - failReason = ignored.message.toString() + reason = ignored.message.toString() throw ignored } finally { try { @@ -321,7 +322,7 @@ class ApigwBuildResourceV3Impl @Autowired constructor( eventSource = userId, triggerType = StartType.SERVICE.name, buildInfo = buildId, - failReason = failReason, + reason = reason, status = status ) ) diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt index 4256d842713..065d23fc4cd 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt @@ -51,6 +51,7 @@ import com.tencent.devops.process.pojo.BuildTaskPauseInfo import com.tencent.devops.process.pojo.ReviewParam import com.tencent.devops.process.pojo.pipeline.ModelRecord import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -449,12 +450,12 @@ class ApigwBuildResourceV4Impl @Autowired constructor( ): BuildId { var buildId: BuildId? = null var status = PipelineTriggerStatus.SUCCEED.name - var failReason = "" + var reason: String = PipelineTriggerReason.TRIGGER_SUCCESS.name try { buildId = action.invoke() } catch (ignored: Exception) { status = PipelineTriggerStatus.FAILED.name - failReason = ignored.message.toString() + reason = ignored.message.toString() throw ignored } finally { try { @@ -467,7 +468,7 @@ class ApigwBuildResourceV4Impl @Autowired constructor( eventSource = userId, triggerType = StartType.SERVICE.name, buildInfo = buildId, - failReason = failReason, + reason = reason, status = status ) ) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineSpecificEvent.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineSpecificEvent.kt index 2ebb505fa7d..2e7d03ba7e6 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineSpecificEvent.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineSpecificEvent.kt @@ -51,6 +51,6 @@ data class PipelineSpecificEvent( val buildInfo: BuildId?, @ApiModelProperty("构建状态") val status: String, - @ApiModelProperty("失败信息") - val failReason: String + @ApiModelProperty("原因") + val reason: String ) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt index 311af05ae41..12e3fde972b 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt @@ -50,7 +50,7 @@ class ServiceTriggerEventResourceImpl @Autowired constructor( triggerType = triggerType, buildInfo = buildInfo, status = status, - failReason = failReason + reason = reason ) } return true diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt index 9cfab62c9af..4e95ba4a311 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt @@ -49,6 +49,7 @@ import com.tencent.devops.process.pojo.ReviewParam import com.tencent.devops.process.pojo.pipeline.ModelDetail import com.tencent.devops.process.pojo.pipeline.ModelRecord import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.service.PipelineRecentUseService import com.tencent.devops.process.service.builds.PipelineBuildFacadeService @@ -559,12 +560,12 @@ class UserBuildResourceImpl @Autowired constructor( ): BuildId { var buildId: BuildId? = null var status = PipelineTriggerStatus.SUCCEED.name - var failReason = "" + var reason: String = PipelineTriggerReason.TRIGGER_SUCCESS.name try { buildId = action.invoke() } catch (ignored: Exception) { status = PipelineTriggerStatus.FAILED.name - failReason = ignored.message.toString() + reason = ignored.message.toString() throw ignored } finally { try { @@ -577,7 +578,7 @@ class UserBuildResourceImpl @Autowired constructor( eventSource = userId, triggerType = StartType.MANUAL.name, buildInfo = buildId, - failReason = failReason, + reason = reason, status = status ) ) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt index ed75ba6e469..be224086dbe 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt @@ -28,6 +28,8 @@ package com.tencent.devops.process.service import com.tencent.devops.common.api.exception.OperationException +import com.tencent.devops.common.api.pojo.I18Variable +import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.MessageUtil import com.tencent.devops.common.api.util.UUIDUtil import com.tencent.devops.common.client.Client @@ -38,6 +40,7 @@ import com.tencent.devops.common.pipeline.enums.StartType import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.common.service.BkTag import com.tencent.devops.common.web.utils.I18nUtil +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.model.process.tables.records.TPipelineRemoteAuthRecord import com.tencent.devops.process.api.service.ServiceBuildResource import com.tencent.devops.process.api.service.ServiceTriggerEventResource @@ -50,6 +53,7 @@ import com.tencent.devops.process.engine.service.PipelineRepositoryService import com.tencent.devops.process.pojo.BuildId import com.tencent.devops.process.pojo.PipelineRemoteToken import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.service.builds.PipelineBuildFacadeService import com.tencent.devops.process.utils.PIPELINE_START_REMOTE_USER_ID @@ -187,12 +191,12 @@ class PipelineRemoteAuthService @Autowired constructor( ): BuildId { var buildId: BuildId? = null var status = PipelineTriggerStatus.SUCCEED.name - var failReason = "" + var reason: String = PipelineTriggerReason.TRIGGER_SUCCESS.name try { buildId = action.invoke() } catch (ignored: Exception) { status = PipelineTriggerStatus.FAILED.name - failReason = ignored.message.toString() + reason = ignored.message.toString() throw ignored } finally { try { @@ -205,8 +209,18 @@ class PipelineRemoteAuthService @Autowired constructor( eventSource = eventSource, triggerType = StartType.REMOTE.name, buildInfo = buildId, - failReason = failReason, - status = status + reason = reason, + status = status, + eventDesc = JsonUtil.toJson( + I18Variable( + code = WebhookI18nConstants.REMOTE_START_EVENT_DESC, + params = listOf( + userId, + eventSource + ) + ), + false + ) ) ) } catch (ignored: Exception) { diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt index aa20e2ee1e8..7246305152e 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt @@ -61,6 +61,7 @@ import com.tencent.devops.process.pojo.pipeline.StartUpInfo import com.tencent.devops.process.pojo.pipeline.SubPipelineStartUpInfo import com.tencent.devops.process.pojo.pipeline.SubPipelineStatus import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.service.builds.PipelineBuildFacadeService import com.tencent.devops.process.service.pipeline.PipelineBuildService @@ -520,12 +521,12 @@ class SubPipelineStartUpService @Autowired constructor( ): BuildId { var buildId: BuildId? = null var status = PipelineTriggerStatus.SUCCEED.name - var failReason = "" + var reason: String = PipelineTriggerReason.TRIGGER_SUCCESS.name try { buildId = action.invoke() } catch (ignored: Exception) { status = PipelineTriggerStatus.FAILED.name - failReason = ignored.message.toString() + reason = ignored.message.toString() throw ignored } finally { try { @@ -549,7 +550,7 @@ class SubPipelineStartUpService @Autowired constructor( ), false ), - failReason = failReason, + reason = reason, status = status ) ) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt index 35716238cc8..2fc2db4bcad 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt @@ -116,6 +116,7 @@ import com.tencent.devops.process.pojo.pipeline.ModelDetail import com.tencent.devops.process.pojo.pipeline.ModelRecord import com.tencent.devops.process.pojo.pipeline.PipelineLatestBuild import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.service.BuildVariableService import com.tencent.devops.process.service.ParamFacadeService @@ -2511,12 +2512,12 @@ class PipelineBuildFacadeService( ): BuildId { var buildId: BuildId? = null var status = PipelineTriggerStatus.SUCCEED.name - var failReason = "" + var reason: String = PipelineTriggerReason.TRIGGER_SUCCESS.name try { buildId = action.invoke() } catch (ignored: Exception) { status = PipelineTriggerStatus.FAILED.name - failReason = ignored.message.toString() + reason = ignored.message.toString() throw ignored } finally { try { @@ -2529,7 +2530,7 @@ class PipelineBuildFacadeService( eventSource = userId, triggerType = StartType.TIME_TRIGGER.name, buildInfo = buildId, - failReason = failReason, + reason = reason, status = status ) ) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 3ffe5048f21..34466d4dd59 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -415,7 +415,7 @@ class PipelineTriggerEventService @Autowired constructor( triggerType: String = PipelineTriggerType.MANUAL.name, buildInfo: BuildId?, status: String = PipelineTriggerStatus.SUCCEED.name, - failReason: String? = null + reason: String? = null ) { logger.info("start save specific event|$projectId|$pipelineId|$userId|$triggerType") val pipelineInfo = client.get(ServicePipelineResource::class).getPipelineInfo( @@ -435,7 +435,7 @@ class PipelineTriggerEventService @Autowired constructor( userId = userId, buildNum = buildInfo?.num.toString(), triggerType = triggerType, - failReason = failReason + reason = reason ) } @@ -454,7 +454,7 @@ class PipelineTriggerEventService @Autowired constructor( triggerType: String, requestParams: Map?, eventDesc: String? = null, - failReason: String? + reason: String? ) { val eventId = getEventId() val requestId = MDC.get(TraceTag.BIZID) @@ -479,7 +479,7 @@ class PipelineTriggerEventService @Autowired constructor( buildId = buildId, buildNum = buildNum, pipelineName = pipelineName, - reason = failReason + reason = reason ), triggerEvent = PipelineTriggerEvent( eventId = eventId, @@ -501,6 +501,7 @@ class PipelineTriggerEventService @Autowired constructor( PipelineTriggerType.REMOTE.name -> WebhookI18nConstants.REMOTE_START_EVENT_DESC PipelineTriggerType.SERVICE.name -> WebhookI18nConstants.SERVICE_START_EVENT_DESC PipelineTriggerType.PIPELINE.name -> WebhookI18nConstants.PIPELINE_START_EVENT_DESC + PipelineTriggerType.TIME_TRIGGER.name -> WebhookI18nConstants.TIMING_START_EVENT_DESC else -> "" } diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index 7a5118afca4..25ccdf85b6e 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -384,7 +384,7 @@ bkGithubPrEventDesc=Pull request [!{1}] by {1} {2} bkSvnCommitEventDesc=Commit [{0}] pushed by {1} bkManualStartEventDesc=Manually triggered by {0} -bkRemoteStartEventDesc=Remote api triggered by {0} +bkRemoteStartEventDesc=Remote api triggered by {1} [{0}] bkServiceStartEventDesc=Pipeline invocation triggered by {0} invoke bkPipelinetartEventDesc=Pipeline invocation [{2}] triggered by {0} invoke bkTimingStartEventDesc=Timer triggered by {0} diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 83e5a933a07..a53ecd4ad25 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -384,7 +384,7 @@ bkGithubPrEventDesc=Pull request [{1}] 由 {1} {2} bkSvnCommitEventDesc=提交 [{0}] 由 {1} 推送 bkManualStartEventDesc={0} 手动触发 -bkRemoteStartEventDesc={0} 远程触发 +bkRemoteStartEventDesc={1} [{0}] 远程触发 bkServiceStartEventDesc={0} 触发的流水线调用 bkPipelinetartEventDesc={0} 触发的流水线 [{2}] 调用 bkTimingStartEventDesc={0} 定时触发 From d93a4b6cf04fec4abe430fa077d4aa28b62c0098 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 15 Nov 2023 11:14:03 +0800 Subject: [PATCH 122/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- support-files/i18n/process/message_en_US.properties | 2 +- support-files/i18n/process/message_zh_CN.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index 25ccdf85b6e..d72c8ce081f 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -386,7 +386,7 @@ bkSvnCommitEventDesc=Commit [{0}] pushed by {1}{0} bkRemoteStartEventDesc=Remote api triggered by {1} [{0}] bkServiceStartEventDesc=Pipeline invocation triggered by {0} invoke -bkPipelinetartEventDesc=Pipeline invocation [{2}] triggered by {0} invoke +bkPipelineStartEventDesc=Pipeline invocation [{2}] triggered by {0} invoke bkTimingStartEventDesc=Timer triggered by {0} bkEventReplayDesc=Event [{0}] replayed by {1} bkRepoTriggerEventTypeNotMatch=Event type mismatch diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index a53ecd4ad25..69afce7ef4d 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -386,7 +386,7 @@ bkSvnCommitEventDesc=提交 [{0}] 由 {1} bkManualStartEventDesc={0} 手动触发 bkRemoteStartEventDesc={1} [{0}] 远程触发 bkServiceStartEventDesc={0} 触发的流水线调用 -bkPipelinetartEventDesc={0} 触发的流水线 [{2}] 调用 +bkPipelineStartEventDesc={0} 触发的流水线 [{2}] 调用 bkTimingStartEventDesc={0} 定时触发 bkEventReplayDesc=事件 [{0}] 由 {1} 重放 bkRepoTriggerEventTypeNotMatch=事件类型不满足触发条件 From bee0f47145c8fb2afe4effe5bde5d27e7a19b843 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 15 Nov 2023 11:48:15 +0800 Subject: [PATCH 123/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/api/service/ServiceTriggerEventResource.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceTriggerEventResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceTriggerEventResource.kt index 20a43ee77b4..60bc48df3bc 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceTriggerEventResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceTriggerEventResource.kt @@ -44,7 +44,7 @@ import javax.ws.rs.core.MediaType interface ServiceTriggerEventResource { @ApiOperation("保存特殊触发事件") - @Path("projects/{projectId}/{pipelineId}/saveSpecificEvent") + @Path("projects/saveSpecificEvent") @POST fun saveSpecificEvent( @ApiParam("触发参数", required = true) From e77dc92d6ae28a251dbcc5db1a0fd6109957fd9c Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 16 Nov 2023 12:21:17 +0800 Subject: [PATCH 124/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webhook/enums/WebhookI18nConstants.kt | 2 +- .../apigw/v3/ApigwBuildResourceV3Impl.kt | 64 +--- .../apigw/v4/ApigwBuildResourceV4Impl.kt | 64 +--- .../service/ServiceTriggerEventResource.kt | 53 ---- .../trigger/PipelineTriggerEventBuilder.kt | 99 ++++++ .../pojo/trigger/PipelineTriggerType.kt | 2 +- .../tencent/devops/process/utils/Constants.kt | 2 + .../api/ServiceTriggerEventResourceImpl.kt | 58 ---- .../process/api/UserBuildResourceImpl.kt | 64 +--- .../service/PipelineRemoteAuthService.kt | 81 +---- .../service/SubPipelineStartUpService.kt | 104 +------ .../builds/PipelineBuildFacadeService.kt | 75 +---- .../trigger/PipelineTriggerEventAspect.kt | 288 ++++++++++++++++++ .../trigger/PipelineTriggerEventService.kt | 108 ------- 14 files changed, 443 insertions(+), 621 deletions(-) delete mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceTriggerEventResource.kt create mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventBuilder.kt delete mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt diff --git a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt index dc7bb8965c7..eecfed46836 100644 --- a/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt +++ b/src/backend/ci/core/common/common-webhook/api-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/enums/WebhookI18nConstants.kt @@ -68,7 +68,7 @@ object WebhookI18nConstants { const val REMOTE_START_EVENT_DESC = "bkRemoteStartEventDesc" // openApi触发 - const val SERVICE_START_EVENT_DESC = "bkServiceStartEventDesc" + const val OPENAPI_START_EVENT_DESC = "bkServiceStartEventDesc" // 流水线触发 const val PIPELINE_START_EVENT_DESC = "bkPipelineStartEventDesc" diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt index 468db0c092b..5e668490b1c 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwBuildResourceV3Impl.kt @@ -35,16 +35,12 @@ import com.tencent.devops.common.web.RestResource import com.tencent.devops.openapi.api.apigw.v3.ApigwBuildResourceV3 import com.tencent.devops.openapi.utils.ApiGatewayUtil import com.tencent.devops.process.api.service.ServiceBuildResource -import com.tencent.devops.process.api.service.ServiceTriggerEventResource import com.tencent.devops.process.pojo.BuildHistory import com.tencent.devops.process.pojo.BuildHistoryWithVars import com.tencent.devops.process.pojo.BuildId import com.tencent.devops.process.pojo.BuildManualStartupInfo import com.tencent.devops.process.pojo.BuildTaskPauseInfo import com.tencent.devops.process.pojo.pipeline.ModelDetail -import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent -import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason -import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -139,24 +135,15 @@ class ApigwBuildResourceV3Impl @Autowired constructor( buildNo: Int? ): Result { logger.info("OPENAPI_BUILD_V3|$userId|start|$projectId|$pipelineId|$values|$buildNo") - val buildId = saveTriggerEvent( + return client.get(ServiceBuildResource::class).manualStartupNew( userId = userId, projectId = projectId, pipelineId = pipelineId, - values = values, - action = { - client.get(ServiceBuildResource::class).manualStartupNew( - userId = userId, - projectId = projectId, - pipelineId = pipelineId, - values = values ?: emptyMap(), - buildNo = buildNo, - channelCode = apiGatewayUtil.getChannelCode(), - startType = StartType.SERVICE - ).data - } + values = values ?: emptyMap(), + buildNo = buildNo, + channelCode = apiGatewayUtil.getChannelCode(), + startType = StartType.SERVICE ) - return Result(buildId) } override fun stop( @@ -295,47 +282,6 @@ class ApigwBuildResourceV3Impl @Autowired constructor( ) } - private fun saveTriggerEvent( - userId: String, - projectId: String, - pipelineId: String, - values: Map?, - action: () -> BuildId? - ): BuildId { - var buildId: BuildId? = null - var status = PipelineTriggerStatus.SUCCEED.name - var reason: String = PipelineTriggerReason.TRIGGER_SUCCESS.name - try { - buildId = action.invoke() - } catch (ignored: Exception) { - status = PipelineTriggerStatus.FAILED.name - reason = ignored.message.toString() - throw ignored - } finally { - try { - client.get(ServiceTriggerEventResource::class).saveSpecificEvent( - specificEvent = PipelineSpecificEvent( - projectId = projectId, - pipelineId = pipelineId, - requestParams = values, - userId = userId, - eventSource = userId, - triggerType = StartType.SERVICE.name, - buildInfo = buildId, - reason = reason, - status = status - ) - ) - } catch (ignored: Exception) { - logger.warn( - "OPENAPI_BUILD_V3|fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", - ignored - ) - } - } - return buildId!! - } - companion object { private val logger = LoggerFactory.getLogger(ApigwBuildResourceV3Impl::class.java) } diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt index 065d23fc4cd..975e2a9b24c 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwBuildResourceV4Impl.kt @@ -41,7 +41,6 @@ import com.tencent.devops.openapi.api.apigw.v4.ApigwBuildResourceV4 import com.tencent.devops.openapi.service.IndexService import com.tencent.devops.openapi.utils.ApiGatewayUtil import com.tencent.devops.process.api.service.ServiceBuildResource -import com.tencent.devops.process.api.service.ServiceTriggerEventResource import com.tencent.devops.process.pojo.BuildHistory import com.tencent.devops.process.pojo.BuildHistoryRemark import com.tencent.devops.process.pojo.BuildHistoryWithVars @@ -50,9 +49,6 @@ import com.tencent.devops.process.pojo.BuildManualStartupInfo import com.tencent.devops.process.pojo.BuildTaskPauseInfo import com.tencent.devops.process.pojo.ReviewParam import com.tencent.devops.process.pojo.pipeline.ModelRecord -import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent -import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason -import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -176,24 +172,15 @@ class ApigwBuildResourceV4Impl @Autowired constructor( buildNo: Int? ): Result { logger.info("OPENAPI_BUILD_V4|$userId|start|$projectId|$pipelineId|$values|$buildNo") - val buildId = saveTriggerEvent( + return client.get(ServiceBuildResource::class).manualStartupNew( userId = userId, projectId = projectId, pipelineId = pipelineId, - values = values, - action = { - client.get(ServiceBuildResource::class).manualStartupNew( - userId = userId, - projectId = projectId, - pipelineId = pipelineId, - values = values ?: emptyMap(), - buildNo = buildNo, - channelCode = apiGatewayUtil.getChannelCode(), - startType = StartType.SERVICE - ).data - } + values = values ?: emptyMap(), + buildNo = buildNo, + channelCode = apiGatewayUtil.getChannelCode(), + startType = StartType.SERVICE ) - return Result(buildId) } override fun stop( @@ -441,47 +428,6 @@ class ApigwBuildResourceV4Impl @Autowired constructor( ?: throw ParamBlankException("Invalid buildNumber") } - private fun saveTriggerEvent( - userId: String, - projectId: String, - pipelineId: String, - values: Map?, - action: () -> BuildId? - ): BuildId { - var buildId: BuildId? = null - var status = PipelineTriggerStatus.SUCCEED.name - var reason: String = PipelineTriggerReason.TRIGGER_SUCCESS.name - try { - buildId = action.invoke() - } catch (ignored: Exception) { - status = PipelineTriggerStatus.FAILED.name - reason = ignored.message.toString() - throw ignored - } finally { - try { - client.get(ServiceTriggerEventResource::class).saveSpecificEvent( - specificEvent = PipelineSpecificEvent( - projectId = projectId, - pipelineId = pipelineId, - requestParams = values, - userId = userId, - eventSource = userId, - triggerType = StartType.SERVICE.name, - buildInfo = buildId, - reason = reason, - status = status - ) - ) - } catch (ignored: Exception) { - logger.warn( - "OPENAPI_BUILD_V4|fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", - ignored - ) - } - } - return buildId!! - } - companion object { private val logger = LoggerFactory.getLogger(ApigwBuildResourceV4Impl::class.java) } diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceTriggerEventResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceTriggerEventResource.kt deleted file mode 100644 index 60bc48df3bc..00000000000 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/service/ServiceTriggerEventResource.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package com.tencent.devops.process.api.service - -import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent -import io.swagger.annotations.Api -import io.swagger.annotations.ApiOperation -import io.swagger.annotations.ApiParam -import javax.ws.rs.Consumes -import javax.ws.rs.POST -import javax.ws.rs.Path -import javax.ws.rs.Produces -import javax.ws.rs.core.MediaType - -@Api(tags = ["SERVICE_TRIGGER_EVENT"], description = "服务-触发事件") -@Path("/service/trigger/event") -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -interface ServiceTriggerEventResource { - - @ApiOperation("保存特殊触发事件") - @Path("projects/saveSpecificEvent") - @POST - fun saveSpecificEvent( - @ApiParam("触发参数", required = true) - specificEvent: PipelineSpecificEvent - ): Boolean -} diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventBuilder.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventBuilder.kt new file mode 100644 index 00000000000..42f9081661c --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerEventBuilder.kt @@ -0,0 +1,99 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.pojo.trigger + +import java.time.LocalDateTime + +class PipelineTriggerEventBuilder { + private var requestId: String? = null + private var projectId: String? = null + private var eventId: Long? = null + private var triggerType: String? = null + private var eventSource: String? = null + private var eventType: String? = null + private var triggerUser: String? = null + private var eventDesc: String? = null + private var requestParams: Map? = null + private var createTime: LocalDateTime? = null + + fun requestId(requestId: String) = apply { + this.requestId = requestId + } + + fun projectId(projectId: String) = apply { + this.projectId = projectId + } + + fun eventId(eventId: Long) = apply { + this.eventId = eventId + } + + fun triggerType(triggerType: String) = apply { + this.triggerType = triggerType + } + + fun eventSource(eventSource: String) = apply { + this.eventSource = eventSource + } + + fun eventType(eventType: String) = apply { + this.eventType = eventType + } + + fun triggerUser(triggerUser: String) = apply { + this.triggerUser = triggerUser + } + + fun eventDesc(eventDesc: String) = apply { + this.eventDesc = eventDesc + } + + fun requestParams(requestParams: Map) = apply { + this.requestParams = requestParams + } + + fun createTime(createTime: LocalDateTime) = apply { + this.createTime = createTime + } + + fun build(): PipelineTriggerEvent { + return PipelineTriggerEvent( + requestId = requestId!!, + projectId = projectId, + eventId = eventId, + triggerType = triggerType!!, + eventSource = eventSource!!, + eventType = eventType!!, + triggerUser = triggerUser!!, + eventDesc = eventDesc!!, + requestParams = requestParams, + createTime = createTime!! + ) + } +} diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt index c02a960df24..6f91d5ed6f9 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineTriggerType.kt @@ -65,7 +65,7 @@ enum class PipelineTriggerType { // 服务触发 @ApiModelProperty("服务触发") - SERVICE, + OPENAPI, // 流水线触发 @ApiModelProperty("流水线触发") diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/utils/Constants.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/utils/Constants.kt index 2de3db01658..fc066eae3c6 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/utils/Constants.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/utils/Constants.kt @@ -30,6 +30,7 @@ package com.tencent.devops.process.utils const val PIPELINE_VERSION = "BK_CI_PIPELINE_VERSION" // "pipeline.version" const val PIPELINE_START_PARENT_PROJECT_ID = "BK_CI_PARENT_PROJECT_ID" const val PIPELINE_START_PARENT_PIPELINE_ID = "BK_CI_PARENT_PIPELINE_ID" // "pipeline.start.parent.pipeline.id" +const val PIPELINE_START_PARENT_PIPELINE_NAME = "BK_CI_PARENT_PIPELINE_NAME" const val PIPELINE_START_PARENT_BUILD_ID = "BK_CI_PARENT_BUILD_ID" // "pipeline.start.parent.build.id" const val PIPELINE_START_PARENT_BUILD_TASK_ID = "BK_CI_PARENT_BUILD_TASK_ID" // "pipeline.start.parent.build.task.id" const val PIPELINE_START_USER_ID = "BK_CI_START_USER_ID" // "pipeline.start.user.id" @@ -40,6 +41,7 @@ const val PIPELINE_START_SERVICE_USER_ID = "BK_CI_START_SERVICE_USER_ID" // "pip const val PIPELINE_START_MANUAL_USER_ID = "BK_CI_START_MANUAL_USER_ID" // "pipeline.start.manual.user.id" const val PIPELINE_START_TIME_TRIGGER_USER_ID = "BK_CI_START_TIME_TRIGGER_USER_ID" const val PIPELINE_START_REMOTE_USER_ID = "BK_CI_START_REMOTE_USER_ID" +const val PIPELINE_START_REMOTE_CLIENT_IP = "BK_CI_START_REMOTE_CLIENT_IP" const val PIPELINE_START_TYPE = "BK_CI_START_TYPE" // "pipeline.start.type" const val PIPELINE_START_CHANNEL = "BK_CI_START_CHANNEL" // "pipeline.start.channel" const val PIPELINE_BUILD_NUM = "BK_CI_BUILD_NUM" // "pipeline.build.num"// 当前构建的唯一标示ID,从1开始自增 diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt deleted file mode 100644 index 12e3fde972b..00000000000 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/ServiceTriggerEventResourceImpl.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package com.tencent.devops.process.api - -import com.tencent.devops.common.web.RestResource -import com.tencent.devops.process.api.service.ServiceTriggerEventResource -import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent -import com.tencent.devops.process.trigger.PipelineTriggerEventService -import org.springframework.beans.factory.annotation.Autowired - -@Suppress("ALL") -@RestResource -class ServiceTriggerEventResourceImpl @Autowired constructor( - private val pipelineTriggerEventService: PipelineTriggerEventService -) : ServiceTriggerEventResource { - override fun saveSpecificEvent(specificEvent: PipelineSpecificEvent): Boolean { - with(specificEvent) { - pipelineTriggerEventService.saveSpecificEvent( - projectId = projectId, - pipelineId = pipelineId, - requestParams = requestParams, - userId = userId, - eventSource = eventSource, - eventDesc = eventDesc, - triggerType = triggerType, - buildInfo = buildInfo, - status = status, - reason = reason - ) - } - return true - } -} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt index 4e95ba4a311..f74a1a9e799 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt @@ -31,7 +31,6 @@ import com.tencent.devops.common.api.exception.ParamBlankException import com.tencent.devops.common.api.pojo.BuildHistoryPage import com.tencent.devops.common.api.pojo.IdValue import com.tencent.devops.common.api.pojo.Result -import com.tencent.devops.common.client.Client import com.tencent.devops.common.pipeline.enums.BuildStatus import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.common.pipeline.enums.StartType @@ -39,7 +38,6 @@ import com.tencent.devops.common.pipeline.pojo.BuildParameters import com.tencent.devops.common.pipeline.pojo.StageReviewRequest import com.tencent.devops.common.pipeline.pojo.element.Element import com.tencent.devops.common.web.RestResource -import com.tencent.devops.process.api.service.ServiceTriggerEventResource import com.tencent.devops.process.api.user.UserBuildResource import com.tencent.devops.process.pojo.BuildHistory import com.tencent.devops.process.pojo.BuildHistoryRemark @@ -48,9 +46,6 @@ import com.tencent.devops.process.pojo.BuildManualStartupInfo import com.tencent.devops.process.pojo.ReviewParam import com.tencent.devops.process.pojo.pipeline.ModelDetail import com.tencent.devops.process.pojo.pipeline.ModelRecord -import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent -import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason -import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.service.PipelineRecentUseService import com.tencent.devops.process.service.builds.PipelineBuildFacadeService import com.tencent.devops.process.service.builds.PipelineBuildMaintainFacadeService @@ -66,8 +61,7 @@ class UserBuildResourceImpl @Autowired constructor( private val pipelineBuildMaintainFacadeService: PipelineBuildMaintainFacadeService, private val pipelineBuildFacadeService: PipelineBuildFacadeService, private val pipelinePauseBuildFacadeService: PipelinePauseBuildFacadeService, - private val pipelineRecentUseService: PipelineRecentUseService, - private val client: Client + private val pipelineRecentUseService: PipelineRecentUseService ) : UserBuildResource { override fun manualStartupInfo( @@ -101,23 +95,15 @@ class UserBuildResourceImpl @Autowired constructor( triggerReviewers: List? ): Result { checkParam(userId, projectId, pipelineId) - val manualStartup = saveTriggerEvent( + val manualStartup = pipelineBuildFacadeService.buildManualStartup( userId = userId, + startType = StartType.MANUAL, projectId = projectId, pipelineId = pipelineId, values = values, - action = { - pipelineBuildFacadeService.buildManualStartup( - userId = userId, - startType = StartType.MANUAL, - projectId = projectId, - pipelineId = pipelineId, - values = values, - channelCode = ChannelCode.BS, - buildNo = buildNo, - triggerReviewers = triggerReviewers - ) - } + channelCode = ChannelCode.BS, + buildNo = buildNo, + triggerReviewers = triggerReviewers ) pipelineRecentUseService.record(userId, projectId, pipelineId) return Result(manualStartup) @@ -551,44 +537,6 @@ class UserBuildResourceImpl @Autowired constructor( } } - private fun saveTriggerEvent( - userId: String, - projectId: String, - pipelineId: String, - values: Map?, - action: () -> BuildId? - ): BuildId { - var buildId: BuildId? = null - var status = PipelineTriggerStatus.SUCCEED.name - var reason: String = PipelineTriggerReason.TRIGGER_SUCCESS.name - try { - buildId = action.invoke() - } catch (ignored: Exception) { - status = PipelineTriggerStatus.FAILED.name - reason = ignored.message.toString() - throw ignored - } finally { - try { - client.get(ServiceTriggerEventResource::class).saveSpecificEvent( - specificEvent = PipelineSpecificEvent( - projectId = projectId, - pipelineId = pipelineId, - requestParams = values, - userId = userId, - eventSource = userId, - triggerType = StartType.MANUAL.name, - buildInfo = buildId, - reason = reason, - status = status - ) - ) - } catch (ignored: Exception) { - logger.warn("fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) - } - } - return buildId!! - } - companion object { private val logger = LoggerFactory.getLogger(UserBuildResourceImpl::class.java) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt index be224086dbe..841fdc0e883 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineRemoteAuthService.kt @@ -28,8 +28,6 @@ package com.tencent.devops.process.service import com.tencent.devops.common.api.exception.OperationException -import com.tencent.devops.common.api.pojo.I18Variable -import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.MessageUtil import com.tencent.devops.common.api.util.UUIDUtil import com.tencent.devops.common.client.Client @@ -40,10 +38,8 @@ import com.tencent.devops.common.pipeline.enums.StartType import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.common.service.BkTag import com.tencent.devops.common.web.utils.I18nUtil -import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.model.process.tables.records.TPipelineRemoteAuthRecord import com.tencent.devops.process.api.service.ServiceBuildResource -import com.tencent.devops.process.api.service.ServiceTriggerEventResource import com.tencent.devops.process.constant.ProcessMessageCode.BK_REMOTE_CALL_SOURCE_IP import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_GENERATE_REMOTE_TRIGGER_TOKEN_FAILED import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_NO_MATCHING_PIPELINE @@ -52,10 +48,7 @@ import com.tencent.devops.process.engine.control.lock.PipelineRemoteAuthLock import com.tencent.devops.process.engine.service.PipelineRepositoryService import com.tencent.devops.process.pojo.BuildId import com.tencent.devops.process.pojo.PipelineRemoteToken -import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent -import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason -import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus -import com.tencent.devops.process.service.builds.PipelineBuildFacadeService +import com.tencent.devops.process.utils.PIPELINE_START_REMOTE_CLIENT_IP import com.tencent.devops.process.utils.PIPELINE_START_REMOTE_USER_ID import com.tencent.devops.process.utils.PIPELINE_START_TASK_ID import org.jooq.DSLContext @@ -68,7 +61,6 @@ import org.springframework.stereotype.Service class PipelineRemoteAuthService @Autowired constructor( private val dslContext: DSLContext, private val pipelineRemoteAuthDao: PipelineRemoteAuthDao, - private val pipelineBuildFacadeService: PipelineBuildFacadeService, private val pipelineReportService: PipelineRepositoryService, private val redisOperation: RedisOperation, private val client: Client, @@ -126,6 +118,9 @@ class PipelineRemoteAuthService @Autowired constructor( if (!startUser.isNullOrBlank()) { vals[PIPELINE_START_REMOTE_USER_ID] = startUser } + if (!sourceIp.isNullOrBlank()) { + vals[PIPELINE_START_REMOTE_CLIENT_IP] = sourceIp + } logger.info("Start the pipeline remotely of $userId ${pipeline.pipelineId} of project ${pipeline.projectId}") // #5779 为兼容多集群的场景。流水线的启动需要路由到项目对应的集群。此处携带X-DEVOPS-PROJECT-ID头重新请求网关,由网关路由到项目对应的集群 /* #7095 因Bktag设置了router_tag 默认为本集群,导致网关不会根据X-DEVOPS-PROJECT-ID路由。故直接根据项目获取router @@ -134,24 +129,15 @@ class PipelineRemoteAuthService @Autowired constructor( return bkTag.invokeByTag(projectConsulTag) { logger.info("start call service api ${pipeline.projectId} ${pipeline.pipelineId}, " + "$projectConsulTag ${bkTag.getFinalTag()}") - val buildId = saveTriggerEvent( + val buildId = client.getGateway(ServiceBuildResource::class).manualStartupNew( userId = userId!!, projectId = pipeline.projectId, pipelineId = pipeline.pipelineId, - eventSource = sourceIp ?: "", values = vals.toMap(), - action = { - client.getGateway(ServiceBuildResource::class).manualStartupNew( - userId = userId!!, - projectId = pipeline.projectId, - pipelineId = pipeline.pipelineId, - values = vals.toMap(), - channelCode = ChannelCode.BS, - startType = StartType.REMOTE, - buildNo = null - ).data!! - } - ) + channelCode = ChannelCode.BS, + startType = StartType.REMOTE, + buildNo = null + ).data!! // 在远程触发器job中打印sourcIp val taskId = buildVariableService.getVariable( projectId = pipeline.projectId, @@ -181,55 +167,6 @@ class PipelineRemoteAuthService @Autowired constructor( } } - private fun saveTriggerEvent( - userId: String, - eventSource: String, - projectId: String, - pipelineId: String, - values: Map?, - action: () -> BuildId? - ): BuildId { - var buildId: BuildId? = null - var status = PipelineTriggerStatus.SUCCEED.name - var reason: String = PipelineTriggerReason.TRIGGER_SUCCESS.name - try { - buildId = action.invoke() - } catch (ignored: Exception) { - status = PipelineTriggerStatus.FAILED.name - reason = ignored.message.toString() - throw ignored - } finally { - try { - client.get(ServiceTriggerEventResource::class).saveSpecificEvent( - specificEvent = PipelineSpecificEvent( - projectId = projectId, - pipelineId = pipelineId, - requestParams = values, - userId = userId, - eventSource = eventSource, - triggerType = StartType.REMOTE.name, - buildInfo = buildId, - reason = reason, - status = status, - eventDesc = JsonUtil.toJson( - I18Variable( - code = WebhookI18nConstants.REMOTE_START_EVENT_DESC, - params = listOf( - userId, - eventSource - ) - ), - false - ) - ) - ) - } catch (ignored: Exception) { - logger.warn("fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) - } - } - return buildId!! - } - companion object { private val logger = LoggerFactory.getLogger(PipelineRemoteAuthService::class.java) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt index 7246305152e..19ac626dbcf 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt @@ -29,12 +29,9 @@ package com.tencent.devops.process.service import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.api.exception.OperationException -import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.common.api.util.EnvUtils -import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.auth.api.AuthPermission -import com.tencent.devops.common.client.Client import com.tencent.devops.common.pipeline.container.TriggerContainer import com.tencent.devops.common.pipeline.enums.BuildFormPropertyType import com.tencent.devops.common.pipeline.enums.ChannelCode @@ -45,8 +42,6 @@ import com.tencent.devops.common.pipeline.pojo.element.SubPipelineCallElement import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildAtomElement import com.tencent.devops.common.pipeline.pojo.element.market.MarketBuildLessAtomElement import com.tencent.devops.common.web.utils.I18nUtil -import com.tencent.devops.common.webhook.enums.WebhookI18nConstants -import com.tencent.devops.process.api.service.ServiceTriggerEventResource import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_SUB_PIPELINE_NOT_ALLOWED_CIRCULAR_CALL import com.tencent.devops.process.engine.compatibility.BuildParametersCompatibilityTransformer @@ -54,21 +49,18 @@ import com.tencent.devops.process.engine.service.PipelineRepositoryService import com.tencent.devops.process.engine.service.PipelineRuntimeService import com.tencent.devops.process.engine.service.PipelineTaskService import com.tencent.devops.process.permission.PipelinePermissionService -import com.tencent.devops.process.pojo.BuildId import com.tencent.devops.process.pojo.PipelineId import com.tencent.devops.process.pojo.pipeline.ProjectBuildId import com.tencent.devops.process.pojo.pipeline.StartUpInfo import com.tencent.devops.process.pojo.pipeline.SubPipelineStartUpInfo import com.tencent.devops.process.pojo.pipeline.SubPipelineStatus -import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent -import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason -import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.service.builds.PipelineBuildFacadeService import com.tencent.devops.process.service.pipeline.PipelineBuildService import com.tencent.devops.process.utils.PIPELINE_START_CHANNEL import com.tencent.devops.process.utils.PIPELINE_START_PARENT_BUILD_ID import com.tencent.devops.process.utils.PIPELINE_START_PARENT_BUILD_TASK_ID import com.tencent.devops.process.utils.PIPELINE_START_PARENT_PIPELINE_ID +import com.tencent.devops.process.utils.PIPELINE_START_PARENT_PIPELINE_NAME import com.tencent.devops.process.utils.PIPELINE_START_PARENT_PROJECT_ID import com.tencent.devops.process.utils.PIPELINE_START_PIPELINE_USER_ID import com.tencent.devops.process.utils.PIPELINE_START_USER_ID @@ -91,8 +83,7 @@ class SubPipelineStartUpService @Autowired constructor( private val subPipelineStatusService: SubPipelineStatusService, private val pipelineTaskService: PipelineTaskService, private val buildParamCompatibilityTransformer: BuildParametersCompatibilityTransformer, - private val pipelinePermissionService: PipelinePermissionService, - private val client: Client + private val pipelinePermissionService: PipelinePermissionService ) { companion object { @@ -241,6 +232,8 @@ class SubPipelineStartUpService @Autowired constructor( BuildParameters(key = PIPELINE_START_PARENT_PROJECT_ID, value = parentProjectId) params[PIPELINE_START_PARENT_PIPELINE_ID] = BuildParameters(key = PIPELINE_START_PARENT_PIPELINE_ID, value = parentPipelineId) + params[PIPELINE_START_PARENT_PIPELINE_ID] = + BuildParameters(key = PIPELINE_START_PARENT_PIPELINE_NAME, value = parentPipelineInfo.pipelineName) params[PIPELINE_START_PARENT_BUILD_ID] = BuildParameters(key = PIPELINE_START_PARENT_BUILD_ID, value = parentBuildId) params[PIPELINE_START_PARENT_BUILD_TASK_ID] = @@ -254,37 +247,25 @@ class SubPipelineStartUpService @Autowired constructor( // 校验父流水线最后修改人是否有子流水线执行权限 checkPermission(userId = parentPipelineInfo.lastModifyUser, projectId = projectId, pipelineId = pipelineId) // 子流水线的调用不受频率限制 - val subBuildId = saveTriggerEvent( - userId = userId, - projectId = projectId, - pipelineId = pipelineId, - values = params.mapValues { it.value.value.toString() }, - parentProjectId = parentProjectId, - parentPipelineId = parentPipelineId, - parentBuildId = parentBuildId, - parentPipelineName = parentPipelineInfo.pipelineName, - action = { - pipelineBuildService.startPipeline( - userId = readyToBuildPipelineInfo.lastModifyUser, - pipeline = readyToBuildPipelineInfo, - startType = StartType.PIPELINE, - pipelineParamMap = params, - channelCode = channelCode, - isMobile = isMobile, - model = model, - frequencyLimit = false - ) - } - ) + val subBuildId = pipelineBuildService.startPipeline( + userId = readyToBuildPipelineInfo.lastModifyUser, + pipeline = readyToBuildPipelineInfo, + startType = StartType.PIPELINE, + pipelineParamMap = params, + channelCode = channelCode, + isMobile = isMobile, + model = model, + frequencyLimit = false + ).id // 更新父流水线关联子流水线构建id pipelineTaskService.updateSubBuildId( projectId = parentProjectId, buildId = parentBuildId, taskId = parentTaskId, - subBuildId = subBuildId.id, + subBuildId = subBuildId, subProjectId = readyToBuildPipelineInfo.projectId ) - return subBuildId.id + return subBuildId } finally { logger.info("It take(${System.currentTimeMillis() - startEpoch})ms to start sub-pipeline($pipelineId)") } @@ -507,57 +488,4 @@ class SubPipelineStartUpService @Autowired constructor( fun getSubPipelineStatus(projectId: String, buildId: String): Result { return Result(subPipelineStatusService.getSubPipelineStatus(projectId, buildId)) } - - private fun saveTriggerEvent( - userId: String, - projectId: String, - pipelineId: String, - values: Map?, - parentProjectId: String, - parentPipelineId: String, - parentBuildId: String, - parentPipelineName: String, - action: () -> BuildId? - ): BuildId { - var buildId: BuildId? = null - var status = PipelineTriggerStatus.SUCCEED.name - var reason: String = PipelineTriggerReason.TRIGGER_SUCCESS.name - try { - buildId = action.invoke() - } catch (ignored: Exception) { - status = PipelineTriggerStatus.FAILED.name - reason = ignored.message.toString() - throw ignored - } finally { - try { - client.get(ServiceTriggerEventResource::class).saveSpecificEvent( - specificEvent = PipelineSpecificEvent( - projectId = projectId, - pipelineId = pipelineId, - requestParams = values, - userId = userId, - eventSource = parentPipelineId, - triggerType = StartType.PIPELINE.name, - buildInfo = buildId, - eventDesc = JsonUtil.toJson( - I18Variable( - code = WebhookI18nConstants.PIPELINE_START_EVENT_DESC, - params = listOf( - userId, - "/console/pipeline/$parentProjectId/$parentPipelineId/detail/$parentBuildId", - parentPipelineName - ) - ), - false - ), - reason = reason, - status = status - ) - ) - } catch (ignored: Exception) { - logger.warn("fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) - } - } - return buildId!! - } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt index 2fc2db4bcad..7d925b61228 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/builds/PipelineBuildFacadeService.kt @@ -39,7 +39,6 @@ import com.tencent.devops.common.api.pojo.SimpleResult import com.tencent.devops.common.api.util.MessageUtil import com.tencent.devops.common.api.util.PageUtil import com.tencent.devops.common.auth.api.AuthPermission -import com.tencent.devops.common.client.Client import com.tencent.devops.common.event.dispatcher.pipeline.PipelineEventDispatcher import com.tencent.devops.common.event.enums.ActionType import com.tencent.devops.common.log.pojo.message.LogMessage @@ -64,7 +63,6 @@ import com.tencent.devops.common.pipeline.utils.BuildStatusSwitcher import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.common.service.utils.HomeHostUtil import com.tencent.devops.common.web.utils.I18nUtil -import com.tencent.devops.process.api.service.ServiceTriggerEventResource import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.constant.ProcessMessageCode.BK_BUILD_HISTORY import com.tencent.devops.process.constant.ProcessMessageCode.BK_BUILD_STATUS @@ -115,9 +113,6 @@ import com.tencent.devops.process.pojo.VmInfo import com.tencent.devops.process.pojo.pipeline.ModelDetail import com.tencent.devops.process.pojo.pipeline.ModelRecord import com.tencent.devops.process.pojo.pipeline.PipelineLatestBuild -import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent -import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason -import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus import com.tencent.devops.process.service.BuildVariableService import com.tencent.devops.process.service.ParamFacadeService import com.tencent.devops.process.service.PipelineTaskPauseService @@ -168,8 +163,7 @@ class PipelineBuildFacadeService( private val buildParamCompatibilityTransformer: BuildParametersCompatibilityTransformer, private val pipelineRedisService: PipelineRedisService, private val pipelineRetryFacadeService: PipelineRetryFacadeService, - private val webhookBuildParameterService: WebhookBuildParameterService, - private val client: Client + private val webhookBuildParameterService: WebhookBuildParameterService ) { @Value("\${pipeline.build.cancel.intervalLimitTime:60}") @@ -701,26 +695,17 @@ class PipelineBuildFacadeService( val triggerContainer = model.stages[0].containers[0] as TriggerContainer val paramPamp = buildParamCompatibilityTransformer.parseTriggerParam(triggerContainer.params, parameters) - val buildId = saveTriggerEvent( + return pipelineBuildService.startPipeline( userId = userId, - projectId = projectId, - pipelineId = pipelineId, - values = paramPamp.mapValues { it.value.value.toString() }, - action = { - pipelineBuildService.startPipeline( - userId = userId, - pipeline = pipeline, - startType = StartType.TIME_TRIGGER, - pipelineParamMap = paramPamp, - channelCode = pipeline.channelCode, - isMobile = false, - model = model, - signPipelineVersion = null, - frequencyLimit = false - ) - } - ) - return buildId.id + pipeline = pipeline, + startType = StartType.TIME_TRIGGER, + pipelineParamMap = paramPamp, + channelCode = pipeline.channelCode, + isMobile = false, + model = model, + signPipelineVersion = null, + frequencyLimit = false + ).id } finally { logger.info("Timer| It take(${System.currentTimeMillis() - startEpoch})ms to start pipeline($pipelineId)") } @@ -2502,42 +2487,4 @@ class PipelineBuildFacadeService( checkManualReviewParamOut(item.valueType, item, value) } } - - private fun saveTriggerEvent( - userId: String, - projectId: String, - pipelineId: String, - values: Map?, - action: () -> BuildId - ): BuildId { - var buildId: BuildId? = null - var status = PipelineTriggerStatus.SUCCEED.name - var reason: String = PipelineTriggerReason.TRIGGER_SUCCESS.name - try { - buildId = action.invoke() - } catch (ignored: Exception) { - status = PipelineTriggerStatus.FAILED.name - reason = ignored.message.toString() - throw ignored - } finally { - try { - client.get(ServiceTriggerEventResource::class).saveSpecificEvent( - specificEvent = PipelineSpecificEvent( - projectId = projectId, - pipelineId = pipelineId, - requestParams = values, - userId = userId, - eventSource = userId, - triggerType = StartType.TIME_TRIGGER.name, - buildInfo = buildId, - reason = reason, - status = status - ) - ) - } catch (ignored: Exception) { - logger.warn("fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored) - } - } - return buildId!! - } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt new file mode 100644 index 00000000000..53a1af65ea9 --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt @@ -0,0 +1,288 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.trigger + +import com.tencent.devops.common.api.pojo.I18Variable +import com.tencent.devops.common.pipeline.enums.ChannelCode +import com.tencent.devops.common.pipeline.enums.StartType +import com.tencent.devops.common.service.trace.TraceTag +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants.MANUAL_START_EVENT_DESC +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants.OPENAPI_START_EVENT_DESC +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants.PIPELINE_START_EVENT_DESC +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants.REMOTE_START_EVENT_DESC +import com.tencent.devops.common.webhook.enums.WebhookI18nConstants.TIMING_START_EVENT_DESC +import com.tencent.devops.process.engine.pojo.PipelineInfo +import com.tencent.devops.process.pojo.BuildId +import com.tencent.devops.process.pojo.trigger.PipelineTriggerDetail +import com.tencent.devops.process.pojo.trigger.PipelineTriggerDetailBuilder +import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent +import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventBuilder +import com.tencent.devops.process.pojo.trigger.PipelineTriggerReason +import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus +import com.tencent.devops.process.pojo.trigger.PipelineTriggerType +import com.tencent.devops.process.utils.PIPELINE_RETRY_BUILD_ID +import com.tencent.devops.process.utils.PIPELINE_START_PARENT_BUILD_ID +import com.tencent.devops.process.utils.PIPELINE_START_PARENT_PIPELINE_ID +import com.tencent.devops.process.utils.PIPELINE_START_PARENT_PIPELINE_NAME +import com.tencent.devops.process.utils.PIPELINE_START_PARENT_PROJECT_ID +import com.tencent.devops.process.utils.PIPELINE_START_REMOTE_CLIENT_IP +import org.aspectj.lang.ProceedingJoinPoint +import org.aspectj.lang.annotation.Around +import org.aspectj.lang.annotation.Aspect +import org.aspectj.lang.reflect.MethodSignature +import org.slf4j.LoggerFactory +import org.slf4j.MDC +import org.springframework.stereotype.Service +import java.time.LocalDateTime + +@Service +@Aspect +class PipelineTriggerEventAspect( + private val triggerEventService: PipelineTriggerEventService +) { + + companion object { + private val logger = LoggerFactory.getLogger(PipelineTriggerEventAspect::class.java) + } + + @Around("execution(* com.tencent.devops.process.service.pipeline.PipelineBuildService.startPipeline(..))") + fun aroundStartPipeline(pjp: ProceedingJoinPoint): Any? { + var result: Any? = null + var exception: Throwable? = null + try { + result = pjp.proceed() + return result + } catch (e: Throwable) { + exception = e + throw e + } finally { + saveTriggerEvent(pjp = pjp, result = result, exception = exception) + } + } + + private fun saveTriggerEvent(pjp: ProceedingJoinPoint, result: Any?, exception: Throwable?) { + try { + // 参数value + val parameterValue = pjp.args + // 参数key + val parameterNames = (pjp.signature as MethodSignature).parameterNames + var pipeline: PipelineInfo? = null + var userId: String? = null + var channelCode: ChannelCode? = null + var startValues: Map? = null + var startType: StartType? = null + + for (index in parameterValue.indices) { + when (parameterNames[index]) { + "pipeline" -> pipeline = parameterValue[index] as PipelineInfo + "userId" -> userId = parameterValue[index]?.toString() + "channelCode" -> channelCode = parameterValue[index] as ChannelCode + "startValues" -> startValues = parameterValue[index] as Map? + "startType" -> startType = parameterValue[index] as StartType + else -> Unit + } + } + // 判断是否应该跳过保存触发事件 + val isSkip = skipSaveTriggerEvent( + pipeline = pipeline, + userId = userId, + channelCode = channelCode, + startType = startType, + startValues = startValues, + result = result, + exception = exception + ) + if (isSkip) { + return + } + val triggerEvent = + buildTriggerEvent(userId = userId!!, startValues = startValues, startType = startType!!) ?: return + + val triggerDetail = buildTriggerDetail( + pipeline = pipeline!!, + eventId = triggerEvent.eventId!!, + result = result, + exception = exception + ) + triggerEventService.saveEvent( + triggerEvent = triggerEvent, + triggerDetail = triggerDetail + ) + } catch (ignored: Throwable) { + // 为了不影响业务,保存事件异常不抛出 + logger.warn("Failed to save trigger event", ignored) + } + } + + private fun skipSaveTriggerEvent( + pipeline: PipelineInfo?, + userId: String?, + channelCode: ChannelCode?, + startType: StartType?, + startValues: Map?, + result: Any?, + exception: Throwable? + ): Boolean { + if (result == null && exception == null) { + return true + } + if (pipeline == null || userId == null || channelCode == null || startType == null) { + return true + } + // 不是BS渠道的不需要记录,webhook的在webhook触发时已记录,在这不需要记录 + if (channelCode != ChannelCode.BS || startType == StartType.WEB_HOOK) { + return true + } + // 重试不需要记录 + return startValues != null && startValues[PIPELINE_RETRY_BUILD_ID] != null + } + + private fun buildTriggerEvent( + userId: String, + startValues: Map?, + startType: StartType + ): PipelineTriggerEvent? { + val requestId = MDC.get(TraceTag.BIZID) + val eventId = triggerEventService.getEventId() + val triggerEventBuilder = PipelineTriggerEventBuilder() + triggerEventBuilder.requestId(requestId) + triggerEventBuilder.eventId(eventId) + triggerEventBuilder.triggerUser(userId) + triggerEventBuilder.createTime(LocalDateTime.now()) + startValues?.let { triggerEventBuilder.requestParams(it) } + + when (startType) { + StartType.MANUAL -> { + triggerEventBuilder.triggerType(PipelineTriggerType.MANUAL.name) + triggerEventBuilder.eventSource(userId) + triggerEventBuilder.eventType(PipelineTriggerType.MANUAL.name) + triggerEventBuilder.eventDesc( + I18Variable( + code = MANUAL_START_EVENT_DESC, + params = listOf(userId) + ).toJsonStr() + ) + } + + StartType.REMOTE -> { + val eventSource = startValues?.get(PIPELINE_START_REMOTE_CLIENT_IP) ?: userId + triggerEventBuilder.triggerType(PipelineTriggerType.REMOTE.name) + triggerEventBuilder.eventSource(eventSource) + triggerEventBuilder.eventType(PipelineTriggerType.REMOTE.name) + triggerEventBuilder.eventDesc( + I18Variable( + code = REMOTE_START_EVENT_DESC, + params = listOf(userId) + ).toJsonStr() + ) + } + + StartType.TIME_TRIGGER -> { + triggerEventBuilder.triggerType(PipelineTriggerType.TIME_TRIGGER.name) + triggerEventBuilder.eventSource(userId) + triggerEventBuilder.eventType(PipelineTriggerType.TIME_TRIGGER.name) + triggerEventBuilder.eventDesc( + I18Variable( + code = TIMING_START_EVENT_DESC, + params = listOf(userId) + ).toJsonStr() + ) + } + + StartType.PIPELINE -> { + val parentProjectId = startValues?.get(PIPELINE_START_PARENT_PROJECT_ID) + val parentPipelineId = startValues?.get(PIPELINE_START_PARENT_PIPELINE_ID) + val parentPipelineName = startValues?.get(PIPELINE_START_PARENT_PIPELINE_NAME) + val parentBuildId = startValues?.get(PIPELINE_START_PARENT_BUILD_ID) + if (parentProjectId == null || parentPipelineId == null || + parentBuildId == null || parentPipelineName == null + ) { + return null + } + triggerEventBuilder.triggerType(PipelineTriggerType.PIPELINE.name) + triggerEventBuilder.eventSource(parentPipelineId) + triggerEventBuilder.eventType(PipelineTriggerType.PIPELINE.name) + triggerEventBuilder.eventDesc( + I18Variable( + code = PIPELINE_START_EVENT_DESC, + params = listOf( + userId, + "/console/pipeline/$parentProjectId/$parentPipelineId/detail/$parentBuildId", + parentPipelineName + ) + ).toJsonStr() + ) + } + // 目前channel为BS的,只有openapi的startType为service + StartType.SERVICE -> { + triggerEventBuilder.triggerType(PipelineTriggerType.OPENAPI.name) + triggerEventBuilder.eventSource(userId) + triggerEventBuilder.eventType(PipelineTriggerType.OPENAPI.name) + triggerEventBuilder.eventDesc( + I18Variable( + code = OPENAPI_START_EVENT_DESC, + params = listOf(userId) + ).toJsonStr() + ) + } + + else -> return null + } + return triggerEventBuilder.build() + } + + private fun buildTriggerDetail( + pipeline: PipelineInfo, + eventId: Long, + result: Any?, + exception: Throwable? + ): PipelineTriggerDetail { + val triggerDetailBuilder = PipelineTriggerDetailBuilder() + triggerDetailBuilder.eventId(eventId) + triggerDetailBuilder.projectId(pipeline.projectId) + triggerDetailBuilder.pipelineId(pipelineId = pipeline.pipelineId) + triggerDetailBuilder.pipelineName(pipeline.pipelineName) + + when { + result != null -> { + val buildId = result as BuildId + triggerDetailBuilder.status(PipelineTriggerStatus.SUCCEED.name) + triggerDetailBuilder.buildId(buildId.id) + triggerDetailBuilder.buildNum(buildId.num?.toString() ?: "") + } + + exception != null -> { + triggerDetailBuilder.status(PipelineTriggerStatus.FAILED.name) + triggerDetailBuilder.reason(PipelineTriggerReason.TRIGGER_FAILED.name) + triggerDetailBuilder.reasonDetail(exception.message ?: "unknown error") + } + } + return triggerDetailBuilder.build() + } +} diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt index 34466d4dd59..ff54a300504 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventService.kt @@ -37,19 +37,15 @@ import com.tencent.devops.common.api.util.JsonUtil import com.tencent.devops.common.api.util.PageUtil import com.tencent.devops.common.api.util.timestampmilli import com.tencent.devops.common.client.Client -import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.common.service.trace.TraceTag import com.tencent.devops.common.service.utils.HomeHostUtil import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.common.web.utils.I18nUtil.getCodeLanMessage -import com.tencent.devops.common.webhook.enums.WebhookI18nConstants import com.tencent.devops.common.webhook.enums.WebhookI18nConstants.EVENT_REPLAY_DESC -import com.tencent.devops.process.api.service.ServicePipelineResource import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_TRIGGER_DETAIL_NOT_FOUND import com.tencent.devops.process.constant.ProcessMessageCode.ERROR_TRIGGER_REPLAY_PIPELINE_NOT_EMPTY import com.tencent.devops.process.dao.PipelineTriggerEventDao -import com.tencent.devops.process.pojo.BuildId import com.tencent.devops.process.pojo.trigger.PipelineTriggerDetail import com.tencent.devops.process.pojo.trigger.PipelineTriggerEvent import com.tencent.devops.process.pojo.trigger.PipelineTriggerEventVo @@ -401,110 +397,6 @@ class PipelineTriggerEventService @Autowired constructor( return true } - /** - * 保存特殊触发事件 - * 远程/手动/openApi - */ - fun saveSpecificEvent( - projectId: String, - pipelineId: String, - userId: String, - eventSource: String, - eventDesc: String? = null, - requestParams: Map?, - triggerType: String = PipelineTriggerType.MANUAL.name, - buildInfo: BuildId?, - status: String = PipelineTriggerStatus.SUCCEED.name, - reason: String? = null - ) { - logger.info("start save specific event|$projectId|$pipelineId|$userId|$triggerType") - val pipelineInfo = client.get(ServicePipelineResource::class).getPipelineInfo( - projectId = projectId, - pipelineId = pipelineId, - channelCode = ChannelCode.BS - ).data - saveManualStartEvent( - projectId = projectId, - pipelineId = pipelineId, - pipelineName = pipelineInfo?.pipelineName ?: "", - eventSource = eventSource, - eventDesc = eventDesc, - buildId = buildInfo?.id ?: "", - status = status, - requestParams = requestParams, - userId = userId, - buildNum = buildInfo?.num.toString(), - triggerType = triggerType, - reason = reason - ) - } - - /** - * 保存手动触发事件 - */ - private fun saveManualStartEvent( - projectId: String, - pipelineId: String, - pipelineName: String, - eventSource: String, - buildId: String?, - buildNum: String?, - userId: String, - status: String, - triggerType: String, - requestParams: Map?, - eventDesc: String? = null, - reason: String? - ) { - val eventId = getEventId() - val requestId = MDC.get(TraceTag.BIZID) - // 事件描述 - val targetEventDesc = if (eventDesc.isNullOrBlank()) { - JsonUtil.toJson( - I18Variable( - code = getI18Code(triggerType), - params = listOf(eventSource) - ), - false - ) - } else { - eventDesc - } - saveEvent( - triggerDetail = PipelineTriggerDetail( - eventId = eventId, - status = status, - projectId = projectId, - pipelineId = pipelineId, - buildId = buildId, - buildNum = buildNum, - pipelineName = pipelineName, - reason = reason - ), - triggerEvent = PipelineTriggerEvent( - eventId = eventId, - projectId = projectId, - eventDesc = targetEventDesc, - eventSource = eventSource, - triggerType = triggerType, - eventType = triggerType, - triggerUser = userId, - requestParams = requestParams, - createTime = LocalDateTime.now(), - requestId = requestId - ) - ) - } - - private fun getI18Code(triggerType: String) = when (triggerType) { - PipelineTriggerType.MANUAL.name -> WebhookI18nConstants.MANUAL_START_EVENT_DESC - PipelineTriggerType.REMOTE.name -> WebhookI18nConstants.REMOTE_START_EVENT_DESC - PipelineTriggerType.SERVICE.name -> WebhookI18nConstants.SERVICE_START_EVENT_DESC - PipelineTriggerType.PIPELINE.name -> WebhookI18nConstants.PIPELINE_START_EVENT_DESC - PipelineTriggerType.TIME_TRIGGER.name -> WebhookI18nConstants.TIMING_START_EVENT_DESC - else -> "" - } - /** * 获取国际化构建事件描述 */ From c7a9e9a339fbf1d9e180c58d68ff57dea04eecfa Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 16 Nov 2023 15:24:28 +0800 Subject: [PATCH 125/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/trigger/PipelineTriggerEventAspect.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt index 53a1af65ea9..dd06d058d2e 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt @@ -122,10 +122,15 @@ class PipelineTriggerEventAspect( return } val triggerEvent = - buildTriggerEvent(userId = userId!!, startValues = startValues, startType = startType!!) ?: return + buildTriggerEvent( + userId = userId!!, + projectId = pipeline!!.projectId, + startValues = startValues, + startType = startType!! + ) ?: return val triggerDetail = buildTriggerDetail( - pipeline = pipeline!!, + pipeline = pipeline, eventId = triggerEvent.eventId!!, result = result, exception = exception @@ -140,6 +145,7 @@ class PipelineTriggerEventAspect( } } + @Suppress("ComplexCondition") private fun skipSaveTriggerEvent( pipeline: PipelineInfo?, userId: String?, @@ -165,6 +171,7 @@ class PipelineTriggerEventAspect( private fun buildTriggerEvent( userId: String, + projectId: String, startValues: Map?, startType: StartType ): PipelineTriggerEvent? { @@ -172,6 +179,7 @@ class PipelineTriggerEventAspect( val eventId = triggerEventService.getEventId() val triggerEventBuilder = PipelineTriggerEventBuilder() triggerEventBuilder.requestId(requestId) + triggerEventBuilder.projectId(projectId) triggerEventBuilder.eventId(eventId) triggerEventBuilder.triggerUser(userId) triggerEventBuilder.createTime(LocalDateTime.now()) From 5212f3fb9c1b073ecd11f4499acde778fe1ad56a Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 16 Nov 2023 16:25:24 +0800 Subject: [PATCH 126/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trigger/PipelineTriggerEventAspect.kt | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt index dd06d058d2e..91f536c04a0 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt @@ -31,6 +31,7 @@ package com.tencent.devops.process.trigger import com.tencent.devops.common.api.pojo.I18Variable import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.common.pipeline.enums.StartType +import com.tencent.devops.common.pipeline.pojo.BuildParameters import com.tencent.devops.common.service.trace.TraceTag import com.tencent.devops.common.webhook.enums.WebhookI18nConstants.MANUAL_START_EVENT_DESC import com.tencent.devops.common.webhook.enums.WebhookI18nConstants.OPENAPI_START_EVENT_DESC @@ -96,6 +97,7 @@ class PipelineTriggerEventAspect( var userId: String? = null var channelCode: ChannelCode? = null var startValues: Map? = null + var pipelineParamMap: MutableMap? = null var startType: StartType? = null for (index in parameterValue.indices) { @@ -105,6 +107,8 @@ class PipelineTriggerEventAspect( "channelCode" -> channelCode = parameterValue[index] as ChannelCode "startValues" -> startValues = parameterValue[index] as Map? "startType" -> startType = parameterValue[index] as StartType + "pipelineParamMap" -> + pipelineParamMap = parameterValue[index] as MutableMap? else -> Unit } } @@ -114,7 +118,7 @@ class PipelineTriggerEventAspect( userId = userId, channelCode = channelCode, startType = startType, - startValues = startValues, + pipelineParamMap = pipelineParamMap, result = result, exception = exception ) @@ -126,6 +130,7 @@ class PipelineTriggerEventAspect( userId = userId!!, projectId = pipeline!!.projectId, startValues = startValues, + pipelineParamMap = pipelineParamMap, startType = startType!! ) ?: return @@ -151,7 +156,7 @@ class PipelineTriggerEventAspect( userId: String?, channelCode: ChannelCode?, startType: StartType?, - startValues: Map?, + pipelineParamMap: MutableMap?, result: Any?, exception: Throwable? ): Boolean { @@ -166,13 +171,14 @@ class PipelineTriggerEventAspect( return true } // 重试不需要记录 - return startValues != null && startValues[PIPELINE_RETRY_BUILD_ID] != null + return pipelineParamMap != null && pipelineParamMap[PIPELINE_RETRY_BUILD_ID] != null } private fun buildTriggerEvent( userId: String, projectId: String, startValues: Map?, + pipelineParamMap: MutableMap?, startType: StartType ): PipelineTriggerEvent? { val requestId = MDC.get(TraceTag.BIZID) @@ -224,10 +230,10 @@ class PipelineTriggerEventAspect( } StartType.PIPELINE -> { - val parentProjectId = startValues?.get(PIPELINE_START_PARENT_PROJECT_ID) - val parentPipelineId = startValues?.get(PIPELINE_START_PARENT_PIPELINE_ID) - val parentPipelineName = startValues?.get(PIPELINE_START_PARENT_PIPELINE_NAME) - val parentBuildId = startValues?.get(PIPELINE_START_PARENT_BUILD_ID) + val parentProjectId = pipelineParamMap?.get(PIPELINE_START_PARENT_PROJECT_ID)?.value?.toString() + val parentPipelineId = pipelineParamMap?.get(PIPELINE_START_PARENT_PIPELINE_ID)?.value?.toString() + val parentPipelineName = pipelineParamMap?.get(PIPELINE_START_PARENT_PIPELINE_NAME)?.value?.toString() + val parentBuildId = pipelineParamMap?.get(PIPELINE_START_PARENT_BUILD_ID)?.value?.toString() if (parentProjectId == null || parentPipelineId == null || parentBuildId == null || parentPipelineName == null ) { From dd3512fa9677e2f772a71ad776a793c3b99ec32a Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 16 Nov 2023 16:44:50 +0800 Subject: [PATCH 127/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tencent/devops/process/trigger/PipelineTriggerEventAspect.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt index 91f536c04a0..336290d117c 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt @@ -234,6 +234,7 @@ class PipelineTriggerEventAspect( val parentPipelineId = pipelineParamMap?.get(PIPELINE_START_PARENT_PIPELINE_ID)?.value?.toString() val parentPipelineName = pipelineParamMap?.get(PIPELINE_START_PARENT_PIPELINE_NAME)?.value?.toString() val parentBuildId = pipelineParamMap?.get(PIPELINE_START_PARENT_BUILD_ID)?.value?.toString() + logger.info("$parentProjectId:$parentPipelineId:$parentPipelineName:$parentBuildId") if (parentProjectId == null || parentPipelineId == null || parentBuildId == null || parentPipelineName == null ) { From d4af4c79374cf758ab1fd48233043343622842fd Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 16 Nov 2023 16:46:12 +0800 Subject: [PATCH 128/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/trigger/PipelineTriggerEventAspect.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt index 336290d117c..958fa785ba0 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt @@ -234,7 +234,7 @@ class PipelineTriggerEventAspect( val parentPipelineId = pipelineParamMap?.get(PIPELINE_START_PARENT_PIPELINE_ID)?.value?.toString() val parentPipelineName = pipelineParamMap?.get(PIPELINE_START_PARENT_PIPELINE_NAME)?.value?.toString() val parentBuildId = pipelineParamMap?.get(PIPELINE_START_PARENT_BUILD_ID)?.value?.toString() - logger.info("$parentProjectId:$parentPipelineId:$parentPipelineName:$parentBuildId") + logger.info("subPipeline event: $parentProjectId:$parentPipelineId:$parentPipelineName:$parentBuildId") if (parentProjectId == null || parentPipelineId == null || parentBuildId == null || parentPipelineName == null ) { From c6569ca42ca117eeb3c1a527b8230113ba6e0965 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 16 Nov 2023 17:12:24 +0800 Subject: [PATCH 129/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tencent/devops/process/service/SubPipelineStartUpService.kt | 2 +- .../devops/process/trigger/PipelineTriggerEventAspect.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt index 19ac626dbcf..cd3dba6ed97 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/SubPipelineStartUpService.kt @@ -232,7 +232,7 @@ class SubPipelineStartUpService @Autowired constructor( BuildParameters(key = PIPELINE_START_PARENT_PROJECT_ID, value = parentProjectId) params[PIPELINE_START_PARENT_PIPELINE_ID] = BuildParameters(key = PIPELINE_START_PARENT_PIPELINE_ID, value = parentPipelineId) - params[PIPELINE_START_PARENT_PIPELINE_ID] = + params[PIPELINE_START_PARENT_PIPELINE_NAME] = BuildParameters(key = PIPELINE_START_PARENT_PIPELINE_NAME, value = parentPipelineInfo.pipelineName) params[PIPELINE_START_PARENT_BUILD_ID] = BuildParameters(key = PIPELINE_START_PARENT_BUILD_ID, value = parentBuildId) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt index 958fa785ba0..25949d23c9f 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt @@ -174,6 +174,7 @@ class PipelineTriggerEventAspect( return pipelineParamMap != null && pipelineParamMap[PIPELINE_RETRY_BUILD_ID] != null } + @Suppress("ComplexCondition") private fun buildTriggerEvent( userId: String, projectId: String, @@ -234,7 +235,6 @@ class PipelineTriggerEventAspect( val parentPipelineId = pipelineParamMap?.get(PIPELINE_START_PARENT_PIPELINE_ID)?.value?.toString() val parentPipelineName = pipelineParamMap?.get(PIPELINE_START_PARENT_PIPELINE_NAME)?.value?.toString() val parentBuildId = pipelineParamMap?.get(PIPELINE_START_PARENT_BUILD_ID)?.value?.toString() - logger.info("subPipeline event: $parentProjectId:$parentPipelineId:$parentPipelineName:$parentBuildId") if (parentProjectId == null || parentPipelineId == null || parentBuildId == null || parentPipelineName == null ) { From 3407670f611b602f72357e66fc72440512c38ed3 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 16 Nov 2023 17:48:07 +0800 Subject: [PATCH 130/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/trigger/PipelineTriggerEventAspect.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt index 25949d23c9f..e4a8c80dac7 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/trigger/PipelineTriggerEventAspect.kt @@ -213,7 +213,7 @@ class PipelineTriggerEventAspect( triggerEventBuilder.eventDesc( I18Variable( code = REMOTE_START_EVENT_DESC, - params = listOf(userId) + params = listOf(eventSource, userId) ).toJsonStr() ) } From da24341079a2a0b61e9b070f62d2bb76845122a2 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 16 Nov 2023 18:35:20 +0800 Subject: [PATCH 131/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../i18n/process/message_en_US.properties | 58 +++++++++---------- .../i18n/process/message_zh_CN.properties | 58 +++++++++---------- 2 files changed, 58 insertions(+), 58 deletions(-) diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index d72c8ce081f..062b53544e6 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -359,36 +359,36 @@ commonShutdownSuccessContent=【${%s}】- 【${%s}】#${%s} Execution succeed, commonShutdownFailureContent=【${%s}】- 【${%s}】#${%s} Execution failed,consume time${%s}, trigger user: ${%s}。 bkBeforePosition=Check-in- Control points can only be executed if the conditions are met. bkAfterPosition=Check-out - Subsequent plugins can only be executed if the conditions are met. -bkTgitPushEventDesc=[{0}] Commit [{2}] pushed by {3} -bkTgitIssueOpenedEventDesc=Issue [!{1}] opened by {2} -bkTgitIssueUpdatedEventDesc=Issue [!{1}] updated by {2} -bkTgitIssueClosedEventDesc=Issue [!{1}] closed by {2} -bkTgitIssueReopenedEventDesc=Issue [!{1}] reopened by {2} -bkTgitMrCreatedEventDesc=Merge requests [!{1}] opened by {2} -bkTgitMrUpdatedEventDesc=Merge requests [!{1}] updated by {2} -bkTgitMrClosedEventDesc=Merge requests [!{1}] closed by {2} -bkTgitMrReopenedEventDesc=Merge requests [!{1}] reopened by {2} -bkTgitMrPushUpdatedEventDesc=Merge requests [!{1}] push updated by {2} -bkTgitMrMergedEventDesc=Merge requests [!{1}] merged by {2} -bkTgitTagPushEventDesc=[{0}]Tag [{2}] pushed by {3} -bkTgitNoteEventDesc=Note [{1}] submitted by {2} -bkTgitReviewCreatedEventDesc=Code review [{1}] created by {2} -bkTgitReviewApprovedEventDesc=Code review [{1}] approved by {2} +bkTgitPushEventDesc=[{0}] Commit [{2}] pushed by {3} +bkTgitIssueOpenedEventDesc=Issue [!{1}] opened by {2} +bkTgitIssueUpdatedEventDesc=Issue [!{1}] updated by {2} +bkTgitIssueClosedEventDesc=Issue [!{1}] closed by {2} +bkTgitIssueReopenedEventDesc=Issue [!{1}] reopened by {2} +bkTgitMrCreatedEventDesc=Merge requests [!{1}] opened by {2} +bkTgitMrUpdatedEventDesc=Merge requests [!{1}] updated by {2} +bkTgitMrClosedEventDesc=Merge requests [!{1}] closed by {2} +bkTgitMrReopenedEventDesc=Merge requests [!{1}] reopened by {2} +bkTgitMrPushUpdatedEventDesc=Merge requests [!{1}] push updated by {2} +bkTgitMrMergedEventDesc=Merge requests [!{1}] merged by {2} +bkTgitTagPushEventDesc=[{0}]Tag [{2}] pushed by {3} +bkTgitNoteEventDesc=Note [{1}] submitted by {2} +bkTgitReviewCreatedEventDesc=Code review [{1}] created by {2} +bkTgitReviewApprovedEventDesc=Code review [{1}] approved by {2} bkTgitReviewApprovingEventDesc=Code review [{1}] approving -bkTgitReviewChangeDeniedEventDesc=Code review [{1}] change denied by {2} -bkTgitReviewChangeRequiredEventDesc=Code review [{1}] change required by {2} -bkGithubPushEventDesc=[{0}] Commit [{2}] pushed by {3} -bkGithubCreateBranchEventDesc=Branch [{1}] created by {2} -bkGithubCreateTagEventDesc=Tag [{1}] pushed by {2} -bkGithubPrEventDesc=Pull request [!{1}] by {2} {3} -bkP4EventDesc=Change [{0}] by {1} {2} -bkSvnCommitEventDesc=Commit [{0}] pushed by {1} -bkManualStartEventDesc=Manually triggered by {0} -bkRemoteStartEventDesc=Remote api triggered by {1} [{0}] -bkServiceStartEventDesc=Pipeline invocation triggered by {0} invoke -bkPipelineStartEventDesc=Pipeline invocation [{2}] triggered by {0} invoke -bkTimingStartEventDesc=Timer triggered by {0} -bkEventReplayDesc=Event [{0}] replayed by {1} +bkTgitReviewChangeDeniedEventDesc=Code review [{1}] change denied by {2} +bkTgitReviewChangeRequiredEventDesc=Code review [{1}] change required by {2} +bkGithubPushEventDesc=[{0}] Commit [{2}] pushed by {3} +bkGithubCreateBranchEventDesc=Branch [{1}] created by {2} +bkGithubCreateTagEventDesc=Tag [{1}] pushed by {2} +bkGithubPrEventDesc=Pull request [!{1}] by {2} {3} +bkP4EventDesc=Change [{0}] by {1} {2} +bkSvnCommitEventDesc=Commit [{0}] pushed by {1} +bkManualStartEventDesc=Manually triggered by {0} +bkRemoteStartEventDesc=Remote api triggered by {1} [{0}] +bkServiceStartEventDesc=Pipeline invocation triggered by {0} invoke +bkPipelineStartEventDesc=Sub-Pipeline triggered by [{2}] {0} +bkTimingStartEventDesc=Timer triggered by {0} +bkEventReplayDesc=Event [{0}] replayed by {1} bkRepoTriggerEventTypeNotMatch=Event type mismatch bkRepoTriggerTargetBranchNotMatch=Target branch [{0}] of merge request does not match bkRepoTriggerTargetBranchIgnored=Target branch [{0}] of merge request has been excluded diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 69afce7ef4d..33fb0208971 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -359,36 +359,36 @@ commonShutdownSuccessContent=【${%s}】- 【${%s}】#${%s} 执行成功,耗 commonShutdownFailureContent=【${%s}】- 【${%s}】#${%s} 执行失败,耗时${%s}, 触发人: ${%s}。 bkBeforePosition=准入-满足条件才能执行控制点 bkAfterPosition=准出-满足条件才能执行后续插件 -bkTgitPushEventDesc=[{0}] 提交 [{2}] 由 {3} 推送 -bkTgitIssueCreatedEventDesc=议题 [!{1}] 由 {2} 创建 -bkTgitIssueUpdatedEventDesc=议题 [!{1}] 由 {2} 更新 -bkTgitIssueClosedEventDesc=议题 [!{1}] 由 {2} 关闭 -bkTgitIssueReopenedEventDesc=议题 [!{1}] 由 {2} 重新打开 -bkTgitMrCreatedEventDesc=合并请求 [!{1}] 由 {2} 创建 -bkTgitMrUpdatedEventDesc=合并请求 [!{1}] 由 {2} 更新 -bkTgitMrClosedEventDesc=合并请求 [!{1}] 由 {2} 关闭 -bkTgitMrReopenedEventDesc=合并请求 [!{1}] 由 {2} 重新打开 -bkTgitMrPushUpdatedEventDesc=合并请求 [!{1}] 由 {2} 在源分支提交代码触发 -bkTgitMrMergedEventDesc=合并请求 [!{1}] 由 {2} 合并 -bkTgitTagPushEventDesc=[{0}] 创建Tag [{2}] 由 {3} 推送 -bkTgitNoteEventDesc=评论 [{1}] 由 {2} 发表 -bkTgitReviewCreatedEventDesc=代码审查 [{1}] 由 {2} 创建 -bkTgitReviewApprovedEventDesc=代码审查 [{1}] 由 {2} 评审通过 +bkTgitPushEventDesc=[{0}] 提交 [{2}] 由 {3} 推送 +bkTgitIssueCreatedEventDesc=议题 [!{1}] 由 {2} 创建 +bkTgitIssueUpdatedEventDesc=议题 [!{1}] 由 {2} 更新 +bkTgitIssueClosedEventDesc=议题 [!{1}] 由 {2} 关闭 +bkTgitIssueReopenedEventDesc=议题 [!{1}] 由 {2} 重新打开 +bkTgitMrCreatedEventDesc=合并请求 [!{1}] 由 {2} 创建 +bkTgitMrUpdatedEventDesc=合并请求 [!{1}] 由 {2} 更新 +bkTgitMrClosedEventDesc=合并请求 [!{1}] 由 {2} 关闭 +bkTgitMrReopenedEventDesc=合并请求 [!{1}] 由 {2} 重新打开 +bkTgitMrPushUpdatedEventDesc=合并请求 [!{1}] 由 {2} 在源分支提交代码触发 +bkTgitMrMergedEventDesc=合并请求 [!{1}] 由 {2} 合并 +bkTgitTagPushEventDesc=[{0}] 创建Tag [{2}] 由 {3} 推送 +bkTgitNoteEventDesc=评论 [{1}] 由 {2} 发表 +bkTgitReviewCreatedEventDesc=代码审查 [{1}] 由 {2} 创建 +bkTgitReviewApprovedEventDesc=代码审查 [{1}] 由 {2} 评审通过 bkTgitReviewApprovingEventDesc=代码审查 [{1}] 评审中 -bkTgitReviewChangeDeniedEventDesc=代码审查 [{1}] 被 {2} 拒绝 -bkTgitReviewChangeRequiredEventDesc=代码审查 [{1}] 由 {2} 要求修改 -bkGithubPushEventDesc=[{0}] 提交 [{2}] 由 {3} 推送 -bkGithubCreateBranchEventDesc=Branch [{1}] 由 {2} 创建 -bkGithubCreateTagEventDesc=Tag [{1}] 由 {2} 推送 -bkGithubPrEventDesc=Pull request [{1}] 由 {2} {3} -bkP4EventDesc=Change {0} 由 {1} {2} -bkSvnCommitEventDesc=提交 [{0}] 由 {1} 推送 -bkManualStartEventDesc={0} 手动触发 -bkRemoteStartEventDesc={1} [{0}] 远程触发 -bkServiceStartEventDesc={0} 触发的流水线调用 -bkPipelineStartEventDesc={0} 触发的流水线 [{2}] 调用 -bkTimingStartEventDesc={0} 定时触发 -bkEventReplayDesc=事件 [{0}] 由 {1} 重放 +bkTgitReviewChangeDeniedEventDesc=代码审查 [{1}] 被 {2} 拒绝 +bkTgitReviewChangeRequiredEventDesc=代码审查 [{1}] 由 {2} 要求修改 +bkGithubPushEventDesc=[{0}] 提交 [{2}] 由 {3} 推送 +bkGithubCreateBranchEventDesc=Branch [{1}] 由 {2} 创建 +bkGithubCreateTagEventDesc=Tag [{1}] 由 {2} 推送 +bkGithubPrEventDesc=Pull request [{1}] 由 {2} {3} +bkP4EventDesc=Change {0} 由 {1} {2} +bkSvnCommitEventDesc=提交 [{0}] 由 {1} 推送 +bkManualStartEventDesc={0} 手动触发 +bkRemoteStartEventDesc={1} [{0}] 远程触发 +bkServiceStartEventDesc={0} 触发的流水线调用 +bkPipelineStartEventDesc=[{2}] {0} 子流水线调用 +bkTimingStartEventDesc={0} 定时触发 +bkEventReplayDesc=事件 [{0}] 由 {1} 重放 bkRepoTriggerEventTypeNotMatch=事件类型不满足触发条件 bkRepoTriggerTargetBranchNotMatch=MR目标分支[{0}]不满足触发条件 bkRepoTriggerTargetBranchIgnored=MR目标分支[{0}]被排除 From faeee866c207d9618e36e007b530cd6fe18f8280 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 16 Nov 2023 18:44:29 +0800 Subject: [PATCH 132/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- support-files/i18n/process/message_en_US.properties | 2 +- support-files/i18n/process/message_zh_CN.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index 062b53544e6..4fd43293dc2 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -384,7 +384,7 @@ bkGithubPrEventDesc=Pull request [!{1}] by {1} {2} bkSvnCommitEventDesc=Commit [{0}] pushed by {1} bkManualStartEventDesc=Manually triggered by {0} -bkRemoteStartEventDesc=Remote api triggered by {1} [{0}] +bkRemoteStartEventDesc=Remote api triggered by {0} [{1}] bkServiceStartEventDesc=Pipeline invocation triggered by {0} invoke bkPipelineStartEventDesc=Sub-Pipeline triggered by [{2}] {0} bkTimingStartEventDesc=Timer triggered by {0} diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 33fb0208971..2f666aa21e0 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -384,7 +384,7 @@ bkGithubPrEventDesc=Pull request [{1}] 由 {1} {2} bkSvnCommitEventDesc=提交 [{0}] 由 {1} 推送 bkManualStartEventDesc={0} 手动触发 -bkRemoteStartEventDesc={1} [{0}] 远程触发 +bkRemoteStartEventDesc={0} [{1}] 远程触发 bkServiceStartEventDesc={0} 触发的流水线调用 bkPipelineStartEventDesc=[{2}] {0} 子流水线调用 bkTimingStartEventDesc={0} 定时触发 From 7c8f2423d6549e94710f68470bf2a4f87caa1caf Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Sat, 18 Nov 2023 16:08:30 +0800 Subject: [PATCH 133/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pipeline/utils/RepositoryConfigUtils.kt | 76 +- .../process/api/op/OpScmWebhookResource.kt | 5 + .../api/user/UserScmWebhookResource.kt | 7 - .../pojo/trigger/PipelineSpecificEvent.kt | 56 -- .../process/engine/dao/PipelineWebhookDao.kt | 2 +- .../process/api/UserScmWebhookResourceImpl.kt | 6 - .../api/op/OpScmWebhookResourceImpl.kt | 13 +- .../engine/pojo/WebhookElementParams.kt | 41 -- .../engine/service/PipelineWebhookService.kt | 681 +++--------------- .../service/PipelineWebhookUpgradeService.kt | 408 +++++++++++ .../repository/pojo/CodeGitRepository.kt | 2 + .../repository/pojo/CodeGitlabRepository.kt | 2 + .../repository/pojo/CodeP4Repository.kt | 2 + .../repository/pojo/CodeSvnRepository.kt | 2 + .../repository/pojo/CodeTGitRepository.kt | 2 + .../repository/pojo/GithubRepository.kt | 2 + .../devops/repository/pojo/Repository.kt | 2 + 17 files changed, 618 insertions(+), 691 deletions(-) delete mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineSpecificEvent.kt delete mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/pojo/WebhookElementParams.kt create mode 100644 src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookUpgradeService.kt diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/utils/RepositoryConfigUtils.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/utils/RepositoryConfigUtils.kt index 11524943f51..387b35f8521 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/utils/RepositoryConfigUtils.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/utils/RepositoryConfigUtils.kt @@ -29,6 +29,7 @@ package com.tencent.devops.common.pipeline.utils import com.tencent.devops.common.api.enums.RepositoryConfig import com.tencent.devops.common.api.enums.RepositoryType +import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.exception.InvalidParamException import com.tencent.devops.common.api.util.EnvUtils import com.tencent.devops.common.pipeline.pojo.element.Element @@ -42,6 +43,7 @@ import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitlabWebHook import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeP4WebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeSVNWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeTGitWebHookTriggerElement +import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType object RepositoryConfigUtils { @@ -133,19 +135,83 @@ object RepositoryConfigUtils { ) } + fun buildWebhookConfig( + element: Element, + variables: Map + ): Triple { + return when (element) { + is CodeGitWebHookTriggerElement -> { + val repositoryConfig = RepositoryConfig( + repositoryHashId = element.repositoryHashId, + repositoryName = EnvUtils.parseEnv(element.repositoryName, variables), + repositoryType = element.repositoryType ?: RepositoryType.ID + ) + Triple(ScmType.CODE_GIT, element.eventType, repositoryConfig) + } + + is CodeSVNWebHookTriggerElement -> { + val repositoryConfig = RepositoryConfig( + repositoryHashId = element.repositoryHashId, + repositoryName = EnvUtils.parseEnv(element.repositoryName, variables), + repositoryType = element.repositoryType ?: RepositoryType.ID + ) + Triple(ScmType.CODE_SVN, CodeEventType.PUSH_COMMIT, repositoryConfig) + } + + is CodeGitlabWebHookTriggerElement -> { + val repositoryConfig = RepositoryConfig( + repositoryHashId = element.repositoryHashId, + repositoryName = EnvUtils.parseEnv(element.repositoryName, variables), + repositoryType = element.repositoryType ?: RepositoryType.ID + ) + Triple(ScmType.CODE_GITLAB, element.eventType, repositoryConfig) + } + + is CodeGithubWebHookTriggerElement -> { + val repositoryConfig = RepositoryConfig( + repositoryHashId = element.repositoryHashId, + repositoryName = EnvUtils.parseEnv(element.repositoryName, variables), + repositoryType = element.repositoryType ?: RepositoryType.ID + ) + Triple(ScmType.GITHUB, element.eventType, repositoryConfig) + } + + is CodeTGitWebHookTriggerElement -> { + val repositoryConfig = RepositoryConfig( + repositoryHashId = element.data.input.repositoryHashId, + repositoryName = EnvUtils.parseEnv(element.data.input.repositoryName, variables), + repositoryType = element.data.input.repositoryType ?: RepositoryType.ID + ) + Triple(ScmType.CODE_TGIT, element.data.input.eventType, repositoryConfig) + } + + is CodeP4WebHookTriggerElement -> { + val repositoryConfig = RepositoryConfig( + repositoryHashId = element.data.input.repositoryHashId, + repositoryName = EnvUtils.parseEnv(element.data.input.repositoryName, variables), + repositoryType = element.data.input.repositoryType ?: RepositoryType.ID + ) + Triple(ScmType.CODE_P4, element.data.input.eventType, repositoryConfig) + } + + else -> + throw InvalidParamException("Unknown code element -> $element") + } + } + fun getRepositoryConfig( repoHashId: String?, repoName: String?, repoType: RepositoryType?, - variable: Map? = null + variables: Map? = null ): RepositoryConfig { return when (repoType) { RepositoryType.ID -> RepositoryConfig(repoHashId, null, RepositoryType.ID) RepositoryType.NAME -> { - val repositoryName = if (variable.isNullOrEmpty()) { + val repositoryName = if (variables.isNullOrEmpty()) { repoName!! } else { - EnvUtils.parseEnv(repoName!!, variable) + EnvUtils.parseEnv(repoName!!, variables) } RepositoryConfig(null, repositoryName, RepositoryType.NAME) } @@ -153,10 +219,10 @@ object RepositoryConfigUtils { if (!repoHashId.isNullOrBlank()) { RepositoryConfig(repoHashId, null, RepositoryType.ID) } else if (!repoName.isNullOrBlank()) { - val repositoryName = if (variable.isNullOrEmpty()) { + val repositoryName = if (variables.isNullOrEmpty()) { repoName } else { - EnvUtils.parseEnv(repoName, variable) + EnvUtils.parseEnv(repoName, variables) } RepositoryConfig(null, repositoryName, RepositoryType.NAME) } else { diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/op/OpScmWebhookResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/op/OpScmWebhookResource.kt index e5097221fed..4757a1a38af 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/op/OpScmWebhookResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/op/OpScmWebhookResource.kt @@ -17,6 +17,11 @@ import javax.ws.rs.core.MediaType @Consumes(MediaType.APPLICATION_JSON) interface OpScmWebhookResource { + @ApiOperation("更新所有的webhook项目名") + @PUT + @Path("/updateProjectNameAndTaskId") + fun updateProjectNameAndTaskId(): Result + @ApiOperation("更新webhook secret") @PUT @Path("/updateWebhookSecret") diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserScmWebhookResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserScmWebhookResource.kt index 19fa90526e0..f1a3eb3f3cc 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserScmWebhookResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserScmWebhookResource.kt @@ -37,7 +37,6 @@ import io.swagger.annotations.ApiParam import javax.ws.rs.Consumes import javax.ws.rs.GET import javax.ws.rs.HeaderParam -import javax.ws.rs.PUT import javax.ws.rs.Path import javax.ws.rs.PathParam import javax.ws.rs.Produces @@ -49,12 +48,6 @@ import javax.ws.rs.core.MediaType @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) interface UserScmWebhookResource { - - @ApiOperation("更新所有的webhook项目名") - @PUT - @Path("/updateProjectNameAndTaskId") - fun updateProjectNameAndTaskId(): Result - @ApiOperation("根据代码库类型获取事件") @GET @Path("/eventType") diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineSpecificEvent.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineSpecificEvent.kt deleted file mode 100644 index 2e7d03ba7e6..00000000000 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/trigger/PipelineSpecificEvent.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ -package com.tencent.devops.process.pojo.trigger - -import com.tencent.devops.process.pojo.BuildId -import io.swagger.annotations.ApiModel -import io.swagger.annotations.ApiModelProperty - -@ApiModel("流水线特殊触发事件") -data class PipelineSpecificEvent( - @ApiModelProperty("项目Id") - val projectId: String, - @ApiModelProperty("流水线Id") - val pipelineId: String, - @ApiModelProperty("用户信息") - val userId: String, - @ApiModelProperty("事件源") - val eventSource: String, - @ApiModelProperty("事件描述") - val eventDesc: String? = null, - @ApiModelProperty("请求参数") - val requestParams: Map?, - @ApiModelProperty("触发类型") - val triggerType: String = PipelineTriggerType.MANUAL.name, - @ApiModelProperty("构建信息") - val buildInfo: BuildId?, - @ApiModelProperty("构建状态") - val status: String, - @ApiModelProperty("原因") - val reason: String -) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt index aa9ca2c3340..0b30adf76e1 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineWebhookDao.kt @@ -294,7 +294,7 @@ class PipelineWebhookDao { dslContext: DSLContext, repositoryHashId: String?, eventType: String, - externalId: String, + externalId: String?, pipelineId: String, projectId: String, taskId: String diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserScmWebhookResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserScmWebhookResourceImpl.kt index cc9596919e1..c6ce6b19792 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserScmWebhookResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserScmWebhookResourceImpl.kt @@ -41,12 +41,6 @@ import org.springframework.beans.factory.annotation.Autowired class UserScmWebhookResourceImpl @Autowired constructor( private val pipelineWebhookService: PipelineWebhookService ) : UserScmWebhookResource { - - override fun updateProjectNameAndTaskId(): Result { - pipelineWebhookService.updateProjectNameAndTaskId() - return Result(true) - } - override fun getEventType(scmType: String): Result> { val eventTypeList = when (scmType) { ScmType.CODE_GIT.name, ScmType.CODE_TGIT.name -> diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/op/OpScmWebhookResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/op/OpScmWebhookResourceImpl.kt index 0b678c022bf..41d954f348f 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/op/OpScmWebhookResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/op/OpScmWebhookResourceImpl.kt @@ -3,20 +3,25 @@ package com.tencent.devops.process.api.op import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.common.web.RestResource -import com.tencent.devops.process.engine.service.PipelineWebhookService +import com.tencent.devops.process.engine.service.PipelineWebhookUpgradeService @RestResource class OpScmWebhookResourceImpl( - private val pipelineWebhookService: PipelineWebhookService + private val pipelineWebhookUpgradeService: PipelineWebhookUpgradeService ) : OpScmWebhookResource { + override fun updateProjectNameAndTaskId(): Result { + pipelineWebhookUpgradeService.updateProjectNameAndTaskId() + return Result(true) + } + override fun updateWebhookSecret(scmType: String): Result { - pipelineWebhookService.updateWebhookSecret(ScmType.valueOf(scmType)) + pipelineWebhookUpgradeService.updateWebhookSecret(ScmType.valueOf(scmType)) return Result(true) } override fun updateWebhookEventInfo(): Result { - pipelineWebhookService.updateWebhookEventInfo() + pipelineWebhookUpgradeService.updateWebhookEventInfo() return Result(true) } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/pojo/WebhookElementParams.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/pojo/WebhookElementParams.kt deleted file mode 100644 index 9a72b6c28e3..00000000000 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/pojo/WebhookElementParams.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package com.tencent.devops.process.engine.pojo - -import com.tencent.devops.common.api.enums.RepositoryConfig -import com.tencent.devops.common.api.enums.ScmType -import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType - -/** - * webhook事件触发插件参数配置 - */ -data class WebhookElementParams( - val repositoryConfig: RepositoryConfig, - val scmType: ScmType, - val eventType: CodeEventType? -) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index 21af9fdc25e..99607fe2d6f 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -29,12 +29,9 @@ package com.tencent.devops.process.engine.service import com.fasterxml.jackson.databind.ObjectMapper import com.tencent.devops.common.api.enums.RepositoryConfig -import com.tencent.devops.common.api.enums.RepositoryType import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.exception.ErrorCodeException -import com.tencent.devops.common.api.exception.InvalidParamException import com.tencent.devops.common.api.pojo.Result -import com.tencent.devops.common.api.util.EnvUtils import com.tencent.devops.common.api.util.PageUtil import com.tencent.devops.common.auth.api.AuthPermission import com.tencent.devops.common.client.Client @@ -42,12 +39,6 @@ import com.tencent.devops.common.notify.enums.NotifyType import com.tencent.devops.common.pipeline.Model import com.tencent.devops.common.pipeline.container.TriggerContainer import com.tencent.devops.common.pipeline.pojo.element.Element -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGithubWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitlabWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeP4WebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeSVNWebHookTriggerElement -import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeTGitWebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.WebHookTriggerElement import com.tencent.devops.common.pipeline.pojo.element.trigger.enums.CodeEventType import com.tencent.devops.common.pipeline.utils.RepositoryConfigUtils @@ -60,26 +51,17 @@ import com.tencent.devops.notify.pojo.SendNotifyMessageTemplateRequest import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.engine.dao.PipelineResDao import com.tencent.devops.process.engine.dao.PipelineWebhookDao -import com.tencent.devops.process.engine.pojo.WebhookElementParams import com.tencent.devops.process.permission.PipelinePermissionService import com.tencent.devops.process.pojo.PipelineNotifyTemplateEnum import com.tencent.devops.process.pojo.webhook.PipelineWebhook import com.tencent.devops.process.pojo.webhook.WebhookTriggerPipeline import com.tencent.devops.process.service.scm.ScmProxyService import com.tencent.devops.repository.api.ServiceRepositoryResource -import com.tencent.devops.repository.pojo.CodeGitRepository -import com.tencent.devops.repository.pojo.CodeGitlabRepository -import com.tencent.devops.repository.pojo.CodeP4Repository -import com.tencent.devops.repository.pojo.CodeSvnRepository -import com.tencent.devops.repository.pojo.CodeTGitRepository -import com.tencent.devops.repository.pojo.GithubRepository import com.tencent.devops.repository.pojo.Repository 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 /** * 流水线webhook存储服务 @@ -97,8 +79,9 @@ class PipelineWebhookService @Autowired constructor( private val pipelinePermissionService: PipelinePermissionService, private val redisOperation: RedisOperation ) { - - private val logger = LoggerFactory.getLogger(javaClass)!! + companion object { + private val logger = LoggerFactory.getLogger(PipelineWebhookService::class.java) + } fun addWebhook( projectId: String, @@ -112,102 +95,74 @@ class PipelineWebhookService @Autowired constructor( return } val triggerContainer = model.stages[0].containers[0] as TriggerContainer - val params = triggerContainer.params.associate { param -> + val variables = triggerContainer.params.associate { param -> param.id to param.defaultValue.toString() } val elements = triggerContainer.elements.filterIsInstance() val failedElementNames = mutableListOf() elements.forEach { element -> - val webhookElementParams = getElementRepositoryConfig(element, variable = params) - ?: return@forEach - with(webhookElementParams) { - try { - logger.info("$pipelineId| Trying to add the $scmType web hook for repo($repositoryConfig)") - saveWebhook( - pipelineWebhook = PipelineWebhook( - projectId = projectId, - pipelineId = pipelineId, - repositoryType = scmType, - repoType = repositoryConfig.repositoryType, - repoHashId = repositoryConfig.repositoryHashId, - repoName = repositoryConfig.repositoryName, - taskId = element.id - ), - codeEventType = eventType, - repositoryConfig = repositoryConfig, - createPipelineFlag = true, - version = element.version - ) - } catch (ignore: Exception) { - failedElementNames.add("- ${element.name}: ${ignore.message}") - logger.warn("$projectId|$pipelineId|add webhook failed", ignore) - } - } - } - if (failedElementNames.isNotEmpty()) { - client.get(ServiceNotifyMessageTemplateResource::class).sendNotifyMessageByTemplate( - SendNotifyMessageTemplateRequest( - templateCode = - PipelineNotifyTemplateEnum.PIPELINE_WEBHOOK_REGISTER_FAILURE_NOTIFY_TEMPLATE.templateCode, - receivers = mutableSetOf(userId), - notifyType = mutableSetOf(NotifyType.RTX.name), - titleParams = mapOf("pipelineName" to model.name), - bodyParams = mapOf( - "pipelineName" to model.name, - "elementNames" to failedElementNames.joinToString(""), - "pipelineEditUrl" to pipelineEditUrl(projectId, pipelineId) - ), - cc = null, - bcc = null + try { + saveWebhook( + projectId = projectId, + pipelineId = pipelineId, + element = element, + variables = variables ) - ) + } catch (ignore: Exception) { + failedElementNames.add("- ${element.name}: ${ignore.message}") + logger.warn("$projectId|$pipelineId|add webhook failed", ignore) + } } + sendNotify( + userId = userId, + projectId = projectId, + pipelineId = pipelineId, + pipelineName = model.name, + failedElementNames = failedElementNames + ) } - fun saveWebhook( - pipelineWebhook: PipelineWebhook, - codeEventType: CodeEventType? = null, - repositoryConfig: RepositoryConfig, - createPipelineFlag: Boolean? = false, - version: String + private fun saveWebhook( + projectId: String, + pipelineId: String, + element: Element, + variables: Map ) { - logger.info("save Webhook[$pipelineWebhook]") - var continueFlag = true - if (createPipelineFlag != null && createPipelineFlag) { - // 新增流水线时,模版里配置的代码库是变量或者当前项目下不存在,不需创建webhook - try { - val repo = scmProxyService.getRepo(pipelineWebhook.projectId, repositoryConfig) - } catch (e: Exception) { - logger.info("skip save Webhook[$pipelineWebhook]: ${e.message}") - continueFlag = false - } - } - - if (continueFlag) { - val repository = registerWebhook( - pipelineWebhook = pipelineWebhook, - repositoryConfig = repositoryConfig, - codeEventType = codeEventType, - version = version - ) - if (repository != null) { - pipelineWebhook.repositoryHashId = repository.repoHashId - pipelineWebhook.eventType = codeEventType?.name ?: "" - pipelineWebhook.externalId = getExternalId(repository) - pipelineWebhook.projectName = getProjectName(repository.projectName) - pipelineWebhookDao.save( - dslContext = dslContext, - pipelineWebhook = pipelineWebhook - ) - } - } + val (repositoryType, eventType, repositoryConfig) = + RepositoryConfigUtils.buildWebhookConfig(element, variables) + logger.info("$pipelineId| Trying to add the $repositoryType web hook for repo($repositoryConfig)") + val repository = registerWebhook( + projectId = projectId, + repositoryType = repositoryType, + repositoryConfig = repositoryConfig, + codeEventType = eventType, + elementVersion = element.version + ) ?: return + val pipelineWebhook = PipelineWebhook( + projectId = projectId, + pipelineId = pipelineId, + repositoryType = repositoryType, + repoType = repositoryConfig.repositoryType, + repoHashId = repositoryConfig.repositoryHashId, + repoName = repositoryConfig.repositoryName, + taskId = element.id, + projectName = getProjectName(repository.projectName), + repositoryHashId = repository.repoHashId, + eventType = eventType?.name ?: "", + externalId = repository.getExternalId() + ) + pipelineWebhookDao.save( + dslContext = dslContext, + pipelineWebhook = pipelineWebhook + ) } private fun registerWebhook( - pipelineWebhook: PipelineWebhook, + projectId: String, + repositoryType: ScmType, repositoryConfig: RepositoryConfig, codeEventType: CodeEventType?, - version: String + elementVersion: String ): Repository? { // 防止同一个仓库注册多个相同事件的webhook val redisLock = RedisLock( @@ -217,42 +172,56 @@ class PipelineWebhookService @Autowired constructor( ) try { redisLock.lock() - return when (pipelineWebhook.repositoryType) { + return when (repositoryType) { ScmType.CODE_GIT -> scmProxyService.addGitWebhook( - projectId = pipelineWebhook.projectId, + projectId = projectId, repositoryConfig = repositoryConfig, codeEventType = codeEventType ) + ScmType.CODE_SVN -> - scmProxyService.addSvnWebhook(pipelineWebhook.projectId, repositoryConfig) + scmProxyService.addSvnWebhook(projectId = projectId, repositoryConfig = repositoryConfig) + ScmType.CODE_GITLAB -> - scmProxyService.addGitlabWebhook(pipelineWebhook.projectId, repositoryConfig, codeEventType) + scmProxyService.addGitlabWebhook( + projectId = projectId, + repositoryConfig = repositoryConfig, + codeEventType = codeEventType + ) + ScmType.GITHUB -> { client.get(ServiceRepositoryResource::class).get( - pipelineWebhook.projectId, - repositoryConfig.getURLEncodeRepositoryId(), - repositoryConfig.repositoryType + projectId = projectId, + repositoryId = repositoryConfig.getURLEncodeRepositoryId(), + repositoryType = repositoryConfig.repositoryType ).data!! } + ScmType.CODE_TGIT -> { - scmProxyService.addTGitWebhook(pipelineWebhook.projectId, repositoryConfig, codeEventType) + scmProxyService.addTGitWebhook( + projectId = projectId, + repositoryConfig = repositoryConfig, + codeEventType = codeEventType + ) } + ScmType.CODE_P4 -> - if (WebhookUtils.isCustomP4TriggerVersion(version)) { + if (WebhookUtils.isCustomP4TriggerVersion(elementVersion)) { val repo = client.get(ServiceRepositoryResource::class).get( - pipelineWebhook.projectId, - repositoryConfig.getURLEncodeRepositoryId(), - repositoryConfig.repositoryType + projectId = projectId, + repositoryId = repositoryConfig.getURLEncodeRepositoryId(), + repositoryType = repositoryConfig.repositoryType ).data!! repo } else { scmProxyService.addP4Webhook( - projectId = pipelineWebhook.projectId, + projectId = projectId, repositoryConfig = repositoryConfig, codeEventType = codeEventType ) } + else -> { null } @@ -262,6 +231,33 @@ class PipelineWebhookService @Autowired constructor( } } + private fun sendNotify( + userId: String, + projectId: String, + pipelineId: String, + pipelineName: String, + failedElementNames: List + ) { + if (failedElementNames.isNotEmpty()) { + client.get(ServiceNotifyMessageTemplateResource::class).sendNotifyMessageByTemplate( + SendNotifyMessageTemplateRequest( + templateCode = + PipelineNotifyTemplateEnum.PIPELINE_WEBHOOK_REGISTER_FAILURE_NOTIFY_TEMPLATE.templateCode, + receivers = mutableSetOf(userId), + notifyType = mutableSetOf(NotifyType.RTX.name), + titleParams = mapOf("pipelineName" to pipelineName), + bodyParams = mapOf( + "pipelineName" to pipelineName, + "elementNames" to failedElementNames.joinToString(""), + "pipelineEditUrl" to pipelineEditUrl(projectId, pipelineId) + ), + cc = null, + bcc = null + ) + ) + } + } + private fun pipelineEditUrl(projectId: String, pipelineId: String) = "${HomeHostUtil.innerServerHost()}/console/pipeline/$projectId/$pipelineId/edit" @@ -314,19 +310,6 @@ class PipelineWebhookService @Autowired constructor( ) ?: emptyList() } - fun listPipelineWebhook( - name: String, - repositoryType: String, - eventType: String - ): List { - return pipelineWebhookDao.listWebhookPipeline( - dslContext = dslContext, - projectName = getProjectName(name), - repositoryType = repositoryType, - eventType = eventType - ) ?: emptyList() - } - fun getProjectName(projectName: String): String { // 如果项目名是三层的,比如a/b/c,那对应的rep_name是b val repoSplit = projectName.split("/") @@ -336,254 +319,6 @@ class PipelineWebhookService @Autowired constructor( return repoSplit[1].trim() } - private fun getRepositoryConfig( - pipelineWebhook: PipelineWebhook, - variable: Map? = null - ): RepositoryConfig { - return getRepositoryConfig( - repoHashId = pipelineWebhook.repoHashId, - repoName = pipelineWebhook.repoName, - repoType = pipelineWebhook.repoType, - variable = variable - ) - } - - private fun getRepositoryConfig( - repoHashId: String?, - repoName: String?, - repoType: RepositoryType?, - variable: Map? = null - ): RepositoryConfig { - return when (repoType) { - RepositoryType.ID -> RepositoryConfig(repoHashId, null, RepositoryType.ID) - RepositoryType.NAME -> { - val repositoryName = if (variable == null || variable.isEmpty()) { - repoName!! - } else { - EnvUtils.parseEnv(repoName!!, variable) - } - RepositoryConfig(null, repositoryName, RepositoryType.NAME) - } - else -> { - if (!repoHashId.isNullOrBlank()) { - RepositoryConfig(repoHashId, null, RepositoryType.ID) - } else if (!repoName.isNullOrBlank()) { - val repositoryName = if (variable == null || variable.isEmpty()) { - repoName - } else { - EnvUtils.parseEnv(repoName, variable) - } - RepositoryConfig(null, repositoryName, RepositoryType.NAME) - } else { - // 两者不能同时为空 - throw ErrorCodeException( - errorCode = ProcessMessageCode.ERROR_PARAM_WEBHOOK_ID_NAME_ALL_NULL - ) - } - } - } - } - - fun listRepositoryTypeWebhooks( - repositoryType: ScmType, - start: Int, - limit: Int - ): Result> { - if (start < 0) { - return Result(emptyList()) - } - val list = pipelineWebhookDao.getPipelineWebHooksByRepositoryType(dslContext, repositoryType.name, start, limit) - val pipelineWebhookList = mutableListOf() - list.forEach { - pipelineWebhookList.add(pipelineWebhookDao.convert(it)) - } - return Result(pipelineWebhookList) - } - - fun updateProjectNameAndTaskId() { - ScmType.values().forEach { - doUpdateProjectNameAndTaskId(it) - } - } - - /** - * 批量更新TASK_ID和PROJECT_NAME - */ - private fun doUpdateProjectNameAndTaskId(type: ScmType) { - val pipelines = mutableMapOf/*trigger element*/>() - val pipelineVariables = HashMap>() - val usedTask = mutableListOf() - var start = 0 - loop@ while (true) { - val typeWebhooksResp = listRepositoryTypeWebhooks(type, start, 100) - if (typeWebhooksResp.isNotOk() || typeWebhooksResp.data == null || typeWebhooksResp.data!!.isEmpty()) { - break@loop - } - typeWebhooksResp.data!!.forEach webhook@{ - with(it) { - try { - val (elements, params) = getElementsAndParams( - projectId = projectId, - pipelineId = pipelineId, - pipelines = pipelines, - pipelineVariables = pipelineVariables - ) - - val result = matchElement(elements = elements, params = params, usedTask = usedTask) - if (!result) { - logger.warn("$id|$pipelineId|$taskId|not match element, delete webhook $it") - pipelineWebhookDao.deleteById(dslContext = dslContext, projectId = projectId, id = id!!) - } - } catch (t: Throwable) { - logger.warn("update projectName and taskId $it exception ignore", t) - } - } - } - start += 100 - } - } - - private fun getElementsAndParams( - projectId: String, - pipelineId: String, - pipelines: MutableMap/*trigger element*/>, - pipelineVariables: MutableMap> - ): Pair, Map> { - return if (pipelines[pipelineId] == null) { - val model = getModel(projectId, pipelineId) - // 如果model为空,缓存空值 - val (elements, params) = if (model == null) { - Pair(emptyList(), emptyMap()) - } else { - val triggerContainer = model.stages[0].containers[0] as TriggerContainer - val params = triggerContainer.params.associate { param -> - param.id to param.defaultValue.toString() - } - Pair(triggerContainer.elements.filterIsInstance(), params) - } - pipelines[pipelineId] = elements - pipelineVariables[pipelineId] = params - Pair(elements, params) - } else { - Pair(pipelines[pipelineId]!!, pipelineVariables[pipelineId]!!) - } - } - - private fun PipelineWebhook.matchElement( - elements: List, - params: Map, - usedTask: MutableList - ): Boolean { - val webhookRepositoryConfig = getRepositoryConfig(this, params) - if (elements.isEmpty()) { - logger.warn("$id|$pipelineId|$taskId|pipeline does not exist") - return false - } - val repo = try { - client.get(ServiceRepositoryResource::class).get( - projectId = projectId, - repositoryId = webhookRepositoryConfig.getURLEncodeRepositoryId(), - repositoryType = webhookRepositoryConfig.repositoryType - ).data - } catch (e: Exception) { - null - } - if (repo == null) { - logger.warn("$id|$pipelineId|$taskId|repo[$webhookRepositoryConfig] does not exist") - return false - } - var findResult = false - for (element in elements) { - val (elementRepositoryConfig, elementScmType) = getElementRepositoryConfig(element, params) ?: continue - val usedKey = "${pipelineId}_${element.id!!}" - if (webhookRepositoryConfig.getRepositoryId() == elementRepositoryConfig.getRepositoryId() && - elementScmType == repositoryType && - !usedTask.contains(usedKey) - ) { - /* - * 配置相同并且没有使用过才进行更新和标记 - * 1. 如果taskId为空,则表示没有更新过,直接更新 - * 2. 如果taskId不为空,taskId和插件ID相同,则标记已使用 - * */ - if (taskId == null) { - pipelineWebhookDao.updateProjectNameAndTaskId( - dslContext = dslContext, - projectId = projectId, - projectName = getProjectName(repo.projectName), - taskId = element.id!!, - id = id!! - ) - usedTask.add(usedKey) - findResult = true - break - } else if (taskId == element.id) { - usedTask.add(usedKey) - findResult = true - break - } - } - } - return findResult - } - - private fun getElementRepositoryConfig( - element: Element, - variable: Map - ): WebhookElementParams? { - if (element !is WebHookTriggerElement) { - return null - } - val elementRepositoryConfig = RepositoryConfigUtils.buildConfig(element) - val realRepositoryConfig = with(elementRepositoryConfig) { - getRepositoryConfig( - repoHashId = repositoryHashId, - repoName = repositoryName, - repoType = repositoryType, - variable = variable - ) - } - return when (element) { - is CodeGitWebHookTriggerElement -> - WebhookElementParams( - repositoryConfig = realRepositoryConfig, - scmType = ScmType.CODE_GIT, - eventType = element.eventType - ) - is CodeGithubWebHookTriggerElement -> - WebhookElementParams( - repositoryConfig = realRepositoryConfig, - scmType = ScmType.GITHUB, - eventType = element.eventType - ) - is CodeGitlabWebHookTriggerElement -> - WebhookElementParams( - repositoryConfig = realRepositoryConfig, - scmType = ScmType.CODE_GITLAB, - eventType = element.eventType - ) - is CodeSVNWebHookTriggerElement -> - WebhookElementParams( - repositoryConfig = realRepositoryConfig, - scmType = ScmType.CODE_SVN, - eventType = CodeEventType.POST_COMMIT - ) - is CodeTGitWebHookTriggerElement -> - WebhookElementParams( - repositoryConfig = realRepositoryConfig, - scmType = ScmType.CODE_TGIT, - eventType = element.data.input.eventType - ) - is CodeP4WebHookTriggerElement -> - WebhookElementParams( - repositoryConfig = realRepositoryConfig, - scmType = ScmType.CODE_P4, - eventType = element.data.input.eventType - ) - else -> - throw InvalidParamException("Unknown code element -> $element") - } - } - fun listWebhook( userId: String, projectId: String, @@ -615,200 +350,4 @@ class PipelineWebhookService @Autowired constructor( ) ?: emptyList() } - fun updateWebhookSecret(type: ScmType) { - val pipelines = mutableMapOf/*trigger element*/>() - val pipelineVariables = HashMap>() - var start = 0 - loop@ while (true) { - logger.info("update webhook secret|start=$start") - val typeWebhooksResp = listRepositoryTypeWebhooks(type, start, 100) - if (typeWebhooksResp.isNotOk() || typeWebhooksResp.data == null || typeWebhooksResp.data!!.isEmpty()) { - break@loop - } - typeWebhooksResp.data!!.forEach webhook@{ - it.doUpdateWebhookSecret(pipelines, pipelineVariables) - } - start += 100 - } - } - - private fun PipelineWebhook.doUpdateWebhookSecret( - pipelines: MutableMap>, - pipelineVariables: HashMap> - ) { - try { - val (elements, params) = getElementsAndParams( - projectId = projectId, - pipelineId = pipelineId, - pipelines = pipelines, - pipelineVariables = pipelineVariables - ) - - val repositoryConfig = getRepositoryConfig(this, params) - for (element in elements) { - if (element.id == taskId) { - when (element) { - is CodeGitWebHookTriggerElement -> - scmProxyService.addGitWebhook( - projectId, - repositoryConfig = repositoryConfig, - codeEventType = element.eventType - ) - is CodeTGitWebHookTriggerElement -> - scmProxyService.addTGitWebhook( - projectId, - repositoryConfig = repositoryConfig, - codeEventType = element.data.input.eventType - ) - is CodeGitlabWebHookTriggerElement -> - scmProxyService.addGitlabWebhook( - projectId, - repositoryConfig = repositoryConfig, - codeEventType = element.eventType - ) - } - break - } - } - } catch (t: Throwable) { - logger.warn("$id|$pipelineId|update webhook secret exception ignore", t) - } - } - - fun updateWebhookEventInfo() { - val startTime = System.currentTimeMillis() - val threadPoolExecutor = Executors.newSingleThreadExecutor() - threadPoolExecutor.submit { - logger.info("PipelineWebhookService:begin updateWebhookEventInfo threadPoolExecutor") - try { - updateWebhookEventInfoTask() - } catch (ignored: Exception) { - logger.warn("PipelineWebhookService:updateWebhookEventInfo failed", ignored) - } finally { - threadPoolExecutor.shutdown() - logger.info("updateWebhookEventInfo finish cost: ${System.currentTimeMillis() - startTime}") - } - } - } - - private fun updateWebhookEventInfoTask() { - var offset = 0 - val limit = 1000 - val repoCache = mutableMapOf>() - // 上一个更新的项目ID - var preProjectId: String? = null - do { - val pipelines = pipelineWebhookDao.listPipelines( - dslContext = dslContext, - limit = limit, - offset = offset - ) - pipelines.forEach { (projectId, pipelineId) -> - // 更改项目,清空代码库缓存 - if (preProjectId != null && preProjectId != projectId) { - repoCache.clear() - } - preProjectId = projectId - val model = getModel(projectId, pipelineId) - if (model == null) { - logger.info("$projectId|$pipelineId|model is null") - return@forEach - } - val triggerContainer = model.stages[0].containers[0] as TriggerContainer - val params = triggerContainer.params.associate { param -> - param.id to param.defaultValue.toString() - } - val elementMap = - triggerContainer.elements.filterIsInstance().associateBy { it.id } - val pipelineWebhooks = pipelineWebhookDao.listWebhook( - dslContext = dslContext, - projectId = projectId, - pipelineId = pipelineId, - limit = limit, - offset = 0 - ) - pipelineWebhooks?.forEach webhook@{ webhook -> - try { - if (webhook.taskId.isNullOrBlank()) return@webhook - val element = elementMap[webhook.taskId] ?: return@webhook - val webhookElementParams = getElementRepositoryConfig(element, variable = params) - ?: run { - logger.info("webhook not find match element|${webhook.id}") - return@webhook - } - val elementRepositoryConfig = webhookElementParams.repositoryConfig - val webhookRepositoryConfig = getRepositoryConfig(webhook, params) - // 插件的配置与表中数据不一致,如保存流水线时,注册webhook失败,就会导致数据不一致,打印日志统计 - if (elementRepositoryConfig.getRepositoryId() != webhookRepositoryConfig.getRepositoryId()) { - logger.info( - "webhook repository config different from element repository config|" + - "webhook:$webhookRepositoryConfig|element:$elementRepositoryConfig" - ) - } - // 缓存代码库信息,避免频繁调用代码库信息接口 - val repoCacheKey = "${projectId}_${webhookRepositoryConfig.getRepositoryId()}" - val repositoryOptional = repoCache[repoCacheKey] ?: run { - val repo = try { - scmProxyService.getRepo( - projectId = projectId, - repositoryConfig = webhookRepositoryConfig - ) - } catch (ignored: Exception) { - logger.warn( - "$projectId|$pipelineId|${webhookRepositoryConfig.getRepositoryId()}|" + - "fail to get repository info", ignored - ) - null - } - val optional = Optional.ofNullable(repo) - repoCache[repoCacheKey] = optional - optional - } - val repository = if (repositoryOptional.isPresent) { - repositoryOptional.get() - } else { - null - } - - // 历史原因,git的projectName有三个,如aaa/bbb/ccc,只读取了bbb,统计数据量 - if (repository != null && webhook.projectName != repository.projectName) { - logger.info( - "webhook projectName different from repo projectName|" + - "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 = repositoryHashId - ) - } catch (ignored: Exception) { - logger.info("update webhook event info error|$webhook", ignored) - } - } - } - offset += limit - } while (pipelines.size == 1000) - } - - private fun getExternalId(repository: Repository?) = when (repository) { - is CodeGitRepository -> repository.gitProjectId - is CodeTGitRepository -> repository.gitProjectId - is CodeGitlabRepository -> repository.gitProjectId - is CodeSvnRepository -> repository.projectName - is CodeP4Repository -> repository.projectName - is GithubRepository -> repository.gitProjectId - else -> "" - }?.toString() ?: "" } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookUpgradeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookUpgradeService.kt new file mode 100644 index 00000000000..3a2bbcc2e44 --- /dev/null +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookUpgradeService.kt @@ -0,0 +1,408 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +package com.tencent.devops.process.engine.service + +import com.tencent.devops.common.api.enums.RepositoryType +import com.tencent.devops.common.api.enums.ScmType +import com.tencent.devops.common.api.pojo.Result +import com.tencent.devops.common.client.Client +import com.tencent.devops.common.pipeline.container.TriggerContainer +import com.tencent.devops.common.pipeline.pojo.element.Element +import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitWebHookTriggerElement +import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeGitlabWebHookTriggerElement +import com.tencent.devops.common.pipeline.pojo.element.trigger.CodeTGitWebHookTriggerElement +import com.tencent.devops.common.pipeline.pojo.element.trigger.WebHookTriggerElement +import com.tencent.devops.common.pipeline.utils.RepositoryConfigUtils +import com.tencent.devops.process.engine.dao.PipelineWebhookDao +import com.tencent.devops.process.pojo.webhook.PipelineWebhook +import com.tencent.devops.process.service.scm.ScmProxyService +import com.tencent.devops.repository.api.ServiceRepositoryResource +import com.tencent.devops.repository.pojo.Repository +import org.jooq.DSLContext +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service +import java.util.Optional +import java.util.concurrent.Executors + +@Service +class PipelineWebhookUpgradeService( + private val scmProxyService: ScmProxyService, + private val dslContext: DSLContext, + private val pipelineWebhookDao: PipelineWebhookDao, + private val client: Client, + private val pipelineWebhookService: PipelineWebhookService +) { + + companion object { + private val logger = LoggerFactory.getLogger(PipelineWebhookUpgradeService::class.java) + } + + fun updateProjectNameAndTaskId() { + ScmType.values().forEach { + doUpdateProjectNameAndTaskId(it) + } + } + + /** + * 批量更新TASK_ID和PROJECT_NAME + */ + @Suppress("NestedBlockDepth") + private fun doUpdateProjectNameAndTaskId(type: ScmType) { + val pipelines = mutableMapOf/*trigger element*/>() + val pipelineVariables = HashMap>() + val usedTask = mutableListOf() + var start = 0 + loop@ while (true) { + val typeWebhooksResp = listRepositoryTypeWebhooks(type, start, 100) + if (typeWebhooksResp.isNotOk() || typeWebhooksResp.data == null || typeWebhooksResp.data!!.isEmpty()) { + break@loop + } + typeWebhooksResp.data!!.forEach webhook@{ + with(it) { + try { + val (elements, params) = getElementsAndParams( + projectId = projectId, + pipelineId = pipelineId, + pipelines = pipelines, + pipelineVariables = pipelineVariables + ) + + val result = matchElement(elements = elements, params = params, usedTask = usedTask) + if (!result) { + logger.warn("$id|$pipelineId|$taskId|not match element, delete webhook $it") + pipelineWebhookDao.deleteById(dslContext = dslContext, projectId = projectId, id = id!!) + } + } catch (t: Throwable) { + logger.warn("update projectName and taskId $it exception ignore", t) + } + } + } + start += 100 + } + } + + fun listRepositoryTypeWebhooks( + repositoryType: ScmType, + start: Int, + limit: Int + ): Result> { + if (start < 0) { + return Result(emptyList()) + } + val list = pipelineWebhookDao.getPipelineWebHooksByRepositoryType(dslContext, repositoryType.name, start, limit) + val pipelineWebhookList = mutableListOf() + list.forEach { + pipelineWebhookList.add(pipelineWebhookDao.convert(it)) + } + return Result(pipelineWebhookList) + } + + private fun getElementsAndParams( + projectId: String, + pipelineId: String, + pipelines: MutableMap/*trigger element*/>, + pipelineVariables: MutableMap> + ): Pair, Map> { + return if (pipelines[pipelineId] == null) { + val model = pipelineWebhookService.getModel(projectId, pipelineId) + // 如果model为空,缓存空值 + val (elements, params) = if (model == null) { + Pair(emptyList(), emptyMap()) + } else { + val triggerContainer = model.stages[0].containers[0] as TriggerContainer + val params = triggerContainer.params.associate { param -> + param.id to param.defaultValue.toString() + } + Pair(triggerContainer.elements.filterIsInstance(), params) + } + pipelines[pipelineId] = elements + pipelineVariables[pipelineId] = params + Pair(elements, params) + } else { + Pair(pipelines[pipelineId]!!, pipelineVariables[pipelineId]!!) + } + } + + @Suppress("LoopWithTooManyJumpStatements") + private fun PipelineWebhook.matchElement( + elements: List, + params: Map, + usedTask: MutableList + ): Boolean { + val webhookRepositoryConfig = RepositoryConfigUtils.getRepositoryConfig( + repoHashId = repoHashId, + repoName = repoName, + repoType = repoType, + variables = params + ) + if (elements.isEmpty()) { + logger.warn("$id|$pipelineId|$taskId|pipeline does not exist") + return false + } + val repo = try { + client.get(ServiceRepositoryResource::class).get( + projectId = projectId, + repositoryId = webhookRepositoryConfig.getURLEncodeRepositoryId(), + repositoryType = webhookRepositoryConfig.repositoryType + ).data + } catch (e: Exception) { + null + } + if (repo == null) { + logger.warn("$id|$pipelineId|$taskId|repo[$webhookRepositoryConfig] does not exist") + return false + } + var findResult = false + for (element in elements) { + val (elementScmType, elementEventType, elementRepositoryConfig) = + RepositoryConfigUtils.buildWebhookConfig(element, params) ?: continue + val usedKey = "${pipelineId}_${element.id!!}" + if (webhookRepositoryConfig.getRepositoryId() == elementRepositoryConfig.getRepositoryId() && + elementScmType == repositoryType && + !usedTask.contains(usedKey) + ) { + /* + * 配置相同并且没有使用过才进行更新和标记 + * 1. 如果taskId为空,则表示没有更新过,直接更新 + * 2. 如果taskId不为空,taskId和插件ID相同,则标记已使用 + * */ + if (taskId == null) { + pipelineWebhookDao.updateProjectNameAndTaskId( + dslContext = dslContext, + projectId = projectId, + projectName = pipelineWebhookService.getProjectName(repo.projectName), + taskId = element.id!!, + id = id!! + ) + usedTask.add(usedKey) + findResult = true + break + } else if (taskId == element.id) { + usedTask.add(usedKey) + findResult = true + break + } + } + } + return findResult + } + + fun updateWebhookSecret(type: ScmType) { + val pipelines = mutableMapOf/*trigger element*/>() + val pipelineVariables = HashMap>() + var start = 0 + loop@ while (true) { + logger.info("update webhook secret|start=$start") + val typeWebhooksResp = listRepositoryTypeWebhooks(type, start, 100) + if (typeWebhooksResp.isNotOk() || typeWebhooksResp.data == null || typeWebhooksResp.data!!.isEmpty()) { + break@loop + } + typeWebhooksResp.data!!.forEach webhook@{ + it.doUpdateWebhookSecret(pipelines, pipelineVariables) + } + start += 100 + } + } + + private fun PipelineWebhook.doUpdateWebhookSecret( + pipelines: MutableMap>, + pipelineVariables: HashMap> + ) { + try { + val (elements, params) = getElementsAndParams( + projectId = projectId, + pipelineId = pipelineId, + pipelines = pipelines, + pipelineVariables = pipelineVariables + ) + + val repositoryConfig = RepositoryConfigUtils.getRepositoryConfig( + repoHashId = repoHashId, + repoName = repoName, + repoType = repoType, + variables = params + ) + for (element in elements) { + if (element.id == taskId) { + when (element) { + is CodeGitWebHookTriggerElement -> + scmProxyService.addGitWebhook( + projectId, + repositoryConfig = repositoryConfig, + codeEventType = element.eventType + ) + is CodeTGitWebHookTriggerElement -> + scmProxyService.addTGitWebhook( + projectId, + repositoryConfig = repositoryConfig, + codeEventType = element.data.input.eventType + ) + is CodeGitlabWebHookTriggerElement -> + scmProxyService.addGitlabWebhook( + projectId, + repositoryConfig = repositoryConfig, + codeEventType = element.eventType + ) + } + break + } + } + } catch (t: Throwable) { + logger.warn("$id|$pipelineId|update webhook secret exception ignore", t) + } + } + + fun updateWebhookEventInfo() { + val startTime = System.currentTimeMillis() + val threadPoolExecutor = Executors.newSingleThreadExecutor() + threadPoolExecutor.submit { + logger.info("PipelineWebhookService:begin updateWebhookEventInfo threadPoolExecutor") + try { + updateWebhookEventInfoTask() + } catch (ignored: Exception) { + logger.warn("PipelineWebhookService:updateWebhookEventInfo failed", ignored) + } finally { + threadPoolExecutor.shutdown() + logger.info("updateWebhookEventInfo finish cost: ${System.currentTimeMillis() - startTime}") + } + } + } + + private fun updateWebhookEventInfoTask() { + var offset = 0 + val limit = 1000 + val repoCache = mutableMapOf>() + // 上一个更新的项目ID + var preProjectId: String? = null + do { + val pipelines = pipelineWebhookDao.listPipelines( + dslContext = dslContext, + limit = limit, + offset = offset + ) + pipelines.forEach { (projectId, pipelineId) -> + // 更改项目,清空代码库缓存 + if (preProjectId != null && preProjectId != projectId) { + repoCache.clear() + } + preProjectId = projectId + val model = pipelineWebhookService.getModel(projectId, pipelineId) + if (model == null) { + logger.info("$projectId|$pipelineId|model is null") + return@forEach + } + val triggerContainer = model.stages[0].containers[0] as TriggerContainer + val params = triggerContainer.params.associate { param -> + param.id to param.defaultValue.toString() + } + val elementMap = + triggerContainer.elements.filterIsInstance().associateBy { it.id } + val pipelineWebhooks = pipelineWebhookDao.listWebhook( + dslContext = dslContext, + projectId = projectId, + pipelineId = pipelineId, + limit = limit, + offset = 0 + ) + pipelineWebhooks?.forEach webhook@{ webhook -> + try { + if (webhook.taskId.isNullOrBlank()) return@webhook + val element = elementMap[webhook.taskId] ?: return@webhook + val (elementScmType, elementEventType, elementRepositoryConfig) = + RepositoryConfigUtils.buildWebhookConfig(element, params) + val webhookRepositoryConfig = RepositoryConfigUtils.getRepositoryConfig( + repoHashId = webhook.repoHashId, + repoName = webhook.repoName, + repoType = webhook.repoType, + variables = params + ) + // 插件的配置与表中数据不一致,如保存流水线时,注册webhook失败,就会导致数据不一致,打印日志统计 + if (elementRepositoryConfig.getRepositoryId() != webhookRepositoryConfig.getRepositoryId()) { + logger.info( + "webhook repository config different from element repository config|" + + "webhook:$webhookRepositoryConfig|element:$elementRepositoryConfig" + ) + } + // 缓存代码库信息,避免频繁调用代码库信息接口 + val repoCacheKey = "${projectId}_${webhookRepositoryConfig.getRepositoryId()}" + val repositoryOptional = repoCache[repoCacheKey] ?: run { + val repo = try { + scmProxyService.getRepo( + projectId = projectId, + repositoryConfig = webhookRepositoryConfig + ) + } catch (ignored: Exception) { + logger.warn( + "$projectId|$pipelineId|${webhookRepositoryConfig.getRepositoryId()}|" + + "fail to get repository info", ignored + ) + null + } + val optional = Optional.ofNullable(repo) + repoCache[repoCacheKey] = optional + optional + } + val repository = if (repositoryOptional.isPresent) { + repositoryOptional.get() + } else { + null + } + + // 历史原因,git的projectName有三个,如aaa/bbb/ccc,只读取了bbb,统计数据量 + if (repository != null && webhook.projectName != repository.projectName) { + logger.info( + "webhook projectName different from repo projectName|" + + "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 = elementEventType?.name ?: "", + externalId = repository?.getExternalId(), + projectId = projectId, + pipelineId = pipelineId, + taskId = webhook.taskId!!, + repositoryHashId = repositoryHashId + ) + } catch (ignored: Exception) { + logger.info("update webhook event info error|$webhook", ignored) + } + } + } + offset += limit + } while (pipelines.size == 1000) + } +} diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeGitRepository.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeGitRepository.kt index f09e754648c..7a46c271fb5 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeGitRepository.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeGitRepository.kt @@ -75,4 +75,6 @@ data class CodeGitRepository( GitUtils.isLegalSshUrl(url) } } + + override fun getExternalId(): String = gitProjectId?.toString() ?: "" } diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeGitlabRepository.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeGitlabRepository.kt index 0a826adc82b..e8d44a436fa 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeGitlabRepository.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeGitlabRepository.kt @@ -74,4 +74,6 @@ data class CodeGitlabRepository( GitUtils.isLegalSshUrl(url) } } + + override fun getExternalId(): String = gitProjectId?.toString() ?: "" } diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeP4Repository.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeP4Repository.kt index 01c85581aaa..9b80c0c8ca0 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeP4Repository.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeP4Repository.kt @@ -59,4 +59,6 @@ data class CodeP4Repository( override fun isLegal(): Boolean { return true } + + override fun getExternalId(): String = projectName } diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeSvnRepository.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeSvnRepository.kt index b61cc90d115..0af510c06a4 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeSvnRepository.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeSvnRepository.kt @@ -85,4 +85,6 @@ data class CodeSvnRepository( } override fun getStartPrefix() = "svn+ssh://" + + override fun getExternalId(): String = projectName } diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeTGitRepository.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeTGitRepository.kt index 39b0188095e..eab6ddd7eb2 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeTGitRepository.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/CodeTGitRepository.kt @@ -75,4 +75,6 @@ data class CodeTGitRepository( GitUtils.isLegalSshUrl(url) } } + + override fun getExternalId(): String = gitProjectId?.toString() ?: "" } diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/GithubRepository.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/GithubRepository.kt index 61e6846db2f..381bee41972 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/GithubRepository.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/GithubRepository.kt @@ -55,4 +55,6 @@ data class GithubRepository( } override fun getStartPrefix() = "https://github.com/" + + override fun getExternalId(): String = gitProjectId?.toString() ?: "" } diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/Repository.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/Repository.kt index e5d921f6255..1e33f2abd65 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/Repository.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/Repository.kt @@ -55,4 +55,6 @@ interface Repository { fun getStartPrefix(): String fun getFormatURL() = url + + fun getExternalId(): String = projectName } From bceb602ce0d3b29c3152a5e368dbf5d9675da94e Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Sat, 18 Nov 2023 16:43:11 +0800 Subject: [PATCH 134/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/engine/service/PipelineWebhookService.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index 99607fe2d6f..7b0fbea62a9 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -349,5 +349,4 @@ class PipelineWebhookService @Autowired constructor( limit = limit.limit ) ?: emptyList() } - } From b53b06c0e1eea8e12d0be25bd105667f38217b27 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Sat, 18 Nov 2023 17:16:49 +0800 Subject: [PATCH 135/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/code/filter/ContainsFilter.kt | 12 +- .../service/code/filter/RegexContainFilter.kt | 19 +- .../process/api/UserBuildResourceImpl.kt | 5 - .../api/external/ExternalScmResourceImpl.kt | 21 +- .../service/PipelineWebhookUpgradeService.kt | 192 ++++++++++-------- 5 files changed, 120 insertions(+), 129 deletions(-) diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/ContainsFilter.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/ContainsFilter.kt index 4a2aade9166..1db5720e0da 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/ContainsFilter.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/ContainsFilter.kt @@ -47,17 +47,7 @@ class ContainsFilter( override fun doFilter(response: WebhookFilterResponse): Boolean { logger.info("$pipelineId|triggerOn:$triggerOn|included:$included|$filterName filter") - - return buildFilterFailedReason( - action = { - included.isEmpty() || included.contains(triggerOn) - }, - response = response - ) - } - - private fun buildFilterFailedReason(action: () -> Boolean, response: WebhookFilterResponse): Boolean { - val filterResult = action.invoke() + val filterResult = included.isEmpty() || included.contains(triggerOn) if (!filterResult && failedReason.isNotBlank()) { response.failedReason = failedReason } diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/RegexContainFilter.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/RegexContainFilter.kt index 9576c7889f1..55025621f9e 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/RegexContainFilter.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/filter/RegexContainFilter.kt @@ -49,12 +49,11 @@ class RegexContainFilter( override fun doFilter(response: WebhookFilterResponse): Boolean { logger.info("$pipelineId|triggerOn:$triggerOn|included:$included|$filterName filter") - return buildFilterFailedReason( - action = { - filterAction() - }, - response = response - ) + val filterResult = filterAction() + if (!filterResult && failedReason.isNotBlank()) { + response.failedReason = failedReason + } + return filterResult } @SuppressWarnings("ReturnCount") @@ -73,12 +72,4 @@ class RegexContainFilter( } return false } - - private fun buildFilterFailedReason(action: () -> Boolean, response: WebhookFilterResponse): Boolean { - val filterResult = action.invoke() - if (!filterResult && failedReason.isNotBlank()) { - response.failedReason = failedReason - } - return filterResult - } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt index f74a1a9e799..b1f41a9973b 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildResourceImpl.kt @@ -51,7 +51,6 @@ import com.tencent.devops.process.service.builds.PipelineBuildFacadeService import com.tencent.devops.process.service.builds.PipelineBuildMaintainFacadeService import com.tencent.devops.process.service.builds.PipelinePauseBuildFacadeService import io.micrometer.core.annotation.Timed -import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import javax.ws.rs.core.Response @@ -536,8 +535,4 @@ class UserBuildResourceImpl @Autowired constructor( throw ParamBlankException("Invalid projectId") } } - - companion object { - private val logger = LoggerFactory.getLogger(UserBuildResourceImpl::class.java) - } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/external/ExternalScmResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/external/ExternalScmResourceImpl.kt index a3f3b15be55..3f47a797617 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/external/ExternalScmResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/external/ExternalScmResourceImpl.kt @@ -30,7 +30,6 @@ 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 @@ -39,7 +38,6 @@ 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 @@ -62,19 +60,16 @@ class ExternalScmResourceImpl @Autowired constructor( secret: String?, traceId: String, body: String - ): Result { - logger.info("traceId: ${MDC.get(TraceTag.BIZID)}") - return Result( - CodeWebhookEventDispatcher.dispatchEvent( - rabbitTemplate = rabbitTemplate, - event = GitWebhookEvent( - requestContent = body, - event = event, - secret = secret - ) + ): Result = Result( + CodeWebhookEventDispatcher.dispatchEvent( + rabbitTemplate = rabbitTemplate, + event = GitWebhookEvent( + requestContent = body, + event = event, + secret = secret ) ) - } + ) override fun webHookGitlabCommit(event: String) = Result(CodeWebhookEventDispatcher.dispatchEvent(rabbitTemplate, GitlabWebhookEvent(requestContent = event))) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookUpgradeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookUpgradeService.kt index 3a2bbcc2e44..d383eed3c0b 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookUpgradeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookUpgradeService.kt @@ -28,6 +28,7 @@ package com.tencent.devops.process.engine.service +import com.tencent.devops.common.api.enums.RepositoryConfig import com.tencent.devops.common.api.enums.RepositoryType import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.pojo.Result @@ -248,7 +249,7 @@ class PipelineWebhookUpgradeService( repoType = repoType, variables = params ) - for (element in elements) { + elements.forEach { element -> if (element.id == taskId) { when (element) { is CodeGitWebHookTriggerElement -> @@ -257,12 +258,14 @@ class PipelineWebhookUpgradeService( repositoryConfig = repositoryConfig, codeEventType = element.eventType ) + is CodeTGitWebHookTriggerElement -> scmProxyService.addTGitWebhook( projectId, repositoryConfig = repositoryConfig, codeEventType = element.data.input.eventType ) + is CodeGitlabWebHookTriggerElement -> scmProxyService.addGitlabWebhook( projectId, @@ -270,7 +273,7 @@ class PipelineWebhookUpgradeService( codeEventType = element.eventType ) } - break + return } } } catch (t: Throwable) { @@ -312,97 +315,114 @@ class PipelineWebhookUpgradeService( repoCache.clear() } preProjectId = projectId - val model = pipelineWebhookService.getModel(projectId, pipelineId) - if (model == null) { - logger.info("$projectId|$pipelineId|model is null") - return@forEach + updatePipelineEventInfo(projectId = projectId, pipelineId = pipelineId, repoCache = repoCache) + } + offset += limit + } while (pipelines.size == 1000) + } + + private fun updatePipelineEventInfo( + projectId: String, + pipelineId: String, + repoCache: MutableMap> + ) { + val model = pipelineWebhookService.getModel(projectId, pipelineId) + if (model == null) { + logger.info("$projectId|$pipelineId|model is null") + return + } + val triggerContainer = model.stages[0].containers[0] as TriggerContainer + val params = triggerContainer.params.associate { param -> + param.id to param.defaultValue.toString() + } + val elementMap = + triggerContainer.elements.filterIsInstance().associateBy { it.id } + val pipelineWebhooks = pipelineWebhookDao.listWebhook( + dslContext = dslContext, + projectId = projectId, + pipelineId = pipelineId, + limit = 1000, + offset = 0 + ) + pipelineWebhooks?.forEach webhook@{ webhook -> + try { + if (webhook.taskId.isNullOrBlank()) return@webhook + val element = elementMap[webhook.taskId] ?: return@webhook + val (elementScmType, elementEventType, elementRepositoryConfig) = + RepositoryConfigUtils.buildWebhookConfig(element, params) + val webhookRepositoryConfig = RepositoryConfigUtils.getRepositoryConfig( + repoHashId = webhook.repoHashId, + repoName = webhook.repoName, + repoType = webhook.repoType, + variables = params + ) + // 插件的配置与表中数据不一致,如保存流水线时,注册webhook失败,就会导致数据不一致,打印日志统计 + if (elementRepositoryConfig.getRepositoryId() != webhookRepositoryConfig.getRepositoryId()) { + logger.info( + "webhook repository config different from element repository config|" + + "webhook:$webhookRepositoryConfig|element:$elementRepositoryConfig" + ) } - val triggerContainer = model.stages[0].containers[0] as TriggerContainer - val params = triggerContainer.params.associate { param -> - param.id to param.defaultValue.toString() + val repository = getAndCacheRepo(projectId, webhookRepositoryConfig, repoCache) + + // 历史原因,git的projectName有三个,如aaa/bbb/ccc,只读取了bbb,统计数据量 + if (repository != null && webhook.projectName != repository.projectName) { + logger.info( + "webhook projectName different from repo projectName|" + + "webhook:${webhook.projectName}|repo:${repository.projectName}" + ) + } + val repositoryHashId = when { + repository != null -> repository.repoHashId + webhookRepositoryConfig.repositoryType == RepositoryType.ID -> + webhookRepositoryConfig.repositoryHashId + + else -> null } - val elementMap = - triggerContainer.elements.filterIsInstance().associateBy { it.id } - val pipelineWebhooks = pipelineWebhookDao.listWebhook( + pipelineWebhookDao.updateWebhookEventInfo( dslContext = dslContext, + eventType = elementEventType?.name ?: "", + externalId = repository?.getExternalId(), projectId = projectId, pipelineId = pipelineId, - limit = limit, - offset = 0 + taskId = webhook.taskId!!, + repositoryHashId = repositoryHashId ) - pipelineWebhooks?.forEach webhook@{ webhook -> - try { - if (webhook.taskId.isNullOrBlank()) return@webhook - val element = elementMap[webhook.taskId] ?: return@webhook - val (elementScmType, elementEventType, elementRepositoryConfig) = - RepositoryConfigUtils.buildWebhookConfig(element, params) - val webhookRepositoryConfig = RepositoryConfigUtils.getRepositoryConfig( - repoHashId = webhook.repoHashId, - repoName = webhook.repoName, - repoType = webhook.repoType, - variables = params - ) - // 插件的配置与表中数据不一致,如保存流水线时,注册webhook失败,就会导致数据不一致,打印日志统计 - if (elementRepositoryConfig.getRepositoryId() != webhookRepositoryConfig.getRepositoryId()) { - logger.info( - "webhook repository config different from element repository config|" + - "webhook:$webhookRepositoryConfig|element:$elementRepositoryConfig" - ) - } - // 缓存代码库信息,避免频繁调用代码库信息接口 - val repoCacheKey = "${projectId}_${webhookRepositoryConfig.getRepositoryId()}" - val repositoryOptional = repoCache[repoCacheKey] ?: run { - val repo = try { - scmProxyService.getRepo( - projectId = projectId, - repositoryConfig = webhookRepositoryConfig - ) - } catch (ignored: Exception) { - logger.warn( - "$projectId|$pipelineId|${webhookRepositoryConfig.getRepositoryId()}|" + - "fail to get repository info", ignored - ) - null - } - val optional = Optional.ofNullable(repo) - repoCache[repoCacheKey] = optional - optional - } - val repository = if (repositoryOptional.isPresent) { - repositoryOptional.get() - } else { - null - } - - // 历史原因,git的projectName有三个,如aaa/bbb/ccc,只读取了bbb,统计数据量 - if (repository != null && webhook.projectName != repository.projectName) { - logger.info( - "webhook projectName different from repo projectName|" + - "webhook:${webhook.projectName}|repo:${repository.projectName}" - ) - } - val repositoryHashId = when { - repository != null -> repository.repoHashId - webhookRepositoryConfig.repositoryType == RepositoryType.ID -> - webhookRepositoryConfig.repositoryHashId + } catch (ignored: Exception) { + logger.info("update webhook event info error|$webhook", ignored) + } + } + } - else -> null - } - pipelineWebhookDao.updateWebhookEventInfo( - dslContext = dslContext, - eventType = elementEventType?.name ?: "", - externalId = repository?.getExternalId(), - projectId = projectId, - pipelineId = pipelineId, - taskId = webhook.taskId!!, - repositoryHashId = repositoryHashId - ) - } catch (ignored: Exception) { - logger.info("update webhook event info error|$webhook", ignored) - } - } + private fun getAndCacheRepo( + projectId: String, + webhookRepositoryConfig: RepositoryConfig, + repoCache: MutableMap> + ): Repository? { + // 缓存代码库信息,避免频繁调用代码库信息接口 + val repoCacheKey = "${projectId}_${webhookRepositoryConfig.getRepositoryId()}" + val repositoryOptional = repoCache[repoCacheKey] ?: run { + val repo = try { + scmProxyService.getRepo( + projectId = projectId, + repositoryConfig = webhookRepositoryConfig + ) + } catch (ignored: Exception) { + logger.warn( + "$projectId|${webhookRepositoryConfig.getRepositoryId()}|" + + "fail to get repository info", ignored + ) + null } - offset += limit - } while (pipelines.size == 1000) + val optional = Optional.ofNullable(repo) + repoCache[repoCacheKey] = optional + optional + } + val repository = if (repositoryOptional.isPresent) { + repositoryOptional.get() + } else { + null + } + return repository } } From ffb7dd1f75f4a786b2bb9a4c90d96e1342aabd98 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Sat, 18 Nov 2023 17:25:44 +0800 Subject: [PATCH 136/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/engine/service/PipelineWebhookUpgradeService.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookUpgradeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookUpgradeService.kt index d383eed3c0b..0c59acbcf53 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookUpgradeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookUpgradeService.kt @@ -182,7 +182,7 @@ class PipelineWebhookUpgradeService( var findResult = false for (element in elements) { val (elementScmType, elementEventType, elementRepositoryConfig) = - RepositoryConfigUtils.buildWebhookConfig(element, params) ?: continue + RepositoryConfigUtils.buildWebhookConfig(element, params) val usedKey = "${pipelineId}_${element.id!!}" if (webhookRepositoryConfig.getRepositoryId() == elementRepositoryConfig.getRepositoryId() && elementScmType == repositoryType && @@ -231,6 +231,7 @@ class PipelineWebhookUpgradeService( } } + @Suppress("NestedBlockDepth") private fun PipelineWebhook.doUpdateWebhookSecret( pipelines: MutableMap>, pipelineVariables: HashMap> From 82500a971adac3a5d211585b4d8a151b69085324 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Thu, 16 Nov 2023 18:44:29 +0800 Subject: [PATCH 137/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- support-files/i18n/process/message_en_US.properties | 2 +- support-files/i18n/process/message_zh_CN.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index 062b53544e6..4fd43293dc2 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -384,7 +384,7 @@ bkGithubPrEventDesc=Pull request [!{1}] by {1} {2} bkSvnCommitEventDesc=Commit [{0}] pushed by {1} bkManualStartEventDesc=Manually triggered by {0} -bkRemoteStartEventDesc=Remote api triggered by {1} [{0}] +bkRemoteStartEventDesc=Remote api triggered by {0} [{1}] bkServiceStartEventDesc=Pipeline invocation triggered by {0} invoke bkPipelineStartEventDesc=Sub-Pipeline triggered by [{2}] {0} bkTimingStartEventDesc=Timer triggered by {0} diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 33fb0208971..2f666aa21e0 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -384,7 +384,7 @@ bkGithubPrEventDesc=Pull request [{1}] 由 {1} {2} bkSvnCommitEventDesc=提交 [{0}] 由 {1} 推送 bkManualStartEventDesc={0} 手动触发 -bkRemoteStartEventDesc={1} [{0}] 远程触发 +bkRemoteStartEventDesc={0} [{1}] 远程触发 bkServiceStartEventDesc={0} 触发的流水线调用 bkPipelineStartEventDesc=[{2}] {0} 子流水线调用 bkTimingStartEventDesc={0} 定时触发 From a9647696a1d7055bc0650bc2c65c9efcd220fdd0 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 20 Nov 2023 11:57:50 +0800 Subject: [PATCH 138/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pipeline/pojo/element/trigger/enums/CodeEventType.kt | 5 ++++- .../code/handler/github/GithubCreateTriggerHandler.kt | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/enums/CodeEventType.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/enums/CodeEventType.kt index 83cf199cc26..4122a547ee2 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/enums/CodeEventType.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/enums/CodeEventType.kt @@ -85,7 +85,10 @@ enum class CodeEventType { PUSH, MERGE_REQUEST, MERGE_REQUEST_ACCEPT, - CREATE + CREATE, + REVIEW, + ISSUES, + NOTE ) val CODE_P4_EVENTS = listOf( diff --git a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt index 5662194f712..7886358ef25 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/handler/github/GithubCreateTriggerHandler.kt @@ -88,8 +88,8 @@ class GithubCreateTriggerHandler : GitHookTriggerHandler { return I18Variable( code = i18Code, params = listOf( - getBranchName(event), linkUrl, + getBranchName(event), getUsername(event) ) ).toJsonStr() From 3ba1a698522d5a4d548aa447e4c35bf18c5665d3 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 20 Nov 2023 12:42:26 +0800 Subject: [PATCH 139/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/engine/service/PipelineWebhookUpgradeService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookUpgradeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookUpgradeService.kt index 0c59acbcf53..5787b33d9e9 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookUpgradeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookUpgradeService.kt @@ -150,7 +150,7 @@ class PipelineWebhookUpgradeService( } } - @Suppress("LoopWithTooManyJumpStatements") + @Suppress("LoopWithTooManyJumpStatements", "ComplexMethod") private fun PipelineWebhook.matchElement( elements: List, params: Map, From ee2931558bdd1d9768b3e41539ab1701d4bfa1dc Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 20 Nov 2023 18:26:58 +0800 Subject: [PATCH 140/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../i18n/process/message_en_US.properties | 34 +++++++++---------- .../i18n/process/message_zh_CN.properties | 4 +-- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/support-files/i18n/process/message_en_US.properties b/support-files/i18n/process/message_en_US.properties index 4fd43293dc2..30f2e7ed438 100644 --- a/support-files/i18n/process/message_en_US.properties +++ b/support-files/i18n/process/message_en_US.properties @@ -359,24 +359,24 @@ commonShutdownSuccessContent=【${%s}】- 【${%s}】#${%s} Execution succeed, commonShutdownFailureContent=【${%s}】- 【${%s}】#${%s} Execution failed,consume time${%s}, trigger user: ${%s}。 bkBeforePosition=Check-in- Control points can only be executed if the conditions are met. bkAfterPosition=Check-out - Subsequent plugins can only be executed if the conditions are met. -bkTgitPushEventDesc=[{0}] Commit [{2}] pushed by {3} -bkTgitIssueOpenedEventDesc=Issue [!{1}] opened by {2} -bkTgitIssueUpdatedEventDesc=Issue [!{1}] updated by {2} -bkTgitIssueClosedEventDesc=Issue [!{1}] closed by {2} -bkTgitIssueReopenedEventDesc=Issue [!{1}] reopened by {2} -bkTgitMrCreatedEventDesc=Merge requests [!{1}] opened by {2} -bkTgitMrUpdatedEventDesc=Merge requests [!{1}] updated by {2} -bkTgitMrClosedEventDesc=Merge requests [!{1}] closed by {2} -bkTgitMrReopenedEventDesc=Merge requests [!{1}] reopened by {2} -bkTgitMrPushUpdatedEventDesc=Merge requests [!{1}] push updated by {2} -bkTgitMrMergedEventDesc=Merge requests [!{1}] merged by {2} -bkTgitTagPushEventDesc=[{0}]Tag [{2}] pushed by {3} -bkTgitNoteEventDesc=Note [{1}] submitted by {2} -bkTgitReviewCreatedEventDesc=Code review [{1}] created by {2} -bkTgitReviewApprovedEventDesc=Code review [{1}] approved by {2} +bkTgitPushEventDesc=[{0}] Commit [{2}] pushed by {3} +bkTgitIssueOpenedEventDesc=Issue [!{1}] opened by {2} +bkTgitIssueUpdatedEventDesc=Issue [!{1}] updated by {2} +bkTgitIssueClosedEventDesc=Issue [!{1}] closed by {2} +bkTgitIssueReopenedEventDesc=Issue [!{1}] reopened by {2} +bkTgitMrCreatedEventDesc=Merge requests [!{1}] opened by {2} +bkTgitMrUpdatedEventDesc=Merge requests [!{1}] updated by {2} +bkTgitMrClosedEventDesc=Merge requests [!{1}] closed by {2} +bkTgitMrReopenedEventDesc=Merge requests [!{1}] reopened by {2} +bkTgitMrPushUpdatedEventDesc=Merge requests [!{1}] push updated by {2} +bkTgitMrMergedEventDesc=Merge requests [!{1}] merged by {2} +bkTgitTagPushEventDesc=[{0}]Tag [{2}] pushed by {3} +bkTgitNoteEventDesc=Note [{1}] submitted by {2} +bkTgitReviewCreatedEventDesc=Code review [{1}] created by {2} +bkTgitReviewApprovedEventDesc=Code review [{1}] approved by {2} bkTgitReviewApprovingEventDesc=Code review [{1}] approving -bkTgitReviewChangeDeniedEventDesc=Code review [{1}] change denied by {2} -bkTgitReviewChangeRequiredEventDesc=Code review [{1}] change required by {2} +bkTgitReviewChangeDeniedEventDesc=Code review [{1}] change denied by {2} +bkTgitReviewChangeRequiredEventDesc=Code review [{1}] change required by {2} bkGithubPushEventDesc=[{0}] Commit [{2}] pushed by {3} bkGithubCreateBranchEventDesc=Branch [{1}] created by {2} bkGithubCreateTagEventDesc=Tag [{1}] pushed by {2} diff --git a/support-files/i18n/process/message_zh_CN.properties b/support-files/i18n/process/message_zh_CN.properties index 2f666aa21e0..2760a28a4a8 100644 --- a/support-files/i18n/process/message_zh_CN.properties +++ b/support-files/i18n/process/message_zh_CN.properties @@ -378,9 +378,9 @@ bkTgitReviewApprovingEventDesc=代码审查 [{1}{1}] 被 {2} 拒绝 bkTgitReviewChangeRequiredEventDesc=代码审查 [{1}] 由 {2} 要求修改 bkGithubPushEventDesc=[{0}] 提交 [{2}] 由 {3} 推送 -bkGithubCreateBranchEventDesc=Branch [{1}] 由 {2} 创建 +bkGithubCreateBranchEventDesc=分支 [{1}] 由 {2} 创建 bkGithubCreateTagEventDesc=Tag [{1}] 由 {2} 推送 -bkGithubPrEventDesc=Pull request [{1}] 由 {2} {3} +bkGithubPrEventDesc=拉取请求 [{1}] 由 {2} {3} bkP4EventDesc=Change {0} 由 {1} {2} bkSvnCommitEventDesc=提交 [{0}] 由 {1} 推送 bkManualStartEventDesc={0} 手动触发 From 3b4da05002a82697a4e0fad3cb62069b523ed324 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Tue, 21 Nov 2023 12:07:54 +0800 Subject: [PATCH 141/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/webhook/WebhookRequestService.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt index ccb51348e45..8e1191b16a7 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/webhook/WebhookRequestService.kt @@ -84,9 +84,14 @@ class WebhookRequestService( requestBody = request.body, createTime = eventTime ) - client.get(ServiceRepositoryWebhookResource::class).saveWebhookRequest( - repositoryWebhookRequest = repositoryWebhookRequest - ).data!! + try { + client.get(ServiceRepositoryWebhookResource::class).saveWebhookRequest( + repositoryWebhookRequest = repositoryWebhookRequest + ).data!! + } catch (ignored: Throwable) { + // 日志保存异常,不影响正常触发 + logger.warn("Failed to save webhook request", ignored) + } webhookTriggerService.trigger( scmType = scmType, matcher = matcher, From 6e563beca5a1ac46e29ea00f8fe01192092cd769 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Tue, 21 Nov 2023 15:10:54 +0800 Subject: [PATCH 142/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- support-files/templates/#etc#ci#common.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/support-files/templates/#etc#ci#common.yml b/support-files/templates/#etc#ci#common.yml index fad4f6872de..530f05b930a 100644 --- a/support-files/templates/#etc#ci#common.yml +++ b/support-files/templates/#etc#ci#common.yml @@ -216,6 +216,12 @@ spring: - index: 52 name: T_PIPELINE_BUILD_RECORD_TASK databaseShardingStrategy: SHARDING + - index: 53 + name: T_PIPELINE_TRIGGER_EVENT + databaseShardingStrategy: SHARDING + - index: 54 + name: T_PIPELINE_TRIGGER_DETAIL + databaseShardingStrategy: SHARDING endpoints: From 66b8a9fdee35ea77ca5d68b1de3bba4a1af79032 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Tue, 21 Nov 2023 18:04:52 +0800 Subject: [PATCH 143/143] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8E=E4=BB=A3=E7=A0=81=E5=BA=93=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=9F=A5=E7=9C=8B=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=BA=93=E4=BA=8B=E4=BB=B6=20#8122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- support-files/sql/1001_ci_process_ddl_mysql.sql | 4 ++-- .../sql/2003_v2.x/2020_ci_process-update_v2.0_mysql.sql | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/support-files/sql/1001_ci_process_ddl_mysql.sql b/support-files/sql/1001_ci_process_ddl_mysql.sql index 94431ceec4f..1737a0f3c7f 100644 --- a/support-files/sql/1001_ci_process_ddl_mysql.sql +++ b/support-files/sql/1001_ci_process_ddl_mysql.sql @@ -640,8 +640,8 @@ CREATE TABLE IF NOT EXISTS `T_PIPELINE_WEBHOOK` ( `PROJECT_NAME` VARCHAR(128) DEFAULT NULL COMMENT '项目名称', `TASK_ID` VARCHAR(34) DEFAULT NULL COMMENT '任务id', `DELETE` BIT(1) DEFAULT 0 COMMENT '是否删除', - `EVENT_TYPE` varchar(32) DEFAULT NULL COMMENT '事件类型', - `EXTERNAL_ID` varchar(32) DEFAULT NULL COMMENT 'webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port', + `EVENT_TYPE` varchar(64) DEFAULT NULL COMMENT '事件类型', + `EXTERNAL_ID` varchar(255) DEFAULT NULL COMMENT '代码库平台ID', `REPOSITORY_HASH_ID` varchar(64) null comment '代码库hashId', PRIMARY KEY (`ID`), UNIQUE KEY `UNI_INX_TPW_PROJECT_PIPELINE_TASK` (`PROJECT_ID`, `PIPELINE_ID`,`TASK_ID`), diff --git a/support-files/sql/2003_v2.x/2020_ci_process-update_v2.0_mysql.sql b/support-files/sql/2003_v2.x/2020_ci_process-update_v2.0_mysql.sql index 5ff4a257e3c..9e8b2a08b5e 100644 --- a/support-files/sql/2003_v2.x/2020_ci_process-update_v2.0_mysql.sql +++ b/support-files/sql/2003_v2.x/2020_ci_process-update_v2.0_mysql.sql @@ -91,7 +91,7 @@ BEGIN AND TABLE_NAME = 'T_PIPELINE_WEBHOOK' AND COLUMN_NAME = 'EVENT_TYPE') THEN ALTER TABLE `T_PIPELINE_WEBHOOK` - ADD COLUMN `EVENT_TYPE` varchar(32) DEFAULT null COMMENT '事件类型'; + ADD COLUMN `EVENT_TYPE` varchar(64) DEFAULT null COMMENT '事件类型'; END IF; IF NOT EXISTS(SELECT 1 @@ -100,7 +100,7 @@ BEGIN AND TABLE_NAME = 'T_PIPELINE_WEBHOOK' AND COLUMN_NAME = 'EXTERNAL_ID') THEN ALTER TABLE `T_PIPELINE_WEBHOOK` - ADD COLUMN `EXTERNAL_ID` varchar(32) DEFAULT null COMMENT 'webhook事件生产者ID,工蜂-工蜂ID,github-github id,svn-svn path,p4-p4port'; + ADD COLUMN `EXTERNAL_ID` varchar(255) DEFAULT null COMMENT '代码库平台ID'; END IF; IF NOT EXISTS(SELECT 1