Skip to content

Commit

Permalink
Use sha instead of ref
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Mar 27, 2023
1 parent 6d8746a commit 1394a03
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/main/java/com/jcabi/github/RtChecks.java
Expand Up @@ -97,15 +97,21 @@ public Collection<? extends Check> all() throws IOException {
.path(coords.user())
.path(coords.repo())
.path("/commits")
.path(this.pull.head().ref())
.path(this.pull.head().sha())
.path("/check-runs")
.back()
.method(Request.GET).fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK);
final JsonObject object = rest.as(JsonResponse.class).json().readObject();
final JsonObject object = rest.as(JsonResponse.class)
.json()
.readObject();
return Optional.ofNullable(object.getJsonArray("check_runs"))
.map(obj -> obj.stream().map(RtChecks::check).collect(Collectors.toList()))
.map(
obj -> obj.stream()
.map(RtChecks::check)
.collect(Collectors.toList())
)
.orElseGet(Collections::emptyList);
}

Expand Down
22 changes: 18 additions & 4 deletions src/test/java/com/jcabi/github/RtChecksTest.java
Expand Up @@ -86,13 +86,18 @@ public void getsAllChecks() throws IOException {
}
}

/**
* Checks whether RtChecks can return empty checks if they are absent.
*
* @throws IOException If some I/O problem happens.
*/
@Test
public void returnsEmptyChecksIfTheyAreAbsent() throws IOException {
try (final MkContainer container = new MkGrizzlyContainer()
.next(
new MkAnswer.Simple(
HttpURLConnection.HTTP_OK,
RtChecksTest.jsonWithoutCheckRuns()
RtChecksTest.empty()
)
)
.start(this.resource.port())) {
Expand All @@ -106,6 +111,12 @@ public void returnsEmptyChecksIfTheyAreAbsent() throws IOException {
}
}

/**
* Checks whether RtChecks can throw an exception
* if response code is not 200.
*
* @throws IOException If some I/O problem happens.
*/
@Test
public void assertsOkResponse() throws IOException {
try (final MkContainer container = new MkGrizzlyContainer()
Expand Down Expand Up @@ -150,9 +161,12 @@ private static String jsonWithCheckRuns() {
.toString();
}

private static String jsonWithoutCheckRuns() {
/**
* Creates json response body without check runs.
* @return Json response body.
*/
private static String empty() {
return Json.createObjectBuilder()
.add("total_count", Json.createValue(1))
.build()
.toString();
}
Expand All @@ -175,7 +189,7 @@ private Repo repo() throws IOException {
Mockito.doReturn(pull).when(pulls).get(0);
Mockito.doReturn(repo).when(pull).repo();
Mockito.doReturn(ref).when(pull).head();
Mockito.doReturn("abcdef1").when(ref).ref();
Mockito.doReturn("abcdef1").when(ref).sha();
return repo;
}
}

0 comments on commit 1394a03

Please sign in to comment.