use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.
the class RobotCommentsIT method addedRobotCommentsAreLinkedToChangeMessages.
@UseClockStep
@Test
public void addedRobotCommentsAreLinkedToChangeMessages() throws Exception {
// 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(10, TimeUnit.SECONDS);
RobotCommentInput c1 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
RobotCommentInput c2 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
RobotCommentInput c3 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
// Give the robot comments identifiable names for testing
c1.message = "robot comment 1";
c2.message = "robot comment 2";
c3.message = "robot comment 3";
testCommentHelper.addRobotComment(changeId, c1, "robot message 1");
TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
testCommentHelper.addRobotComment(changeId, c2, "robot message 2");
TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
testCommentHelper.addRobotComment(changeId, c3, "robot message 3");
TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
Map<String, List<RobotCommentInfo>> robotComments = gApi.changes().id(changeId).robotComments();
List<RobotCommentInfo> robotCommentsList = robotComments.values().stream().flatMap(List::stream).collect(toList());
List<ChangeMessageInfo> allMessages = gApi.changes().id(changeId).get(MESSAGES).messages.stream().collect(toList());
assertThat(allMessages.stream().map(cm -> cm.message).collect(toList())).containsExactly("Uploaded patch set 1.", "Patch Set 1:\n\n(1 comment)\n\nrobot message 1", "Patch Set 1:\n\n(1 comment)\n\nrobot message 2", "Patch Set 1:\n\n(1 comment)\n\nrobot message 3");
assertThat(robotCommentsList.stream().map(c -> c.message).collect(toList())).containsExactly("robot comment 1", "robot comment 2", "robot comment 3");
String message1ChangeId = allMessages.stream().filter(c -> c.message.contains("robot message 1")).collect(onlyElement()).id;
String message2ChangeId = allMessages.stream().filter(c -> c.message.contains("robot message 2")).collect(onlyElement()).id;
String message3ChangeId = allMessages.stream().filter(c -> c.message.contains("robot message 3")).collect(onlyElement()).id;
String comment1MessageId = robotCommentsList.stream().filter(c -> c.message.equals("robot comment 1")).collect(onlyElement()).changeMessageId;
String comment2MessageId = robotCommentsList.stream().filter(c -> c.message.equals("robot comment 2")).collect(onlyElement()).changeMessageId;
String comment3MessageId = robotCommentsList.stream().filter(c -> c.message.equals("robot comment 3")).collect(onlyElement()).changeMessageId;
/**
* All change messages have the auto-generated tag. Robot comments can be linked to
* auto-generated messages where each comment is linked to the next nearest change message in
* timestamp
*/
assertThat(message1ChangeId).isEqualTo(comment1MessageId);
assertThat(message2ChangeId).isEqualTo(comment2MessageId);
assertThat(message3ChangeId).isEqualTo(comment3MessageId);
}
use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.
the class RobotCommentsIT method patchsetLevelRobotCommentCanBeAddedAndRetrieved.
@Test
public void patchsetLevelRobotCommentCanBeAddedAndRetrieved() throws Exception {
RobotCommentInput input = TestCommentHelper.createRobotCommentInput(PATCHSET_LEVEL);
testCommentHelper.addRobotComment(changeId, input);
List<RobotCommentInfo> results = getRobotComments();
assertThatList(results).onlyElement().path().isEqualTo(PATCHSET_LEVEL);
}
use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.
the class RobotCommentsIT method getFixPreviewForCommitMsg.
@Test
public void getFixPreviewForCommitMsg() throws Exception {
String footer = "Change-Id: " + changeId;
updateCommitMessage(changeId, "Commit title\n\nCommit message line 1\nLine 2\nLine 3\nLast line\n\n" + footer + "\n");
FixReplacementInfo commitMsgReplacement = new FixReplacementInfo();
commitMsgReplacement.path = Patch.COMMIT_MSG;
// The test assumes that the first 5 lines is a header.
// Line 10 has content "Line 2"
commitMsgReplacement.range = createRange(10, 0, 11, 0);
commitMsgReplacement.replacement = "New content\n";
FixSuggestionInfo commitMsgSuggestionInfo = createFixSuggestionInfo(commitMsgReplacement);
RobotCommentInput commitMsgRobotCommentInput = TestCommentHelper.createRobotCommentInput(Patch.COMMIT_MSG, commitMsgSuggestionInfo);
testCommentHelper.addRobotComment(changeId, commitMsgRobotCommentInput);
List<RobotCommentInfo> robotCommentInfos = getRobotComments();
List<String> fixIds = getFixIds(robotCommentInfos);
String fixId = Iterables.getOnlyElement(fixIds);
Map<String, DiffInfo> fixPreview = gApi.changes().id(changeId).current().getFixPreview(fixId);
assertThat(fixPreview).hasSize(1);
assertThat(fixPreview).containsKey(Patch.COMMIT_MSG);
DiffInfo diff = fixPreview.get(Patch.COMMIT_MSG);
assertThat(diff).metaA().name().isEqualTo(Patch.COMMIT_MSG);
assertThat(diff).metaA().contentType().isEqualTo(GERRIT_COMMIT_MESSAGE_TYPE);
assertThat(diff).metaB().name().isEqualTo(Patch.COMMIT_MSG);
assertThat(diff).metaB().contentType().isEqualTo(GERRIT_COMMIT_MESSAGE_TYPE);
assertThat(diff).content().element(0).commonLines().hasSize(9);
// Header has a dynamic content, do not check it
assertThat(diff).content().element(0).commonLines().element(6).isEqualTo("Commit title");
assertThat(diff).content().element(0).commonLines().element(7).isEqualTo("");
assertThat(diff).content().element(0).commonLines().element(8).isEqualTo("Commit message line 1");
assertThat(diff).content().element(1).linesOfA().containsExactly("Line 2");
assertThat(diff).content().element(1).linesOfB().containsExactly("New content");
assertThat(diff).content().element(2).commonLines().containsExactly("Line 3", "Last line", "", footer, "");
}
use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.
the class RobotCommentsIT method fixOnCurrentPatchSetWithChangeEditOnPreviousPatchSetCannotBeApplied.
@Test
public void fixOnCurrentPatchSetWithChangeEditOnPreviousPatchSetCannotBeApplied() throws Exception {
// Create an empty change edit.
gApi.changes().id(changeId).edit().create();
// Add another patch set.
amendChange(changeId);
fixReplacementInfo.path = FILE_NAME;
fixReplacementInfo.replacement = "Modified content";
fixReplacementInfo.range = createRange(3, 1, 3, 3);
testCommentHelper.addRobotComment(changeId, withFixRobotCommentInput);
List<RobotCommentInfo> robotCommentInfos = getRobotComments();
List<String> fixIds = getFixIds(robotCommentInfos);
String fixId = Iterables.getOnlyElement(fixIds);
ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> gApi.changes().id(changeId).current().applyFix(fixId));
assertThat(thrown).hasMessageThat().contains("based");
}
use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.
the class PatchsetOperationsImplTest method robotCommentIsCreatedWithRobotId.
@Test
public void robotCommentIsCreatedWithRobotId() throws Exception {
Change.Id changeId = changeOperations.newChange().create();
String commentUuid = changeOperations.change(changeId).currentPatchset().newRobotComment().robotId("robot-id").create();
RobotCommentInfo comment = getRobotCommentFromServerInCurrentPatchset(changeId, commentUuid);
assertThat(comment).robotId().isEqualTo("robot-id");
}
Aggregations