Search in sources :

Example 1 with CIBuildStatus

use of com.hp.octane.integrations.dto.snapshots.CIBuildStatus in project octane-gitlab-service by MicroFocus.

the class OctaneServices method getJobBuildStatus.

@Override
public CIBuildStatusInfo getJobBuildStatus(String jobCiId, String parameterName, String parameterValue) {
    ParsedPath parsedPath = new ParsedPath(jobCiId, gitLabApi, PathType.PIPELINE);
    try {
        List<Pipeline> pipelines = gitLabApi.getPipelineApi().getPipelines(parsedPath.getPathWithNameSpace());
        Optional<Pipeline> chosenPipeline = pipelines.stream().map(pipeline -> {
            try {
                List<Variable> pipelineVariables = gitLabApi.getPipelineApi().getPipelineVariables(parsedPath.getPathWithNameSpace(), pipeline.getId());
                for (Variable variable : pipelineVariables) {
                    if (variable.getKey().equals(parameterName) && variable.getValue().equals(parameterValue)) {
                        return pipeline;
                    }
                }
                return null;
            } catch (GitLabApiException e) {
                log.error("Failed to get variables from pipeline", e);
                throw new RuntimeException(e);
            }
        }).filter(Objects::nonNull).findAny();
        if (chosenPipeline.isPresent()) {
            String status = chosenPipeline.get().getStatus().toValue();
            CIBuildStatus currentCIBuildStatus = getCIBuildStatus(status);
            Optional<CIBuildStatus> buildStatus = Arrays.stream(CIBuildStatus.values()).filter(ciBuildStatus -> Objects.equals(ciBuildStatus, currentCIBuildStatus)).findAny();
            if (!buildStatus.isPresent()) {
                throw new RuntimeException("Failed to get the correct build status");
            }
            return dtoFactory.newDTO(CIBuildStatusInfo.class).setJobCiId(jobCiId).setBuildStatus(buildStatus.get()).setBuildCiId(getBuildCiId(chosenPipeline.get())).setParamName(parameterName).setParamValue(parameterValue).setResult(getCiBuildResult(status));
        }
        throw new RuntimeException("Failed to get information about the pipeline");
    } catch (GitLabApiException e) {
        log.error("Failed to get job build status of the pipeline run", e);
        throw new RuntimeException(e);
    }
}
Also used : java.util(java.util) com.hp.octane.integrations.dto.tests(com.hp.octane.integrations.dto.tests) CIBuildStatus(com.hp.octane.integrations.dto.snapshots.CIBuildStatus) Branch(org.gitlab4j.api.models.Branch) Job(org.gitlab4j.api.models.Job) URL(java.net.URL) EncodeCiJobBase64Parameter(com.hp.octane.integrations.services.configurationparameters.EncodeCiJobBase64Parameter) HttpStatus(org.apache.http.HttpStatus) Autowired(org.springframework.beans.factory.annotation.Autowired) Scope(org.springframework.context.annotation.Scope) Variable(org.gitlab4j.api.models.Variable) ConfigStructure(com.microfocus.octane.gitlab.model.ConfigStructure) TestResultsHelper(com.microfocus.octane.gitlab.helpers.TestResultsHelper) CIParameter(com.hp.octane.integrations.dto.parameters.CIParameter) DTOFactory(com.hp.octane.integrations.dto.DTOFactory) PipelineNode(com.hp.octane.integrations.dto.pipelines.PipelineNode) CIBuildResult(com.hp.octane.integrations.dto.snapshots.CIBuildResult) CIBuildStatusInfo(com.hp.octane.integrations.dto.general.CIBuildStatusInfo) PermissionException(com.hp.octane.integrations.exceptions.PermissionException) PREFIX(com.microfocus.octane.gitlab.helpers.PasswordEncryption.PREFIX) CIServerInfo(com.hp.octane.integrations.dto.general.CIServerInfo) CIPluginServices(com.hp.octane.integrations.CIPluginServices) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) JunitTestResultsProvider(com.microfocus.octane.gitlab.testresults.JunitTestResultsProvider) Application(com.microfocus.octane.gitlab.app.Application) Pipeline(org.gitlab4j.api.models.Pipeline) ApplicationSettings(com.microfocus.octane.gitlab.app.ApplicationSettings) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) CIPluginInfo(com.hp.octane.integrations.dto.general.CIPluginInfo) Component(org.springframework.stereotype.Component) Logger(org.apache.logging.log4j.Logger) OctaneConfiguration(com.hp.octane.integrations.OctaneConfiguration) CIParameters(com.hp.octane.integrations.dto.parameters.CIParameters) java.io(java.io) CIJobsList(com.hp.octane.integrations.dto.general.CIJobsList) GitLabApiException(org.gitlab4j.api.GitLabApiException) com.microfocus.octane.gitlab.helpers(com.microfocus.octane.gitlab.helpers) ConfigurationParameterFactory(com.hp.octane.integrations.services.configurationparameters.factory.ConfigurationParameterFactory) LogManager(org.apache.logging.log4j.LogManager) CIProxyConfiguration(com.hp.octane.integrations.dto.configuration.CIProxyConfiguration) GitLabApi(org.gitlab4j.api.GitLabApi) CIBuildStatus(com.hp.octane.integrations.dto.snapshots.CIBuildStatus) Variable(org.gitlab4j.api.models.Variable) GitLabApiException(org.gitlab4j.api.GitLabApiException) Pipeline(org.gitlab4j.api.models.Pipeline)

Aggregations

CIPluginServices (com.hp.octane.integrations.CIPluginServices)1 OctaneConfiguration (com.hp.octane.integrations.OctaneConfiguration)1 DTOFactory (com.hp.octane.integrations.dto.DTOFactory)1 CIProxyConfiguration (com.hp.octane.integrations.dto.configuration.CIProxyConfiguration)1 CIBuildStatusInfo (com.hp.octane.integrations.dto.general.CIBuildStatusInfo)1 CIJobsList (com.hp.octane.integrations.dto.general.CIJobsList)1 CIPluginInfo (com.hp.octane.integrations.dto.general.CIPluginInfo)1 CIServerInfo (com.hp.octane.integrations.dto.general.CIServerInfo)1 CIParameter (com.hp.octane.integrations.dto.parameters.CIParameter)1 CIParameters (com.hp.octane.integrations.dto.parameters.CIParameters)1 PipelineNode (com.hp.octane.integrations.dto.pipelines.PipelineNode)1 CIBuildResult (com.hp.octane.integrations.dto.snapshots.CIBuildResult)1 CIBuildStatus (com.hp.octane.integrations.dto.snapshots.CIBuildStatus)1 com.hp.octane.integrations.dto.tests (com.hp.octane.integrations.dto.tests)1 PermissionException (com.hp.octane.integrations.exceptions.PermissionException)1 EncodeCiJobBase64Parameter (com.hp.octane.integrations.services.configurationparameters.EncodeCiJobBase64Parameter)1 ConfigurationParameterFactory (com.hp.octane.integrations.services.configurationparameters.factory.ConfigurationParameterFactory)1 Application (com.microfocus.octane.gitlab.app.Application)1 ApplicationSettings (com.microfocus.octane.gitlab.app.ApplicationSettings)1 com.microfocus.octane.gitlab.helpers (com.microfocus.octane.gitlab.helpers)1