mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-21 15:50:49 +00:00
Compare commits
5 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6aea47c2c | ||
|
|
23069ac2fc | ||
|
|
0b2fdc598b | ||
|
|
aac30b923c | ||
|
|
318caf6123 |
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<version>1.18</version>
|
<version>1.19</version>
|
||||||
<name>GitHub API for Java</name>
|
<name>GitHub API for Java</name>
|
||||||
<url>http://github-api.kohsuke.org/</url>
|
<url>http://github-api.kohsuke.org/</url>
|
||||||
<description>GitHub API for Java</description>
|
<description>GitHub API for Java</description>
|
||||||
|
|||||||
51
src/main/java/org/kohsuke/github/GHBranch.java
Normal file
51
src/main/java/org/kohsuke/github/GHBranch.java
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -461,6 +461,18 @@ public class GHRepository {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets branches by {@linkplain GHBranch#getName() their names}.
|
||||||
|
*/
|
||||||
|
public Map<String,GHBranch> getBranches() throws IOException {
|
||||||
|
Map<String,GHBranch> r = new TreeMap<String,GHBranch>();
|
||||||
|
for (GHBranch p : root.retrieve3("/repos/"+owner.login+"/"+name+"/branches", GHBranch[].class)) {
|
||||||
|
p.wrap(this);
|
||||||
|
r.put(p.getName(),p);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
public Map<Integer, GHMilestone> getMilestones() throws IOException {
|
public Map<Integer, GHMilestone> getMilestones() throws IOException {
|
||||||
Map<Integer,GHMilestone> milestones = new TreeMap<Integer, GHMilestone>();
|
Map<Integer,GHMilestone> milestones = new TreeMap<Integer, GHMilestone>();
|
||||||
GHMilestone[] ms = root.retrieve3("/repos/"+owner.login+"/"+name+"/milestones", GHMilestone[].class);
|
GHMilestone[] ms = root.retrieve3("/repos/"+owner.login+"/"+name+"/milestones", GHMilestone[].class);
|
||||||
|
|||||||
36
src/main/java/org/kohsuke/github/JsonBranch.java
Normal file
36
src/main/java/org/kohsuke/github/JsonBranch.java
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
40
src/main/java/org/kohsuke/github/JsonBranches.java
Normal file
40
src/main/java/org/kohsuke/github/JsonBranches.java
Normal file
@@ -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<GHBranch> branches;
|
||||||
|
|
||||||
|
public List<GHBranch> wrap(GHRepository owner) {
|
||||||
|
for (GHBranch branch : branches)
|
||||||
|
branch.wrap(owner);
|
||||||
|
return branches;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import org.kohsuke.github.GHEvent;
|
|||||||
import org.kohsuke.github.GHEventInfo;
|
import org.kohsuke.github.GHEventInfo;
|
||||||
import org.kohsuke.github.GHEventPayload;
|
import org.kohsuke.github.GHEventPayload;
|
||||||
import org.kohsuke.github.GHHook;
|
import org.kohsuke.github.GHHook;
|
||||||
|
import org.kohsuke.github.GHBranch;
|
||||||
import org.kohsuke.github.GHIssueState;
|
import org.kohsuke.github.GHIssueState;
|
||||||
import org.kohsuke.github.GHOrganization;
|
import org.kohsuke.github.GHOrganization;
|
||||||
import org.kohsuke.github.GHOrganization.Permission;
|
import org.kohsuke.github.GHOrganization.Permission;
|
||||||
@@ -14,7 +15,9 @@ import org.kohsuke.github.GitHub;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test for simple App.
|
* Unit test for simple App.
|
||||||
@@ -55,6 +58,13 @@ public class AppTest extends TestCase {
|
|||||||
System.out.println(o);
|
System.out.println(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBranches() throws Exception {
|
||||||
|
GitHub gitHub = GitHub.connect();
|
||||||
|
Map<String,GHBranch> b =
|
||||||
|
gitHub.getUser("jenkinsci").getRepository("jenkins").getBranches();
|
||||||
|
System.out.println(b);
|
||||||
|
}
|
||||||
|
|
||||||
public void tryHook() throws Exception {
|
public void tryHook() throws Exception {
|
||||||
GitHub gitHub = GitHub.connect();
|
GitHub gitHub = GitHub.connect();
|
||||||
GHRepository r = gitHub.getMyself().getRepository("test2");
|
GHRepository r = gitHub.getMyself().getRepository("test2");
|
||||||
|
|||||||
Reference in New Issue
Block a user