Adding github service to the github controller
@@ -11,11 +11,14 @@ import com.checkmarx.flow.dto.github.*;
import com.checkmarx.flow.exception.InvalidTokenException;
import com.checkmarx.flow.exception.MachinaRuntimeException;
import com.checkmarx.flow.service.FlowService;
+import com.checkmarx.flow.service.GitHubService;
import com.checkmarx.flow.service.HelperService;
import com.checkmarx.flow.utils.ScanUtils;
import com.checkmarx.sdk.config.Constants;
import com.checkmarx.sdk.config.CxProperties;
+import com.checkmarx.sdk.dto.CxConfig;
import com.checkmarx.sdk.dto.Filter;
+import com.checkmarx.sdk.exception.CheckmarxException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
@@ -60,18 +63,18 @@ public class GitHubController {
private final JiraProperties jiraProperties;
private final FlowService flowService;
private final HelperService helperService;
+ private final GitHubService gitHubService;
private Mac hmac;
- @ConstructorProperties({"properties", "flowProperties", "cxProperties",
- "jiraProperties", "flowService", "helperService"})
public GitHubController(GitHubProperties properties, FlowProperties flowProperties, CxProperties cxProperties,
- JiraProperties jiraProperties, FlowService flowService, HelperService helperService) {
+ JiraProperties jiraProperties, FlowService flowService, HelperService helperService, GitHubService gitHubService) {
this.properties = properties;
this.flowProperties = flowProperties;
this.cxProperties = cxProperties;
this.jiraProperties = jiraProperties;
this.flowService = flowService;
this.helperService = helperService;
+ this.gitHubService = gitHubService;
}
@PostConstruct
@@ -129,7 +132,6 @@ public class GitHubController {
PullEvent event;
ObjectMapper mapper = new ObjectMapper();
MachinaOverride o = ScanUtils.getMachinaOverride(override);
-
try {
event = mapper.readValue(body, PullEvent.class);
} catch (IOException e) {
@@ -234,6 +236,7 @@ public class GitHubController {
.filters(filters)
.build();
+ CxConfig configOverride = gitHubService.getCxConfigOverride(request);
request = ScanUtils.overrideMap(request, o);
request.putAdditionalMetadata("statuses_url", event.getPullRequest().getStatusesUrl());
request.setId(uid);
@@ -243,10 +246,9 @@ public class GitHubController {
}
- }catch (IllegalArgumentException e){
- String errorMessage = "Error submitting Scan Request. Product or Bugtracker option incorrect ".concat(product != null ? product : "").concat(" | ").concat(bug != null ? bug : "");
+ }catch (IllegalArgumentException | CheckmarxException e){
+ String errorMessage = "Error submitting Scan Request. Please check that Product or Bugtracker option is correct ".concat(product != null ? product : "").concat(" | ").concat(bug != null ? bug : "");
log.error(errorMessage);
- ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(EventResponse.builder()
.message(errorMessage)
@@ -258,7 +260,6 @@ public class GitHubController {
.message("Scan Request Successfully Submitted")
.success(true)
.build());
-
}
/**
