use of com.checkmarx.flow.dto.bitbucket.Change in project cx-flow by checkmarx-ltd.
the class BitbucketCloudController method pushRequest.
/**
* Receive Push event submitted from Bitbucket
*/
@PostMapping(value = { "/{product}", "/" }, headers = PUSH)
public ResponseEntity<EventResponse> pushRequest(@RequestBody PushEvent body, @PathVariable(value = "product", required = false) String product, ControllerRequest controllerRequest, @RequestParam(value = "token") String token) {
log.debug("Push Request body contents are {}", body.toString());
String uid = helperService.getShortUid();
MDC.put(FlowConstants.MAIN_MDC_ENTRY, uid);
validateBitBucketRequest(token);
controllerRequest = ensureNotNull(controllerRequest);
try {
Repository repository = body.getRepository();
String app = repository.getName();
if (!ScanUtils.empty(controllerRequest.getApplication())) {
app = controllerRequest.getApplication();
}
// set the default bug tracker as per yml
setBugTracker(flowProperties, controllerRequest);
BugTracker.Type bugType = ScanUtils.getBugTypeEnum(controllerRequest.getBug(), flowProperties.getBugTrackerImpl());
if (controllerRequest.getAppOnly() != null) {
flowProperties.setTrackApplicationOnly(controllerRequest.getAppOnly());
}
if (ScanUtils.empty(product)) {
product = ScanRequest.Product.CX.getProduct();
}
ScanRequest.Product p = ScanRequest.Product.valueOf(product.toUpperCase(Locale.ROOT));
List<Change> changeList = body.getPush().getChanges();
String currentBranch = null;
if (changeList != null) {
currentBranch = changeList.get(0).getNew().getName();
}
List<String> branches = getBranches(controllerRequest, flowProperties);
String hash = null;
if (changeList != null) {
hash = changeList.get(0).getNew().getTarget().getHash();
}
BugTracker bt = ScanUtils.getBugTracker(controllerRequest.getAssignee(), bugType, jiraProperties, controllerRequest.getBug());
FilterConfiguration filter = filterFactory.getFilter(controllerRequest, flowProperties);
/*Determine emails*/
List<String> emails = new ArrayList<>();
if (changeList != null) {
for (Change ch : changeList) {
for (Commit c : ch.getCommits()) {
String author = c.getAuthor().getRaw();
if (!ScanUtils.empty(author)) {
emails.add(author);
}
}
}
}
String gitUrl = repository.getLinks().getHtml().getHref().concat(".git");
String configToken = scmConfigOverrider.determineConfigToken(properties, controllerRequest.getScmInstance());
String gitAuthUrl = gitAuthUrlGenerator.addCredToUrl(ScanRequest.Repository.BITBUCKET, gitUrl, configToken);
ScanRequest request = ScanRequest.builder().application(app).product(p).project(controllerRequest.getProject()).team(controllerRequest.getTeam()).namespace(getProjectNamespace(repository)).repoName(repository.getName()).repoUrl(gitUrl).repoUrlWithAuth(gitAuthUrl).repoType(ScanRequest.Repository.BITBUCKET).branch(currentBranch).refs(Constants.CX_BRANCH_PREFIX.concat(currentBranch)).email(emails).scanPreset(controllerRequest.getPreset()).incremental(controllerRequest.getIncremental()).excludeFolders(controllerRequest.getExcludeFolders()).excludeFiles(controllerRequest.getExcludeFiles()).bugTracker(bt).filter(filter).hash(hash).organizationId(getOrganizationid(repository)).gitUrl(gitUrl).build();
setScmInstance(controllerRequest, request);
fillRequestWithAdditionalData(request, repository, body.toString());
checkForConfigAsCode(request);
request.setId(uid);
if (helperService.isBranch2Scan(request, branches)) {
flowService.initiateAutomation(request);
}
} catch (IllegalArgumentException e) {
return getBadRequestMessage(e, controllerRequest, product);
}
return getSuccessMessage();
}
Aggregations