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
12 changes: 11 additions & 1 deletion src/main/java/org/kohsuke/github/GHCheckRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.net.URL;

/**
* Represents a deployment
* Represents a check run.
*
* @see <a href="https://developer.github.com/v3/checks/runs/">documentation</a>
*/
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
101 changes: 101 additions & 0 deletions src/main/java/org/kohsuke/github/GHEventPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,107 @@ void wrapUp(GitHub root) {
organization.wrapUp(root);
}
}
}

/**
* A git commit status was changed.
*
* @see <a href="https://developer.github.com/v3/activity/events/types/#statusevent">authoritative source</a>
*/
@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);
}
}
}
}
14 changes: 11 additions & 3 deletions src/test/java/org/kohsuke/github/GHEventPayloadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "baxterthehacker/public-repo",
"target_url": null,
"context": "default",
"description": null,
"description": "status description",
"state": "success",
"commit": {
"sha": "9049f1265b7d61be4a8904a9a27120d2064dab3b",
Expand Down Expand Up @@ -201,4 +201,4 @@
"type": "User",
"site_admin": false
}
}
}