Skip to content

Commit

Permalink
Merge pull request TencentBlueKing#10078 from yjieliang/feat-9996
Browse files Browse the repository at this point in the history
feat:插件代码库自动开启 stream ci 时,项目归属信息优化 TencentBlueKing#9996
  • Loading branch information
bkci-bot authored Mar 14, 2024
2 parents eb38d96 + a4da185 commit 768f8be
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import com.tencent.devops.project.pojo.enums.ProjectAuthSecrecyStatus
import com.tencent.devops.project.pojo.enums.ProjectChannelCode
import com.tencent.devops.project.pojo.user.UserDeptDetail
import com.tencent.devops.project.util.ProjectUtils
import java.net.URLDecoder
import java.time.LocalDateTime
import org.jooq.Condition
import org.jooq.DSLContext
import org.jooq.Record
Expand All @@ -55,8 +57,6 @@ import org.jooq.Record3
import org.jooq.Result
import org.jooq.impl.DSL
import org.springframework.stereotype.Repository
import java.net.URLDecoder
import java.time.LocalDateTime

@Suppress("ALL")
@Repository
Expand Down Expand Up @@ -963,6 +963,19 @@ class ProjectDao {
}
}

fun batchUpdateProductId(
dslContext: DSLContext,
englishNames: List<String>,
productId: Int
) {
with(TProject.T_PROJECT) {
dslContext.update(this)
.set(PRODUCT_ID, productId)
.where(ENGLISH_NAME.`in`(englishNames))
.execute()
}
}

fun updateOrganizationByEnglishName(
dslContext: DSLContext,
englishName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ import com.tencent.devops.project.service.ProjectService
import com.tencent.devops.project.service.ShardingRoutingRuleAssignService
import com.tencent.devops.project.util.ProjectUtils
import com.tencent.devops.project.util.exception.ProjectNotExistException
import java.io.File
import java.io.InputStream
import java.util.regex.Pattern
import javax.ws.rs.NotFoundException
import org.glassfish.jersey.media.multipart.FormDataContentDisposition
import org.jooq.DSLContext
import org.jooq.impl.DSL
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.dao.DuplicateKeyException
import java.io.File
import java.io.InputStream
import java.util.regex.Pattern
import javax.ws.rs.NotFoundException

@Suppress("ALL")
abstract class AbsProjectServiceImpl @Autowired constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ import com.tencent.devops.repository.pojo.RepositoryId
import com.tencent.devops.repository.pojo.RepositoryInfo
import com.tencent.devops.repository.pojo.RepositoryInfoWithPermission
import com.tencent.devops.repository.pojo.enums.Permission
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.DELETE
import javax.ws.rs.GET
Expand Down Expand Up @@ -244,4 +244,15 @@ interface ServiceRepositoryResource {
@Parameter(description = "插件代码库关联关系")
atomRefRepositoryInfo: List<AtomRefRepositoryInfo>
): Result<Boolean>

@Operation(summary = "根据代码库哈希ID查询GIT项目ID")
@POST
@Path("/git/project/retrieve")
fun getGitProjectIdByRepositoryHashId(
@Parameter(description = "用户ID", required = true)
@HeaderParam(AUTH_HEADER_USER_ID)
userId: String,
@Parameter(description = "代码库哈希ID列表", required = true)
repositoryHashIdList: List<String>
): Result<List<String>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@ import com.tencent.devops.common.api.enums.ScmType
import com.tencent.devops.common.api.util.HashUtil
import com.tencent.devops.common.web.utils.I18nUtil
import com.tencent.devops.model.repository.tables.TRepository
import com.tencent.devops.model.repository.tables.TRepositoryCodeGit
import com.tencent.devops.model.repository.tables.records.TRepositoryRecord
import com.tencent.devops.repository.constant.RepositoryMessageCode.GIT_NOT_FOUND
import com.tencent.devops.repository.pojo.enums.RepositorySortEnum
import com.tencent.devops.repository.pojo.enums.RepositorySortTypeEnum
import java.time.LocalDateTime
import javax.ws.rs.NotFoundException
import org.jooq.Condition
import org.jooq.DSLContext
import org.jooq.Record1
import org.jooq.Result
import org.jooq.impl.DSL
import org.springframework.stereotype.Repository
import java.time.LocalDateTime
import javax.ws.rs.NotFoundException

@Repository
@Suppress("ALL")
Expand Down Expand Up @@ -450,4 +451,18 @@ class RepositoryDao {
.execute()
}
}

fun getGitProjectIdByRepositoryHashId(
dslContext: DSLContext,
repositoryHashIdList: List<String>
): List<String> {
val tRepository = TRepository.T_REPOSITORY
with(TRepositoryCodeGit.T_REPOSITORY_CODE_GIT) {
return dslContext.select(GIT_PROJECT_ID)
.from(this)
.join(tRepository).on(REPOSITORY_ID.eq(tRepository.REPOSITORY_ID))
.where(tRepository.REPOSITORY_HASH_ID.`in`(repositoryHashIdList))
.fetchInto(String::class.java)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ import com.tencent.devops.repository.pojo.RepositoryInfoWithPermission
import com.tencent.devops.repository.pojo.enums.Permission
import com.tencent.devops.repository.service.RepoPipelineService
import com.tencent.devops.repository.service.RepositoryService
import org.springframework.beans.factory.annotation.Autowired
import java.net.URLDecoder
import org.springframework.beans.factory.annotation.Autowired

@RestResource
@Suppress("ALL")
Expand Down Expand Up @@ -230,4 +230,11 @@ class ServiceRepositoryResourceImpl @Autowired constructor(
)
return Result(true)
}

override fun getGitProjectIdByRepositoryHashId(
userId: String,
repositoryHashIdList: List<String>
): Result<List<String>> {
return Result(repositoryService.getGitProjectIdByRepositoryHashId(userId, repositoryHashIdList))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,10 @@ class RepositoryService @Autowired constructor(
}
}

fun getGitProjectIdByRepositoryHashId(userId: String, repositoryHashIdList: List<String>): List<String> {
return repositoryDao.getGitProjectIdByRepositoryHashId(dslContext, repositoryHashIdList)
}

companion object {
private val logger = LoggerFactory.getLogger(RepositoryService::class.java)
const val MAX_ALIAS_LENGTH = 255
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import com.tencent.devops.store.pojo.atom.AtomVersion
import com.tencent.devops.store.pojo.atom.GetRelyAtom
import com.tencent.devops.store.pojo.atom.InstallAtomReq
import com.tencent.devops.store.pojo.atom.enums.AtomStatusEnum
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
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ import com.tencent.devops.store.pojo.common.KEY_UPDATE_TIME
import com.tencent.devops.store.pojo.common.enums.StoreProjectTypeEnum
import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum
import com.tencent.devops.store.utils.VersionUtils
import java.net.URLDecoder
import java.time.LocalDateTime
import org.jooq.Condition
import org.jooq.DSLContext
import org.jooq.Field
Expand All @@ -98,8 +100,6 @@ import org.jooq.Result
import org.jooq.SelectOnConditionStep
import org.jooq.impl.DSL
import org.springframework.stereotype.Repository
import java.net.URLDecoder
import java.time.LocalDateTime

@Suppress("ALL")
@Repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class StreamGitConfig {
@Value("\${git.gitUrl:#{null}}")
val gitUrl: String? = null

@Value("\${git.defaultAtomProjectGroupName:#{null}}")
val defaultAtomProjectGroupName: String? = null

/* github config */
@Value("\${github.signSecret:}")
val signSecret: String = ""
Expand Down

0 comments on commit 768f8be

Please sign in to comment.