Skip to content

Commit

Permalink
feat: codecc 支持使用github账号登录态和鉴权 #7363
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuanruitao committed Oct 14, 2022
1 parent 52a51c0 commit 2504d73
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
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 2504d73

Please sign in to comment.