use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.
the class RobotCommentsIT method twoConflictingFixesOnSameFileCannotBeApplied.
@Test
public void twoConflictingFixesOnSameFileCannotBeApplied() throws Exception {
FixReplacementInfo fixReplacementInfo1 = new FixReplacementInfo();
fixReplacementInfo1.path = FILE_NAME;
fixReplacementInfo1.range = createRange(2, 0, 3, 1);
fixReplacementInfo1.replacement = "First modification\n";
FixSuggestionInfo fixSuggestionInfo1 = createFixSuggestionInfo(fixReplacementInfo1);
FixReplacementInfo fixReplacementInfo2 = new FixReplacementInfo();
fixReplacementInfo2.path = FILE_NAME;
fixReplacementInfo2.range = createRange(3, 0, 4, 0);
fixReplacementInfo2.replacement = "Some other modified content\n";
FixSuggestionInfo fixSuggestionInfo2 = createFixSuggestionInfo(fixReplacementInfo2);
RobotCommentInput robotCommentInput1 = TestCommentHelper.createRobotCommentInput(FILE_NAME, fixSuggestionInfo1);
RobotCommentInput robotCommentInput2 = TestCommentHelper.createRobotCommentInput(FILE_NAME, fixSuggestionInfo2);
testCommentHelper.addRobotComment(changeId, robotCommentInput1);
testCommentHelper.addRobotComment(changeId, robotCommentInput2);
List<RobotCommentInfo> robotCommentInfos = getRobotComments();
List<String> fixIds = getFixIds(robotCommentInfos);
gApi.changes().id(changeId).current().applyFix(fixIds.get(0));
ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> gApi.changes().id(changeId).current().applyFix(fixIds.get(1)));
assertThat(thrown).hasMessageThat().contains("merge");
}
use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.
the class RobotCommentsIT method fixInvolvingTwoFilesCanBeApplied.
@Test
public void fixInvolvingTwoFilesCanBeApplied() throws Exception {
FixReplacementInfo fixReplacementInfo1 = new FixReplacementInfo();
fixReplacementInfo1.path = FILE_NAME;
fixReplacementInfo1.range = createRange(2, 0, 3, 0);
fixReplacementInfo1.replacement = "First modification\n";
FixReplacementInfo fixReplacementInfo2 = new FixReplacementInfo();
fixReplacementInfo2.path = FILE_NAME2;
fixReplacementInfo2.range = createRange(1, 0, 2, 0);
fixReplacementInfo2.replacement = "Different file modification\n";
FixSuggestionInfo fixSuggestionInfo = createFixSuggestionInfo(fixReplacementInfo1, fixReplacementInfo2);
withFixRobotCommentInput.fixSuggestions = ImmutableList.of(fixSuggestionInfo);
testCommentHelper.addRobotComment(changeId, withFixRobotCommentInput);
List<RobotCommentInfo> robotCommentInfos = getRobotComments();
List<String> fixIds = getFixIds(robotCommentInfos);
String fixId = Iterables.getOnlyElement(fixIds);
gApi.changes().id(changeId).current().applyFix(fixId);
Optional<BinaryResult> file = gApi.changes().id(changeId).edit().getFile(FILE_NAME);
BinaryResultSubject.assertThat(file).value().asString().isEqualTo("First line\nFirst modification\nThird line\nFourth line\nFifth line\nSixth line\n" + "Seventh line\nEighth line\nNinth line\nTenth line\n");
Optional<BinaryResult> file2 = gApi.changes().id(changeId).edit().getFile(FILE_NAME2);
BinaryResultSubject.assertThat(file2).value().asString().isEqualTo("Different file modification\n2nd line\n3rd line\n");
}
use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.
the class RobotCommentsIT method getFixPreviewForNonExistingFile.
@Test
public void getFixPreviewForNonExistingFile() throws Exception {
FixReplacementInfo replacement = new FixReplacementInfo();
replacement.path = "a_non_existent_file.txt";
replacement.range = createRange(1, 0, 2, 0);
replacement.replacement = "Modified content\n";
FixSuggestionInfo fixSuggestion = createFixSuggestionInfo(replacement);
RobotCommentInput commentInput = TestCommentHelper.createRobotCommentInput(FILE_NAME2, fixSuggestion);
testCommentHelper.addRobotComment(changeId, commentInput);
List<RobotCommentInfo> robotCommentInfos = getRobotComments();
List<String> fixIds = getFixIds(robotCommentInfos);
String fixId = Iterables.getOnlyElement(fixIds);
assertThrows(ResourceNotFoundException.class, () -> gApi.changes().id(changeId).current().getFixPreview(fixId));
}
use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.
the class RobotCommentsIT method canCreateRobotCommentWithHumanCommentAsParent.
@Test
public void canCreateRobotCommentWithHumanCommentAsParent() throws Exception {
Change.Id changeId = changeOperations.newChange().create();
String changeIdString = changeOperations.change(changeId).get().changeId();
String parentCommentUuid = changeOperations.change(changeId).currentPatchset().newComment().create();
ReviewInput.RobotCommentInput robotCommentInput = TestCommentHelper.createRobotCommentInputWithMandatoryFields(COMMIT_MSG);
robotCommentInput.message = "comment reply";
robotCommentInput.inReplyTo = parentCommentUuid;
testCommentHelper.addRobotComment(changeIdString, robotCommentInput);
RobotCommentInfo resultComment = Iterables.getOnlyElement(gApi.changes().id(changeIdString).current().robotCommentsAsList().stream().filter(c -> c.message.equals("comment reply")).collect(toImmutableSet()));
assertThat(resultComment.inReplyTo).isEqualTo(parentCommentUuid);
}
use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.
the class RobotCommentsIT method applyingFixOnTopOfChangeEditReturnsEditInfoForUpdatedChangeEdit.
@Test
public void applyingFixOnTopOfChangeEditReturnsEditInfoForUpdatedChangeEdit() throws Exception {
gApi.changes().id(changeId).edit().create();
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);
EditInfo editInfo = gApi.changes().id(changeId).current().applyFix(fixId);
Optional<EditInfo> expectedEditInfo = gApi.changes().id(changeId).edit().get();
String expectedEditCommit = expectedEditInfo.map(edit -> edit.commit.commit).orElse("");
assertThat(editInfo).commit().commit().isEqualTo(expectedEditCommit);
String expectedBaseRevision = expectedEditInfo.map(edit -> edit.baseRevision).orElse("");
assertThat(editInfo).baseRevision().isEqualTo(expectedBaseRevision);
}
Aggregations