use of org.gitlab4j.api.models.Variable in project octane-gitlab-service by MicroFocus.
the class MergeRequestHistoryHandler method executeFirstScan.
public void executeFirstScan() {
try {
List<Project> gitLabProjects = gitLabApi.getProjectApi().getProjects().stream().filter(project -> {
Map<String, String> projectGroupVariables = VariablesHelper.getProjectGroupVariables(gitLabApi, project);
Optional<Variable> shouldPublishToOctane = VariablesHelper.getProjectVariable(gitLabApi, project.getId(), applicationSettings.getConfig().getPublishMergeRequestsVariableName());
return (shouldPublishToOctane.isPresent() && Boolean.parseBoolean(shouldPublishToOctane.get().getValue())) || (projectGroupVariables.containsKey(applicationSettings.getConfig().getPublishMergeRequestsVariableName()) && Boolean.parseBoolean(projectGroupVariables.get(applicationSettings.getConfig().getPublishMergeRequestsVariableName())));
}).collect(Collectors.toList());
gitLabProjects.forEach(project -> {
try {
Path pathToFile = Paths.get(watchPath.toString() + "/" + project.getId());
if (!Files.exists(pathToFile)) {
sendMergeRequestsToOctane(project);
Files.createFile(pathToFile);
}
} catch (GitLabApiException | IOException e) {
log.warn(e.getMessage(), e);
}
});
} catch (GitLabApiException e) {
log.error(e.getMessage(), e);
}
}
use of org.gitlab4j.api.models.Variable in project octane-gitlab-service by MicroFocus.
the class VariablesHelper method convertJSONArrayToVariables.
public static List<Variable> convertJSONArrayToVariables(JSONArray jsonVariablesList) {
List<Variable> variableList = new ArrayList<>();
jsonVariablesList.forEach(variable -> {
Variable var = new Variable();
var.setKey(((JSONObject) variable).getString("key"));
var.setValue(((JSONObject) variable).getString("value"));
// var.setProtected(((JSONObject) variable).getString("protected"));
variableList.add(var);
});
return variableList;
}
use of org.gitlab4j.api.models.Variable in project choerodon-starters by open-hand.
the class PipelineApi method createPipelineScheduleVariable.
/**
* Create a pipeline schedule variable.
*
* <pre><code>GitLab Endpoint: POST /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables</code></pre>
*
* @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
* @param pipelineScheduleId the pipelineSchedule ID
* @param key the key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed
* @param value the value for the variable
* @return a Pipeline instance with the newly created pipeline schedule variable
* @throws GitLabApiException if any exception occurs during execution
*/
public Variable createPipelineScheduleVariable(Object projectIdOrPath, Integer pipelineScheduleId, String key, String value) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("key", key, true).withParam("value", value, true);
Response response = post(Response.Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "pipeline_schedules", pipelineScheduleId, "variables");
return (response.readEntity(Variable.class));
}
use of org.gitlab4j.api.models.Variable in project octane-gitlab-service by MicroFocus.
the class GitlabServices method getParameters.
public List<CIParameter> getParameters(ParsedPath project) {
List<CIParameter> parametersList = new ArrayList<>();
List<Variable> projectVariables = VariablesHelper.getVariables(project, gitLabApi, applicationSettings.getConfig());
projectVariables.forEach(var -> {
CIParameter param = dtoFactory.newDTO(CIParameter.class);
param.setType(CIParameterType.STRING);
param.setName(var.getKey());
param.setDefaultValue(var.getValue());
parametersList.add(param);
});
return parametersList;
}
use of org.gitlab4j.api.models.Variable 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);
}
}
Aggregations