diff options
author | Aurelien Poscia <aurelien.poscia@sonarsource.com> | 2024-07-17 15:02:49 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-07-19 20:03:00 +0000 |
commit | 4924cb32e937b9295843237d06805e3846492435 (patch) | |
tree | d4d56226cfcdcaaa0084cf9490775e768255ecbb /server/sonar-alm-client/src | |
parent | 4f149b2007a8ba30e7b62dc1d3c8ffaf1484bd56 (diff) | |
download | sonarqube-4924cb32e937b9295843237d06805e3846492435.tar.gz sonarqube-4924cb32e937b9295843237d06805e3846492435.zip |
SONAR-22531 Retrieve project's visibility from GitLab
Diffstat (limited to 'server/sonar-alm-client/src')
2 files changed, 41 insertions, 32 deletions
diff --git a/server/sonar-alm-client/src/main/java/org/sonar/alm/client/gitlab/Project.java b/server/sonar-alm-client/src/main/java/org/sonar/alm/client/gitlab/Project.java index c9bd8e664df..b4a17165370 100644 --- a/server/sonar-alm-client/src/main/java/org/sonar/alm/client/gitlab/Project.java +++ b/server/sonar-alm-client/src/main/java/org/sonar/alm/client/gitlab/Project.java @@ -43,6 +43,9 @@ public class Project { @SerializedName("path_with_namespace") private final String pathWithNamespace; + @SerializedName("visibility") + private String visibility; + @SerializedName("web_url") private String webUrl; @@ -98,8 +101,11 @@ public class Project { return pathWithNamespace; } + public String getVisibility() { + return visibility; + } + public String getWebUrl() { return webUrl; } - } diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabApplicationClientTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabApplicationClientTest.java index 37343a1a938..37cc5f9defb 100644 --- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabApplicationClientTest.java +++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabApplicationClientTest.java @@ -56,7 +56,6 @@ public class GitlabApplicationClientTest { @Rule public LogTester logTester = new LogTester(); - private GitlabPaginatedHttpClient gitlabPaginatedHttpClient = mock(); private final MockWebServer server = new MockWebServer(); @@ -131,19 +130,22 @@ public class GitlabApplicationClientTest { public void get_project() { MockResponse response = new MockResponse() .setResponseCode(200) - .setBody("{\n" - + " \"id\": 12345,\n" - + " \"name\": \"SonarQube example 1\",\n" - + " \"name_with_namespace\": \"SonarSource / SonarQube / SonarQube example 1\",\n" - + " \"path\": \"sonarqube-example-1\",\n" - + " \"path_with_namespace\": \"sonarsource/sonarqube/sonarqube-example-1\",\n" - + " \"web_url\": \"https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-1\"\n" - + " }"); + .setBody(""" + { + "id": 12345, + "name": "SonarQube example 1", + "name_with_namespace": "SonarSource / SonarQube / SonarQube example 1", + "path": "sonarqube-example-1", + "path_with_namespace": "sonarsource/sonarqube/sonarqube-example-1", + "visibility": "visibilityFromGitLab", + "web_url": "https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-1" + } + """); server.enqueue(response); assertThat(underTest.getProject(gitlabUrl, "pat", 12345L)) - .extracting(Project::getId, Project::getName) - .containsExactly(12345L, "SonarQube example 1"); + .extracting(Project::getId, Project::getName, Project::getVisibility) + .containsExactly(12345L, "SonarQube example 1", "visibilityFromGitLab"); } @Test @@ -376,15 +378,16 @@ public class GitlabApplicationClientTest { @Test public void get_project_details() throws InterruptedException { MockResponse projectResponse = new MockResponse() - .setResponseCode(200) - .setBody("{" - + " \"id\": 1234," - + " \"name\": \"SonarQube example 2\"," - + " \"name_with_namespace\": \"SonarSource / SonarQube / SonarQube example 2\"," - + " \"path\": \"sonarqube-example-2\"," - + " \"path_with_namespace\": \"sonarsource/sonarqube/sonarqube-example-2\"," - + " \"web_url\": \"https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-2\"" - + "}"); + .setResponseCode(200) + .setBody(""" + {\ + "id": 1234,\ + "name": "SonarQube example 2",\ + "name_with_namespace": "SonarSource / SonarQube / SonarQube example 2",\ + "path": "sonarqube-example-2",\ + "path_with_namespace": "sonarsource/sonarqube/sonarqube-example-2",\ + "web_url": "https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-2"\ + }"""); server.enqueue(projectResponse); @@ -396,22 +399,22 @@ public class GitlabApplicationClientTest { assertThat(project).isNotNull(); assertThat(gitlabUrlCall).isEqualTo( - server.url("") + "projects/1234"); + server.url("") + "projects/1234"); assertThat(projectGitlabRequest.getMethod()).isEqualTo("GET"); } @Test public void get_reporter_level_access_project() throws InterruptedException { MockResponse projectResponse = new MockResponse() - .setResponseCode(200) - .setBody("[{" - + " \"id\": 1234," - + " \"name\": \"SonarQube example 2\"," - + " \"name_with_namespace\": \"SonarSource / SonarQube / SonarQube example 2\"," - + " \"path\": \"sonarqube-example-2\"," - + " \"path_with_namespace\": \"sonarsource/sonarqube/sonarqube-example-2\"," - + " \"web_url\": \"https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-2\"" - + "}]"); + .setResponseCode(200) + .setBody("[{" + + " \"id\": 1234," + + " \"name\": \"SonarQube example 2\"," + + " \"name_with_namespace\": \"SonarSource / SonarQube / SonarQube example 2\"," + + " \"path\": \"sonarqube-example-2\"," + + " \"path_with_namespace\": \"sonarsource/sonarqube/sonarqube-example-2\"," + + " \"web_url\": \"https://example.gitlab.com/sonarsource/sonarqube/sonarqube-example-2\"" + + "}]"); server.enqueue(projectResponse); @@ -423,7 +426,7 @@ public class GitlabApplicationClientTest { assertThat(project).isNotNull(); assertThat(gitlabUrlCall).isEqualTo( - server.url("") + "projects?min_access_level=20&id_after=1233&id_before=1235"); + server.url("") + "projects?min_access_level=20&id_after=1233&id_before=1235"); assertThat(projectGitlabRequest.getMethod()).isEqualTo("GET"); } |