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);
}
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);
}
}
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;
}
Aggregations