diff --git a/src/main/java/org/kohsuke/github/GHCompare.java b/src/main/java/org/kohsuke/github/GHCompare.java
new file mode 100644
index 0000000000..31d5a07bd5
--- /dev/null
+++ b/src/main/java/org/kohsuke/github/GHCompare.java
@@ -0,0 +1,156 @@
+package org.kohsuke.github;
+
+import java.net.URL;
+import java.util.Date;
+
+/**
+ * The model user for comparing 2 commits in the GitHub API.
+ *
+ * @author Michael Clarke
+ */
+public class GHCompare {
+
+ private String url, html_url, permalink_url, diff_url, patch_url;
+ public Status status;
+ private int ahead_by, behind_by, total_commits;
+ private Commit base_commit, merge_base_commit;
+ private Commit[] commits;
+ private GHCommit.File[] files;
+
+ private GHRepository owner;
+
+ public URL getUrl() {
+ return GitHub.parseURL(url);
+ }
+
+ public URL getHtmlUrl() {
+ return GitHub.parseURL(html_url);
+ }
+
+ public URL getPermalinkUrl() {
+ return GitHub.parseURL(permalink_url);
+ }
+
+ public URL getDiffUrl() {
+ return GitHub.parseURL(diff_url);
+ }
+
+ public URL getPatchUrl() {
+ return GitHub.parseURL(patch_url);
+ }
+
+ public Status getStatus() {
+ return status;
+ }
+
+ public int getAheadBy() {
+ return ahead_by;
+ }
+
+ public int getBehindBy() {
+ return behind_by;
+ }
+
+ public int getTotalCommits() {
+ return total_commits;
+ }
+
+ public Commit getBaseCommit() {
+ return base_commit;
+ }
+
+ public Commit getMergeBaseCommit() {
+ return merge_base_commit;
+ }
+
+ public Commit[] getCommits() {
+ return commits;
+ }
+
+
+ public GHCompare wrap(GHRepository owner) {
+ this.owner = owner;
+ for (Commit commit : commits) {
+ commit.wrapUp(owner);
+ }
+ merge_base_commit.wrapUp(owner);
+ base_commit.wrapUp(owner);
+ return this;
+ }
+
+ /**
+ * Compare commits had a child commit element with additional details we want to capture.
+ * This extenstion of GHCommit provides that.
+ */
+ public static class Commit extends GHCommit {
+
+ private InnerCommit commit;
+
+ public InnerCommit getCommit() {
+ return commit;
+ }
+ }
+
+
+ public static class InnerCommit {
+ private String url, sha, message;
+ private User author, committer;
+ private Tree tree;
+
+ public String getUrl() {
+ return url;
+ }
+
+ public String getSha() {
+ return sha;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public User getAuthor() {
+ return author;
+ }
+
+ public User getCommitter() {
+ return committer;
+ }
+
+ public Tree getTree() {
+ return tree;
+ }
+ }
+
+ public static class Tree {
+ private String url, sha;
+
+ public String getUrl() {
+ return url;
+ }
+
+ public String getSha() {
+ return sha;
+ }
+ }
+
+ public static class User {
+ private String name, email, date;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public Date getDate() {
+ return GitHub.parseDate(date);
+ }
+ }
+
+ public static enum Status {
+ behind, ahead, identical;
+ }
+}
diff --git a/src/main/java/org/kohsuke/github/GHRef.java b/src/main/java/org/kohsuke/github/GHRef.java
new file mode 100644
index 0000000000..6efbb749a0
--- /dev/null
+++ b/src/main/java/org/kohsuke/github/GHRef.java
@@ -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);
+ }
+ }
+}
diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java
index 703ff2378f..101707ed46 100644
--- a/src/main/java/org/kohsuke/github/GHRepository.java
+++ b/src/main/java/org/kohsuke/github/GHRepository.java
@@ -393,6 +393,38 @@ public GHHook getHook(int id) throws IOException {
return root.retrieve().to(String.format("/repos/%s/%s/hooks/%d", owner.login, name, id), GHHook.class).wrap(this);
}
+ /**
+ * Gets a comparison between 2 points in the repository. This would be similar
+ * to calling git log id1...id2 against a local repository.
+ * @param id1 an identifier for the first point to compare from, this can be a sha1 ID (for a commit, tag etc) or a direct tag name
+ * @param id2 an identifier for the second point to compare to. Can be the same as the first point.
+ * @return the comparison output
+ * @throws IOException on failure communicating with GitHub
+ */
+ public GHCompare getCompare(String id1, String id2) throws IOException {
+ GHCompare compare = root.retrieve().to(String.format("/repos/%s/%s/compare/%s...%s", owner.login, name, id1, id2), GHCompare.class);
+ 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. tags or commits
+ * @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.
*/