diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwRepositoryResourceV3Impl.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwRepositoryResourceV3Impl.kt index b7b12f20677..f81d0ddc4fc 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwRepositoryResourceV3Impl.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwRepositoryResourceV3Impl.kt @@ -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( diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwRepositoryResourceV4Impl.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwRepositoryResourceV4Impl.kt index 9a7e9abf21f..b65848a68d1 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwRepositoryResourceV4Impl.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwRepositoryResourceV4Impl.kt @@ -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) } diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserBuildParametersResource.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserBuildParametersResource.kt index f4736b6ce4b..7a3344f59e3 100644 --- a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserBuildParametersResource.kt +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/api/user/UserBuildParametersResource.kt @@ -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 @@ -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("获取构建的公共参数") @@ -55,4 +61,58 @@ interface UserBuildParametersResource { @HeaderParam(AUTH_HEADER_USER_ID) userId: String ): Result> + + @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> + + @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> } diff --git a/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/BuildFormRepositoryValue.kt b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/BuildFormRepositoryValue.kt new file mode 100644 index 00000000000..70944727616 --- /dev/null +++ b/src/backend/ci/core/process/api-process/src/main/kotlin/com/tencent/devops/process/pojo/BuildFormRepositoryValue.kt @@ -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 +) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/scm/ScmProxyService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/scm/ScmProxyService.kt index 112a547bcc6..0889d04694d 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/scm/ScmProxyService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/service/scm/ScmProxyService.kt @@ -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)") } @@ -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)") } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildParametersResourceImpl.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildParametersResourceImpl.kt index 238129bf4fb..1b943c9d83a 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildParametersResourceImpl.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/api/UserBuildParametersResourceImpl.kt @@ -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 @@ -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( @@ -66,4 +79,69 @@ class UserBuildParametersResourceImpl : UserBuildParametersResource { override fun getCommonBuildParams(userId: String): Result> { return result } + + override fun listRepositoryAliasName( + userId: String, + projectId: String, + repositoryType: String?, + permission: Permission, + aliasName: String?, + page: Int?, + pageSize: Int? + ): Result> { + 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> { + return Result( + listRepositoryInfo( + userId = userId, + projectId = projectId, + repositoryType = repositoryType, + page = page, + pageSize = pageSize, + aliasName = aliasName + ).map { BuildFormRepositoryValue(id = it.repositoryHashId!!, name = it.aliasName) } + ) + } } diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/ParamFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/ParamFacadeService.kt index b8191361b9a..a247a9881d2 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/ParamFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/ParamFacadeService.kt @@ -29,6 +29,7 @@ package com.tencent.devops.process.service import com.tencent.devops.artifactory.api.service.ServiceArtifactoryResource import com.tencent.devops.artifactory.pojo.CustomFileSearchCondition +import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.exception.OperationException import com.tencent.devops.common.api.util.Watcher import com.tencent.devops.common.auth.api.AuthPermission @@ -42,6 +43,7 @@ import com.tencent.devops.process.engine.service.PipelineRuntimeService import com.tencent.devops.process.permission.PipelinePermissionService import com.tencent.devops.process.pojo.SubPipeline import com.tencent.devops.repository.api.ServiceRepositoryResource +import com.tencent.devops.repository.pojo.RepositoryInfo import com.tencent.devops.repository.pojo.enums.Permission import com.tencent.devops.store.api.container.ServiceContainerResource import org.slf4j.LoggerFactory @@ -99,7 +101,7 @@ class ParamFacadeService @Autowired constructor( val options = refs.map { BuildFormValue(it, it) } - val searchUrl = "/ms/process/api/user/scm/$projectId/${formProperty.repoHashId}/refs?search={words}" + val searchUrl = "/process/api/user/scm/$projectId/${formProperty.repoHashId}/refs?search={words}" val replaceKey = "{words}" return copyFormProperty( property = formProperty, @@ -137,18 +139,26 @@ class ParamFacadeService @Autowired constructor( projectId: String, codelibFormProperty: BuildFormProperty ): BuildFormProperty { - val codeAliasName = codeService.listRepository(projectId, codelibFormProperty.scmType!!) - val aliasNames = if ((!userId.isNullOrBlank()) && codeAliasName.isNotEmpty()) { + val aliasNames = if ((!userId.isNullOrBlank())) { // 检查代码库的权限, 只返回用户有权限代码库 - val hasPermissionCodelibs = getPermissionCodelibList(userId!!, projectId) + val hasPermissionCodelibs = getPermissionCodelibList(userId, projectId, codelibFormProperty.scmType!!) logger.info("[$userId|$projectId] Get the permission code lib list ($hasPermissionCodelibs)") - codeAliasName.filter { hasPermissionCodelibs.contains(it.repositoryHashId) } - .map { BuildFormValue(it.aliasName, it.aliasName) } + hasPermissionCodelibs.map { BuildFormValue(it.aliasName, it.aliasName) } } else { + val codeAliasName = codeService.listRepository(projectId, codelibFormProperty.scmType!!) codeAliasName.map { BuildFormValue(it.aliasName, it.aliasName) } } - return copyFormProperty(codelibFormProperty, aliasNames) + val searchUrl = "/process/api/user/buildParam/repository/$projectId/aliasName?" + + "repositoryType=${codelibFormProperty.scmType!!}&permission=${Permission.LIST.name}" + + "&aliasName={words}&page=1&pageSize=100" + val replaceKey = "{words}" + return copyFormProperty( + property = codelibFormProperty, + options = aliasNames, + searchUrl = searchUrl, + replaceKey = replaceKey + ) } private fun addContainerTypeProperties( @@ -163,7 +173,7 @@ class ParamFacadeService @Autowired constructor( } val containerType = property.containerType!! val containers = client.get(ServiceContainerResource::class) - .getContainers(userId!!, projectId, containerType.buildType, containerType.os) + .getContainers(userId, projectId, containerType.buildType, containerType.os) if (containers.data == null || containers.data!!.resources == null) { logger.warn("[$userId|$projectId|$property] Fail to get the container properties") return property @@ -261,27 +271,24 @@ class ParamFacadeService @Autowired constructor( ) } - private fun getPermissionCodelibList(userId: String, projectId: String): List { - val watcher = Watcher("getPermissionCodelibList_${userId}_$projectId") - val hashIdList = mutableListOf() - try { + private fun getPermissionCodelibList(userId: String, projectId: String, scmType: ScmType?): List { + val watcher = Watcher("getPermissionCodelibList_${userId}_${projectId}_${scmType?.name}") + return try { client.get(ServiceRepositoryResource::class).hasPermissionList( userId = userId, projectId = projectId, permission = Permission.LIST, - repositoryType = null - ).data?.records?.forEach { repo -> - if (!repo.repositoryHashId.isNullOrBlank()) { - hashIdList.add(repo.repositoryHashId.toString()) - } - } + repositoryType = scmType?.name, + page = 1, + pageSize = 100 + ).data?.records ?: emptyList() } catch (e: RuntimeException) { logger.warn("[$userId|$projectId] Fail to get the permission code lib list", e) + emptyList() } finally { watcher.stop() LogUtils.printCostTimeWE(watcher, errorThreshold = 4000) } - return hashIdList } private fun getHasPermissionPipelineList(userId: String?, projectId: String): List { diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceGithubResource.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceGithubResource.kt index 20b795f38ef..771fded56a9 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceGithubResource.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceGithubResource.kt @@ -157,4 +157,28 @@ interface ServiceGithubResource { @QueryParam("tag") tag: String ): Result + + @ApiOperation("List all the branches of github") + @GET + @Path("/branches") + fun listBranches( + @ApiParam("accessToken", required = true) + @QueryParam("accessToken") + accessToken: String, + @ApiParam("projectName", required = true) + @QueryParam("projectName") + projectName: String + ): Result> + + @ApiOperation("List all the branches of github") + @GET + @Path("/tags") + fun listTags( + @ApiParam("accessToken", required = true) + @QueryParam("accessToken") + accessToken: String, + @ApiParam("projectName", required = true) + @QueryParam("projectName") + projectName: String + ): Result> } diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryResource.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryResource.kt index e98ec3f589d..eb73696cbe5 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryResource.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryResource.kt @@ -121,6 +121,7 @@ interface ServiceRepositoryResource { @ApiOperation("代码库列表") @GET @Path("/{projectId}/hasPermissionList") + @SuppressWarnings("LongParameterList") fun hasPermissionList( @ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE) @HeaderParam(AUTH_HEADER_USER_ID) @@ -130,10 +131,19 @@ interface ServiceRepositoryResource { projectId: String, @ApiParam("仓库类型", required = false) @QueryParam("repositoryType") - repositoryType: ScmType?, + repositoryType: String?, @ApiParam("对应权限", required = true, defaultValue = "") @QueryParam("permission") - permission: Permission + permission: Permission, + @ApiParam("第几页", required = false, defaultValue = "1") + @QueryParam("page") + page: Int? = null, + @ApiParam("每页多少条", required = false, defaultValue = "20") + @QueryParam("pageSize") + pageSize: Int? = null, + @ApiParam("别名", required = false) + @QueryParam("aliasName") + aliasName: String? = null ): Result> @ApiOperation("获取项目代码库列表") diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/UserRepositoryResource.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/UserRepositoryResource.kt index 13b6c768693..7825fd44e5a 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/UserRepositoryResource.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/UserRepositoryResource.kt @@ -198,7 +198,7 @@ interface UserRepositoryResource { projectId: String, @ApiParam("仓库类型", required = false) @QueryParam("repositoryType") - repositoryType: ScmType?, + repositoryType: String?, @ApiParam("对应权限", required = true, defaultValue = "") @QueryParam("permission") permission: Permission, @@ -207,7 +207,10 @@ interface UserRepositoryResource { page: Int?, @ApiParam("每页多少条", required = false, defaultValue = "20") @QueryParam("pageSize") - pageSize: Int? + pageSize: Int?, + @ApiParam("别名", required = false) + @QueryParam("aliasName") + aliasName: String? = null ): Result> @ApiOperation("删除代码库") diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/github/GithubBranch.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/github/GithubBranch.kt index f6c0f475228..1839bbcc62a 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/github/GithubBranch.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/github/GithubBranch.kt @@ -81,7 +81,7 @@ data class GithubCommit( val sha: String, @ApiModelProperty("节点id", name = "node_id") @JsonProperty("node_id") - val nodeId: String, + val nodeId: String?, @ApiModelProperty("提交内容") val commit: GithubCommitData? ) diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/github/GithubRepoBranch.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/github/GithubRepoBranch.kt new file mode 100644 index 00000000000..8edc7258764 --- /dev/null +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/github/GithubRepoBranch.kt @@ -0,0 +1,54 @@ +/* + * 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.repository.pojo.github + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty + +/** + * github获取分支列表:/repos/{owner}/{repo}/branches + { + "name": "release-1.2", + "commit": { + "sha": "7dcca23c12383c18d4b1710c42fe97adb44c7c8b", + "url": "https://api.github.com/repos/Tencent/bk-ci/commits/7dcca23c12383c18d4b1710c42fe97adb44c7c8b" + }, + "protected": true + } + */ +@JsonIgnoreProperties(ignoreUnknown = true) +@ApiModel("仓库分支信息") +data class GithubRepoBranch( + @ApiModelProperty("名称") + val name: String, + @ApiModelProperty("提交信息") + val commit: GithubRepoCommit, + @ApiModelProperty("是否是保护分支") + val protected: Boolean +) diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/github/GithubRepoCommit.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/github/GithubRepoCommit.kt new file mode 100644 index 00000000000..0866af9181f --- /dev/null +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/github/GithubRepoCommit.kt @@ -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.repository.pojo.github + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties + +@JsonIgnoreProperties(ignoreUnknown = true) +data class GithubRepoCommit( + val sha: String, + val url: String +) diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/github/GithubRepoTag.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/github/GithubRepoTag.kt new file mode 100644 index 00000000000..431305b5189 --- /dev/null +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/github/GithubRepoTag.kt @@ -0,0 +1,60 @@ +/* + * 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.repository.pojo.github + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonProperty +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty + +/** + * github获取tag列表接口: /repos/{owner}/{repo}/tags + * { + "name": "v1.7.22-RC.2", + "zipball_url": "https://api.github.com/repos/Tencent/bk-ci/zipball/refs/tags/v1.7.22-RC.2", + "tarball_url": "https://api.github.com/repos/Tencent/bk-ci/tarball/refs/tags/v1.7.22-RC.2", + "commit": { + "sha": "c4a9464c710eae94c1538ede27e538c61643fe65", + "url": "https://api.github.com/repos/Tencent/bk-ci/commits/c4a9464c710eae94c1538ede27e538c61643fe65" + }, + "node_id": "MDM6UmVmMTg5MTUzNDkxOnJlZnMvdGFncy92MS43LjIyLVJDLjI=" + } + */ +@JsonIgnoreProperties(ignoreUnknown = true) +@ApiModel("仓库tag信息") +data class GithubRepoTag( + @ApiModelProperty("名称") + val name: String, + @JsonProperty("zipball_url") + val zipballUrl: String, + @JsonProperty("tarball_url") + val tarballUrl: String, + val commit: GithubRepoCommit, + @JsonProperty("node_id") + val nodeId: String +) diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryDao.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryDao.kt index 21cce6cbb12..15892d4ed02 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryDao.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryDao.kt @@ -92,7 +92,7 @@ class RepositoryDao { fun countByProject( dslContext: DSLContext, projectIds: Collection, - repositoryType: ScmType?, + repositoryTypes: List?, aliasName: String?, repositoryIds: Set? ): Long { @@ -107,12 +107,12 @@ class RepositoryDao { if (!aliasName.isNullOrBlank()) { step.and(ALIAS_NAME.like("%$aliasName%")) } - return when (repositoryType) { + return when (repositoryTypes) { null -> { step.fetchOne(0, Long::class.java)!! } else -> { - step.and(TYPE.eq(repositoryType.name)) + step.and(TYPE.`in`(repositoryTypes)) step.fetchOne(0, Long::class.java)!! } } @@ -214,7 +214,7 @@ class RepositoryDao { fun listByProject( dslContext: DSLContext, projectId: String, - repositoryType: ScmType?, + repositoryTypes: List?, aliasName: String?, repositoryIds: Set?, offset: Int, @@ -232,11 +232,11 @@ class RepositoryDao { step.and(ALIAS_NAME.like("%$aliasName%")) } - when (repositoryType) { + when (repositoryTypes) { null -> { } else -> { - step.and(TYPE.eq(repositoryType.name)) + step.and(TYPE.`in`(repositoryTypes)) } } diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceGithubResourceImpl.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceGithubResourceImpl.kt index 351c19ee006..2117005b439 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceGithubResourceImpl.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceGithubResourceImpl.kt @@ -94,4 +94,12 @@ class ServiceGithubResourceImpl @Autowired constructor( override fun getGithubTag(accessToken: String, projectName: String, tag: String): Result { return Result(githubService.getTag(accessToken, projectName, tag)) } + + override fun listBranches(accessToken: String, projectName: String): Result> { + return Result(githubService.listBranches(accessToken, projectName)) + } + + override fun listTags(accessToken: String, projectName: String): Result> { + return Result(githubService.listTags(accessToken, projectName)) + } } diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceRepositoryResourceImpl.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceRepositoryResourceImpl.kt index a6e9aef4eb0..cabd220b1fd 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceRepositoryResourceImpl.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceRepositoryResourceImpl.kt @@ -106,8 +106,11 @@ class ServiceRepositoryResourceImpl @Autowired constructor( override fun hasPermissionList( userId: String, projectId: String, - repositoryType: ScmType?, - permission: Permission + repositoryType: String?, + permission: Permission, + page: Int?, + pageSize: Int?, + aliasName: String? ): Result> { if (userId.isBlank()) { throw ParamBlankException("Invalid userId") @@ -122,16 +125,19 @@ class ServiceRepositoryResourceImpl @Autowired constructor( Permission.EDIT -> AuthPermission.EDIT Permission.USE -> AuthPermission.USE } - val limit = PageUtil.convertPageSizeToSQLLimit(0, 9999) + val pageNotNull = page ?: 0 + val pageSizeNotNull = pageSize ?: 9999 + val limit = PageUtil.convertPageSizeToSQLLimit(pageNotNull, pageSizeNotNull) val result = repositoryService.hasPermissionList( userId = userId, projectId = projectId, repositoryType = repositoryType, authPermission = bkAuthPermission, offset = limit.offset, - limit = limit.limit + limit = limit.limit, + aliasName = aliasName ) - return Result(Page(0, 9999, result.count, result.records)) + return Result(Page(pageNotNull, pageSizeNotNull, result.count, result.records)) } override fun listByProjects(projectIds: Set, page: Int?, pageSize: Int?): Result> { diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryResourceImpl.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryResourceImpl.kt index 99a4bd93995..51a77657f3e 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryResourceImpl.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryResourceImpl.kt @@ -165,10 +165,11 @@ class UserRepositoryResourceImpl @Autowired constructor( override fun hasPermissionList( userId: String, projectId: String, - repositoryType: ScmType?, + repositoryType: String?, permission: Permission, page: Int?, - pageSize: Int? + pageSize: Int?, + aliasName: String? ): Result> { if (userId.isBlank()) { throw ParamBlankException("Invalid userId") @@ -188,12 +189,13 @@ class UserRepositoryResourceImpl @Autowired constructor( val pageSizeNotNull = pageSize ?: PageSize val limit = PageUtil.convertPageSizeToSQLLimit(pageNotNull, pageSizeNotNull) val result = repositoryService.hasPermissionList( - userId, - projectId, - repositoryType, - bkAuthPermission, - limit.offset, - limit.limit + userId = userId, + projectId = projectId, + repositoryType = repositoryType, + authPermission = bkAuthPermission, + offset = limit.offset, + limit = limit.limit, + aliasName = aliasName ) return Result(Page(pageNotNull, pageSizeNotNull, result.count, result.records)) } diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepositoryService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepositoryService.kt index 1ad3c64b239..e3ad5a98857 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepositoryService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepositoryService.kt @@ -973,14 +973,14 @@ class RepositoryService @Autowired constructor( repositoryDao.countByProject( dslContext = dslContext, projectIds = setOf(projectId), - repositoryType = repositoryType, + repositoryTypes = repositoryType?.let { listOf(it) }, aliasName = aliasName, repositoryIds = hasListPermissionRepoList.toSet() ) val repositoryRecordList = repositoryDao.listByProject( dslContext = dslContext, projectId = projectId, - repositoryType = repositoryType, + repositoryTypes = repositoryType?.let { listOf(it) }, aliasName = aliasName, repositoryIds = hasListPermissionRepoList.toSet(), offset = offset, @@ -1060,26 +1060,28 @@ class RepositoryService @Autowired constructor( fun hasPermissionList( userId: String, projectId: String, - repositoryType: ScmType?, + repositoryType: String?, authPermission: AuthPermission, offset: Int, - limit: Int + limit: Int, + aliasName: String? = null ): SQLPage { val hasPermissionList = repositoryPermissionService.filterRepository(userId, projectId, authPermission) + val repositoryTypes = repositoryType?.split(",")?.map { ScmType.valueOf(it) } val count = repositoryDao.countByProject( dslContext = dslContext, projectIds = setOf(projectId), - repositoryType = repositoryType, - aliasName = null, + repositoryTypes = repositoryTypes, + aliasName = aliasName, repositoryIds = hasPermissionList.toSet() ) val repositoryRecordList = repositoryDao.listByProject( dslContext = dslContext, projectId = projectId, - repositoryType = repositoryType, - aliasName = null, + repositoryTypes = repositoryTypes, + aliasName = aliasName, repositoryIds = hasPermissionList.toSet(), offset = offset, limit = limit @@ -1107,7 +1109,7 @@ class RepositoryService @Autowired constructor( val count = repositoryDao.countByProject( dslContext = dslContext, projectIds = projectIds, - repositoryType = repositoryType, + repositoryTypes = repositoryType?.let { listOf(it) }, aliasName = null, repositoryIds = null ) @@ -1143,7 +1145,7 @@ class RepositoryService @Autowired constructor( val count = repositoryDao.countByProject( dslContext = dslContext, projectIds = arrayListOf(projectId), - repositoryType = null, + repositoryTypes = null, aliasName = aliasName, repositoryIds = null ) @@ -1152,7 +1154,7 @@ class RepositoryService @Autowired constructor( dslContext = dslContext, projectId = projectId, aliasName = aliasName, - repositoryType = null, + repositoryTypes = null, repositoryIds = null, offset = offset, limit = limit diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/GithubService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/GithubService.kt index 8ae2bdead1d..5b88c85cec6 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/GithubService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/GithubService.kt @@ -46,6 +46,8 @@ import com.tencent.devops.repository.pojo.GithubCheckRuns import com.tencent.devops.repository.pojo.GithubCheckRunsResponse import com.tencent.devops.repository.pojo.github.GithubBranch import com.tencent.devops.repository.pojo.github.GithubRepo +import com.tencent.devops.repository.pojo.github.GithubRepoBranch +import com.tencent.devops.repository.pojo.github.GithubRepoTag import com.tencent.devops.repository.pojo.github.GithubTag import com.tencent.devops.scm.config.GitConfig import com.tencent.devops.scm.exception.GithubApiException @@ -55,7 +57,6 @@ import okhttp3.Request import okhttp3.RequestBody import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass import org.springframework.stereotype.Service import java.time.ZoneId import java.time.ZonedDateTime @@ -65,7 +66,6 @@ import javax.ws.rs.core.Response @Service @Suppress("ALL") -@ConditionalOnMissingClass class GithubService @Autowired constructor( private val githubTokenService: GithubTokenService, private val githubOAuthService: GithubOAuthService, @@ -231,6 +231,40 @@ class GithubService @Autowired constructor( } } + override fun listBranches(token: String, projectName: String): List { + logger.info("listBranches| $projectName") + return RetryUtils.execute(object : RetryUtils.Action> { + override fun fail(e: Throwable): List { + logger.error("listBranches fail| e=${e.message}", e) + throw e + } + + override fun execute(): List { + val path = "repos/$projectName/branches?page=1&per_page=100" + val request = buildGet(token, path) + val body = getBody(OPERATION_LIST_BRANCHS, request) + return objectMapper.readValue>(body).map { it.name } + } + }, 3, SLEEP_MILLS_FOR_RETRY_500) + } + + override fun listTags(token: String, projectName: String): List { + logger.info("listTags| $projectName") + return RetryUtils.execute(object : RetryUtils.Action> { + override fun fail(e: Throwable): List { + logger.error("listTags fail| e=${e.message}", e) + throw e + } + + override fun execute(): List { + val path = "repos/$projectName/tags?page=1&per_page=100" + val request = buildGet(token, path) + val body = getBody(OPERATION_LIST_TAGS, request) + return objectMapper.readValue>(body).map { it.name } + } + }, 3, SLEEP_MILLS_FOR_RETRY_500) + } + private fun buildPost(token: String, path: String, body: String): Request { return request(token, path) .post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), body)) @@ -306,5 +340,7 @@ class GithubService @Autowired constructor( private const val OPERATION_GET_REPOS = "获取仓库列表" private const val OPERATION_GET_BRANCH = "获取指定分支" private const val OPERATION_GET_TAG = "获取指定Tag" + private const val OPERATION_LIST_BRANCHS = "获取分支列表" + private const val OPERATION_LIST_TAGS = "获取Tag列表" } } diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/IGithubService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/IGithubService.kt index a20bfa35a3c..20a3aa26619 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/IGithubService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/github/IGithubService.kt @@ -57,4 +57,8 @@ interface IGithubService { fun getTag(token: String, projectName: String, tag: String): GithubTag? fun getFileContent(projectName: String, ref: String, filePath: String): String + + fun listBranches(token: String, projectName: String): List + + fun listTags(token: String, projectName: String): List } diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/scm/GitOauthService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/scm/GitOauthService.kt index 130dfd98589..8cadc4dea7a 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/scm/GitOauthService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/scm/GitOauthService.kt @@ -79,7 +79,7 @@ class GitOauthService @Autowired constructor( val logger = LoggerFactory.getLogger(GitOauthService::class.java) } - override fun getProject(userId: String, projectId: String, repoHashId: String?): AuthorizeResult { + override fun getProject(userId: String, projectId: String, repoHashId: String?, search: String?): AuthorizeResult { logger.info("start to get project: userId:$userId") // 1. 获取accessToken,没有就返回403 val authParams = mapOf( @@ -91,7 +91,15 @@ class GitOauthService @Autowired constructor( val accessToken = getAccessToken(userId) ?: return AuthorizeResult(403, getAuthUrl(authParams)) val authResult = AuthorizeResult(200, "") return try { - authResult.project.addAll(gitService.getProject(accessToken = accessToken.accessToken, userId = userId)) + authResult.project.addAll( + gitService.getProjectList( + accessToken = accessToken.accessToken, + userId = userId, + page = 1, + pageSize = 100, + search = search + ) + ) authResult } catch (e: Exception) { logger.info("get oauth project fail: ${e.message}") diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/scm/GitService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/scm/GitService.kt index 919e7b5241e..633541dd4b9 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/scm/GitService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/scm/GitService.kt @@ -161,7 +161,7 @@ class GitService @Autowired constructor( name = obj["name"].asString, nameWithNameSpace = obj["name_with_namespace"].asString, sshUrl = obj["ssh_url_to_repo"].asString, - httpUrl = obj["http_url_to_repo"].asString, + httpUrl = obj["https_url_to_repo"].asString, lastActivity = DateTimeUtil.convertLocalDateTimeToTimestamp( LocalDateTime.parse( lastActivityTime @@ -224,7 +224,7 @@ class GitService @Autowired constructor( name = project["name"].asString, nameWithNameSpace = project["name_with_namespace"].asString, sshUrl = project["ssh_url_to_repo"].asString, - httpUrl = project["http_url_to_repo"].asString, + httpUrl = project["https_url_to_repo"].asString, lastActivity = DateTimeUtil.convertLocalDateTimeToTimestamp( LocalDateTime.parse(lastActivityTime)) * 1000L )) diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/scm/IGitOauthService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/scm/IGitOauthService.kt index 90f0b5e5f87..a5767459e2a 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/scm/IGitOauthService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/scm/IGitOauthService.kt @@ -37,7 +37,7 @@ import com.tencent.devops.scm.pojo.Project @Suppress("ALL") interface IGitOauthService { - fun getProject(userId: String, projectId: String, repoHashId: String?): AuthorizeResult + fun getProject(userId: String, projectId: String, repoHashId: String?, search: String? = null): AuthorizeResult fun getProjectList(userId: String, page: Int?, pageSize: Int?): List fun getBranch(userId: String, repository: String, page: Int?, pageSize: Int?): List fun getTag(userId: String, repository: String, page: Int?, pageSize: Int?): List