]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-22531 Retrieve project's visibility from GitLab
authorAurelien Poscia <aurelien.poscia@sonarsource.com>
Wed, 17 Jul 2024 13:02:49 +0000 (15:02 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 19 Jul 2024 20:03:00 +0000 (20:03 +0000)
server/sonar-alm-client/src/main/java/org/sonar/alm/client/gitlab/Project.java
server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabApplicationClientTest.java

index c9bd8e664df0f5633fc52c00b5a4885d5693b85d..b4a171653702d3c75886ef68eca0dffd45b51105 100644 (file)
@@ -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;
   }
-
 }
index 37343a1a9386f3304ee3b79af349ecdab7d49a5b..37cc5f9defbdfa05afaf484a7379cc20ebdfdecb 100644 (file)
@@ -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");
   }