use of com.checkmarx.flow.dto.azure.AdoDetailsRequest in project cx-flow by checkmarx-ltd.
the class TfsController method pullPushRequest.
@PostMapping(value = { "/{product}/tfs/pull", "/tfs/pull", "/{product}/tfs/push", "/tfs/push" })
public ResponseEntity<EventResponse> pullPushRequest(HttpServletRequest httpRequest, @RequestBody PullEvent body, @RequestHeader(value = AUTHORIZATION) String auth, @PathVariable(value = "product", required = false) String product, ControllerRequest controllerRequest, AdoDetailsRequest adoDetailsRequest) {
String action = getAction(httpRequest);
String uid = helperService.getShortUid();
MDC.put(FlowConstants.MAIN_MDC_ENTRY, uid);
if (log.isInfoEnabled()) {
log.info(String.format("Processing TFS %s request", action));
}
validateBasicAuth(auth);
Resource resource = body.getResource();
controllerRequest = ensureNotNull(controllerRequest);
adoDetailsRequest = ensureDetailsNotNull(adoDetailsRequest);
if (ACTION_PULL.equals(action) && !body.getEventType().equals(PULL_EVENT)) {
log.info("Pull requested not processed. Event was not 'opened' ({})", body.getEventType());
return ResponseEntity.accepted().body(EventResponse.builder().message("No processing occurred for updates to Pull Request").success(true).build());
}
FlowOverride o = ScanUtils.getMachinaOverride(Optional.ofNullable(controllerRequest.getOverride()).orElse(null));
Repository repository = resource.getRepository();
String app = repository.getName();
if (app.startsWith(properties.getTestRepository())) {
log.info("Handling TFS Test Event");
return ResponseEntity.ok(EventResponse.builder().message("Test Event").success(true).build());
}
Optional.ofNullable(controllerRequest.getAppOnly()).ifPresent(flowProperties::setTrackApplicationOnly);
FilterConfiguration filter = filterFactory.getFilter(controllerRequest, flowProperties);
ScanRequestBuilder requestBuilder = ScanRequest.builder().application(Optional.ofNullable(controllerRequest.getApplication()).orElse(app)).product(getProductForName(product)).project(Optional.ofNullable(controllerRequest.getProject()).orElse(null)).team(Optional.ofNullable(controllerRequest.getTeam()).orElse(null)).namespace(repository.getProject().getName().replace(" ", "_")).repoName(repository.getName()).repoType(ScanRequest.Repository.ADO).scanPreset(controllerRequest.getPreset()).incremental(controllerRequest.getIncremental()).excludeFolders(controllerRequest.getExcludeFolders()).excludeFiles(controllerRequest.getExcludeFiles()).filter(filter);
if (ACTION_PULL.equals(action)) {
BugTracker.Type bugType = Optional.ofNullable(controllerRequest.getBug()).map(theBug -> ScanUtils.getBugTypeEnum(theBug, flowProperties.getBugTrackerImpl())).orElse(BugTracker.Type.ADOPULL);
Optional.ofNullable(controllerRequest.getAppOnly()).ifPresent(flowProperties::setTrackApplicationOnly);
BugTracker bugTracker = ScanUtils.getBugTracker(Optional.ofNullable(controllerRequest.getAssignee()).orElse(null), bugType, jiraProperties, Optional.ofNullable(controllerRequest.getBug()).orElse(null));
requestBuilder.refs(resource.getSourceRefName()).repoUrl(repository.getWebUrl()).repoUrlWithAuth(addTokenToUrl(repository.getWebUrl(), properties.getToken())).mergeNoteUri(resource.getUrl().concat("/threads")).branch(ScanUtils.getBranchFromRef(resource.getSourceRefName())).mergeTargetBranch(ScanUtils.getBranchFromRef(resource.getTargetRefName())).email(null).bugTracker(bugTracker);
} else if (ACTION_PUSH.equals(action)) {
String bug = Optional.ofNullable(controllerRequest.getBug()).orElse(flowProperties.getBugTracker());
BugTracker.Type bugType = ScanUtils.getBugTypeEnum(bug, flowProperties.getBugTrackerImpl());
BugTracker bugTracker = ScanUtils.getBugTracker(Optional.ofNullable(controllerRequest.getAssignee()).orElse(null), bugType, jiraProperties, Optional.ofNullable(controllerRequest.getBug()).orElse(null));
requestBuilder.refs(resource.getRefUpdates().get(0).getName()).repoUrl(repository.getRemoteUrl()).repoUrlWithAuth(addTokenToUrl(repository.getRemoteUrl(), properties.getToken())).branch(ScanUtils.getBranchFromRef(resource.getRefUpdates().get(0).getName())).defaultBranch(repository.getDefaultBranch()).email(determineEmails(resource)).bugTracker(bugTracker);
}
ScanRequest request = requestBuilder.build();
request = configOverrider.overrideScanRequestProperties(o, request);
if (ACTION_PULL.equals(action)) {
request.putAdditionalMetadata("statuses_url", resource.getUrl().concat("/statuses"));
}
addMetadataToScanRequest(adoDetailsRequest, request);
request.putAdditionalMetadata(HTMLHelper.WEB_HOOK_PAYLOAD, body.toString());
request.setId(uid);
// only initiate scan/automation if target branch is applicable
List<String> branches = new ArrayList<>();
Optional<List<String>> branch = Optional.ofNullable(controllerRequest.getBranch());
if (branch.isPresent()) {
branches.addAll(branch.get());
} else if (CollectionUtils.isNotEmpty(flowProperties.getBranches())) {
branches.addAll(flowProperties.getBranches());
}
if (helperService.isBranch2Scan(request, branches)) {
flowService.initiateAutomation(request);
}
return ResponseEntity.accepted().body(EventResponse.builder().message("Scan Request Successfully Submitted").success(true).build());
}
Aggregations