From cb3d413e5e9076d71e6766fa9d72c63cb9af9c7e Mon Sep 17 00:00:00 2001 From: Johno Crawford Date: Thu, 24 Jan 2013 17:23:07 +0100 Subject: [PATCH 1/7] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4eb2d73fae..dacf973b25 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.36 + 1.37-SNAPSHOT GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java From 8ba61bb3a6c687b3191e4f55fb3199d1499978d4 Mon Sep 17 00:00:00 2001 From: johnou Date: Thu, 24 Jan 2013 17:31:43 +0100 Subject: [PATCH 2/7] Revert 2ef5dec4660476467844ac12ae785a8944d5bc9d and add source encoding to deter build warnings. --- pom.xml | 4 ++++ src/test/java/org/kohsuke/AppTest.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index dacf973b25..10874c8092 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,10 @@ + + UTF-8 + + diff --git a/src/test/java/org/kohsuke/AppTest.java b/src/test/java/org/kohsuke/AppTest.java index ffcccbf1e7..efe3dc4ae1 100644 --- a/src/test/java/org/kohsuke/AppTest.java +++ b/src/test/java/org/kohsuke/AppTest.java @@ -188,7 +188,7 @@ public void testCommitComment() throws Exception { } public void testCreateCommitComment() throws Exception { - GHCommit commit = gitHub.getUser("johnou").getRepository("sandbox-ant").getCommit("8ae38db0ea5837313ab5f39d43a6f73de3bd9000"); + GHCommit commit = gitHub.getUser("kohsuke").getRepository("sandbox-ant").getCommit("8ae38db0ea5837313ab5f39d43a6f73de3bd9000"); GHCommitComment c = commit.createComment("[testing](http://kohsuse.org/)"); System.out.println(c); c.update("updated text"); From 5ccc3f4ccda4b2a65437294fd7aaba07ec7fd586 Mon Sep 17 00:00:00 2001 From: Michael Clarke Date: Fri, 15 Feb 2013 09:43:27 +0000 Subject: [PATCH 3/7] Adding in support for the compare command in the API --- .../java/org/kohsuke/github/GHCompare.java | 156 ++++++++++++++++++ .../java/org/kohsuke/github/GHRepository.java | 13 ++ 2 files changed, 169 insertions(+) create mode 100644 src/main/java/org/kohsuke/github/GHCompare.java 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/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 703ff2378f..334072f285 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -393,6 +393,19 @@ 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); + } + /** * Gets a commit object in this repository. */ From 349df60ce889840a398d7d1b9f0a2a22e747f82d Mon Sep 17 00:00:00 2001 From: Michael Clarke Date: Fri, 15 Feb 2013 23:55:04 +0000 Subject: [PATCH 4/7] Adding in support for the refs command and filters in the API --- src/main/java/org/kohsuke/github/GHRef.java | 43 +++++++++++++++++++ .../java/org/kohsuke/github/GHRepository.java | 19 ++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/main/java/org/kohsuke/github/GHRef.java 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 334072f285..101707ed46 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -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. 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. */ From c284f90a1a9c73f15d583ecf91ff67e4d48bd5bd Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 14 Mar 2013 18:56:37 -0700 Subject: [PATCH 5/7] adding some more type-safe overloads --- src/main/java/org/kohsuke/github/GHRepository.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 101707ed46..5302413c3a 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -406,6 +406,14 @@ public GHCompare getCompare(String id1, String id2) throws IOException { return compare.wrap(this); } + public GHCompare getCompare(GHCommit id1, GHCommit id2) throws IOException { + return getCompare(id1.getSHA1(),id2.getSHA1()); + } + + public GHCompare getCompare(GHBranch id1, GHBranch id2) throws IOException { + return getCompare(id1.getName(),id2.getName()); + } + /** * Retrieves all refs for the github repository. * @return an array of GHRef elements coresponding with the refs in the remote repository. From d5f5fa0e0a0b34eaef8d81033a48cecb1c1d0251 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 14 Mar 2013 19:02:05 -0700 Subject: [PATCH 6/7] doc improvement --- src/main/java/org/kohsuke/github/GHRef.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/org/kohsuke/github/GHRef.java b/src/main/java/org/kohsuke/github/GHRef.java index 6efbb749a0..9d19c7e57c 100644 --- a/src/main/java/org/kohsuke/github/GHRef.java +++ b/src/main/java/org/kohsuke/github/GHRef.java @@ -12,14 +12,23 @@ public class GHRef { private String ref, url; private GHObject object; + /** + * Name of the ref, such as "refs/tags/abc" + */ public String getRef() { return ref; } + /** + * The API URL of this tag, such as https://api.github.com/repos/jenkinsci/jenkins/git/refs/tags/1.312 + */ public URL getUrl() { return GitHub.parseURL(url); } + /** + * The object that this ref points to. + */ public GHObject getObject() { return object; } @@ -28,14 +37,23 @@ public GHObject getObject() { public static class GHObject { private String type, sha, url; + /** + * Type of the object, such as "commit" + */ public String getType() { return type; } + /** + * SHA1 of this object. + */ public String getSha() { return sha; } + /** + * API URL to this Git data, such as https://api.github.com/repos/jenkinsci/jenkins/git/commits/b72322675eb0114363a9a86e9ad5a170d1d07ac0 + */ public URL getUrl() { return GitHub.parseURL(url); } From e8b8971b7291fe20133030016e4484d02641d854 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 14 Mar 2013 19:06:05 -0700 Subject: [PATCH 7/7] [maven-release-plugin] prepare release github-api-1.37 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 10874c8092..ebc3110a3a 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.37-SNAPSHOT + 1.37 GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java