Skip to content

Commit

Permalink
Adding in support for the refs command and filters in the API
Browse files Browse the repository at this point in the history
  • Loading branch information
mc1arke committed Feb 15, 2013
1 parent 5ccc3f4 commit 349df60
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/main/java/org/kohsuke/github/GHRef.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.kohsuke.github;

import java.net.URL;

/**
* Provides information on a Git ref from GitHub.
*
* @author Michael Clarke
*/
public class GHRef {

private String ref, url;
private GHObject object;

public String getRef() {
return ref;
}

public URL getUrl() {
return GitHub.parseURL(url);
}

public GHObject getObject() {
return object;
}


public static class GHObject {
private String type, sha, url;

public String getType() {
return type;
}

public String getSha() {
return sha;
}

public URL getUrl() {
return GitHub.parseURL(url);
}
}
}
19 changes: 19 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,25 @@ public GHCompare getCompare(String id1, String id2) throws IOException {
return compare.wrap(this);
}

/**
* Retrieves all refs for the github repository.
* @return an array of GHRef elements coresponding with the refs in the remote repository.
* @throws IOException on failure communicating with GitHub
*/
public GHRef[] getRefs() throws IOException {
return root.retrieve().to(String.format("/repos/%s/%s/git/refs", owner.login, name), GHRef[].class);
}

/**
* Retrienved all refs of the given type for the current GitHub repository.
* @param refType the type of reg to search for e.g. <tt>tags</tt> or <tt>commits</tt>
* @return an array of all refs matching the request type
* @throws IOException on failure communicating with GitHub, potentially due to an invalid ref type being requested
*/
public GHRef[] getRefs(String refType) throws IOException {
return root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refType), GHRef[].class);
}

/**
* Gets a commit object in this repository.
*/
Expand Down

0 comments on commit 349df60

Please sign in to comment.