use of com.microfocus.octane.gitlab.helpers.ParsedPath in project octane-gitlab-service by MicroFocus.
the class GitlabServices method createStructure.
PipelineNode createStructure(String buildId) {
ParsedPath project = new ParsedPath(buildId, gitLabApi, PathType.MULTI_BRUNCH);
// add a webhook to new Octane pipeline (gitlab project) in Octane
try {
if (project.isMultiBranch()) {
addWebHookToProject(project.getFullPathOfProject(), true);
return dtoFactory.newDTO(PipelineNode.class).setJobCiId(project.getJobCiId(true)).setMultiBranchType(MultiBranchType.MULTI_BRANCH_PARENT).setName(project.getNameWithNameSpaceForDisplayName()).setParameters(getParameters(project));
}
project = new ParsedPath(buildId, gitLabApi, PathType.PIPELINE);
addWebHookToProject(project.getId(), true);
return dtoFactory.newDTO(PipelineNode.class).setJobCiId(project.getJobCiId(false)).setName(project.getNameWithNameSpaceForDisplayName()).setParameters(getParameters(project));
} catch (GitLabApiException e) {
log.error("unable to update webhook when create a pipeline in Octane for project:" + project.getDisplayName(), e);
return null;
}
}
use of com.microfocus.octane.gitlab.helpers.ParsedPath in project octane-gitlab-service by MicroFocus.
the class GitlabServices method getJobList.
CIJobsList getJobList() {
CIJobsList ciJobsList = dtoFactory.newDTO(CIJobsList.class);
List<PipelineNode> list = new ArrayList<>();
String projectNames = "";
try {
ProjectFilter filter = new ProjectFilter();
filter.withMinAccessLevel(AccessLevel.MAINTAINER);
List<Project> projectsFilters = gitLabApi.getProjectApi().getProjects(filter);
log.info("There are only " + projectsFilters.size() + " projects with access level => MAINTAINER for the integrated user");
for (Project project : projectsFilters) {
try {
ParsedPath parseProject = new ParsedPath(project, gitLabApi);
PipelineNode buildConf;
if (parseProject.isMultiBranch()) {
buildConf = dtoFactory.newDTO(PipelineNode.class).setJobCiId(parseProject.getJobCiId(true)).setName(project.getNameWithNamespace()).setMultiBranchType(MultiBranchType.MULTI_BRANCH_PARENT);
} else {
buildConf = dtoFactory.newDTO(PipelineNode.class).setJobCiId(parseProject.getJobCiId(false)).setName(project.getNameWithNamespace());
}
projectNames = projectNames + buildConf.getName() + ",";
list.add(buildConf);
} catch (Exception e) {
log.warn("Failed to add some tags to the job list", e);
}
}
} catch (Exception e) {
log.warn("Failed to add some jobs to the job list", e);
}
log.info("getJobList results:" + projectNames);
ciJobsList.setJobs(list.toArray(new PipelineNode[list.size()]));
return ciJobsList;
}
use of com.microfocus.octane.gitlab.helpers.ParsedPath 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