]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19337 Add endpoint to validate GitHub provisioning config. (#8414)
authorWojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com>
Wed, 31 May 2023 13:13:59 +0000 (15:13 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 1 Jun 2023 20:02:58 +0000 (20:02 +0000)
server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubBinding.java
server/sonar-auth-github/src/main/java/org/sonar/auth/github/GitHubSettings.java

index 90b77f763de6b12e85f65f36b68bdb3e366d2fb3..bb569f0db86f07f0070e014f794ab47ca0b6258e 100644 (file)
@@ -21,13 +21,41 @@ package org.sonar.alm.client.github;
 
 import com.google.gson.annotations.SerializedName;
 import java.util.List;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
 
 import static org.sonar.alm.client.github.GithubApplicationClient.Repository;
 
 public class GithubBinding {
 
   private GithubBinding() {
-    //nothing to do
+    // nothing to do
+  }
+
+  public static class GsonApp {
+
+    @SerializedName("installations_count")
+    private long installationsCount;
+
+    @SerializedName("permissions")
+    Permissions permissions;
+
+    public GsonApp(long installationsCount, Permissions permissions) {
+      this.installationsCount = installationsCount;
+      this.permissions = permissions;
+    }
+
+    public GsonApp() {
+      // http://stackoverflow.com/a/18645370/229031
+    }
+
+    public Permissions getPermissions() {
+      return permissions;
+    }
+
+    public long getInstallationsCount() {
+      return installationsCount;
+    }
   }
 
   public static class GsonInstallations {
@@ -82,32 +110,6 @@ public class GithubBinding {
       return account;
     }
 
-    public static class Permissions {
-      @SerializedName("checks")
-      String checks;
-      @SerializedName("members")
-      String members;
-
-      public Permissions(String checks, String members) {
-        this.checks = checks;
-        this.members = members;
-      }
-
-      public Permissions() {
-        // even if empty constructor is not required for Gson, it is strongly
-        // recommended:
-        // http://stackoverflow.com/a/18645370/229031
-      }
-
-      public String getMembers() {
-        return members;
-      }
-
-      public String getChecks() {
-        return checks;
-      }
-    }
-
     public static class GsonAccount {
       @SerializedName("id")
       long id;
@@ -132,6 +134,42 @@ public class GithubBinding {
     }
   }
 
+  public static class Permissions {
+    @SerializedName("checks")
+    String checks;
+    @SerializedName("members")
+    String members;
+    @SerializedName("emails")
+    String emails;
+
+    public Permissions(@Nullable String checks, @Nullable String members, @Nullable String emails) {
+      this.checks = checks;
+      this.members = members;
+      this.emails = emails;
+    }
+
+    public Permissions() {
+      // even if empty constructor is not required for Gson, it is strongly
+      // recommended:
+      // http://stackoverflow.com/a/18645370/229031
+    }
+
+    @CheckForNull
+    public String getMembers() {
+      return members;
+    }
+
+    @CheckForNull
+    public String getChecks() {
+      return checks;
+    }
+
+    @CheckForNull
+    public String getEmails() {
+      return emails;
+    }
+  }
+
   public static class GsonRepositorySearch {
     @SerializedName("total_count")
     int totalCount;
index cd1e30d010eb9618ec3f99205fbe3c0b997be877..26fa5bc939212c5e926ceb90391f756daa4adc03 100644 (file)
@@ -64,6 +64,7 @@ public class GitHubSettings {
   private static final String CATEGORY = "authentication";
   private static final String SUBCATEGORY = "github";
 
+
   private final Configuration configuration;
 
   private final InternalProperties internalProperties;
@@ -113,6 +114,10 @@ public class GitHubSettings {
     return urlWithEndingSlash(configuration.get(API_URL).orElse(""));
   }
 
+  public String apiURLOrDefault() {
+    return configuration.get(API_URL).map(GitHubSettings::urlWithEndingSlash).orElse(DEFAULT_API_URL);
+  }
+
   public Set<String> getOrganizations() {
     return Set.of(configuration.getStringArray(ORGANIZATIONS));
   }