Collect all maniphestEdit code in Conduit
Conduit should encapsulate Phabricator's API. So maniphestEdit methods
belong in there.
Change-Id: I0ec457d5ad097bef4871733b1e4ca8709ddcd219
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/PhabricatorItsFacade.java b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/PhabricatorItsFacade.java
index e2cea8c..4fb423d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/PhabricatorItsFacade.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/PhabricatorItsFacade.java
@@ -14,24 +14,16 @@
package com.googlesource.gerrit.plugins.its.phabricator;
-import com.google.common.collect.Sets;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.server.config.GerritServerConfig;
-import com.google.gson.Gson;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
import com.google.inject.Inject;
import com.googlesource.gerrit.plugins.its.base.its.ItsFacade;
import com.googlesource.gerrit.plugins.its.phabricator.conduit.Conduit;
import com.googlesource.gerrit.plugins.its.phabricator.conduit.ConduitErrorException;
import com.googlesource.gerrit.plugins.its.phabricator.conduit.ConduitException;
-import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ManiphestResults;
-import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ManiphestSearch;
-import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ProjectSearch;
import java.io.IOException;
import java.net.URL;
-import java.util.Set;
import org.eclipse.jgit.lib.Config;
public class PhabricatorItsFacade implements ItsFacade {
@@ -41,7 +33,6 @@
private static final String GERRIT_CONFIG_TOKEN = "token";
private final Conduit conduit;
- private final Gson gson;
@Inject
public PhabricatorItsFacade(
@@ -52,7 +43,6 @@
String token = cfg.getString(pluginName, null, GERRIT_CONFIG_TOKEN);
this.conduit = conduitFactory.create(url, token);
- this.gson = new Gson();
}
@Override
@@ -107,12 +97,12 @@
case "add-project":
assertParameters(action, chopped, 1);
- maniphestEdit(chopped[1], taskId, Conduit.ACTION_PROJECT_ADD);
+ conduit.maniphestEdit(chopped[1], taskId, Conduit.ACTION_PROJECT_ADD);
break;
case "remove-project":
assertParameters(action, chopped, 1);
- maniphestEdit(chopped[1], taskId, Conduit.ACTION_PROJECT_REMOVE);
+ conduit.maniphestEdit(chopped[1], taskId, Conduit.ACTION_PROJECT_REMOVE);
break;
default:
throw new IOException("Unknown action " + action);
@@ -131,35 +121,6 @@
}
}
- private void maniphestEdit(String projectName, int taskId, String actions) throws IOException {
- try {
- ProjectSearch projectSearch = conduit.projectSearch(projectName);
- String projectPhid = projectSearch.getPhid();
-
- Set<String> projectPhids = Sets.newHashSet(projectPhid);
-
- ManiphestResults taskSearch = conduit.maniphestSearch(taskId);
- JsonArray maniphestResultEntryValue = taskSearch.getData().getAsJsonArray();
-
- for (JsonElement jsonElement : maniphestResultEntryValue) {
- ManiphestSearch maniphestResultManiphestSearch =
- gson.fromJson(jsonElement, ManiphestSearch.class);
- for (JsonElement jsonElement2 :
- maniphestResultManiphestSearch
- .getAttachments()
- .getProjects()
- .getProjectPHIDs()
- .getAsJsonArray()) {
- projectPhids.add(jsonElement2.getAsString());
- }
- }
-
- conduit.maniphestEdit(taskId, projectPhids, actions);
- } catch (ConduitException e) {
- throw new IOException("Error on conduit", e);
- }
- }
-
@Override
public String healthCheck(final Check check) throws IOException {
// This method is not used, so there is no need to implement it.
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/Conduit.java b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/Conduit.java
index 96aa46c..be28ab2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/Conduit.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/Conduit.java
@@ -14,6 +14,7 @@
package com.googlesource.gerrit.plugins.its.phabricator.conduit;
+import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
@@ -23,12 +24,15 @@
import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ConduitPing;
import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ManiphestEdit;
import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ManiphestResults;
+import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ManiphestSearch;
import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ProjectResults;
import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ProjectSearch;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* Bindings for Phabricator's Conduit API
@@ -104,6 +108,35 @@
return maniphestEdit(taskId, null, projects, action);
}
+ public void maniphestEdit(String projectName, int taskId, String actions) throws IOException {
+ try {
+ ProjectSearch projectSearch = projectSearch(projectName);
+ String projectPhid = projectSearch.getPhid();
+
+ Set<String> projectPhids = Sets.newHashSet(projectPhid);
+
+ ManiphestResults taskSearch = maniphestSearch(taskId);
+ JsonArray maniphestResultEntryValue = taskSearch.getData().getAsJsonArray();
+
+ for (JsonElement jsonElement : maniphestResultEntryValue) {
+ ManiphestSearch maniphestResultManiphestSearch =
+ gson.fromJson(jsonElement, ManiphestSearch.class);
+ for (JsonElement jsonElement2 :
+ maniphestResultManiphestSearch
+ .getAttachments()
+ .getProjects()
+ .getProjectPHIDs()
+ .getAsJsonArray()) {
+ projectPhids.add(jsonElement2.getAsString());
+ }
+ }
+
+ maniphestEdit(taskId, projectPhids, actions);
+ } catch (ConduitException e) {
+ throw new IOException("Error on conduit", e);
+ }
+ }
+
/** Runs the API's 'maniphest.edit' method */
public ManiphestEdit maniphestEdit(
int taskId, String comment, Iterable<String> projects, String action)