Search in sources :

Example 1 with BitbucketServerPullRequestEvent

use of com.checkmarx.flow.dto.bitbucketserver.plugin.postwebhook.BitbucketServerPullRequestEvent in project cx-flow by checkmarx-ltd.

the class PostWebhookController method doMerge.

private ResponseEntity<EventResponse> doMerge(String body, String product, String credentials, String token, ControllerRequest controllerRequest, String eventType) {
    String uid = helperService.getShortUid();
    MDC.put(FlowConstants.MAIN_MDC_ENTRY, uid);
    log.info("Processing BitBucket(Post Web Hook) {} request", eventType);
    validateCredentials(credentials, token);
    ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    BitbucketServerPullRequestEvent event;
    try {
        event = mapper.readValue(body, BitbucketServerPullRequestEvent.class);
    } catch (IOException e) {
        throw new MachinaRuntimeException(e);
    }
    String application = event.getPullrequest().getFromRef().getRepository().getSlug();
    if (!ScanUtils.empty(controllerRequest.getApplication())) {
        application = controllerRequest.getApplication();
    }
    if (ScanUtils.empty(product)) {
        product = ScanRequest.Product.CX.getProduct();
    }
    BitbucketServerEventHandler handler = BitbucketServerMergeHandler.builder().controllerRequest(controllerRequest).currentBranch(event.getPullrequest().getFromRef().getBranch().getName()).targetBranch(event.getPullrequest().getToRef().getBranch().getName()).fromRefLatestCommit(event.getPullrequest().getFromRef().getCommit().getHash()).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()).repositoryName(event.getPullrequest().getFromRef().getRepository().getSlug()).refId(event.getPullrequest().getFromRef().getBranch().getName()).browseUrl(event.getPullrequest().getFromRef().getRepository().getLinks().get("self").get(BROWSE_URL_INDEX).getHref()).webhookPayload(body).configProvider(this).product(product).application(application).build();
    return handler.execute(uid);
}
Also used : BitbucketServerPullRequestEvent(com.checkmarx.flow.dto.bitbucketserver.plugin.postwebhook.BitbucketServerPullRequestEvent) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) BitbucketServerEventHandler(com.checkmarx.flow.handlers.bitbucket.server.BitbucketServerEventHandler) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

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