Migrate from maniphest.info to maniphest.search conduit API endpoint
Change-Id: I341469d50a741511c5eb20a521e934b84ef69e9d
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 62c2f78..82264bc 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
@@ -17,13 +17,16 @@
import com.google.common.collect.Sets;
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.ManiphestInfo;
+import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ManiphestSearch;
+import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ManiphestResults;
import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ProjectInfo;
import java.io.IOException;
import java.net.URL;
@@ -39,6 +42,7 @@
private static final String GERRIT_CONFIG_TOKEN = "token";
private final Conduit conduit;
+ private final Gson gson;
@Inject
public PhabricatorItsFacade(@PluginName String pluginName, @GerritServerConfig Config cfg) {
@@ -46,6 +50,7 @@
String token = cfg.getString(pluginName, null, GERRIT_CONFIG_TOKEN);
this.conduit = new Conduit(url, token);
+ this.gson = new Gson();
}
@Override
@@ -72,7 +77,7 @@
int task_id = Integer.parseInt(bugId);
try {
try {
- conduit.maniphestInfo(task_id);
+ conduit.maniphestSearch(task_id);
ret = true;
} catch (ConduitErrorException e) {
// An ERR_BAD_TASK just means that the task does not exist.
@@ -131,9 +136,14 @@
Set<String> projectPhids = Sets.newHashSet(projectPhid);
- ManiphestInfo taskInfo = conduit.maniphestInfo(taskId);
- for (JsonElement jsonElement : taskInfo.getProjectPHIDs().getAsJsonArray()) {
- projectPhids.add(jsonElement.getAsString());
+ 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);
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 fa834fe..15e227d 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
@@ -19,7 +19,8 @@
import com.google.gson.JsonObject;
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.ManiphestInfo;
+import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ManiphestSearch;
+import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ManiphestResults;
import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.ProjectInfo;
import com.googlesource.gerrit.plugins.its.phabricator.conduit.results.QueryResult;
import java.util.ArrayList;
@@ -77,13 +78,26 @@
return result;
}
- /** Runs the API's 'maniphest.Info' method */
- public ManiphestInfo maniphestInfo(int taskId) throws ConduitException {
- Map<String, Object> params = new HashMap<>();
- params.put("task_id", taskId);
+ /**
+ * Runs the API's 'maniphest.search' method
+ */
+ public ManiphestResults maniphestSearch(int taskId) throws ConduitException {
+ HashMap<String, Object> params = new HashMap<>();
+ HashMap<String, Object> params2 = new HashMap<>();
+ HashMap<String, Object> params3 = new HashMap<>();
- JsonElement callResult = conduitConnection.call("maniphest.info", params, token);
- ManiphestInfo result = gson.fromJson(callResult, ManiphestInfo.class);
+ List<Object> list = new ArrayList<>();
+ list.add(taskId);
+
+ params2.put("ids", list);
+
+ params.put("constraints", params2);
+
+ params3.put("projects", true);
+ params.put("attachments", params3);
+
+ JsonElement callResult = conduitConnection.call("maniphest.search", params, token);
+ ManiphestResults result = gson.fromJson(callResult, ManiphestResults.class);
return result;
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ManiphestInfo.java b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ManiphestInfo.java
deleted file mode 100644
index 7358c79..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ManiphestInfo.java
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (C) 2014 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.googlesource.gerrit.plugins.its.phabricator.conduit.results;
-
-/**
- * Models the result for a call to maniphest.info
- *
- * <p>JSON looks like:
- *
- * <pre>
- * {
- * "id":"48",
- * "phid":"PHID-TASK-pemd324eosnymq3tdkyo",
- * "authorPHID":"PHID-USER-na3one2sht11aone",
- * "ownerPHID":null,
- * "ccPHIDs":[
- * "PHID-USER-h4n62fq2kt2v3a2qjyqh"
- * ],
- * "status":"open",
- * "statusName":"Open",
- * "isClosed":false,
- * "priority": "Needs Triage",
- * "priorityColor":"violet",
- * "title":"QChris test task",
- * "description":"",
- * "projectPHIDs":[],
- * "uri":"https://phab-01.wmflabs.org/T47",
- * "auxiliary":{
- * "std:maniphest:security_topic":"default",
- * "isdc:sprint:storypoints":null
- * },
- * "objectName":"T47",
- * "dateCreated":"1413484594",
- * "dateModified":1413549869,
- * "dependsOnTaskPHIDs":[]
- * }
- * </pre>
- */
-public class ManiphestInfo extends Task {}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ManiphestResults.java b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ManiphestResults.java
new file mode 100644
index 0000000..8a28795
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ManiphestResults.java
@@ -0,0 +1,48 @@
+// Copyright (C) 2018 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.googlesource.gerrit.plugins.its.phabricator.conduit.results;
+
+import com.google.gson.JsonElement;
+
+/**
+ * Models the result for API methods
+ *
+ * <p>JSON looks like:
+ *
+ * <pre>
+ * {
+ * "data": [
+ * { ... }
+ * ],
+ * "maps": {},
+ * "query": {
+ * "queryKey": null
+ * },
+ * "cursor": {
+ * "limit": 100,
+ * "after": null,
+ * "before": null,
+ * "order": null
+ * }
+ * }
+ * </pre>
+ */
+public class ManiphestResults {
+ private JsonElement data;
+
+ public JsonElement getData() {
+ return data;
+ }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ManiphestSearch.java b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ManiphestSearch.java
new file mode 100644
index 0000000..1f98709
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/phabricator/conduit/results/ManiphestSearch.java
@@ -0,0 +1,102 @@
+// Copyright (C) 2018 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.googlesource.gerrit.plugins.its.phabricator.conduit.results;
+
+import com.google.gson.JsonElement;
+
+/**
+ * Models the result for a call to maniphest.search
+ *
+ * <p>JSON looks like:
+ *
+ * <pre>
+ * {
+ * "id": 1,
+ * "type": "TASK",
+ * "phid": "PHID-TASK-qu55xzt7g5gusqkdiv5r",
+ * "fields": {
+ * "name": "First task",
+ * "description": {
+ * "raw": "Test"
+ * },
+ * "authorPHID": "PHID-USER-aruq7lrst6el3od2jpgm",
+ * "ownerPHID": null,
+ * "status": {
+ * "value": "open",
+ * "name": "Open",
+ * "color": null
+ * },
+ * "priority": {
+ * "value": 100,
+ * "subpriority": 0,
+ * "name": "Unbreak Now!",
+ * "color": "pink"
+ * },
+ * "points": null,
+ * "subtype": "default",
+ * "closerPHID": null,
+ * "dateClosed": null,
+ * "spacePHID": null,
+ * "dateCreated": 1530558541,
+ * "dateModified": 1538054886,
+ * "policy": {
+ * "view": "public",
+ * "interact": "public",
+ * "edit": "users"
+ * },
+ * },
+ * "attachments": {
+ * "projects": {
+ * "projectPHIDs": [
+ * "PHID-PROJ-ro6wrekgi7u3fwzz5p6a"
+ * ]
+ * }
+ * }
+ * }
+ * </pre>
+ */
+public class ManiphestSearch {
+ private int id;
+ private JsonElement fields;
+ private Attachments attachments;
+
+ public int getId() {
+ return id;
+ }
+
+ public JsonElement getFields() {
+ return fields;
+ }
+
+ public Attachments getAttachments() {
+ return attachments;
+ }
+
+ public class Attachments {
+ private Projects projects;
+
+ public Projects getProjects() {
+ return projects;
+ }
+ }
+
+ public class Projects {
+ private JsonElement projectPHIDs;
+
+ public JsonElement getProjectPHIDs() {
+ return projectPHIDs;
+ }
+ }
+}