Merge "Allow linking robot comments to auto-generated change messages."
This commit is contained in:
@@ -242,7 +242,9 @@ public class CommentsUtil {
|
|||||||
* @param changeMessages list of change messages
|
* @param changeMessages list of change messages
|
||||||
*/
|
*/
|
||||||
public static void linkCommentsToChangeMessages(
|
public static void linkCommentsToChangeMessages(
|
||||||
List<? extends CommentInfo> comments, List<ChangeMessage> changeMessages) {
|
List<? extends CommentInfo> comments,
|
||||||
|
List<ChangeMessage> changeMessages,
|
||||||
|
boolean skipAutoGeneratedMessages) {
|
||||||
ArrayList<ChangeMessage> sortedChangeMessages =
|
ArrayList<ChangeMessage> sortedChangeMessages =
|
||||||
changeMessages.stream()
|
changeMessages.stream()
|
||||||
.sorted(comparing(ChangeMessage::getWrittenOn))
|
.sorted(comparing(ChangeMessage::getWrittenOn))
|
||||||
@@ -257,7 +259,7 @@ public class CommentsUtil {
|
|||||||
// message in timestamp
|
// message in timestamp
|
||||||
while (cmItr < sortedChangeMessages.size()) {
|
while (cmItr < sortedChangeMessages.size()) {
|
||||||
ChangeMessage cm = sortedChangeMessages.get(cmItr);
|
ChangeMessage cm = sortedChangeMessages.get(cmItr);
|
||||||
if (isAfter(comment, cm) || skipChangeMessage(cm)) {
|
if (isAfter(comment, cm) || (skipAutoGeneratedMessages && isAutoGenerated(cm))) {
|
||||||
cmItr += 1;
|
cmItr += 1;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
@@ -269,7 +271,7 @@ public class CommentsUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean skipChangeMessage(ChangeMessage cm) {
|
private static boolean isAutoGenerated(ChangeMessage cm) {
|
||||||
return ChangeMessagesUtil.isAutogenerated(cm.getTag());
|
return ChangeMessagesUtil.isAutogenerated(cm.getTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class ListChangeComments implements RestReadView<ChangeResource> {
|
|||||||
throws PermissionBackendException {
|
throws PermissionBackendException {
|
||||||
ImmutableList<CommentInfo> commentInfos = getCommentFormatter().formatAsList(comments);
|
ImmutableList<CommentInfo> commentInfos = getCommentFormatter().formatAsList(comments);
|
||||||
List<ChangeMessage> changeMessages = changeMessagesUtil.byChange(rsrc.getNotes());
|
List<ChangeMessage> changeMessages = changeMessagesUtil.byChange(rsrc.getNotes());
|
||||||
CommentsUtil.linkCommentsToChangeMessages(commentInfos, changeMessages);
|
CommentsUtil.linkCommentsToChangeMessages(commentInfos, changeMessages, true);
|
||||||
return commentInfos;
|
return commentInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ public class ListChangeComments implements RestReadView<ChangeResource> {
|
|||||||
List<CommentInfo> commentInfos =
|
List<CommentInfo> commentInfos =
|
||||||
commentInfosMap.values().stream().flatMap(List::stream).collect(toList());
|
commentInfosMap.values().stream().flatMap(List::stream).collect(toList());
|
||||||
List<ChangeMessage> changeMessages = changeMessagesUtil.byChange(rsrc.getNotes());
|
List<ChangeMessage> changeMessages = changeMessagesUtil.byChange(rsrc.getNotes());
|
||||||
CommentsUtil.linkCommentsToChangeMessages(commentInfos, changeMessages);
|
CommentsUtil.linkCommentsToChangeMessages(commentInfos, changeMessages, true);
|
||||||
return commentInfosMap;
|
return commentInfosMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class ListChangeRobotComments implements RestReadView<ChangeResource> {
|
|||||||
List<RobotCommentInfo> commentInfos =
|
List<RobotCommentInfo> commentInfos =
|
||||||
robotCommentsMap.values().stream().flatMap(List::stream).collect(toList());
|
robotCommentsMap.values().stream().flatMap(List::stream).collect(toList());
|
||||||
List<ChangeMessage> changeMessages = changeMessagesUtil.byChange(rsrc.getNotes());
|
List<ChangeMessage> changeMessages = changeMessagesUtil.byChange(rsrc.getNotes());
|
||||||
CommentsUtil.linkCommentsToChangeMessages(commentInfos, changeMessages);
|
CommentsUtil.linkCommentsToChangeMessages(commentInfos, changeMessages, false);
|
||||||
return Response.ok(robotCommentsMap);
|
return Response.ok(robotCommentsMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class ListRobotComments implements RestReadView<RevisionResource> {
|
|||||||
Iterable<RobotComment> comments, RevisionResource rsrc) throws PermissionBackendException {
|
Iterable<RobotComment> comments, RevisionResource rsrc) throws PermissionBackendException {
|
||||||
ImmutableList<RobotCommentInfo> commentInfos = getCommentFormatter().formatAsList(comments);
|
ImmutableList<RobotCommentInfo> commentInfos = getCommentFormatter().formatAsList(comments);
|
||||||
List<ChangeMessage> changeMessages = changeMessagesUtil.byChange(rsrc.getNotes());
|
List<ChangeMessage> changeMessages = changeMessagesUtil.byChange(rsrc.getNotes());
|
||||||
CommentsUtil.linkCommentsToChangeMessages(commentInfos, changeMessages);
|
CommentsUtil.linkCommentsToChangeMessages(commentInfos, changeMessages, false);
|
||||||
return commentInfos;
|
return commentInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ public class ListRobotComments implements RestReadView<RevisionResource> {
|
|||||||
List<RobotCommentInfo> commentInfos =
|
List<RobotCommentInfo> commentInfos =
|
||||||
commentInfosMap.values().stream().flatMap(List::stream).collect(toList());
|
commentInfosMap.values().stream().flatMap(List::stream).collect(toList());
|
||||||
List<ChangeMessage> changeMessages = changeMessagesUtil.byChange(rsrc.getNotes());
|
List<ChangeMessage> changeMessages = changeMessagesUtil.byChange(rsrc.getNotes());
|
||||||
CommentsUtil.linkCommentsToChangeMessages(commentInfos, changeMessages);
|
CommentsUtil.linkCommentsToChangeMessages(commentInfos, changeMessages, false);
|
||||||
return commentInfosMap;
|
return commentInfosMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import com.google.gerrit.extensions.client.Comment.Range;
|
|||||||
import com.google.gerrit.extensions.client.Side;
|
import com.google.gerrit.extensions.client.Side;
|
||||||
import com.google.gerrit.extensions.common.CommentInfo;
|
import com.google.gerrit.extensions.common.CommentInfo;
|
||||||
import com.google.gerrit.extensions.common.FixSuggestionInfo;
|
import com.google.gerrit.extensions.common.FixSuggestionInfo;
|
||||||
|
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -144,6 +145,7 @@ public class TestCommentHelper {
|
|||||||
reviewInput.robotComments =
|
reviewInput.robotComments =
|
||||||
Collections.singletonMap(robotCommentInput.path, ImmutableList.of(robotCommentInput));
|
Collections.singletonMap(robotCommentInput.path, ImmutableList.of(robotCommentInput));
|
||||||
reviewInput.message = message;
|
reviewInput.message = message;
|
||||||
|
reviewInput.tag = ChangeMessagesUtil.AUTOGENERATED_TAG_PREFIX;
|
||||||
gApi.changes().id(targetChangeId).current().review(reviewInput);
|
gApi.changes().id(targetChangeId).current().review(reviewInput);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ public class RobotCommentsIT extends AbstractDaemonTest {
|
|||||||
TestTimeUtil.resetWithClockStep(0, TimeUnit.SECONDS);
|
TestTimeUtil.resetWithClockStep(0, TimeUnit.SECONDS);
|
||||||
createChange();
|
createChange();
|
||||||
/* Advancing the time after creating the change so that the first robot comment is not in the same timestamp as with the change creation */
|
/* Advancing the time after creating the change so that the first robot comment is not in the same timestamp as with the change creation */
|
||||||
TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
|
TestTimeUtil.incrementClock(10, TimeUnit.SECONDS);
|
||||||
|
|
||||||
RobotCommentInput c1 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
|
RobotCommentInput c1 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
|
||||||
RobotCommentInput c2 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
|
RobotCommentInput c2 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
|
||||||
@@ -220,9 +220,9 @@ public class RobotCommentsIT extends AbstractDaemonTest {
|
|||||||
.changeMessageId;
|
.changeMessageId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload PS message, robot message 1 & robot comment 1 all have the same timestamp. The robot
|
* All change messages have the auto-generated tag. Robot comments can be linked to
|
||||||
* comment is matched to robot message 1 because the PS upload message is auto-generated and is
|
* auto-generated messages where each comment is linked to the next nearest change message in
|
||||||
* ignored in matching
|
* timestamp
|
||||||
*/
|
*/
|
||||||
assertThat(message1ChangeId).isEqualTo(comment1MessageId);
|
assertThat(message1ChangeId).isEqualTo(comment1MessageId);
|
||||||
assertThat(message2ChangeId).isEqualTo(comment2MessageId);
|
assertThat(message2ChangeId).isEqualTo(comment2MessageId);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableList;
|
|||||||
import com.google.gerrit.entities.Change;
|
import com.google.gerrit.entities.Change;
|
||||||
import com.google.gerrit.entities.ChangeMessage;
|
import com.google.gerrit.entities.ChangeMessage;
|
||||||
import com.google.gerrit.extensions.common.CommentInfo;
|
import com.google.gerrit.extensions.common.CommentInfo;
|
||||||
|
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||||
import com.google.gerrit.server.CommentsUtil;
|
import com.google.gerrit.server.CommentsUtil;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -33,27 +34,38 @@ public class ListChangeCommentsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void commentsLinkedToChangeMessages() {
|
public void commentsLinkedToChangeMessages() {
|
||||||
|
/**
|
||||||
|
* Human comments should not be linked to auto-generated messages. A comment is linked to the
|
||||||
|
* nearest next change message in timestamp
|
||||||
|
*/
|
||||||
CommentInfo c1 = getNewCommentInfo("c1", Timestamp.valueOf("2018-01-01 09:01:00"));
|
CommentInfo c1 = getNewCommentInfo("c1", Timestamp.valueOf("2018-01-01 09:01:00"));
|
||||||
CommentInfo c2 = getNewCommentInfo("c2", Timestamp.valueOf("2018-01-01 09:01:15"));
|
CommentInfo c2 = getNewCommentInfo("c2", Timestamp.valueOf("2018-01-01 09:01:15"));
|
||||||
CommentInfo c3 = getNewCommentInfo("c3", Timestamp.valueOf("2018-01-01 09:01:25"));
|
CommentInfo c3 = getNewCommentInfo("c3", Timestamp.valueOf("2018-01-01 09:01:25"));
|
||||||
|
|
||||||
ChangeMessage cm1 =
|
ChangeMessage cm1 =
|
||||||
getNewChangeMessage("cm1key", "cm1", Timestamp.valueOf("2018-01-01 00:00:00"));
|
getNewChangeMessage("cm1key", "cm1", Timestamp.valueOf("2018-01-01 00:00:00"), null);
|
||||||
|
ChangeMessage cmIgnore =
|
||||||
|
getNewChangeMessage(
|
||||||
|
"cm2key",
|
||||||
|
"cm2",
|
||||||
|
Timestamp.valueOf("2018-01-01 09:01:15"),
|
||||||
|
ChangeMessagesUtil.AUTOGENERATED_TAG_PREFIX);
|
||||||
ChangeMessage cm2 =
|
ChangeMessage cm2 =
|
||||||
getNewChangeMessage("cm2key", "cm2", Timestamp.valueOf("2018-01-01 09:01:15"));
|
getNewChangeMessage("cm2key", "cm2", Timestamp.valueOf("2018-01-01 09:01:16"), null);
|
||||||
ChangeMessage cm3 =
|
ChangeMessage cm3 =
|
||||||
getNewChangeMessage("cm3key", "cm3", Timestamp.valueOf("2018-01-01 09:01:27"));
|
getNewChangeMessage("cm3key", "cm3", Timestamp.valueOf("2018-01-01 09:01:27"), null);
|
||||||
|
|
||||||
assertThat(c1.changeMessageId).isNull();
|
assertThat(c1.changeMessageId).isNull();
|
||||||
assertThat(c2.changeMessageId).isNull();
|
assertThat(c2.changeMessageId).isNull();
|
||||||
assertThat(c3.changeMessageId).isNull();
|
assertThat(c3.changeMessageId).isNull();
|
||||||
|
|
||||||
ImmutableList<CommentInfo> comments = ImmutableList.of(c1, c2, c3);
|
ImmutableList<CommentInfo> comments = ImmutableList.of(c1, c2, c3);
|
||||||
ImmutableList<ChangeMessage> changeMessages = ImmutableList.of(cm1, cm2, cm3);
|
ImmutableList<ChangeMessage> changeMessages = ImmutableList.of(cm1, cmIgnore, cm2, cm3);
|
||||||
|
|
||||||
CommentsUtil.linkCommentsToChangeMessages(comments, changeMessages);
|
CommentsUtil.linkCommentsToChangeMessages(comments, changeMessages, true);
|
||||||
|
|
||||||
assertThat(c1.changeMessageId).isEqualTo(changeMessageKey(cm2));
|
assertThat(c1.changeMessageId).isEqualTo(changeMessageKey(cm2));
|
||||||
|
/** comment 2 ignored the auto-generated change message */
|
||||||
assertThat(c2.changeMessageId).isEqualTo(changeMessageKey(cm2));
|
assertThat(c2.changeMessageId).isEqualTo(changeMessageKey(cm2));
|
||||||
assertThat(c3.changeMessageId).isEqualTo(changeMessageKey(cm3));
|
assertThat(c3.changeMessageId).isEqualTo(changeMessageKey(cm3));
|
||||||
}
|
}
|
||||||
@@ -65,10 +77,12 @@ public class ListChangeCommentsTest {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ChangeMessage getNewChangeMessage(String id, String message, Timestamp ts) {
|
private static ChangeMessage getNewChangeMessage(
|
||||||
|
String id, String message, Timestamp ts, String tag) {
|
||||||
ChangeMessage.Key key = ChangeMessage.key(Change.id(1), id);
|
ChangeMessage.Key key = ChangeMessage.key(Change.id(1), id);
|
||||||
ChangeMessage cm = new ChangeMessage(key, null, ts, null);
|
ChangeMessage cm = new ChangeMessage(key, null, ts, null);
|
||||||
cm.setMessage(message);
|
cm.setMessage(message);
|
||||||
|
cm.setTag(tag);
|
||||||
return cm;
|
return cm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user