Skip to content

Commit

Permalink
Merge pull request #11267 from mingshewhe/bug_11254
Browse files Browse the repository at this point in the history
bug: [PAC].ci下的目录已经删除,但是关联的流水线组没有删除,也无法手工删除 #11254
  • Loading branch information
bkci-bot authored Nov 29, 2024
2 parents a7ae539 + 98657bf commit 1ddbb8a
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "用户-流水线视图")
Expand All @@ -26,4 +29,19 @@ interface OpPipelineViewResource {
@HeaderParam(AUTH_HEADER_USER_ID)
userId: String
): Result<Boolean>

@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<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean> {
Thread { pipelineViewGroupService.initAllView() }.start()
return Result(true)
}

override fun deleteYamlView(
projectId: String,
repoHashId: String,
directory: String
): Result<Boolean> {
pipelineYamlViewService.deleteYamlView(
projectId = projectId,
repoHashId = repoHashId,
directory = directory
)
return Result(true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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同步记录
Expand Down Expand Up @@ -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,
Expand All @@ -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处理,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -299,17 +298,6 @@ class PipelineYamlService(
}
}

fun listEnablePacPipelineMap(
projectId: String,
pipelineIds: List<String>
): List<PipelineYamlInfo> {
return pipelineYamlInfoDao.listByPipelineIds(
dslContext = dslContext,
projectId = projectId,
pipelineIds = pipelineIds
)
}

/**
* 获取当前分支或blob_id对应的最新的版本
*/
Expand Down Expand Up @@ -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
)
}

Expand Down Expand Up @@ -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
)
}
}

0 comments on commit 1ddbb8a

Please sign in to comment.