aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-alm-client
diff options
context:
space:
mode:
authorAntoine Vinot <antoine.vinot@sonarsource.com>2022-12-30 11:30:35 +0100
committersonartech <sonartech@sonarsource.com>2022-12-30 20:02:50 +0000
commitf3c01c86ab9e7db644c40b4105c10b08ddfbd8a5 (patch)
treee5e11e14bb1e4f36f7e7148ae4f381fedced6e4e /server/sonar-alm-client
parent959f6e157c0a6da4a09369ce0d78f5e916bb0232 (diff)
downloadsonarqube-f3c01c86ab9e7db644c40b4105c10b08ddfbd8a5.tar.gz
sonarqube-f3c01c86ab9e7db644c40b4105c10b08ddfbd8a5.zip
SONAR-17827 Update usage of GitHub.com APIs to match the new versioning system.
Diffstat (limited to 'server/sonar-alm-client')
-rw-r--r--server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationHttpClientImpl.java7
-rw-r--r--server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java10
2 files changed, 8 insertions, 9 deletions
diff --git a/server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationHttpClientImpl.java b/server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationHttpClientImpl.java
index 11845309142..2d8721ce52f 100644
--- a/server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationHttpClientImpl.java
+++ b/server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationHttpClientImpl.java
@@ -53,9 +53,8 @@ public class GithubApplicationHttpClientImpl implements GithubApplicationHttpCli
private static final Logger LOG = Loggers.get(GithubApplicationHttpClientImpl.class);
private static final Pattern NEXT_LINK_PATTERN = Pattern.compile("<([^<]+)>; rel=\"next\"");
- private static final String GITHUB_API_VERSION_JSON = "application/vnd.github.v3+json";
- private static final String ANTIOPE_PREVIEW_JSON = "application/vnd.github.antiope-preview+json";
- private static final String MACHINE_MAN_PREVIEW_JSON = "application/vnd.github.machine-man-preview+json";
+ private static final String GH_API_VERSION_HEADER = "X-GitHub-Api-Version";
+ private static final String GH_API_VERSION = "2022-11-28";
private final OkHttpClient client;
@@ -181,7 +180,7 @@ public class GithubApplicationHttpClientImpl implements GithubApplicationHttpCli
Request.Builder url = new Request.Builder().url(toAbsoluteEndPoint(appUrl, endPoint));
if (token != null) {
url.addHeader("Authorization", token.getAuthorizationHeaderPrefix() + " " + token);
- url.addHeader("Accept", String.format("%s, %s, %s", ANTIOPE_PREVIEW_JSON, MACHINE_MAN_PREVIEW_JSON, GITHUB_API_VERSION_JSON));
+ url.addHeader(GH_API_VERSION_HEADER, GH_API_VERSION);
}
return url;
}
diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java
index 5b41d67b2e6..10fab6083c4 100644
--- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java
+++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java
@@ -49,9 +49,9 @@ import static org.junit.Assert.fail;
@RunWith(DataProviderRunner.class)
public class GithubApplicationHttpClientImplTest {
- private static final String BETA_API_HEADER = "application/vnd.github.antiope-preview+json, " +
- "application/vnd.github.machine-man-preview+json, " +
- "application/vnd.github.v3+json";
+ private static final String GH_API_VERSION_HEADER = "X-GitHub-Api-Version";
+ private static final String GH_API_VERSION = "2022-11-28";
+
@Rule
public MockWebServer server = new MockWebServer();
@@ -126,7 +126,7 @@ public class GithubApplicationHttpClientImplTest {
assertThat(recordedRequest.getMethod()).isEqualTo("GET");
assertThat(recordedRequest.getPath()).isEqualTo(randomEndPoint);
assertThat(recordedRequest.getHeader("Authorization")).isEqualTo("token " + accessToken.getValue());
- assertThat(recordedRequest.getHeader("Accept")).isEqualTo(BETA_API_HEADER);
+ assertThat(recordedRequest.getHeader(GH_API_VERSION_HEADER)).isEqualTo(GH_API_VERSION);
}
@Test
@@ -260,7 +260,7 @@ public class GithubApplicationHttpClientImplTest {
assertThat(recordedRequest.getMethod()).isEqualTo("POST");
assertThat(recordedRequest.getPath()).isEqualTo(randomEndPoint);
assertThat(recordedRequest.getHeader("Authorization")).isEqualTo("token " + accessToken.getValue());
- assertThat(recordedRequest.getHeader("Accept")).isEqualTo(BETA_API_HEADER);
+ assertThat(recordedRequest.getHeader(GH_API_VERSION_HEADER)).isEqualTo(GH_API_VERSION);
}
@Test