diff --git a/pom.xml b/pom.xml
index 7675cf7dee..452fbaba7f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
github-api
- 1.18
+ 1.19
GitHub API for Java
http://github-api.kohsuke.org/
GitHub API for Java
diff --git a/src/main/java/org/kohsuke/github/GHBranch.java b/src/main/java/org/kohsuke/github/GHBranch.java
new file mode 100644
index 0000000000..1c68bfa758
--- /dev/null
+++ b/src/main/java/org/kohsuke/github/GHBranch.java
@@ -0,0 +1,51 @@
+package org.kohsuke.github;
+
+/**
+ * A branch in a repository.
+ *
+ * @author Yusuke Kokubo
+ */
+public class GHBranch {
+ private GitHub root;
+ private GHRepository owner;
+
+ private String name;
+ private Commit commit;
+
+ public static class Commit {
+ String sha,url;
+ }
+
+ public GitHub getRoot() {
+ return root;
+ }
+
+ /**
+ * Repository that this branch is in.
+ */
+ public GHRepository getOwner() {
+ return owner;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * The commit that this branch currently points to.
+ */
+ public String getSHA1() {
+ return commit.sha;
+ }
+
+ @Override
+ public String toString() {
+ return "Branch:" + name + " in " + owner.getUrl();
+ }
+
+ /*package*/ GHBranch wrap(GHRepository repo) {
+ this.owner = repo;
+ this.root = repo.root;
+ return this;
+ }
+}
diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java
index 83eb21ad91..7684bfed14 100644
--- a/src/main/java/org/kohsuke/github/GHRepository.java
+++ b/src/main/java/org/kohsuke/github/GHRepository.java
@@ -461,6 +461,18 @@ public boolean remove(Object url) {
return this;
}
+ /**
+ * Gets branches by {@linkplain GHBranch#getName() their names}.
+ */
+ public Map getBranches() throws IOException {
+ Map r = new TreeMap();
+ for (GHBranch p : root.retrieve3("/repos/"+owner.login+"/"+name+"/branches", GHBranch[].class)) {
+ p.wrap(this);
+ r.put(p.getName(),p);
+ }
+ return r;
+ }
+
public Map getMilestones() throws IOException {
Map milestones = new TreeMap();
GHMilestone[] ms = root.retrieve3("/repos/"+owner.login+"/"+name+"/milestones", GHMilestone[].class);
diff --git a/src/main/java/org/kohsuke/github/JsonBranch.java b/src/main/java/org/kohsuke/github/JsonBranch.java
new file mode 100644
index 0000000000..dd4678ec72
--- /dev/null
+++ b/src/main/java/org/kohsuke/github/JsonBranch.java
@@ -0,0 +1,36 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011, Eric Maupin
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.kohsuke.github;
+
+/**
+ * @author Eric Maupin
+ */
+class JsonBranch {
+ GHBranch branch;
+
+ GHBranch wrap(GHRepository r) {
+ return branch.wrap(r);
+ }
+}
diff --git a/src/main/java/org/kohsuke/github/JsonBranches.java b/src/main/java/org/kohsuke/github/JsonBranches.java
new file mode 100644
index 0000000000..57a06bce37
--- /dev/null
+++ b/src/main/java/org/kohsuke/github/JsonBranches.java
@@ -0,0 +1,40 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011, Eric Maupin
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.kohsuke.github;
+
+import java.util.List;
+
+/**
+ * @author Eric Maupin
+ */
+class JsonBranches {
+ List branches;
+
+ public List wrap(GHRepository owner) {
+ for (GHBranch branch : branches)
+ branch.wrap(owner);
+ return branches;
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/org/kohsuke/AppTest.java b/src/test/java/org/kohsuke/AppTest.java
index a9af305266..06fcedb22a 100644
--- a/src/test/java/org/kohsuke/AppTest.java
+++ b/src/test/java/org/kohsuke/AppTest.java
@@ -5,6 +5,7 @@
import org.kohsuke.github.GHEventInfo;
import org.kohsuke.github.GHEventPayload;
import org.kohsuke.github.GHHook;
+import org.kohsuke.github.GHBranch;
import org.kohsuke.github.GHIssueState;
import org.kohsuke.github.GHOrganization;
import org.kohsuke.github.GHOrganization.Permission;
@@ -14,7 +15,9 @@
import java.io.IOException;
import java.net.URL;
+import java.util.Map;
import java.util.Set;
+import java.util.List;
/**
* Unit test for simple App.
@@ -55,6 +58,13 @@ public void testMemberOrgs() throws Exception {
System.out.println(o);
}
+ public void testBranches() throws Exception {
+ GitHub gitHub = GitHub.connect();
+ Map b =
+ gitHub.getUser("jenkinsci").getRepository("jenkins").getBranches();
+ System.out.println(b);
+ }
+
public void tryHook() throws Exception {
GitHub gitHub = GitHub.connect();
GHRepository r = gitHub.getMyself().getRepository("test2");