Skip to content

Commit

Permalink
Revert "bug:流水线实例复制功能没有复制相应实例的参数值 #10580"
Browse files Browse the repository at this point in the history
This reverts commit 0a55a81.
  • Loading branch information
mingshewhe committed Aug 5, 2024
1 parent d704b67 commit bca3ec2
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -206,20 +205,4 @@ interface UserTemplateInstanceResource {
@QueryParam("desc")
desc: Boolean?
): Result<TemplateInstancePage>

@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<TemplateModelDetail>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -166,18 +165,4 @@ class UserTemplateInstanceResourceImpl @Autowired constructor(
)
)
}

override fun copyTemplateInstance(
userId: String,
projectId: String,
pipelineId: String
): Result<TemplateModelDetail> {
return Result(
templateFacadeService.copyTemplateInstance(
userId = userId,
projectId = projectId,
pipelineId = pipelineId
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit bca3ec2

Please sign in to comment.