mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-13 08:21:20 +00:00
Compare commits
18 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e88a0c91b | ||
|
|
d070f9deb0 | ||
|
|
b736e20a74 | ||
|
|
aad20d0a03 | ||
|
|
7ff97348d9 | ||
|
|
68dda3a46d | ||
|
|
2cd44f8c33 | ||
|
|
9775954aff | ||
|
|
1a071b0b54 | ||
|
|
8dcea59c74 | ||
|
|
f482f77871 | ||
|
|
b058c39ee1 | ||
|
|
b926b6c67f | ||
|
|
3fb8e5f799 | ||
|
|
9ebc9c0867 | ||
|
|
f1f96713a4 | ||
|
|
fc3b6d2c2e | ||
|
|
d0d0716b3b |
4
pom.xml
4
pom.xml
@@ -7,7 +7,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<version>1.66</version>
|
<version>1.67</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>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
|
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
|
||||||
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
|
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
|
||||||
<url>http://${project.artifactId}.kohsuke.org/</url>
|
<url>http://${project.artifactId}.kohsuke.org/</url>
|
||||||
<tag>github-api-1.66</tag>
|
<tag>github-api-1.67</tag>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asset in a release.
|
* Asset in a release.
|
||||||
@@ -60,6 +61,14 @@ public class GHAsset extends GHObject {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated This object has no HTML URL.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public URL getHtmlUrl() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public String getBrowserDownloadUrl() {
|
public String getBrowserDownloadUrl() {
|
||||||
return browser_download_url;
|
return browser_download_url;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,78 +10,83 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author janinko
|
* @author janinko
|
||||||
* @see GitHub#createToken(Collection, String, String)
|
* @see GitHub#createToken(Collection, String, String)
|
||||||
* @see http://developer.github.com/v3/oauth/#create-a-new-authorization
|
* @see <a href="http://developer.github.com/v3/oauth/#create-a-new-authorization">API documentation</a>
|
||||||
*/
|
*/
|
||||||
public class GHAuthorization extends GHObject {
|
public class GHAuthorization extends GHObject {
|
||||||
public static final String USER = "user";
|
public static final String USER = "user";
|
||||||
public static final String USER_EMAIL = "user:email";
|
public static final String USER_EMAIL = "user:email";
|
||||||
public static final String USER_FOLLOW = "user:follow";
|
public static final String USER_FOLLOW = "user:follow";
|
||||||
public static final String PUBLIC_REPO = "public_repo";
|
public static final String PUBLIC_REPO = "public_repo";
|
||||||
public static final String REPO = "repo";
|
public static final String REPO = "repo";
|
||||||
public static final String REPO_STATUS = "repo:status";
|
public static final String REPO_STATUS = "repo:status";
|
||||||
public static final String DELETE_REPO = "delete_repo";
|
public static final String DELETE_REPO = "delete_repo";
|
||||||
public static final String NOTIFICATIONS = "notifications";
|
public static final String NOTIFICATIONS = "notifications";
|
||||||
public static final String GIST = "gist";
|
public static final String GIST = "gist";
|
||||||
public static final String READ_HOOK = "read:repo_hook";
|
public static final String READ_HOOK = "read:repo_hook";
|
||||||
public static final String WRITE_HOOK = "write:repo_hook";
|
public static final String WRITE_HOOK = "write:repo_hook";
|
||||||
public static final String AMIN_HOOK = "admin:repo_hook";
|
public static final String AMIN_HOOK = "admin:repo_hook";
|
||||||
public static final String READ_ORG = "read:org";
|
public static final String READ_ORG = "read:org";
|
||||||
public static final String WRITE_ORG = "write:org";
|
public static final String WRITE_ORG = "write:org";
|
||||||
public static final String ADMIN_ORG = "admin:org";
|
public static final String ADMIN_ORG = "admin:org";
|
||||||
public static final String READ_KEY = "read:public_key";
|
public static final String READ_KEY = "read:public_key";
|
||||||
public static final String WRITE_KEY = "write:public_key";
|
public static final String WRITE_KEY = "write:public_key";
|
||||||
public static final String ADMIN_KEY = "admin:public_key";
|
public static final String ADMIN_KEY = "admin:public_key";
|
||||||
|
|
||||||
private GitHub root;
|
private GitHub root;
|
||||||
private List<String> scopes;
|
private List<String> scopes;
|
||||||
private String token;
|
private String token;
|
||||||
private App app;
|
private App app;
|
||||||
private String note;
|
private String note;
|
||||||
private String note_url;
|
private String note_url;
|
||||||
|
|
||||||
public GitHub getRoot() {
|
public GitHub getRoot() {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getScopes() {
|
public List<String> getScopes() {
|
||||||
return scopes;
|
return scopes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getToken(){
|
public String getToken() {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public URL getAppUrl(){
|
public URL getAppUrl() {
|
||||||
return GitHub.parseURL(app.url);
|
return GitHub.parseURL(app.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAppName() {
|
public String getAppName() {
|
||||||
return app.name;
|
return app.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public URL getApiURL(){
|
public URL getApiURL() {
|
||||||
return GitHub.parseURL(url);
|
return GitHub.parseURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNote() {
|
/**
|
||||||
return note;
|
* @deprecated This object has no HTML URL.
|
||||||
}
|
*/
|
||||||
|
@Override
|
||||||
|
public URL getHtmlUrl() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public URL getNoteUrl(){
|
public String getNote() {
|
||||||
|
return note;
|
||||||
|
}
|
||||||
|
|
||||||
|
public URL getNoteUrl() {
|
||||||
return GitHub.parseURL(note_url);
|
return GitHub.parseURL(note_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ GHAuthorization wrap(GitHub root) {
|
/*package*/ GHAuthorization wrap(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static class App {
|
||||||
|
private String url;
|
||||||
|
private String name;
|
||||||
private static class App{
|
}
|
||||||
private String url;
|
|
||||||
private String name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,26 +32,26 @@ public class GHCommit {
|
|||||||
|
|
||||||
private int comment_count;
|
private int comment_count;
|
||||||
|
|
||||||
@WithBridgeMethods(value=GHAuthor.class,castRequired=true)
|
@WithBridgeMethods(value = GHAuthor.class, castRequired = true)
|
||||||
public GitUser getAuthor() {
|
public GitUser getAuthor() {
|
||||||
return author;
|
return author;
|
||||||
}
|
}
|
||||||
|
|
||||||
@WithBridgeMethods(value=GHAuthor.class,castRequired=true)
|
@WithBridgeMethods(value = GHAuthor.class, castRequired = true)
|
||||||
public GitUser getCommitter() {
|
public GitUser getCommitter() {
|
||||||
return committer;
|
return committer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commit message.
|
* Commit message.
|
||||||
*/
|
*/
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCommentCount() {
|
public int getCommentCount() {
|
||||||
return comment_count;
|
return comment_count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -153,14 +153,13 @@ public class GHCommit {
|
|||||||
Stats stats;
|
Stats stats;
|
||||||
List<Parent> parents;
|
List<Parent> parents;
|
||||||
User author,committer;
|
User author,committer;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ShortInfo getCommitShortInfo() {
|
public ShortInfo getCommitShortInfo() {
|
||||||
return commit;
|
return commit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The repository that contains the commit.
|
* The repository that contains the commit.
|
||||||
*/
|
*/
|
||||||
public GHRepository getOwner() {
|
public GHRepository getOwner() {
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a status of a commit.
|
* Represents a status of a commit.
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
* @see GHRepository#getCommitStatus(String)
|
* @see GHRepository#getLastCommitStatus(String)
|
||||||
* @see GHCommit#getStatus()
|
* @see GHCommit#getLastStatus()
|
||||||
*/
|
*/
|
||||||
public class GHCommitStatus extends GHObject {
|
public class GHCommitStatus extends GHObject {
|
||||||
String state;
|
String state;
|
||||||
@@ -49,7 +50,15 @@ public class GHCommitStatus extends GHObject {
|
|||||||
return creator;
|
return creator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getContext() {
|
public String getContext() {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated This object has no HTML URL.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public URL getHtmlUrl() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,10 +70,10 @@ public class GHCompare {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GHCommit.File[] getFiles() {
|
public GHCommit.File[] getFiles() {
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHCompare wrap(GHRepository owner) {
|
public GHCompare wrap(GHRepository owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
for (Commit commit : commits) {
|
for (Commit commit : commits) {
|
||||||
commit.wrapUp(owner);
|
commit.wrapUp(owner);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class GHDeployKey {
|
|||||||
protected String url, key, title;
|
protected String url, key, title;
|
||||||
protected boolean verified;
|
protected boolean verified;
|
||||||
protected int id;
|
protected int id;
|
||||||
private GHRepository owner;
|
private GHRepository owner;
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
@@ -31,10 +31,10 @@ public class GHDeployKey {
|
|||||||
return verified;
|
return verified;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHDeployKey wrap(GHRepository repo) {
|
public GHDeployKey wrap(GHRepository repo) {
|
||||||
this.owner = repo;
|
this.owner = repo;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this).append("title",title).append("id",id).append("key",key).toString();
|
return new ToStringBuilder(this).append("title",title).append("id",id).append("key",key).toString();
|
||||||
|
|||||||
@@ -50,4 +50,12 @@ public class GHDeployment extends GHObject {
|
|||||||
public String getSha(){
|
public String getSha(){
|
||||||
return sha;
|
return sha;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated This object has no HTML URL.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public URL getHtmlUrl() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,5 +32,11 @@ public class GHDeploymentStatus extends GHObject {
|
|||||||
return GHDeploymentState.valueOf(state.toUpperCase());
|
return GHDeploymentState.valueOf(state.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated This object has no HTML URL.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public URL getHtmlUrl() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,6 +165,7 @@ public abstract class GHEventPayload {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
void wrapUp(GitHub root) {
|
void wrapUp(GitHub root) {
|
||||||
|
super.wrapUp(root);
|
||||||
if (repository!=null)
|
if (repository!=null)
|
||||||
repository.wrap(root);
|
repository.wrap(root);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.kohsuke.github;
|
|||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -60,8 +61,8 @@ public class GHGist extends GHObject {
|
|||||||
return git_push_url;
|
return git_push_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHtmlUrl() {
|
public URL getHtmlUrl() {
|
||||||
return html_url;
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPublic() {
|
public boolean isPublic() {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -51,4 +52,12 @@ public class GHHook extends GHObject {
|
|||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
new Requester(repository.root).method("DELETE").to(String.format("/repos/%s/%s/hooks/%d", repository.getOwnerName(), repository.getName(), id));
|
new Requester(repository.root).method("DELETE").to(String.format("/repos/%s/%s/hooks/%d", repository.getOwnerName(), repository.getName(), id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated This object has no HTML URL.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public URL getHtmlUrl() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ import java.util.Locale;
|
|||||||
public class GHIssue extends GHObject {
|
public class GHIssue extends GHObject {
|
||||||
GitHub root;
|
GitHub root;
|
||||||
GHRepository owner;
|
GHRepository owner;
|
||||||
|
|
||||||
// API v3
|
// API v3
|
||||||
protected GHUser assignee;
|
protected GHUser assignee;
|
||||||
protected String state;
|
protected String state;
|
||||||
protected int number;
|
protected int number;
|
||||||
@@ -74,9 +74,9 @@ public class GHIssue extends GHObject {
|
|||||||
|
|
||||||
/*package*/ GHIssue wrap(GitHub root) {
|
/*package*/ GHIssue wrap(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
if(assignee != null) assignee.wrapUp(root);
|
if(assignee != null) assignee.wrapUp(root);
|
||||||
if(user != null) user.wrapUp(root);
|
if(user != null) user.wrapUp(root);
|
||||||
if(closed_by != null) closed_by.wrapUp(root);
|
if(closed_by != null) closed_by.wrapUp(root);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,9 +134,9 @@ public class GHIssue extends GHObject {
|
|||||||
return GitHub.parseDate(closed_at);
|
return GitHub.parseDate(closed_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
public URL getApiURL(){
|
public URL getApiURL(){
|
||||||
return GitHub.parseURL(url);
|
return GitHub.parseURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the issue by adding a comment.
|
* Updates the issue by adding a comment.
|
||||||
@@ -185,16 +185,16 @@ public class GHIssue extends GHObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains all the comments associated with this issue.
|
* Obtains all the comments associated with this issue.
|
||||||
*
|
*
|
||||||
* @see #listComments()
|
* @see #listComments()
|
||||||
|
*/
|
||||||
|
public List<GHIssueComment> getComments() throws IOException {
|
||||||
|
return listComments().asList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains all the comments associated with this issue.
|
||||||
*/
|
*/
|
||||||
public List<GHIssueComment> getComments() throws IOException {
|
|
||||||
return listComments().asList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Obtains all the comments associated with this issue.
|
|
||||||
*/
|
|
||||||
public PagedIterable<GHIssueComment> listComments() throws IOException {
|
public PagedIterable<GHIssueComment> listComments() throws IOException {
|
||||||
return new PagedIterable<GHIssueComment>() {
|
return new PagedIterable<GHIssueComment>() {
|
||||||
public PagedIterator<GHIssueComment> iterator() {
|
public PagedIterator<GHIssueComment> iterator() {
|
||||||
@@ -216,16 +216,16 @@ public class GHIssue extends GHObject {
|
|||||||
return "/repos/"+owner.getOwnerName()+"/"+owner.getName()+"/issues/"+number;
|
return "/repos/"+owner.getOwnerName()+"/"+owner.getName()+"/issues/"+number;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHUser getAssignee() {
|
public GHUser getAssignee() {
|
||||||
return assignee;
|
return assignee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User who submitted the issue.
|
* User who submitted the issue.
|
||||||
*/
|
*/
|
||||||
public GHUser getUser() {
|
public GHUser getUser() {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reports who has closed the issue.
|
* Reports who has closed the issue.
|
||||||
@@ -235,46 +235,46 @@ public class GHIssue extends GHObject {
|
|||||||
* even for an issue that's already closed. See
|
* even for an issue that's already closed. See
|
||||||
* https://github.com/kohsuke/github-api/issues/60.
|
* https://github.com/kohsuke/github-api/issues/60.
|
||||||
*/
|
*/
|
||||||
public GHUser getClosedBy() {
|
public GHUser getClosedBy() {
|
||||||
if(!"closed".equals(state)) return null;
|
if(!"closed".equals(state)) return null;
|
||||||
if(closed_by != null) return closed_by;
|
if(closed_by != null) return closed_by;
|
||||||
|
|
||||||
//TODO closed_by = owner.getIssue(number).getClosed_by();
|
//TODO closed_by = owner.getIssue(number).getClosed_by();
|
||||||
return closed_by;
|
return closed_by;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCommentsCount(){
|
public int getCommentsCount(){
|
||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns non-null if this issue is a shadow of a pull request.
|
* Returns non-null if this issue is a shadow of a pull request.
|
||||||
*/
|
*/
|
||||||
public PullRequest getPullRequest() {
|
public PullRequest getPullRequest() {
|
||||||
return pull_request;
|
return pull_request;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPullRequest() {
|
public boolean isPullRequest() {
|
||||||
return pull_request!=null;
|
return pull_request!=null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHMilestone getMilestone() {
|
public GHMilestone getMilestone() {
|
||||||
return milestone;
|
return milestone;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class PullRequest{
|
public static class PullRequest{
|
||||||
private String diff_url, patch_url, html_url;
|
private String diff_url, patch_url, html_url;
|
||||||
|
|
||||||
public URL getDiffUrl() {
|
public URL getDiffUrl() {
|
||||||
return GitHub.parseURL(diff_url);
|
return GitHub.parseURL(diff_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public URL getPatchUrl() {
|
public URL getPatchUrl() {
|
||||||
return GitHub.parseURL(patch_url);
|
return GitHub.parseURL(patch_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public URL getUrl() {
|
public URL getUrl() {
|
||||||
return GitHub.parseURL(html_url);
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,4 +71,12 @@ public class GHIssueComment extends GHObject {
|
|||||||
public GHUser getUser() throws IOException {
|
public GHUser getUser() throws IOException {
|
||||||
return owner.root.getUser(user.getLogin());
|
return owner.root.getUser(user.getLogin());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated This object has no HTML URL.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public URL getHtmlUrl() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@@ -11,52 +12,56 @@ import java.util.Locale;
|
|||||||
*/
|
*/
|
||||||
public class GHMilestone extends GHObject {
|
public class GHMilestone extends GHObject {
|
||||||
GitHub root;
|
GitHub root;
|
||||||
GHRepository owner;
|
GHRepository owner;
|
||||||
|
|
||||||
GHUser creator;
|
GHUser creator;
|
||||||
private String state, due_on, title, description;
|
private String state, due_on, title, description, html_url;
|
||||||
private int closed_issues, open_issues, number;
|
private int closed_issues, open_issues, number;
|
||||||
|
|
||||||
public GitHub getRoot() {
|
public GitHub getRoot() {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHRepository getOwner() {
|
public GHRepository getOwner() {
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHUser getCreator() {
|
public GHUser getCreator() {
|
||||||
return creator;
|
return creator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getDueOn() {
|
public Date getDueOn() {
|
||||||
if (due_on == null) return null;
|
if (due_on == null) return null;
|
||||||
return GitHub.parseDate(due_on);
|
return GitHub.parseDate(due_on);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getClosedIssues() {
|
public int getClosedIssues() {
|
||||||
return closed_issues;
|
return closed_issues;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOpenIssues() {
|
public int getOpenIssues() {
|
||||||
return open_issues;
|
return open_issues;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumber() {
|
public int getNumber() {
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHMilestoneState getState() {
|
public URL getHtmlUrl() {
|
||||||
return Enum.valueOf(GHMilestoneState.class, state.toUpperCase(Locale.ENGLISH));
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GHMilestoneState getState() {
|
||||||
|
return Enum.valueOf(GHMilestoneState.class, state.toUpperCase(Locale.ENGLISH));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes this issue.
|
* Closes this issue.
|
||||||
@@ -73,9 +78,9 @@ public class GHMilestone extends GHObject {
|
|||||||
return "/repos/"+owner.getOwnerName()+"/"+owner.getName()+"/milestones/"+number;
|
return "/repos/"+owner.getOwnerName()+"/"+owner.getName()+"/milestones/"+number;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHMilestone wrap(GHRepository repo) {
|
public GHMilestone wrap(GHRepository repo) {
|
||||||
this.owner = repo;
|
this.owner = repo;
|
||||||
this.root = repo.root;
|
this.root = repo.root;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ public abstract class GHObject {
|
|||||||
return GitHub.parseURL(url);
|
return GitHub.parseURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL of this object for humans, which renders some HTML.
|
||||||
|
*/
|
||||||
|
@WithBridgeMethods(value=String.class, adapterMethod="urlToString")
|
||||||
|
public abstract URL getHtmlUrl();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When was this resource last updated?
|
* When was this resource last updated?
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.kohsuke.github;
|
|||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -214,8 +215,9 @@ public abstract class GHPerson extends GHObject {
|
|||||||
return blog;
|
return blog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHtmlUrl() {
|
@Override
|
||||||
return html_url;
|
public URL getHtmlUrl() {
|
||||||
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -37,20 +37,20 @@ import java.util.Locale;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public class GHPullRequest extends GHIssue {
|
public class GHPullRequest extends GHIssue {
|
||||||
|
|
||||||
private String patch_url, diff_url, issue_url;
|
private String patch_url, diff_url, issue_url;
|
||||||
private GHCommitPointer base;
|
private GHCommitPointer base;
|
||||||
private String merged_at;
|
private String merged_at;
|
||||||
private GHCommitPointer head;
|
private GHCommitPointer head;
|
||||||
|
|
||||||
// details that are only available when obtained from ID
|
// details that are only available when obtained from ID
|
||||||
private GHUser merged_by;
|
private GHUser merged_by;
|
||||||
private int review_comments, additions;
|
private int review_comments, additions;
|
||||||
private boolean merged;
|
private boolean merged;
|
||||||
private Boolean mergeable;
|
private Boolean mergeable;
|
||||||
private int deletions;
|
private int deletions;
|
||||||
private String mergeable_state;
|
private String mergeable_state;
|
||||||
private int changed_files;
|
private int changed_files;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GitHub doesn't return some properties of {@link GHIssue} when requesting the GET on the 'pulls' API
|
* GitHub doesn't return some properties of {@link GHIssue} when requesting the GET on the 'pulls' API
|
||||||
@@ -60,15 +60,15 @@ public class GHPullRequest extends GHIssue {
|
|||||||
private transient boolean fetchedIssueDetails;
|
private transient boolean fetchedIssueDetails;
|
||||||
|
|
||||||
|
|
||||||
GHPullRequest wrapUp(GHRepository owner) {
|
GHPullRequest wrapUp(GHRepository owner) {
|
||||||
this.wrap(owner);
|
this.wrap(owner);
|
||||||
return wrapUp(owner.root);
|
return wrapUp(owner.root);
|
||||||
}
|
}
|
||||||
|
|
||||||
GHPullRequest wrapUp(GitHub root) {
|
GHPullRequest wrapUp(GitHub root) {
|
||||||
if (owner!=null) owner.wrap(root);
|
if (owner != null) owner.wrap(root);
|
||||||
if (base!=null) base.wrapUp(root);
|
if (base != null) base.wrapUp(root);
|
||||||
if (head!=null) head.wrapUp(root);
|
if (head != null) head.wrapUp(root);
|
||||||
if (merged_by != null) merged_by.wrapUp(root);
|
if (merged_by != null) merged_by.wrapUp(root);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -85,8 +85,8 @@ public class GHPullRequest extends GHIssue {
|
|||||||
public URL getPatchUrl() {
|
public URL getPatchUrl() {
|
||||||
return GitHub.parseURL(patch_url);
|
return GitHub.parseURL(patch_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The URL of the patch file.
|
* The URL of the patch file.
|
||||||
* like https://github.com/jenkinsci/jenkins/pull/100.patch
|
* like https://github.com/jenkinsci/jenkins/pull/100.patch
|
||||||
*/
|
*/
|
||||||
@@ -108,8 +108,8 @@ public class GHPullRequest extends GHIssue {
|
|||||||
public GHCommitPointer getHead() {
|
public GHCommitPointer getHead() {
|
||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Date getIssueUpdatedAt() throws IOException {
|
public Date getIssueUpdatedAt() throws IOException {
|
||||||
return super.getUpdatedAt();
|
return super.getUpdatedAt();
|
||||||
}
|
}
|
||||||
@@ -126,65 +126,65 @@ public class GHPullRequest extends GHIssue {
|
|||||||
return GitHub.parseDate(merged_at);
|
return GitHub.parseDate(merged_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<GHLabel> getLabels() throws IOException {
|
public Collection<GHLabel> getLabels() throws IOException {
|
||||||
fetchIssue();
|
fetchIssue();
|
||||||
return super.getLabels();
|
return super.getLabels();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GHUser getClosedBy() {
|
public GHUser getClosedBy() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PullRequest getPullRequest() {
|
public PullRequest getPullRequest() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// details that are only available via get with ID
|
// details that are only available via get with ID
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
public GHUser getMergedBy() throws IOException {
|
public GHUser getMergedBy() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return merged_by;
|
return merged_by;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getReviewComments() throws IOException {
|
public int getReviewComments() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return review_comments;
|
return review_comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAdditions() throws IOException {
|
public int getAdditions() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return additions;
|
return additions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMerged() throws IOException {
|
public boolean isMerged() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return merged;
|
return merged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getMergeable() throws IOException {
|
public Boolean getMergeable() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return mergeable;
|
return mergeable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDeletions() throws IOException {
|
public int getDeletions() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return deletions;
|
return deletions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMergeableState() throws IOException {
|
public String getMergeableState() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return mergeable_state;
|
return mergeable_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getChangedFiles() throws IOException {
|
public int getChangedFiles() throws IOException {
|
||||||
populate();
|
populate();
|
||||||
return changed_files;
|
return changed_files;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fully populate the data by retrieving missing data.
|
* Fully populate the data by retrieving missing data.
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.kohsuke.github;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -44,8 +45,8 @@ public class GHRelease extends GHObject {
|
|||||||
return draft;
|
return draft;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHtmlUrl() {
|
public URL getHtmlUrl() {
|
||||||
return html_url;
|
return GitHub.parseURL(html_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ public class GHRepository extends GHObject {
|
|||||||
|
|
||||||
private GHRepoPermission permissions;
|
private GHRepoPermission permissions;
|
||||||
|
|
||||||
|
private GHRepository source, parent;
|
||||||
|
|
||||||
public GHDeploymentBuilder createDeployment(String ref) {
|
public GHDeploymentBuilder createDeployment(String ref) {
|
||||||
return new GHDeploymentBuilder(this,ref);
|
return new GHDeploymentBuilder(this,ref);
|
||||||
}
|
}
|
||||||
@@ -159,6 +161,10 @@ public class GHRepository extends GHObject {
|
|||||||
return ssh_url;
|
return ssh_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public URL getHtmlUrl() {
|
||||||
|
return GitHub.parseURL(html_url);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Short repository name without the owner. For example 'jenkins' in case of http://github.com/jenkinsci/jenkins
|
* Short repository name without the owner. For example 'jenkins' in case of http://github.com/jenkinsci/jenkins
|
||||||
*/
|
*/
|
||||||
@@ -353,7 +359,7 @@ public class GHRepository extends GHObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the primary branch you'll configure in the "Admin > Options" config page.
|
* Returns the primary branch you'll configure in the "Admin > Options" config page.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* This field is null until the user explicitly configures the master branch.
|
* This field is null until the user explicitly configures the master branch.
|
||||||
@@ -642,48 +648,48 @@ public class GHRepository extends GHObject {
|
|||||||
return GHRef.wrap(root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refType), GHRef[].class),root);
|
return GHRef.wrap(root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refType), GHRef[].class),root);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Retrive a ref of the given type for the current GitHub repository.
|
* Retrive a ref of the given type for the current GitHub repository.
|
||||||
*
|
*
|
||||||
* @param refName
|
* @param refName
|
||||||
* eg: heads/branch
|
* eg: heads/branch
|
||||||
* @return refs matching the request type
|
* @return refs matching the request type
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* on failure communicating with GitHub, potentially due to an
|
* on failure communicating with GitHub, potentially due to an
|
||||||
* invalid ref type being requested
|
* invalid ref type being requested
|
||||||
*/
|
*/
|
||||||
public GHRef getRef(String refName) throws IOException {
|
public GHRef getRef(String refName) throws IOException {
|
||||||
return root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refName), GHRef.class).wrap(root);
|
return root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refName), GHRef.class).wrap(root);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Retrive a tree of the given type for the current GitHub repository.
|
* Retrive a tree of the given type for the current GitHub repository.
|
||||||
*
|
*
|
||||||
* @param sha - sha number or branch name ex: "master"
|
* @param sha - sha number or branch name ex: "master"
|
||||||
* @return refs matching the request type
|
* @return refs matching the request type
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* on failure communicating with GitHub, potentially due to an
|
* on failure communicating with GitHub, potentially due to an
|
||||||
* invalid tree type being requested
|
* invalid tree type being requested
|
||||||
*/
|
*/
|
||||||
public GHTree getTree(String sha) throws IOException {
|
public GHTree getTree(String sha) throws IOException {
|
||||||
String url = String.format("/repos/%s/%s/git/trees/%s", owner.login, name, sha);
|
String url = String.format("/repos/%s/%s/git/trees/%s", owner.login, name, sha);
|
||||||
return root.retrieve().to(url, GHTree.class).wrap(root);
|
return root.retrieve().to(url, GHTree.class).wrap(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the tree for the current GitHub repository, recursively as described in here:
|
* Retrieves the tree for the current GitHub repository, recursively as described in here:
|
||||||
* https://developer.github.com/v3/git/trees/#get-a-tree-recursively
|
* https://developer.github.com/v3/git/trees/#get-a-tree-recursively
|
||||||
*
|
*
|
||||||
* @param sha - sha number or branch name ex: "master"
|
* @param sha - sha number or branch name ex: "master"
|
||||||
* @param recursive use 1
|
* @param recursive use 1
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* on failure communicating with GitHub, potentially due to an
|
* on failure communicating with GitHub, potentially due to an
|
||||||
* invalid tree type being requested
|
* invalid tree type being requested
|
||||||
*/
|
*/
|
||||||
public GHTree getTreeRecursive(String sha, int recursive) throws IOException {
|
public GHTree getTreeRecursive(String sha, int recursive) throws IOException {
|
||||||
String url = String.format("/repos/%s/%s/git/trees/%s?recursive=%d", owner.login, name, sha, recursive);
|
String url = String.format("/repos/%s/%s/git/trees/%s?recursive=%d", owner.login, name, sha, recursive);
|
||||||
return root.retrieve().to(url, GHTree.class).wrap(root);
|
return root.retrieve().to(url, GHTree.class).wrap(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a commit object in this repository.
|
* Gets a commit object in this repository.
|
||||||
*/
|
*/
|
||||||
public GHCommit getCommit(String sha1) throws IOException {
|
public GHCommit getCommit(String sha1) throws IOException {
|
||||||
@@ -780,10 +786,10 @@ public class GHRepository extends GHObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see {@link #createCommitStatus(String, GHCommitState,String,String,String) createCommitStatus}
|
* @see #createCommitStatus(String, GHCommitState,String,String,String)
|
||||||
*/
|
*/
|
||||||
public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description) throws IOException {
|
public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description) throws IOException {
|
||||||
return createCommitStatus(sha1, state, targetUrl, description,null);
|
return createCommitStatus(sha1, state, targetUrl, description,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -989,10 +995,10 @@ public class GHRepository extends GHObject {
|
|||||||
*/
|
*/
|
||||||
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>();
|
||||||
for (GHMilestone m : listMilestones(GHIssueState.OPEN)) {
|
for (GHMilestone m : listMilestones(GHIssueState.OPEN)) {
|
||||||
milestones.put(m.getNumber(), m);
|
milestones.put(m.getNumber(), m);
|
||||||
}
|
}
|
||||||
return milestones;
|
return milestones;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1012,16 +1018,16 @@ public class GHRepository extends GHObject {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHMilestone getMilestone(int number) throws IOException {
|
public GHMilestone getMilestone(int number) throws IOException {
|
||||||
GHMilestone m = milestones.get(number);
|
GHMilestone m = milestones.get(number);
|
||||||
if (m == null) {
|
if (m == null) {
|
||||||
m = root.retrieve().to(getApiTailUrl("milestones/" + number), GHMilestone.class);
|
m = root.retrieve().to(getApiTailUrl("milestones/" + number), GHMilestone.class);
|
||||||
m.owner = this;
|
m.owner = this;
|
||||||
m.root = root;
|
m.root = root;
|
||||||
milestones.put(m.getNumber(), m);
|
milestones.put(m.getNumber(), m);
|
||||||
}
|
}
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHContent getFileContent(String path) throws IOException {
|
public GHContent getFileContent(String path) throws IOException {
|
||||||
return getFileContent(path, null);
|
return getFileContent(path, null);
|
||||||
@@ -1088,25 +1094,57 @@ public class GHRepository extends GHObject {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHMilestone createMilestone(String title, String description) throws IOException {
|
public GHMilestone createMilestone(String title, String description) throws IOException {
|
||||||
return new Requester(root)
|
return new Requester(root)
|
||||||
.with("title", title).with("description", description).method("POST").to(getApiTailUrl("milestones"), GHMilestone.class).wrap(this);
|
.with("title", title).with("description", description).method("POST").to(getApiTailUrl("milestones"), GHMilestone.class).wrap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHDeployKey addDeployKey(String title,String key) throws IOException {
|
public GHDeployKey addDeployKey(String title,String key) throws IOException {
|
||||||
return new Requester(root)
|
return new Requester(root)
|
||||||
.with("title", title).with("key", key).method("POST").to(getApiTailUrl("keys"), GHDeployKey.class).wrap(this);
|
.with("title", title).with("key", key).method("POST").to(getApiTailUrl("keys"), GHDeployKey.class).wrap(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GHDeployKey> getDeployKeys() throws IOException{
|
public List<GHDeployKey> getDeployKeys() throws IOException{
|
||||||
List<GHDeployKey> list = new ArrayList<GHDeployKey>(Arrays.asList(
|
List<GHDeployKey> list = new ArrayList<GHDeployKey>(Arrays.asList(
|
||||||
root.retrieve().to(getApiTailUrl("keys"), GHDeployKey[].class)));
|
root.retrieve().to(getApiTailUrl("keys"), GHDeployKey[].class)));
|
||||||
for (GHDeployKey h : list)
|
for (GHDeployKey h : list)
|
||||||
h.wrap(this);
|
h.wrap(this);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forked repositories have a 'source' attribute that specifies the ultimate source of the forking chain.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* {@link GHRepository} that points to the root repository where this repository is forked
|
||||||
|
* (indirectly or directly) from. Otherwise null.
|
||||||
|
* @see #getParent()
|
||||||
|
*/
|
||||||
|
public GHRepository getSource() throws IOException {
|
||||||
|
if (source == null) return null;
|
||||||
|
if (source.root == null)
|
||||||
|
source = root.getRepository(source.getFullName());
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forked repositories have a 'parent' attribute that specifies the repository this repository
|
||||||
|
* is directly forked from. If we keep traversing {@link #getParent()} until it returns null, that
|
||||||
|
* is {@link #getSource()}.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* {@link GHRepository} that points to the repository where this repository is forked
|
||||||
|
* directly from. Otherwise null.
|
||||||
|
* @see #getSource()
|
||||||
|
*/
|
||||||
|
public GHRepository getParent() throws IOException {
|
||||||
|
if (parent == null) return null;
|
||||||
|
if (parent.root == null)
|
||||||
|
parent = root.getRepository(parent.getFullName());
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscribes to this repository to get notifications.
|
* Subscribes to this repository to get notifications.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -47,10 +47,10 @@ public class GHTeam {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the current members.
|
* Retrieves the current members.
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHUser> listMembers() throws IOException {
|
public PagedIterable<GHUser> listMembers() throws IOException {
|
||||||
return new PagedIterable<GHUser>() {
|
return new PagedIterable<GHUser>() {
|
||||||
public PagedIterator<GHUser> iterator() {
|
public PagedIterator<GHUser> iterator() {
|
||||||
return new PagedIterator<GHUser>(org.root.retrieve().asIterator(api("/members"), GHUser[].class)) {
|
return new PagedIterator<GHUser>(org.root.retrieve().asIterator(api("/members"), GHUser[].class)) {
|
||||||
@@ -64,8 +64,8 @@ public class GHTeam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Set<GHUser> getMembers() throws IOException {
|
public Set<GHUser> getMembers() throws IOException {
|
||||||
return Collections.unmodifiableSet(listMembers().asSet());
|
return Collections.unmodifiableSet(listMembers().asSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if this team has the specified user as a member.
|
* Checks if this team has the specified user as a member.
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.kohsuke.github;
|
|||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,6 +38,14 @@ public class GHThread extends GHObject {
|
|||||||
return GitHub.parseDate(last_read_at);
|
return GitHub.parseDate(last_read_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated This object has no HTML URL.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public URL getHtmlUrl() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public String getReason() {
|
public String getReason() {
|
||||||
return reason;
|
return reason;
|
||||||
}
|
}
|
||||||
@@ -59,6 +68,41 @@ public class GHThread extends GHObject {
|
|||||||
return subject.type;
|
return subject.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this thread is about an issue, return that issue.
|
||||||
|
*
|
||||||
|
* @return null if this thread is not about an issue.
|
||||||
|
*/
|
||||||
|
public GHIssue getBoundIssue() throws IOException {
|
||||||
|
if (!"Issue".equals(subject.type) && "PullRequest".equals(subject.type))
|
||||||
|
return null;
|
||||||
|
return repository.getIssue(
|
||||||
|
Integer.parseInt(subject.url.substring(subject.url.lastIndexOf('/') + 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this thread is about a pull request, return that pull request.
|
||||||
|
*
|
||||||
|
* @return null if this thread is not about a pull request.
|
||||||
|
*/
|
||||||
|
public GHPullRequest getBoundPullRequest() throws IOException {
|
||||||
|
if (!"PullRequest".equals(subject.type))
|
||||||
|
return null;
|
||||||
|
return repository.getPullRequest(
|
||||||
|
Integer.parseInt(subject.url.substring(subject.url.lastIndexOf('/') + 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this thread is about a commit, return that commit.
|
||||||
|
*
|
||||||
|
* @return null if this thread is not about a commit.
|
||||||
|
*/
|
||||||
|
public GHCommit getBoundCommit() throws IOException {
|
||||||
|
if (!"Commit".equals(subject.type))
|
||||||
|
return null;
|
||||||
|
return repository.getCommit(subject.url.substring(subject.url.lastIndexOf('/') + 1));
|
||||||
|
}
|
||||||
|
|
||||||
/*package*/ GHThread wrap(GitHub root) {
|
/*package*/ GHThread wrap(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
if (this.repository!=null)
|
if (this.repository!=null)
|
||||||
|
|||||||
@@ -13,46 +13,46 @@ import java.util.List;
|
|||||||
* @see GHRepository#getTree(String)
|
* @see GHRepository#getTree(String)
|
||||||
*/
|
*/
|
||||||
public class GHTree {
|
public class GHTree {
|
||||||
/* package almost final */GitHub root;
|
/* package almost final */GitHub root;
|
||||||
|
|
||||||
private boolean truncated;
|
private boolean truncated;
|
||||||
private String sha, url;
|
private String sha, url;
|
||||||
private GHTreeEntry[] tree;
|
private GHTreeEntry[] tree;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SHA for this trees
|
* The SHA for this trees
|
||||||
*/
|
*/
|
||||||
public String getSha() {
|
public String getSha() {
|
||||||
return sha;
|
return sha;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an array of entries of the trees
|
* Return an array of entries of the trees
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public List<GHTreeEntry> getTree() {
|
public List<GHTreeEntry> getTree() {
|
||||||
return Collections.unmodifiableList(Arrays.asList(tree));
|
return Collections.unmodifiableList(Arrays.asList(tree));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the number of items in the tree array exceeded the GitHub maximum limit.
|
* Returns true if the number of items in the tree array exceeded the GitHub maximum limit.
|
||||||
* @return true true if the number of items in the tree array exceeded the GitHub maximum limit otherwise false.
|
* @return true true if the number of items in the tree array exceeded the GitHub maximum limit otherwise false.
|
||||||
*/
|
*/
|
||||||
public boolean isTruncated() {
|
public boolean isTruncated() {
|
||||||
return truncated;
|
return truncated;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The API URL of this tag, such as
|
* The API URL of this tag, such as
|
||||||
* "url": "https://api.github.com/repos/octocat/Hello-World/trees/fc6274d15fa3ae2ab983129fb037999f264ba9a7",
|
* "url": "https://api.github.com/repos/octocat/Hello-World/trees/fc6274d15fa3ae2ab983129fb037999f264ba9a7",
|
||||||
*/
|
*/
|
||||||
public URL getUrl() {
|
public URL getUrl() {
|
||||||
return GitHub.parseURL(url);
|
return GitHub.parseURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */GHTree wrap(GitHub root) {
|
/* package */GHTree wrap(GitHub root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
|||||||
* <p>
|
* <p>
|
||||||
* This library aims to be safe for use by multiple threads concurrently, although
|
* This library aims to be safe for use by multiple threads concurrently, although
|
||||||
* the library itself makes no attempt to control/serialize potentially conflicting
|
* the library itself makes no attempt to control/serialize potentially conflicting
|
||||||
* operations to GitHub, such as updating & deleting a repository at the same time.
|
* operations to GitHub, such as updating & deleting a repository at the same time.
|
||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
@@ -252,11 +252,11 @@ public class GitHub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link GHUser} that represents yourself.
|
* Gets the {@link GHUser} that represents yourself.
|
||||||
*/
|
*/
|
||||||
@WithBridgeMethods(GHUser.class)
|
@WithBridgeMethods(GHUser.class)
|
||||||
public GHMyself getMyself() throws IOException {
|
public GHMyself getMyself() throws IOException {
|
||||||
requireCredential();
|
requireCredential();
|
||||||
|
|
||||||
GHMyself u = retrieve().to("/user", GHMyself.class);
|
GHMyself u = retrieve().to("/user", GHMyself.class);
|
||||||
|
|
||||||
@@ -264,20 +264,20 @@ public class GitHub {
|
|||||||
users.put(u.getLogin(), u);
|
users.put(u.getLogin(), u);
|
||||||
|
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains the object that represents the named user.
|
* Obtains the object that represents the named user.
|
||||||
*/
|
*/
|
||||||
public GHUser getUser(String login) throws IOException {
|
public GHUser getUser(String login) throws IOException {
|
||||||
GHUser u = users.get(login);
|
GHUser u = users.get(login);
|
||||||
if (u == null) {
|
if (u == null) {
|
||||||
u = retrieve().to("/users/" + login, GHUser.class);
|
u = retrieve().to("/users/" + login, GHUser.class);
|
||||||
u.root = this;
|
u.root = this;
|
||||||
users.put(u.getLogin(), u);
|
users.put(u.getLogin(), u);
|
||||||
}
|
}
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -415,14 +415,14 @@ public class GitHub {
|
|||||||
*
|
*
|
||||||
* @see <a href="http://developer.github.com/v3/oauth/#create-a-new-authorization">Documentation</a>
|
* @see <a href="http://developer.github.com/v3/oauth/#create-a-new-authorization">Documentation</a>
|
||||||
*/
|
*/
|
||||||
public GHAuthorization createToken(Collection<String> scope, String note, String noteUrl) throws IOException{
|
public GHAuthorization createToken(Collection<String> scope, String note, String noteUrl) throws IOException{
|
||||||
Requester requester = new Requester(this)
|
Requester requester = new Requester(this)
|
||||||
.with("scopes", scope)
|
.with("scopes", scope)
|
||||||
.with("note", note)
|
.with("note", note)
|
||||||
.with("note_url", noteUrl);
|
.with("note_url", noteUrl);
|
||||||
|
|
||||||
return requester.method("POST").to("/authorizations", GHAuthorization.class).wrap(this);
|
return requester.method("POST").to("/authorizations", GHAuthorization.class).wrap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that the credential is valid.
|
* Ensures that the credential is valid.
|
||||||
|
|||||||
@@ -45,18 +45,18 @@ public class GitHubBuilder {
|
|||||||
* @throws IOException If there are no credentials defined in the ~/.github properties file or the process environment.
|
* @throws IOException If there are no credentials defined in the ~/.github properties file or the process environment.
|
||||||
*/
|
*/
|
||||||
public static GitHubBuilder fromCredentials() throws IOException {
|
public static GitHubBuilder fromCredentials() throws IOException {
|
||||||
Exception cause = null;
|
Exception cause = null;
|
||||||
GitHubBuilder builder;
|
GitHubBuilder builder;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
builder = fromPropertyFile();
|
builder = fromPropertyFile();
|
||||||
|
|
||||||
if (builder.user != null)
|
if (builder.user != null)
|
||||||
return builder;
|
return builder;
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
// fall through
|
// fall through
|
||||||
cause = e;
|
cause = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
builder = fromEnvironment();
|
builder = fromEnvironment();
|
||||||
|
|
||||||
@@ -77,8 +77,8 @@ public class GitHubBuilder {
|
|||||||
|
|
||||||
private static void loadIfSet(String envName, Properties p, String propName) {
|
private static void loadIfSet(String envName, Properties p, String propName) {
|
||||||
String v = System.getenv(envName);
|
String v = System.getenv(envName);
|
||||||
if (v != null)
|
if (v != null)
|
||||||
p.put(propName, v);
|
p.put(propName, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,12 +87,12 @@ public class GitHubBuilder {
|
|||||||
* different clients of this library will all recognize one consistent set of coordinates.
|
* different clients of this library will all recognize one consistent set of coordinates.
|
||||||
*/
|
*/
|
||||||
public static GitHubBuilder fromEnvironment(String loginVariableName, String passwordVariableName, String oauthVariableName, String endpointVariableName) throws IOException {
|
public static GitHubBuilder fromEnvironment(String loginVariableName, String passwordVariableName, String oauthVariableName, String endpointVariableName) throws IOException {
|
||||||
Properties env = new Properties();
|
Properties env = new Properties();
|
||||||
loadIfSet(loginVariableName,env,"login");
|
loadIfSet(loginVariableName,env,"login");
|
||||||
loadIfSet(passwordVariableName,env,"password");
|
loadIfSet(passwordVariableName,env,"password");
|
||||||
loadIfSet(oauthVariableName,env,"oauth");
|
loadIfSet(oauthVariableName,env,"oauth");
|
||||||
loadIfSet(endpointVariableName,env,"endpoint");
|
loadIfSet(endpointVariableName,env,"endpoint");
|
||||||
return fromProperties(env);
|
return fromProperties(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -116,7 +116,7 @@ public class GitHubBuilder {
|
|||||||
* login, password, oauth
|
* login, password, oauth
|
||||||
*/
|
*/
|
||||||
public static GitHubBuilder fromEnvironment() throws IOException {
|
public static GitHubBuilder fromEnvironment() throws IOException {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
for (Entry<String, String> e : System.getenv().entrySet()) {
|
for (Entry<String, String> e : System.getenv().entrySet()) {
|
||||||
String name = e.getKey().toLowerCase(Locale.ENGLISH);
|
String name = e.getKey().toLowerCase(Locale.ENGLISH);
|
||||||
if (name.startsWith("github_")) name=name.substring(7);
|
if (name.startsWith("github_")) name=name.substring(7);
|
||||||
|
|||||||
@@ -479,6 +479,9 @@ class Requester {
|
|||||||
* Handle API error by either throwing it or by returning normally to retry.
|
* Handle API error by either throwing it or by returning normally to retry.
|
||||||
*/
|
*/
|
||||||
/*package*/ void handleApiError(IOException e) throws IOException {
|
/*package*/ void handleApiError(IOException e) throws IOException {
|
||||||
|
if (uc.getResponseCode() == 401) // Unauthorized == bad creds
|
||||||
|
throw e;
|
||||||
|
|
||||||
if ("0".equals(uc.getHeaderField("X-RateLimit-Remaining"))) {
|
if ("0".equals(uc.getHeaderField("X-RateLimit-Remaining"))) {
|
||||||
root.rateLimitHandler.onError(e,uc);
|
root.rateLimitHandler.onError(e,uc);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ public abstract class AbstractGitHubApiTestBase extends Assert {
|
|||||||
if (f.exists()) {
|
if (f.exists()) {
|
||||||
// use the non-standard credential preferentially, so that developers of this library do not have
|
// use the non-standard credential preferentially, so that developers of this library do not have
|
||||||
// to clutter their event stream.
|
// to clutter their event stream.
|
||||||
gitHub = GitHubBuilder.fromPropertyFile(f.getPath()).build();
|
gitHub = GitHubBuilder.fromPropertyFile(f.getPath()).withRateLimitHandler(RateLimitHandler.FAIL).build();
|
||||||
} else {
|
} else {
|
||||||
gitHub = GitHub.connect();
|
gitHub = GitHubBuilder.fromCredentials().withRateLimitHandler(RateLimitHandler.FAIL).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -598,10 +598,10 @@ public class AppTest extends AbstractGitHubApiTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRef() throws IOException {
|
public void testRef() throws IOException {
|
||||||
GHRef masterRef = gitHub.getRepository("jenkinsci/jenkins").getRef("heads/master");
|
GHRef masterRef = gitHub.getRepository("jenkinsci/jenkins").getRef("heads/master");
|
||||||
assertEquals("https://api.github.com/repos/jenkinsci/jenkins/git/refs/heads/master", masterRef.getUrl().toString());
|
assertEquals("https://api.github.com/repos/jenkinsci/jenkins/git/refs/heads/master", masterRef.getUrl().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void directoryListing() throws IOException {
|
public void directoryListing() throws IOException {
|
||||||
@@ -618,8 +618,8 @@ public class AppTest extends AbstractGitHubApiTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddDeployKey() throws IOException {
|
public void testAddDeployKey() throws IOException {
|
||||||
GHRepository myRepository = Iterables.get(gitHub.getMyself().getRepositories().values(),0);
|
GHRepository myRepository = Iterables.get(gitHub.getMyself().getRepositories().values(),0);
|
||||||
final GHDeployKey newDeployKey = myRepository.addDeployKey("test", "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUt0RAycC5cS42JKh6SecfFZBR1RrF+2hYMctz4mk74/arBE+wFb7fnSHGzdGKX2h5CFOWODifRCJVhB7hlVxodxe+QkQQYAEL/x1WVCJnGgTGQGOrhOMj95V3UE5pQKhsKD608C+u5tSofcWXLToP1/wZ7U4/AHjqYi08OLsWToHCax55TZkvdt2jo0hbIoYU+XI9Q8Uv4ONDN1oabiOdgeKi8+crvHAuvNleiBhWVBzFh8KdfzaH5uNdw7ihhFjEd1vzqACsjCINCjdMfzl6jD9ExuWuE92nZJnucls2cEoNC6k2aPmrZDg9hA32FXVpyseY+bDUWFU6LO2LG6PB kohsuke@atlas");
|
final GHDeployKey newDeployKey = myRepository.addDeployKey("test", "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUt0RAycC5cS42JKh6SecfFZBR1RrF+2hYMctz4mk74/arBE+wFb7fnSHGzdGKX2h5CFOWODifRCJVhB7hlVxodxe+QkQQYAEL/x1WVCJnGgTGQGOrhOMj95V3UE5pQKhsKD608C+u5tSofcWXLToP1/wZ7U4/AHjqYi08OLsWToHCax55TZkvdt2jo0hbIoYU+XI9Q8Uv4ONDN1oabiOdgeKi8+crvHAuvNleiBhWVBzFh8KdfzaH5uNdw7ihhFjEd1vzqACsjCINCjdMfzl6jD9ExuWuE92nZJnucls2cEoNC6k2aPmrZDg9hA32FXVpyseY+bDUWFU6LO2LG6PB kohsuke@atlas");
|
||||||
try {
|
try {
|
||||||
assertNotNull(newDeployKey.getId());
|
assertNotNull(newDeployKey.getId());
|
||||||
|
|
||||||
@@ -636,11 +636,11 @@ public class AppTest extends AbstractGitHubApiTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCommitStatusContext() throws IOException {
|
public void testCommitStatusContext() throws IOException {
|
||||||
GHRepository myRepository = Iterables.get(gitHub.getMyself().getRepositories().values(), 0);
|
GHRepository myRepository = Iterables.get(gitHub.getMyself().getRepositories().values(), 0);
|
||||||
GHRef masterRef = myRepository.getRef("heads/master");
|
GHRef masterRef = myRepository.getRef("heads/master");
|
||||||
GHCommitStatus commitStatus = myRepository.createCommitStatus(masterRef.getObject().getSha(), GHCommitState.SUCCESS, "http://www.example.com", "test", "test/context");
|
GHCommitStatus commitStatus = myRepository.createCommitStatus(masterRef.getObject().getSha(), GHCommitState.SUCCESS, "http://www.example.com", "test", "test/context");
|
||||||
assertEquals("test/context", commitStatus.getContext());
|
assertEquals("test/context", commitStatus.getContext());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -671,28 +671,28 @@ public class AppTest extends AbstractGitHubApiTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTrees() throws IOException {
|
public void testTrees() throws IOException {
|
||||||
GHTree masterTree = gitHub.getRepository("kohsuke/github-api").getTree("master");
|
GHTree masterTree = gitHub.getRepository("kohsuke/github-api").getTree("master");
|
||||||
boolean foundReadme = false;
|
boolean foundReadme = false;
|
||||||
for(GHTreeEntry e : masterTree.getTree()){
|
for(GHTreeEntry e : masterTree.getTree()){
|
||||||
if("readme".equalsIgnoreCase(e.getPath().replaceAll(".md", ""))){
|
if("readme".equalsIgnoreCase(e.getPath().replaceAll("\\.md", ""))){
|
||||||
foundReadme = true;
|
foundReadme = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertTrue(foundReadme);
|
assertTrue(foundReadme);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTreesRecursive() throws IOException {
|
public void testTreesRecursive() throws IOException {
|
||||||
GHTree masterTree = gitHub.getRepository("kohsuke/github-api").getTreeRecursive("master", 1);
|
GHTree masterTree = gitHub.getRepository("kohsuke/github-api").getTreeRecursive("master", 1);
|
||||||
boolean foundThisFile = false;
|
boolean foundThisFile = false;
|
||||||
for(GHTreeEntry e : masterTree.getTree()){
|
for(GHTreeEntry e : masterTree.getTree()){
|
||||||
if(e.getPath().endsWith(AppTest.class.getSimpleName() + ".java")){
|
if(e.getPath().endsWith(AppTest.class.getSimpleName() + ".java")){
|
||||||
foundThisFile = true;
|
foundThisFile = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertTrue(foundThisFile);
|
assertTrue(foundThisFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -30,21 +30,21 @@ public class GitHubTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testGitHubBuilderFromEnvironment() throws IOException {
|
public void testGitHubBuilderFromEnvironment() throws IOException {
|
||||||
|
|
||||||
Map<String, String>props = new HashMap<String, String>();
|
Map<String, String>props = new HashMap<String, String>();
|
||||||
|
|
||||||
props.put("login", "bogus");
|
props.put("login", "bogus");
|
||||||
props.put("oauth", "bogus");
|
props.put("oauth", "bogus");
|
||||||
props.put("password", "bogus");
|
props.put("password", "bogus");
|
||||||
|
|
||||||
setupEnvironment(props);
|
setupEnvironment(props);
|
||||||
|
|
||||||
GitHubBuilder builder = GitHubBuilder.fromEnvironment();
|
GitHubBuilder builder = GitHubBuilder.fromEnvironment();
|
||||||
|
|
||||||
assertEquals("bogus", builder.user);
|
assertEquals("bogus", builder.user);
|
||||||
assertEquals("bogus", builder.oauthToken);
|
assertEquals("bogus", builder.oauthToken);
|
||||||
assertEquals("bogus", builder.password);
|
assertEquals("bogus", builder.password);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -55,59 +55,54 @@ public class GitHubTest extends TestCase {
|
|||||||
* Its used to wire in values for the github credentials to test that the GitHubBuilder works properly to resolve them.
|
* Its used to wire in values for the github credentials to test that the GitHubBuilder works properly to resolve them.
|
||||||
*/
|
*/
|
||||||
private void setupEnvironment(Map<String, String> newenv) {
|
private void setupEnvironment(Map<String, String> newenv) {
|
||||||
try
|
try {
|
||||||
{
|
Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
|
||||||
Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
|
Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
|
||||||
Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
|
theEnvironmentField.setAccessible(true);
|
||||||
theEnvironmentField.setAccessible(true);
|
Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null);
|
||||||
Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null);
|
env.putAll(newenv);
|
||||||
env.putAll(newenv);
|
Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment");
|
||||||
Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment");
|
theCaseInsensitiveEnvironmentField.setAccessible(true);
|
||||||
theCaseInsensitiveEnvironmentField.setAccessible(true);
|
Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
|
||||||
Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
|
cienv.putAll(newenv);
|
||||||
cienv.putAll(newenv);
|
} catch (NoSuchFieldException e) {
|
||||||
}
|
try {
|
||||||
catch (NoSuchFieldException e)
|
Class[] classes = Collections.class.getDeclaredClasses();
|
||||||
{
|
Map<String, String> env = System.getenv();
|
||||||
try {
|
for (Class cl : classes) {
|
||||||
Class[] classes = Collections.class.getDeclaredClasses();
|
if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
|
||||||
Map<String, String> env = System.getenv();
|
Field field = cl.getDeclaredField("m");
|
||||||
for(Class cl : classes) {
|
field.setAccessible(true);
|
||||||
if("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
|
Object obj = field.get(env);
|
||||||
Field field = cl.getDeclaredField("m");
|
Map<String, String> map = (Map<String, String>) obj;
|
||||||
field.setAccessible(true);
|
map.clear();
|
||||||
Object obj = field.get(env);
|
map.putAll(newenv);
|
||||||
Map<String, String> map = (Map<String, String>) obj;
|
}
|
||||||
map.clear();
|
}
|
||||||
map.putAll(newenv);
|
} catch (Exception e2) {
|
||||||
}
|
e2.printStackTrace();
|
||||||
}
|
}
|
||||||
} catch (Exception e2) {
|
} catch (Exception e1) {
|
||||||
e2.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
} catch (Exception e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGitHubBuilderFromCustomEnvironment() throws IOException {
|
|
||||||
|
|
||||||
Map<String, String>props = new HashMap<String, String>();
|
|
||||||
|
|
||||||
props.put("customLogin", "bogusLogin");
|
|
||||||
props.put("customOauth", "bogusOauth");
|
|
||||||
props.put("customPassword", "bogusPassword");
|
|
||||||
props.put("customEndpoint", "bogusEndpoint");
|
|
||||||
|
|
||||||
setupEnvironment(props);
|
|
||||||
|
|
||||||
GitHubBuilder builder = GitHubBuilder.fromEnvironment("customLogin", "customPassword", "customOauth", "customEndpoint");
|
|
||||||
|
|
||||||
assertEquals("bogusLogin", builder.user);
|
|
||||||
assertEquals("bogusOauth", builder.oauthToken);
|
|
||||||
assertEquals("bogusPassword", builder.password);
|
|
||||||
assertEquals("bogusEndpoint", builder.endpoint);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testGitHubBuilderFromCustomEnvironment() throws IOException {
|
||||||
|
Map<String, String> props = new HashMap<String, String>();
|
||||||
|
|
||||||
|
props.put("customLogin", "bogusLogin");
|
||||||
|
props.put("customOauth", "bogusOauth");
|
||||||
|
props.put("customPassword", "bogusPassword");
|
||||||
|
props.put("customEndpoint", "bogusEndpoint");
|
||||||
|
|
||||||
|
setupEnvironment(props);
|
||||||
|
|
||||||
|
GitHubBuilder builder = GitHubBuilder.fromEnvironment("customLogin", "customPassword", "customOauth", "customEndpoint");
|
||||||
|
|
||||||
|
assertEquals("bogusLogin", builder.user);
|
||||||
|
assertEquals("bogusOauth", builder.oauthToken);
|
||||||
|
assertEquals("bogusPassword", builder.password);
|
||||||
|
assertEquals("bogusEndpoint", builder.endpoint);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user