From fcd35cad7943bb7205f023a8630b5e2ad5f59752 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Tue, 30 Jul 2024 17:08:22 +0800 Subject: [PATCH 01/25] =?UTF-8?q?feat=EF=BC=9A=E6=B5=81=E6=B0=B4=E7=BA=BF?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=AE=A1=E7=90=86=E6=9C=BA=E5=88=B6=20#8161?= =?UTF-8?q?=20=E6=A8=A1=E6=9D=BF=E5=B8=B8=E9=87=8F=E5=AE=9E=E4=BE=8B?= =?UTF-8?q?=E5=8C=96=E6=97=B6=E8=BD=AC=E6=8D=A2=E6=88=90=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF=E5=B8=B8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 模板实例化时模板常量转换成流水线常量 2. 保存为模板时,流水线常量转换成模板常量 --- .../process/engine/utils/PipelineUtils.kt | 37 ++++++++++++++++++- .../service/template/TemplateFacadeService.kt | 2 +- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/utils/PipelineUtils.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/utils/PipelineUtils.kt index d8b8c27fbba..062c79a5358 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/utils/PipelineUtils.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/utils/PipelineUtils.kt @@ -158,6 +158,39 @@ object PipelineUtils { return stages } + /** + * 将流水线常量转换成模板常量 + */ + fun fixedTemplateParam(model: Model): Model { + val triggerContainer = model.stages[0].containers[0] as TriggerContainer + val params = mutableListOf() + val templateParams = mutableListOf() + triggerContainer.params.forEach { + if (it.constant == true) { + templateParams.add(it) + } else { + params.add(it) + } + } + val fixedTriggerContainer = triggerContainer.copy( + params = params, + templateParams = if (templateParams.isEmpty()) { + null + } else { + templateParams + } + ) + val stages = ArrayList() + model.stages.forEachIndexed { index, stage -> + if (index == 0) { + stages.add(stage.copy(containers = listOf(fixedTriggerContainer))) + } else { + stages.add(stage) + } + } + return model.copy(stages = stages) + } + /** * 通过流水线参数和模板编排生成新Model */ @@ -178,7 +211,9 @@ object PipelineUtils { BuildPropertyCompatibilityTools.mergeProperties( from = templateTrigger.params, to = BuildPropertyCompatibilityTools.mergeProperties( - from = templateTrigger.templateParams!!, to = param ?: emptyList() + // 模板常量需要变成流水线常量 + from = templateTrigger.templateParams!!.map { it.copy(constant = true) }, + to = param ?: emptyList() ) ) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt index da357044710..517fb7ea74a 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt @@ -369,7 +369,7 @@ class TemplateFacadeService @Autowired constructor( statusCode = Response.Status.NOT_FOUND.statusCode, errorCode = ProcessMessageCode.ERROR_PIPELINE_MODEL_NOT_EXISTS ) - val templateModel: Model = objectMapper.readValue(template) + val templateModel: Model = PipelineUtils.fixedTemplateParam(objectMapper.readValue(template)) checkTemplateAtomsForExplicitVersion(templateModel, userId) val templateId = UUIDUtil.generate() dslContext.transaction { configuration -> From 138535cba5c9c5b89d46954f91b0d234daac1d9d Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Tue, 30 Jul 2024 21:03:52 +0800 Subject: [PATCH 02/25] =?UTF-8?q?feat=EF=BC=9A=E6=B5=81=E6=B0=B4=E7=BA=BF?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=AE=A1=E7=90=86=E6=9C=BA=E5=88=B6=20#8161?= =?UTF-8?q?=20=E6=A8=A1=E6=9D=BF=E5=B8=B8=E9=87=8F=E5=AE=9E=E4=BE=8B?= =?UTF-8?q?=E5=8C=96=E6=97=B6=E8=BD=AC=E6=8D=A2=E6=88=90=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF=E5=B8=B8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 模板实例化时模板常量转换成流水线常量 2. 保存为模板时,流水线常量转换成模板常量 --- .../devops/process/service/template/TemplateFacadeService.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/template/TemplateFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt index 517fb7ea74a..805d5a1816e 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt @@ -382,7 +382,7 @@ class TemplateFacadeService @Autowired constructor( templateName = saveAsTemplateReq.templateName, versionName = INIT_TEMPLATE_NAME, userId = userId, - template = template, + template = JsonUtil.toJson(templateModel, formatted = false), storeFlag = false, version = client.get(ServiceAllocIdResource::class).generateSegmentId(TEMPLATE_BIZ_TAG_NAME).data, desc = null From e986b171193de4a49a6d1c9f214ba74bbed2a222 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Wed, 31 Jul 2024 14:38:26 +0800 Subject: [PATCH 03/25] =?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=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=B2=A1=E6=9C=89oauth=E7=94=A8=E6=88=B7=EF=BC=8C=E6=89=A7?= =?UTF-8?q?=E8=A1=8Cpac=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builds/PipelineBuildFacadeService.kt | 1 - .../process/yaml/PipelineYamlFacadeService.kt | 20 +++---------------- 2 files changed, 3 insertions(+), 18 deletions(-) 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 d65c55e9a1f..e0706d86cfa 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 @@ -671,7 +671,6 @@ class PipelineBuildFacadeService( ) // 如果是PAC流水线,需要加上代码库hashId,给checkout:self使用 pipelineYamlFacadeService.buildYamlManualParamMap( - userId = userId, projectId = projectId, pipelineId = pipelineId )?.let { diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/yaml/PipelineYamlFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/yaml/PipelineYamlFacadeService.kt index baef71cd0c5..aea246c6a9c 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/yaml/PipelineYamlFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/yaml/PipelineYamlFacadeService.kt @@ -452,28 +452,14 @@ class PipelineYamlFacadeService @Autowired constructor( /** * 构建yaml流水线触发变量 */ - fun buildYamlManualParamMap(userId: String, projectId: String, pipelineId: String): Map? { + fun buildYamlManualParamMap(projectId: String, pipelineId: String): Map? { val pipelineYamlInfo = pipelineYamlInfoDao.get( dslContext = dslContext, projectId = projectId, pipelineId = pipelineId ) ?: return null - val repoHashId = pipelineYamlInfo.repoHashId - val repository = client.get(ServiceRepositoryResource::class).get( - projectId = projectId, - repositoryId = repoHashId, - repositoryType = RepositoryType.ID - ).data ?: return null - val setting = PacRepoSetting(repository = repository) - val event = PipelineYamlManualEvent( - userId = userId, - projectId = projectId, - repoHashId = repoHashId, - scmType = repository.getScmType() - ) - val action = eventActionFactory.loadManualEvent(setting = setting, event = event) return mutableMapOf( - BK_REPO_WEBHOOK_HASH_ID to BuildParameters(BK_REPO_WEBHOOK_HASH_ID, repoHashId), + BK_REPO_WEBHOOK_HASH_ID to BuildParameters(BK_REPO_WEBHOOK_HASH_ID, pipelineYamlInfo.repoHashId), PIPELINE_WEBHOOK_BRANCH to BuildParameters( - PIPELINE_WEBHOOK_BRANCH, action.data.context.defaultBranch ?: "" + PIPELINE_WEBHOOK_BRANCH, pipelineYamlInfo.defaultBranch ?: "" ) ) } From 69a79c6dad19aa5cade36e5661ca69c0ccdf9871 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 1 Aug 2024 11:41:07 +0800 Subject: [PATCH 04/25] =?UTF-8?q?feat=EF=BC=9A=E6=96=B0=E5=BB=BA/=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=97=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=B5=81=E6=B0=B4=E7=BA=BF=20#8164=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9E=84=E5=BB=BA=E5=8E=86=E5=8F=B2=E5=8C=BA?= =?UTF-8?q?=E5=88=86=E6=BA=90=E6=9D=90=E6=96=99=E5=88=86=E6=94=AF=E5=92=8C?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E5=88=86=E6=94=AF=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 构建历史支持源材料和触发材料搜索 2. 触发分支和源材料分支支持下来搜索 --- .../api/app/AppPipelineBuildResource.kt | 8 +- .../api/service/ServiceBuildResource.kt | 8 +- .../process/api/user/UserBuildResource.kt | 29 +- .../devops/process/enums/HistorySearchType.kt | 39 +++ .../process/engine/dao/PipelineBuildDao.kt | 255 ++++++++++++++++-- .../engine/service/PipelineRuntimeService.kt | 135 +++++++--- .../process/api/ServiceBuildResourceImpl.kt | 8 +- .../process/api/UserBuildResourceImpl.kt | 34 ++- .../api/app/AppPipelineBuildResourceImpl.kt | 8 +- .../builds/PipelineBuildFacadeService.kt | 36 ++- 10 files changed, 485 insertions(+), 75 deletions(-) create mode 100644 src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/enums/HistorySearchType.kt diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/app/AppPipelineBuildResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/app/AppPipelineBuildResource.kt index 99f0888e629..34c467360c6 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/app/AppPipelineBuildResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/app/AppPipelineBuildResource.kt @@ -347,6 +347,12 @@ interface AppPipelineBuildResource { buildMsg: String?, @Parameter(description = "查看指定版本调试数据", required = false, example = "false") @QueryParam("version") - customVersion: Int? = null + customVersion: Int? = null, + @Parameter(description = "触发代码库", required = false) + @QueryParam("triggerAlias") + triggerAlias: List?, + @Parameter(description = "触发分支", required = false) + @QueryParam("triggerBranch") + triggerBranch: List? ): Result> } 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 7b22149b9c5..f75f41007d3 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 @@ -504,7 +504,13 @@ interface ServiceBuildResource { archiveFlag: Boolean? = false, @Parameter(description = "查看指定版本调试数据", required = false, example = "false") @QueryParam("version") - customVersion: Int? = null + customVersion: Int? = null, + @Parameter(description = "触发代码库", required = false) + @QueryParam("triggerAlias") + triggerAlias: List?, + @Parameter(description = "触发分支", required = false) + @QueryParam("triggerBranch") + triggerBranch: List? ): Result> @Operation(summary = "获取构建详情") diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserBuildResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserBuildResource.kt index 6a744d74b60..834f9122939 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserBuildResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserBuildResource.kt @@ -38,6 +38,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.annotation.BkField +import com.tencent.devops.process.enums.HistorySearchType import com.tencent.devops.process.pojo.BuildHistory import com.tencent.devops.process.pojo.BuildHistoryRemark import com.tencent.devops.process.pojo.BuildId @@ -400,13 +401,13 @@ interface UserBuildResource { @Parameter(description = "每页多少条", required = false, example = "20") @QueryParam("pageSize") pageSize: Int?, - @Parameter(description = "代码库别名", required = false) + @Parameter(description = "源材料代码库别名", required = false) @QueryParam("materialAlias") materialAlias: List?, @Parameter(description = "代码库URL", required = false) @QueryParam("materialUrl") materialUrl: String?, - @Parameter(description = "分支", required = false) + @Parameter(description = "源材料分支", required = false) @QueryParam("materialBranch") materialBranch: List?, @Parameter(description = "commitId", required = false) @@ -462,7 +463,13 @@ interface UserBuildResource { archiveFlag: Boolean? = false, @Parameter(description = "查看指定版本调试数据", required = false, example = "false") @QueryParam("version") - customVersion: Int? = null + customVersion: Int? = null, + @Parameter(description = "触发代码库", required = false) + @QueryParam("triggerAlias") + triggerAlias: List?, + @Parameter(description = "触发分支", required = false) + @QueryParam("triggerBranch") + triggerBranch: List? ): Result> @Operation(summary = "修改流水线备注") @@ -534,7 +541,13 @@ interface UserBuildResource { pipelineId: String, @Parameter(description = "查看指定版本调试数据", required = false, example = "false") @QueryParam("version") - debugVersion: Int? = null + debugVersion: Int? = null, + @Parameter(description = "搜索分支关键字", required = false) + @QueryParam("search") + search: String?, + @Parameter(description = "搜索类型, 触发/源材料", required = false) + @QueryParam("type") + type: HistorySearchType? ): Result> @Operation(summary = "获取流水线构建中的查询条件-分支") @@ -556,7 +569,13 @@ interface UserBuildResource { alias: List?, @Parameter(description = "查看指定版本调试数据", required = false, example = "false") @QueryParam("debugVersion") - debugVersion: Int? = null + debugVersion: Int? = null, + @Parameter(description = "搜索分支关键字", required = false) + @QueryParam("search") + search: String?, + @Parameter(description = "搜索类型,触发/源材料", required = false) + @QueryParam("type") + type: HistorySearchType? ): Result> @Operation(summary = "触发审核") diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/enums/HistorySearchType.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/enums/HistorySearchType.kt new file mode 100644 index 00000000000..10e00ed6517 --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/enums/HistorySearchType.kt @@ -0,0 +1,39 @@ +/* + * 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.enums + +/** + * 构建历史搜索类型 + */ +enum class HistorySearchType { + // 触发器 + TRIGGER, + + // 源材料 + MATERIAL +} diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt index 211a783230e..7c1e539dbf4 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt @@ -49,13 +49,11 @@ import com.tencent.devops.model.process.tables.records.TPipelineBuildHistoryReco import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.engine.pojo.BuildInfo import com.tencent.devops.process.engine.pojo.BuildRetryInfo +import com.tencent.devops.process.enums.HistorySearchType import com.tencent.devops.process.pojo.BuildStageStatus import com.tencent.devops.process.pojo.PipelineBuildMaterial import com.tencent.devops.process.pojo.app.StartBuildContext import com.tencent.devops.process.pojo.code.WebhookInfo -import java.sql.Timestamp -import java.time.LocalDateTime -import javax.ws.rs.core.Response import org.jooq.Condition import org.jooq.DSLContext import org.jooq.DatePart @@ -64,6 +62,9 @@ import org.jooq.RecordMapper import org.jooq.SelectConditionStep import org.jooq.impl.DSL import org.springframework.stereotype.Repository +import java.sql.Timestamp +import java.time.LocalDateTime +import javax.ws.rs.core.Response @Suppress("ALL") @Repository @@ -956,7 +957,9 @@ class PipelineBuildDao { buildNoEnd: Int?, buildMsg: String?, startUser: List?, - debugVersion: Int? + debugVersion: Int?, + triggerAlias: List?, + triggerBranch: List? ): Int { return if (debugVersion == null) { with(T_PIPELINE_BUILD_HISTORY) { @@ -983,7 +986,9 @@ class PipelineBuildDao { remark = remark, buildNoStart = buildNoStart, buildNoEnd = buildNoEnd, - buildMsg = buildMsg + buildMsg = buildMsg, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) where.fetchOne(0, Int::class.java)!! } @@ -1014,7 +1019,9 @@ class PipelineBuildDao { remark = remark, buildNoStart = buildNoStart, buildNoEnd = buildNoEnd, - buildMsg = buildMsg + buildMsg = buildMsg, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) where.fetchOne(0, Int::class.java)!! } @@ -1048,7 +1055,9 @@ class PipelineBuildDao { buildMsg: String?, startUser: List?, updateTimeDesc: Boolean? = null, - debugVersion: Int? + debugVersion: Int?, + triggerAlias: List?, + triggerBranch: List? ): Collection { return if (debugVersion == null) { with(T_PIPELINE_BUILD_HISTORY) { @@ -1074,7 +1083,9 @@ class PipelineBuildDao { remark = remark, buildNoStart = buildNoStart, buildNoEnd = buildNoEnd, - buildMsg = buildMsg + buildMsg = buildMsg, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) when (updateTimeDesc) { @@ -1111,7 +1122,9 @@ class PipelineBuildDao { remark = remark, buildNoStart = buildNoStart, buildNoEnd = buildNoEnd, - buildMsg = buildMsg + buildMsg = buildMsg, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) when (updateTimeDesc) { true -> where.orderBy(UPDATE_TIME.desc(), BUILD_ID) @@ -1145,7 +1158,9 @@ class PipelineBuildDao { remark: String?, buildNoStart: Int?, buildNoEnd: Int?, - buildMsg: String? + buildMsg: String?, + triggerAlias: List?, + triggerBranch: List? ) { if (!materialAlias.isNullOrEmpty() && materialAlias.first().isNotBlank()) { var conditionsOr: Condition @@ -1243,6 +1258,156 @@ class PipelineBuildDao { if (!buildMsg.isNullOrBlank()) { where.and(BUILD_MSG.like("%$buildMsg%")) } + if (!triggerAlias.isNullOrEmpty() && triggerAlias.first().isNotBlank()) { + var conditionsOr: Condition + + conditionsOr = JooqUtils.jsonExtract(t1 = WEBHOOK_INFO, t2 = "\$.webhookAliasName", lower = true) + .like("%${triggerAlias.first().lowercase()}%") + + triggerAlias.forEachIndexed { index, s -> + if (index == 0) return@forEachIndexed + conditionsOr = conditionsOr.or( + JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookAliasName", lower = true) + .like("%${s.lowercase()}%") + ) + } + where.and(conditionsOr) + } + if (!triggerBranch.isNullOrEmpty() && triggerBranch.first().isNotBlank()) { + var conditionsOr: Condition + + conditionsOr = JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookBranch", lower = true) + .like("%${triggerBranch.first().lowercase()}%") + + triggerBranch.forEachIndexed { index, s -> + if (index == 0) return@forEachIndexed + conditionsOr = conditionsOr.or( + JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookBranch", lower = true) + .like("%${s.lowercase()}%") + ) + } + where.and(conditionsOr) + } + } + + private fun TPipelineBuildHistory.makeSearchOptionsCondition( + where: SelectConditionStep<*>, + type: HistorySearchType, + materialAlias: List? = null, + materialBranch: String? = null, + triggerAlias: List? = null, + triggerBranch: String? = null + ) { + when (type) { + HistorySearchType.MATERIAL -> + where.and(MATERIAL.isNotNull) + + HistorySearchType.TRIGGER -> + where.and(WEBHOOK_INFO.isNotNull) + } + if (!materialAlias.isNullOrEmpty() && materialAlias.first().isNotBlank()) { + var conditionsOr: Condition + + conditionsOr = JooqUtils.jsonExtract(t1 = MATERIAL, t2 = "\$[*].aliasName", lower = true) + .like("%${materialAlias.first().lowercase()}%") + + materialAlias.forEachIndexed { index, s -> + if (index == 0) return@forEachIndexed + conditionsOr = conditionsOr.or( + JooqUtils.jsonExtract(MATERIAL, "\$[*].aliasName", lower = true) + .like("%${s.lowercase()}%") + ) + } + where.and(conditionsOr) + } + if (!materialBranch.isNullOrBlank()) { + where.and( + JooqUtils.jsonExtract(MATERIAL, "\$[*].branchName", lower = true) + .like("%${materialBranch.lowercase()}%") + ) + } + if (!triggerAlias.isNullOrEmpty() && triggerAlias.first().isNotBlank()) { + var conditionsOr: Condition + + conditionsOr = JooqUtils.jsonExtract(t1 = WEBHOOK_INFO, t2 = "\$.webhookAliasName", lower = true) + .like("%${triggerAlias.first().lowercase()}%") + + triggerAlias.forEachIndexed { index, s -> + if (index == 0) return@forEachIndexed + conditionsOr = conditionsOr.or( + JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookAliasName", lower = true) + .like("%${s.lowercase()}%") + ) + } + where.and(conditionsOr) + } + + if (!triggerBranch.isNullOrBlank()) { + where.and( + JooqUtils.jsonExtract(WEBHOOK_INFO, "\$[*].webhookBranch", lower = true) + .like("%${triggerBranch.lowercase()}%") + ) + } + } + + private fun TPipelineBuildHistoryDebug.makeSearchOptionsDebugCondition( + where: SelectConditionStep<*>, + type: HistorySearchType, + materialAlias: List? = null, + materialBranch: String? = null, + triggerAlias: List? = null, + triggerBranch: String? = null + ) { + when (type) { + HistorySearchType.MATERIAL -> + where.and(MATERIAL.isNotNull) + + HistorySearchType.TRIGGER -> + where.and(WEBHOOK_INFO.isNotNull) + } + if (!materialAlias.isNullOrEmpty() && materialAlias.first().isNotBlank()) { + var conditionsOr: Condition + + conditionsOr = JooqUtils.jsonExtract(t1 = MATERIAL, t2 = "\$[*].aliasName", lower = true) + .like("%${materialAlias.first().lowercase()}%") + + materialAlias.forEachIndexed { index, s -> + if (index == 0) return@forEachIndexed + conditionsOr = conditionsOr.or( + JooqUtils.jsonExtract(MATERIAL, "\$[*].aliasName", lower = true) + .like("%${s.lowercase()}%") + ) + } + where.and(conditionsOr) + } + if (!materialBranch.isNullOrBlank()) { + where.and( + JooqUtils.jsonExtract(MATERIAL, "\$[*].branchName", lower = true) + .like("%${materialBranch.lowercase()}%") + ) + } + if (!triggerAlias.isNullOrEmpty() && triggerAlias.first().isNotBlank()) { + var conditionsOr: Condition + + conditionsOr = JooqUtils.jsonExtract(t1 = WEBHOOK_INFO, t2 = "\$.webhookAliasName", lower = true) + .like("%${triggerAlias.first().lowercase()}%") + + triggerAlias.forEachIndexed { index, s -> + if (index == 0) return@forEachIndexed + conditionsOr = conditionsOr.or( + JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookAliasName", lower = true) + .like("%${s.lowercase()}%") + ) + } + where.and(conditionsOr) + } + + if (!triggerBranch.isNullOrBlank()) { + where.and( + JooqUtils.jsonExtract(WEBHOOK_INFO, "\$[*].webhookBranch", lower = true) + .like("%${triggerBranch.lowercase()}%") + ) + } } private fun TPipelineBuildHistoryDebug.makeDebugCondition( @@ -1266,7 +1431,9 @@ class PipelineBuildDao { remark: String?, buildNoStart: Int?, buildNoEnd: Int?, - buildMsg: String? + buildMsg: String?, + triggerAlias: List?, + triggerBranch: List? ) { // 增加过滤,对前端屏蔽已删除的构建 where.and(DELETE_TIME.isNull) @@ -1366,6 +1533,36 @@ class PipelineBuildDao { if (!buildMsg.isNullOrBlank()) { where.and(BUILD_MSG.like("%$buildMsg%")) } + if (!triggerAlias.isNullOrEmpty() && triggerAlias.first().isNotBlank()) { + var conditionsOr: Condition + + conditionsOr = JooqUtils.jsonExtract(t1 = WEBHOOK_INFO, t2 = "\$.webhookAliasName", lower = true) + .like("%${triggerAlias.first().lowercase()}%") + + triggerAlias.forEachIndexed { index, s -> + if (index == 0) return@forEachIndexed + conditionsOr = conditionsOr.or( + JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookAliasName", lower = true) + .like("%${s.lowercase()}%") + ) + } + where.and(conditionsOr) + } + if (!triggerBranch.isNullOrEmpty() && triggerBranch.first().isNotBlank()) { + var conditionsOr: Condition + + conditionsOr = JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookBranch", lower = true) + .like("%${triggerBranch.first().lowercase()}%") + + triggerBranch.forEachIndexed { index, s -> + if (index == 0) return@forEachIndexed + conditionsOr = conditionsOr.or( + JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookBranch", lower = true) + .like("%${s.lowercase()}%") + ) + } + where.and(conditionsOr) + } } fun updateBuildRemark( @@ -1410,25 +1607,49 @@ class PipelineBuildDao { } } - fun getBuildHistoryMaterial( + /** + * 构建历史搜索下拉框 + */ + fun listHistorySearchOptions( dslContext: DSLContext, projectId: String, pipelineId: String, - debugVersion: Int? + debugVersion: Int?, + type: HistorySearchType, + materialAlias: List? = null, + materialBranch: String? = null, + triggerAlias: List? = null, + triggerBranch: String? = null ): Collection { return if (debugVersion == null) { with(T_PIPELINE_BUILD_HISTORY) { - dslContext.selectFrom(this) + val where = dslContext.selectFrom(this) .where(PIPELINE_ID.eq(pipelineId).and(PROJECT_ID.eq(projectId))) - .orderBy(BUILD_NUM.desc()).limit(DEFAULT_PAGE_SIZE) + makeSearchOptionsCondition( + where = where, + type = type, + materialAlias = materialAlias, + materialBranch = materialBranch, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch + ) + where.orderBy(BUILD_NUM.desc()).limit(DEFAULT_PAGE_SIZE) .fetch(mapper) } } else { with(T_PIPELINE_BUILD_HISTORY_DEBUG) { - dslContext.selectFrom(this) + val where = dslContext.selectFrom(this) .where(PIPELINE_ID.eq(pipelineId).and(PROJECT_ID.eq(projectId))) .and(VERSION.eq(debugVersion)) - .orderBy(BUILD_NUM.desc()).limit(DEFAULT_PAGE_SIZE) + makeSearchOptionsDebugCondition( + where = where, + type = type, + materialAlias = materialAlias, + materialBranch = materialBranch, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch + ) + where.orderBy(BUILD_NUM.desc()).limit(DEFAULT_PAGE_SIZE) .fetch(debugMapper) } } 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 6d97ed88e11..b6d2af48002 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 @@ -106,6 +106,7 @@ import com.tencent.devops.process.engine.service.record.TaskBuildRecordService import com.tencent.devops.process.engine.service.rule.PipelineRuleService import com.tencent.devops.process.engine.utils.ContainerUtils import com.tencent.devops.process.engine.utils.PipelineUtils +import com.tencent.devops.process.enums.HistorySearchType import com.tencent.devops.process.pojo.BuildBasicInfo import com.tencent.devops.process.pojo.BuildHistory import com.tencent.devops.process.pojo.BuildId @@ -136,15 +137,15 @@ import com.tencent.devops.process.utils.PIPELINE_NAME import com.tencent.devops.process.utils.PIPELINE_RETRY_COUNT import com.tencent.devops.process.utils.PIPELINE_START_TASK_ID import com.tencent.devops.process.utils.PipelineVarUtil -import java.time.LocalDateTime -import java.util.Date -import java.util.concurrent.TimeUnit import org.jooq.DSLContext import org.jooq.Result 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 +import java.util.Date +import java.util.concurrent.TimeUnit /** * 流水线运行时相关的服务 @@ -371,7 +372,9 @@ class PipelineRuntimeService @Autowired constructor( startUser: List?, updateTimeDesc: Boolean? = null, queryDslContext: DSLContext? = null, - debugVersion: Int? + debugVersion: Int?, + triggerAlias: List?, + triggerBranch: List? ): List { val currentTimestamp = System.currentTimeMillis() // 限制最大一次拉1000,防止攻击 @@ -404,7 +407,9 @@ class PipelineRuntimeService @Autowired constructor( buildMsg = buildMsg, startUser = startUser, updateTimeDesc = updateTimeDesc, - debugVersion = debugVersion + debugVersion = debugVersion, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) val result = mutableListOf() list.forEach { @@ -417,43 +422,105 @@ class PipelineRuntimeService @Autowired constructor( pipelineBuildDao.updateBuildRemark(dslContext, projectId, pipelineId, buildId, remark) } - fun getHistoryConditionRepo(projectId: String, pipelineId: String, debugVersion: Int?): List { - val history = pipelineBuildDao.getBuildHistoryMaterial(dslContext, projectId, pipelineId, debugVersion) - val materialObjList = mutableListOf() - history.forEach { - if (!it.material.isNullOrEmpty()) { - materialObjList.addAll(it.material!!) + fun getHistoryConditionRepo( + projectId: String, + pipelineId: String, + debugVersion: Int?, + search: String?, + type: HistorySearchType? = HistorySearchType.MATERIAL + ): List { + return when (type) { + HistorySearchType.MATERIAL -> { + val history = pipelineBuildDao.listHistorySearchOptions( + dslContext = dslContext, + projectId = projectId, + pipelineId = pipelineId, + debugVersion = debugVersion, + type = type, + materialAlias = search?.let { listOf(it) } + ) + val materialObjList = mutableListOf() + history.forEach { + if (!it.material.isNullOrEmpty()) { + materialObjList.addAll(it.material!!) + } + } + materialObjList.filter { !it.aliasName.isNullOrBlank() }.map { it.aliasName!! }.distinct() } + + HistorySearchType.TRIGGER -> { + val history = pipelineBuildDao.listHistorySearchOptions( + dslContext = dslContext, + projectId = projectId, + pipelineId = pipelineId, + debugVersion = debugVersion, + type = type, + triggerAlias = search?.let { listOf(it) } + ) + history.filter { it.webhookInfo != null && !it.webhookInfo!!.webhookAliasName.isNullOrBlank() } + .map { it.webhookInfo!!.webhookAliasName!! }.distinct() + } + + else -> emptyList() } - return materialObjList.filter { !it.aliasName.isNullOrBlank() }.map { it.aliasName!! }.distinct() } fun getHistoryConditionBranch( projectId: String, pipelineId: String, aliasList: List?, - debugVersion: Int? = null + debugVersion: Int? = null, + search: String?, + type: HistorySearchType? = HistorySearchType.MATERIAL ): List { - val history = pipelineBuildDao.getBuildHistoryMaterial(dslContext, projectId, pipelineId, debugVersion) - val materialObjList = mutableListOf() - history.forEach { - if (!it.material.isNullOrEmpty()) { - materialObjList.addAll(it.material!!) + return when (type) { + HistorySearchType.MATERIAL -> { + val history = pipelineBuildDao.listHistorySearchOptions( + dslContext = dslContext, + projectId = projectId, + pipelineId = pipelineId, + debugVersion = debugVersion, + type = type, + materialAlias = aliasList, + materialBranch = search + ) + val materialObjList = mutableListOf() + history.forEach { + if (!it.material.isNullOrEmpty()) { + materialObjList.addAll(it.material!!) + } + } + val aliasNames = if (aliasList.isNullOrEmpty()) { + materialObjList.map { it.aliasName } + } else { + aliasList + } + + val result = mutableListOf() + aliasNames.distinct().forEach { alias -> + val branchNames = materialObjList.filter { + it.aliasName == alias && !it.branchName.isNullOrBlank() + }.map { it.branchName!! }.distinct() + result.addAll(branchNames) + } + result } - } - val aliasNames = if (aliasList.isNullOrEmpty()) { - materialObjList.map { it.aliasName } - } else { - aliasList - } - val result = mutableListOf() - aliasNames.distinct().forEach { alias -> - val branchNames = materialObjList.filter { it.aliasName == alias && !it.branchName.isNullOrBlank() } - .map { it.branchName!! }.distinct() - result.addAll(branchNames) + HistorySearchType.TRIGGER -> { + val history = pipelineBuildDao.listHistorySearchOptions( + dslContext = dslContext, + projectId = projectId, + pipelineId = pipelineId, + debugVersion = debugVersion, + type = type, + triggerAlias = aliasList, + triggerBranch = search + ) + history.filter { it.webhookInfo != null && !it.webhookInfo!!.webhookBranch.isNullOrBlank() } + .map { it.webhookInfo!!.webhookBranch!! }.distinct() + } + else -> emptyList() } - return result.distinct() } private fun genBuildHistory( @@ -1792,7 +1859,9 @@ class PipelineRuntimeService @Autowired constructor( buildMsg: String? = null, startUser: List? = null, queryDslContext: DSLContext? = null, - debugVersion: Int? = null + debugVersion: Int? = null, + triggerAlias: List?, + triggerBranch: List? ): Int { return pipelineBuildDao.count( dslContext = queryDslContext ?: dslContext, @@ -1818,7 +1887,9 @@ class PipelineRuntimeService @Autowired constructor( buildNoEnd = buildNoEnd, buildMsg = buildMsg, startUser = startUser, - debugVersion = debugVersion + debugVersion = debugVersion, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) } 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 70f6091c997..4502e8b1f50 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 @@ -385,7 +385,9 @@ class ServiceBuildResourceImpl @Autowired constructor( buildMsg: String?, startUser: List?, archiveFlag: Boolean?, - customVersion: Int? + customVersion: Int?, + triggerAlias: List?, + triggerBranch: List? ): Result> { checkUserId(userId) checkParam(projectId, pipelineId) @@ -419,7 +421,9 @@ class ServiceBuildResourceImpl @Autowired constructor( startUser = startUser?.filter { it.isNotBlank() }, updateTimeDesc = updateTimeDesc, archiveFlag = archiveFlag, - customVersion = customVersion + customVersion = customVersion, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) return Result(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 b3f5d17faeb..8c4585739c7 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 @@ -42,6 +42,7 @@ import com.tencent.devops.common.pipeline.pojo.element.Element import com.tencent.devops.common.web.RestResource import com.tencent.devops.process.api.user.UserBuildResource import com.tencent.devops.process.engine.service.PipelineProgressRateService +import com.tencent.devops.process.enums.HistorySearchType import com.tencent.devops.process.pojo.BuildHistory import com.tencent.devops.process.pojo.BuildHistoryRemark import com.tencent.devops.process.pojo.BuildId @@ -450,7 +451,9 @@ class UserBuildResourceImpl @Autowired constructor( buildNoEnd: Int?, buildMsg: String?, archiveFlag: Boolean?, - customVersion: Int? + customVersion: Int?, + triggerAlias: List?, + triggerBranch: List? ): Result> { checkParam(userId, projectId, pipelineId) val result = pipelineBuildFacadeService.getHistoryBuild( @@ -479,7 +482,9 @@ class UserBuildResourceImpl @Autowired constructor( buildNoEnd = buildNoEnd, buildMsg = buildMsg, archiveFlag = archiveFlag, - customVersion = customVersion + customVersion = customVersion, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) if (archiveFlag != true) { pipelineRecentUseService.record(userId, projectId, pipelineId) @@ -527,12 +532,21 @@ class UserBuildResourceImpl @Autowired constructor( userId: String, projectId: String, pipelineId: String, - debugVersion: Int? + debugVersion: Int?, + search: String?, + type: HistorySearchType? ): Result> { checkParam(userId, projectId, pipelineId) - return Result(pipelineBuildFacadeService.getHistoryConditionRepo( - userId, projectId, pipelineId, debugVersion - )) + return Result( + pipelineBuildFacadeService.getHistoryConditionRepo( + userId = userId, + projectId = projectId, + pipelineId = pipelineId, + debugVersion = debugVersion, + search = search, + type = type + ) + ) } override fun getHistoryConditionBranch( @@ -540,7 +554,9 @@ class UserBuildResourceImpl @Autowired constructor( projectId: String, pipelineId: String, alias: List?, - debugVersion: Int? + debugVersion: Int?, + search: String?, + type: HistorySearchType? ): Result> { checkParam(userId, projectId, pipelineId) return Result( @@ -549,7 +565,9 @@ class UserBuildResourceImpl @Autowired constructor( projectId = projectId, pipelineId = pipelineId, alias = alias, - debugVersion = debugVersion + debugVersion = debugVersion, + search = search, + type = type ) ) } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/app/AppPipelineBuildResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/app/AppPipelineBuildResourceImpl.kt index 4bde9b93f38..55ff59ccf21 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/app/AppPipelineBuildResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/app/AppPipelineBuildResourceImpl.kt @@ -198,7 +198,9 @@ class AppPipelineBuildResourceImpl @Autowired constructor( buildNoStart: Int?, buildNoEnd: Int?, buildMsg: String?, - customVersion: Int? + customVersion: Int?, + triggerAlias: List?, + triggerBranch: List? ): Result> { checkParam(userId, projectId, pipelineId, pageSize) val result = pipelineBuildFacadeService.getHistoryBuild( @@ -226,7 +228,9 @@ class AppPipelineBuildResourceImpl @Autowired constructor( buildNoStart = buildNoStart, buildNoEnd = buildNoEnd, buildMsg = buildMsg, - customVersion = customVersion + customVersion = customVersion, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) return Result(result) } 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 e0706d86cfa..e416199294a 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 @@ -102,6 +102,7 @@ import com.tencent.devops.process.engine.service.record.ContainerBuildRecordServ import com.tencent.devops.process.engine.service.record.PipelineBuildRecordService import com.tencent.devops.process.engine.utils.BuildUtils import com.tencent.devops.process.engine.utils.PipelineUtils +import com.tencent.devops.process.enums.HistorySearchType import com.tencent.devops.process.jmx.api.ProcessJmxApi import com.tencent.devops.process.permission.PipelinePermissionService import com.tencent.devops.process.pojo.BuildBasicInfo @@ -1964,7 +1965,9 @@ class PipelineBuildFacadeService( startUser: List? = null, updateTimeDesc: Boolean? = null, archiveFlag: Boolean? = false, - customVersion: Int? + customVersion: Int?, + triggerAlias: List?, + triggerBranch: List? ): BuildHistoryPage { val pageNotNull = page ?: 0 val pageSizeNotNull = pageSize ?: 50 @@ -2044,7 +2047,9 @@ class PipelineBuildFacadeService( buildMsg = buildMsg, startUser = startUser, queryDslContext = queryDslContext, - debugVersion = targetDebugVersion + debugVersion = targetDebugVersion, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) val newHistoryBuilds = pipelineRuntimeService.listPipelineBuildHistory( @@ -2074,7 +2079,9 @@ class PipelineBuildFacadeService( startUser = startUser, updateTimeDesc = updateTimeDesc, queryDslContext = queryDslContext, - debugVersion = targetDebugVersion + debugVersion = targetDebugVersion, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) val buildHistories = mutableListOf() buildHistories.addAll(newHistoryBuilds) @@ -2156,7 +2163,9 @@ class PipelineBuildFacadeService( userId: String, projectId: String, pipelineId: String, - debugVersion: Int? + debugVersion: Int?, + search: String?, + type: HistorySearchType? ): List { pipelinePermissionService.validPipelinePermission( userId = userId, @@ -2174,7 +2183,13 @@ class PipelineBuildFacadeService( val draftVersion = pipelineRepositoryService.getDraftVersionResource(projectId, pipelineId) draftVersion?.version == debugVersion } - return pipelineRuntimeService.getHistoryConditionRepo(projectId, pipelineId, targetDebugVersion) + return pipelineRuntimeService.getHistoryConditionRepo( + projectId = projectId, + pipelineId = pipelineId, + debugVersion = targetDebugVersion, + search = search, + type = type + ) } fun getHistoryConditionBranch( @@ -2182,7 +2197,9 @@ class PipelineBuildFacadeService( projectId: String, pipelineId: String, alias: List?, - debugVersion: Int? + debugVersion: Int?, + search: String?, + type: HistorySearchType? ): List { pipelinePermissionService.validPipelinePermission( userId = userId, @@ -2201,7 +2218,12 @@ class PipelineBuildFacadeService( draftVersion?.version == debugVersion } return pipelineRuntimeService.getHistoryConditionBranch( - projectId, pipelineId, alias, targetDebugVersion + projectId = projectId, + pipelineId = pipelineId, + aliasList = alias, + debugVersion = targetDebugVersion, + search = search, + type = type ) } From 9c2162c69d55b888e9c8fa3954c07ed6f00bf0aa Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 1 Aug 2024 19:43:54 +0800 Subject: [PATCH 05/25] =?UTF-8?q?feat=EF=BC=9A=E6=96=B0=E5=BB=BA/=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=97=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=B5=81=E6=B0=B4=E7=BA=BF=20#8164=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9E=84=E5=BB=BA=E5=8E=86=E5=8F=B2=E5=8C=BA?= =?UTF-8?q?=E5=88=86=E6=BA=90=E6=9D=90=E6=96=99=E5=88=86=E6=94=AF=E5=92=8C?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E5=88=86=E6=94=AF=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 构建历史支持源材料和触发材料搜索 2. 触发分支和源材料分支支持下来搜索 --- .../com/tencent/devops/process/engine/dao/PipelineBuildDao.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt index 7c1e539dbf4..a598ed0c9ba 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt @@ -1344,7 +1344,7 @@ class PipelineBuildDao { if (!triggerBranch.isNullOrBlank()) { where.and( - JooqUtils.jsonExtract(WEBHOOK_INFO, "\$[*].webhookBranch", lower = true) + JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookBranch", lower = true) .like("%${triggerBranch.lowercase()}%") ) } @@ -1404,7 +1404,7 @@ class PipelineBuildDao { if (!triggerBranch.isNullOrBlank()) { where.and( - JooqUtils.jsonExtract(WEBHOOK_INFO, "\$[*].webhookBranch", lower = true) + JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookBranch", lower = true) .like("%${triggerBranch.lowercase()}%") ) } From 57f8791510d8ccf213d5f4d5ad4cfe0a35f5e620 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 1 Aug 2024 20:46:24 +0800 Subject: [PATCH 06/25] =?UTF-8?q?feat=EF=BC=9A=E6=96=B0=E5=BB=BA/=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=97=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=B5=81=E6=B0=B4=E7=BA=BF=20#8164=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9E=84=E5=BB=BA=E5=8E=86=E5=8F=B2=E5=8C=BA?= =?UTF-8?q?=E5=88=86=E6=BA=90=E6=9D=90=E6=96=99=E5=88=86=E6=94=AF=E5=92=8C?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E5=88=86=E6=94=AF=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 构建历史支持源材料和触发材料搜索 2. 触发分支和源材料分支支持下来搜索 --- .../com/tencent/devops/process/engine/dao/PipelineBuildDao.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt index a598ed0c9ba..4021f20e438 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt @@ -73,7 +73,7 @@ class PipelineBuildDao { companion object { private val mapper = PipelineBuildInfoJooqMapper() private val debugMapper = PipelineDebugBuildInfoJooqMapper() - private const val DEFAULT_PAGE_SIZE = 10 + private const val DEFAULT_PAGE_SIZE = 100 } fun create(dslContext: DSLContext, startBuildContext: StartBuildContext) { From d53a163d90838eb3386be4783952196fb91d66d5 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 1 Aug 2024 20:47:11 +0800 Subject: [PATCH 07/25] =?UTF-8?q?feat=EF=BC=9A=E6=B5=81=E6=B0=B4=E7=BA=BF?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=AE=A1=E7=90=86=E6=9C=BA=E5=88=B6=20#8161?= =?UTF-8?q?=20=E7=A9=BA=E7=99=BD=E6=A8=A1=E6=9D=BF=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E7=94=B1Blank=E6=94=B9=E6=88=90Default?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sql/5001_init_dml/5001_ci_process-init_ddl_mysql.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/support-files/sql/5001_init_dml/5001_ci_process-init_ddl_mysql.sql b/support-files/sql/5001_init_dml/5001_ci_process-init_ddl_mysql.sql index e5e699547de..cbb7edd1af7 100755 --- a/support-files/sql/5001_init_dml/5001_ci_process-init_ddl_mysql.sql +++ b/support-files/sql/5001_init_dml/5001_ci_process-init_ddl_mysql.sql @@ -2,8 +2,8 @@ SET NAMES utf8mb4; USE devops_ci_process; -- 空白流水线模板 -INSERT IGNORE INTO `T_TEMPLATE` (`VERSION`, `ID`, `TEMPLATE_NAME`, `PROJECT_ID`, `VERSION_NAME`, `CREATOR`, `CREATED_TIME`, `TEMPLATE`, `TYPE`, `CATEGORY`, `LOGO_URL`, `SRC_TEMPLATE_ID`, `STORE_FLAG`, `WEIGHT`) VALUES - (1, '072d516d300b4812a4f652f585eacc36', 'Blank', '', 'init', '', '2019-05-23 16:24:02', '{\n \"name\" : \"Blank\",\n \"desc\" : \"\",\n \"stages\" : [ {\n \"containers\" : [ {\n \"@type\" : \"trigger\",\n \"name\" : \"Trigger\",\n \"elements\" : [ {\n \"@type\" : \"manualTrigger\",\n \"name\" : \"Manual\",\n \"id\" : \"T-1-1-1\",\n \"properties\" : [ ]\n } ]\n } ],\n \"id\" : \"stage-1\"\n }]\n}', 'PUBLIC', '', NULL, NULL, 0, 100); +REPLACE INTO `T_TEMPLATE` (`VERSION`, `ID`, `TEMPLATE_NAME`, `PROJECT_ID`, `VERSION_NAME`, `CREATOR`, `CREATED_TIME`, `TEMPLATE`, `TYPE`, `CATEGORY`, `LOGO_URL`, `SRC_TEMPLATE_ID`, `STORE_FLAG`, `WEIGHT`, `DESC`) VALUES + (1, '072d516d300b4812a4f652f585eacc36', 'Default', '', 'init', '', '2019-05-23 16:24:02', '{\n \"name\" : \"Blank\",\n \"desc\" : \"\",\n \"stages\" : [ {\n \"containers\" : [ {\n \"@type\" : \"trigger\",\n \"name\" : \"Trigger\",\n \"elements\" : [ {\n \"@type\" : \"manualTrigger\",\n \"name\" : \"Manual\",\n \"id\" : \"T-1-1-1\",\n \"properties\" : [ ]\n } ]\n } ],\n \"id\" : \"stage-1\"\n }]\n}', 'PUBLIC', '', NULL, NULL, 0, 100, 'This is an empty pipeline.'); -- Stage预置标签 INSERT IGNORE INTO `T_PIPELINE_STAGE_TAG` (`ID`, `STAGE_TAG_NAME`, `WEIGHT`, `CREATOR`, `MODIFIER`, `CREATE_TIME`, `UPDATE_TIME`) VALUES @@ -29,4 +29,4 @@ INSERT IGNORE INTO `T_PIPELINE_RULE`(`ID`, `RULE_NAME`, `BUS_CODE`, `PROCESSOR`) INSERT IGNORE INTO `T_PIPELINE_RULE`(`ID`, `RULE_NAME`, `BUS_CODE`, `PROCESSOR`) VALUES ('5d6a9ab5f012418ab4827fcb98f564ad', 'BK_CI_PIPELINE_NAME', 'BUILD_NUM', 'BkVarProcessor'); -- 更新模板表UPDATE_TIME为空的历史记录 -UPDATE T_TEMPLATE SET UPDATE_TIME=CREATED_TIME WHERE UPDATE_TIME IS NULL; \ No newline at end of file +UPDATE T_TEMPLATE SET UPDATE_TIME=CREATED_TIME WHERE UPDATE_TIME IS NULL; From 60559712f081392feda565eeda969fd3423172c3 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 1 Aug 2024 21:45:45 +0800 Subject: [PATCH 08/25] =?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=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E7=89=88=E4=B8=8D=E5=BA=94=E8=AF=A5=E6=9C=89?= =?UTF-8?q?GIT=E4=BB=A3=E7=A0=81=E5=BA=93=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserRepositoryConfigResourceImpl.kt | 1 + .../UserRepositoryPacResourceImpl.kt | 25 ++++++++++++------- .../#etc#ci#application-repository.yml | 4 +-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryConfigResourceImpl.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryConfigResourceImpl.kt index a989105bb62..228d1f966bb 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryConfigResourceImpl.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryConfigResourceImpl.kt @@ -50,6 +50,7 @@ class UserRepositoryConfigResourceImpl @Autowired constructor( } override fun list(): Result> { + // TODO 源码管理需要优化 val managers = ScmType.values().map { val status = when { it == ScmType.GITHUB && gitConfig.githubClientId.isBlank() -> diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryPacResourceImpl.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryPacResourceImpl.kt index 7b85f8e0dde..938cf3deaa4 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryPacResourceImpl.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryPacResourceImpl.kt @@ -35,11 +35,13 @@ import com.tencent.devops.common.web.RestResource import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.repository.api.UserRepositoryPacResource import com.tencent.devops.repository.service.RepositoryPacService +import com.tencent.devops.scm.config.GitConfig import org.springframework.beans.factory.annotation.Autowired @RestResource class UserRepositoryPacResourceImpl @Autowired constructor( - private val repositoryPacService: RepositoryPacService + private val repositoryPacService: RepositoryPacService, + private val gitConfig: GitConfig ) : UserRepositoryPacResource { override fun getPacProjectId( @@ -122,14 +124,19 @@ class UserRepositoryPacResourceImpl @Autowired constructor( } override fun supportScmType(): Result> { - return Result(listOf(ScmType.CODE_GIT).map { - IdValue( - id = it.name, - value = I18nUtil.getCodeLanMessage( - messageCode = "TRIGGER_TYPE_${it.name}", - defaultMessage = it.name + // TODO 源码管理需要优化 + return if (gitConfig.clientId.isBlank()) { + return Result(emptyList()) + } else { + Result(listOf(ScmType.CODE_GIT).map { + IdValue( + id = it.name, + value = I18nUtil.getCodeLanMessage( + messageCode = "TRIGGER_TYPE_${it.name}", + defaultMessage = it.name + ) ) - ) - }) + }) + } } } diff --git a/support-files/templates/#etc#ci#application-repository.yml b/support-files/templates/#etc#ci#application-repository.yml index b6f27c3cc02..59e529d5b0b 100644 --- a/support-files/templates/#etc#ci#application-repository.yml +++ b/support-files/templates/#etc#ci#application-repository.yml @@ -25,8 +25,8 @@ scm: git: url: __BK_CI_REPOSITORY_GIT_URL__ apiUrl: __BK_CI_REPOSITORY_GIT_URL__/api/v3 - clientId: clientId - clientSecret: Secret + clientId: __BK_CI_REPOSITORY_GIT_CLIENT_ID__ + clientSecret: __BK_CI_REPOSITORY_GIT_CLIENT_SECRET__ redirectUrl: __BK_CI_PUBLIC_URL__/console/codelib redirectAtomMarketUrl: __BK_CI_PUBLIC_URL__/console/store/atomList gitHookUrl: __BK_CI_PUBLIC_URL__/ms/process/api/external/scm/codegit/commit From 7dd34a43b16d5a5052768cd1645f9c4195984b62 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Thu, 1 Aug 2024 21:46:20 +0800 Subject: [PATCH 09/25] =?UTF-8?q?feat=EF=BC=9A=E5=B7=A5=E8=9C=82MR?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E5=99=A8=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E7=9A=84action=20#8949=20=E4=BF=AE=E6=94=B9g?= =?UTF-8?q?itlab=E4=B8=8D=E8=A7=A6=E5=8F=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webhook/service/code/param/GitlabWebhookElementParams.kt | 5 +---- 1 file changed, 1 insertion(+), 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/param/GitlabWebhookElementParams.kt b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GitlabWebhookElementParams.kt index 3e10a6bc755..93dcbb7b1ff 100644 --- a/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GitlabWebhookElementParams.kt +++ b/src/backend/ci/core/common/common-webhook/biz-common-webhook/src/main/kotlin/com/tencent/devops/common/webhook/service/code/param/GitlabWebhookElementParams.kt @@ -65,9 +65,6 @@ class GitlabWebhookElementParams : ScmWebhookElementParams Date: Fri, 2 Aug 2024 09:27:39 +0800 Subject: [PATCH 10/25] =?UTF-8?q?feat=EF=BC=9A=E5=B7=A5=E8=9C=82MR?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E5=99=A8=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E7=9A=84action=20#8949=20=E4=BF=AE=E6=94=B9g?= =?UTF-8?q?itlab=E4=B8=8D=E8=A7=A6=E5=8F=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- support-files/i18n/message_en_US.properties | 2 +- support-files/i18n/message_zh_CN.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/support-files/i18n/message_en_US.properties b/support-files/i18n/message_en_US.properties index 24a0b2f5b44..364ae164953 100644 --- a/support-files/i18n/message_en_US.properties +++ b/support-files/i18n/message_en_US.properties @@ -131,7 +131,7 @@ 2100131=The SSH private key format is not supported. Only RSA format private keys are supported. 2100132=The operation of third-party service [{0}] has failed. Failure details: {1} -2100133=Plugin[{0}]Merge Request Accept event type has been adjusted to action:merged for Merge Request event. Please switch version to 2.latest or above. +2100133=Trigger [{0}] Merge Request Accept event type has been adjusted to action:merged for Merge Request event. Please switch version to 2.latest or above. 2100135=SVN token is incorrect or SVN path does not have permission 2100136=SVN token is empty, please check the credential type. 2189500=daemon interrupted diff --git a/support-files/i18n/message_zh_CN.properties b/support-files/i18n/message_zh_CN.properties index 9b70b9b4270..4748ae998c7 100644 --- a/support-files/i18n/message_zh_CN.properties +++ b/support-files/i18n/message_zh_CN.properties @@ -131,7 +131,7 @@ 2100131=不支持的SSH私钥格式,仅支持RSA格式私钥 2100132=第三方服务[{0}]操作失败,失败详情:{1} -2100133=插件[{0}]Merge Request Accept事件类型已调整为Merge Request事件对应的监听动作:合并MR,请切换版本至2.latest及以上 +2100133=触发器[{0}]Merge Request Accept事件类型已调整为Merge Request事件对应的监听动作:合并MR,请切换版本至2.latest及以上 2100135=SVN token 不正确 或者 SVN 路径没有权限 2100136=SVN Token 为空, 请检查代码库的凭证类型 2189500=守护进程中断 From c520098a789225d770f3dc266614018ea47cd213 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Fri, 2 Aug 2024 12:13:42 +0800 Subject: [PATCH 11/25] =?UTF-8?q?feat=EF=BC=9A=E6=96=B0=E5=BB=BA/=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=97=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=B5=81=E6=B0=B4=E7=BA=BF=20#8164=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9E=84=E5=BB=BA=E5=8E=86=E5=8F=B2=E5=8C=BA?= =?UTF-8?q?=E5=88=86=E6=BA=90=E6=9D=90=E6=96=99=E5=88=86=E6=94=AF=E5=92=8C?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E5=88=86=E6=94=AF=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 构建历史支持源材料和触发材料搜索 2. 触发分支和源材料分支支持下来搜索 --- .../openapi/api/apigw/v4/ApigwBuildResourceV4.kt | 16 +++++++++++----- .../apigw/v4/ApigwBuildResourceV4Impl.kt | 8 ++++++-- .../process/api/service/ServiceBuildResource.kt | 4 ++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v4/ApigwBuildResourceV4.kt b/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v4/ApigwBuildResourceV4.kt index da13e54e453..59d88faf91b 100644 --- a/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v4/ApigwBuildResourceV4.kt +++ b/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v4/ApigwBuildResourceV4.kt @@ -234,19 +234,19 @@ interface ApigwBuildResourceV4 { ) @QueryParam("updateTimeDesc") updateTimeDesc: Boolean? = null, - @Parameter(description = "代码库别名", required = false) + @Parameter(description = "源材料代码库别名", required = false) @QueryParam("materialAlias") materialAlias: List?, @Parameter(description = "代码库URL", required = false) @QueryParam("materialUrl") materialUrl: String?, - @Parameter(description = "分支", required = false) + @Parameter(description = "源材料分支", required = false) @QueryParam("materialBranch") materialBranch: List?, - @Parameter(description = "commitId", required = false) + @Parameter(description = "源材料commitId", required = false) @QueryParam("materialCommitId") materialCommitId: String?, - @Parameter(description = "commitMessage", required = false) + @Parameter(description = "源材料commitMessage", required = false) @QueryParam("materialCommitMessage") materialCommitMessage: String?, @Parameter(description = "状态", required = false) @@ -296,7 +296,13 @@ interface ApigwBuildResourceV4 { startUser: List?, @Parameter(description = "是否查询归档数据", required = false) @QueryParam("archiveFlag") - archiveFlag: Boolean? = false + archiveFlag: Boolean? = false, + @Parameter(description = "触发代码库", required = false) + @QueryParam("triggerAlias") + triggerAlias: List? = null, + @Parameter(description = "触发分支", required = false) + @QueryParam("triggerBranch") + triggerBranch: List? = null ): Result> @Operation(summary = "获取流水线手动启动参数", tags = ["v4_app_build_startInfo", "v4_user_build_startInfo"]) 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 074d54d28b3..8d484cc457a 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 @@ -128,7 +128,9 @@ class ApigwBuildResourceV4Impl @Autowired constructor( buildNoEnd: Int?, buildMsg: String?, startUser: List?, - archiveFlag: Boolean? + archiveFlag: Boolean?, + triggerAlias: List?, + triggerBranch: List? ): Result> { logger.info( "OPENAPI_BUILD_V4|$userId|get history build|$projectId|$pipelineId|$page|$pageSize" + @@ -165,7 +167,9 @@ class ApigwBuildResourceV4Impl @Autowired constructor( buildNoEnd = buildNoEnd, buildMsg = buildMsg, startUser = startUser, - archiveFlag = archiveFlag + archiveFlag = archiveFlag, + triggerAlias = triggerAlias, + triggerBranch = triggerBranch ) } 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 f75f41007d3..18d6be05fca 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 @@ -507,10 +507,10 @@ interface ServiceBuildResource { customVersion: Int? = null, @Parameter(description = "触发代码库", required = false) @QueryParam("triggerAlias") - triggerAlias: List?, + triggerAlias: List? = null, @Parameter(description = "触发分支", required = false) @QueryParam("triggerBranch") - triggerBranch: List? + triggerBranch: List? = null ): Result> @Operation(summary = "获取构建详情") From 6609449e4f27741aacc18d423258a519a4fa31ea Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Fri, 2 Aug 2024 21:10:18 +0800 Subject: [PATCH 12/25] =?UTF-8?q?feat=EF=BC=9A=E6=B5=81=E6=B0=B4=E7=BA=BF?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=AE=A1=E7=90=86=E6=9C=BA=E5=88=B6=20#8161?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8DT=5FPIPELINE=5FSETTING=E8=A1=A8dead=20lock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/PipelineRepositoryService.kt | 126 ++++++++++-------- 1 file changed, 71 insertions(+), 55 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt index 5e012887f1e..936aa1006ce 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt @@ -287,27 +287,29 @@ class PipelineRepositoryService constructor( ) result } else { - val result = create( - projectId = projectId, - pipelineId = pipelineId, - model = model, - customSetting = setting, - yaml = yaml, - userId = userId, - channelCode = channelCode, - canManualStartup = canManualStartup, - canElementSkip = canElementSkip, - buildNo = buildNo, - modelTasks = modelTasks, - useSubscriptionSettings = useSubscriptionSettings, - useLabelSettings = useLabelSettings, - useConcurrencyGroup = useConcurrencyGroup, - templateId = templateId, - versionStatus = versionStatus, - branchName = branchName, - description = description, - baseVersion = baseVersion - ) + val result = JooqUtils.retryWhenDeadLock { + create( + projectId = projectId, + pipelineId = pipelineId, + model = model, + customSetting = setting, + yaml = yaml, + userId = userId, + channelCode = channelCode, + canManualStartup = canManualStartup, + canElementSkip = canElementSkip, + buildNo = buildNo, + modelTasks = modelTasks, + useSubscriptionSettings = useSubscriptionSettings, + useLabelSettings = useLabelSettings, + useConcurrencyGroup = useConcurrencyGroup, + templateId = templateId, + versionStatus = versionStatus, + branchName = branchName, + description = description, + baseVersion = baseVersion + ) + } operationLogService.addOperationLog( userId = userId, projectId = projectId, @@ -735,18 +737,14 @@ class PipelineRepositoryService constructor( newSetting = setting } // 如果不需要覆盖模板内容,则直接保存传值或默认值 - JooqUtils.retryWhenDeadLock { - pipelineSettingDao.saveSetting(transactionContext, newSetting) - } - JooqUtils.retryWhenDeadLock { - pipelineSettingVersionDao.saveSetting( - dslContext = transactionContext, - setting = newSetting, - id = client.get(ServiceAllocIdResource::class) - .generateSegmentId(PIPELINE_SETTING_VERSION_BIZ_TAG_NAME).data, - version = settingVersion - ) - } + pipelineSettingDao.saveSetting(transactionContext, newSetting) + pipelineSettingVersionDao.saveSetting( + dslContext = transactionContext, + setting = newSetting, + id = client.get(ServiceAllocIdResource::class) + .generateSegmentId(PIPELINE_SETTING_VERSION_BIZ_TAG_NAME).data, + version = settingVersion + ) } else { pipelineSettingDao.updateSetting( dslContext = transactionContext, @@ -755,16 +753,14 @@ class PipelineRepositoryService constructor( name = model.name, desc = model.desc ?: "" )?.let { setting -> - JooqUtils.retryWhenDeadLock { - pipelineSettingVersionDao.saveSetting( - dslContext = transactionContext, - setting = setting, - id = client.get(ServiceAllocIdResource::class) - .generateSegmentId(PIPELINE_SETTING_VERSION_BIZ_TAG_NAME) - .data, - version = settingVersion - ) - } + pipelineSettingVersionDao.saveSetting( + dslContext = transactionContext, + setting = setting, + id = client.get(ServiceAllocIdResource::class) + .generateSegmentId(PIPELINE_SETTING_VERSION_BIZ_TAG_NAME) + .data, + version = settingVersion + ) newSetting = setting } } @@ -1711,6 +1707,28 @@ class PipelineRepositoryService constructor( ) } + return JooqUtils.retryWhenDeadLock { + transactionSaveSetting( + context = context, + setting = setting, + versionStatus = versionStatus, + userId = userId, + updateLastModifyUser = updateLastModifyUser, + version = version, + isTemplate = isTemplate + ) + } + } + + private fun transactionSaveSetting( + context: DSLContext?, + setting: PipelineSetting, + versionStatus: VersionStatus, + userId: String, + updateLastModifyUser: Boolean?, + version: Int, + isTemplate: Boolean + ): PipelineName { var oldName: String = setting.pipelineName (context ?: dslContext).transaction { t -> val transactionContext = DSL.using(t) @@ -1743,19 +1761,17 @@ class PipelineRepositoryService constructor( maxPipelineResNum = old.maxPipelineResNum ) } - JooqUtils.retryWhenDeadLock { - pipelineSettingVersionDao.saveSetting( - dslContext = transactionContext, - setting = setting, - version = version, - isTemplate = isTemplate, - id = client.get(ServiceAllocIdResource::class).generateSegmentId( - PIPELINE_SETTING_VERSION_BIZ_TAG_NAME - ).data - ) - } + pipelineSettingVersionDao.saveSetting( + dslContext = transactionContext, + setting = setting, + version = version, + isTemplate = isTemplate, + id = client.get(ServiceAllocIdResource::class).generateSegmentId( + PIPELINE_SETTING_VERSION_BIZ_TAG_NAME + ).data + ) } - if (versionStatus.isReleasing()) JooqUtils.retryWhenDeadLock { + if (versionStatus.isReleasing()) { pipelineSettingDao.saveSetting( transactionContext, setting, isTemplate ) From 0a55a81aebb4b47a29270cede20a2f0469ba727f Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Sat, 3 Aug 2024 16:09:58 +0800 Subject: [PATCH 13/25] =?UTF-8?q?bug:=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=E5=A4=8D=E5=88=B6=E5=8A=9F=E8=83=BD=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=A4=8D=E5=88=B6=E7=9B=B8=E5=BA=94=E5=AE=9E=E4=BE=8B=E7=9A=84?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=80=BC=20#10580?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../template/UserTemplateInstanceResource.kt | 21 ++++++++++- .../UserTemplateInstanceResourceImpl.kt | 15 ++++++++ .../service/template/TemplateFacadeService.kt | 37 +++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResource.kt index eb305033a7c..f043ab70888 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResource.kt @@ -38,13 +38,14 @@ import com.tencent.devops.process.pojo.PipelineId import com.tencent.devops.process.pojo.enums.TemplateSortTypeEnum import com.tencent.devops.process.pojo.template.TemplateCompareModelResult import com.tencent.devops.process.pojo.template.TemplateInstanceCreate +import com.tencent.devops.process.pojo.template.TemplateInstancePage import com.tencent.devops.process.pojo.template.TemplateInstanceParams import com.tencent.devops.process.pojo.template.TemplateInstanceUpdate +import com.tencent.devops.process.pojo.template.TemplateModelDetail import com.tencent.devops.process.pojo.template.TemplateOperationRet -import com.tencent.devops.process.pojo.template.TemplateInstancePage -import io.swagger.v3.oas.annotations.tags.Tag import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.Parameter +import io.swagger.v3.oas.annotations.tags.Tag import javax.ws.rs.Consumes import javax.ws.rs.GET import javax.ws.rs.HeaderParam @@ -205,4 +206,20 @@ interface UserTemplateInstanceResource { @QueryParam("desc") desc: Boolean? ): Result + + @Operation(summary = "复制流水线实例") + @GET + @Path("/projects/{projectId}/pipelines/{pipelineId}/copy") + @BkApiPermission([BkApiHandleType.API_NO_AUTH_CHECK]) + fun copyTemplateInstance( + @Parameter(description = "用户ID", required = true, example = AUTH_HEADER_USER_ID_DEFAULT_VALUE) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, + @Parameter(description = "项目ID", required = true) + @PathParam("projectId") + projectId: String, + @Parameter(description = "流水线ID", required = true) + @PathParam("pipelineId") + pipelineId: String + ): Result } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResourceImpl.kt index 58a7efaaedc..79c009610e4 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResourceImpl.kt @@ -38,6 +38,7 @@ import com.tencent.devops.process.pojo.template.TemplateInstanceCreate import com.tencent.devops.process.pojo.template.TemplateInstancePage import com.tencent.devops.process.pojo.template.TemplateInstanceParams import com.tencent.devops.process.pojo.template.TemplateInstanceUpdate +import com.tencent.devops.process.pojo.template.TemplateModelDetail import com.tencent.devops.process.pojo.template.TemplateOperationRet import com.tencent.devops.process.service.template.TemplateFacadeService import org.springframework.beans.factory.annotation.Autowired @@ -165,4 +166,18 @@ class UserTemplateInstanceResourceImpl @Autowired constructor( ) ) } + + override fun copyTemplateInstance( + userId: String, + projectId: String, + pipelineId: String + ): Result { + return Result( + templateFacadeService.copyTemplateInstance( + userId = userId, + projectId = projectId, + pipelineId = pipelineId + ) + ) + } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt index 805d5a1816e..ba607649326 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt @@ -2583,6 +2583,43 @@ class TemplateFacadeService @Autowired constructor( return pipelineTemplatePermissionService.enableTemplatePermissionManage(projectId) } + /** + * 复制流水线实例 + * + * 复制流水线参数 + */ + fun copyTemplateInstance( + userId: String, + projectId: String, + pipelineId: String + ): TemplateModelDetail { + val templatePipelineRecord = templatePipelineDao.get(dslContext, projectId, pipelineId) + ?: throw NotFoundException( + I18nUtil.getCodeLanMessage( + messageCode = ERROR_TEMPLATE_NOT_EXISTS, + language = I18nUtil.getLanguage(userId) + ) + ) + val templateModelDetail = + getTemplate(projectId, userId, templatePipelineRecord.templateId, templatePipelineRecord.version) + + val templateParams = (templateModelDetail.template.stages[0].containers[0] as TriggerContainer).templateParams + val templateParamIdMap = templateParams?.map { it.id } ?: emptyList() + + val instanceModel: Model = objectMapper.readValue( + pipelineResourceDao.getVersionModelString(dslContext, projectId, pipelineId, null) + ?: throw ErrorCodeException( + statusCode = Response.Status.NOT_FOUND.statusCode, + errorCode = ProcessMessageCode.ERROR_PIPELINE_MODEL_NOT_EXISTS + ) + ) + val instanceParams = (instanceModel.stages[0].containers[0] as TriggerContainer).params + return templateModelDetail.copy( + // 流水线参数排除模板常量 + params = instanceParams.filterNot { templateParamIdMap.contains(it.id) } + ) + } + companion object { private val logger = LoggerFactory.getLogger(TemplateFacadeService::class.java) private const val INIT_TEMPLATE_NAME = "init" From 3e34bd319a4fea9b5fa0cf9c5690f3225a910bbc Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Sat, 3 Aug 2024 16:39:23 +0800 Subject: [PATCH 14/25] =?UTF-8?q?bug:=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=E5=A4=8D=E5=88=B6=E5=8A=9F=E8=83=BD=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=A4=8D=E5=88=B6=E7=9B=B8=E5=BA=94=E5=AE=9E=E4=BE=8B=E7=9A=84?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=80=BC=20#10580?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/api/template/UserTemplateInstanceResource.kt | 6 +++--- .../api/template/UserTemplateInstanceResourceImpl.kt | 4 ++-- .../process/service/template/TemplateFacadeService.kt | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResource.kt index f043ab70888..6a8a735ab27 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResource.kt @@ -207,11 +207,11 @@ interface UserTemplateInstanceResource { desc: Boolean? ): Result - @Operation(summary = "复制流水线实例") + @Operation(summary = "获取流水线实例") @GET - @Path("/projects/{projectId}/pipelines/{pipelineId}/copy") + @Path("/projects/{projectId}/pipelines/{pipelineId}") @BkApiPermission([BkApiHandleType.API_NO_AUTH_CHECK]) - fun copyTemplateInstance( + fun getTemplateInstance( @Parameter(description = "用户ID", required = true, example = AUTH_HEADER_USER_ID_DEFAULT_VALUE) @HeaderParam(AUTH_HEADER_USER_ID) userId: String, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResourceImpl.kt index 79c009610e4..5ee5a5bb1fd 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResourceImpl.kt @@ -167,13 +167,13 @@ class UserTemplateInstanceResourceImpl @Autowired constructor( ) } - override fun copyTemplateInstance( + override fun getTemplateInstance( userId: String, projectId: String, pipelineId: String ): Result { return Result( - templateFacadeService.copyTemplateInstance( + templateFacadeService.getTemplateInstance( userId = userId, projectId = projectId, pipelineId = pipelineId diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt index ba607649326..6218c15b417 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt @@ -2584,11 +2584,10 @@ class TemplateFacadeService @Autowired constructor( } /** - * 复制流水线实例 + * 获取流水线实例 * - * 复制流水线参数 */ - fun copyTemplateInstance( + fun getTemplateInstance( userId: String, projectId: String, pipelineId: String From d6e18e689fac70e89d43663b9afe392b23f1b8b1 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Sat, 3 Aug 2024 16:40:03 +0800 Subject: [PATCH 15/25] =?UTF-8?q?feat=EF=BC=9A=E6=B5=81=E6=B0=B4=E7=BA=BF?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=AE=A1=E7=90=86=E6=9C=BA=E5=88=B6=20#8161?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8DT=5FPIPELINE=5FSETTING=E8=A1=A8dead=20lock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/tencent/devops/common/db/utils/JooqUtils.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/common/common-db-base/src/main/kotlin/com/tencent/devops/common/db/utils/JooqUtils.kt b/src/backend/ci/core/common/common-db-base/src/main/kotlin/com/tencent/devops/common/db/utils/JooqUtils.kt index 23c357d61a1..f07743de031 100644 --- a/src/backend/ci/core/common/common-db-base/src/main/kotlin/com/tencent/devops/common/db/utils/JooqUtils.kt +++ b/src/backend/ci/core/common/common-db-base/src/main/kotlin/com/tencent/devops/common/db/utils/JooqUtils.kt @@ -28,8 +28,6 @@ package com.tencent.devops.common.db.utils import com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException -import java.math.BigDecimal -import java.sql.Timestamp import org.jooq.DatePart import org.jooq.Field import org.jooq.Record @@ -37,6 +35,9 @@ import org.jooq.SelectOptionStep import org.jooq.SelectUnionStep import org.jooq.exception.DataAccessException import org.jooq.impl.DSL +import org.springframework.dao.DeadlockLoserDataAccessException +import java.math.BigDecimal +import java.sql.Timestamp object JooqUtils { @@ -47,6 +48,8 @@ object JooqUtils { action() } catch (dae: DataAccessException) { if (dae.isDeadLock()) action() else throw dae + } catch (dae: DeadlockLoserDataAccessException) { + action() } } From 1b259d09c792dfe26f0601a9e5a1ec0b6eeb07af Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Mon, 5 Aug 2024 11:40:27 +0800 Subject: [PATCH 16/25] =?UTF-8?q?bug:=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=E5=A4=8D=E5=88=B6=E5=8A=9F=E8=83=BD=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=A4=8D=E5=88=B6=E7=9B=B8=E5=BA=94=E5=AE=9E=E4=BE=8B=E7=9A=84?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=80=BC=20#10580=20=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E4=BF=9D=E5=AD=98=E6=97=B6=E6=B8=85=E7=90=86?= =?UTF-8?q?=E6=97=A0=E7=94=A8=E4=B8=8B=E6=8B=89=E6=A1=86=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/common/pipeline/container/TriggerContainer.kt | 2 +- .../devops/process/service/template/TemplateFacadeService.kt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/container/TriggerContainer.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/container/TriggerContainer.kt index 1a8ea378f51..ecfedd5642b 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/container/TriggerContainer.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/container/TriggerContainer.kt @@ -55,7 +55,7 @@ data class TriggerContainer( @get:Schema(title = "参数化构建", required = false) var params: List = listOf(), @get:Schema(title = "模板参数构建", required = false) - val templateParams: List? = null, + var templateParams: List? = null, @get:Schema(title = "构建版本号", required = false) var buildNo: BuildNo? = null, @get:Schema(title = diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt index 6218c15b417..758f8434ef8 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt @@ -2382,6 +2382,9 @@ class TemplateFacadeService @Autowired constructor( stage.containers.forEach { container -> if (container is TriggerContainer) { container.params = PipelineUtils.cleanOptions(params = container.params) + container.templateParams = container.templateParams?.let { + PipelineUtils.cleanOptions(params = it) + } } if (container.containerId.isNullOrBlank()) { container.containerId = container.id From a312c4c4192b35010766d8d21d8dc64018a4d44c Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Mon, 5 Aug 2024 11:45:45 +0800 Subject: [PATCH 17/25] =?UTF-8?q?feat=EF=BC=9A=E5=B7=A5=E8=9C=82MR?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E5=99=A8=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E7=9A=84action=20#8949=20=E4=BF=AE=E5=A4=8Dw?= =?UTF-8?q?ebhook=20request=20=E4=BF=9D=E5=AD=98=E6=97=B6event=5Fmessage?= =?UTF-8?q?=E8=B6=85=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/process/webhook/WebhookRequestService.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 9aca356668b..1c6a622f6b3 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 @@ -79,7 +79,13 @@ class WebhookRequestService( externalId = matcher.getExternalId(), eventType = matcher.getEventType().name, triggerUser = matcher.getUsername(), - eventMessage = matcher.getMessage() ?: "", + eventMessage = matcher.getMessage()?.let { + if (it.length >= 128) { + it.substring(0, 128) + } else { + it + } + } ?: "", repositoryType = scmType.name, requestHeader = request.headers, requestParam = request.queryParams, From fdd661437cce3d60c9adab03dcc63d5392179b4a Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Mon, 5 Aug 2024 14:51:14 +0800 Subject: [PATCH 18/25] =?UTF-8?q?feat=EF=BC=9A=E6=B5=81=E6=B0=B4=E7=BA=BF?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=AE=A1=E7=90=86=E6=9C=BA=E5=88=B6=20#8161?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8DT=5FPIPELINE=5FSETTING=E8=A1=A8dead=20lock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tencent/devops/common/db/utils/JooqUtils.kt | 12 +++++++++--- .../devops/common/db/utils/JooqUtilsTest.kt | 14 ++++++++++++++ .../engine/service/PipelineRepositoryService.kt | 4 ++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/backend/ci/core/common/common-db-base/src/main/kotlin/com/tencent/devops/common/db/utils/JooqUtils.kt b/src/backend/ci/core/common/common-db-base/src/main/kotlin/com/tencent/devops/common/db/utils/JooqUtils.kt index f07743de031..ef23fd7dd89 100644 --- a/src/backend/ci/core/common/common-db-base/src/main/kotlin/com/tencent/devops/common/db/utils/JooqUtils.kt +++ b/src/backend/ci/core/common/common-db-base/src/main/kotlin/com/tencent/devops/common/db/utils/JooqUtils.kt @@ -43,13 +43,19 @@ object JooqUtils { const val JooqDeadLockMessage = "Deadlock found when trying to get lock; try restarting transaction" - fun retryWhenDeadLock(action: () -> T): T { + fun retryWhenDeadLock(retryTime: Int = 1, action: () -> T): T { return try { action() } catch (dae: DataAccessException) { - if (dae.isDeadLock()) action() else throw dae + if (retryTime - 1 < 0) { + throw dae + } + if (dae.isDeadLock()) retryWhenDeadLock(retryTime - 1, action) else throw dae } catch (dae: DeadlockLoserDataAccessException) { - action() + if (retryTime - 1 < 0) { + throw dae + } + retryWhenDeadLock(retryTime - 1, action) } } diff --git a/src/backend/ci/core/common/common-db-base/src/test/kotlin/com/tencent/devops/common/db/utils/JooqUtilsTest.kt b/src/backend/ci/core/common/common-db-base/src/test/kotlin/com/tencent/devops/common/db/utils/JooqUtilsTest.kt index 17e2b4b7f82..13612a47f0b 100644 --- a/src/backend/ci/core/common/common-db-base/src/test/kotlin/com/tencent/devops/common/db/utils/JooqUtilsTest.kt +++ b/src/backend/ci/core/common/common-db-base/src/test/kotlin/com/tencent/devops/common/db/utils/JooqUtilsTest.kt @@ -2,6 +2,7 @@ package com.tencent.devops.common.db.utils import org.jooq.exception.DataAccessException import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test class JooqUtilsTest { @@ -18,6 +19,19 @@ class JooqUtilsTest { Assertions.assertEquals(expect, actual) } + @Test + @DisplayName("重试多次") + fun retryWhenDeadLock_2() { + var actual = 0 + JooqUtils.retryWhenDeadLock(3) { + if (actual++ < 3) { + throw DataAccessException("mock sql dead lock; ${JooqUtils.JooqDeadLockMessage}") + } + } + val expect = 4 // retry + Assertions.assertEquals(expect, actual) + } + @Test fun assertThrowsRetryWhenDeadLock() { var actual = 0 diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt index 936aa1006ce..9a6509046a8 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRepositoryService.kt @@ -287,7 +287,7 @@ class PipelineRepositoryService constructor( ) result } else { - val result = JooqUtils.retryWhenDeadLock { + val result = JooqUtils.retryWhenDeadLock(3) { create( projectId = projectId, pipelineId = pipelineId, @@ -1707,7 +1707,7 @@ class PipelineRepositoryService constructor( ) } - return JooqUtils.retryWhenDeadLock { + return JooqUtils.retryWhenDeadLock(3) { transactionSaveSetting( context = context, setting = setting, From 6c1d317c67363ba92b3ea2ce1f192b273add612b Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Mon, 5 Aug 2024 15:40:11 +0800 Subject: [PATCH 19/25] =?UTF-8?q?feat=EF=BC=9A=E6=96=B0=E5=BB=BA/=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=97=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=B5=81=E6=B0=B4=E7=BA=BF=20#8164=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9E=84=E5=BB=BA=E5=8E=86=E5=8F=B2=E5=8C=BA?= =?UTF-8?q?=E5=88=86=E6=BA=90=E6=9D=90=E6=96=99=E5=88=86=E6=94=AF=E5=92=8C?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E5=88=86=E6=94=AF=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 构建历史支持源材料和触发材料搜索 2. 触发分支和源材料分支支持下来搜索 --- .../devops/process/engine/service/PipelineRuntimeService.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 b6d2af48002..2b2af422745 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 @@ -490,10 +490,10 @@ class PipelineRuntimeService @Autowired constructor( materialObjList.addAll(it.material!!) } } - val aliasNames = if (aliasList.isNullOrEmpty()) { - materialObjList.map { it.aliasName } - } else { + val aliasNames = if (!aliasList.isNullOrEmpty() && aliasList.first().isNotBlank()) { aliasList + } else { + materialObjList.map { it.aliasName } } val result = mutableListOf() From 79cb6113accb866b217fb44613e14a209ef1ef7f Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Mon, 5 Aug 2024 16:41:23 +0800 Subject: [PATCH 20/25] =?UTF-8?q?feat=EF=BC=9A=E6=96=B0=E5=BB=BA/=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=97=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=B5=81=E6=B0=B4=E7=BA=BF=20#8164=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9E=84=E5=BB=BA=E5=8E=86=E5=8F=B2=E5=8C=BA?= =?UTF-8?q?=E5=88=86=E6=BA=90=E6=9D=90=E6=96=99=E5=88=86=E6=94=AF=E5=92=8C?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E5=88=86=E6=94=AF=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 构建历史支持源材料和触发材料搜索 2. 触发分支和源材料分支支持下来搜索 --- .../engine/service/PipelineRuntimeService.kt | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) 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 2b2af422745..0d6c0cd26f1 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 @@ -429,7 +429,7 @@ class PipelineRuntimeService @Autowired constructor( search: String?, type: HistorySearchType? = HistorySearchType.MATERIAL ): List { - return when (type) { + val aliasNames = when (type) { HistorySearchType.MATERIAL -> { val history = pipelineBuildDao.listHistorySearchOptions( dslContext = dslContext, @@ -445,7 +445,9 @@ class PipelineRuntimeService @Autowired constructor( materialObjList.addAll(it.material!!) } } - materialObjList.filter { !it.aliasName.isNullOrBlank() }.map { it.aliasName!! }.distinct() + materialObjList.filter { !it.aliasName.isNullOrBlank() } + .map { it.aliasName!! } + .distinct() } HistorySearchType.TRIGGER -> { @@ -458,11 +460,17 @@ class PipelineRuntimeService @Autowired constructor( triggerAlias = search?.let { listOf(it) } ) history.filter { it.webhookInfo != null && !it.webhookInfo!!.webhookAliasName.isNullOrBlank() } - .map { it.webhookInfo!!.webhookAliasName!! }.distinct() + .map { it.webhookInfo!!.webhookAliasName!! } + .distinct() } else -> emptyList() } + return if (search.isNullOrBlank()) { + aliasNames + } else { + aliasNames.filter { it.contains(search) } + } } fun getHistoryConditionBranch( @@ -473,7 +481,7 @@ class PipelineRuntimeService @Autowired constructor( search: String?, type: HistorySearchType? = HistorySearchType.MATERIAL ): List { - return when (type) { + val branchNames = when (type) { HistorySearchType.MATERIAL -> { val history = pipelineBuildDao.listHistorySearchOptions( dslContext = dslContext, @@ -503,7 +511,7 @@ class PipelineRuntimeService @Autowired constructor( }.map { it.branchName!! }.distinct() result.addAll(branchNames) } - result + result.distinct() } HistorySearchType.TRIGGER -> { @@ -521,6 +529,11 @@ class PipelineRuntimeService @Autowired constructor( } else -> emptyList() } + return if (search.isNullOrBlank()) { + branchNames + } else { + branchNames.filter { it.contains(search) } + } } private fun genBuildHistory( From d704b677a37976255482a31141a20123e081f70e Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Mon, 5 Aug 2024 21:17:37 +0800 Subject: [PATCH 21/25] =?UTF-8?q?Revert=20"bug:=E6=B5=81=E6=B0=B4=E7=BA=BF?= =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E5=A4=8D=E5=88=B6=E5=8A=9F=E8=83=BD=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=A4=8D=E5=88=B6=E7=9B=B8=E5=BA=94=E5=AE=9E=E4=BE=8B?= =?UTF-8?q?=E7=9A=84=E5=8F=82=E6=95=B0=E5=80=BC=20#10580"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 3e34bd319a4fea9b5fa0cf9c5690f3225a910bbc. --- .../process/api/template/UserTemplateInstanceResource.kt | 6 +++--- .../api/template/UserTemplateInstanceResourceImpl.kt | 4 ++-- .../process/service/template/TemplateFacadeService.kt | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResource.kt index 6a8a735ab27..f043ab70888 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResource.kt @@ -207,11 +207,11 @@ interface UserTemplateInstanceResource { desc: Boolean? ): Result - @Operation(summary = "获取流水线实例") + @Operation(summary = "复制流水线实例") @GET - @Path("/projects/{projectId}/pipelines/{pipelineId}") + @Path("/projects/{projectId}/pipelines/{pipelineId}/copy") @BkApiPermission([BkApiHandleType.API_NO_AUTH_CHECK]) - fun getTemplateInstance( + fun copyTemplateInstance( @Parameter(description = "用户ID", required = true, example = AUTH_HEADER_USER_ID_DEFAULT_VALUE) @HeaderParam(AUTH_HEADER_USER_ID) userId: String, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResourceImpl.kt index 5ee5a5bb1fd..79c009610e4 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResourceImpl.kt @@ -167,13 +167,13 @@ class UserTemplateInstanceResourceImpl @Autowired constructor( ) } - override fun getTemplateInstance( + override fun copyTemplateInstance( userId: String, projectId: String, pipelineId: String ): Result { return Result( - templateFacadeService.getTemplateInstance( + templateFacadeService.copyTemplateInstance( userId = userId, projectId = projectId, pipelineId = pipelineId diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt index 758f8434ef8..bc4919dc28f 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt @@ -2587,10 +2587,11 @@ class TemplateFacadeService @Autowired constructor( } /** - * 获取流水线实例 + * 复制流水线实例 * + * 复制流水线参数 */ - fun getTemplateInstance( + fun copyTemplateInstance( userId: String, projectId: String, pipelineId: String From bca3ec272e0f5d28f23835a71e8ece41c241d7e3 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Mon, 5 Aug 2024 21:17:39 +0800 Subject: [PATCH 22/25] =?UTF-8?q?Revert=20"bug:=E6=B5=81=E6=B0=B4=E7=BA=BF?= =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E5=A4=8D=E5=88=B6=E5=8A=9F=E8=83=BD=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=A4=8D=E5=88=B6=E7=9B=B8=E5=BA=94=E5=AE=9E=E4=BE=8B?= =?UTF-8?q?=E7=9A=84=E5=8F=82=E6=95=B0=E5=80=BC=20#10580"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 0a55a81aebb4b47a29270cede20a2f0469ba727f. --- .../template/UserTemplateInstanceResource.kt | 21 +---------- .../UserTemplateInstanceResourceImpl.kt | 15 -------- .../service/template/TemplateFacadeService.kt | 37 ------------------- 3 files changed, 2 insertions(+), 71 deletions(-) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResource.kt index f043ab70888..eb305033a7c 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResource.kt @@ -38,14 +38,13 @@ import com.tencent.devops.process.pojo.PipelineId import com.tencent.devops.process.pojo.enums.TemplateSortTypeEnum import com.tencent.devops.process.pojo.template.TemplateCompareModelResult import com.tencent.devops.process.pojo.template.TemplateInstanceCreate -import com.tencent.devops.process.pojo.template.TemplateInstancePage import com.tencent.devops.process.pojo.template.TemplateInstanceParams import com.tencent.devops.process.pojo.template.TemplateInstanceUpdate -import com.tencent.devops.process.pojo.template.TemplateModelDetail import com.tencent.devops.process.pojo.template.TemplateOperationRet +import com.tencent.devops.process.pojo.template.TemplateInstancePage +import io.swagger.v3.oas.annotations.tags.Tag import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.Parameter -import io.swagger.v3.oas.annotations.tags.Tag import javax.ws.rs.Consumes import javax.ws.rs.GET import javax.ws.rs.HeaderParam @@ -206,20 +205,4 @@ interface UserTemplateInstanceResource { @QueryParam("desc") desc: Boolean? ): Result - - @Operation(summary = "复制流水线实例") - @GET - @Path("/projects/{projectId}/pipelines/{pipelineId}/copy") - @BkApiPermission([BkApiHandleType.API_NO_AUTH_CHECK]) - fun copyTemplateInstance( - @Parameter(description = "用户ID", required = true, example = AUTH_HEADER_USER_ID_DEFAULT_VALUE) - @HeaderParam(AUTH_HEADER_USER_ID) - userId: String, - @Parameter(description = "项目ID", required = true) - @PathParam("projectId") - projectId: String, - @Parameter(description = "流水线ID", required = true) - @PathParam("pipelineId") - pipelineId: String - ): Result } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResourceImpl.kt index 79c009610e4..58a7efaaedc 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/template/UserTemplateInstanceResourceImpl.kt @@ -38,7 +38,6 @@ import com.tencent.devops.process.pojo.template.TemplateInstanceCreate import com.tencent.devops.process.pojo.template.TemplateInstancePage import com.tencent.devops.process.pojo.template.TemplateInstanceParams import com.tencent.devops.process.pojo.template.TemplateInstanceUpdate -import com.tencent.devops.process.pojo.template.TemplateModelDetail import com.tencent.devops.process.pojo.template.TemplateOperationRet import com.tencent.devops.process.service.template.TemplateFacadeService import org.springframework.beans.factory.annotation.Autowired @@ -166,18 +165,4 @@ class UserTemplateInstanceResourceImpl @Autowired constructor( ) ) } - - override fun copyTemplateInstance( - userId: String, - projectId: String, - pipelineId: String - ): Result { - return Result( - templateFacadeService.copyTemplateInstance( - userId = userId, - projectId = projectId, - pipelineId = pipelineId - ) - ) - } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt index bc4919dc28f..e7bb18cd178 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/template/TemplateFacadeService.kt @@ -2586,43 +2586,6 @@ class TemplateFacadeService @Autowired constructor( return pipelineTemplatePermissionService.enableTemplatePermissionManage(projectId) } - /** - * 复制流水线实例 - * - * 复制流水线参数 - */ - fun copyTemplateInstance( - userId: String, - projectId: String, - pipelineId: String - ): TemplateModelDetail { - val templatePipelineRecord = templatePipelineDao.get(dslContext, projectId, pipelineId) - ?: throw NotFoundException( - I18nUtil.getCodeLanMessage( - messageCode = ERROR_TEMPLATE_NOT_EXISTS, - language = I18nUtil.getLanguage(userId) - ) - ) - val templateModelDetail = - getTemplate(projectId, userId, templatePipelineRecord.templateId, templatePipelineRecord.version) - - val templateParams = (templateModelDetail.template.stages[0].containers[0] as TriggerContainer).templateParams - val templateParamIdMap = templateParams?.map { it.id } ?: emptyList() - - val instanceModel: Model = objectMapper.readValue( - pipelineResourceDao.getVersionModelString(dslContext, projectId, pipelineId, null) - ?: throw ErrorCodeException( - statusCode = Response.Status.NOT_FOUND.statusCode, - errorCode = ProcessMessageCode.ERROR_PIPELINE_MODEL_NOT_EXISTS - ) - ) - val instanceParams = (instanceModel.stages[0].containers[0] as TriggerContainer).params - return templateModelDetail.copy( - // 流水线参数排除模板常量 - params = instanceParams.filterNot { templateParamIdMap.contains(it.id) } - ) - } - companion object { private val logger = LoggerFactory.getLogger(TemplateFacadeService::class.java) private const val INIT_TEMPLATE_NAME = "init" From 628202e39202e3831c868dd8f3c768125d6d5cff Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Mon, 5 Aug 2024 21:25:24 +0800 Subject: [PATCH 23/25] =?UTF-8?q?feat=EF=BC=9A=E6=96=B0=E5=BB=BA/=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=97=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=B5=81=E6=B0=B4=E7=BA=BF=20#8164=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9E=84=E5=BB=BA=E5=8E=86=E5=8F=B2=E5=8C=BA?= =?UTF-8?q?=E5=88=86=E6=BA=90=E6=9D=90=E6=96=99=E5=88=86=E6=94=AF=E5=92=8C?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E5=88=86=E6=94=AF=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 构建历史支持源材料和触发材料搜索 2. 触发分支和源材料分支支持下来搜索 使用服务内存搜索代替mysql搜索 --- .../process/engine/dao/PipelineBuildDao.kt | 158 ++---------------- .../engine/service/PipelineRuntimeService.kt | 14 +- 2 files changed, 20 insertions(+), 152 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt index 4021f20e438..8c6e707546e 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt @@ -73,7 +73,7 @@ class PipelineBuildDao { companion object { private val mapper = PipelineBuildInfoJooqMapper() private val debugMapper = PipelineDebugBuildInfoJooqMapper() - private const val DEFAULT_PAGE_SIZE = 100 + private const val DEFAULT_PAGE_SIZE = 50 } fun create(dslContext: DSLContext, startBuildContext: StartBuildContext) { @@ -1290,126 +1290,6 @@ class PipelineBuildDao { } } - private fun TPipelineBuildHistory.makeSearchOptionsCondition( - where: SelectConditionStep<*>, - type: HistorySearchType, - materialAlias: List? = null, - materialBranch: String? = null, - triggerAlias: List? = null, - triggerBranch: String? = null - ) { - when (type) { - HistorySearchType.MATERIAL -> - where.and(MATERIAL.isNotNull) - - HistorySearchType.TRIGGER -> - where.and(WEBHOOK_INFO.isNotNull) - } - if (!materialAlias.isNullOrEmpty() && materialAlias.first().isNotBlank()) { - var conditionsOr: Condition - - conditionsOr = JooqUtils.jsonExtract(t1 = MATERIAL, t2 = "\$[*].aliasName", lower = true) - .like("%${materialAlias.first().lowercase()}%") - - materialAlias.forEachIndexed { index, s -> - if (index == 0) return@forEachIndexed - conditionsOr = conditionsOr.or( - JooqUtils.jsonExtract(MATERIAL, "\$[*].aliasName", lower = true) - .like("%${s.lowercase()}%") - ) - } - where.and(conditionsOr) - } - if (!materialBranch.isNullOrBlank()) { - where.and( - JooqUtils.jsonExtract(MATERIAL, "\$[*].branchName", lower = true) - .like("%${materialBranch.lowercase()}%") - ) - } - if (!triggerAlias.isNullOrEmpty() && triggerAlias.first().isNotBlank()) { - var conditionsOr: Condition - - conditionsOr = JooqUtils.jsonExtract(t1 = WEBHOOK_INFO, t2 = "\$.webhookAliasName", lower = true) - .like("%${triggerAlias.first().lowercase()}%") - - triggerAlias.forEachIndexed { index, s -> - if (index == 0) return@forEachIndexed - conditionsOr = conditionsOr.or( - JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookAliasName", lower = true) - .like("%${s.lowercase()}%") - ) - } - where.and(conditionsOr) - } - - if (!triggerBranch.isNullOrBlank()) { - where.and( - JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookBranch", lower = true) - .like("%${triggerBranch.lowercase()}%") - ) - } - } - - private fun TPipelineBuildHistoryDebug.makeSearchOptionsDebugCondition( - where: SelectConditionStep<*>, - type: HistorySearchType, - materialAlias: List? = null, - materialBranch: String? = null, - triggerAlias: List? = null, - triggerBranch: String? = null - ) { - when (type) { - HistorySearchType.MATERIAL -> - where.and(MATERIAL.isNotNull) - - HistorySearchType.TRIGGER -> - where.and(WEBHOOK_INFO.isNotNull) - } - if (!materialAlias.isNullOrEmpty() && materialAlias.first().isNotBlank()) { - var conditionsOr: Condition - - conditionsOr = JooqUtils.jsonExtract(t1 = MATERIAL, t2 = "\$[*].aliasName", lower = true) - .like("%${materialAlias.first().lowercase()}%") - - materialAlias.forEachIndexed { index, s -> - if (index == 0) return@forEachIndexed - conditionsOr = conditionsOr.or( - JooqUtils.jsonExtract(MATERIAL, "\$[*].aliasName", lower = true) - .like("%${s.lowercase()}%") - ) - } - where.and(conditionsOr) - } - if (!materialBranch.isNullOrBlank()) { - where.and( - JooqUtils.jsonExtract(MATERIAL, "\$[*].branchName", lower = true) - .like("%${materialBranch.lowercase()}%") - ) - } - if (!triggerAlias.isNullOrEmpty() && triggerAlias.first().isNotBlank()) { - var conditionsOr: Condition - - conditionsOr = JooqUtils.jsonExtract(t1 = WEBHOOK_INFO, t2 = "\$.webhookAliasName", lower = true) - .like("%${triggerAlias.first().lowercase()}%") - - triggerAlias.forEachIndexed { index, s -> - if (index == 0) return@forEachIndexed - conditionsOr = conditionsOr.or( - JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookAliasName", lower = true) - .like("%${s.lowercase()}%") - ) - } - where.and(conditionsOr) - } - - if (!triggerBranch.isNullOrBlank()) { - where.and( - JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookBranch", lower = true) - .like("%${triggerBranch.lowercase()}%") - ) - } - } - private fun TPipelineBuildHistoryDebug.makeDebugCondition( where: SelectConditionStep<*>, materialAlias: List?, @@ -1615,24 +1495,19 @@ class PipelineBuildDao { projectId: String, pipelineId: String, debugVersion: Int?, - type: HistorySearchType, - materialAlias: List? = null, - materialBranch: String? = null, - triggerAlias: List? = null, - triggerBranch: String? = null + type: HistorySearchType ): Collection { return if (debugVersion == null) { with(T_PIPELINE_BUILD_HISTORY) { val where = dslContext.selectFrom(this) .where(PIPELINE_ID.eq(pipelineId).and(PROJECT_ID.eq(projectId))) - makeSearchOptionsCondition( - where = where, - type = type, - materialAlias = materialAlias, - materialBranch = materialBranch, - triggerAlias = triggerAlias, - triggerBranch = triggerBranch - ) + when (type) { + HistorySearchType.MATERIAL -> + where.and(MATERIAL.isNotNull) + + HistorySearchType.TRIGGER -> + where.and(WEBHOOK_INFO.isNotNull) + } where.orderBy(BUILD_NUM.desc()).limit(DEFAULT_PAGE_SIZE) .fetch(mapper) } @@ -1641,14 +1516,13 @@ class PipelineBuildDao { val where = dslContext.selectFrom(this) .where(PIPELINE_ID.eq(pipelineId).and(PROJECT_ID.eq(projectId))) .and(VERSION.eq(debugVersion)) - makeSearchOptionsDebugCondition( - where = where, - type = type, - materialAlias = materialAlias, - materialBranch = materialBranch, - triggerAlias = triggerAlias, - triggerBranch = triggerBranch - ) + when (type) { + HistorySearchType.MATERIAL -> + where.and(MATERIAL.isNotNull) + + HistorySearchType.TRIGGER -> + where.and(WEBHOOK_INFO.isNotNull) + } where.orderBy(BUILD_NUM.desc()).limit(DEFAULT_PAGE_SIZE) .fetch(debugMapper) } 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 0d6c0cd26f1..00cbc472dc8 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 @@ -436,8 +436,7 @@ class PipelineRuntimeService @Autowired constructor( projectId = projectId, pipelineId = pipelineId, debugVersion = debugVersion, - type = type, - materialAlias = search?.let { listOf(it) } + type = type ) val materialObjList = mutableListOf() history.forEach { @@ -456,8 +455,7 @@ class PipelineRuntimeService @Autowired constructor( projectId = projectId, pipelineId = pipelineId, debugVersion = debugVersion, - type = type, - triggerAlias = search?.let { listOf(it) } + type = type ) history.filter { it.webhookInfo != null && !it.webhookInfo!!.webhookAliasName.isNullOrBlank() } .map { it.webhookInfo!!.webhookAliasName!! } @@ -488,9 +486,7 @@ class PipelineRuntimeService @Autowired constructor( projectId = projectId, pipelineId = pipelineId, debugVersion = debugVersion, - type = type, - materialAlias = aliasList, - materialBranch = search + type = type ) val materialObjList = mutableListOf() history.forEach { @@ -520,9 +516,7 @@ class PipelineRuntimeService @Autowired constructor( projectId = projectId, pipelineId = pipelineId, debugVersion = debugVersion, - type = type, - triggerAlias = aliasList, - triggerBranch = search + type = type ) history.filter { it.webhookInfo != null && !it.webhookInfo!!.webhookBranch.isNullOrBlank() } .map { it.webhookInfo!!.webhookBranch!! }.distinct() From a41f1d0c7e6a1d29a971bad192f8f7ef803ce355 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Mon, 5 Aug 2024 21:49:31 +0800 Subject: [PATCH 24/25] =?UTF-8?q?feat=EF=BC=9A=E6=96=B0=E5=BB=BA/=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=97=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=B5=81=E6=B0=B4=E7=BA=BF=20#8164=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9E=84=E5=BB=BA=E5=8E=86=E5=8F=B2=E5=8C=BA?= =?UTF-8?q?=E5=88=86=E6=BA=90=E6=9D=90=E6=96=99=E5=88=86=E6=94=AF=E5=92=8C?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E5=88=86=E6=94=AF=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 构建历史支持源材料和触发材料搜索 2. 触发分支和源材料分支支持下来搜索 使用服务内存搜索代替mysql搜索 --- .../engine/service/PipelineRuntimeService.kt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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 00cbc472dc8..86a80d22fe2 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 @@ -518,8 +518,20 @@ class PipelineRuntimeService @Autowired constructor( debugVersion = debugVersion, type = type ) - history.filter { it.webhookInfo != null && !it.webhookInfo!!.webhookBranch.isNullOrBlank() } - .map { it.webhookInfo!!.webhookBranch!! }.distinct() + val webhookInfoList = history.filter { it.webhookInfo != null }.map { it.webhookInfo!! } + val aliasNames = if (!aliasList.isNullOrEmpty() && aliasList.first().isNotBlank()) { + aliasList + } else { + webhookInfoList.map { it.webhookAliasName } + } + val result = mutableListOf() + aliasNames.distinct().forEach { alias -> + val branchNames = webhookInfoList.filter { + it.webhookAliasName == alias && !it.webhookBranch.isNullOrBlank() + }.map { it.webhookBranch!! }.distinct() + result.addAll(branchNames) + } + result.distinct() } else -> emptyList() } From c306839888be03c2e1d97ea49ec699caf56a93d5 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Tue, 6 Aug 2024 10:54:17 +0800 Subject: [PATCH 25/25] =?UTF-8?q?feat=EF=BC=9A=E6=96=B0=E5=BB=BA/=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=97=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=B5=81=E6=B0=B4=E7=BA=BF=20#8164=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=8D=E5=88=B6=E6=A8=A1=E6=9D=BF=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=E7=BC=BA=E5=B0=91templateVersion=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/tencent/devops/process/pojo/PipelineDetail.kt | 2 ++ .../devops/process/service/PipelineVersionFacadeService.kt | 1 + 2 files changed, 3 insertions(+) diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/PipelineDetail.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/PipelineDetail.kt index 98e08b733c1..b689006e170 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/PipelineDetail.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/PipelineDetail.kt @@ -51,6 +51,8 @@ data class PipelineDetail( val instanceFromTemplate: Boolean, @get:Schema(title = "当前模板的ID", required = false) var templateId: String?, + @get:Schema(title = "关联模板版本", required = false) + var templateVersion: Long?, @get:Schema(title = "草稿或最新的发布版本") val version: Int, @get:Schema(title = "草稿或最新的发布版本名称") diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineVersionFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineVersionFacadeService.kt index f2272a07d26..4a00709c108 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineVersionFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineVersionFacadeService.kt @@ -196,6 +196,7 @@ class PipelineVersionFacadeService @Autowired constructor( hasCollect = detailInfo.hasCollect, instanceFromTemplate = detailInfo.instanceFromTemplate, templateId = detailInfo.templateId, + templateVersion = detailInfo.templateVersion, canManualStartup = detailInfo.canManualStartup, canDebug = canDebug, canRelease = canRelease,