Search in sources :

Example 1 with PullEvent

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

the class BitbucketServerController method doMergeEvent.

private ResponseEntity<EventResponse> doMergeEvent(String body, String product, String signature, ControllerRequest controllerRequest) {
    String uid = helperService.getShortUid();
    MDC.put(FlowConstants.MAIN_MDC_ENTRY, uid);
    log.info("Processing BitBucket MERGE request");
    verifyHmacSignature(body, signature);
    ObjectMapper mapper = new ObjectMapper();
    PullEvent event;
    try {
        event = mapper.readValue(body, PullEvent.class);
        log.debug("Successfully consumed request payload : {}", body);
    } catch (IOException e) {
        log.debug("Error occurred while consuming request payload, body {}, error {}", body, e);
        throw new MachinaRuntimeException(e);
    }
    String application = event.getPullRequest().getFromRef().getRepository().getName();
    if (!ScanUtils.empty(controllerRequest.getApplication())) {
        application = controllerRequest.getApplication();
    }
    if (ScanUtils.empty(product)) {
        product = ScanRequest.Product.CX.getProduct();
    }
    BitbucketServerEventHandler handler = BitbucketServerMergeHandler.builder().controllerRequest(controllerRequest).application(application).currentBranch(event.getPullRequest().getFromRef().getDisplayId()).targetBranch(event.getPullRequest().getToRef().getDisplayId()).fromRefLatestCommit(event.getPullRequest().getFromRef().getLatestCommit()).fromProjectKey(event.getPullRequest().getFromRef().getRepository().getProject().getKey()).fromSlug(event.getPullRequest().getFromRef().getRepository().getSlug()).toProjectKey(event.getPullRequest().getToRef().getRepository().getProject().getKey()).toSlug(event.getPullRequest().getToRef().getRepository().getSlug()).pullRequestId(event.getPullRequest().getId().toString()).repositoryName(event.getPullRequest().getFromRef().getRepository().getName()).refId(event.getPullRequest().getFromRef().getId()).browseUrl(event.getPullRequest().getFromRef().getRepository().getLinks().getSelf().get(INDEX_FROM_SELF).getHref()).webhookPayload(body).configProvider(this).product(product).build();
    return handler.execute(uid);
}
Also used : MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) BitbucketServerEventHandler(com.checkmarx.flow.handlers.bitbucket.server.BitbucketServerEventHandler) PullEvent(com.checkmarx.flow.dto.bitbucketserver.PullEvent) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

PullEvent (com.checkmarx.flow.dto.bitbucketserver.PullEvent)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