Skip to content

Commit

Permalink
Update info.
Browse files Browse the repository at this point in the history
  • Loading branch information
random1223 committed Aug 31, 2024
1 parent 875fde0 commit 2e9bf63
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class CodeAnalysisResultDto {
private CodeAnalyzerType codeAnalyzerType;

private Map<String, List<CodeAnalysisIssueDto>> issuesByFile = new LinkedHashMap<>();
private int issueCount = 0;


public CodeAnalysisResultDto(String language, CodeAnalyzerType codeAnalyzerType) {
Expand All @@ -18,6 +19,12 @@ public CodeAnalysisResultDto(String language, CodeAnalyzerType codeAnalyzerType)
this.displayTitle = language;
}

public void setIssuesByFile(Map<String, List<CodeAnalysisIssueDto>> issuesByFile) {
this.issuesByFile = issuesByFile;
if(issuesByFile!=null){
issueCount += issuesByFile.size();
}
}

public void addIssue(CodeAnalysisIssueDto issueDto) {
if(issueDto == null){
Expand All @@ -27,6 +34,7 @@ public void addIssue(CodeAnalysisIssueDto issueDto) {
String filePath = issueDto.getFilePath();
issuesByFile.putIfAbsent(filePath, new ArrayList<>());
issuesByFile.get(filePath).add(issueDto);
issueCount++;
}

public void addIssues(List<CodeAnalysisIssueDto> codeAnalysisIssueDtoList) {
Expand Down Expand Up @@ -71,8 +79,8 @@ public Map<String, List<CodeAnalysisIssueDto>> getIssuesByFile() {
return issuesByFile;
}

public void setIssuesByFile(Map<String, List<CodeAnalysisIssueDto>> issuesByFile) {
this.issuesByFile = issuesByFile;
}

public int getIssueCount() {
return issueCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

import static io.codety.scanner.util.CodetyConstant.ENV_CODETY_FAIL_JOB_WHEN_CODE_ISSUE_WAS_FOUND;

Expand Down Expand Up @@ -64,10 +65,18 @@ public boolean distributeAnalysisResult(AnalyzerRequest analyzerRequest, CodeAna
sarifResultReporter.deliverResult(analyzerRequest, codeAnalysisResultSetDto);

List<CodeAnalysisResultDto> codeAnalysisResultDtoList = codeAnalysisResultSetDto.getCodeAnalysisResultDtoList();
if(codeAnalysisResultDtoList!=null && codeAnalysisResultDtoList.size() > 0 && analyzerRequest.isFailJobWhenCodeIssueWasFound()){
int count = codeAnalysisResultDtoList == null ? 0 : codeAnalysisResultDtoList.size();
CodetyConsoleLogger.info("Fail the job due to "+count+" code issue(s) were found and " + ENV_CODETY_FAIL_JOB_WHEN_CODE_ISSUE_WAS_FOUND + " is true");
System.exit(-1);
if(codeAnalysisResultDtoList!=null){
boolean containsCodeIssue = false;
for(CodeAnalysisResultDto resultDto : codeAnalysisResultDtoList){
if(resultDto.getIssueCount() > 0){
containsCodeIssue = true;
break;
}
}
if(containsCodeIssue && analyzerRequest.isFailJobWhenCodeIssueWasFound()) {
CodetyConsoleLogger.info("Fail the job due to code issue(s) were found and " + ENV_CODETY_FAIL_JOB_WHEN_CODE_ISSUE_WAS_FOUND + " is true");
System.exit(-1);
}
}

return true;
Expand Down

0 comments on commit 2e9bf63

Please sign in to comment.