Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 134ece9

Browse filesBrowse files
committed
Merge pull request hub4j#95 from suryagaddipati/ghref
Add support for retriving a single ref
2 parents 3097378 + 3e4b06e commit 134ece9
Copy full SHA for 134ece9

File tree

Expand file treeCollapse file tree

2 files changed

+19
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-1
lines changed

‎src/main/java/org/kohsuke/github/GHRepository.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+13-1Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,19 @@ public GHRef[] getRefs() throws IOException {
561561
public GHRef[] getRefs(String refType) throws IOException {
562562
return root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refType), GHRef[].class);
563563
}
564-
564+
/**
565+
* Retrive a ref of the given type for the current GitHub repository.
566+
*
567+
* @param refName
568+
* eg: heads/branch
569+
* @return refs matching the request type
570+
* @throws IOException
571+
* on failure communicating with GitHub, potentially due to an
572+
* invalid ref type being requested
573+
*/
574+
public GHRef getRef(String refName) throws IOException {
575+
return root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refName), GHRef.class);
576+
}
565577
/**
566578
* Gets a commit object in this repository.
567579
*/

‎src/test/java/org/kohsuke/github/AppTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/AppTest.java
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,12 @@ public void testCreateRelease() throws Exception {
529529
}
530530
}
531531

532+
@Test
533+
public void testRef() throws IOException {
534+
GHRef masterRef = gitHub.getRepository("jenkinsci/jenkins").getRef("heads/master");
535+
assertEquals("https://api.github.com/repos/jenkinsci/jenkins/git/refs/heads/master", masterRef.getUrl().toString());
536+
}
537+
532538
@Test
533539
public void directoryListing() throws IOException {
534540
List<GHContent> children = gitHub.getRepository("jenkinsci/jenkins").getDirectoryContent("core");

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.