Skip to content

Commit

Permalink
feat:希望流水线变量支持tgit的分支 TencentBlueKing#3660
Browse files Browse the repository at this point in the history
  • Loading branch information
mingshewhe committed May 7, 2022
1 parent 798ff62 commit a139dc3
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -133,7 +134,13 @@ interface ServiceRepositoryResource {
repositoryType: ScmType?,
@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,
): Result<Page<RepositoryInfo>>

@ApiOperation("获取项目代码库列表")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -207,7 +207,10 @@ interface UserRepositoryResource {
page: Int?,
@ApiParam("每页多少条", required = false, defaultValue = "20")
@QueryParam("pageSize")
pageSize: Int?
pageSize: Int?,
@ApiParam("别名", required = false)
@QueryParam("pageSize")
aliasName: String? = null
): Result<Page<RepositoryInfo>>

@ApiOperation("删除代码库")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class RepositoryDao {
fun countByProject(
dslContext: DSLContext,
projectIds: Collection<String>,
repositoryType: ScmType?,
repositoryTypes: List<ScmType>?,
aliasName: String?,
repositoryIds: Set<Long>?
): Long {
Expand All @@ -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)!!
}
}
Expand Down Expand Up @@ -214,7 +214,7 @@ class RepositoryDao {
fun listByProject(
dslContext: DSLContext,
projectId: String,
repositoryType: ScmType?,
repositoryTypes: List<ScmType>?,
aliasName: String?,
repositoryIds: Set<Long>?,
offset: Int,
Expand All @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ class ServiceRepositoryResourceImpl @Autowired constructor(
userId: String,
projectId: String,
repositoryType: ScmType?,
permission: Permission
permission: Permission,
page: Int?,
pageSize: Int?,
): Result<Page<RepositoryInfo>> {
if (userId.isBlank()) {
throw ParamBlankException("Invalid userId")
Expand All @@ -122,16 +124,18 @@ 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,
repositoryType = repositoryType?.name,
authPermission = bkAuthPermission,
offset = limit.offset,
limit = limit.limit
)
return Result(Page(0, 9999, result.count, result.records))
return Result(Page(pageNotNull, pageSizeNotNull, result.count, result.records))
}

override fun listByProjects(projectIds: Set<String>, page: Int?, pageSize: Int?): Result<Page<RepositoryInfo>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Page<RepositoryInfo>> {
if (userId.isBlank()) {
throw ParamBlankException("Invalid userId")
Expand All @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<RepositoryInfo> {
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
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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
)
Expand All @@ -1152,7 +1154,7 @@ class RepositoryService @Autowired constructor(
dslContext = dslContext,
projectId = projectId,
aliasName = aliasName,
repositoryType = null,
repositoryTypes = null,
repositoryIds = null,
offset = offset,
limit = limit
Expand Down

0 comments on commit a139dc3

Please sign in to comment.