Filter out RO GitHub repositories for replication

When setting up Gerrit->GitHub replication using the repositories
wizard, it does not make sense to list the ones that are read-only
and then risking to amend replication.config with settings that
would never work.

It is much better to make sure that what the repos we list are the
ones that actually we are authorized to replicate to.

Change-Id: I976cfd02ea45032bd9236dc73cac5f62996baca4
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/RepositoriesListController.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/RepositoriesListController.java
index 45198ab..87cc52e 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/RepositoriesListController.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/RepositoriesListController.java
@@ -30,6 +30,8 @@
 import org.kohsuke.github.GHRepository;
 import org.kohsuke.github.PagedIterable;
 import org.kohsuke.github.PagedIterator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 
@@ -39,6 +41,7 @@
 
 @Singleton
 public class RepositoriesListController implements VelocityController {
+  private static final Logger log = LoggerFactory.getLogger(RepositoriesListController.class);
   private final ProjectCache projects;
   private final GitHubConfig config;
 
@@ -63,18 +66,24 @@
 
     while (repoIter.hasNext() && numRepos < config.repositoryListLimit) {
       GHRepository ghRepository = repoIter.next();
-      JsonObject repository = new JsonObject();
-      String projectName = organisation + "/" + ghRepository.getName();
-      if (projects.get(Project.NameKey.parse(projectName)) == null) {
-        repository.add("name", new JsonPrimitive(ghRepository.getName()));
-        repository.add("organisation", new JsonPrimitive(organisation));
-        repository.add(
-            "description",
-            new JsonPrimitive(
-                Strings.nullToEmpty(ghRepository.getDescription())));
-        repository.add("private", new JsonPrimitive(ghRepository.isPrivate()));
-        jsonRepos.add(repository);
-        numRepos++;
+      if (ghRepository.hasPushAccess() && ghRepository.hasPullAccess()) {
+        JsonObject repository = new JsonObject();
+        String projectName = organisation + "/" + ghRepository.getName();
+        if (projects.get(Project.NameKey.parse(projectName)) == null) {
+          repository.add("name", new JsonPrimitive(ghRepository.getName()));
+          repository.add("organisation", new JsonPrimitive(organisation));
+          repository.add(
+              "description",
+              new JsonPrimitive(Strings.nullToEmpty(ghRepository
+                  .getDescription())));
+          repository
+              .add("private", new JsonPrimitive(ghRepository.isPrivate()));
+          jsonRepos.add(repository);
+          numRepos++;
+        }
+      } else {
+        log.warn("Skipping repository {} because user {} has no push/pull access to it",
+            ghRepository.getName(), user.getUserName());
       }
     }