Skip to content

Commit ec75313

Browse files
Marquis WongMarquis Wong
authored andcommitted
Send comments as robotComments (#238)
Robot comments show up in the Findings tab, instead of in the comments. This makes it much easier to differentiate from them a reviewer's comments. The API requires a "runId" for the comment. I've chosen to just send a random UUID for now, but eventually we could wire in something like a build number or something.
1 parent ce4d75e commit ec75313

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/main/java/pl/touk/sputnik/connector/gerrit/ReviewInputBuilder.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import pl.touk.sputnik.review.ReviewFile;
1313

1414
import java.util.HashMap;
15-
import java.util.List;
15+
import java.util.UUID;
1616
import java.util.stream.Collectors;
1717

1818
@AllArgsConstructor
@@ -29,21 +29,24 @@ public ReviewInput toReviewInput(@NotNull Review review, @Nullable String tag) {
2929
if (StringUtils.isNotBlank(tag)) {
3030
reviewInput.tag = tag;
3131
}
32-
reviewInput.comments = review.getFiles().stream()
32+
reviewInput.robotComments = review.getFiles().stream()
3333
.collect(Collectors.toMap(ReviewFile::getReviewFilename, this::buildFileComments));
3434
return reviewInput;
3535
}
3636

3737
@NotNull
38-
private List<ReviewInput.CommentInput> buildFileComments(@NotNull ReviewFile reviewFile) {
38+
private List<ReviewInput.RobotCommentInput> buildFileComments(@NotNull ReviewFile reviewFile) {
3939
return reviewFile.getComments().stream()
4040
.map(this::buildCommentInput)
4141
.collect(Collectors.toList());
4242
}
4343

4444
@NotNull
45-
private ReviewInput.CommentInput buildCommentInput(Comment comment) {
46-
ReviewInput.CommentInput commentInput = new ReviewInput.CommentInput();
45+
private ReviewInput.RobotCommentInput buildCommentInput(Comment comment) {
46+
ReviewInput.RobotCommentInput commentInput = new ReviewInput.RobotCommentInput();
47+
48+
commentInput.robotId = "sputnik";
49+
commentInput.robotRunId = UUID.randomUUID().toString();
4750
commentInput.line = comment.getLine();
4851
commentInput.message = comment.getMessage();
4952
return commentInput;

src/test/java/pl/touk/sputnik/connector/gerrit/ReviewInputBuilderTest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package pl.touk.sputnik.connector.gerrit;
22

33
import com.google.gerrit.extensions.api.changes.ReviewInput;
4+
import com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput;
45
import org.junit.jupiter.api.Test;
56
import org.junit.jupiter.api.extension.ExtendWith;
67
import org.junit.jupiter.params.ParameterizedTest;
@@ -11,6 +12,8 @@
1112
import pl.touk.sputnik.configuration.ConfigurationBuilder;
1213
import pl.touk.sputnik.review.Review;
1314

15+
import java.util.List;
16+
1417
import static org.assertj.core.api.Assertions.assertThat;
1518

1619
@ExtendWith(MockitoExtension.class)
@@ -28,10 +31,15 @@ void shouldBuildReviewInput() {
2831
ReviewInput reviewInput = reviewInputBuilder.toReviewInput(review, TAG);
2932

3033
assertThat(reviewInput.message).isEqualTo("Total 8 violations found");
31-
assertThat(reviewInput.comments).hasSize(4);
34+
assertThat(reviewInput.comments).isNull();
35+
assertThat(reviewInput.robotComments).hasSize(4);
3236
assertThat(reviewInput.tag).isEqualTo(TAG);
33-
assertThat(reviewInput.comments.get("filename1")).hasSize(2);
34-
assertThat(reviewInput.comments.get("filename1").get(0).message).isEqualTo("test1");
37+
List<RobotCommentInput> file1comments = reviewInput.robotComments.get("filename1");
38+
assertThat(file1comments).hasSize(2);
39+
RobotCommentInput comment1 = file1comments.get(0);
40+
assertThat(comment1.message).isEqualTo("test1");
41+
assertThat(comment1.robotId).isEqualTo("sputnik");
42+
assertThat(comment1.robotRunId).isNotEmpty();
3543
assertThat(reviewInput.labels.get("Code-Review")).isEqualTo((short) 1);
3644
}
3745

0 commit comments

Comments
 (0)