Skip to content

Commit

Permalink
feat:流水线支持归档目录 TencentBlueKing#9320
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxuwan committed Sep 11, 2023
1 parent b89d40c commit 2b5360f
Showing 1 changed file with 71 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class BkRepoService @Autowired constructor(
) {
logger.info(
"setProperties, userId: $userId, projectId: $projectId, artifactoryType: $artifactoryType, " +
"argPath: $argPath, properties: $properties"
"argPath: $argPath, properties: $properties"
)
if (properties.isEmpty()) {
logger.info("property empty")
Expand All @@ -197,7 +197,7 @@ class BkRepoService @Autowired constructor(
): List<Property> {
logger.info(
"getProperties, userId: $userId, projectId: $projectId, artifactoryType: $artifactoryType," +
" path: $path"
" path: $path"
)
val normalizedPath = PathUtils.checkAndNormalizeAbsPath(path)
val matadataMap =
Expand Down Expand Up @@ -229,8 +229,8 @@ class BkRepoService @Autowired constructor(
): List<FileDetail> {
logger.info(
"getPropertiesByRegex, projectId: $projectId, pipelineId: $pipelineId, buildId: $buildId, " +
"artifactoryType: $artifactoryType, argPath: $argPath, crossProjectId: $crossProjectId, " +
"crossPipineId: $crossPipineId, crossBuildNo: $crossBuildNo"
"artifactoryType: $artifactoryType, argPath: $argPath, crossProjectId: $crossProjectId, " +
"crossPipineId: $crossPipineId, crossBuildNo: $crossBuildNo"
)

var targetProjectId = projectId
Expand All @@ -249,10 +249,10 @@ class BkRepoService @Autowired constructor(
channelCode = ChannelCode.BS
).data
targetBuildId = (targetBuild ?: throw BadRequestException(
I18nUtil.getCodeLanMessage(
messageCode = BUILD_NOT_EXIST,
params = arrayOf(crossBuildNo)
)
I18nUtil.getCodeLanMessage(
messageCode = BUILD_NOT_EXIST,
params = arrayOf(crossBuildNo)
)
)).id
}
}
Expand Down Expand Up @@ -333,7 +333,7 @@ class BkRepoService @Autowired constructor(
): List<AppFileInfo> {
logger.info(
"getBuildFileList, userId: $userId, projectId: $projectId," +
" pipelineId: $pipelineId, buildId: $buildId"
" pipelineId: $pipelineId, buildId: $buildId"
)
pipelineService.validatePermission(
userId,
Expand Down Expand Up @@ -457,9 +457,9 @@ class BkRepoService @Autowired constructor(
if (!metadataMap.containsKey(ARCHIVE_PROPS_PIPELINE_ID) || metadataMap[ARCHIVE_PROPS_PIPELINE_ID].isNullOrBlank()) {
throw BadRequestException(
I18nUtil.getCodeLanMessage(
messageCode = METADATA_NOT_EXIST,
params = arrayOf("pipelineId")
)
messageCode = METADATA_NOT_EXIST,
params = arrayOf("pipelineId")
)
)
}
val pipelineId = metadataMap[ARCHIVE_PROPS_PIPELINE_ID]
Expand Down Expand Up @@ -532,34 +532,23 @@ class BkRepoService @Autowired constructor(

logger.info(
"pipelineHasPermissionList.contains(pipelineId):" +
" ${(!checkPermission || pipelineHasPermissionList.contains(pipelineId))}"
" ${(!checkPermission || pipelineHasPermissionList.contains(pipelineId))}"
)
if ((!checkPermission || pipelineHasPermissionList.contains(pipelineId)) &&
pipelineIdToNameMap.containsKey(pipelineId) && buildIdToNameMap.containsKey(buildId)
) {
val pipelineName = pipelineIdToNameMap[pipelineId]!!
val buildName = buildIdToNameMap[buildId]!!
fileInfoList.add(
FileInfo(
name = it.name,
fullName = pipelineService.getFullName(
it.fullPath,
pipelineId,
pipelineName,
buildId,
buildName
),
path = it.fullPath,
fullPath = it.fullPath,
size = it.size,
folder = it.folder,
modifiedTime = LocalDateTime.parse(it.lastModifiedDate, DateTimeFormatter.ISO_DATE_TIME)
.timestamp(),
artifactoryType = RepoUtils.getTypeByRepo(it.repoName),
buildPipelineArtifactInfo(
nodeInfo = it,
pipelineId = pipelineId,
pipelineName = pipelineName,
buildId = buildId,
buildName = buildName,
properties = properties,
appVersion = appVersion,
shortUrl = shortUrl,
md5 = it.md5
shortUrl = shortUrl
)
)
}
Expand All @@ -575,25 +564,51 @@ class BkRepoService @Autowired constructor(
}
}

private fun buildCustomArtifactInfo(
private fun buildPipelineArtifactInfo(
nodeInfo: QueryNodeInfo,
pipelineId: String,
pipelineName: String,
buildId: String,
buildName: String,
properties: List<Property>,
appVersion: String?
appVersion: String?,
shortUrl: String
): FileInfo {
// 归档插件归档目录时,在目录多归档一个.bkci_pipeline文件, 记录归档目录的信息
return if (nodeInfo.name == ".bkci_pipeline") {
buildFolderArtifactInfo(nodeInfo, properties)
} else {
FileInfo(
name = nodeInfo.path.split("/").last { it.isNotBlank() },
fullName = nodeInfo.path,
path = nodeInfo.path,
fullPath = nodeInfo.path,
name = nodeInfo.name,
fullName = pipelineService.getFullName(
nodeInfo.fullPath,
pipelineId,
pipelineName,
buildId,
buildName
),
path = nodeInfo.fullPath,
fullPath = nodeInfo.fullPath,
size = nodeInfo.size,
folder = true,
folder = nodeInfo.folder,
modifiedTime = LocalDateTime.parse(nodeInfo.lastModifiedDate, DateTimeFormatter.ISO_DATE_TIME)
.timestamp(),
artifactoryType = RepoUtils.getTypeByRepo(nodeInfo.repoName),
properties = properties
properties = properties,
appVersion = appVersion,
shortUrl = shortUrl,
md5 = nodeInfo.md5
)
}
}

private fun buildCustomArtifactInfo(
nodeInfo: QueryNodeInfo,
properties: List<Property>,
appVersion: String?
): FileInfo {
// 归档插件归档目录时,在目录多归档一个.bkci_pipeline文件, 记录归档目录的信息
return if (nodeInfo.name == ".bkci_pipeline") {
buildFolderArtifactInfo(nodeInfo, properties)
} else {
FileInfo(
name = nodeInfo.name,
Expand All @@ -612,6 +627,21 @@ class BkRepoService @Autowired constructor(
}
}

private fun buildFolderArtifactInfo(nodeInfo: QueryNodeInfo, properties: List<Property>): FileInfo {
return FileInfo(
name = nodeInfo.path.split("/").last { it.isNotBlank() },
fullName = nodeInfo.path,
path = nodeInfo.path,
fullPath = nodeInfo.path,
size = nodeInfo.size,
folder = true,
modifiedTime = LocalDateTime.parse(nodeInfo.lastModifiedDate, DateTimeFormatter.ISO_DATE_TIME)
.timestamp(),
artifactoryType = RepoUtils.getTypeByRepo(nodeInfo.repoName),
properties = properties
)
}

private fun buildImageArtifactInfo(manifestInfo: QueryNodeInfo): FileInfo {
with(manifestInfo) {
val (imageName, version) = PathUtils.getImageNameAndVersion(fullPath)
Expand Down Expand Up @@ -778,7 +808,7 @@ class BkRepoService @Autowired constructor(
): String {
logger.info(
"externalDownloadUrl, creatorId: $creatorId, userId: $userId," +
" projectId: $projectId, artifactoryType: $artifactoryType, fullPath: $fullPath, ttl: $ttl"
" projectId: $projectId, artifactoryType: $artifactoryType, fullPath: $fullPath, ttl: $ttl"
)
val shareUri = bkRepoClient.createShareUri(
creatorId = creatorId,
Expand Down

0 comments on commit 2b5360f

Please sign in to comment.