diff --git a/pom.xml b/pom.xml index c7ef908b17..b54c58bc47 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.66 + 1.67 GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java @@ -16,7 +16,7 @@ scm:git:git@github.com/kohsuke/${project.artifactId}.git scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git http://${project.artifactId}.kohsuke.org/ - github-api-1.66 + github-api-1.67 diff --git a/src/main/java/org/kohsuke/github/GHAsset.java b/src/main/java/org/kohsuke/github/GHAsset.java index fb79e758d6..9f0be15863 100644 --- a/src/main/java/org/kohsuke/github/GHAsset.java +++ b/src/main/java/org/kohsuke/github/GHAsset.java @@ -1,6 +1,7 @@ package org.kohsuke.github; import java.io.IOException; +import java.net.URL; /** * Asset in a release. @@ -60,6 +61,14 @@ public String getState() { return state; } + /** + * @deprecated This object has no HTML URL. + */ + @Override + public URL getHtmlUrl() { + return null; + } + public String getBrowserDownloadUrl() { return browser_download_url; } diff --git a/src/main/java/org/kohsuke/github/GHAuthorization.java b/src/main/java/org/kohsuke/github/GHAuthorization.java index b464b9cb68..f990cbefb3 100644 --- a/src/main/java/org/kohsuke/github/GHAuthorization.java +++ b/src/main/java/org/kohsuke/github/GHAuthorization.java @@ -10,78 +10,83 @@ * * @author janinko * @see GitHub#createToken(Collection, String, String) - * @see http://developer.github.com/v3/oauth/#create-a-new-authorization + * @see API documentation */ public class GHAuthorization extends GHObject { - public static final String USER = "user"; - public static final String USER_EMAIL = "user:email"; - public static final String USER_FOLLOW = "user:follow"; - public static final String PUBLIC_REPO = "public_repo"; - public static final String REPO = "repo"; - public static final String REPO_STATUS = "repo:status"; - public static final String DELETE_REPO = "delete_repo"; - public static final String NOTIFICATIONS = "notifications"; - public static final String GIST = "gist"; - public static final String READ_HOOK = "read:repo_hook"; - public static final String WRITE_HOOK = "write:repo_hook"; - public static final String AMIN_HOOK = "admin:repo_hook"; - public static final String READ_ORG = "read:org"; - public static final String WRITE_ORG = "write:org"; - public static final String ADMIN_ORG = "admin:org"; - public static final String READ_KEY = "read:public_key"; - public static final String WRITE_KEY = "write:public_key"; - public static final String ADMIN_KEY = "admin:public_key"; - - private GitHub root; - private List scopes; - private String token; - private App app; - private String note; - private String note_url; + public static final String USER = "user"; + public static final String USER_EMAIL = "user:email"; + public static final String USER_FOLLOW = "user:follow"; + public static final String PUBLIC_REPO = "public_repo"; + public static final String REPO = "repo"; + public static final String REPO_STATUS = "repo:status"; + public static final String DELETE_REPO = "delete_repo"; + public static final String NOTIFICATIONS = "notifications"; + public static final String GIST = "gist"; + public static final String READ_HOOK = "read:repo_hook"; + public static final String WRITE_HOOK = "write:repo_hook"; + public static final String AMIN_HOOK = "admin:repo_hook"; + public static final String READ_ORG = "read:org"; + public static final String WRITE_ORG = "write:org"; + public static final String ADMIN_ORG = "admin:org"; + public static final String READ_KEY = "read:public_key"; + public static final String WRITE_KEY = "write:public_key"; + public static final String ADMIN_KEY = "admin:public_key"; + + private GitHub root; + private List scopes; + private String token; + private App app; + private String note; + private String note_url; public GitHub getRoot() { return root; } - public List getScopes() { - return scopes; - } + public List getScopes() { + return scopes; + } - public String getToken(){ - return token; - } + public String getToken() { + return token; + } - public URL getAppUrl(){ + public URL getAppUrl() { return GitHub.parseURL(app.url); - } - - public String getAppName() { - return app.name; - } - - public URL getApiURL(){ - return GitHub.parseURL(url); - } + } - public String getNote() { - return note; - } + public String getAppName() { + return app.name; + } - public URL getNoteUrl(){ - return GitHub.parseURL(note_url); - } + public URL getApiURL() { + return GitHub.parseURL(url); + } - /*package*/ GHAuthorization wrap(GitHub root) { - this.root = root; - return this; - } + /** + * @deprecated This object has no HTML URL. + */ + @Override + public URL getHtmlUrl() { + return null; + } + public String getNote() { + return note; + } + public URL getNoteUrl() { + return GitHub.parseURL(note_url); + } + /*package*/ GHAuthorization wrap(GitHub root) { + this.root = root; + return this; + } - private static class App{ - private String url; - private String name; - } + private static class App { + private String url; + private String name; + } } diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index 75f084c8ea..fbb7c24fdd 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -32,26 +32,26 @@ public static class ShortInfo { private int comment_count; - @WithBridgeMethods(value=GHAuthor.class,castRequired=true) - public GitUser getAuthor() { - return author; - } + @WithBridgeMethods(value = GHAuthor.class, castRequired = true) + public GitUser getAuthor() { + return author; + } - @WithBridgeMethods(value=GHAuthor.class,castRequired=true) - public GitUser getCommitter() { - return committer; - } + @WithBridgeMethods(value = GHAuthor.class, castRequired = true) + public GitUser getCommitter() { + return committer; + } /** * Commit message. */ - public String getMessage() { - return message; - } + public String getMessage() { + return message; + } - public int getCommentCount() { - return comment_count; - } + public int getCommentCount() { + return comment_count; + } } /** @@ -153,14 +153,13 @@ static class User { Stats stats; List parents; User author,committer; - - + public ShortInfo getCommitShortInfo() { - return commit; - } + return commit; + } - /** + /** * The repository that contains the commit. */ public GHRepository getOwner() { diff --git a/src/main/java/org/kohsuke/github/GHCommitStatus.java b/src/main/java/org/kohsuke/github/GHCommitStatus.java index 98112ae2e7..c9241442bf 100644 --- a/src/main/java/org/kohsuke/github/GHCommitStatus.java +++ b/src/main/java/org/kohsuke/github/GHCommitStatus.java @@ -1,14 +1,15 @@ package org.kohsuke.github; import java.io.IOException; +import java.net.URL; import java.util.Date; /** * Represents a status of a commit. * * @author Kohsuke Kawaguchi - * @see GHRepository#getCommitStatus(String) - * @see GHCommit#getStatus() + * @see GHRepository#getLastCommitStatus(String) + * @see GHCommit#getLastStatus() */ public class GHCommitStatus extends GHObject { String state; @@ -49,7 +50,15 @@ public GHUser getCreator() { return creator; } - public String getContext() { - return context; - } + public String getContext() { + return context; + } + + /** + * @deprecated This object has no HTML URL. + */ + @Override + public URL getHtmlUrl() { + return null; + } } diff --git a/src/main/java/org/kohsuke/github/GHCompare.java b/src/main/java/org/kohsuke/github/GHCompare.java index 9ca63b6e3b..2c2bc5ba72 100644 --- a/src/main/java/org/kohsuke/github/GHCompare.java +++ b/src/main/java/org/kohsuke/github/GHCompare.java @@ -70,10 +70,10 @@ public Commit[] getCommits() { } public GHCommit.File[] getFiles() { - return files; - } + return files; + } - public GHCompare wrap(GHRepository owner) { + public GHCompare wrap(GHRepository owner) { this.owner = owner; for (Commit commit : commits) { commit.wrapUp(owner); diff --git a/src/main/java/org/kohsuke/github/GHDeployKey.java b/src/main/java/org/kohsuke/github/GHDeployKey.java index 6e4ed496a6..eb2c2c00fb 100644 --- a/src/main/java/org/kohsuke/github/GHDeployKey.java +++ b/src/main/java/org/kohsuke/github/GHDeployKey.java @@ -9,7 +9,7 @@ public class GHDeployKey { protected String url, key, title; protected boolean verified; protected int id; - private GHRepository owner; + private GHRepository owner; public int getId() { return id; @@ -31,10 +31,10 @@ public boolean isVerified() { return verified; } - public GHDeployKey wrap(GHRepository repo) { - this.owner = repo; - return this; - } + public GHDeployKey wrap(GHRepository repo) { + this.owner = repo; + return this; + } public String toString() { return new ToStringBuilder(this).append("title",title).append("id",id).append("key",key).toString(); diff --git a/src/main/java/org/kohsuke/github/GHDeployment.java b/src/main/java/org/kohsuke/github/GHDeployment.java index 58fff1a0d4..51a7843d0b 100644 --- a/src/main/java/org/kohsuke/github/GHDeployment.java +++ b/src/main/java/org/kohsuke/github/GHDeployment.java @@ -50,4 +50,12 @@ public String getRef() { public String getSha(){ return sha; } + + /** + * @deprecated This object has no HTML URL. + */ + @Override + public URL getHtmlUrl() { + return null; + } } diff --git a/src/main/java/org/kohsuke/github/GHDeploymentStatus.java b/src/main/java/org/kohsuke/github/GHDeploymentStatus.java index 78cf1b2ba2..c8679c1343 100644 --- a/src/main/java/org/kohsuke/github/GHDeploymentStatus.java +++ b/src/main/java/org/kohsuke/github/GHDeploymentStatus.java @@ -32,5 +32,11 @@ public GHDeploymentState getState() { return GHDeploymentState.valueOf(state.toUpperCase()); } - + /** + * @deprecated This object has no HTML URL. + */ + @Override + public URL getHtmlUrl() { + return null; + } } diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index 4e718a2dc6..cd248c80ec 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -165,6 +165,7 @@ public GHRepository getRepository() { @Override void wrapUp(GitHub root) { + super.wrapUp(root); if (repository!=null) repository.wrap(root); } diff --git a/src/main/java/org/kohsuke/github/GHGist.java b/src/main/java/org/kohsuke/github/GHGist.java index 801aef22d7..f608af3da6 100644 --- a/src/main/java/org/kohsuke/github/GHGist.java +++ b/src/main/java/org/kohsuke/github/GHGist.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.io.IOException; +import java.net.URL; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -60,8 +61,8 @@ public String getGitPushUrl() { return git_push_url; } - public String getHtmlUrl() { - return html_url; + public URL getHtmlUrl() { + return GitHub.parseURL(html_url); } public boolean isPublic() { diff --git a/src/main/java/org/kohsuke/github/GHHook.java b/src/main/java/org/kohsuke/github/GHHook.java index 7b9c523a05..ffe4837509 100644 --- a/src/main/java/org/kohsuke/github/GHHook.java +++ b/src/main/java/org/kohsuke/github/GHHook.java @@ -1,6 +1,7 @@ package org.kohsuke.github; import java.io.IOException; +import java.net.URL; import java.util.Collections; import java.util.EnumSet; import java.util.List; @@ -51,4 +52,12 @@ public Map getConfig() { public void delete() throws IOException { 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; + } } diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index 69ffc29a86..8c071a93f8 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -44,8 +44,8 @@ public class GHIssue extends GHObject { GitHub root; GHRepository owner; - - // API v3 + + // API v3 protected GHUser assignee; protected String state; protected int number; @@ -74,9 +74,9 @@ public static class Label extends GHLabel { /*package*/ GHIssue wrap(GitHub root) { this.root = root; - if(assignee != null) assignee.wrapUp(root); - if(user != null) user.wrapUp(root); - if(closed_by != null) closed_by.wrapUp(root); + if(assignee != null) assignee.wrapUp(root); + if(user != null) user.wrapUp(root); + if(closed_by != null) closed_by.wrapUp(root); return this; } @@ -134,9 +134,9 @@ public Date getClosedAt() { return GitHub.parseDate(closed_at); } - public URL getApiURL(){ + public URL getApiURL(){ return GitHub.parseURL(url); - } + } /** * Updates the issue by adding a comment. @@ -185,16 +185,16 @@ public void setLabels(String... labels) throws IOException { /** * Obtains all the comments associated with this issue. - * - * @see #listComments() + * + * @see #listComments() + */ + public List getComments() throws IOException { + return listComments().asList(); + } + + /** + * Obtains all the comments associated with this issue. */ - public List getComments() throws IOException { - return listComments().asList(); - } - - /** - * Obtains all the comments associated with this issue. - */ public PagedIterable listComments() throws IOException { return new PagedIterable() { public PagedIterator iterator() { @@ -216,16 +216,16 @@ protected String getIssuesApiRoute() { return "/repos/"+owner.getOwnerName()+"/"+owner.getName()+"/issues/"+number; } - public GHUser getAssignee() { - return assignee; - } - + public GHUser getAssignee() { + return assignee; + } + /** * User who submitted the issue. */ - public GHUser getUser() { + public GHUser getUser() { return user; - } + } /** * Reports who has closed the issue. @@ -235,46 +235,46 @@ public GHUser getUser() { * even for an issue that's already closed. See * https://github.com/kohsuke/github-api/issues/60. */ - public GHUser getClosedBy() { - if(!"closed".equals(state)) return null; - if(closed_by != null) return closed_by; - - //TODO closed_by = owner.getIssue(number).getClosed_by(); - return closed_by; - } - - public int getCommentsCount(){ - return comments; - } + public GHUser getClosedBy() { + if(!"closed".equals(state)) return null; + if(closed_by != null) return closed_by; + + //TODO closed_by = owner.getIssue(number).getClosed_by(); + return closed_by; + } + + public int getCommentsCount(){ + return comments; + } /** * Returns non-null if this issue is a shadow of a pull request. */ - public PullRequest getPullRequest() { - return pull_request; - } + public PullRequest getPullRequest() { + return pull_request; + } public boolean isPullRequest() { return pull_request!=null; } - public GHMilestone getMilestone() { - return milestone; - } - - public static class PullRequest{ - private String diff_url, patch_url, html_url; - - public URL getDiffUrl() { - return GitHub.parseURL(diff_url); - } - - public URL getPatchUrl() { - return GitHub.parseURL(patch_url); - } - - public URL getUrl() { - return GitHub.parseURL(html_url); - } - } + public GHMilestone getMilestone() { + return milestone; + } + + public static class PullRequest{ + private String diff_url, patch_url, html_url; + + public URL getDiffUrl() { + return GitHub.parseURL(diff_url); + } + + public URL getPatchUrl() { + return GitHub.parseURL(patch_url); + } + + public URL getUrl() { + return GitHub.parseURL(html_url); + } + } } diff --git a/src/main/java/org/kohsuke/github/GHIssueComment.java b/src/main/java/org/kohsuke/github/GHIssueComment.java index d9fb52e1df..732c508a2d 100644 --- a/src/main/java/org/kohsuke/github/GHIssueComment.java +++ b/src/main/java/org/kohsuke/github/GHIssueComment.java @@ -71,4 +71,12 @@ public String getUserName() { public GHUser getUser() throws IOException { return owner.root.getUser(user.getLogin()); } + + /** + * @deprecated This object has no HTML URL. + */ + @Override + public URL getHtmlUrl() { + return null; + } } diff --git a/src/main/java/org/kohsuke/github/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java index eae45fb5df..146c92abb3 100644 --- a/src/main/java/org/kohsuke/github/GHMilestone.java +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -1,6 +1,7 @@ package org.kohsuke.github; import java.io.IOException; +import java.net.URL; import java.util.Date; import java.util.Locale; @@ -11,52 +12,56 @@ */ public class GHMilestone extends GHObject { GitHub root; - GHRepository owner; + GHRepository owner; - GHUser creator; - private String state, due_on, title, description; - private int closed_issues, open_issues, number; + GHUser creator; + private String state, due_on, title, description, html_url; + private int closed_issues, open_issues, number; - public GitHub getRoot() { - return root; - } - - public GHRepository getOwner() { - return owner; - } - - public GHUser getCreator() { - return creator; - } - - public Date getDueOn() { - if (due_on == null) return null; - return GitHub.parseDate(due_on); - } - - public String getTitle() { - return title; - } - - public String getDescription() { - return description; - } - - public int getClosedIssues() { - return closed_issues; - } - - public int getOpenIssues() { - return open_issues; - } - - public int getNumber() { - return number; - } - - public GHMilestoneState getState() { - return Enum.valueOf(GHMilestoneState.class, state.toUpperCase(Locale.ENGLISH)); - } + public GitHub getRoot() { + return root; + } + + public GHRepository getOwner() { + return owner; + } + + public GHUser getCreator() { + return creator; + } + + public Date getDueOn() { + if (due_on == null) return null; + return GitHub.parseDate(due_on); + } + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; + } + + public int getClosedIssues() { + return closed_issues; + } + + public int getOpenIssues() { + return open_issues; + } + + public int getNumber() { + return number; + } + + public URL getHtmlUrl() { + return GitHub.parseURL(html_url); + } + + public GHMilestoneState getState() { + return Enum.valueOf(GHMilestoneState.class, state.toUpperCase(Locale.ENGLISH)); + } /** * Closes this issue. @@ -73,9 +78,9 @@ protected String getApiRoute() { return "/repos/"+owner.getOwnerName()+"/"+owner.getName()+"/milestones/"+number; } - public GHMilestone wrap(GHRepository repo) { - this.owner = repo; - this.root = repo.root; - return this; - } + public GHMilestone wrap(GHRepository repo) { + this.owner = repo; + this.root = repo.root; + return this; + } } diff --git a/src/main/java/org/kohsuke/github/GHObject.java b/src/main/java/org/kohsuke/github/GHObject.java index bf1a3b2948..914f1280d3 100644 --- a/src/main/java/org/kohsuke/github/GHObject.java +++ b/src/main/java/org/kohsuke/github/GHObject.java @@ -38,6 +38,12 @@ public URL getUrl() { 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? */ diff --git a/src/main/java/org/kohsuke/github/GHPerson.java b/src/main/java/org/kohsuke/github/GHPerson.java index fa651bb681..1a9a0f1575 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -2,6 +2,7 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.net.URL; import java.util.Arrays; import java.util.Collections; import java.util.Date; @@ -214,8 +215,9 @@ public String getBlog() throws IOException { return blog; } - public String getHtmlUrl() { - return html_url; + @Override + public URL getHtmlUrl() { + return GitHub.parseURL(html_url); } /** diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 7510cdf6c5..7c46a9c1c5 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -37,20 +37,20 @@ */ @SuppressWarnings({"UnusedDeclaration"}) public class GHPullRequest extends GHIssue { - - private String patch_url, diff_url, issue_url; - private GHCommitPointer base; - private String merged_at; - private GHCommitPointer head; + + private String patch_url, diff_url, issue_url; + private GHCommitPointer base; + private String merged_at; + private GHCommitPointer head; // details that are only available when obtained from ID private GHUser merged_by; - private int review_comments, additions; - private boolean merged; - private Boolean mergeable; - private int deletions; - private String mergeable_state; - private int changed_files; + private int review_comments, additions; + private boolean merged; + private Boolean mergeable; + private int deletions; + private String mergeable_state; + private int changed_files; /** * 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; - GHPullRequest wrapUp(GHRepository owner) { - this.wrap(owner); + GHPullRequest wrapUp(GHRepository owner) { + this.wrap(owner); return wrapUp(owner.root); } - + GHPullRequest wrapUp(GitHub root) { - if (owner!=null) owner.wrap(root); - if (base!=null) base.wrapUp(root); - if (head!=null) head.wrapUp(root); + if (owner != null) owner.wrap(root); + if (base != null) base.wrapUp(root); + if (head != null) head.wrapUp(root); if (merged_by != null) merged_by.wrapUp(root); return this; } @@ -85,8 +85,8 @@ protected String getApiRoute() { public URL getPatchUrl() { return GitHub.parseURL(patch_url); } - - /** + + /** * The URL of the patch file. * like https://github.com/jenkinsci/jenkins/pull/100.patch */ @@ -108,8 +108,8 @@ public GHCommitPointer getBase() { public GHCommitPointer getHead() { return head; } - - @Deprecated + + @Deprecated public Date getIssueUpdatedAt() throws IOException { return super.getUpdatedAt(); } @@ -126,65 +126,65 @@ public Date getMergedAt() { return GitHub.parseDate(merged_at); } - @Override - public Collection getLabels() throws IOException { + @Override + public Collection getLabels() throws IOException { fetchIssue(); - return super.getLabels(); - } + return super.getLabels(); + } @Override - public GHUser getClosedBy() { - return null; - } + public GHUser getClosedBy() { + return null; + } - @Override - public PullRequest getPullRequest() { - return null; - } + @Override + public PullRequest getPullRequest() { + return null; + } -// + // // details that are only available via get with ID // // public GHUser getMergedBy() throws IOException { populate(); - return merged_by; - } + return merged_by; + } - public int getReviewComments() throws IOException { + public int getReviewComments() throws IOException { populate(); - return review_comments; - } + return review_comments; + } - public int getAdditions() throws IOException { + public int getAdditions() throws IOException { populate(); - return additions; - } + return additions; + } public boolean isMerged() throws IOException { populate(); - return merged; - } + return merged; + } - public Boolean getMergeable() throws IOException { + public Boolean getMergeable() throws IOException { populate(); - return mergeable; - } + return mergeable; + } - public int getDeletions() throws IOException { + public int getDeletions() throws IOException { populate(); - return deletions; - } + return deletions; + } - public String getMergeableState() throws IOException { + public String getMergeableState() throws IOException { populate(); - return mergeable_state; - } + return mergeable_state; + } - public int getChangedFiles() throws IOException { + public int getChangedFiles() throws IOException { populate(); - return changed_files; - } + return changed_files; + } /** * Fully populate the data by retrieving missing data. diff --git a/src/main/java/org/kohsuke/github/GHRelease.java b/src/main/java/org/kohsuke/github/GHRelease.java index 88d978258e..86736e909d 100644 --- a/src/main/java/org/kohsuke/github/GHRelease.java +++ b/src/main/java/org/kohsuke/github/GHRelease.java @@ -3,6 +3,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.net.URL; import java.util.Arrays; import java.util.Date; import java.util.List; @@ -44,8 +45,8 @@ public boolean isDraft() { return draft; } - public String getHtmlUrl() { - return html_url; + public URL getHtmlUrl() { + return GitHub.parseURL(html_url); } public String getName() { diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index ff1539892d..e4459e84d6 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -63,6 +63,8 @@ public class GHRepository extends GHObject { private GHRepoPermission permissions; + private GHRepository source, parent; + public GHDeploymentBuilder createDeployment(String ref) { return new GHDeploymentBuilder(this,ref); } @@ -159,6 +161,10 @@ public String getSshUrl() { 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 */ @@ -353,7 +359,7 @@ public Date getPushedAt() { } /** - * 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 * This field is null until the user explicitly configures the master branch. @@ -642,48 +648,48 @@ public GHRef[] getRefs(String refType) throws IOException { 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. - * - * @param refName - * eg: heads/branch - * @return refs matching the request type - * @throws IOException - * on failure communicating with GitHub, potentially due to an - * invalid ref type being requested - */ - 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); - } + * Retrive a ref of the given type for the current GitHub repository. + * + * @param refName + * eg: heads/branch + * @return refs matching the request type + * @throws IOException + * on failure communicating with GitHub, potentially due to an + * invalid ref type being requested + */ + 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); + } + /** + * Retrive a tree of the given type for the current GitHub repository. + * + * @param sha - sha number or branch name ex: "master" + * @return refs matching the request type + * @throws IOException + * on failure communicating with GitHub, potentially due to an + * invalid tree type being requested + */ + public GHTree getTree(String sha) throws IOException { + String url = String.format("/repos/%s/%s/git/trees/%s", owner.login, name, sha); + return root.retrieve().to(url, GHTree.class).wrap(root); + } + + /** + * Retrieves the tree for the current GitHub repository, recursively as described in here: + * https://developer.github.com/v3/git/trees/#get-a-tree-recursively + * + * @param sha - sha number or branch name ex: "master" + * @param recursive use 1 + * @throws IOException + * on failure communicating with GitHub, potentially due to an + * invalid tree type being requested + */ + 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); + return root.retrieve().to(url, GHTree.class).wrap(root); + } + /** - * Retrive a tree of the given type for the current GitHub repository. - * - * @param sha - sha number or branch name ex: "master" - * @return refs matching the request type - * @throws IOException - * on failure communicating with GitHub, potentially due to an - * invalid tree type being requested - */ - public GHTree getTree(String sha) throws IOException { - String url = String.format("/repos/%s/%s/git/trees/%s", owner.login, name, sha); - return root.retrieve().to(url, GHTree.class).wrap(root); - } - - /** - * Retrieves the tree for the current GitHub repository, recursively as described in here: - * https://developer.github.com/v3/git/trees/#get-a-tree-recursively - * - * @param sha - sha number or branch name ex: "master" - * @param recursive use 1 - * @throws IOException - * on failure communicating with GitHub, potentially due to an - * invalid tree type being requested - */ - 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); - return root.retrieve().to(url, GHTree.class).wrap(root); - } - - /** * Gets a commit object in this repository. */ public GHCommit getCommit(String sha1) throws IOException { @@ -780,10 +786,10 @@ public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, Strin } /** - * @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 { - return createCommitStatus(sha1, state, targetUrl, description,null); + return createCommitStatus(sha1, state, targetUrl, description,null); } /** @@ -989,10 +995,10 @@ public Map getBranches() throws IOException { */ public Map getMilestones() throws IOException { Map milestones = new TreeMap(); - for (GHMilestone m : listMilestones(GHIssueState.OPEN)) { - milestones.put(m.getNumber(), m); - } - return milestones; + for (GHMilestone m : listMilestones(GHIssueState.OPEN)) { + milestones.put(m.getNumber(), m); + } + return milestones; } /** @@ -1012,16 +1018,16 @@ protected void wrapUp(GHMilestone[] page) { }; } - public GHMilestone getMilestone(int number) throws IOException { - GHMilestone m = milestones.get(number); - if (m == null) { + public GHMilestone getMilestone(int number) throws IOException { + GHMilestone m = milestones.get(number); + if (m == null) { m = root.retrieve().to(getApiTailUrl("milestones/" + number), GHMilestone.class); - m.owner = this; - m.root = root; - milestones.put(m.getNumber(), m); - } - return m; - } + m.owner = this; + m.root = root; + milestones.put(m.getNumber(), m); + } + return m; + } public GHContent getFileContent(String path) throws IOException { return getFileContent(path, null); @@ -1088,25 +1094,57 @@ public GHContentUpdateResponse createContent(byte[] contentBytes, String commitM return response; } - public GHMilestone createMilestone(String title, String description) throws IOException { + public GHMilestone createMilestone(String title, String description) throws IOException { return new Requester(root) .with("title", title).with("description", description).method("POST").to(getApiTailUrl("milestones"), GHMilestone.class).wrap(this); - } - - public GHDeployKey addDeployKey(String title,String key) throws IOException { - return new Requester(root) + } + + public GHDeployKey addDeployKey(String title,String key) throws IOException { + return new Requester(root) .with("title", title).with("key", key).method("POST").to(getApiTailUrl("keys"), GHDeployKey.class).wrap(this); - - } - - public List getDeployKeys() throws IOException{ - List list = new ArrayList(Arrays.asList( - root.retrieve().to(getApiTailUrl("keys"), GHDeployKey[].class))); - for (GHDeployKey h : list) - h.wrap(this); - return list; - } + + } + + public List getDeployKeys() throws IOException{ + List list = new ArrayList(Arrays.asList( + root.retrieve().to(getApiTailUrl("keys"), GHDeployKey[].class))); + for (GHDeployKey h : list) + h.wrap(this); + 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. */ diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index 4ec4c7cf87..7213f327c9 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -47,10 +47,10 @@ public int getId() { return id; } - /** - * Retrieves the current members. - */ - public PagedIterable listMembers() throws IOException { + /** + * Retrieves the current members. + */ + public PagedIterable listMembers() throws IOException { return new PagedIterable() { public PagedIterator iterator() { return new PagedIterator(org.root.retrieve().asIterator(api("/members"), GHUser[].class)) { @@ -64,8 +64,8 @@ protected void wrapUp(GHUser[] page) { } public Set getMembers() throws IOException { - return Collections.unmodifiableSet(listMembers().asSet()); - } + return Collections.unmodifiableSet(listMembers().asSet()); + } /** * Checks if this team has the specified user as a member. diff --git a/src/main/java/org/kohsuke/github/GHThread.java b/src/main/java/org/kohsuke/github/GHThread.java index e1f749a9f1..6a2608f253 100644 --- a/src/main/java/org/kohsuke/github/GHThread.java +++ b/src/main/java/org/kohsuke/github/GHThread.java @@ -2,6 +2,7 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.net.URL; import java.util.Date; /** @@ -37,6 +38,14 @@ public Date getLastReadAt() { return GitHub.parseDate(last_read_at); } + /** + * @deprecated This object has no HTML URL. + */ + @Override + public URL getHtmlUrl() { + return null; + } + public String getReason() { return reason; } @@ -59,6 +68,41 @@ public String getType() { 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) { this.root = root; if (this.repository!=null) diff --git a/src/main/java/org/kohsuke/github/GHTree.java b/src/main/java/org/kohsuke/github/GHTree.java index 90cf3c78e8..aaf98e77e2 100644 --- a/src/main/java/org/kohsuke/github/GHTree.java +++ b/src/main/java/org/kohsuke/github/GHTree.java @@ -13,46 +13,46 @@ * @see GHRepository#getTree(String) */ public class GHTree { - /* package almost final */GitHub root; - - private boolean truncated; - private String sha, url; - private GHTreeEntry[] tree; - - /** - * The SHA for this trees - */ - public String getSha() { - return sha; - } - - /** - * Return an array of entries of the trees - * @return - */ - public List getTree() { - return Collections.unmodifiableList(Arrays.asList(tree)); - } - - /** - * 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. - */ - public boolean isTruncated() { - return truncated; - } - - /** - * The API URL of this tag, such as - * "url": "https://api.github.com/repos/octocat/Hello-World/trees/fc6274d15fa3ae2ab983129fb037999f264ba9a7", - */ - public URL getUrl() { - return GitHub.parseURL(url); - } - - /* package */GHTree wrap(GitHub root) { - this.root = root; - return this; - } + /* package almost final */GitHub root; + + private boolean truncated; + private String sha, url; + private GHTreeEntry[] tree; + + /** + * The SHA for this trees + */ + public String getSha() { + return sha; + } + + /** + * Return an array of entries of the trees + * @return + */ + public List getTree() { + return Collections.unmodifiableList(Arrays.asList(tree)); + } + + /** + * 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. + */ + public boolean isTruncated() { + return truncated; + } + + /** + * The API URL of this tag, such as + * "url": "https://api.github.com/repos/octocat/Hello-World/trees/fc6274d15fa3ae2ab983129fb037999f264ba9a7", + */ + public URL getUrl() { + return GitHub.parseURL(url); + } + + /* package */GHTree wrap(GitHub root) { + this.root = root; + return this; + } } diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 33601668ff..744a6d36e9 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -60,7 +60,7 @@ *

* This library aims to be safe for use by multiple threads concurrently, although * 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 */ @@ -252,11 +252,11 @@ public GHRateLimit getRateLimit() throws IOException { } /** - * Gets the {@link GHUser} that represents yourself. - */ + * Gets the {@link GHUser} that represents yourself. + */ @WithBridgeMethods(GHUser.class) - public GHMyself getMyself() throws IOException { - requireCredential(); + public GHMyself getMyself() throws IOException { + requireCredential(); GHMyself u = retrieve().to("/user", GHMyself.class); @@ -264,20 +264,20 @@ public GHMyself getMyself() throws IOException { users.put(u.getLogin(), u); return u; - } - - /** - * Obtains the object that represents the named user. - */ - public GHUser getUser(String login) throws IOException { - GHUser u = users.get(login); - if (u == null) { + } + + /** + * Obtains the object that represents the named user. + */ + public GHUser getUser(String login) throws IOException { + GHUser u = users.get(login); + if (u == null) { u = retrieve().to("/users/" + login, GHUser.class); u.root = this; users.put(u.getLogin(), u); - } - return u; - } + } + return u; + } /** @@ -415,14 +415,14 @@ public GHRepository createRepository(String name, String description, String hom * * @see Documentation */ - public GHAuthorization createToken(Collection scope, String note, String noteUrl) throws IOException{ - Requester requester = new Requester(this) - .with("scopes", scope) - .with("note", note) - .with("note_url", noteUrl); - - return requester.method("POST").to("/authorizations", GHAuthorization.class).wrap(this); - } + public GHAuthorization createToken(Collection scope, String note, String noteUrl) throws IOException{ + Requester requester = new Requester(this) + .with("scopes", scope) + .with("note", note) + .with("note_url", noteUrl); + + return requester.method("POST").to("/authorizations", GHAuthorization.class).wrap(this); + } /** * Ensures that the credential is valid. diff --git a/src/main/java/org/kohsuke/github/GitHubBuilder.java b/src/main/java/org/kohsuke/github/GitHubBuilder.java index 98248b94b0..c0ecaffda5 100644 --- a/src/main/java/org/kohsuke/github/GitHubBuilder.java +++ b/src/main/java/org/kohsuke/github/GitHubBuilder.java @@ -45,18 +45,18 @@ public GitHubBuilder() { * @throws IOException If there are no credentials defined in the ~/.github properties file or the process environment. */ public static GitHubBuilder fromCredentials() throws IOException { - Exception cause = null; - GitHubBuilder builder; + Exception cause = null; + GitHubBuilder builder; - try { - builder = fromPropertyFile(); + try { + builder = fromPropertyFile(); - if (builder.user != null) - return builder; - } catch (FileNotFoundException e) { + if (builder.user != null) + return builder; + } catch (FileNotFoundException e) { // fall through cause = e; - } + } builder = fromEnvironment(); @@ -77,8 +77,8 @@ public static GitHubBuilder fromEnvironment(String loginVariableName, String pas private static void loadIfSet(String envName, Properties p, String propName) { String v = System.getenv(envName); - if (v != null) - p.put(propName, v); + if (v != null) + p.put(propName, v); } /** @@ -87,12 +87,12 @@ private static void loadIfSet(String envName, Properties p, String propName) { * 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 { - Properties env = new Properties(); - loadIfSet(loginVariableName,env,"login"); + Properties env = new Properties(); + loadIfSet(loginVariableName,env,"login"); loadIfSet(passwordVariableName,env,"password"); loadIfSet(oauthVariableName,env,"oauth"); loadIfSet(endpointVariableName,env,"endpoint"); - return fromProperties(env); + return fromProperties(env); } /** @@ -116,7 +116,7 @@ public static GitHubBuilder fromEnvironment(String loginVariableName, String pas * login, password, oauth */ public static GitHubBuilder fromEnvironment() throws IOException { - Properties props = new Properties(); + Properties props = new Properties(); for (Entry e : System.getenv().entrySet()) { String name = e.getKey().toLowerCase(Locale.ENGLISH); if (name.startsWith("github_")) name=name.substring(7); diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index cbab7b82fb..960940e7cf 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -479,6 +479,9 @@ private InputStream wrapStream(InputStream in) throws IOException { * Handle API error by either throwing it or by returning normally to retry. */ /*package*/ void handleApiError(IOException e) throws IOException { + if (uc.getResponseCode() == 401) // Unauthorized == bad creds + throw e; + if ("0".equals(uc.getHeaderField("X-RateLimit-Remaining"))) { root.rateLimitHandler.onError(e,uc); } diff --git a/src/test/java/org/kohsuke/github/AbstractGitHubApiTestBase.java b/src/test/java/org/kohsuke/github/AbstractGitHubApiTestBase.java index a4311429d7..f1753481e7 100644 --- a/src/test/java/org/kohsuke/github/AbstractGitHubApiTestBase.java +++ b/src/test/java/org/kohsuke/github/AbstractGitHubApiTestBase.java @@ -19,9 +19,9 @@ public void setUp() throws Exception { if (f.exists()) { // use the non-standard credential preferentially, so that developers of this library do not have // to clutter their event stream. - gitHub = GitHubBuilder.fromPropertyFile(f.getPath()).build(); + gitHub = GitHubBuilder.fromPropertyFile(f.getPath()).withRateLimitHandler(RateLimitHandler.FAIL).build(); } else { - gitHub = GitHub.connect(); + gitHub = GitHubBuilder.fromCredentials().withRateLimitHandler(RateLimitHandler.FAIL).build(); } } diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index b5d7c517a7..5cdb17e987 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -598,10 +598,10 @@ public void testCreateRelease() throws Exception { } @Test - public void testRef() throws IOException { - GHRef masterRef = gitHub.getRepository("jenkinsci/jenkins").getRef("heads/master"); - assertEquals("https://api.github.com/repos/jenkinsci/jenkins/git/refs/heads/master", masterRef.getUrl().toString()); - } + public void testRef() throws IOException { + GHRef masterRef = gitHub.getRepository("jenkinsci/jenkins").getRef("heads/master"); + assertEquals("https://api.github.com/repos/jenkinsci/jenkins/git/refs/heads/master", masterRef.getUrl().toString()); + } @Test public void directoryListing() throws IOException { @@ -618,8 +618,8 @@ public void directoryListing() throws IOException { @Test public void testAddDeployKey() throws IOException { - 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"); + 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"); try { assertNotNull(newDeployKey.getId()); @@ -636,11 +636,11 @@ public boolean apply(GHDeployKey deployKey) { @Test public void testCommitStatusContext() throws IOException { - GHRepository myRepository = Iterables.get(gitHub.getMyself().getRepositories().values(), 0); - GHRef masterRef = myRepository.getRef("heads/master"); - GHCommitStatus commitStatus = myRepository.createCommitStatus(masterRef.getObject().getSha(), GHCommitState.SUCCESS, "http://www.example.com", "test", "test/context"); - assertEquals("test/context", commitStatus.getContext()); - + GHRepository myRepository = Iterables.get(gitHub.getMyself().getRepositories().values(), 0); + GHRef masterRef = myRepository.getRef("heads/master"); + GHCommitStatus commitStatus = myRepository.createCommitStatus(masterRef.getObject().getSha(), GHCommitState.SUCCESS, "http://www.example.com", "test", "test/context"); + assertEquals("test/context", commitStatus.getContext()); + } @Test @@ -671,28 +671,28 @@ public void testReadme() throws IOException { @Test public void testTrees() throws IOException { - GHTree masterTree = gitHub.getRepository("kohsuke/github-api").getTree("master"); - boolean foundReadme = false; - for(GHTreeEntry e : masterTree.getTree()){ - if("readme".equalsIgnoreCase(e.getPath().replaceAll(".md", ""))){ - foundReadme = true; - break; - } - } - assertTrue(foundReadme); + GHTree masterTree = gitHub.getRepository("kohsuke/github-api").getTree("master"); + boolean foundReadme = false; + for(GHTreeEntry e : masterTree.getTree()){ + if("readme".equalsIgnoreCase(e.getPath().replaceAll("\\.md", ""))){ + foundReadme = true; + break; + } + } + assertTrue(foundReadme); } @Test public void testTreesRecursive() throws IOException { - GHTree masterTree = gitHub.getRepository("kohsuke/github-api").getTreeRecursive("master", 1); - boolean foundThisFile = false; - for(GHTreeEntry e : masterTree.getTree()){ - if(e.getPath().endsWith(AppTest.class.getSimpleName() + ".java")){ - foundThisFile = true; - break; - } - } - assertTrue(foundThisFile); + GHTree masterTree = gitHub.getRepository("kohsuke/github-api").getTreeRecursive("master", 1); + boolean foundThisFile = false; + for(GHTreeEntry e : masterTree.getTree()){ + if(e.getPath().endsWith(AppTest.class.getSimpleName() + ".java")){ + foundThisFile = true; + break; + } + } + assertTrue(foundThisFile); } @Test diff --git a/src/test/java/org/kohsuke/github/GitHubTest.java b/src/test/java/org/kohsuke/github/GitHubTest.java index 4ac4ecfea2..578bbc13f3 100644 --- a/src/test/java/org/kohsuke/github/GitHubTest.java +++ b/src/test/java/org/kohsuke/github/GitHubTest.java @@ -30,21 +30,21 @@ public void testGitHubServerWithoutServer() throws Exception { } public void testGitHubBuilderFromEnvironment() throws IOException { - - Mapprops = new HashMap(); - - props.put("login", "bogus"); - props.put("oauth", "bogus"); - props.put("password", "bogus"); - - setupEnvironment(props); - - GitHubBuilder builder = GitHubBuilder.fromEnvironment(); - - assertEquals("bogus", builder.user); - assertEquals("bogus", builder.oauthToken); - assertEquals("bogus", builder.password); - + + Mapprops = new HashMap(); + + props.put("login", "bogus"); + props.put("oauth", "bogus"); + props.put("password", "bogus"); + + setupEnvironment(props); + + GitHubBuilder builder = GitHubBuilder.fromEnvironment(); + + assertEquals("bogus", builder.user); + assertEquals("bogus", builder.oauthToken); + assertEquals("bogus", builder.password); + } /* @@ -55,59 +55,54 @@ public void testGitHubBuilderFromEnvironment() throws IOException { * Its used to wire in values for the github credentials to test that the GitHubBuilder works properly to resolve them. */ private void setupEnvironment(Map newenv) { - try - { - Class processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment"); - Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment"); - theEnvironmentField.setAccessible(true); - Map env = (Map) theEnvironmentField.get(null); - env.putAll(newenv); - Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment"); - theCaseInsensitiveEnvironmentField.setAccessible(true); - Map cienv = (Map) theCaseInsensitiveEnvironmentField.get(null); - cienv.putAll(newenv); - } - catch (NoSuchFieldException e) - { - try { - Class[] classes = Collections.class.getDeclaredClasses(); - Map env = System.getenv(); - for(Class cl : classes) { - if("java.util.Collections$UnmodifiableMap".equals(cl.getName())) { - Field field = cl.getDeclaredField("m"); - field.setAccessible(true); - Object obj = field.get(env); - Map map = (Map) obj; - map.clear(); - map.putAll(newenv); - } - } - } catch (Exception e2) { - e2.printStackTrace(); - } - } catch (Exception e1) { - e1.printStackTrace(); - } - - } + try { + Class processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment"); + Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment"); + theEnvironmentField.setAccessible(true); + Map env = (Map) theEnvironmentField.get(null); + env.putAll(newenv); + Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment"); + theCaseInsensitiveEnvironmentField.setAccessible(true); + Map cienv = (Map) theCaseInsensitiveEnvironmentField.get(null); + cienv.putAll(newenv); + } catch (NoSuchFieldException e) { + try { + Class[] classes = Collections.class.getDeclaredClasses(); + Map env = System.getenv(); + for (Class cl : classes) { + if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) { + Field field = cl.getDeclaredField("m"); + field.setAccessible(true); + Object obj = field.get(env); + Map map = (Map) obj; + map.clear(); + map.putAll(newenv); + } + } + } catch (Exception e2) { + e2.printStackTrace(); + } + } catch (Exception e1) { + e1.printStackTrace(); + } + } + + public void testGitHubBuilderFromCustomEnvironment() throws IOException { + Map props = new HashMap(); + + props.put("customLogin", "bogusLogin"); + props.put("customOauth", "bogusOauth"); + props.put("customPassword", "bogusPassword"); + props.put("customEndpoint", "bogusEndpoint"); - public void testGitHubBuilderFromCustomEnvironment() throws IOException { - - Mapprops = new HashMap(); - - props.put("customLogin", "bogusLogin"); - props.put("customOauth", "bogusOauth"); - props.put("customPassword", "bogusPassword"); - props.put("customEndpoint", "bogusEndpoint"); + setupEnvironment(props); - 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); + GitHubBuilder builder = GitHubBuilder.fromEnvironment("customLogin", "customPassword", "customOauth", "customEndpoint"); + + assertEquals("bogusLogin", builder.user); + assertEquals("bogusOauth", builder.oauthToken); + assertEquals("bogusPassword", builder.password); + assertEquals("bogusEndpoint", builder.endpoint); } - + }