Skip to content

Commit

Permalink
Merge pull request #10911 from royalhuang/issue_9861
Browse files Browse the repository at this point in the history
feat:草稿版本UI展示 #9861 控制草稿相关查询内容
  • Loading branch information
mingshewhe authored Sep 5, 2024
2 parents 3759f6e + 8dc3025 commit 2df1ddf
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ interface AppPipelineBuildResource {
@Parameter(description = "构建信息", required = false)
@QueryParam("buildMsg")
buildMsg: String?,
@Parameter(description = "查看指定版本调试数据", required = false, example = "false")
@QueryParam("version")
customVersion: Int? = null,
@Parameter(description = "指定调试数据", required = false)
@QueryParam("debug")
debug: Boolean? = null,
@Parameter(description = "触发代码库", required = false)
@QueryParam("triggerAlias")
triggerAlias: List<String>?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,9 @@ interface ServiceBuildResource {
@Parameter(description = "是否查询归档数据", required = false)
@QueryParam("archiveFlag")
archiveFlag: Boolean? = false,
@Parameter(description = "查看指定版本调试数据", required = false, example = "false")
@QueryParam("version")
customVersion: Int? = null,
@Parameter(description = "指定调试数据", required = false)
@QueryParam("debug")
debug: Boolean? = null,
@Parameter(description = "触发代码库", required = false)
@QueryParam("triggerAlias")
triggerAlias: List<String>? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ interface UserBuildResource {
@Parameter(description = "是否查询归档数据", required = false)
@QueryParam("archiveFlag")
archiveFlag: Boolean? = false,
@Parameter(description = "查看指定版本调试数据", required = false, example = "false")
@QueryParam("version")
customVersion: Int? = null,
@Parameter(description = "指定调试数据", required = false)
@QueryParam("debug")
debug: Boolean? = null,
@Parameter(description = "触发代码库", required = false)
@QueryParam("triggerAlias")
triggerAlias: List<String>?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ class PipelineBuildDao {
return normal.plus(debug)
}

/**
* 查询BuildInfo,兼容所有运行时调用,不排除已删除的调试记录
* @param dslContext: 事务上下文
* @param projectId: 项目Id
* @param buildId: 构建Id
*/
fun getBuildInfo(
dslContext: DSLContext,
projectId: String,
Expand All @@ -332,6 +338,29 @@ class PipelineBuildDao {
}
}

/**
* 查询BuildInfo,返回给用户侧的数据,需要排除已删除的调试记录
* @param dslContext: 事务上下文
* @param projectId: 项目Id
* @param buildId: 构建Id
*/
fun getUserBuildInfo(
dslContext: DSLContext,
projectId: String,
buildId: String
): BuildInfo? {
return with(T_PIPELINE_BUILD_HISTORY) {
dslContext.selectFrom(this)
.where(PROJECT_ID.eq(projectId).and(BUILD_ID.eq(buildId)))
.fetchAny(mapper)
} ?: with(T_PIPELINE_BUILD_HISTORY_DEBUG) {
dslContext.selectFrom(this)
.where(PROJECT_ID.eq(projectId).and(BUILD_ID.eq(buildId)))
.and(DELETE_TIME.isNull)
.fetchAny(debugMapper)
}
}

fun getStartUser(dslContext: DSLContext, projectId: String, buildId: String): String? {
return with(T_PIPELINE_BUILD_HISTORY) {
dslContext.select(START_USER)
Expand Down Expand Up @@ -376,7 +405,7 @@ class PipelineBuildDao {
with(T_PIPELINE_BUILD_HISTORY_DEBUG) {
val conditions = mutableListOf<Condition>()
conditions.add(BUILD_ID.`in`(buildIds))
// 增加过滤,对前端屏蔽已删除的构建
// 增加过滤,对前端屏蔽已删除的构建
conditions.add(DELETE_TIME.isNull)
if (projectId != null) {
conditions.add(PROJECT_ID.eq(projectId))
Expand Down Expand Up @@ -956,12 +985,12 @@ class PipelineBuildDao {
buildNoEnd: Int?,
buildMsg: String?,
startUser: List<String>?,
debugVersion: Int?,
debug: Boolean?,
triggerAlias: List<String>?,
triggerBranch: List<String>?,
triggerUser: List<String>?
): Int {
return if (debugVersion == null) {
return if (debug != true) {
with(T_PIPELINE_BUILD_HISTORY) {
val where = dslContext.selectCount()
.from(this).where(PROJECT_ID.eq(projectId)).and(PIPELINE_ID.eq(pipelineId))
Expand Down Expand Up @@ -998,7 +1027,6 @@ class PipelineBuildDao {
val where = dslContext.selectCount()
.from(this)
.where(PROJECT_ID.eq(projectId)).and(PIPELINE_ID.eq(pipelineId))
.and(VERSION.eq(debugVersion))
makeDebugCondition(
where = where,
materialAlias = materialAlias,
Expand Down Expand Up @@ -1057,12 +1085,12 @@ class PipelineBuildDao {
buildMsg: String?,
startUser: List<String>?,
updateTimeDesc: Boolean? = null,
debugVersion: Int?,
debug: Boolean?,
triggerAlias: List<String>?,
triggerBranch: List<String>?,
triggerUser: List<String>?
): Collection<BuildInfo> {
return if (debugVersion == null) {
return if (debug != true) {
with(T_PIPELINE_BUILD_HISTORY) {
val where = dslContext.selectFrom(this).where(PROJECT_ID.eq(projectId)).and(PIPELINE_ID.eq(pipelineId))
makeCondition(
Expand Down Expand Up @@ -1104,7 +1132,6 @@ class PipelineBuildDao {
with(T_PIPELINE_BUILD_HISTORY_DEBUG) {
val where = dslContext.selectFrom(this)
.where(PROJECT_ID.eq(projectId)).and(PIPELINE_ID.eq(pipelineId))
.and(VERSION.eq(debugVersion))
makeDebugCondition(
where = where,
materialAlias = materialAlias,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class PipelineBuildDetailService @Autowired constructor(

val record = buildDetailDao.get(dslContext, projectId, buildId) ?: return null

val buildInfo = pipelineBuildDao.getBuildInfo(
val buildInfo = pipelineBuildDao.getUserBuildInfo(
dslContext = dslContext,
projectId = projectId,
buildId = buildId
Expand Down Expand Up @@ -367,12 +367,4 @@ class PipelineBuildDetailService @Autowired constructor(
cancelUser = cancelUserId
)
}

fun getBuildDetailPipelineId(projectId: String, buildId: String): String? {
return pipelineBuildDao.getBuildInfo(
dslContext = dslContext,
projectId = projectId,
buildId = buildId
)?.pipelineId
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import javax.ws.rs.core.Response
@Suppress("LongParameterList")
class PipelineProgressRateService constructor(
private val taskBuildRecordService: TaskBuildRecordService,
private val pipelineBuildDetailService: PipelineBuildDetailService,
private val pipelineTaskService: PipelineTaskService,
private val pipelineRuntimeService: PipelineRuntimeService,
private val buildRecordService: ContainerBuildRecordService,
Expand All @@ -34,7 +33,7 @@ class PipelineProgressRateService constructor(
logger.info("report progress rate:$projectId|$buildId|$executeCount|$jobHeartbeatRequest")
val task2ProgressRate = jobHeartbeatRequest?.task2ProgressRate ?: return
if (task2ProgressRate.isEmpty()) return
val pipelineId = pipelineBuildDetailService.getBuildDetailPipelineId(projectId, buildId) ?: return
val pipelineId = pipelineRuntimeService.getBuildInfo(projectId, buildId)?.pipelineId ?: return
task2ProgressRate.forEach { (taskId, progressRate) ->
taskBuildRecordService.updateTaskRecord(
projectId = projectId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ class PipelineRuntimeService @Autowired constructor(
startUser: List<String>?,
updateTimeDesc: Boolean? = null,
queryDslContext: DSLContext? = null,
debugVersion: Int?,
debug: Boolean?,
triggerAlias: List<String>?,
triggerBranch: List<String>?,
triggerUser: List<String>?
Expand Down Expand Up @@ -408,7 +408,7 @@ class PipelineRuntimeService @Autowired constructor(
buildMsg = buildMsg,
startUser = startUser,
updateTimeDesc = updateTimeDesc,
debugVersion = debugVersion,
debug = debug,
triggerAlias = triggerAlias,
triggerBranch = triggerBranch,
triggerUser = triggerUser
Expand Down Expand Up @@ -1885,7 +1885,7 @@ class PipelineRuntimeService @Autowired constructor(
buildMsg: String? = null,
startUser: List<String>? = null,
queryDslContext: DSLContext? = null,
debugVersion: Int? = null,
debug: Boolean?,
triggerAlias: List<String>?,
triggerBranch: List<String>?,
triggerUser: List<String>?
Expand Down Expand Up @@ -1914,7 +1914,7 @@ class PipelineRuntimeService @Autowired constructor(
buildNoEnd = buildNoEnd,
buildMsg = buildMsg,
startUser = startUser,
debugVersion = debugVersion,
debug = debug,
triggerAlias = triggerAlias,
triggerBranch = triggerBranch,
triggerUser = triggerUser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ open class BaseBuildDetailService constructor(
}

private fun pipelineDetailChangeEvent(projectId: String, buildId: String) {
val pipelineBuildInfo = pipelineBuildDao.getBuildInfo(dslContext, projectId, buildId)
val pipelineBuildInfo = pipelineBuildDao.getUserBuildInfo(dslContext, projectId, buildId)
if (pipelineBuildInfo?.channelCode == ChannelCode.GIT) pipelineEventDispatcher.dispatch(
// 异步转发,解耦核心
// TODO stream内部和开源前端未更新前,保持推送
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ open class BaseBuildRecordService(
executeCount: Int
) {
val userId = startUser
?: pipelineBuildDao.getBuildInfo(dslContext, projectId, buildId)?.startUser
?: pipelineBuildDao.getUserBuildInfo(dslContext, projectId, buildId)?.startUser
?: return
pipelineEventDispatcher.dispatch(
PipelineBuildWebSocketPushEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ class PipelineStatusService(
buildTaskCountList.filter { it.value2() == BuildStatus.SUCCEED.ordinal }.sumOf { it.value3() }

// 获取触发方式
val buildInfo = pipelineBuildDao.getBuildInfo(dslContext, projectId, pipelineBuildSummary.latestBuildId)
val buildInfo = pipelineBuildDao.getUserBuildInfo(
dslContext, projectId, pipelineBuildSummary.latestBuildId
)

// todo还没想好与Pipeline结合,减少这部分的代码,收归一处
return PipelineStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import com.tencent.devops.common.pipeline.pojo.BuildFormValue
import com.tencent.devops.common.pipeline.pojo.StageReviewRequest
import com.tencent.devops.common.web.RestResource
import com.tencent.devops.process.api.service.ServiceBuildResource
import com.tencent.devops.process.engine.service.PipelineBuildDetailService
import com.tencent.devops.process.engine.service.PipelineRuntimeService
import com.tencent.devops.process.engine.service.vmbuild.EngineVMBuildService
import com.tencent.devops.process.pojo.BuildBasicInfo
Expand Down Expand Up @@ -70,7 +69,6 @@ class ServiceBuildResourceImpl @Autowired constructor(
private val pipelineBuildMaintainFacadeService: PipelineBuildMaintainFacadeService,
private val pipelineBuildFacadeService: PipelineBuildFacadeService,
private val engineVMBuildService: EngineVMBuildService,
private val pipelineBuildDetailService: PipelineBuildDetailService,
private val pipelinePauseBuildFacadeService: PipelinePauseBuildFacadeService,
private val pipelineRuntimeService: PipelineRuntimeService
) : ServiceBuildResource {
Expand All @@ -79,7 +77,7 @@ class ServiceBuildResourceImpl @Autowired constructor(
throw ParamBlankException("Invalid buildId, it must not empty.")
}
return Result(
pipelineBuildDetailService.getBuildDetailPipelineId(projectId, buildId)
pipelineRuntimeService.getBuildInfo(projectId, buildId)?.pipelineId
?: throw ParamBlankException("Invalid buildId, please check if projectId & buildId are related")
)
}
Expand Down Expand Up @@ -385,7 +383,7 @@ class ServiceBuildResourceImpl @Autowired constructor(
buildMsg: String?,
startUser: List<String>?,
archiveFlag: Boolean?,
customVersion: Int?,
debug: Boolean?,
triggerAlias: List<String>?,
triggerBranch: List<String>?,
triggerUser: List<String>?
Expand Down Expand Up @@ -422,7 +420,7 @@ class ServiceBuildResourceImpl @Autowired constructor(
startUser = startUser?.filter { it.isNotBlank() },
updateTimeDesc = updateTimeDesc,
archiveFlag = archiveFlag,
customVersion = customVersion,
debug = debug,
triggerAlias = triggerAlias,
triggerBranch = triggerBranch,
triggerUser = triggerUser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ class UserBuildResourceImpl @Autowired constructor(
buildNoEnd: Int?,
buildMsg: String?,
archiveFlag: Boolean?,
customVersion: Int?,
debug: Boolean?,
triggerAlias: List<String>?,
triggerBranch: List<String>?,
triggerUser: List<String>?
Expand Down Expand Up @@ -483,7 +483,7 @@ class UserBuildResourceImpl @Autowired constructor(
buildNoEnd = buildNoEnd,
buildMsg = buildMsg,
archiveFlag = archiveFlag,
customVersion = customVersion,
debug = debug,
triggerAlias = triggerAlias,
triggerBranch = triggerBranch,
triggerUser = triggerUser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class AppPipelineBuildResourceImpl @Autowired constructor(
buildNoStart: Int?,
buildNoEnd: Int?,
buildMsg: String?,
customVersion: Int?,
debug: Boolean?,
triggerAlias: List<String>?,
triggerBranch: List<String>?,
triggerUser: List<String>?
Expand Down Expand Up @@ -229,7 +229,7 @@ class AppPipelineBuildResourceImpl @Autowired constructor(
buildNoStart = buildNoStart,
buildNoEnd = buildNoEnd,
buildMsg = buildMsg,
customVersion = customVersion,
debug = debug,
triggerAlias = triggerAlias,
triggerBranch = triggerBranch,
triggerUser = triggerUser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@ class PipelineBuildFacadeService(
startUser: List<String>? = null,
updateTimeDesc: Boolean? = null,
archiveFlag: Boolean? = false,
customVersion: Int?,
debug: Boolean?,
triggerAlias: List<String>?,
triggerBranch: List<String>?,
triggerUser: List<String>?
Expand Down Expand Up @@ -2016,26 +2016,6 @@ class PipelineBuildFacadeService(
permission = AuthPermission.VIEW
)
}
// 如果请求的参数是草稿版本的版本号,则返回调试记录,如果是当前正式版本则返回正式记录
// 否则按版本查询返回空数据
val customResource = pipelineRepositoryService.getPipelineResourceVersion(
projectId = projectId, pipelineId = pipelineId,
version = customVersion, includeDraft = true
)
val targetDebugVersion = if (customResource?.status == VersionStatus.COMMITTING) {
customVersion
} else if (customResource?.version == pipelineInfo.version) {
null
} else {
return BuildHistoryPage(
page = pageNotNull,
pageSize = limit,
count = 0,
records = emptyList(),
hasDownloadPermission = false,
pipelineVersion = pipelineInfo.version
)
}

val newTotalCount = pipelineRuntimeService.getPipelineBuildHistoryCount(
projectId = projectId,
Expand All @@ -2061,7 +2041,7 @@ class PipelineBuildFacadeService(
buildMsg = buildMsg,
startUser = startUser,
queryDslContext = queryDslContext,
debugVersion = targetDebugVersion,
debug = debug,
triggerAlias = triggerAlias,
triggerBranch = triggerBranch,
triggerUser = triggerUser
Expand Down Expand Up @@ -2094,7 +2074,7 @@ class PipelineBuildFacadeService(
startUser = startUser,
updateTimeDesc = updateTimeDesc,
queryDslContext = queryDslContext,
debugVersion = targetDebugVersion,
debug = debug,
triggerAlias = triggerAlias,
triggerBranch = triggerBranch,
triggerUser = triggerUser
Expand Down

0 comments on commit 2df1ddf

Please sign in to comment.