diff --git a/src/main/java/org/kohsuke/github/GHCheckRun.java b/src/main/java/org/kohsuke/github/GHCheckRun.java index ac45e636fd..72cd268652 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRun.java +++ b/src/main/java/org/kohsuke/github/GHCheckRun.java @@ -6,7 +6,7 @@ import java.net.URL; /** - * Represents a deployment + * Represents a check run. * * @see documentation */ @@ -20,6 +20,7 @@ public class GHCheckRun extends GHObject { private String status; private String conclusion; private String name; + private String headSha; private GHPullRequest[] pullRequests; GHCheckRun wrap(GHRepository owner) { @@ -52,6 +53,15 @@ public String getName() { return name; } + /** + * Gets the HEAD SHA. + * + * @return sha for the HEAD commit + */ + public String getHeadSha() { + return headSha; + } + GHPullRequest[] getPullRequests() throws IOException { if (pullRequests != null && pullRequests.length != 0) { for (GHPullRequest singlePull : pullRequests) { diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index 64c0567558..f3607eea39 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -1428,6 +1428,107 @@ void wrapUp(GitHub root) { organization.wrapUp(root); } } + } + + /** + * A git commit status was changed. + * + * @see authoritative source + */ + @SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "Constructed by JSON deserialization") + public static class Status extends GHEventPayload { + private String context; + private String description; + private GHCommitState state; + private GHCommit commit; + private GHRepository repository; + + /** + * Gets the status content. + * + * @return status content + */ + public String getContext() { + return context; + } + + /** + * Gets the status description. + * + * @return status description + */ + public String getDescription() { + return description; + } + + /** + * Gets the status state. + * + * @return status state + */ + public GHCommitState getState() { + return state; + } + /** + * Sets the status stage. + * + * @param state + * status state + */ + public void setState(GHCommitState state) { + this.state = state; + } + + /** + * Gets the commit associated with the status event. + * + * @return commit + */ + public GHCommit getCommit() { + return commit; + } + + /** + * Sets the commit associated with the status event. + * + * @param commit + * commit + */ + public void setCommit(GHCommit commit) { + this.commit = commit; + } + + /** + * Gets the repository associated with the status event. + * + * @return repository + */ + public GHRepository getRepository() { + return repository; + } + + /** + * Sets the repository associated with the status event. + * + * @param repository + * repository + */ + public void setRepository(GHRepository repository) { + this.repository = repository; + } + + @Override + void wrapUp(GitHub root) { + super.wrapUp(root); + if (state == null) { + throw new IllegalStateException( + "Expected status payload, but got something else. Maybe we've got another type of event?"); + } + if (repository != null) { + repository.wrap(root); + commit.wrapUp(repository); + } + } } } diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index a4360618fb..80e2774f5c 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -294,9 +294,16 @@ public void repository() throws Exception { assertThat(event.getSender().getLogin(), is("baxterthehacker")); } - // TODO implement support classes and write test - // @Test - // public void status() throws Exception {} + @Test + public void status() throws Exception { + GHEventPayload.Status event = GitHub.offline() + .parseEventPayload(payload.asReader(), GHEventPayload.Status.class); + assertThat(event.getContext(), is("default")); + assertThat(event.getDescription(), is("status description")); + assertThat(event.getState(), is(GHCommitState.SUCCESS)); + assertThat(event.getCommit().getSHA1(), is("9049f1265b7d61be4a8904a9a27120d2064dab3b")); + assertThat(event.getRepository().getOwner().getLogin(), is("baxterthehacker")); + } // TODO implement support classes and write test // @Test @@ -314,6 +321,7 @@ public void checkRunEvent() throws Exception { assertThat(event.getRepository().getName(), is("Hello-World")); assertThat(event.getAction(), is("created")); assertThat(event.getCheckRun().getName(), is("Octocoders-linter")); + assertThat(event.getCheckRun().getHeadSha(), is("ec26c3e57ca3a959ca5aad62de7213c562f8c821")); } } diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/status.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/status.json index a9c45c5c93..058a40624f 100644 --- a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/status.json +++ b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/status.json @@ -4,7 +4,7 @@ "name": "baxterthehacker/public-repo", "target_url": null, "context": "default", - "description": null, + "description": "status description", "state": "success", "commit": { "sha": "9049f1265b7d61be4a8904a9a27120d2064dab3b", @@ -201,4 +201,4 @@ "type": "User", "site_admin": false } -} \ No newline at end of file +}