aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-alm-client/src
diff options
context:
space:
mode:
authorBelen Pruvost <belen.pruvost@sonarsource.com>2021-03-29 14:24:12 +0200
committersonartech <sonartech@sonarsource.com>2021-03-29 20:03:43 +0000
commitadf79f5372bddf3c0f8767dfa3700103e62fda6b (patch)
treeebf1533b4abc3cbe61a30ce26e3157f0a255acb1 /server/sonar-alm-client/src
parent1b2921d043afd96a1415f7fafaa11de86027057a (diff)
downloadsonarqube-adf79f5372bddf3c0f8767dfa3700103e62fda6b.tar.gz
sonarqube-adf79f5372bddf3c0f8767dfa3700103e62fda6b.zip
SONAR-14628 ADO use version-specific API endpoints
Diffstat (limited to 'server/sonar-alm-client/src')
-rw-r--r--server/sonar-alm-client/src/main/java/org/sonar/alm/client/azure/AzureDevOpsHttpClient.java13
-rw-r--r--server/sonar-alm-client/src/test/java/org/sonar/alm/client/azure/AzureDevOpsHttpClientTest.java18
2 files changed, 17 insertions, 14 deletions
diff --git a/server/sonar-alm-client/src/main/java/org/sonar/alm/client/azure/AzureDevOpsHttpClient.java b/server/sonar-alm-client/src/main/java/org/sonar/alm/client/azure/AzureDevOpsHttpClient.java
index 36cb08dea3b..082e8247e72 100644
--- a/server/sonar-alm-client/src/main/java/org/sonar/alm/client/azure/AzureDevOpsHttpClient.java
+++ b/server/sonar-alm-client/src/main/java/org/sonar/alm/client/azure/AzureDevOpsHttpClient.java
@@ -45,8 +45,11 @@ import static org.sonar.api.internal.apachecommons.lang.StringUtils.substringBef
@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";
@@ -60,13 +63,13 @@ public class AzureDevOpsHttpClient {
}
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));
}
@@ -74,16 +77,16 @@ public class AzureDevOpsHttpClient {
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));
}
diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/azure/AzureDevOpsHttpClientTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/azure/AzureDevOpsHttpClientTest.java
index da1ea680661..bfb9c22b0be 100644
--- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/azure/AzureDevOpsHttpClientTest.java
+++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/azure/AzureDevOpsHttpClientTest.java
@@ -78,12 +78,12 @@ public class AzureDevOpsHttpClientTest {
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
@@ -132,12 +132,12 @@ public class AzureDevOpsHttpClientTest {
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)
@@ -198,12 +198,12 @@ public class AzureDevOpsHttpClientTest {
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())
@@ -218,7 +218,7 @@ public class AzureDevOpsHttpClientTest {
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();
}
@@ -251,12 +251,12 @@ public class AzureDevOpsHttpClientTest {
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");