Skip to content

Commit

Permalink
Merge pull request #97 from suryagaddipati/add_context_to_commit_status
Browse files Browse the repository at this point in the history
Add support for adding context to commit status.
  • Loading branch information
kohsuke committed Jun 8, 2014
2 parents 7bf31ca + e3d6e08 commit d0b8e2e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/java/org/kohsuke/github/GHCommitStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class GHCommitStatus {
String target_url,description;
int id;
String url;
String context;
GHUser creator;

private GitHub root;
Expand Down Expand Up @@ -69,4 +70,8 @@ public String getUrl() {
public GHUser getCreator() {
return creator;
}

public String getContext() {
return context;
}
}
12 changes: 11 additions & 1 deletion src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -658,14 +658,24 @@ public GHCommitStatus getLastCommitStatus(String sha1) throws IOException {
* Optional parameter that points to the URL that has more details.
* @param description
* Optional short description.
* @param context
* Optinal commit status context.
*/
public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description) throws IOException {
public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description, String context) throws IOException {
return new Requester(root)
.with("state", state.name().toLowerCase(Locale.ENGLISH))
.with("target_url", targetUrl)
.with("description", description)
.with("context", context)
.to(String.format("/repos/%s/%s/statuses/%s",owner.login,this.name,sha1),GHCommitStatus.class).wrapUp(root);
}

/**
* @see {@link #createCommitStatus(String, GHCommitState,String,String,String) createCommitStatus}
*/
public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description) throws IOException {
return createCommitStatus(sha1, state, targetUrl, description,null);
}

/**
* Lists repository events.
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/org/kohsuke/github/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,15 @@ public boolean apply(GHDeployKey deployKey) {
});
newDeployKey.delete();
}

@Test
public void testCommitStatusContext() throws IOException {
GHRepository myRepository = Iterables.get(gitHub.getMyself().getRepositories().values(),0);
GHRef masterRef = myRepository.getRef("heads/master");
GHCommitStatus commitStatus = myRepository.createCommitStatus(masterRef.getObject().getSha(), GHCommitState.SUCCESS, "http://www.example.com", "test", "test/context");
assertEquals("test/context", commitStatus.getContext());

}

private void kohsuke() {
String login = getUser().getLogin();
Expand Down

0 comments on commit d0b8e2e

Please sign in to comment.