use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.
the class ChangesRestApiBindingsIT method robotCommentEndpoints.
@Test
public void robotCommentEndpoints() throws Exception {
String changeId = createChange().getChangeId();
RobotCommentInput robotCommentInput = new RobotCommentInput();
robotCommentInput.robotId = "happyRobot";
robotCommentInput.robotRunId = "1";
robotCommentInput.line = 1;
robotCommentInput.message = "nit: trailing whitespace";
robotCommentInput.path = Patch.COMMIT_MSG;
ReviewInput reviewInput = new ReviewInput();
reviewInput.robotComments = Collections.singletonMap(robotCommentInput.path, ImmutableList.of(robotCommentInput));
reviewInput.message = "robot comment test";
gApi.changes().id(changeId).current().review(reviewInput);
List<RobotCommentInfo> robotCommentInfos = gApi.changes().id(changeId).current().robotCommentsAsList();
RobotCommentInfo robotCommentInfo = Iterables.getOnlyElement(robotCommentInfos);
RestApiCallHelper.execute(adminRestSession, ROBOT_COMMENT_ENDPOINTS, changeId, "current", robotCommentInfo.id);
}
use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.
the class RobotCommentsIT method addedRobotCommentsCanBeRetrieved.
@Test
public void addedRobotCommentsCanBeRetrieved() throws Exception {
RobotCommentInput in = TestCommentHelper.createRobotCommentInput(FILE_NAME);
testCommentHelper.addRobotComment(changeId, in);
Map<String, List<RobotCommentInfo>> out = gApi.changes().id(changeId).current().robotComments();
assertThat(out).hasSize(1);
RobotCommentInfo comment = Iterables.getOnlyElement(out.get(in.path));
assertRobotComment(comment, in, false);
}
use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.
the class RobotCommentsIT method twoFixesOfSameRobotCommentCanBeApplied.
@Test
public void twoFixesOfSameRobotCommentCanBeApplied() throws Exception {
FixReplacementInfo fixReplacementInfo1 = new FixReplacementInfo();
fixReplacementInfo1.path = FILE_NAME;
fixReplacementInfo1.range = createRange(2, 0, 3, 0);
fixReplacementInfo1.replacement = "First modification\n";
FixSuggestionInfo fixSuggestionInfo1 = createFixSuggestionInfo(fixReplacementInfo1);
FixReplacementInfo fixReplacementInfo2 = new FixReplacementInfo();
fixReplacementInfo2.path = FILE_NAME;
fixReplacementInfo2.range = createRange(8, 0, 9, 0);
fixReplacementInfo2.replacement = "Some other modified content\n";
FixSuggestionInfo fixSuggestionInfo2 = createFixSuggestionInfo(fixReplacementInfo2);
withFixRobotCommentInput.fixSuggestions = ImmutableList.of(fixSuggestionInfo1, fixSuggestionInfo2);
testCommentHelper.addRobotComment(changeId, withFixRobotCommentInput);
List<RobotCommentInfo> robotCommentInfos = getRobotComments();
List<String> fixIds = getFixIds(robotCommentInfos);
gApi.changes().id(changeId).current().applyFix(fixIds.get(0));
gApi.changes().id(changeId).current().applyFix(fixIds.get(1));
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\nSome other modified content\nNinth line\nTenth line\n");
}
use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.
the class RobotCommentsIT method getFixPreview.
@Test
public void getFixPreview() throws Exception {
FixReplacementInfo fixReplacementInfoFile1 = new FixReplacementInfo();
fixReplacementInfoFile1.path = FILE_NAME;
fixReplacementInfoFile1.replacement = "some replacement code";
fixReplacementInfoFile1.range = createRange(3, 9, 8, 4);
FixReplacementInfo fixReplacementInfoFile2 = new FixReplacementInfo();
fixReplacementInfoFile2.path = FILE_NAME2;
fixReplacementInfoFile2.replacement = "New line\n";
fixReplacementInfoFile2.range = createRange(2, 0, 2, 0);
fixSuggestionInfo = createFixSuggestionInfo(fixReplacementInfoFile1, fixReplacementInfoFile2);
withFixRobotCommentInput = TestCommentHelper.createRobotCommentInput(FILE_NAME, fixSuggestionInfo);
testCommentHelper.addRobotComment(changeId, withFixRobotCommentInput);
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(2);
assertThat(fixPreview).containsKey(FILE_NAME);
assertThat(fixPreview).containsKey(FILE_NAME2);
DiffInfo diff = fixPreview.get(FILE_NAME);
assertThat(diff).intralineStatus().isEqualTo(IntraLineStatus.OK);
assertThat(diff).webLinks().isNull();
assertThat(diff).binary().isNull();
assertThat(diff).diffHeader().isNull();
assertThat(diff).changeType().isEqualTo(ChangeType.MODIFIED);
assertThat(diff).metaA().totalLineCount().isEqualTo(11);
assertThat(diff).metaA().name().isEqualTo(FILE_NAME);
assertThat(diff).metaA().commitId().isEqualTo(commitId);
assertThat(diff).metaA().contentType().isEqualTo(PLAIN_TEXT_CONTENT_TYPE);
assertThat(diff).metaA().webLinks().isNull();
assertThat(diff).metaB().totalLineCount().isEqualTo(6);
assertThat(diff).metaB().name().isEqualTo(FILE_NAME);
assertThat(diff).metaB().commitId().isNull();
assertThat(diff).metaB().contentType().isEqualTo(PLAIN_TEXT_CONTENT_TYPE);
assertThat(diff).metaB().webLinks().isNull();
assertThat(diff).content().hasSize(3);
assertThat(diff).content().element(0).commonLines().containsExactly("First line", "Second line");
assertThat(diff).content().element(0).linesOfA().isNull();
assertThat(diff).content().element(0).linesOfB().isNull();
assertThat(diff).content().element(1).commonLines().isNull();
assertThat(diff).content().element(1).linesOfA().containsExactly("Third line", "Fourth line", "Fifth line", "Sixth line", "Seventh line", "Eighth line");
assertThat(diff).content().element(1).linesOfB().containsExactly("Third linsome replacement codeth line");
assertThat(diff).content().element(2).commonLines().containsExactly("Ninth line", "Tenth line", "");
assertThat(diff).content().element(2).linesOfA().isNull();
assertThat(diff).content().element(2).linesOfB().isNull();
DiffInfo diff2 = fixPreview.get(FILE_NAME2);
assertThat(diff2).intralineStatus().isEqualTo(IntraLineStatus.OK);
assertThat(diff2).webLinks().isNull();
assertThat(diff2).binary().isNull();
assertThat(diff2).diffHeader().isNull();
assertThat(diff2).changeType().isEqualTo(ChangeType.MODIFIED);
assertThat(diff2).metaA().totalLineCount().isEqualTo(4);
assertThat(diff2).metaA().name().isEqualTo(FILE_NAME2);
assertThat(diff2).metaA().commitId().isEqualTo(commitId);
assertThat(diff2).metaA().contentType().isEqualTo(PLAIN_TEXT_CONTENT_TYPE);
assertThat(diff2).metaA().webLinks().isNull();
assertThat(diff2).metaB().totalLineCount().isEqualTo(5);
assertThat(diff2).metaB().name().isEqualTo(FILE_NAME2);
assertThat(diff2).metaB().commitId().isNull();
assertThat(diff2).metaA().contentType().isEqualTo(PLAIN_TEXT_CONTENT_TYPE);
assertThat(diff2).metaB().webLinks().isNull();
assertThat(diff2).content().hasSize(3);
assertThat(diff2).content().element(0).commonLines().containsExactly("1st line");
assertThat(diff2).content().element(0).linesOfA().isNull();
assertThat(diff2).content().element(0).linesOfB().isNull();
assertThat(diff2).content().element(1).commonLines().isNull();
assertThat(diff2).content().element(1).linesOfA().isNull();
assertThat(diff2).content().element(1).linesOfB().containsExactly("New line");
assertThat(diff2).content().element(2).commonLines().containsExactly("2nd line", "3rd line", "");
assertThat(diff2).content().element(2).linesOfA().isNull();
assertThat(diff2).content().element(2).linesOfB().isNull();
}
use of com.google.gerrit.extensions.common.RobotCommentInfo in project gerrit by GerritCodeReview.
the class RobotCommentsIT method applyingFixReturnsEditInfoForCreatedChangeEdit.
@Test
public void applyingFixReturnsEditInfoForCreatedChangeEdit() 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();
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