Search in sources :

Example 1 with GitlabClient

use of com.epam.pipeline.manager.git.GitlabClient in project cloud-pipeline by epam.

the class SystemPreferences method areGitPreferencesValid.

private boolean areGitPreferencesValid(Map<String, Preference> gitPreferences) {
    long adminId = Long.parseLong(gitPreferences.get(GIT_USER_ID.getKey()).getValue());
    GitlabClient client = gitManager.getGitlabClient(gitPreferences.get(GIT_HOST.getKey()).getValue(), gitPreferences.get(GIT_TOKEN.getKey()).getValue(), adminId, gitPreferences.get(GIT_USER_NAME.getKey()).getValue());
    client.buildCloneCredentials(false, false, 1L);
    try {
        GitlabVersion version = client.getVersion();
        Matcher matcher = GIT_VERSION_PATTERN.matcher(version.getVersion());
        if (matcher.find()) {
            Integer major = Integer.parseInt(matcher.group(1));
            Integer minor = Integer.parseInt(matcher.group(2));
            if ((major == 9 && minor >= 5) || (major == 8 && minor < 3)) {
                throw new IllegalArgumentException("Invalid git version: " + version.getVersion());
            }
        } else {
            throw new IllegalArgumentException("Invalid git version: " + version.getVersion());
        }
    } catch (GitClientException e) {
        throw new IllegalArgumentException("Could not request Gitlab version", e);
    }
    return true;
}
Also used : GitlabClient(com.epam.pipeline.manager.git.GitlabClient) GitlabVersion(com.epam.pipeline.entity.git.GitlabVersion) Matcher(java.util.regex.Matcher) GitClientException(com.epam.pipeline.exception.git.GitClientException)

Aggregations

GitlabVersion (com.epam.pipeline.entity.git.GitlabVersion)1 GitClientException (com.epam.pipeline.exception.git.GitClientException)1 GitlabClient (com.epam.pipeline.manager.git.GitlabClient)1 Matcher (java.util.regex.Matcher)1