return doGet(token, url, r -> buildGson().fromJson(r.body().charStream(), GsonAzureProjectList.class));
}
+ public GsonAzureProject getProject(String serverUrl, String token, String projectName) {
+ String url = String.format("%s/_apis/projects/%s?%s", getTrimmedUrl(serverUrl), projectName, API_VERSION_3);
+ LOG.debug(String.format("get project : [%s]", url));
+ return doGet(token, url, r -> buildGson().fromJson(r.body().charStream(), GsonAzureProject.class));
+
+ }
+
public GsonAzureRepoList getRepos(String serverUrl, String token, @Nullable String projectName) {
String url;
if (projectName != null && !projectName.isEmpty()) {
if (!response.isSuccessful()) {
LOG.debug(UNABLE_TO_CONTACT_AZURE_SERVER + ": {} {}", response.request().url().toString(), response.code());
if (response.code() == HttpURLConnection.HTTP_UNAUTHORIZED) {
- throw new IllegalArgumentException("Invalid personal access token");
+ throw new AzureDevopsServerException(response.code(), "Invalid personal access token");
}
ResponseBody responseBody = response.body();
String body = responseBody == null ? "" : responseBody.string();
String errorMessage = generateErrorMessage(body, UNABLE_TO_CONTACT_AZURE_SERVER);
LOG.info(String.format("Azure API call to [%s] failed with %s http code. Azure response content : [%s]", response.request().url().toString(), response.code(), body));
- throw new IllegalArgumentException(errorMessage);
+ throw new AzureDevopsServerException(response.code(), errorMessage);
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.alm.client.azure;
+
+public class AzureDevopsServerException extends IllegalArgumentException {
+ private final int httpCode;
+
+ public AzureDevopsServerException(int httpCode, String clientErrorMessage) {
+ super(clientErrorMessage);
+ this.httpCode = httpCode;
+ }
+
+ public int getHttpCode() {
+ return httpCode;
+ }
+}