From ca0a2befe4a9ba158287b6bd29276dc1af6f7f9d Mon Sep 17 00:00:00 2001 From: "mehmet.afacan" Date: Tue, 5 Dec 2023 14:16:24 +0300 Subject: [PATCH] issue1587: withName method created in GHCheckRunBuilder and its test has been written. --- .../org/kohsuke/github/GHCheckRunBuilder.java | 15 ++++++++++ .../kohsuke/github/GHCheckRunBuilderTest.java | 28 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java b/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java index 13e09cdd5e..6ff21c8553 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java @@ -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. * diff --git a/src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java b/src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java index 9f8f11571e..019a49b785 100644 --- a/src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java +++ b/src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java @@ -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)); + } }