Skip to content

Commit de7e62e

Browse files
authored
Merge pull request #10447 from mingshewhe/bug_10445
bug: 修复release-1.8编译报错 #10445
2 parents b85a1f7 + 4395dd6 commit de7e62e

File tree

8 files changed

+230
-7
lines changed

8 files changed

+230
-7
lines changed

.github/workflows/frontend.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ jobs:
3030
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
3131
restore-keys: |
3232
${{ runner.os }}-yarn-
33-
- run: yarn install && yarn start && yarn public
33+
- run: |
34+
export NODE_OPTIONS=--openssl-legacy-provider
35+
yarn install && yarn start && yarn public
3436
working-directory: src/frontend
3537
- uses: actions/upload-artifact@v1
3638
with:

.github/workflows/release.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ jobs:
2121
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
2222
restore-keys: |
2323
${{ runner.os }}-yarn-
24-
- run: yarn install && yarn start && yarn public
24+
- run: |
25+
export NODE_OPTIONS=--openssl-legacy-provider
26+
yarn install && yarn start && yarn public
2527
working-directory: src/frontend
2628
- uses: actions/upload-artifact@v1
2729
with:
@@ -187,10 +189,11 @@ jobs:
187189
- name: frontend
188190
id: codecc-frontend
189191
run: |
192+
export NODE_OPTIONS=--openssl-legacy-provider
190193
cd src/frontend/devops-codecc
191194
rm -rf dist
192195
npm i
193-
npm run build
196+
npm i --force && npm run build
194197
if [ -f dist/index.html ]; then
195198
mv dist/index.html dist/frontend#index.html
196199
fi

bk-ci

-1
This file was deleted.

src/backend/codecc/core/common/common-client/common-client-base/src/main/kotlin/com/tencent/devops/common/client/Client.kt

+20
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,26 @@ abstract class Client constructor(
109109
feignProxy.javaClass.interfaces, devopsProxy))
110110
}
111111

112+
fun <T : Any> getDevopsService(clz: Class<T>, projectId: String): T {
113+
// 获取为feign定义的拦截器
114+
DevopsProxy.projectIdThreadLocal.set(projectId)
115+
val feignProxy = Feign.builder()
116+
.client(feignClient)
117+
.errorDecoder(clientErrorDecoder)
118+
.encoder(jacksonEncoder)
119+
.decoder(jacksonDecoder)
120+
.contract(jaxRsContract)
121+
.options(Request.Options(10000, 30000))
122+
.requestInterceptor(SpringContextUtil.getBean(
123+
RequestInterceptor::class.java, "devopsRequestInterceptor"))
124+
.target(DevopsServiceTarget(findServiceName(clz.kotlin,"", ""), clz,
125+
allProperties.devopsDevUrl
126+
?: ""))
127+
val devopsProxy = DevopsProxy(feignProxy, clz)
128+
return clz.cast(
129+
Proxy.newProxyInstance(feignProxy.javaClass.classLoader, feignProxy.javaClass.interfaces, devopsProxy))
130+
}
131+
112132
fun <T : Any> get(clz: Class<T>): T = get(clz.kotlin)
113133

114134
abstract fun <T : Any> get(clz: KClass<T>): T
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
3+
*
4+
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license.
7+
*
8+
* A copy of the MIT License is included in this file.
9+
*
10+
*
11+
* Terms of the MIT License:
12+
* ---------------------------------------------------
13+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
14+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
15+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
16+
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
17+
*
18+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
19+
* the Software.
20+
*
21+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
22+
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
23+
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26+
*/
27+
28+
package com.tencent.devops.common.client.discovery
29+
30+
import org.springframework.cloud.client.ServiceInstance
31+
32+
interface DiscoveryUtils {
33+
34+
fun getInstanceTags(instance : ServiceInstance) : List<String>
35+
36+
fun getRegistrationTags(instance : ServiceInstance) : List<String>
37+
38+
fun getRegistration() : ServiceInstance
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
3+
*
4+
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license.
7+
*
8+
* A copy of the MIT License is included in this file.
9+
*
10+
*
11+
* Terms of the MIT License:
12+
* ---------------------------------------------------
13+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
14+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
15+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
16+
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
17+
*
18+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
19+
* the Software.
20+
*
21+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
22+
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
23+
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26+
*/
27+
28+
package com.tencent.devops.common.client.discovery
29+
30+
import org.springframework.cloud.client.ServiceInstance
31+
import org.springframework.cloud.client.serviceregistry.Registration
32+
import org.springframework.cloud.consul.discovery.ConsulServiceInstance
33+
import org.springframework.cloud.consul.serviceregistry.ConsulRegistration
34+
35+
class ConsulDiscoveryUtils constructor(
36+
private val registration: Registration
37+
) : DiscoveryUtils {
38+
39+
override fun getInstanceTags(instance: ServiceInstance): List<String> {
40+
return if (instance is ConsulServiceInstance) {
41+
instance.tags
42+
} else {
43+
instance.metadata.values.toList()
44+
}
45+
}
46+
47+
override fun getRegistrationTags(instance: ServiceInstance): List<String> {
48+
return if (instance is ConsulRegistration) {
49+
instance.service.tags
50+
} else {
51+
instance.metadata.values.toList()
52+
}
53+
}
54+
55+
override fun getRegistration(): ServiceInstance {
56+
return registration
57+
}
58+
}

src/backend/codecc/core/defect/biz-defect-migration/src/main/kotlin/com/tencent/bk/codecc/defect/service/impl/PipelineScmServiceImpl.kt

+95-2
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ import com.tencent.bk.codecc.defect.dao.mongotemplate.CodeRepoInfoDao
44
import com.tencent.bk.codecc.defect.service.PipelineScmService
55
import com.tencent.bk.codecc.task.api.ServiceTaskRestResource
66
import com.tencent.devops.common.api.CodeRepoVO
7+
import com.tencent.devops.common.api.codecc.util.JsonUtil
78
import com.tencent.devops.common.api.enums.RepositoryType
89
import com.tencent.devops.common.api.exception.CodeCCException
910
import com.tencent.devops.common.api.pojo.Result
10-
import com.tencent.devops.common.api.codecc.util.JsonUtil
1111
import com.tencent.devops.common.client.Client
12+
import com.tencent.devops.common.client.proxy.DevopsProxy
1213
import com.tencent.devops.common.constant.ComConstants
1314
import com.tencent.devops.common.constant.CommonMessageCode
1415
import com.tencent.devops.common.util.HttpPathUrlUtil
16+
import com.tencent.devops.common.util.OkhttpUtils
1517
import com.tencent.devops.repository.api.ExternalCodeccRepoResource
18+
import com.tencent.devops.repository.api.ServiceOauthResource
1619
import com.tencent.devops.repository.api.ServiceRepositoryResource
1720
import com.tencent.devops.repository.api.scm.ServiceGitResource
21+
import com.tencent.devops.repository.pojo.enums.RepoAuthType
1822
import org.apache.commons.collections.CollectionUtils
1923
import org.apache.commons.lang.math.NumberUtils
2024
import org.apache.commons.lang3.RandomStringUtils
@@ -32,6 +36,7 @@ class PipelineScmServiceImpl @Autowired constructor(
3236

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

3742
@Value("\${codecc.privatetoken:#{null}}")
@@ -203,4 +208,92 @@ class PipelineScmServiceImpl @Autowired constructor(
203208
return client.getDevopsService(ServiceGitResource::class.java).getAuthUrl(authParamJsonStr = authParamJsonStr).data
204209
?: ""
205210
}
206-
}
211+
212+
override fun getStreamFileContent(
213+
projectId: String,
214+
userId: String,
215+
repoUrl: String,
216+
filePath: String,
217+
reversion: String?,
218+
branch: String?
219+
): String? {
220+
if (projectId.startsWith("github_")) {
221+
return getGithubFileContent(repoUrl, reversion ?: branch ?: "", filePath)
222+
}
223+
val token = try {
224+
val tokenResult = client.getDevopsService(ServiceOauthResource::class.java, projectId).gitGet(userId)
225+
if (tokenResult.data == null || tokenResult.isNotOk()) {
226+
logger.error("can not get user repository token: $userId $repoUrl $filePath $reversion $branch")
227+
throw CodeCCException(errorCode = CommonMessageCode.OAUTH_TOKEN_IS_INVALID)
228+
}
229+
tokenResult.data!!.accessToken
230+
} catch (e: CodeCCException) {
231+
if (e.errorCode == CommonMessageCode.OAUTH_TOKEN_IS_INVALID) {
232+
throw e
233+
} else {
234+
""
235+
}
236+
} finally {
237+
DevopsProxy.projectIdThreadLocal.remove()
238+
}
239+
if (token.isBlank()) {
240+
return ""
241+
}
242+
243+
val fileContent = try {
244+
logger.info("get file content: $repoUrl | $filePath | $reversion | $branch | $token")
245+
val result = client.getDevopsService(ExternalCodeccRepoResource::class.java, projectId)
246+
.getGitFileContentCommon(
247+
repoUrl = repoUrl,
248+
filePath = filePath.removePrefix("/"),
249+
ref = if(!reversion.isNullOrBlank()) reversion else branch,
250+
token = token,
251+
authType = RepoAuthType.OAUTH
252+
)
253+
if (result.isNotOk()) {
254+
logger.error("get file content fail!")
255+
throw CodeCCException(CommonMessageCode.CODE_NORMAL_CONTENT_ERROR)
256+
}
257+
result.data
258+
} catch (e: CodeCCException) {
259+
return if (e.errorCode == CommonMessageCode.FILE_CONTENT_TOO_LARGE) {
260+
FILE_TOO_LARGE_CONTENT
261+
} else {
262+
throw e
263+
}
264+
} catch (e: Exception) {
265+
logger.error(
266+
"get git file content fail!, repoUrl: {}, filePath: {}, token: {}",
267+
repoUrl,
268+
filePath,
269+
token,
270+
e
271+
)
272+
throw CodeCCException(CommonMessageCode.CODE_CONTENT_ERROR)
273+
} finally {
274+
DevopsProxy.projectIdThreadLocal.remove()
275+
}
276+
277+
278+
return fileContent
279+
}
280+
281+
/**
282+
* 获取 Github 文本内容
283+
* 等待蓝盾支持后,切换到蓝盾的版本
284+
*/
285+
private fun getGithubFileContent(repoUrl: String, ref: String, filePath: String): String {
286+
val headerIndex = if (repoUrl.startsWith("https://")) {
287+
8
288+
} else if (repoUrl.startsWith("http://")) {
289+
7
290+
} else {
291+
0
292+
}
293+
val startIndex = repoUrl.indexOf("/", headerIndex)
294+
val endIndex = repoUrl.lastIndexOf(".git")
295+
val projectName = repoUrl.substring(startIndex + 1, endIndex)
296+
val url = "https://raw.githubusercontent.com/$projectName/$ref/$filePath"
297+
return OkhttpUtils.doGet(url)
298+
}
299+
}

src/backend/codecc/core/defect/biz-defect/src/main/kotlin/com/tencent/bk/codecc/defect/service/PipelineScmService.kt

+10-1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,13 @@ interface PipelineScmService {
6060
* @return
6161
*/
6262
fun getOauthUrl(userId: String, projectId: String, taskId: Long, toolName: String): String
63-
}
63+
64+
fun getStreamFileContent(
65+
projectId: String,
66+
userId: String,
67+
repoUrl: String,
68+
filePath: String,
69+
reversion: String?,
70+
branch: String?
71+
): String?
72+
}

0 commit comments

Comments
 (0)