Search in sources :

Example 26 with RobotCommentInfo

use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.

the class RobotCommentsIT method fixOnPreviousPatchSetWithoutChangeEditCannotBeApplied.

@Test
public void fixOnPreviousPatchSetWithoutChangeEditCannotBeApplied() throws Exception {
    fixReplacementInfo.path = FILE_NAME;
    fixReplacementInfo.replacement = "Modified content";
    fixReplacementInfo.range = createRange(3, 1, 3, 3);
    testCommentHelper.addRobotComment(changeId, withFixRobotCommentInput);
    List<RobotCommentInfo> robotCommentInfos = getRobotComments();
    // Remember patch set and add another one.
    String previousRevision = gApi.changes().id(changeId).get().currentRevision;
    amendChange(changeId);
    List<String> fixIds = getFixIds(robotCommentInfos);
    String fixId = Iterables.getOnlyElement(fixIds);
    ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> gApi.changes().id(changeId).revision(previousRevision).applyFix(fixId));
    assertThat(thrown).hasMessageThat().contains("current");
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 27 with RobotCommentInfo

use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.

the class RobotCommentsIT method getFixPreviewAddNewLineAtEnd.

@Test
public void getFixPreviewAddNewLineAtEnd() throws Exception {
    FixReplacementInfo replacement = new FixReplacementInfo();
    replacement.path = FILE_NAME3;
    replacement.range = createRange(2, 8, 2, 8);
    replacement.replacement = "\n";
    FixSuggestionInfo fixSuggestion = createFixSuggestionInfo(replacement);
    RobotCommentInput commentInput = TestCommentHelper.createRobotCommentInput(FILE_NAME3, fixSuggestion);
    testCommentHelper.addRobotComment(changeId, commentInput);
    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(FILE_NAME3);
    DiffInfo diff = fixPreview.get(FILE_NAME3);
    assertThat(diff).metaA().totalLineCount().isEqualTo(2);
    // Original file doesn't have EOL marker at the end of file.
    // Due to the additional EOL mark diff has one additional line
    // This behavior is in line with ordinary get diff API.
    assertThat(diff).metaB().totalLineCount().isEqualTo(3);
    assertThat(diff).content().hasSize(2);
    assertThat(diff).content().element(0).commonLines().containsExactly("1st line");
    assertThat(diff).content().element(1).linesOfA().containsExactly("2nd line");
    assertThat(diff).content().element(1).linesOfB().containsExactly("2nd line", "");
}
Also used : FixReplacementInfo(com.google.gerrit.extensions.common.FixReplacementInfo) FixSuggestionInfo(com.google.gerrit.extensions.common.FixSuggestionInfo) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 28 with RobotCommentInfo

use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.

the class RobotCommentsIT method fixWithTwoCloseReplacementsOnSameFileCanBeApplied.

@Test
public void fixWithTwoCloseReplacementsOnSameFileCanBeApplied() 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_NAME;
    fixReplacementInfo2.range = createRange(3, 0, 4, 0);
    fixReplacementInfo2.replacement = "Some other modified content\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\nSome other modified content\nFourth line\nFifth line\n" + "Sixth line\nSeventh line\nEighth line\nNinth line\nTenth line\n");
}
Also used : FixReplacementInfo(com.google.gerrit.extensions.common.FixReplacementInfo) FixSuggestionInfo(com.google.gerrit.extensions.common.FixSuggestionInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 29 with RobotCommentInfo

use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.

the class RobotCommentsIT method createdChangeEditIsBasedOnCurrentPatchSet.

@Test
public void createdChangeEditIsBasedOnCurrentPatchSet() throws Exception {
    String currentRevision = gApi.changes().id(changeId).get().currentRevision;
    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);
    assertThat(editInfo).baseRevision().isEqualTo(currentRevision);
}
Also used : EditInfo(com.google.gerrit.extensions.common.EditInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 30 with RobotCommentInfo

use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.

the class ListChangeRobotComments method apply.

@Override
public Response<Map<String, List<RobotCommentInfo>>> apply(ChangeResource rsrc) throws AuthException, PermissionBackendException {
    ChangeData cd = changeDataFactory.create(rsrc.getNotes());
    Map<String, List<RobotCommentInfo>> robotCommentsMap = commentJson.get().setFillAccounts(true).setFillPatchSet(true).newRobotCommentFormatter().format(commentsUtil.robotCommentsByChange(cd.notes()));
    List<RobotCommentInfo> commentInfos = robotCommentsMap.values().stream().flatMap(List::stream).collect(toList());
    List<ChangeMessage> changeMessages = changeMessagesUtil.byChange(rsrc.getNotes());
    CommentsUtil.linkCommentsToChangeMessages(commentInfos, changeMessages, false);
    return Response.ok(robotCommentsMap);
}
Also used : ChangeMessage(com.google.gerrit.entities.ChangeMessage) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) ChangeData(com.google.gerrit.server.query.change.ChangeData)

Aggregations

RobotCommentInfo (com.google.gerrit.extensions.common.RobotCommentInfo)34 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)33 Test (org.junit.Test)33 RobotCommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput)18 FixReplacementInfo (com.google.gerrit.extensions.common.FixReplacementInfo)16 FixSuggestionInfo (com.google.gerrit.extensions.common.FixSuggestionInfo)15 Change (com.google.gerrit.entities.Change)9 BinaryResult (com.google.gerrit.extensions.restapi.BinaryResult)8 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)7 ImmutableList (com.google.common.collect.ImmutableList)6 DiffInfo (com.google.gerrit.extensions.common.DiffInfo)6 RobotCommentInfoSubject.assertThatList (com.google.gerrit.extensions.common.testing.RobotCommentInfoSubject.assertThatList)6 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)6 EditInfo (com.google.gerrit.extensions.common.EditInfo)5 List (java.util.List)5 Collectors.toList (java.util.stream.Collectors.toList)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)3 Iterables (com.google.common.collect.Iterables)3 MoreCollectors.onlyElement (com.google.common.collect.MoreCollectors.onlyElement)3