Search in sources :

Example 1 with Pullrequest

use of com.checkmarx.flow.dto.bitbucket.Pullrequest in project cx-flow by checkmarx-ltd.

the class BitbucketCloudController method handleMergeEvent.

public ResponseEntity<EventResponse> handleMergeEvent(MergeEvent body, String product, ControllerRequest controllerRequest, String token) {
    log.debug("Merge Request body contents are {}", body.toString());
    String uid = helperService.getShortUid();
    MDC.put(FlowConstants.MAIN_MDC_ENTRY, uid);
    validateBitBucketRequest(token);
    log.info("Processing BitBucket MERGE request");
    controllerRequest = ensureNotNull(controllerRequest);
    try {
        Repository repository = body.getRepository();
        String app = repository.getName();
        if (!ScanUtils.empty(controllerRequest.getApplication())) {
            app = controllerRequest.getApplication();
        }
        BugTracker.Type bugType = BugTracker.Type.BITBUCKETPULL;
        if (!ScanUtils.empty(controllerRequest.getBug())) {
            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));
        Pullrequest pullRequest = body.getPullrequest();
        String currentBranch = pullRequest.getSource().getBranch().getName();
        String targetBranch = pullRequest.getDestination().getBranch().getName();
        List<String> branches = getBranches(controllerRequest, flowProperties);
        String hash = pullRequest.getSource().getCommit().getHash();
        BugTracker bt = ScanUtils.getBugTracker(controllerRequest.getAssignee(), bugType, jiraProperties, controllerRequest.getBug());
        FilterConfiguration filter = filterFactory.getFilter(controllerRequest, flowProperties);
        String gitUrl = repository.getLinks().getHtml().getHref().concat(".git");
        String configToken = scmConfigOverrider.determineConfigToken(properties, controllerRequest.getScmInstance());
        String gitAuthUrl = gitAuthUrlGenerator.addCredToUrl(ScanRequest.Repository.BITBUCKET, gitUrl, configToken);
        String mergeEndpoint = pullRequest.getLinks().getComments().getHref();
        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).mergeTargetBranch(targetBranch).mergeNoteUri(mergeEndpoint).refs(Constants.CX_BRANCH_PREFIX.concat(currentBranch)).email(null).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();
}
Also used : ScanRequest(com.checkmarx.flow.dto.ScanRequest) Repository(com.checkmarx.flow.dto.bitbucket.Repository) FilterConfiguration(com.checkmarx.sdk.dto.filtering.FilterConfiguration) BugTracker(com.checkmarx.flow.dto.BugTracker) Pullrequest(com.checkmarx.flow.dto.bitbucket.Pullrequest)

Aggregations

BugTracker (com.checkmarx.flow.dto.BugTracker)1 ScanRequest (com.checkmarx.flow.dto.ScanRequest)1 Pullrequest (com.checkmarx.flow.dto.bitbucket.Pullrequest)1 Repository (com.checkmarx.flow.dto.bitbucket.Repository)1 FilterConfiguration (com.checkmarx.sdk.dto.filtering.FilterConfiguration)1