Skip to content

Commit

Permalink
feat:流水线插件代码库开启默认分支保护 TencentBlueKing#9814
Browse files Browse the repository at this point in the history
  • Loading branch information
yjieliang committed Jan 18, 2024
1 parent 4f451b6 commit 01bc229
Showing 1 changed file with 29 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.tencent.devops.common.api.util.JsonUtil
import com.tencent.devops.common.api.util.OkhttpUtils
import com.tencent.devops.common.api.util.OkhttpUtils.stringLimit
import com.tencent.devops.common.api.util.script.CommonScriptUtils
import com.tencent.devops.common.redis.RedisOperation
import com.tencent.devops.common.service.prometheus.BkTimed
import com.tencent.devops.common.service.utils.RetryUtils
import com.tencent.devops.common.web.utils.I18nUtil
Expand Down Expand Up @@ -203,16 +204,16 @@ class GitService @Autowired constructor(
val pageNotNull = page ?: 1
val pageSizeNotNull = pageSize ?: 20
val url = "${gitConfig.gitApiUrl}/projects" +
"?access_token=$accessToken&page=$pageNotNull&per_page=$pageSizeNotNull"
.addParams(
mapOf(
"search" to search,
"order_by" to orderBy?.value,
"sort" to sort?.value,
"owned" to owned,
"min_access_level" to minAccessLevel?.level
"?access_token=$accessToken&page=$pageNotNull&per_page=$pageSizeNotNull"
.addParams(
mapOf(
"search" to search,
"order_by" to orderBy?.value,
"sort" to sort?.value,
"owned" to owned,
"min_access_level" to minAccessLevel?.level
)
)
)
val res = mutableListOf<Project>()
val request = Request.Builder()
.url(url)
Expand Down Expand Up @@ -257,12 +258,12 @@ class GitService @Autowired constructor(
val pageSizeNotNull = pageSize ?: 20
val repoId = URLEncoder.encode(repository, "utf-8")
val url = "${gitConfig.gitApiUrl}/projects/$repoId/repository/branches" +
"?access_token=$accessToken&page=$pageNotNull&per_page=$pageSizeNotNull" +
if (search != null) {
"&search=$search"
} else {
""
}
"?access_token=$accessToken&page=$pageNotNull&per_page=$pageSizeNotNull" +
if (search != null) {
"&search=$search"
} else {
""
}
val res = mutableListOf<GitBranch>()
val request = Request.Builder()
.url(url)
Expand Down Expand Up @@ -320,7 +321,7 @@ class GitService @Autowired constructor(
logger.info("start to get the $userId's $repository tag by page: $pageNotNull pageSize: $pageSizeNotNull")
val repoId = URLEncoder.encode(repository, "utf-8")
val url = "${gitConfig.gitApiUrl}/projects/$repoId/repository/tags" +
"?access_token=$accessToken&page=$pageNotNull&per_page=$pageSizeNotNull"
"?access_token=$accessToken&page=$pageNotNull&per_page=$pageSizeNotNull"
val res = mutableListOf<GitTag>()
val request = Request.Builder()
.url(url)
Expand Down Expand Up @@ -375,11 +376,11 @@ class GitService @Autowired constructor(
val startEpoch = System.currentTimeMillis()
try {
val url = "${gitConfig.gitUrl}/oauth/token" +
"?client_id=${gitConfig.clientId}" +
"&client_secret=${gitConfig.clientSecret}" +
"&grant_type=refresh_token" +
"&refresh_token=${accessToken.refreshToken}" +
"&redirect_uri=${gitConfig.gitHookUrl}"
"?client_id=${gitConfig.clientId}" +
"&client_secret=${gitConfig.clientSecret}" +
"&grant_type=refresh_token" +
"&refresh_token=${accessToken.refreshToken}" +
"&redirect_uri=${gitConfig.gitHookUrl}"
val request = Request.Builder()
.url(url)
.post(RequestBody.create("application/x-www-form-urlencoded;charset=utf-8".toMediaTypeOrNull(), ""))
Expand All @@ -396,7 +397,7 @@ class GitService @Autowired constructor(
@BkTimed(extraTags = ["operation", "AUTHORIZE"], value = "bk_tgit_api_time")
override fun getAuthUrl(authParamJsonStr: String): String {
return "${gitConfig.gitUrl}/oauth/authorize?client_id=${gitConfig.clientId}" +
"&redirect_uri=${gitConfig.callbackUrl}&response_type=code&state=$authParamJsonStr"
"&redirect_uri=${gitConfig.callbackUrl}&response_type=code&state=$authParamJsonStr"
}

@BkTimed(extraTags = ["operation", "TOKEN"], value = "bk_tgit_api_time")
Expand All @@ -406,8 +407,8 @@ class GitService @Autowired constructor(
try {
val tokenUrl =
"${gitConfig.gitUrl}/oauth/token?client_id=${gitConfig.clientId}" +
"&client_secret=${gitConfig.clientSecret}&code=$code" +
"&grant_type=authorization_code&redirect_uri=${gitConfig.redirectUrl}"
"&client_secret=${gitConfig.clientSecret}&code=$code" +
"&grant_type=authorization_code&redirect_uri=${gitConfig.redirectUrl}"
logger.info("getToken url>> $tokenUrl")
val request = Request.Builder()
.url(tokenUrl)
Expand Down Expand Up @@ -492,7 +493,7 @@ class GitService @Autowired constructor(
try {
val url =
"$apiUrl/projects/${URLEncoder.encode(repoName, "UTF-8")}/repository/blobs/" +
"${URLEncoder.encode(ref, "UTF-8")}?filepath=${URLEncoder.encode(filePath, "UTF-8")}"
"${URLEncoder.encode(ref, "UTF-8")}?filepath=${URLEncoder.encode(filePath, "UTF-8")}"
var realUrl = url
val request = if (authType == RepoAuthType.OAUTH) {
realUrl += "&access_token=$token"
Expand Down Expand Up @@ -1081,7 +1082,7 @@ class GitService @Autowired constructor(
): GitMrInfo {
val url = StringBuilder(
"${getApiUrl(repoUrl)}/projects/${URLEncoder.encode(repoName, "UTF-8")}" +
"/merge_request/$mrId"
"/merge_request/$mrId"
)
logger.info("get mr info url: $url")
setToken(tokenType, url, token)
Expand Down Expand Up @@ -1576,7 +1577,7 @@ class GitService @Autowired constructor(
} else {
""
} +
"&page=$newPage" + "&per_page=$newPageSize"
"&page=$newPage" + "&per_page=$newPageSize"
)
logger.info("getGitCIAllMembers request url: $url")
val request = Request.Builder()
Expand Down Expand Up @@ -1833,7 +1834,7 @@ class GitService @Autowired constructor(
): Result<Boolean> {
logger.info(
"enableCi projectName:$projectName," +
"enable:$enable,tokenType:$tokenType"
"enable:$enable,tokenType:$tokenType"
)
val encodeProjectName = URLEncoder.encode(projectName, "utf-8")
val url = StringBuilder("${gitConfig.gitApiUrl}/projects/$encodeProjectName/ci/enable")
Expand Down

0 comments on commit 01bc229

Please sign in to comment.