use of com.hp.octane.integrations.dto.events.CIEventType in project octane-gitlab-service by MicroFocus.
the class EventListener method getCIEvents.
private List<CIEvent> getCIEvents(JSONObject event) {
List<CIEvent> events = new ArrayList<>();
CIEventType eventType = getEventType(event);
Integer buildCiId = getEventTargetObjectId(event);
Object duration = getDuration(event);
Long startTime = getStartTime(event, duration);
SCMData scmData = null;
boolean isScmNull = true;
if (isPipelineEvent(event)) {
if (eventType == CIEventType.STARTED) {
scmData = getScmData(event);
isScmNull = scmData == null;
} else {
String GITLAB_BLANK_SHA = "0000000000000000000000000000000000000000";
isScmNull = event.getJSONObject("object_attributes").getString("before_sha").equals(GITLAB_BLANK_SHA);
}
}
events.add(dtoFactory.newDTO(CIEvent.class).setProjectDisplayName(getCiDisplayName(event)).setEventType(eventType).setBuildCiId(buildCiId.toString()).setNumber(buildCiId.toString()).setProject(getCiFullName(event)).setResult(eventType == CIEventType.STARTED || eventType == CIEventType.DELETED ? null : convertCiBuildResult(getStatus(event))).setStartTime(startTime).setEstimatedDuration(null).setDuration(calculateDuration(eventType, duration)).setScmData(null).setCauses(getCauses(event, isScmNull)).setPhaseType(isPipelineEvent(event) ? PhaseType.POST : PhaseType.INTERNAL));
if (scmData != null) {
events.add(dtoFactory.newDTO(CIEvent.class).setProjectDisplayName(getCiDisplayName(event)).setEventType(CIEventType.SCM).setBuildCiId(buildCiId.toString()).setNumber(null).setProject(getCiFullName(event)).setResult(null).setStartTime(null).setEstimatedDuration(null).setDuration(null).setScmData(scmData).setCauses(getCauses(event, false)).setPhaseType(null));
}
return events;
}
use of com.hp.octane.integrations.dto.events.CIEventType in project octane-gitlab-service by MicroFocus.
the class EventListener method handleEvent.
private Response handleEvent(JSONObject event) {
log.traceEntry();
try {
if (isMergeRequestEvent(event)) {
return handleMergeRequestEvent(event);
}
CIEventType eventType = getEventType(event);
if (eventType == CIEventType.UNDEFINED || eventType == CIEventType.QUEUED)
return Response.ok().build();
List<CIEvent> eventList = getCIEvents(event);
eventList.forEach(ciEvent -> {
if (ciEvent.getResult() == null) {
ciEvent.setResult(CIBuildResult.UNAVAILABLE);
}
try {
log.trace(new ObjectMapper().writeValueAsString(ciEvent));
} catch (Exception e) {
log.debug("Failed to trace an incoming event", e);
}
if (eventType == CIEventType.FINISHED || eventType == CIEventType.STARTED) {
ParsedPath parsedPath = null;
if (ciEvent.getProject().endsWith("/build")) {
parsedPath = new ParsedPath(ciEvent.getProject().substring(0, ciEvent.getProject().length() - 6), gitLabApi, PathType.PROJECT);
if (parsedPath.isMultiBranch()) {
ciEvent.setSkipValidation(true);
}
}
if (ciEvent.getProject().contains(ParsedPath.PIPELINE_JOB_CI_ID_PREFIX)) {
parsedPath = new ParsedPath(ciEvent.getProject(), gitLabApi, PathType.PIPELINE);
if (parsedPath.isMultiBranch()) {
String projectDisplayName = parsedPath.getNameWithNameSpaceForDisplayName() != null ? parsedPath.getNameWithNameSpaceForDisplayName() : parsedPath.getFullPathOfProjectWithBranch();
ciEvent.setProjectDisplayName(projectDisplayName + "/" + parsedPath.getCurrentBranch());
ciEvent.setParentCiId(parsedPath.getJobCiId(true)).setMultiBranchType(MultiBranchType.MULTI_BRANCH_CHILD).setSkipValidation(true);
}
}
if (isPipelineEvent(event)) {
List<CIParameter> parametersList = new ArrayList<>();
JSONArray variablesList = VariablesHelper.getVariablesListFromPipelineEvent(event);
// check if this parameter is in job level:
List<Variable> allVariables = VariablesHelper.getVariables(parsedPath, gitLabApi, applicationSettings.getConfig());
variablesList.forEach(var -> {
parametersList.add(VariablesHelper.convertVariableToParameter(var));
});
if (parametersList.size() > 0) {
ciEvent.setParameters(parametersList);
}
}
}
OctaneSDK.getClients().forEach(client -> client.getEventsService().publishEvent(ciEvent));
});
if (eventType == CIEventType.FINISHED) {
Integer projectId = isPipelineEvent(event) ? event.getJSONObject("project").getInt("id") : event.getInt("project_id");
if (!isPipelineEvent(event)) {
Project project = gitLabApi.getProjectApi().getProject(projectId);
Integer jobId = getEventTargetObjectId(event);
Job job = gitLabApi.getJobApi().getJob(projectId, jobId);
if (job.getArtifactsFile() != null) {
sendCodeCoverage(projectId, project, job);
GherkinTestResultsProvider gherkinTestResultsProvider = GherkinTestResultsProvider.getInstance(applicationSettings);
boolean isGherkinTestsExist = gherkinTestResultsProvider.createTestList(project, job, gitLabApi.getJobApi().downloadArtifactsFile(projectId, job.getId()));
// looking for Regular tests
if (!isGherkinTestsExist) {
JunitTestResultsProvider testResultsProduce = JunitTestResultsProvider.getInstance(applicationSettings);
boolean testResultsExist = testResultsProduce.createTestList(project, job, gitLabApi.getJobApi().downloadArtifactsFile(projectId, job.getId()));
if (!testResultsExist) {
String warning = String.format("No test results found by using the %s pattern", applicationSettings.getConfig().getGitlabTestResultsFilePattern());
log.warn(warning);
return Response.ok().entity(warning).build();
}
}
}
}
}
} catch (Exception e) {
log.warn("An error occurred while handling GitLab event", e);
}
log.traceExit();
return Response.ok().build();
}
Aggregations