Skip to content

Commit deffb93

Browse files
Merge pull request #453 from checkmarx-ltd/PR-CXFLW-1646-restrict-branch-fix
Fix for PR decoration while using RestrictResultsToBranch parameter
2 parents e1d26d3 + 5ba0e68 commit deffb93

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

src/main/java/com/checkmarx/sdk/config/CxProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public class CxProperties extends CxPropertiesBase{
142142
private Boolean considerScanningStatus = false;
143143

144144
@Getter @Setter
145-
private Boolean projectSummary= false;
145+
private Boolean projectSummary= true;
146146

147147

148148
/**

src/main/java/com/checkmarx/sdk/service/CxService.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.checkmarx.sdk.config.CxPropertiesBase;
66
import com.checkmarx.sdk.dto.cx.preandpostaction.CustomTaskByName;
77
import com.checkmarx.sdk.dto.cx.preandpostaction.ScanSettings;
8+
import com.checkmarx.sdk.dto.cx.projectdetails.CustomField;
89
import com.checkmarx.sdk.dto.cx.projectdetails.ProjectFieldDetails;
910
import com.checkmarx.sdk.dto.sast.Filter;
1011
import com.checkmarx.sdk.dto.ScanResults;
@@ -40,6 +41,7 @@
4041
import org.json.JSONException;
4142
import org.json.JSONObject;
4243
import org.slf4j.Logger;
44+
import org.slf4j.LoggerFactory;
4345
import org.springframework.beans.factory.annotation.Qualifier;
4446
import org.springframework.core.io.FileSystemResource;
4547
import org.springframework.http.*;
@@ -104,7 +106,7 @@ public class CxService implements CxClient {
104106
Created (2)
105107
*/
106108
public static final Integer REPORT_STATUS_CREATED = 2;
107-
private static final Logger log = org.slf4j.LoggerFactory.getLogger(CxService.class);
109+
private static final Logger log = LoggerFactory.getLogger(CxService.class);
108110
private static final String CUSTOM_FIELDS = "/customFields";
109111
private static final String TEAMS = "/auth/teams";
110112
private static final String TEAM = "/auth/teams/{id}";
@@ -663,11 +665,14 @@ public ScanResults getReportContent(Integer reportId, FilterConfiguration filter
663665
cxScanBuilder.additionalDetails(getAdditionalScanDetails(cxResults));
664666
CxScanSummary scanSummary = null;
665667
CxScanSummary projectSummary = null;
666-
if (cxProperties.getRestrictResultsToBranch() != null && cxProperties.getRestrictResultsToBranch()) {
667-
if(cxProperties.getProjectSummary()!=null && cxProperties.getProjectSummary()){
668-
projectSummary = getScanSummaryByScanId(Integer.valueOf(cxResults.getScanId()));
669-
}
670-
scanSummary = new CxScanSummary(summary);
668+
if (cxProperties.getCxBranch() && cxProperties.getRestrictResultsToBranch() != null && cxProperties.getRestrictResultsToBranch()) {
669+
if(cxProperties.getProjectSummary()!=null && cxProperties.getProjectSummary()){
670+
CxProjectBranchingStatus branch = getProjectBranchingStatus(Integer.valueOf(cxResults.getProjectId()));
671+
if(branch!=null){
672+
projectSummary = getScanSummary(branch.getOriginalProjectId());
673+
}
674+
}
675+
scanSummary = new CxScanSummary(summary);
671676
} else {
672677
scanSummary = getScanSummaryByScanId(Integer.valueOf(cxResults.getScanId()));
673678
}
@@ -695,6 +700,15 @@ public ScanResults getReportContent(Integer reportId, FilterConfiguration filter
695700
}
696701
}
697702

703+
private Map<String, Integer> normalizeSummary(Map<String, Integer> summary){
704+
// Normalize keys to capitalize format eg: HIGH -> High
705+
Map<String, Integer> normalized = new HashMap<>();
706+
for (Map.Entry<String, Integer> entry : summary.entrySet()) {
707+
normalized.put(org.springframework.util.StringUtils.capitalize(entry.getKey().toLowerCase()), entry.getValue());
708+
}
709+
return normalized;
710+
}
711+
698712
/**
699713
* Retrieve the report by reportId, mapped to ScanResults DTO, applying filtering as requested
700714
*/
@@ -866,9 +880,12 @@ public ScanResults getReportContent(File file, FilterConfiguration filter) throw
866880
if (!cxProperties.getOffline() && !ScanUtils.empty(cxResults.getScanId())) {
867881
CxScanSummary scanSummary = null;
868882
CxScanSummary projectSummary = null;
869-
if (cxProperties.getRestrictResultsToBranch() != null && cxProperties.getRestrictResultsToBranch()) {
883+
if (cxProperties.getCxBranch() && cxProperties.getRestrictResultsToBranch() != null && cxProperties.getRestrictResultsToBranch()) {
870884
if(cxProperties.getProjectSummary()!=null && cxProperties.getProjectSummary()){
871-
projectSummary = getScanSummaryByScanId(Integer.valueOf(cxResults.getScanId()));
885+
CxProjectBranchingStatus branch = getProjectBranchingStatus(Integer.valueOf(cxResults.getProjectId()));
886+
if(branch!=null){
887+
projectSummary = getScanSummary(branch.getOriginalProjectId());
888+
}
872889
}
873890
scanSummary = new CxScanSummary(summary);
874891
} else {
@@ -1006,7 +1023,7 @@ private Map<String, Integer> getIssues(FilterConfiguration filter, String sessio
10061023
log.debug("sastFilters: {}", sastFilters);
10071024

10081025
Set<Integer> similarityIdsToExclude = null;
1009-
if (cxProperties.getRestrictResultsToBranch() != null && cxProperties.getRestrictResultsToBranch()) {
1026+
if (cxProperties.getCxBranch() && cxProperties.getRestrictResultsToBranch() != null && cxProperties.getRestrictResultsToBranch()) {
10101027
log.debug("Restricting results to current branch");
10111028
int projectId = Integer.parseInt(cxResults.getProjectId());
10121029
CxProjectBranchingStatus branch = getProjectBranchingStatus(projectId);
@@ -1043,7 +1060,7 @@ private Map<String, Integer> getIssues(FilterConfiguration filter, String sessio
10431060
log.error("Null Pointer Exception Occurred while getting issue");
10441061
log.error(ExceptionUtils.getStackTrace(e));
10451062
}
1046-
return summary;
1063+
return normalizeSummary(summary);
10471064
}
10481065

10491066
private ScanResults.XIssue buildIssue(ScanResults.XIssue.XIssueBuilder xIssueBuilder,ResultType resultType,QueryType result,DateTimeFormatter formatter,CxXMLResultsType cxResults,String session,List<ScanResults.XIssue> cxIssueList,Map<String, Integer> summary,boolean flag){

0 commit comments

Comments
 (0)