mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-14 00:11:23 +00:00
Compare commits
10 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3dd738b0db | ||
|
|
6480dde247 | ||
|
|
555dab7403 | ||
|
|
13158a28e1 | ||
|
|
cbaca87bbc | ||
|
|
5166202f67 | ||
|
|
35d45ca47d | ||
|
|
b66ede98c7 | ||
|
|
1ba8f2ccbf | ||
|
|
82133c117a |
9
pom.xml
9
pom.xml
@@ -7,7 +7,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<version>1.33</version>
|
<version>1.34</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>
|
||||||
@@ -85,6 +85,13 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>repo.jenkins-ci.org</id>
|
||||||
|
<url>http://repo.jenkins-ci.org/public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
<reporting>
|
<reporting>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|||||||
@@ -66,19 +66,22 @@ public class GitHub {
|
|||||||
private final Map<String,GHOrganization> orgs = new HashMap<String, GHOrganization>();
|
private final Map<String,GHOrganization> orgs = new HashMap<String, GHOrganization>();
|
||||||
/*package*/ String oauthAccessToken;
|
/*package*/ String oauthAccessToken;
|
||||||
|
|
||||||
private final String githubServer;
|
private final String apiUrl;
|
||||||
|
|
||||||
private GitHub(String login, String apiToken, String password) {
|
private GitHub(String login, String apiToken, String password) {
|
||||||
this ("github.com", login, apiToken, password);
|
this ("https://api.github.com", login, apiToken, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param githubServer
|
* @param apiUrl
|
||||||
* The host name of the GitHub (or GitHub enterprise) server, such as "github.com".
|
* The URL of GitHub (or GitHub enterprise) API endpoint, such as "https://api.github.com" or
|
||||||
|
* "http://ghe.acme.com/api/v3". Note that GitHub Enterprise has <tt>/api/v3</tt> in the URL.
|
||||||
|
* For historical reasons, this parameter still accepts the bare domain name, but that's considered deprecated.
|
||||||
*/
|
*/
|
||||||
private GitHub(String githubServer, String login, String apiToken, String password) {
|
private GitHub(String apiUrl, String login, String apiToken, String password) {
|
||||||
this.githubServer = githubServer;
|
if (apiUrl.endsWith("/")) apiUrl = apiUrl.substring(0, apiUrl.length()-1); // normalize
|
||||||
|
this.apiUrl = apiUrl;
|
||||||
this.login = login;
|
this.login = login;
|
||||||
this.apiToken = apiToken;
|
this.apiToken = apiToken;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
@@ -91,9 +94,9 @@ public class GitHub {
|
|||||||
encodedAuthorization = null;
|
encodedAuthorization = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GitHub (String githubServer, String oauthAccessToken) throws IOException {
|
private GitHub (String apiUrl, String oauthAccessToken) throws IOException {
|
||||||
|
|
||||||
this.githubServer = githubServer;
|
this.apiUrl = apiUrl;
|
||||||
this.password = null;
|
this.password = null;
|
||||||
this.encodedAuthorization = null;
|
this.encodedAuthorization = null;
|
||||||
|
|
||||||
@@ -118,6 +121,21 @@ public class GitHub {
|
|||||||
return new GitHub(props.getProperty("login"),props.getProperty("token"),props.getProperty("password"));
|
return new GitHub(props.getProperty("login"),props.getProperty("token"),props.getProperty("password"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Version that connects to GitHub Enterprise.
|
||||||
|
*
|
||||||
|
* @param apiUrl
|
||||||
|
* The URL of GitHub (or GitHub enterprise) API endpoint, such as "https://api.github.com" or
|
||||||
|
* "http://ghe.acme.com/api/v3". Note that GitHub Enterprise has <tt>/api/v3</tt> in the URL.
|
||||||
|
* For historical reasons, this parameter still accepts the bare domain name, but that's considered deprecated.
|
||||||
|
*/
|
||||||
|
public static GitHub connectToEnterprise(String apiUrl, String login, String apiToken) {
|
||||||
|
// not exposing password because the login process still assumes https://github.com/
|
||||||
|
// if we are to fix this, fix that by getting rid of createWebClient() and replace the e-mail service hook
|
||||||
|
// with GitHub API.
|
||||||
|
return new GitHub(apiUrl,login,apiToken,null);
|
||||||
|
}
|
||||||
|
|
||||||
public static GitHub connect(String login, String apiToken){
|
public static GitHub connect(String login, String apiToken){
|
||||||
return new GitHub(login,apiToken,null);
|
return new GitHub(login,apiToken,null);
|
||||||
}
|
}
|
||||||
@@ -153,10 +171,15 @@ public class GitHub {
|
|||||||
tailApiUrl = tailApiUrl + (tailApiUrl.indexOf('?')>=0 ?'&':'?') + "access_token=" + oauthAccessToken;
|
tailApiUrl = tailApiUrl + (tailApiUrl.indexOf('?')>=0 ?'&':'?') + "access_token=" + oauthAccessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tailApiUrl.startsWith("/"))
|
if (tailApiUrl.startsWith("/")) {
|
||||||
return new URL("https://api."+githubServer+tailApiUrl);
|
if ("github.com".equals(apiUrl)) {// backward compatibility
|
||||||
else
|
return new URL("https://api.github.com" + tailApiUrl);
|
||||||
|
} else {
|
||||||
|
return new URL(apiUrl + tailApiUrl);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
return new URL(tailApiUrl);
|
return new URL(tailApiUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ Requester retrieve() {
|
/*package*/ Requester retrieve() {
|
||||||
@@ -227,7 +250,7 @@ public class GitHub {
|
|||||||
*/
|
*/
|
||||||
public GHRepository getRepository(String name) throws IOException {
|
public GHRepository getRepository(String name) throws IOException {
|
||||||
String[] tokens = name.split("/");
|
String[] tokens = name.split("/");
|
||||||
return getUser(tokens[0]).getRepository(tokens[1]);
|
return retrieve().to("/repos/" + tokens[0] + '/' + tokens[1], GHRepository.class).wrap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
24
src/test/java/org/kohsuke/github/GitHubTest.java
Normal file
24
src/test/java/org/kohsuke/github/GitHubTest.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for {@link GitHub}.
|
||||||
|
*/
|
||||||
|
public class GitHubTest extends TestCase {
|
||||||
|
|
||||||
|
public void testGitHubServerWithHttp() throws Exception {
|
||||||
|
GitHub hub = GitHub.connectToEnterprise("http://enterprise.kohsuke.org/api/v3", "kohsuke", "token");
|
||||||
|
assertEquals("http://enterprise.kohsuke.org/api/v3/test", hub.getApiURL("/test").toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGitHubServerWithHttps() throws Exception {
|
||||||
|
GitHub hub = GitHub.connectToEnterprise("https://enterprise.kohsuke.org/api/v3", "kohsuke", "token");
|
||||||
|
assertEquals("https://enterprise.kohsuke.org/api/v3/test", hub.getApiURL("/test").toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGitHubServerWithoutServer() throws Exception {
|
||||||
|
GitHub hub = GitHub.connect("kohsuke", "token", "password");
|
||||||
|
assertEquals("https://api.github.com/test", hub.getApiURL("/test").toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user