Search in sources :

Example 1 with PushEvent

use of com.checkmarx.flow.dto.bitbucketserver.PushEvent in project cx-flow by checkmarx-ltd.

the class BitbucketServerController method pushRequest.

/**
 * Receive Push event submitted from Bitbucket
 */
@PostMapping(value = { "/{product}", "/" }, headers = PUSH)
public ResponseEntity<EventResponse> pushRequest(@RequestBody String body, @PathVariable(value = "product", required = false) String product, @RequestHeader(value = SIGNATURE) String signature, ControllerRequest controllerRequest) {
    String uid = helperService.getShortUid();
    MDC.put(FlowConstants.MAIN_MDC_ENTRY, uid);
    log.info("Processing BitBucket PUSH request");
    verifyHmacSignature(body, signature);
    ObjectMapper mapper = new ObjectMapper();
    PushEvent event;
    try {
        event = mapper.readValue(body, PushEvent.class);
    } catch (IOException e) {
        throw new MachinaRuntimeException(e);
    }
    if (event.getChanges().get(0).getType().equalsIgnoreCase("DELETE")) {
        log.info("Push event is associated with a Delete branch event...ignoring request");
        return handleDeleteEvent(body, uid, event, signature, product, controllerRequest);
    }
    String application = event.getRepository().getName();
    if (!ScanUtils.empty(controllerRequest.getApplication())) {
        application = controllerRequest.getApplication();
    }
    if (ScanUtils.empty(product)) {
        product = ScanRequest.Product.CX.getProduct();
    }
    BitbucketServerEventHandler handler = BitbucketServerPushHandler.builder().controllerRequest(controllerRequest).branchFromRef(event.getChanges().get(INDEX_FROM_CHANGES).getRefId()).toHash(event.getChanges().get(INDEX_FROM_CHANGES).getToHash()).email(event.getActor().getEmailAddress()).fromProjectKey(event.getRepository().getProject().getKey()).fromSlug(event.getRepository().getSlug()).toProjectKey(event.getRepository().getProject().getKey()).toSlug(event.getRepository().getSlug()).repositoryName(event.getRepository().getName()).refId(event.getChanges().get(INDEX_FROM_CHANGES).getRefId()).browseUrl(event.getRepository().getLinks().getSelf().get(INDEX_FROM_SELF).getHref()).webhookPayload(body).configProvider(this).product(product).application(application).build();
    return handler.execute(uid);
}
Also used : PushEvent(com.checkmarx.flow.dto.bitbucketserver.PushEvent) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) BitbucketServerEventHandler(com.checkmarx.flow.handlers.bitbucket.server.BitbucketServerEventHandler) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

PushEvent (com.checkmarx.flow.dto.bitbucketserver.PushEvent)1 MachinaRuntimeException (com.checkmarx.flow.exception.MachinaRuntimeException)1 BitbucketServerEventHandler (com.checkmarx.flow.handlers.bitbucket.server.BitbucketServerEventHandler)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1