Skip to content

Commit

Permalink
Merge pull request #7779 from Yuanruitao/release-1.9
Browse files Browse the repository at this point in the history
feat: codecc 支持使用github账号登录态和鉴权
  • Loading branch information
irwinsun authored Oct 17, 2022
2 parents 1cad783 + 2504d73 commit 6be32b2
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 10 deletions.
5 changes: 4 additions & 1 deletion scripts/deploy-codecc/bk-codecc-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ install_codecc__ms_common (){
done
# 保持微服务部分子目录的强一致性.
rsync -ra --delete "$BK_CODECC_SRC_DIR/$MS_NAME/lib" "$BK_CODECC_SRC_DIR/$MS_NAME/com" "$BK_CODECC_HOME/$MS_NAME"
# CodeCC启动jar包依赖顺序特殊调整
mkdir -p $BK_CODECC_HOME/$MS_NAME/priority
ls -al $BK_CODECC_HOME/$MS_NAME/lib/|grep codecc-common 2>/dev/null && mv $BK_CODECC_HOME/$MS_NAME/lib/codecc-common-*.jar $BK_CODECC_HOME/$MS_NAME/priority/
sed -i -e '/CLASSPATH/s/.*/CLASSPATH=\".:priority\/*:lib\/*\"/' $BK_CODECC_HOME/$MS_NAME/service.env
}

# 仅需复制frontend目录.
Expand Down Expand Up @@ -178,4 +182,3 @@ else
echo "INFO: using default installer for codecc micro-service."
install_codecc__ms_common "$MS_NAME" "$@"
fi

2 changes: 1 addition & 1 deletion scripts/deploy-codecc/bkce-set-env03-codecc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ codecc_env_03="./bin/03-userdef/codecc.env"

set_env03 (){
for kv in "$@"; do
grep -qxF "$kv" "$codecc_env_default" 2>/dev/null || echo "$kv" >> "$codecc_env_default"
if ! grep -q "^${kv%%=*}=[^ ]" "$codecc_env_03" 2>/dev/null; then # 非空则不覆盖.
echo "SET_ENV03: $codecc_env_03 中未曾赋值,新增 $kv"
[[ "$kv" =~ ^[A-Z0-9_]+=$ ]] && echo -e "\033[31;1m注意:\033[m$kv 赋值为空,请检查蓝鲸是否安装正确
Expand Down Expand Up @@ -86,4 +87,3 @@ fi

echo "合并env."
./bin/merge_env.sh codecc &>/dev/null || true

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ package com.tencent.devops.common.client
import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_BK_TICKET
import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_PROJECT_ID
import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_USER_ID
import com.tencent.devops.common.client.discovery.ConsulDiscoveryUtils
import com.tencent.devops.common.client.discovery.DiscoveryUtils
import com.tencent.devops.common.client.ms.ConsulServiceClient
import com.tencent.devops.common.client.pojo.AllProperties
import com.tencent.devops.common.client.proxy.DevopsProxy
Expand All @@ -42,6 +44,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter
import org.springframework.boot.autoconfigure.AutoConfigureOrder
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration
import org.springframework.cloud.client.serviceregistry.Registration
import org.springframework.cloud.consul.discovery.ConsulDiscoveryClient
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
Expand Down Expand Up @@ -117,5 +120,9 @@ class ConsulClientAutoConfiguration {
}
}

@Bean
@ConditionalOnMissingBean(DiscoveryUtils::class)
fun discoveryUtils(@Autowired registration: Registration) = ConsulDiscoveryUtils(registration)


}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ package com.tencent.devops.common.client
import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_BK_TICKET
import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_PROJECT_ID
import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_USER_ID
import com.tencent.devops.common.client.discovery.DiscoveryUtils
import com.tencent.devops.common.client.discovery.KubernetesDiscoveryUtils
import com.tencent.devops.common.client.ms.KubernetesClient
import com.tencent.devops.common.client.pojo.AllProperties
import com.tencent.devops.common.client.proxy.DevopsProxy
Expand All @@ -41,10 +43,13 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.AutoConfigureAfter
import org.springframework.boot.autoconfigure.AutoConfigureOrder
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.cloud.client.discovery.DiscoveryClient
import org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration
import org.springframework.cloud.kubernetes.client.discovery.KubernetesInformerDiscoveryClient
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

import com.tencent.devops.common.service.Profile
import org.springframework.context.annotation.PropertySource
import org.springframework.core.Ordered
import org.springframework.web.context.request.RequestContextHolder
Expand Down Expand Up @@ -118,4 +123,10 @@ class KubernetesClientAutoConfiguration {
}
}

@Bean
@ConditionalOnMissingBean(DiscoveryUtils::class)
fun discoveryUtils(@Autowired discoveryClient: DiscoveryClient,
@Autowired profile: Profile
) = KubernetesDiscoveryUtils(discoveryClient,profile)

}
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ protected String getFileContent(long taskId, String projectId, String userId, St

content = pipelineScmService.getFileContentOauth(oauthUserId, GitUtil.INSTANCE.getProjectName(url),
relPath, (revision != null ? revision : branch));
} else if(projectId.startsWith("git_") || projectId.startsWith("github_")){
} else if (projectId != null && (projectId.startsWith("git_") || projectId.startsWith("github_"))) {
content = pipelineScmService.getStreamFileContent(projectId, userId, url, relPath, revision, branch);
}else {
content = pipelineScmService.getFileContent(taskId, repoId, relPath, revision, branch, subModule, createFrom);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,15 @@ public CommonDefectDetailQueryRspVO processQueryWarningDetailRequest(long taskId
// 校验传入的路径是否合法(路径是否是告警对应的文件)
verifyFilePathIsValid(queryWarningDetailReq.getFilePath(), ccnDefectEntity.getFilePath());

//获取任务信息
Result<TaskDetailVO> taskInfoResult = client.get(ServiceTaskRestResource.class).getTaskInfoById(taskId);
TaskDetailVO taskDetailVO = taskInfoResult.getData();

//根据文件路径从分析集群获取文件内容
String content = getFileContent(taskId, null, userId, ccnDefectEntity.getUrl(), ccnDefectEntity.getRepoId(),
ccnDefectEntity.getRelPath(), ccnDefectEntity.getRevision(), ccnDefectEntity.getBranch(), ccnDefectEntity.getSubModule());
String content = getFileContent(taskId, taskDetailVO == null ? null : taskDetailVO.getProjectId(), userId,
ccnDefectEntity.getUrl(), ccnDefectEntity.getRepoId(),
ccnDefectEntity.getRelPath(), ccnDefectEntity.getRevision(), ccnDefectEntity.getBranch(),
ccnDefectEntity.getSubModule());
content = trimCodeSegment(content, ccnDefectEntity.getStartLines(), ccnDefectEntity.getEndLines(), ccnDefectQueryRspVO);

//设置代码评论
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import com.tencent.bk.codecc.task.api.ServiceTaskRestResource;
import com.tencent.bk.codecc.task.vo.TaskDetailVO;
import com.tencent.devops.common.api.exception.CodeCCException;
import com.tencent.devops.common.api.pojo.Result;
import com.tencent.devops.common.constant.ComConstants;
import com.tencent.devops.common.constant.CommonMessageCode;
import com.tencent.devops.common.service.BizServiceFactory;
Expand Down Expand Up @@ -206,9 +207,14 @@ public CommonDefectDetailQueryRspVO processGetFileContentSegmentRequest(long tas
throw new CodeCCException(CommonMessageCode.RECORD_NOT_EXITS, new String[]{"重复率的缺陷实体"}, null);
}

//获取任务信息
Result<TaskDetailVO> taskInfoResult = client.get(ServiceTaskRestResource.class).getTaskInfoById(taskId);
TaskDetailVO taskDetailVO = taskInfoResult.getData();

// 1. 根据文件路径从分析集群获取文件内容
String content = getFileContent(taskId, null, userId, dupcDefectEntity.getUrl(), dupcDefectEntity.getRepoId(), dupcDefectEntity.getRelPath(),
dupcDefectEntity.getRevision(), dupcDefectEntity.getBranch(), dupcDefectEntity.getSubModule());
String content = getFileContent(taskId, taskDetailVO == null ? null : taskDetailVO.getProjectId(), userId,
dupcDefectEntity.getUrl(), dupcDefectEntity.getRepoId(), dupcDefectEntity.getRelPath(),
dupcDefectEntity.getRevision(), dupcDefectEntity.getBranch(), dupcDefectEntity.getSubModule());

// 2. 根据告警的开始行和结束行截取文件片段
CommonDefectDetailQueryRspVO dupcDefectQueryRspVO = new CommonDefectDetailQueryRspVO();
Expand Down Expand Up @@ -286,13 +292,16 @@ private CommonDefectDetailQueryRspVO getSourceCodeBlockDetail(long taskId, Strin

// 校验传入的路径是否合法(路径是否是告警对应的文件)
verifyFilePathIsValid(defectQueryReqVO.getFilePath(), dupcDefectEntity.getFilePath());

//获取任务信息
Result<TaskDetailVO> taskInfoResult = client.get(ServiceTaskRestResource.class).getTaskInfoById(taskId);
TaskDetailVO taskDetailVO = taskInfoResult.getData();
//根据文件路径从分析集群获取文件内容
String content = "";
if (StringUtils.isNotBlank(dupcDefectEntity.getRelPath()))
{
content = getFileContent(taskId, null, userId, dupcDefectEntity.getUrl(), dupcDefectEntity.getRepoId(), dupcDefectEntity.getRelPath(),
dupcDefectEntity.getRevision(), dupcDefectEntity.getBranch(), dupcDefectEntity.getSubModule());
content = getFileContent(taskId, taskDetailVO == null ? null : taskDetailVO.getProjectId(), userId,
dupcDefectEntity.getUrl(), dupcDefectEntity.getRepoId(), dupcDefectEntity.getRelPath(),
dupcDefectEntity.getRevision(), dupcDefectEntity.getBranch(), dupcDefectEntity.getSubModule());
}

List<CodeBlockEntity> blockEntityList = dupcDefectEntity.getBlockList();
Expand Down

0 comments on commit 6be32b2

Please sign in to comment.