Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/main/java/com/spotify/github/v3/checks/Annotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,24 @@ public interface Annotation {
*/
@Value.Check
@SuppressWarnings("checkstyle:magicnumber")
default void check() {
default Annotation check() {
// max values from https://docs.github.com/en/rest/checks/runs
Preconditions.checkState(title().map(String::length).orElse(0) <= 255,
"'title' exceeded max length of 255");
Preconditions.checkState(message().length() <= 64 * 1024,
"'message' exceeded max length of 64kB");
Preconditions.checkState(rawDetails().map(String::length).orElse(0) <= 64 * 1024,
"'rawDetails' exceeded max length of 64kB");

// Omit this (start_column, end_column) parameter if start_line and end_line have different values
// from https://docs.github.com/en/rest/checks/runs
if (startLine() != endLine() && (startColumn().isPresent() || endColumn().isPresent())) {
return ImmutableAnnotation.builder()
.from(this)
.startColumn(Optional.empty())
.endColumn(Optional.empty())
.build();
}
return this;
}
}
24 changes: 24 additions & 0 deletions src/test/java/com/spotify/github/v3/checks/AnnotationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.spotify.github.jackson.Json;
import com.spotify.github.v3.checks.ImmutableAnnotation.Builder;
import java.util.Optional;
import org.junit.Test;

public class AnnotationTest {
Expand All @@ -37,6 +40,8 @@ private Builder builder() {
.path("path")
.startLine(1)
.endLine(2)
.startColumn(1)
.endColumn(9)
.annotationLevel(AnnotationLevel.notice);
}

Expand Down Expand Up @@ -79,4 +84,23 @@ public void serializesWithEmptyFields() {
String expected = "{\"path\":\"\",\"annotation_level\":\"notice\",\"message\":\"\",\"title\":\"\",\"start_line\":1,\"end_line\":2}";
assertThat(serializedAnnotation, is(expected));
}

@Test
public void clearsColumnFieldsForMultiLineAnnotation() {
Annotation multiLineAnnotation = builder().startLine(1).endLine(2).build();
assertTrue(multiLineAnnotation.startColumn().isEmpty());
assertTrue(multiLineAnnotation.endColumn().isEmpty());

Annotation anotherMultiLineAnnotation = builder().startLine(1).endLine(2).startColumn(Optional.empty()).endColumn(1).build();
assertTrue(anotherMultiLineAnnotation.startColumn().isEmpty());
assertTrue(anotherMultiLineAnnotation.endColumn().isEmpty());

Annotation yetAnotherMultiLineAnnotation = builder().startLine(1).endLine(2).startColumn(1).endColumn(Optional.empty()).build();
assertTrue(yetAnotherMultiLineAnnotation.startColumn().isEmpty());
assertTrue(yetAnotherMultiLineAnnotation.endColumn().isEmpty());

Annotation singleLineAnnotation = builder().startLine(1).endLine(1).build();
assertEquals(1, singleLineAnnotation.startColumn().orElse(0));
assertEquals(9, singleLineAnnotation.endColumn().orElse(0));
}
}