diff options
author | Antoine Vinot <antoine.vinot@sonarsource.com> | 2023-01-03 11:21:57 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-01-03 20:03:04 +0000 |
commit | 6a62f6c3931bb7e99f41b99b4c43f24d882bc0d0 (patch) | |
tree | c6b04880a49127e703bac9bcd80d8bba6af2483b /server | |
parent | e50f4360288c7457cd0e0c098d7f1c13d66e2be4 (diff) | |
download | sonarqube-6a62f6c3931bb7e99f41b99b4c43f24d882bc0d0.tar.gz sonarqube-6a62f6c3931bb7e99f41b99b4c43f24d882bc0d0.zip |
NO-JIRA Refactor code to remove vulnerability FP
Diffstat (limited to 'server')
-rw-r--r-- | server/sonar-alm-client/src/main/java/org/sonar/alm/client/azure/AzureDevOpsHttpClient.java | 16 |
1 files changed, 9 insertions, 7 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 b6d7468c79b..7df02e3aa58 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 @@ -27,6 +27,7 @@ import java.io.IOException; import java.net.HttpURLConnection; import java.nio.charset.StandardCharsets; import java.util.function.Function; +import java.util.stream.Stream; import javax.annotation.Nullable; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -34,12 +35,14 @@ import okhttp3.RequestBody; import okhttp3.Response; import okhttp3.ResponseBody; import org.apache.commons.codec.binary.Base64; +import org.apache.commons.lang.StringUtils; import org.sonar.alm.client.TimeoutConfiguration; import org.sonar.api.server.ServerSide; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonarqube.ws.client.OkHttpClientBuilder; +import static java.util.stream.Collectors.joining; import static org.sonar.api.internal.apachecommons.lang.StringUtils.isBlank; import static org.sonar.api.internal.apachecommons.lang.StringUtils.substringBeforeLast; @@ -83,18 +86,17 @@ 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?%s", getTrimmedUrl(serverUrl), projectName, API_VERSION_3); - } else { - url = String.format("%s/_apis/git/repositories?%s", getTrimmedUrl(serverUrl), API_VERSION_3); - } + String url = Stream.of(getTrimmedUrl(serverUrl), projectName, "_apis/git/repositories?" + API_VERSION_3) + .filter(StringUtils::isNotBlank) + .collect(joining("/")); 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?%s", getTrimmedUrl(serverUrl), projectName, repositoryName, API_VERSION_3); + String url = Stream.of(getTrimmedUrl(serverUrl), projectName, "_apis/git/repositories", repositoryName + "?" + API_VERSION_3) + .filter(StringUtils::isNotBlank) + .collect(joining("/")); LOG.debug(String.format("get repo : [%s]", url)); return doGet(token, url, r -> buildGson().fromJson(r.body().charStream(), GsonAzureRepo.class)); } |