Skip to content

Commit

Permalink
Merge pull request #10447 from mingshewhe/bug_10445
Browse files Browse the repository at this point in the history
bug: 修复release-1.8编译报错 #10445
  • Loading branch information
irwinsun authored Jun 3, 2024
2 parents b85a1f7 + 4395dd6 commit de7e62e
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn install && yarn start && yarn public
- run: |
export NODE_OPTIONS=--openssl-legacy-provider
yarn install && yarn start && yarn public
working-directory: src/frontend
- uses: actions/upload-artifact@v1
with:
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn install && yarn start && yarn public
- run: |
export NODE_OPTIONS=--openssl-legacy-provider
yarn install && yarn start && yarn public
working-directory: src/frontend
- uses: actions/upload-artifact@v1
with:
Expand Down Expand Up @@ -187,10 +189,11 @@ jobs:
- name: frontend
id: codecc-frontend
run: |
export NODE_OPTIONS=--openssl-legacy-provider
cd src/frontend/devops-codecc
rm -rf dist
npm i
npm run build
npm i --force && npm run build
if [ -f dist/index.html ]; then
mv dist/index.html dist/frontend#index.html
fi
Expand Down
1 change: 0 additions & 1 deletion bk-ci
Submodule bk-ci deleted from d418a0
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,26 @@ abstract class Client constructor(
feignProxy.javaClass.interfaces, devopsProxy))
}

fun <T : Any> getDevopsService(clz: Class<T>, projectId: String): T {
// 获取为feign定义的拦截器
DevopsProxy.projectIdThreadLocal.set(projectId)
val feignProxy = Feign.builder()
.client(feignClient)
.errorDecoder(clientErrorDecoder)
.encoder(jacksonEncoder)
.decoder(jacksonDecoder)
.contract(jaxRsContract)
.options(Request.Options(10000, 30000))
.requestInterceptor(SpringContextUtil.getBean(
RequestInterceptor::class.java, "devopsRequestInterceptor"))
.target(DevopsServiceTarget(findServiceName(clz.kotlin,"", ""), clz,
allProperties.devopsDevUrl
?: ""))
val devopsProxy = DevopsProxy(feignProxy, clz)
return clz.cast(
Proxy.newProxyInstance(feignProxy.javaClass.classLoader, feignProxy.javaClass.interfaces, devopsProxy))
}

fun <T : Any> get(clz: Class<T>): T = get(clz.kotlin)

abstract fun <T : Any> get(clz: KClass<T>): T
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.common.client.discovery

import org.springframework.cloud.client.ServiceInstance

interface DiscoveryUtils {

fun getInstanceTags(instance : ServiceInstance) : List<String>

fun getRegistrationTags(instance : ServiceInstance) : List<String>

fun getRegistration() : ServiceInstance
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.common.client.discovery

import org.springframework.cloud.client.ServiceInstance
import org.springframework.cloud.client.serviceregistry.Registration
import org.springframework.cloud.consul.discovery.ConsulServiceInstance
import org.springframework.cloud.consul.serviceregistry.ConsulRegistration

class ConsulDiscoveryUtils constructor(
private val registration: Registration
) : DiscoveryUtils {

override fun getInstanceTags(instance: ServiceInstance): List<String> {
return if (instance is ConsulServiceInstance) {
instance.tags
} else {
instance.metadata.values.toList()
}
}

override fun getRegistrationTags(instance: ServiceInstance): List<String> {
return if (instance is ConsulRegistration) {
instance.service.tags
} else {
instance.metadata.values.toList()
}
}

override fun getRegistration(): ServiceInstance {
return registration
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ import com.tencent.bk.codecc.defect.dao.mongotemplate.CodeRepoInfoDao
import com.tencent.bk.codecc.defect.service.PipelineScmService
import com.tencent.bk.codecc.task.api.ServiceTaskRestResource
import com.tencent.devops.common.api.CodeRepoVO
import com.tencent.devops.common.api.codecc.util.JsonUtil
import com.tencent.devops.common.api.enums.RepositoryType
import com.tencent.devops.common.api.exception.CodeCCException
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.api.codecc.util.JsonUtil
import com.tencent.devops.common.client.Client
import com.tencent.devops.common.client.proxy.DevopsProxy
import com.tencent.devops.common.constant.ComConstants
import com.tencent.devops.common.constant.CommonMessageCode
import com.tencent.devops.common.util.HttpPathUrlUtil
import com.tencent.devops.common.util.OkhttpUtils
import com.tencent.devops.repository.api.ExternalCodeccRepoResource
import com.tencent.devops.repository.api.ServiceOauthResource
import com.tencent.devops.repository.api.ServiceRepositoryResource
import com.tencent.devops.repository.api.scm.ServiceGitResource
import com.tencent.devops.repository.pojo.enums.RepoAuthType
import org.apache.commons.collections.CollectionUtils
import org.apache.commons.lang.math.NumberUtils
import org.apache.commons.lang3.RandomStringUtils
Expand All @@ -32,6 +36,7 @@ class PipelineScmServiceImpl @Autowired constructor(

companion object {
private val logger = LoggerFactory.getLogger(PipelineScmServiceImpl::class.java)
private val FILE_TOO_LARGE_CONTENT = "当前告警代码文件大小超过1M,不能在平台查看代码详情,可以根据告警行号在IDE查看";
}

@Value("\${codecc.privatetoken:#{null}}")
Expand Down Expand Up @@ -203,4 +208,92 @@ class PipelineScmServiceImpl @Autowired constructor(
return client.getDevopsService(ServiceGitResource::class.java).getAuthUrl(authParamJsonStr = authParamJsonStr).data
?: ""
}
}

override fun getStreamFileContent(
projectId: String,
userId: String,
repoUrl: String,
filePath: String,
reversion: String?,
branch: String?
): String? {
if (projectId.startsWith("github_")) {
return getGithubFileContent(repoUrl, reversion ?: branch ?: "", filePath)
}
val token = try {
val tokenResult = client.getDevopsService(ServiceOauthResource::class.java, projectId).gitGet(userId)
if (tokenResult.data == null || tokenResult.isNotOk()) {
logger.error("can not get user repository token: $userId $repoUrl $filePath $reversion $branch")
throw CodeCCException(errorCode = CommonMessageCode.OAUTH_TOKEN_IS_INVALID)
}
tokenResult.data!!.accessToken
} catch (e: CodeCCException) {
if (e.errorCode == CommonMessageCode.OAUTH_TOKEN_IS_INVALID) {
throw e
} else {
""
}
} finally {
DevopsProxy.projectIdThreadLocal.remove()
}
if (token.isBlank()) {
return ""
}

val fileContent = try {
logger.info("get file content: $repoUrl | $filePath | $reversion | $branch | $token")
val result = client.getDevopsService(ExternalCodeccRepoResource::class.java, projectId)
.getGitFileContentCommon(
repoUrl = repoUrl,
filePath = filePath.removePrefix("/"),
ref = if(!reversion.isNullOrBlank()) reversion else branch,
token = token,
authType = RepoAuthType.OAUTH
)
if (result.isNotOk()) {
logger.error("get file content fail!")
throw CodeCCException(CommonMessageCode.CODE_NORMAL_CONTENT_ERROR)
}
result.data
} catch (e: CodeCCException) {
return if (e.errorCode == CommonMessageCode.FILE_CONTENT_TOO_LARGE) {
FILE_TOO_LARGE_CONTENT
} else {
throw e
}
} catch (e: Exception) {
logger.error(
"get git file content fail!, repoUrl: {}, filePath: {}, token: {}",
repoUrl,
filePath,
token,
e
)
throw CodeCCException(CommonMessageCode.CODE_CONTENT_ERROR)
} finally {
DevopsProxy.projectIdThreadLocal.remove()
}


return fileContent
}

/**
* 获取 Github 文本内容
* 等待蓝盾支持后,切换到蓝盾的版本
*/
private fun getGithubFileContent(repoUrl: String, ref: String, filePath: String): String {
val headerIndex = if (repoUrl.startsWith("https://")) {
8
} else if (repoUrl.startsWith("http://")) {
7
} else {
0
}
val startIndex = repoUrl.indexOf("/", headerIndex)
val endIndex = repoUrl.lastIndexOf(".git")
val projectName = repoUrl.substring(startIndex + 1, endIndex)
val url = "https://raw.githubusercontent.com/$projectName/$ref/$filePath"
return OkhttpUtils.doGet(url)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,13 @@ interface PipelineScmService {
* @return
*/
fun getOauthUrl(userId: String, projectId: String, taskId: Long, toolName: String): String
}

fun getStreamFileContent(
projectId: String,
userId: String,
repoUrl: String,
filePath: String,
reversion: String?,
branch: String?
): String?
}

0 comments on commit de7e62e

Please sign in to comment.