From d070f9deb0d3e266c682e46b1caee5088c35d837 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Mon, 13 Apr 2015 18:25:44 -0700 Subject: [PATCH] TAB -> WS --- .../org/kohsuke/github/GHAuthorization.java | 119 ++++++++------- .../java/org/kohsuke/github/GHCommit.java | 37 +++-- .../org/kohsuke/github/GHCommitStatus.java | 6 +- .../java/org/kohsuke/github/GHCompare.java | 6 +- .../java/org/kohsuke/github/GHDeployKey.java | 10 +- src/main/java/org/kohsuke/github/GHIssue.java | 108 +++++++------- .../java/org/kohsuke/github/GHMilestone.java | 104 ++++++------- .../org/kohsuke/github/GHPullRequest.java | 110 +++++++------- .../java/org/kohsuke/github/GHRepository.java | 138 +++++++++--------- src/main/java/org/kohsuke/github/GHTeam.java | 12 +- src/main/java/org/kohsuke/github/GHTree.java | 70 ++++----- src/main/java/org/kohsuke/github/GitHub.java | 42 +++--- .../org/kohsuke/github/GitHubBuilder.java | 28 ++-- src/test/java/org/kohsuke/github/AppTest.java | 58 ++++---- .../java/org/kohsuke/github/GitHubTest.java | 133 ++++++++--------- 15 files changed, 486 insertions(+), 495 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHAuthorization.java b/src/main/java/org/kohsuke/github/GHAuthorization.java index 1afa3fabc..f990cbefb 100644 --- a/src/main/java/org/kohsuke/github/GHAuthorization.java +++ b/src/main/java/org/kohsuke/github/GHAuthorization.java @@ -13,83 +13,80 @@ import java.util.List; * @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"; + 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; + 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(){ + public String getAppName() { + return app.name; + } + + public URL getApiURL() { return GitHub.parseURL(url); - } + } - /** - * @deprecated This object has no HTML URL. - */ - @Override - public URL getHtmlUrl() { - return null; - } + /** + * @deprecated This object has no HTML URL. + */ + @Override + public URL getHtmlUrl() { + return null; + } - public String getNote() { - return note; - } + public String getNote() { + return note; + } - public URL getNoteUrl(){ + public URL getNoteUrl() { return GitHub.parseURL(note_url); - } + } - /*package*/ GHAuthorization wrap(GitHub root) { - this.root = root; - return this; - } + /*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 75f084c8e..fbb7c24fd 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -32,26 +32,26 @@ public class GHCommit { 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 @@ public class GHCommit { 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 c568b66f6..c9241442b 100644 --- a/src/main/java/org/kohsuke/github/GHCommitStatus.java +++ b/src/main/java/org/kohsuke/github/GHCommitStatus.java @@ -50,9 +50,9 @@ public class GHCommitStatus extends GHObject { return creator; } - public String getContext() { - return context; - } + public String getContext() { + return context; + } /** * @deprecated This object has no HTML URL. diff --git a/src/main/java/org/kohsuke/github/GHCompare.java b/src/main/java/org/kohsuke/github/GHCompare.java index 9ca63b6e3..2c2bc5ba7 100644 --- a/src/main/java/org/kohsuke/github/GHCompare.java +++ b/src/main/java/org/kohsuke/github/GHCompare.java @@ -70,10 +70,10 @@ public class GHCompare { } 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 6e4ed496a..eb2c2c00f 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 class GHDeployKey { 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/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index 69ffc29a8..8c071a93f 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -44,8 +44,8 @@ import java.util.Locale; 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 class GHIssue extends GHObject { /*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 class GHIssue extends GHObject { 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 class GHIssue extends GHObject { /** * 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 @@ public class GHIssue extends GHObject { 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 class GHIssue extends GHObject { * 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 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 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/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java index 6b802bfcf..146c92abb 100644 --- a/src/main/java/org/kohsuke/github/GHMilestone.java +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -12,56 +12,56 @@ import java.util.Locale; */ public class GHMilestone extends GHObject { GitHub root; - GHRepository owner; + GHRepository owner; - GHUser creator; - private String state, due_on, title, description, html_url; - 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 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)); - } + public URL getHtmlUrl() { + return GitHub.parseURL(html_url); + } + + public GHMilestoneState getState() { + return Enum.valueOf(GHMilestoneState.class, state.toUpperCase(Locale.ENGLISH)); + } /** * Closes this issue. @@ -78,9 +78,9 @@ public class GHMilestone extends GHObject { 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/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 7510cdf6c..7c46a9c1c 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -37,20 +37,20 @@ import java.util.Locale; */ @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 @@ public class GHPullRequest extends GHIssue { 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 class GHPullRequest extends GHIssue { public GHCommitPointer getHead() { return head; } - - @Deprecated + + @Deprecated public Date getIssueUpdatedAt() throws IOException { return super.getUpdatedAt(); } @@ -126,65 +126,65 @@ public class GHPullRequest extends GHIssue { 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/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 3ec758bb1..e4459e84d 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -648,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); } /** - * 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 { @@ -789,7 +789,7 @@ public class GHRepository extends GHObject { * @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); } /** @@ -995,10 +995,10 @@ public class GHRepository extends GHObject { */ 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; } /** @@ -1018,16 +1018,16 @@ public class GHRepository extends GHObject { }; } - 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); @@ -1094,24 +1094,24 @@ public class GHRepository extends GHObject { 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. diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index 4ec4c7cf8..7213f327c 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -47,10 +47,10 @@ public class GHTeam { 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 @@ public class GHTeam { } 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/GHTree.java b/src/main/java/org/kohsuke/github/GHTree.java index 90cf3c78e..aaf98e77e 100644 --- a/src/main/java/org/kohsuke/github/GHTree.java +++ b/src/main/java/org/kohsuke/github/GHTree.java @@ -13,46 +13,46 @@ import java.util.List; * @see GHRepository#getTree(String) */ public class GHTree { - /* package almost final */GitHub root; + /* package almost final */GitHub root; - private boolean truncated; - private String sha, url; - private GHTreeEntry[] tree; + private boolean truncated; + private String sha, url; + private GHTreeEntry[] tree; - /** - * The SHA for this trees - */ - public String getSha() { - return sha; - } + /** + * 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)); - } + /** + * 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; - } + /** + * 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); - } + /** + * 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 */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 9f855f687..744a6d36e 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -252,11 +252,11 @@ public class GitHub { } /** - * 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 class GitHub { 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 class GitHub { * * @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); + 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); - } + 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 98248b94b..c0ecaffda 100644 --- a/src/main/java/org/kohsuke/github/GitHubBuilder.java +++ b/src/main/java/org/kohsuke/github/GitHubBuilder.java @@ -45,18 +45,18 @@ public class 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 class GitHubBuilder { 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 @@ public class GitHubBuilder { * 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 class GitHubBuilder { * 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/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index 8e7fe8972..5cdb17e98 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -598,10 +598,10 @@ public class AppTest extends AbstractGitHubApiTestBase { } @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 class AppTest extends AbstractGitHubApiTestBase { @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 class AppTest extends AbstractGitHubApiTestBase { @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 class AppTest extends AbstractGitHubApiTestBase { @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 4ac4ecfea..578bbc13f 100644 --- a/src/test/java/org/kohsuke/github/GitHubTest.java +++ b/src/test/java/org/kohsuke/github/GitHubTest.java @@ -30,21 +30,21 @@ public class GitHubTest extends TestCase { } 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 class GitHubTest extends TestCase { * 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(); - } - - } - - 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); - - GitHubBuilder builder = GitHubBuilder.fromEnvironment("customLogin", "customPassword", "customOauth", "customEndpoint"); - - assertEquals("bogusLogin", builder.user); - assertEquals("bogusOauth", builder.oauthToken); - assertEquals("bogusPassword", builder.password); - assertEquals("bogusEndpoint", builder.endpoint); + 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"); + + 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); + } + }