From 318caf6123d57de79a671ea1bc32bb34775f1df9 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 8 Mar 2012 12:51:59 -0800 Subject: [PATCH 1/5] [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 7675cf7dee..75ff686300 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.18 + 1.19-SNAPSHOT GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java From aac30b923c8648005cfc592de40f68f743959926 Mon Sep 17 00:00:00 2001 From: Frederik Fix Date: Thu, 5 Apr 2012 16:21:24 +0200 Subject: [PATCH 2/5] implement listing of branches --- .../java/org/kohsuke/github/GHBranch.java | 50 +++++++++++++++++++ .../java/org/kohsuke/github/GHRepository.java | 8 +++ .../java/org/kohsuke/github/JsonBranch.java | 38 ++++++++++++++ .../java/org/kohsuke/github/JsonBranches.java | 42 ++++++++++++++++ src/test/java/org/kohsuke/AppTest.java | 9 ++++ 5 files changed, 147 insertions(+) create mode 100644 src/main/java/org/kohsuke/github/GHBranch.java create mode 100644 src/main/java/org/kohsuke/github/JsonBranch.java create mode 100644 src/main/java/org/kohsuke/github/JsonBranches.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..2a7099f592 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHBranch.java @@ -0,0 +1,50 @@ +package org.kohsuke.github; + +import java.util.Date; +import java.util.Locale; + +/** + * + * @author Yusuke Kokubo + * + */ +public class GHBranch { + GitHub root; + GHRepository owner; + + GHUser creator; + private String name; + private GHCommitPointer commit; + + public GitHub getRoot() { + return root; + } + + public GHRepository getOwner() { + return owner; + } + + public GHUser getCreator() { + return creator; + } + + public String getName() { + return name; + } + + public GHCommitPointer getCommit() { + return commit; + } + + @Override + public String toString() { + return "Branch:"+name+" in "+owner.getUrl(); + } + + + public 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..4c13775158 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -461,6 +461,14 @@ public boolean remove(Object url) { return this; } + /* get list of branches not merged into master */ + public List getBranches() throws IOException { + GHBranch[] r = root.retrieve3("/repos/"+owner.login+"/"+name+"/branches", GHBranch[].class); + for (GHBranch p : r) + p.wrap(this); + return new ArrayList(Arrays.asList(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..fb35718c3b --- /dev/null +++ b/src/main/java/org/kohsuke/github/JsonBranch.java @@ -0,0 +1,38 @@ +/* + * 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) { + branch.owner = r; + branch.root = r.root; + return branch; + } +} 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..80a4d73ed1 --- /dev/null +++ b/src/main/java/org/kohsuke/github/JsonBranches.java @@ -0,0 +1,42 @@ +/* + * 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.owner = owner; + branch.root = owner.root; + } + 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..5ca04e1c35 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; @@ -15,6 +16,7 @@ import java.io.IOException; import java.net.URL; import java.util.Set; +import java.util.List; /** * Unit test for simple App. @@ -55,6 +57,13 @@ public void testMemberOrgs() throws Exception { System.out.println(o); } + public void testBranches() throws Exception { + GitHub gitHub = GitHub.connect(); + List 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"); From 0b2fdc598b992a1235493641d88a215ad44e4fe5 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 6 Apr 2012 08:22:44 -0700 Subject: [PATCH 3/5] cleaning up --- .../java/org/kohsuke/github/GHBranch.java | 85 ++++++++++--------- .../java/org/kohsuke/github/JsonBranch.java | 4 +- .../java/org/kohsuke/github/JsonBranches.java | 6 +- 3 files changed, 46 insertions(+), 49 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHBranch.java b/src/main/java/org/kohsuke/github/GHBranch.java index 2a7099f592..1c68bfa758 100644 --- a/src/main/java/org/kohsuke/github/GHBranch.java +++ b/src/main/java/org/kohsuke/github/GHBranch.java @@ -1,50 +1,51 @@ package org.kohsuke.github; -import java.util.Date; -import java.util.Locale; - /** + * A branch in a repository. * * @author Yusuke Kokubo - * */ public class GHBranch { - GitHub root; - GHRepository owner; - - GHUser creator; - private String name; - private GHCommitPointer commit; - - public GitHub getRoot() { - return root; - } - - public GHRepository getOwner() { - return owner; - } - - public GHUser getCreator() { - return creator; - } - - public String getName() { - return name; - } - - public GHCommitPointer getCommit() { - return commit; - } - - @Override - public String toString() { - return "Branch:"+name+" in "+owner.getUrl(); - } - - - public GHBranch wrap(GHRepository repo) { - this.owner = repo; - this.root = repo.root; - return this; - } + 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/JsonBranch.java b/src/main/java/org/kohsuke/github/JsonBranch.java index fb35718c3b..dd4678ec72 100644 --- a/src/main/java/org/kohsuke/github/JsonBranch.java +++ b/src/main/java/org/kohsuke/github/JsonBranch.java @@ -31,8 +31,6 @@ class JsonBranch { GHBranch branch; GHBranch wrap(GHRepository r) { - branch.owner = r; - branch.root = r.root; - return branch; + return branch.wrap(r); } } diff --git a/src/main/java/org/kohsuke/github/JsonBranches.java b/src/main/java/org/kohsuke/github/JsonBranches.java index 80a4d73ed1..57a06bce37 100644 --- a/src/main/java/org/kohsuke/github/JsonBranches.java +++ b/src/main/java/org/kohsuke/github/JsonBranches.java @@ -33,10 +33,8 @@ class JsonBranches { List branches; public List wrap(GHRepository owner) { - for (GHBranch branch : branches) { - branch.owner = owner; - branch.root = owner.root; - } + for (GHBranch branch : branches) + branch.wrap(owner); return branches; } } \ No newline at end of file From 23069ac2fcc61e8468964ff38c4aed35c264deac Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 6 Apr 2012 08:24:41 -0700 Subject: [PATCH 4/5] Using map to enable lookup by name. --- src/main/java/org/kohsuke/github/GHRepository.java | 14 +++++++++----- src/test/java/org/kohsuke/AppTest.java | 3 ++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 4c13775158..7684bfed14 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -461,12 +461,16 @@ public boolean remove(Object url) { return this; } - /* get list of branches not merged into master */ - public List getBranches() throws IOException { - GHBranch[] r = root.retrieve3("/repos/"+owner.login+"/"+name+"/branches", GHBranch[].class); - for (GHBranch p : r) + /** + * 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); - return new ArrayList(Arrays.asList(r)); + r.put(p.getName(),p); + } + return r; } public Map getMilestones() throws IOException { diff --git a/src/test/java/org/kohsuke/AppTest.java b/src/test/java/org/kohsuke/AppTest.java index 5ca04e1c35..06fcedb22a 100644 --- a/src/test/java/org/kohsuke/AppTest.java +++ b/src/test/java/org/kohsuke/AppTest.java @@ -15,6 +15,7 @@ import java.io.IOException; import java.net.URL; +import java.util.Map; import java.util.Set; import java.util.List; @@ -59,7 +60,7 @@ public void testMemberOrgs() throws Exception { public void testBranches() throws Exception { GitHub gitHub = GitHub.connect(); - List b = + Map b = gitHub.getUser("jenkinsci").getRepository("jenkins").getBranches(); System.out.println(b); } From f6aea47c2cc57e2648ac82147d957a23c0873d43 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 6 Apr 2012 08:25:43 -0700 Subject: [PATCH 5/5] [maven-release-plugin] prepare release github-api-1.19 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 75ff686300..452fbaba7f 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.19-SNAPSHOT + 1.19 GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java