mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 08:21:21 +00:00
implement listing of branches
This commit is contained in:
50
src/main/java/org/kohsuke/github/GHBranch.java
Normal file
50
src/main/java/org/kohsuke/github/GHBranch.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -461,6 +461,14 @@ public class GHRepository {
|
||||
return this;
|
||||
}
|
||||
|
||||
/* get list of branches not merged into master */
|
||||
public List<GHBranch> getBranches() throws IOException {
|
||||
GHBranch[] r = root.retrieve3("/repos/"+owner.login+"/"+name+"/branches", GHBranch[].class);
|
||||
for (GHBranch p : r)
|
||||
p.wrap(this);
|
||||
return new ArrayList<GHBranch>(Arrays.asList(r));
|
||||
}
|
||||
|
||||
public Map<Integer, GHMilestone> getMilestones() throws IOException {
|
||||
Map<Integer,GHMilestone> milestones = new TreeMap<Integer, GHMilestone>();
|
||||
GHMilestone[] ms = root.retrieve3("/repos/"+owner.login+"/"+name+"/milestones", GHMilestone[].class);
|
||||
|
||||
38
src/main/java/org/kohsuke/github/JsonBranch.java
Normal file
38
src/main/java/org/kohsuke/github/JsonBranch.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
42
src/main/java/org/kohsuke/github/JsonBranches.java
Normal file
42
src/main/java/org/kohsuke/github/JsonBranches.java
Normal file
@@ -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<GHBranch> branches;
|
||||
|
||||
public List<GHBranch> wrap(GHRepository owner) {
|
||||
for (GHBranch branch : branches) {
|
||||
branch.owner = owner;
|
||||
branch.root = owner.root;
|
||||
}
|
||||
return branches;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import org.kohsuke.github.GHEvent;
|
||||
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 org.kohsuke.github.GitHub;
|
||||
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 class AppTest extends TestCase {
|
||||
System.out.println(o);
|
||||
}
|
||||
|
||||
public void testBranches() throws Exception {
|
||||
GitHub gitHub = GitHub.connect();
|
||||
List<GHBranch> 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");
|
||||
|
||||
Reference in New Issue
Block a user