Merge "Support arbitrary properties on robot comments"

This commit is contained in:
Dave Borowitz
2016-10-10 15:42:22 +00:00
committed by Gerrit Code Review
7 changed files with 48 additions and 3 deletions

View File

@@ -5712,6 +5712,8 @@ In addition `RobotCommentInfo` has the following fields:
|`robot_id` ||The ID of the robot that generated this comment.
|`robot_run_id` ||An ID of the run of the robot.
|`url` |optional|URL to more information.
|`properties` |optional|
Robot specific properties as map that maps arbitrary keys to values.
|===========================
[[robot-comment-input]]

View File

@@ -75,6 +75,31 @@ public class RobotCommentsIT extends AbstractDaemonTest {
assertRobotComment(comment3, in);
}
@Test
public void noOptionalFields() throws Exception {
assume().that(notesMigration.enabled()).isTrue();
PushOneCommit.Result r = createChange();
RobotCommentInput in = createRobotCommentInputWithMandatoryFields();
ReviewInput reviewInput = new ReviewInput();
Map<String, List<RobotCommentInput>> robotComments = new HashMap<>();
robotComments.put(in.path, Collections.singletonList(in));
reviewInput.robotComments = robotComments;
reviewInput.message = "comment test";
gApi.changes()
.id(r.getChangeId())
.current()
.review(reviewInput);
Map<String, List<RobotCommentInfo>> out = gApi.changes()
.id(r.getChangeId())
.revision(r.getCommit().name())
.robotComments();
assertThat(out).hasSize(1);
RobotCommentInfo comment = Iterables.getOnlyElement(out.get(in.path));
assertRobotComment(comment, in, false);
}
@Test
public void robotCommentsNotSupported() throws Exception {
assume().that(notesMigration.enabled()).isFalse();
@@ -95,17 +120,25 @@ public class RobotCommentsIT extends AbstractDaemonTest {
.review(reviewInput);
}
private RobotCommentInput createRobotCommentInput() {
private RobotCommentInput createRobotCommentInputWithMandatoryFields() {
RobotCommentInput in = new RobotCommentInput();
in.robotId = "happyRobot";
in.robotRunId = "1";
in.url = "http://www.happy-robot.com";
in.line = 1;
in.message = "nit: trailing whitespace";
in.path = FILE_NAME;
return in;
}
private RobotCommentInput createRobotCommentInput() {
RobotCommentInput in = createRobotCommentInputWithMandatoryFields();
in.url = "http://www.happy-robot.com";
in.properties = new HashMap<>();
in.properties.put("key1", "value1");
in.properties.put("key2", "value2");
return in;
}
private void assertRobotComment(RobotCommentInfo c,
RobotCommentInput expected) {
assertRobotComment(c, expected, true);
@@ -116,6 +149,7 @@ public class RobotCommentsIT extends AbstractDaemonTest {
assertThat(c.robotId).isEqualTo(expected.robotId);
assertThat(c.robotRunId).isEqualTo(expected.robotRunId);
assertThat(c.url).isEqualTo(expected.url);
assertThat(c.properties).isEqualTo(expected.properties);
assertThat(c.line).isEqualTo(expected.line);
assertThat(c.message).isEqualTo(expected.message);

View File

@@ -102,6 +102,7 @@ public class ReviewInput {
public String robotId;
public String robotRunId;
public String url;
public Map<String, String> properties;
}
public ReviewInput message(String msg) {

View File

@@ -14,8 +14,11 @@
package com.google.gerrit.extensions.common;
import java.util.Map;
public class RobotCommentInfo extends CommentInfo {
public String robotId;
public String robotRunId;
public String url;
public Map<String, String> properties;
}

View File

@@ -15,12 +15,14 @@
package com.google.gerrit.reviewdb.client;
import java.sql.Timestamp;
import java.util.Map;
import java.util.Objects;
public class RobotComment extends Comment {
public String robotId;
public String robotRunId;
public String url;
public Map<String, String> properties;
public RobotComment(Key key, Account.Id author, Timestamp writtenOn,
short side, String message, String serverId, String robotId,
@@ -47,7 +49,8 @@ public class RobotComment extends Comment {
.append("range=").append(Objects.toString(range, "")).append(',')
.append("revId=").append(revId != null ? revId : "").append(',')
.append("tag=").append(Objects.toString(tag, "")).append(',')
.append("url=").append(url)
.append("url=").append(url).append(',')
.append("properties=").append(properties != null ? properties : "")
.append('}')
.toString();
}

View File

@@ -180,6 +180,7 @@ class CommentJson {
rci.robotId = c.robotId;
rci.robotRunId = c.robotRunId;
rci.url = c.url;
rci.properties = c.properties;
fillCommentInfo(c, rci, loader);
return rci;
}

View File

@@ -597,6 +597,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
c.robotId, c.robotRunId);
e.parentUuid = Url.decode(c.inReplyTo);
e.url = c.url;
e.properties = c.properties;
e.setLineNbrAndRange(c.line, c.range);
e.tag = in.tag;
setCommentRevId(e, patchListCache, ctx.getChange(), ps);