Search in sources :

Example 1 with GitlabVersion

use of com.epam.pipeline.entity.git.GitlabVersion in project cloud-pipeline by epam.

the class SystemPreferencesValidationTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    Assert.assertNotNull(preferences);
    supportedVersion = new GitlabVersion();
    supportedVersion.setVersion("9.0");
    unsupportedVersion = new GitlabVersion();
    unsupportedVersion.setVersion("9.5");
    Mockito.when(gitManager.getGitlabClient(anyString(), anyString(), Mockito.anyLong(), anyString())).thenReturn(mockGitlabClient);
}
Also used : GitlabVersion(com.epam.pipeline.entity.git.GitlabVersion) Before(org.junit.Before)

Example 2 with GitlabVersion

use of com.epam.pipeline.entity.git.GitlabVersion in project cloud-pipeline by epam.

the class GitlabClient method getVersion.

/**
 * Loads Gitlab version information
 * @return a GitlabVersion object
 * @throws GitClientException
 */
public GitlabVersion getVersion() throws GitClientException {
    try {
        URI uri = new URI(String.format(GITLAB_VERSION_URL, gitHost));
        ResponseEntity<GitlabVersion> versionResponse = new RestTemplate().exchange(uri, HttpMethod.GET, getAuthHeaders(), GitlabVersion.class);
        if (versionResponse.getStatusCode() == HttpStatus.OK) {
            return versionResponse.getBody();
        } else {
            throw new UnexpectedResponseStatusException(versionResponse.getStatusCode());
        }
    } catch (URISyntaxException e) {
        throw new GitClientException(e.getMessage(), e);
    }
}
Also used : GitlabVersion(com.epam.pipeline.entity.git.GitlabVersion) UnexpectedResponseStatusException(com.epam.pipeline.exception.git.UnexpectedResponseStatusException) RestTemplate(org.springframework.web.client.RestTemplate) GitClientException(com.epam.pipeline.exception.git.GitClientException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 3 with GitlabVersion

use of com.epam.pipeline.entity.git.GitlabVersion 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)3 GitClientException (com.epam.pipeline.exception.git.GitClientException)2 UnexpectedResponseStatusException (com.epam.pipeline.exception.git.UnexpectedResponseStatusException)1 GitlabClient (com.epam.pipeline.manager.git.GitlabClient)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Matcher (java.util.regex.Matcher)1 Before (org.junit.Before)1 RestTemplate (org.springframework.web.client.RestTemplate)1