summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2013-07-26 06:32:07 (EDT)
committerGerrit Code Review @ Eclipse.org2013-07-30 05:11:27 (EDT)
commit41803058772d3c266133a56ccb42acd3e09f0798 (patch)
tree2e76ca12568fa2096c05d7b617d8a4dff9f4ea93
parent2419299d4e5288a55a9cc3fdfcc323f13e190bfa (diff)
downloadorg.eclipse.mylyn.reviews-41803058772d3c266133a56ccb42acd3e09f0798.zip
org.eclipse.mylyn.reviews-41803058772d3c266133a56ccb42acd3e09f0798.tar.gz
org.eclipse.mylyn.reviews-41803058772d3c266133a56ccb42acd3e09f0798.tar.bz2
395059: allow to publish inline comments, draftsrefs/changes/53/14653/6
was: fix PatchSetRemoteFactoryTest.testPatchSetComments Bug: 395059 Change-Id: Ieee19e88f1f713b10e9b3491e59cbc802de9341a Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=395059 Signed-off-by: Tomasz Zarna <tomasz.zarna@tasktop.com>
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java38
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ApprovalUtil.java100
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/CommentInfo.java21
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/CommentInput.java69
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewInput.java14
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/CommentInfoTest.java66
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/PatchSetRemoteFactoryTest.java2
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/CommentInfo_draft.json7
8 files changed, 314 insertions, 3 deletions
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
index 402bd0a..f421661 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
@@ -22,9 +22,11 @@ import java.net.HttpURLConnection;
import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -52,6 +54,8 @@ import org.eclipse.mylyn.internal.gerrit.core.client.compat.ProjectDetailX;
import org.eclipse.mylyn.internal.gerrit.core.client.data.GerritQueryResult;
import org.eclipse.mylyn.internal.gerrit.core.client.rest.AbandonInput;
import org.eclipse.mylyn.internal.gerrit.core.client.rest.ChangeInfo;
+import org.eclipse.mylyn.internal.gerrit.core.client.rest.CommentInfo;
+import org.eclipse.mylyn.internal.gerrit.core.client.rest.CommentInput;
import org.eclipse.mylyn.internal.gerrit.core.client.rest.RestoreInput;
import org.eclipse.mylyn.internal.gerrit.core.client.rest.ReviewInfo;
import org.eclipse.mylyn.internal.gerrit.core.client.rest.ReviewInput;
@@ -491,9 +495,41 @@ public class GerritClient extends ReviewsClient {
}
});
} else {
+ ReviewInput reviewInput = new ReviewInput(message);
+ Map<String, CommentInfo[]> drafts = listDrafts(id, monitor);
+ Map<String, CommentInput[]> comments = convert(drafts);
+ if (!comments.isEmpty()) {
+ reviewInput.setComments(comments);
+ }
final String uri = "/a/changes/" + id.getParentKey().get() + "/revisions/" + id.get() + "/review"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- executePostRestRequest(uri, new ReviewInput(message), ReviewInfo.class, null /*no error handler*/, monitor);
+ executePostRestRequest(uri, reviewInput, ReviewInfo.class, null /*no error handler*/, monitor);
+ }
+ }
+
+ private Map<String, CommentInfo[]> listDrafts(final PatchSet.Id id, IProgressMonitor monitor)
+ throws GerritException {
+ String uri = "/changes/" + id.getParentKey().get() + "/revisions/" + id.get() + "/drafts/"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ TypeToken<Map<String, CommentInfo[]>> resultType = new TypeToken<Map<String, CommentInfo[]>>() {
+ };
+
+ return executeGetRestRequest(uri, resultType.getType(), monitor);
+ }
+
+ private Map<String, CommentInput[]> convert(Map<String, CommentInfo[]> commentInfos) {
+ if (commentInfos == null || commentInfos.isEmpty()) {
+ return Collections.<String, CommentInput[]> emptyMap();
+ }
+ Map<String, CommentInput[]> commentInputs = new HashMap<String, CommentInput[]>(commentInfos.size());
+ Set<Entry<String, CommentInfo[]>> entrySet = commentInfos.entrySet();
+ for (Entry<String, CommentInfo[]> entry : entrySet) {
+ CommentInfo[] infos = entry.getValue();
+ List<CommentInput> inputs = new ArrayList<CommentInput>(infos.length);
+ for (CommentInfo info : infos) {
+ inputs.add(new CommentInput(info));
+ }
+ commentInputs.put(entry.getKey(), inputs.toArray(new CommentInput[inputs.size()]));
}
+ return commentInputs;
}
public ReviewerResult addReviewers(String reviewId, final List<String> reviewers, IProgressMonitor monitor)
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ApprovalUtil.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ApprovalUtil.java
new file mode 100644
index 0000000..aeff052
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ApprovalUtil.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.gerrit.core.client.rest;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.google.gerrit.common.data.ApprovalType;
+import com.google.gerrit.reviewdb.ApprovalCategory;
+import com.google.gerrit.reviewdb.ApprovalCategoryValue;
+
+public abstract class ApprovalUtil {
+
+ public static final ApprovalType VRIF;
+
+ public static final ApprovalType CRVW;
+
+ public static final ApprovalType IPCL;
+
+ private static final Map<String, ApprovalType> BY_NAME;
+
+ private static final Map<String, ApprovalType> BY_ID;
+
+ static {
+ ApprovalCategory vrifCategory = new ApprovalCategory(new ApprovalCategory.Id("VRIF"), "Verified"); //$NON-NLS-1$ //$NON-NLS-2$
+ vrifCategory.setAbbreviatedName("V"); //$NON-NLS-1$
+ vrifCategory.setPosition((short) 0);
+ List<ApprovalCategoryValue> vrifValues = new ArrayList<ApprovalCategoryValue>(3);
+ vrifValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(vrifCategory.getId(), (short) -1),
+ "Fails")); //$NON-NLS-1$
+ vrifValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(vrifCategory.getId(), (short) 0),
+ "No score")); //$NON-NLS-1$
+ vrifValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(vrifCategory.getId(), (short) 1),
+ "Verified")); //$NON-NLS-1$
+ VRIF = new ApprovalType(vrifCategory, vrifValues);
+
+ ApprovalCategory crvwCategory = new ApprovalCategory(new ApprovalCategory.Id("CRVW"), "Code Review"); //$NON-NLS-1$ //$NON-NLS-2$
+ crvwCategory.setAbbreviatedName("R"); //$NON-NLS-1$
+ crvwCategory.setPosition((short) 1);
+ List<ApprovalCategoryValue> crvwValues = new ArrayList<ApprovalCategoryValue>(5);
+ crvwValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(crvwCategory.getId(), (short) -2),
+ "Do not submit")); //$NON-NLS-1$
+ crvwValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(crvwCategory.getId(), (short) -1),
+ "I would prefer that you didn\u0027t submit this")); //$NON-NLS-1$
+ crvwValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(crvwCategory.getId(), (short) 0),
+ "No score")); //$NON-NLS-1$
+ crvwValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(crvwCategory.getId(), (short) 1),
+ "Looks good to me, but someone else must approve")); //$NON-NLS-1$
+ crvwValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(crvwCategory.getId(), (short) 2),
+ "Looks good to me, approved")); //$NON-NLS-1$
+ CRVW = new ApprovalType(crvwCategory, crvwValues);
+
+ ApprovalCategory ipclCategory = new ApprovalCategory(new ApprovalCategory.Id("IPCL"), "IP Clean"); //$NON-NLS-1$ //$NON-NLS-2$
+ ipclCategory.setAbbreviatedName("I"); //$NON-NLS-1$
+ ipclCategory.setPosition((short) 2);
+ List<ApprovalCategoryValue> ipclValues = new ArrayList<ApprovalCategoryValue>(3);
+ ipclValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(ipclCategory.getId(), (short) -1),
+ "Unclean IP, do not check in")); //$NON-NLS-1$
+ ipclValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(ipclCategory.getId(), (short) 0),
+ "No score")); //$NON-NLS-1$
+ ipclValues.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(ipclCategory.getId(), (short) 1),
+ "IP review completed")); //$NON-NLS-1$
+ IPCL = new ApprovalType(ipclCategory, ipclValues);
+
+ BY_NAME = new HashMap<String, ApprovalType>(3);
+ BY_NAME.put(VRIF.getCategory().getName(), VRIF);
+ BY_NAME.put(CRVW.getCategory().getName(), CRVW);
+ BY_NAME.put(IPCL.getCategory().getName(), IPCL);
+
+ BY_ID = new HashMap<String, ApprovalType>(3);
+ BY_ID.put(VRIF.getCategory().getId().get(), VRIF);
+ BY_ID.put(CRVW.getCategory().getId().get(), CRVW);
+ BY_ID.put(IPCL.getCategory().getId().get(), IPCL);
+ }
+
+ static ApprovalCategory.Id findCategoryIdByName(String name) {
+ if (BY_NAME.containsKey(name)) {
+ return BY_NAME.get(name).getCategory().getId();
+ }
+ return null;
+ }
+
+ public static String findCategoryNameById(String id) {
+ if (BY_ID.containsKey(id)) {
+ return BY_ID.get(id).getCategory().getName();
+ }
+ return null;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/CommentInfo.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/CommentInfo.java
new file mode 100644
index 0000000..e6b02d8
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/CommentInfo.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.gerrit.core.client.rest;
+
+/**
+ * Data model object for <a
+ * href="https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#comment-info">CommentInfo</a>.
+ */
+public class CommentInfo extends CommentInput {
+
+ // AccountInfo author; // unset for drafts
+}
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/CommentInput.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/CommentInput.java
new file mode 100644
index 0000000..9fa6918
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/CommentInput.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.gerrit.core.client.rest;
+
+import java.sql.Timestamp;
+
+/**
+ * Data model object for <a
+ * href="https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#comment-input">CommentInput</a>.
+ */
+public class CommentInput {
+
+ protected final String kind = "gerritcodereview#comment"; //$NON-NLS-1$
+
+ private String id;
+
+ private String path;
+
+ // REVISION (default) or PARENT
+ private String side;
+
+ // 0 for file comment (default)
+ private int line;
+
+ private String in_reply_to;
+
+ private Timestamp updated;
+
+ private String message;
+
+ public CommentInput() {
+ }
+
+ public CommentInput(CommentInfo info) {
+ this.id = info.getId();
+ this.path = info.getPath();
+ this.line = info.getLine();
+ this.message = info.getMessage();
+ }
+
+ public String getKind() {
+ return kind;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public int getLine() {
+ return line;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+}
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewInput.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewInput.java
index dcb88b5..5d800aa 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewInput.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewInput.java
@@ -10,15 +10,20 @@
*******************************************************************************/
package org.eclipse.mylyn.internal.gerrit.core.client.rest;
+import java.util.Map;
+
import org.eclipse.core.runtime.Assert;
/**
- * Data model object for https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#review-input
+ * Data model object for <a
+ * href="https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#review-input">ReviewInput</a>.
*/
public class ReviewInput {
private final String message;
+ private Map<String, CommentInput[]> comments;
+
public ReviewInput(String msg) {
Assert.isLegal(msg != null);
this.message = msg;
@@ -28,4 +33,11 @@ public class ReviewInput {
return message;
}
+ public Map<String, CommentInput[]> getComments() {
+ return comments;
+ }
+
+ public void setComments(Map<String, CommentInput[]> comments) {
+ this.comments = comments;
+ }
}
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/CommentInfoTest.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/CommentInfoTest.java
new file mode 100644
index 0000000..efbbe94
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/CommentInfoTest.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.gerrit.tests.core.client.rest;
+
+import java.io.File;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil;
+import org.eclipse.mylyn.internal.gerrit.core.client.JSonSupport;
+import org.eclipse.mylyn.internal.gerrit.core.client.rest.CommentInfo;
+import org.junit.Test;
+
+public class CommentInfoTest extends TestCase {
+
+ @Test
+ public void testFromEmptyJson() throws Exception {
+ CommentInfo commentInfo = parseFile("testdata/EmptyWithMagic.json");
+
+ assertNotNull(commentInfo);
+ assertNull(commentInfo.getId());
+ assertEquals("gerritcodereview#comment", commentInfo.getKind());
+ assertNull(commentInfo.getMessage());
+ assertNull(commentInfo.getPath());
+ assertEquals(0, commentInfo.getLine());
+ }
+
+ @Test
+ public void testFromInvalid() throws Exception {
+ CommentInfo commentInfo = parseFile("testdata/InvalidWithMagic.json");
+
+ assertNotNull(commentInfo);
+ assertNull(commentInfo.getId());
+ assertEquals("gerritcodereview#comment", commentInfo.getKind());
+ assertNull(commentInfo.getMessage());
+ assertNull(commentInfo.getPath());
+ assertEquals(0, commentInfo.getLine());
+ }
+
+ @Test
+ public void testFromCodeReviewMinusOne() throws Exception {
+ CommentInfo commentInfo = parseFile("testdata/CommentInfo_draft.json");
+
+ assertNotNull(commentInfo);
+ assertEquals("gerritcodereview#comment", commentInfo.getKind());
+ assertEquals("daeb3561_e122c600", commentInfo.getId());
+ assertEquals("Line 2 Comment", commentInfo.getMessage());
+ assertEquals(2, commentInfo.getLine());
+ }
+
+ private CommentInfo parseFile(String path) throws IOException {
+ File file = CommonTestUtil.getFile(this, path);
+ String content = CommonTestUtil.read(file);
+ return new JSonSupport().parseResponse(content, CommentInfo.class);
+ }
+
+}
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/PatchSetRemoteFactoryTest.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/PatchSetRemoteFactoryTest.java
index aaa0b1b..1aecddb 100644
--- a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/PatchSetRemoteFactoryTest.java
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/PatchSetRemoteFactoryTest.java
@@ -174,7 +174,7 @@ public class PatchSetRemoteFactoryTest extends GerritRemoteTest {
assertThat(fileComment.getDescription(), is("Line 2 Comment"));
reviewHarness.client.publishComments(reviewHarness.shortId, 2, "Submit Comments",
- Collections.<ApprovalCategoryValue.Id> emptySet(), null);
+ Collections.<ApprovalCategoryValue.Id> emptySet(), new NullProgressMonitor());
patchSetConsumer.retrieve(false);
patchSetListener.waitForResponse(3, 3);
allComments = commentFile.getAllComments();
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/CommentInfo_draft.json b/org.eclipse.mylyn.gerrit.tests/testdata/CommentInfo_draft.json
new file mode 100644
index 0000000..3987b5b
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/testdata/CommentInfo_draft.json
@@ -0,0 +1,7 @@
+{
+ "kind" : "gerritcodereview#comment",
+ "id" : "daeb3561_e122c600",
+ "line" : 2,
+ "message" : "Line 2 Comment",
+ "updated" : "2013-07-26 10:00:29.046000000"
+} \ No newline at end of file