@ServerSide
public class AzureDevOpsHttpClient {
+
private static final Logger LOG = Loggers.get(AzureDevOpsHttpClient.class);
+ public static final String API_VERSION_3 = "api-version=3.0";
+
protected static final String GET = "GET";
protected static final String UNABLE_TO_CONTACT_AZURE_SERVER = "Unable to contact Azure DevOps server";
}
public void checkPAT(String serverUrl, String token) {
- String url = String.format("%s/_apis/projects", getTrimmedUrl(serverUrl));
+ String url = String.format("%s/_apis/projects?%s", getTrimmedUrl(serverUrl), API_VERSION_3);
LOG.debug(String.format("check pat : [%s]", url));
doGet(token, url);
}
public GsonAzureProjectList getProjects(String serverUrl, String token) {
- String url = String.format("%s/_apis/projects", getTrimmedUrl(serverUrl));
+ String url = String.format("%s/_apis/projects?%s", getTrimmedUrl(serverUrl), API_VERSION_3);
LOG.debug(String.format("get projects : [%s]", url));
return doGet(token, url, r -> buildGson().fromJson(r.body().charStream(), GsonAzureProjectList.class));
}
public GsonAzureRepoList getRepos(String serverUrl, String token, @Nullable String projectName) {
String url;
if (projectName != null && !projectName.isEmpty()) {
- url = String.format("%s/%s/_apis/git/repositories", getTrimmedUrl(serverUrl), projectName);
+ url = String.format("%s/%s/_apis/git/repositories?%s", getTrimmedUrl(serverUrl), projectName, API_VERSION_3);
} else {
- url = String.format("%s/_apis/git/repositories", getTrimmedUrl(serverUrl));
+ url = String.format("%s/_apis/git/repositories?%s", getTrimmedUrl(serverUrl), API_VERSION_3);
}
LOG.debug(String.format("get repos : [%s]", url));
return doGet(token, url, r -> buildGson().fromJson(r.body().charStream(), GsonAzureRepoList.class));
}
public GsonAzureRepo getRepo(String serverUrl, String token, String projectName, String repositoryName) {
- String url = String.format("%s/%s/_apis/git/repositories/%s", getTrimmedUrl(serverUrl), projectName, repositoryName);
+ String url = String.format("%s/%s/_apis/git/repositories/%s?%s", getTrimmedUrl(serverUrl), projectName, repositoryName, API_VERSION_3);
LOG.debug(String.format("get repo : [%s]", url));
return doGet(token, url, r -> buildGson().fromJson(r.body().charStream(), GsonAzureRepo.class));
}
RecordedRequest request = server.takeRequest(10, TimeUnit.SECONDS);
String azureDevOpsUrlCall = request.getRequestUrl().toString();
- assertThat(azureDevOpsUrlCall).isEqualTo(server.url("") + "_apis/projects");
+ assertThat(azureDevOpsUrlCall).isEqualTo(server.url("") + "_apis/projects?api-version=3.0");
assertThat(request.getMethod()).isEqualTo("GET");
assertThat(logTester.logs()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.DEBUG))
- .contains("check pat : [" + server.url("").toString() + "_apis/projects]");
+ .contains("check pat : [" + server.url("").toString() + "_apis/projects?api-version=3.0]");
}
@Test
RecordedRequest request = server.takeRequest(10, TimeUnit.SECONDS);
String azureDevOpsUrlCall = request.getRequestUrl().toString();
- assertThat(azureDevOpsUrlCall).isEqualTo(server.url("") + "_apis/projects");
+ assertThat(azureDevOpsUrlCall).isEqualTo(server.url("") + "_apis/projects?api-version=3.0");
assertThat(request.getMethod()).isEqualTo("GET");
assertThat(logTester.logs(LoggerLevel.DEBUG)).hasSize(1);
assertThat(logTester.logs(LoggerLevel.DEBUG))
- .contains("get projects : [" + server.url("").toString() + "_apis/projects]");
+ .contains("get projects : [" + server.url("").toString() + "_apis/projects?api-version=3.0]");
assertThat(projects.getValues()).hasSize(2);
assertThat(projects.getValues())
.extracting(GsonAzureProject::getName, GsonAzureProject::getDescription)
RecordedRequest request = server.takeRequest(10, TimeUnit.SECONDS);
String azureDevOpsUrlCall = request.getRequestUrl().toString();
- assertThat(azureDevOpsUrlCall).isEqualTo(server.url("") + "projectName/_apis/git/repositories");
+ assertThat(azureDevOpsUrlCall).isEqualTo(server.url("") + "projectName/_apis/git/repositories?api-version=3.0");
assertThat(request.getMethod()).isEqualTo("GET");
assertThat(logTester.logs(LoggerLevel.DEBUG)).hasSize(1);
assertThat(logTester.logs(LoggerLevel.DEBUG))
- .contains("get repos : [" + server.url("").toString() + "projectName/_apis/git/repositories]");
+ .contains("get repos : [" + server.url("").toString() + "projectName/_apis/git/repositories?api-version=3.0]");
assertThat(repos.getValues()).hasSize(1);
assertThat(repos.getValues())
.extracting(GsonAzureRepo::getName, GsonAzureRepo::getUrl, r -> r.getProject().getName())
RecordedRequest request = server.takeRequest(10, TimeUnit.SECONDS);
String azureDevOpsUrlCall = request.getRequestUrl().toString();
- assertThat(azureDevOpsUrlCall).isEqualTo(server.url("") + "_apis/git/repositories");
+ assertThat(azureDevOpsUrlCall).isEqualTo(server.url("") + "_apis/git/repositories?api-version=3.0");
assertThat(request.getMethod()).isEqualTo("GET");
assertThat(repos.getValues()).isEmpty();
}
RecordedRequest request = server.takeRequest(10, TimeUnit.SECONDS);
String azureDevOpsUrlCall = request.getRequestUrl().toString();
- assertThat(azureDevOpsUrlCall).isEqualTo(server.url("") + "Project-Name/_apis/git/repositories/Repo-Name-1");
+ assertThat(azureDevOpsUrlCall).isEqualTo(server.url("") + "Project-Name/_apis/git/repositories/Repo-Name-1?api-version=3.0");
assertThat(request.getMethod()).isEqualTo("GET");
assertThat(logTester.logs(LoggerLevel.DEBUG)).hasSize(1);
assertThat(logTester.logs(LoggerLevel.DEBUG))
- .contains("get repo : [" + server.url("").toString() + "Project-Name/_apis/git/repositories/Repo-Name-1]");
+ .contains("get repo : [" + server.url("").toString() + "Project-Name/_apis/git/repositories/Repo-Name-1?api-version=3.0]");
assertThat(repo.getId()).isEqualTo("Repo-Id-1");
assertThat(repo.getName()).isEqualTo("Repo-Name-1");
assertThat(repo.getUrl()).isEqualTo("https://ado.sonarqube.com/DefaultCollection/Repo-Id-1");