diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/op/OpPipelineViewResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/op/OpPipelineViewResource.kt index 767c4afb17b4..c09cc0d6937b 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/op/OpPipelineViewResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/op/OpPipelineViewResource.kt @@ -7,10 +7,13 @@ import io.swagger.v3.oas.annotations.tags.Tag import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.Parameter import javax.ws.rs.Consumes +import javax.ws.rs.DELETE import javax.ws.rs.GET import javax.ws.rs.HeaderParam import javax.ws.rs.Path +import javax.ws.rs.PathParam import javax.ws.rs.Produces +import javax.ws.rs.QueryParam import javax.ws.rs.core.MediaType @Tag(name = "USER_PIPELINE_VIEW", description = "用户-流水线视图") @@ -26,4 +29,19 @@ interface OpPipelineViewResource { @HeaderParam(AUTH_HEADER_USER_ID) userId: String ): Result + + @Operation(summary = "删除yaml流水线组") + @DELETE + @Path("{projectId}/{repoHashId}/deleteYamlView") + fun deleteYamlView( + @Parameter(description = "项目ID", required = true) + @PathParam("projectId") + projectId: String, + @Parameter(description = "代码库hashId", required = true) + @PathParam("repoHashId") + repoHashId: String, + @Parameter(description = "yaml文件目录", required = true) + @QueryParam("directory") + directory: String + ): Result } diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineYamlInfoDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineYamlInfoDao.kt index 513aa9e987db..b024f089e1f3 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineYamlInfoDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineYamlInfoDao.kt @@ -226,12 +226,20 @@ class PipelineYamlInfoDao { fun countYamlPipeline( dslContext: DSLContext, projectId: String, - repoHashId: String + repoHashId: String, + directory: String? = null ): Long { return with(TPipelineYamlInfo.T_PIPELINE_YAML_INFO) { dslContext.selectCount().from(this) .where(PROJECT_ID.eq(projectId)) .and(REPO_HASH_ID.eq(repoHashId)) + .let { + if (directory.isNullOrBlank()) { + it + } else { + it.and(DIRECTORY.eq(directory)) + } + } .fetchOne(0, Long::class.java) ?: 0L } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/op/OpPipelineViewResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/op/OpPipelineViewResourceImpl.kt index 320f74f85128..6a7de4745b88 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/op/OpPipelineViewResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/op/OpPipelineViewResourceImpl.kt @@ -3,14 +3,29 @@ package com.tencent.devops.process.api.op import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.common.web.RestResource import com.tencent.devops.process.service.view.PipelineViewGroupService +import com.tencent.devops.process.yaml.PipelineYamlViewService import org.springframework.beans.factory.annotation.Autowired @RestResource class OpPipelineViewResourceImpl @Autowired constructor( - private val pipelineViewGroupService: PipelineViewGroupService + private val pipelineViewGroupService: PipelineViewGroupService, + private val pipelineYamlViewService: PipelineYamlViewService ) : OpPipelineViewResource { override fun initAllView(userId: String): Result { Thread { pipelineViewGroupService.initAllView() }.start() return Result(true) } + + override fun deleteYamlView( + projectId: String, + repoHashId: String, + directory: String + ): Result { + pipelineYamlViewService.deleteYamlView( + projectId = projectId, + repoHashId = repoHashId, + directory = directory + ) + return Result(true) + } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/yaml/PipelineYamlRepositoryService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/yaml/PipelineYamlRepositoryService.kt index 503d7b2153bc..641ed39cd7a9 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/yaml/PipelineYamlRepositoryService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/yaml/PipelineYamlRepositoryService.kt @@ -40,6 +40,7 @@ import com.tencent.devops.common.pipeline.utils.RepositoryConfigUtils import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.process.engine.service.PipelineRepositoryService import com.tencent.devops.process.engine.service.PipelineWebhookService +import com.tencent.devops.process.pojo.pipeline.PipelineYamlView import com.tencent.devops.process.pojo.pipeline.PipelineYamlVo import com.tencent.devops.process.pojo.pipeline.enums.PipelineYamlStatus import com.tencent.devops.process.pojo.webhook.PipelineWebhookVersion @@ -625,16 +626,10 @@ class PipelineYamlRepositoryService @Autowired constructor( // 删除流水线组 val yamlViews = pipelineYamlViewService.listRepoYamlView(projectId = projectId, repoHashId = repoHashId) yamlViews.forEach { yamlView -> - pipelineViewGroupService.deleteViewGroup( + deleteYamlView( projectId = projectId, userId = userId, - viewIdEncode = HashUtil.encodeLongId(yamlView.viewId), - checkPac = false - ) - pipelineYamlViewService.deleteYamlView( - projectId = projectId, - repoHashId = repoHashId, - directory = yamlView.directory + yamlView = yamlView ) } // 删除yaml同步记录 @@ -671,6 +666,26 @@ class PipelineYamlRepositoryService @Autowired constructor( filePath = filePath ) if (refreshView) { + // 如果PAC流水线组已经没有流水线了,那么就将这个流水线组删除 + val directory = GitActionCommon.getCiDirectory(filePath) + val yamlPipelineCnt = pipelineYamlService.countPipelineYaml( + projectId = projectId, + repoHashId = repoHashId, + directory = directory + ) + if (yamlPipelineCnt == 0L) { + pipelineYamlViewService.getPipelineYamlView( + projectId = projectId, + repoHashId = repoHashId, + directory = directory + )?.let { + deleteYamlView( + projectId = projectId, + userId = userId, + yamlView = it + ) + } + } val pipelineInfo = pipelineRepositoryService.getPipelineInfo(projectId, pipelineId) ?: return pipelineViewGroupService.updateGroupAfterPipelineUpdate( projectId = projectId, @@ -682,6 +697,24 @@ class PipelineYamlRepositoryService @Autowired constructor( } } + private fun deleteYamlView( + projectId: String, + userId: String, + yamlView: PipelineYamlView + ) { + pipelineViewGroupService.deleteViewGroup( + projectId = projectId, + userId = userId, + viewIdEncode = HashUtil.encodeLongId(yamlView.viewId), + checkPac = false + ) + pipelineYamlViewService.deleteYamlView( + projectId = projectId, + repoHashId = yamlView.repoHashId, + directory = yamlView.directory + ) + } + /** * TODO 需优化 * 本来应该在com.tencent.devops.process.engine.service.PipelineWebhookService.addWebhook处理, diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/yaml/PipelineYamlService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/yaml/PipelineYamlService.kt index 668c21e01463..8cb7a2e2e18a 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/yaml/PipelineYamlService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/yaml/PipelineYamlService.kt @@ -31,7 +31,6 @@ package com.tencent.devops.process.yaml import com.tencent.devops.common.api.enums.RepositoryType import com.tencent.devops.common.api.model.SQLPage import com.tencent.devops.common.client.Client -import com.tencent.devops.model.process.tables.records.TPipelineYamlBranchFileRecord import com.tencent.devops.process.engine.dao.PipelineInfoDao import com.tencent.devops.process.engine.dao.PipelineWebhookVersionDao import com.tencent.devops.process.engine.dao.PipelineYamlBranchFileDao @@ -299,17 +298,6 @@ class PipelineYamlService( } } - fun listEnablePacPipelineMap( - projectId: String, - pipelineIds: List - ): List { - return pipelineYamlInfoDao.listByPipelineIds( - dslContext = dslContext, - projectId = projectId, - pipelineIds = pipelineIds - ) - } - /** * 获取当前分支或blob_id对应的最新的版本 */ @@ -410,12 +398,14 @@ class PipelineYamlService( fun countPipelineYaml( projectId: String, - repoHashId: String + repoHashId: String, + directory: String? = null ): Long { return pipelineYamlInfoDao.countYamlPipeline( dslContext = dslContext, projectId = projectId, - repoHashId = repoHashId + repoHashId = repoHashId, + directory = directory ) } @@ -514,19 +504,4 @@ class PipelineYamlService( branch = branch ) } - - fun getBranchFilePath( - projectId: String, - repoHashId: String, - branch: String, - filePath: String - ): TPipelineYamlBranchFileRecord? { - return pipelineYamlBranchFileDao.get( - dslContext = dslContext, - projectId = projectId, - repoHashId = repoHashId, - branch = branch, - filePath = filePath - ) - } }