Skip to content

Commit

Permalink
Merge pull request #95 from suryagaddipati/ghref
Browse files Browse the repository at this point in the history
Add support for retriving a single ref
  • Loading branch information
kohsuke committed Jun 5, 2014
2 parents 3097378 + 3e4b06e commit 134ece9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,19 @@ public GHRef[] getRefs() throws IOException {
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);
}

/**
* Retrive a ref of the given type for the current GitHub repository.
*
* @param refName
* eg: heads/branch
* @return refs matching the request type
* @throws IOException
* on failure communicating with GitHub, potentially due to an
* invalid ref type being requested
*/
public GHRef getRef(String refName) throws IOException {
return root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refName), GHRef.class);
}
/**
* Gets a commit object in this repository.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/org/kohsuke/github/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,12 @@ public void testCreateRelease() throws Exception {
}
}

@Test
public void testRef() throws IOException {
GHRef masterRef = gitHub.getRepository("jenkinsci/jenkins").getRef("heads/master");
assertEquals("https://api.github.com/repos/jenkinsci/jenkins/git/refs/heads/master", masterRef.getUrl().toString());
}

@Test
public void directoryListing() throws IOException {
List<GHContent> children = gitHub.getRepository("jenkinsci/jenkins").getDirectoryContent("core");
Expand Down

0 comments on commit 134ece9

Please sign in to comment.