Skip to content

Commit

Permalink
issue1587: withName method created in GHCheckRunBuilder and its test …
Browse files Browse the repository at this point in the history
…has been written.
  • Loading branch information
mehmet.afacan committed Dec 5, 2023
1 parent b59937a commit ca0a2be
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/org/kohsuke/github/GHCheckRunBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ private GHCheckRunBuilder(GHRepository repo, Requester requester) {
.withUrlPath(repo.getApiTailUrl("check-runs/" + checkId)));
}

/**
* With name.
*
* @param name
* the name
* @return the GH check run builder
*/
public @NonNull GHCheckRunBuilder withName(@CheckForNull String name, String oldName) {
if(oldName == null){
throw new GHException("Can not update uncreated check run");
}
requester.with("name", name);
return this;
}

/**
* With details URL.
*
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,32 @@ public void updateCheckRun() throws Exception {
assertThat(checkRun.getOutput().getAnnotationsCount(), equalTo(1));
}

/**
* Update check run with name.
*
* @throws Exception
* the exception
*/
@Test
public void updateCheckRunWithName() throws Exception {
GHCheckRun checkRun = getInstallationGithub().getRepository("hub4j-test-org/test-checks")
.createCheckRun("foo", "89a9ae301e35e667756034fdc933b1fc94f63fc1")
.withStatus(GHCheckRun.Status.IN_PROGRESS)
.withStartedAt(new Date(999_999_000))
.add(new GHCheckRunBuilder.Output("Some Title", "what happened…")
.add(new GHCheckRunBuilder.Annotation("stuff.txt",
1,
GHCheckRun.AnnotationLevel.NOTICE,
"hello to you too").withTitle("Look here")))
.create();
GHCheckRun updated = checkRun.update()
.withStatus(GHCheckRun.Status.COMPLETED)
.withConclusion(GHCheckRun.Conclusion.SUCCESS)
.withCompletedAt(new Date(999_999_999))
.withName("bar", checkRun.getName())
.create();
assertThat(new Date(999_999_000), equalTo(updated.getStartedAt()));
assertThat("foo", equalTo(updated.getName()));
assertThat(checkRun.getOutput().getAnnotationsCount(), equalTo(1));
}
}

0 comments on commit ca0a2be

Please sign in to comment.