Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: 代码库获取项目列表耗时太长 #4290 #6695

Merged
merged 19 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
493ebf1
feature: 代码库获取项目列表耗时太长 #4290
mingshewhe May 4, 2022
57c395c
feature: 代码库获取项目列表耗时太长 #4290
mingshewhe May 4, 2022
798ff62
feature: 代码库获取项目列表耗时太长 #4290
mingshewhe May 4, 2022
a139dc3
feat:希望流水线变量支持tgit的分支 #3660
mingshewhe May 7, 2022
0fba702
feat:当关联的代码库过多,模板实例化的代码库自定义变量没有获取到所有代码库 #1683
mingshewhe May 7, 2022
40bb241
feature: 代码库获取项目列表耗时太长 #4290
mingshewhe May 7, 2022
ff7142a
feature: 代码库获取项目列表耗时太长 #4290
mingshewhe May 7, 2022
ca89430
feature: 代码库获取项目列表耗时太长 #4290
mingshewhe May 7, 2022
4c0a9e6
feat:当关联的代码库过多,模板实例化的代码库自定义变量没有获取到所有代码库 #1683
mingshewhe May 7, 2022
70bbe53
feat:当关联的代码库过多,模板实例化的代码库自定义变量没有获取到所有代码库 #1683
mingshewhe May 7, 2022
3f867bb
feat:希望流水线变量支持tgit的分支 #3660
mingshewhe May 7, 2022
bb2a1a9
feat:希望流水线变量支持tgit的分支 #3660
mingshewhe May 8, 2022
9f62ec6
Merge remote-tracking branch 'github/master' into feat_4290
mingshewhe May 8, 2022
6827884
feature: 代码库获取项目列表耗时太长 #4290
mingshewhe May 8, 2022
feaac9d
feat:希望流水线变量支持tgit的分支 #3660
mingshewhe May 8, 2022
812166e
feat:希望流水线变量支持tgit的分支 #3660
mingshewhe May 8, 2022
2152a00
feat:希望流水线变量支持tgit的分支 #3660
mingshewhe May 9, 2022
cb3350c
feat:希望流水线变量支持tgit的分支 #3660
mingshewhe May 9, 2022
c2e6a5e
feature: 代码库获取项目列表耗时太长 #4290
mingshewhe May 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ class ApigwRepositoryResourceV3Impl @Autowired constructor(private val client: C
return client.get(ServiceRepositoryResource::class).hasPermissionList(
userId = userId,
projectId = projectId,
repositoryType = repositoryType,
permission = Permission.USE)
repositoryType = repositoryType?.name,
permission = Permission.USE
)
}

override fun delete(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ApigwRepositoryResourceV4Impl @Autowired constructor(private val client: C
return client.get(ServiceRepositoryResource::class).hasPermissionList(
userId = userId,
projectId = projectId,
repositoryType = repositoryType,
repositoryType = repositoryType?.name,
permission = Permission.USE)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ package com.tencent.devops.process.api.user
import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID
import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID_DEFAULT_VALUE
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.pipeline.pojo.BuildFormValue
import com.tencent.devops.process.pojo.BuildFormRepositoryValue
import com.tencent.devops.repository.pojo.enums.Permission
import com.tencent.devops.store.pojo.app.BuildEnvParameters
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
Expand All @@ -38,13 +41,16 @@ import javax.ws.rs.Consumes
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

@Api(tags = ["USER_BUILD_PARAMETERS"], description = "用户-构建环境参数")
@Path("/user/buildParam")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@SuppressWarnings("LongParameterList")
interface UserBuildParametersResource {

@ApiOperation("获取构建的公共参数")
Expand All @@ -55,4 +61,58 @@ interface UserBuildParametersResource {
@HeaderParam(AUTH_HEADER_USER_ID)
userId: String
): Result<List<BuildEnvParameters>>

@ApiOperation("构建表单查询代码库别名列表")
@GET
@Path("/repository/{projectId}/aliasName")
fun listRepositoryAliasName(
@ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE)
@HeaderParam(AUTH_HEADER_USER_ID)
userId: String,
@ApiParam("项目ID", required = true)
@PathParam("projectId")
projectId: String,
@ApiParam("仓库类型", required = false)
@QueryParam("repositoryType")
repositoryType: String?,
@ApiParam("对应权限", required = true, defaultValue = "")
@QueryParam("permission")
permission: Permission,
@ApiParam("别名", required = false)
@QueryParam("aliasName")
aliasName: String? = null,
@ApiParam("第几页", required = false, defaultValue = "1")
@QueryParam("page")
page: Int?,
@ApiParam("每页多少条", required = false, defaultValue = "20")
@QueryParam("pageSize")
pageSize: Int?
): Result<List<BuildFormValue>>

@ApiOperation("构建表单查询代码库hashId列表")
@GET
@Path("/repository/{projectId}/hashId")
fun listRepositoryHashId(
@ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE)
@HeaderParam(AUTH_HEADER_USER_ID)
userId: String,
@ApiParam("项目ID", required = true)
@PathParam("projectId")
projectId: String,
@ApiParam("仓库类型", required = false)
@QueryParam("repositoryType")
repositoryType: String?,
@ApiParam("对应权限", required = true, defaultValue = "")
@QueryParam("permission")
permission: Permission,
@ApiParam("别名", required = false)
@QueryParam("aliasName")
aliasName: String? = null,
@ApiParam("第几页", required = false, defaultValue = "1")
@QueryParam("page")
page: Int?,
@ApiParam("每页多少条", required = false, defaultValue = "20")
@QueryParam("pageSize")
pageSize: Int?
): Result<List<BuildFormRepositoryValue>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license.
*
* A copy of the MIT License is included in this file.
*
*
* Terms of the MIT License:
* ---------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.tencent.devops.process.pojo

/**
* 构建表单代码库值
*/
data class BuildFormRepositoryValue(
val id: String,
val name: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,27 @@ class ScmProxyService @Autowired constructor(private val client: Client) {
search = search
)
}
is GithubRepository -> {
val token = getGithubAccessToken(repo.userName)
return client.get(ServiceGithubResource::class).listBranches(
projectName = repo.projectName,
accessToken = token
)
}
is CodeTGitRepository -> {
val credInfo = getCredential(projectId, repo)
return client.get(ServiceScmResource::class).listBranches(
projectName = repo.projectName,
url = repo.url,
type = ScmType.CODE_TGIT,
privateKey = null,
passPhrase = null,
token = credInfo.privateKey,
region = null,
userName = credInfo.username,
search = search
)
}
else -> {
throw IllegalArgumentException("Unknown repo($repo)")
}
Expand Down Expand Up @@ -344,6 +365,24 @@ class ScmProxyService @Autowired constructor(private val client: Client) {
search = search
)
}
is GithubRepository -> {
val token = getGithubAccessToken(repo.userName)
return client.get(ServiceGithubResource::class).listTags(
projectName = repo.projectName,
accessToken = token
)
}
is CodeTGitRepository -> {
val credInfo = getCredential(projectId, repo)
return client.get(ServiceScmResource::class).listTags(
projectName = repo.projectName,
url = repo.url,
type = ScmType.CODE_GIT,
token = credInfo.privateKey,
userName = credInfo.username,
search = search
)
}
else -> {
throw IllegalArgumentException("Unknown repo($repo)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
package com.tencent.devops.process.api

import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.client.Client
import com.tencent.devops.common.pipeline.enums.StartType
import com.tencent.devops.common.pipeline.pojo.BuildFormValue
import com.tencent.devops.common.web.RestResource
import com.tencent.devops.process.api.user.UserBuildParametersResource
import com.tencent.devops.process.pojo.BuildFormRepositoryValue
import com.tencent.devops.process.utils.PIPELINE_BUILD_ID
import com.tencent.devops.process.utils.PIPELINE_BUILD_NUM
import com.tencent.devops.process.utils.PIPELINE_ELEMENT_ID
Expand All @@ -40,11 +43,21 @@ import com.tencent.devops.process.utils.PIPELINE_START_TYPE
import com.tencent.devops.process.utils.PIPELINE_START_USER_NAME
import com.tencent.devops.process.utils.PIPELINE_VMSEQ_ID
import com.tencent.devops.process.utils.PROJECT_NAME
import com.tencent.devops.repository.api.ServiceRepositoryResource
import com.tencent.devops.repository.pojo.enums.Permission
import com.tencent.devops.store.pojo.app.BuildEnvParameters
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired

@Suppress("UNUSED")
@RestResource
class UserBuildParametersResourceImpl : UserBuildParametersResource {
class UserBuildParametersResourceImpl @Autowired constructor(
private val client: Client
) : UserBuildParametersResource {

companion object {
private val logger = LoggerFactory.getLogger(UserBuildParametersResourceImpl::class.java)
}

private val result = Result(
data = listOf(
Expand All @@ -66,4 +79,69 @@ class UserBuildParametersResourceImpl : UserBuildParametersResource {
override fun getCommonBuildParams(userId: String): Result<List<BuildEnvParameters>> {
return result
}

override fun listRepositoryAliasName(
userId: String,
projectId: String,
repositoryType: String?,
permission: Permission,
aliasName: String?,
page: Int?,
pageSize: Int?
): Result<List<BuildFormValue>> {
return Result(
listRepositoryInfo(
userId = userId,
projectId = projectId,
repositoryType = repositoryType,
page = page,
pageSize = pageSize,
aliasName = aliasName
).map { BuildFormValue(it.aliasName, it.aliasName) }
)
}

@SuppressWarnings("LongParameterList")
private fun listRepositoryInfo(
userId: String,
projectId: String,
repositoryType: String?,
page: Int?,
pageSize: Int?,
aliasName: String?
) = try {
client.get(ServiceRepositoryResource::class).hasPermissionList(
userId = userId,
projectId = projectId,
permission = Permission.LIST,
repositoryType = repositoryType,
page = page,
pageSize = pageSize,
aliasName = aliasName
).data?.records ?: emptyList()
} catch (ignore: Exception) {
logger.warn("[$userId|$projectId] Fail to get the repository list", ignore)
emptyList()
}

override fun listRepositoryHashId(
userId: String,
projectId: String,
repositoryType: String?,
permission: Permission,
aliasName: String?,
page: Int?,
pageSize: Int?
): Result<List<BuildFormRepositoryValue>> {
return Result(
listRepositoryInfo(
userId = userId,
projectId = projectId,
repositoryType = repositoryType,
page = page,
pageSize = pageSize,
aliasName = aliasName
).map { BuildFormRepositoryValue(id = it.repositoryHashId!!, name = it.aliasName) }
)
}
}
Loading