Replication target by username not on organization

Previously the replication targets were defined on a per-organization
basis, assuming that only an elected user would be defined for running
the replication process.

However things are more complex and sometimes organizations are not
centrally managed and, especially with OpenSource, different people may
operate independently and have different permissions to different repos.

It is then quite difficult (if not impossible) to define a single user
to carry out replication for all repos. A safer approach is to define
a one-target-per-user logic where each individual can potentially carry
out replication on only a sub-set of repos inside an organisation.

This avoids the potential risk of overwriting the replication user
inside an organisation and allow different users to replicate their own
repos.

Change-Id: I52d4ea9883335a35a15f32a080b1d0b9796d79c6
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/ReplicateProjectStep.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/ReplicateProjectStep.java
index 5410c78..27e3368 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/ReplicateProjectStep.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/ReplicateProjectStep.java
@@ -61,10 +61,9 @@
 
     String repositoryName = getOrganisation() + "/" + getRepositoryName();
     progress.update(1);
-    replicationConfig.addSecureCredentials(getOrganisation(), authUsername,
-        authToken);
+    replicationConfig.addSecureCredentials(authUsername, authToken);
     progress.update(1);
-    replicationConfig.addReplicationRemote(getOrganisation(), gitHubUrl
+    replicationConfig.addReplicationRemote(authUsername, gitHubUrl
         + "/${name}.git", repositoryName);
     progress.endTask();
   }
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/ReplicationConfig.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/ReplicationConfig.java
index 60e8502..0296ce6 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/ReplicationConfig.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/ReplicationConfig.java
@@ -40,26 +40,24 @@
     secureConf = new FileBasedConfig(site.secure_config.toFile(), FS.DETECTED);
   }
 
-  public synchronized void addSecureCredentials(String organisation,
-      String authUsername, String authToken) throws IOException,
+  public synchronized void addSecureCredentials(String authUsername, String authToken) throws IOException,
       ConfigInvalidException {
     secureConf.load();
-    secureConf.setString("remote", organisation, "username", authUsername);
-    secureConf.setString("remote", organisation, "password", authToken);
+    secureConf.setString("remote", authUsername, "username", authUsername);
+    secureConf.setString("remote", authUsername, "password", authToken);
     secureConf.save();
   }
 
-  public synchronized void addReplicationRemote(String organisation,
-      String url, String projectName) throws IOException,
-      ConfigInvalidException {
+  public synchronized void addReplicationRemote(String username, String url,
+      String projectName) throws IOException, ConfigInvalidException {
     replicationConf.load();
-    replicationConf.setString("remote", organisation, "url", url);
+    replicationConf.setString("remote", username, "url", url);
     List<String> projects =
         new ArrayList<String>(Arrays.asList(replicationConf.getStringList(
-            "remote", organisation, "projects")));
+            "remote", username, "projects")));
     projects.add(projectName);
-    replicationConf.setStringList("remote", organisation, "projects", projects);
-    replicationConf.setString("remote", organisation, "push", "refs/*:refs/*");
+    replicationConf.setStringList("remote", username, "projects", projects);
+    replicationConf.setString("remote", username, "push", "refs/*:refs/*");
     replicationConf.save();
   }