From 3b5bc9805324a1b7b2c0e293ffc6efe4990e2345 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Mon, 4 Jun 2012 10:09:15 -0700 Subject: [PATCH 1/7] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a57550ca7c..2ac5dad891 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.26 + 1.27-SNAPSHOT GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java From b5f7208b0dd65b353483628a4ee259b701746b2b Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 12 Jun 2012 14:06:49 -0700 Subject: [PATCH 2/7] Removed v2 API usage and switched to v3. https://github.com/kohsuke/github-api/issues/8 --- .../java/org/kohsuke/github/ApiVersion.java | 1 - src/main/java/org/kohsuke/github/GHIssue.java | 51 +++++++-- .../org/kohsuke/github/GHIssueComment.java | 5 + .../org/kohsuke/github/GHOrganization.java | 21 +++- .../java/org/kohsuke/github/GHPerson.java | 5 + .../java/org/kohsuke/github/GHPersonSet.java | 5 + .../java/org/kohsuke/github/GHRepository.java | 101 ++++++++---------- src/main/java/org/kohsuke/github/GHTeam.java | 24 ++++- src/main/java/org/kohsuke/github/GHUser.java | 19 +++- src/main/java/org/kohsuke/github/GitHub.java | 23 ++-- src/main/java/org/kohsuke/github/Poster.java | 33 ++---- 11 files changed, 169 insertions(+), 119 deletions(-) diff --git a/src/main/java/org/kohsuke/github/ApiVersion.java b/src/main/java/org/kohsuke/github/ApiVersion.java index 922dbe7aa1..9ce1683d25 100644 --- a/src/main/java/org/kohsuke/github/ApiVersion.java +++ b/src/main/java/org/kohsuke/github/ApiVersion.java @@ -7,7 +7,6 @@ */ enum ApiVersion { - V2("https://?/api/v2/json"), V3("https://api.?"); final String templateUrl; diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index 842071b7eb..475a5f7ba2 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -26,11 +26,14 @@ import java.io.IOException; import java.net.URL; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; +import static org.kohsuke.github.ApiVersion.V3; + /** * Represents an issue on GitHub. * @@ -46,6 +49,18 @@ public class GHIssue { private int number,votes,comments; private int position; + /*package*/ GHIssue wrap(GHRepository owner) { + this.owner = owner; + this.root = owner.root; + return this; + } + + /*package*/ static GHIssue[] wrap(GHIssue[] issues, GHRepository owner) { + for (GHIssue i : issues) + i.wrap(owner); + return issues; + } + /** * Repository to which the issue belongs. */ @@ -99,31 +114,55 @@ public Date getUpdatedAt() { * Updates the issue by adding a comment. */ public void comment(String message) throws IOException { - new Poster(root).withCredential().with("comment",message).to(getApiRoute("comment")); + new Poster(root, V3).withCredential().with("body",message).to(getApiRoute()+"/comments",null,"POST"); + } + + private void edit(String key, Object value) throws IOException { + new Poster(root,V3).withCredential()._with(key, value) + .to(getApiRoute(),null,"PATCH"); } /** * Closes this issue. */ public void close() throws IOException { - new Poster(root).withCredential().to(getApiRoute("close")); + edit("state", "closed"); } /** * Reopens this issue. */ public void reopen() throws IOException { - new Poster(root).withCredential().to(getApiRoute("reopen")); + edit("state", "open"); + } + + public void setTitle(String title) throws IOException { + edit("title",title); + } + + public void setBody(String body) throws IOException { + edit("body",body); + } + + public void assignTo(GHUser user) throws IOException { + edit("assignee",user.getLogin()); + } + + public void setLabels(String... labels) throws IOException { + edit("assignee",labels); } /** * Obtains all the comments associated with this issue. */ public List getComments() throws IOException { - return root.retrieve(getApiRoute("comments"), JsonIssueComments.class).wrap(this); + GHIssueComment[] r = root.retrieve3(getApiRoute()+"/comments", GHIssueComment[].class); + for (GHIssueComment c : r) + c.wrapUp(this); + return Arrays.asList(r); } - private String getApiRoute(String verb) { - return "/issues/"+verb+"/"+owner.getOwnerName()+"/"+owner.getName()+"/"+number; + private String getApiRoute() { + return "/repos/"+owner.getOwnerName()+"/"+owner.getName()+"/issues/"+number; } } \ No newline at end of file diff --git a/src/main/java/org/kohsuke/github/GHIssueComment.java b/src/main/java/org/kohsuke/github/GHIssueComment.java index d17c0a2952..9dd96896a1 100644 --- a/src/main/java/org/kohsuke/github/GHIssueComment.java +++ b/src/main/java/org/kohsuke/github/GHIssueComment.java @@ -37,6 +37,11 @@ public class GHIssueComment { private String body, gravatar_id, user, created_at, updated_at; private int id; + /*package*/ GHIssueComment wrapUp(GHIssue owner) { + this.owner = owner; + return this; + } + /** * Gets the issue to which this comment is associated. */ diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index 8af52fc0af..9b2696a873 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -4,7 +4,6 @@ import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.HtmlPage; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.AbstractList; import java.util.ArrayList; @@ -12,6 +11,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.TreeMap; import static org.kohsuke.github.ApiVersion.*; @@ -19,6 +19,10 @@ * @author Kohsuke Kawaguchi */ public class GHOrganization extends GHPerson { + /*package*/ GHOrganization wrapUp(GitHub root) { + return (GHOrganization)super.wrapUp(root); + } + /** * Creates a new repository. * @@ -40,7 +44,12 @@ public GHRepository createRepository(String name, String description, String hom * Teams by their names. */ public Map getTeams() throws IOException { - return root.retrieveWithAuth("/organizations/"+login+"/teams",JsonTeams.class).toMap(this); + GHTeam[] teams = root.retrieveWithAuth3("/orgs/" + login + "/teams", GHTeam[].class); + Map r = new TreeMap(); + for (GHTeam t : teams) { + r.put(t.getName(),t); + } + return r; } /** @@ -88,11 +97,13 @@ public enum Permission { ADMIN, PUSH, PULL } * Creates a new team and assigns the repositories. */ public GHTeam createTeam(String name, Permission p, Collection repositories) throws IOException { - Poster post = new Poster(root).withCredential().with("team[name]", name).with("team[permission]", p.name().toLowerCase()); + Poster post = new Poster(root,V3).withCredential().with("name", name).with("permission", p.name().toLowerCase()); + List repo_names = new ArrayList(); for (GHRepository r : repositories) { - post.with("team[repo_names][]",r.getOwnerName()+'/'+r.getName()); + repo_names.add(r.getName()); } - return post.to("/organizations/"+login+"/teams",JsonTeam.class).wrap(this); + post.with("repo_names",repo_names); + return post.to("/orgs/"+login+"/teams",GHTeam.class,"POST").wrapUp(this); } public GHTeam createTeam(String name, Permission p, GHRepository... repositories) throws IOException { diff --git a/src/main/java/org/kohsuke/github/GHPerson.java b/src/main/java/org/kohsuke/github/GHPerson.java index 1c345462c3..3aaa45ba08 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -33,6 +33,11 @@ public abstract class GHPerson { protected String avatar_url,html_url; protected int followers,following,public_repos,public_gists; + /*package*/ GHPerson wrapUp(GitHub root) { + this.root = root; + return this; + } + /** * Gets the repositories this user owns. */ diff --git a/src/main/java/org/kohsuke/github/GHPersonSet.java b/src/main/java/org/kohsuke/github/GHPersonSet.java index 5b98f036d4..824febee39 100644 --- a/src/main/java/org/kohsuke/github/GHPersonSet.java +++ b/src/main/java/org/kohsuke/github/GHPersonSet.java @@ -1,5 +1,6 @@ package org.kohsuke.github; +import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -16,6 +17,10 @@ public GHPersonSet(Collection c) { super(c); } + public GHPersonSet(T... c) { + super(Arrays.asList(c)); + } + public GHPersonSet(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); } diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 5516382317..87ce6bb95b 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -23,7 +23,6 @@ */ package org.kohsuke.github; -import com.gargoylesoftware.htmlunit.ElementNotFoundException; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlButton; import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput; @@ -33,8 +32,6 @@ import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import java.io.IOException; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; import java.net.URL; import java.util.AbstractSet; import java.util.ArrayList; @@ -144,7 +141,7 @@ public GHUser getOwner() throws IOException { } public List getIssues(GHIssueState state) throws IOException { - return root.retrieve("/issues/list/" + owner.login + "/" + name + "/" + state.toString().toLowerCase(), JsonIssues.class).wrap(this); + return Arrays.asList(GHIssue.wrap(root.retrieve3("/repos/" + owner.login + "/" + name + "/issues?state=" + state.toString().toLowerCase(), GHIssue[].class), this)); } protected String getOwnerName() { @@ -216,10 +213,7 @@ public int getSize() { */ @WithBridgeMethods(Set.class) public GHPersonSet getCollaborators() throws IOException { - GHPersonSet r = new GHPersonSet(); - for (String u : root.retrieve("/repos/show/"+owner.login+"/"+name+"/collaborators",JsonCollaborators.class).collaborators) - r.add(root.getUser(u)); - return r; + return new GHPersonSet(GHUser.wrap(root.retrieve3("/repos/"+owner.login+"/"+name+"/collaborators",GHUser[].class),root)); } /** @@ -227,16 +221,17 @@ public GHPersonSet getCollaborators() throws IOException { * This method deviates from the principle of this library but it works a lot faster than {@link #getCollaborators()}. */ public Set getCollaboratorNames() throws IOException { - Set r = new HashSet(root.retrieve("/repos/show/"+owner.login+"/"+name+"/collaborators",JsonCollaborators.class).collaborators); - return Collections.unmodifiableSet(r); + Set r = new HashSet(); + for (GHUser u : GHUser.wrap(root.retrieve3("/repos/"+owner.login+"/"+name+"/collaborators",GHUser[].class),root)) + r.add(u.login); + return r; } /** * If this repository belongs to an organization, return a set of teams. */ public Set getTeams() throws IOException { - return Collections.unmodifiableSet(root.retrieveWithAuth("/repos/show/"+owner.login+"/"+name+"/teams",JsonTeams.class).toSet( - root.getOrganization(owner.login))); + return Collections.unmodifiableSet(new HashSet(Arrays.asList(GHTeam.wrapUp(root.retrieveWithAuth3("/repos/" + owner.login + "/" + name + "/teams", GHTeam[].class), root.getOrganization(owner.login))))); } public void addCollaborators(GHUser... users) throws IOException { @@ -244,7 +239,7 @@ public void addCollaborators(GHUser... users) throws IOException { } public void addCollaborators(Collection users) throws IOException { - modifyCollaborators(users, "/add/"); + modifyCollaborators(users, "PUT"); } public void removeCollaborators(GHUser... users) throws IOException { @@ -252,13 +247,13 @@ public void removeCollaborators(GHUser... users) throws IOException { } public void removeCollaborators(Collection users) throws IOException { - modifyCollaborators(users, "/remove/"); + modifyCollaborators(users, "DELETE"); } - private void modifyCollaborators(Collection users, String op) throws IOException { + private void modifyCollaborators(Collection users, String method) throws IOException { verifyMine(); for (GHUser user : users) { - new Poster(root).withCredential().to("/repos/collaborators/"+name+ op +user.getLogin()); + new Poster(root,V3).withCredential().to("/repos/"+owner.login+"/"+name+"/collaborators/"+user.getLogin(),null,method); } } @@ -274,31 +269,54 @@ public void setEmailServiceHook(String address) throws IOException { f.submit((HtmlButton) f.getElementsByTagName("button").get(0)); } + private void edit(String key, String value) throws IOException { + new Poster(root,V3).withCredential().with(key,value) + .to("/repos/" + owner.login + "/" + name,null,"PATCH"); + } + /** * Enables or disables the issue tracker for this repository. */ public void enableIssueTracker(boolean v) throws IOException { - new Poster(root).withCredential().with("values[has_issues]",String.valueOf(v)) - .to("/repos/show/" + owner.login + "/" + name); + edit("has_issues", String.valueOf(v)); } /** * Enables or disables Wiki for this repository. */ public void enableWiki(boolean v) throws IOException { - new Poster(root).withCredential().with("values[has_wiki]",String.valueOf(v)) - .to("/repos/show/" + owner.login + "/" + name); + edit("has_wiki", String.valueOf(v)); + } + + public void enableDownloads(boolean v) throws IOException { + edit("has_downloads",String.valueOf(v)); + } + + /** + * Rename this repository. + */ + public void renameTo(String name) throws IOException { + edit("name",name); + } + + public void setDescription(String value) throws IOException { + edit("description",value); + } + + public void setHomepage(String value) throws IOException { + edit("homepage",value); } /** * Deletes this repository. */ public void delete() throws IOException { - Poster poster = new Poster(root).withCredential(); - String url = "/repos/delete/" + owner.login +"/"+name; - - DeleteToken token = poster.to(url, DeleteToken.class); - poster.with("delete_token", token.delete_token).to(url); + throw new UnsupportedOperationException(); // doesn't appear to be available in V3 +// Poster poster = new Poster(root).withCredential(); +// String url = "/repos/delete/" + owner.login +"/"+name; +// +// DeleteToken token = poster.to(url, DeleteToken.class); +// poster.with("delete_token", token.delete_token).to(url); } /** @@ -322,39 +340,6 @@ public GHRepository forkTo(GHOrganization org) throws IOException { return org.getRepository(name); } - /** - * Rename this repository. - */ - public void renameTo(String newName) throws IOException { - WebClient wc = root.createWebClient(); - HtmlPage pg = (HtmlPage)wc.getPage(getUrl()+"/admin"); - for (HtmlForm f : pg.getForms()) { - if (!f.getActionAttribute().endsWith("/rename")) continue; - try { - f.getInputByName("name").setValueAttribute(newName); - f.submit((HtmlButton)f.getElementsByTagName("button").get(0)); - - // overwrite fields - final GHRepository r = getOwner().getRepository(newName); - for (Field fi : getClass().getDeclaredFields()) { - if (Modifier.isStatic(fi.getModifiers())) continue; - fi.setAccessible(true); - try { - fi.set(this,fi.get(r)); - } catch (IllegalAccessException e) { - throw (IllegalAccessError)new IllegalAccessError().initCause(e); - } - } - - return; - } catch (ElementNotFoundException e) { - // continue - } - } - - throw new IllegalArgumentException("Either you don't have the privilege to rename "+owner.login+'/'+name+" or there's a bug in HTML scraping"); - } - /** * Retrieves a specified pull request. */ diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index a9443acb08..037287911a 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -1,6 +1,8 @@ package org.kohsuke.github; import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -15,6 +17,18 @@ public class GHTeam { protected /*final*/ GHOrganization org; + /*package*/ GHTeam wrapUp(GHOrganization owner) { + this.org = owner; + return this; + } + + /*package*/ static GHTeam[] wrapUp(GHTeam[] teams, GHOrganization owner) { + for (GHTeam t : teams) { + t.wrapUp(owner); + } + return teams; + } + public String getName() { return name; } @@ -31,7 +45,7 @@ public int getId() { * Retrieves the current members. */ public Set getMembers() throws IOException { - return org.root.retrieveWithAuth(api("/members"),JsonUsersWithDetails.class).toSet(org.root); + return new HashSet(Arrays.asList(GHUser.wrap(org.root.retrieveWithAuth3(api("/members"),GHUser[].class),org.root))); } public Map getRepositories() throws IOException { @@ -42,22 +56,22 @@ public Map getRepositories() throws IOException { * Adds a member to the team. */ public void add(GHUser u) throws IOException { - org.root.retrieveWithAuth(api("/members?name="+u.getLogin()),null, "POST"); + org.root.retrieveWithAuth3(api("/members/"+u.getLogin()),null, "PUT"); } /** * Removes a member to the team. */ public void remove(GHUser u) throws IOException { - org.root.retrieveWithAuth(api("/members?name="+u.getLogin()),null, "DELETE"); + org.root.retrieveWithAuth3(api("/members/"+u.getLogin()),null, "DELETE"); } public void add(GHRepository r) throws IOException { - org.root.retrieveWithAuth(api("/repositories?name="+r.getOwnerName()+'/'+r.getName()),null, "POST"); + org.root.retrieveWithAuth3(api("/repos/"+r.getOwnerName()+'/'+r.getName()),null, "PUT"); } public void remove(GHRepository r) throws IOException { - org.root.retrieveWithAuth(api("/repositories?name="+r.getOwnerName()+'/'+r.getName()),null, "DELETE"); + org.root.retrieveWithAuth3(api("/repos/"+r.getOwnerName()+'/'+r.getName()),null, "DELETE"); } private String api(String tail) { diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java index fbf36c0e6d..ae1e235945 100644 --- a/src/main/java/org/kohsuke/github/GHUser.java +++ b/src/main/java/org/kohsuke/github/GHUser.java @@ -27,10 +27,13 @@ import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import java.io.IOException; +import java.util.Arrays; import java.util.HashSet; import java.util.Map; import java.util.Set; +import static org.kohsuke.github.ApiVersion.V3; + /** * Represents an user of GitHub. * @@ -42,14 +45,14 @@ public class GHUser extends GHPerson { * Follow this user. */ public void follow() throws IOException { - new Poster(root).withCredential().to("/user/follow/"+login); + new Poster(root, V3).withCredential().to("/user/following/"+login,null,"PUT"); } /** * Unfollow this user. */ public void unfollow() throws IOException { - new Poster(root).withCredential().to("/user/unfollow/"+login); + new Poster(root,V3).withCredential().to("/user/following/"+login,null,"DELETE"); } /** @@ -57,7 +60,8 @@ public void unfollow() throws IOException { */ @WithBridgeMethods(Set.class) public GHPersonSet getFollows() throws IOException { - return root.retrieve("/user/show/"+login+"/following",JsonUsers.class).toSet(root); + GHUser[] followers = root.retrieve3("/users/" + login + "/following", GHUser[].class); + return new GHPersonSet(Arrays.asList(wrap(followers,root))); } /** @@ -65,7 +69,14 @@ public GHPersonSet getFollows() throws IOException { */ @WithBridgeMethods(Set.class) public GHPersonSet getFollowers() throws IOException { - return root.retrieve("/user/show/"+login+"/followers",JsonUsers.class).toSet(root); + GHUser[] followers = root.retrieve3("/users/" + login + "/followers", GHUser[].class); + return new GHPersonSet(Arrays.asList(wrap(followers,root))); + } + + /*package*/ static GHUser[] wrap(GHUser[] users, GitHub root) { + for (GHUser f : users) + f.root = root; + return users; } /** diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index faf1ddc66e..4fdee1cbba 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -25,7 +25,6 @@ import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.ANY; import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE; -import static org.kohsuke.github.ApiVersion.V2; import static org.kohsuke.github.ApiVersion.V3; import java.io.File; @@ -165,26 +164,14 @@ public static GitHub connectAnonymously() { return new URL(v.getApiVersionBaseUrl(githubServer)+tailApiUrl); } - /*package*/ T retrieve(String tailApiUrl, Class type) throws IOException { - return _retrieve(tailApiUrl, type, "GET", false, V2); - } - /*package*/ T retrieve3(String tailApiUrl, Class type) throws IOException { return _retrieve(tailApiUrl, type, "GET", false, V3); } - /*package*/ T retrieveWithAuth(String tailApiUrl, Class type) throws IOException { - return retrieveWithAuth(tailApiUrl, type, "GET"); - } - /*package*/ T retrieveWithAuth3(String tailApiUrl, Class type) throws IOException { return _retrieve(tailApiUrl, type, "GET", true, V3); } - /*package*/ T retrieveWithAuth(String tailApiUrl, Class type, String method) throws IOException { - return _retrieve(tailApiUrl, type, method, true, V2); - } - /*package*/ T retrieveWithAuth3(String tailApiUrl, Class type, String method) throws IOException { return _retrieve(tailApiUrl, type, method, true, V3); } @@ -409,8 +396,7 @@ protected GHUser getUser(GHUser orig) throws IOException { public GHOrganization getOrganization(String name) throws IOException { GHOrganization o = orgs.get(name); if (o==null) { - o = retrieve("/organizations/"+name,JsonOrganization.class).organization; - o.root = this; + o = retrieve3("/orgs/"+name,GHOrganization.class).wrapUp(this); orgs.put(name,o); } return o; @@ -427,7 +413,12 @@ public GHRepository getRepository(String name) throws IOException { } public Map getMyOrganizations() throws IOException { - return retrieveWithAuth("/organizations",JsonOrganizations.class).wrap(this); + GHOrganization[] orgs = retrieveWithAuth3("/user/orgs", GHOrganization[].class); + Map r = new HashMap(); + for (GHOrganization o : orgs) { + r.put(o.name,o.wrapUp(this)); + } + return r; } /** diff --git a/src/main/java/org/kohsuke/github/Poster.java b/src/main/java/org/kohsuke/github/Poster.java index c07b5ddad3..b13a0509cb 100644 --- a/src/main/java/org/kohsuke/github/Poster.java +++ b/src/main/java/org/kohsuke/github/Poster.java @@ -38,6 +38,7 @@ import java.net.ProtocolException; import java.net.URLEncoder; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -63,10 +64,6 @@ private Entry(String key, Object value) { this.key = key; this.value = value; } - - public String toFormArg() throws UnsupportedEncodingException { - return URLEncoder.encode(key,"UTF-8")+'='+URLEncoder.encode(value.toString(),"UTF-8"); - } } Poster(GitHub root, ApiVersion v) { @@ -74,10 +71,6 @@ public String toFormArg() throws UnsupportedEncodingException { this.v = v; } - Poster(GitHub root) { - this(root,ApiVersion.V2); - } - public Poster withCredential() { root.requireCredential(); authenticate = true; @@ -102,6 +95,10 @@ public Poster with(String key, String value) { return _with(key, value); } + public Poster with(String key, Collection value) { + return _with(key, value); + } + public Poster _with(String key, Object value) { if (value!=null) { args.add(new Entry(key,value)); @@ -158,23 +155,11 @@ public T to(String tailApiUrl, Class type, String method) throws IOExcept } - if (v==ApiVersion.V2) { - StringBuilder body = new StringBuilder(); - for (Entry e : args) { - if (body.length()>0) body.append('&'); - body.append(e.toFormArg()); - } - - OutputStreamWriter o = new OutputStreamWriter(uc.getOutputStream(), "UTF-8"); - o.write(body.toString()); - o.close(); - } else { - Map json = new HashMap(); - for (Entry e : args) { - json.put(e.key, e.value); - } - MAPPER.writeValue(uc.getOutputStream(),json); + Map json = new HashMap(); + for (Entry e : args) { + json.put(e.key, e.value); } + MAPPER.writeValue(uc.getOutputStream(),json); try { InputStreamReader r = new InputStreamReader(uc.getInputStream(), "UTF-8"); From 5525ae8921499dcf0e216b46b3c1f5aaeae727a4 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 12 Jun 2012 14:16:59 -0700 Subject: [PATCH 3/7] Removed unused JSON databinding classes --- src/main/java/org/kohsuke/github/GHTeam.java | 18 +++++--- .../java/org/kohsuke/github/JsonBranch.java | 36 --------------- .../java/org/kohsuke/github/JsonBranches.java | 40 ----------------- .../org/kohsuke/github/JsonCollaborators.java | 33 -------------- .../java/org/kohsuke/github/JsonIssue.java | 38 ---------------- .../org/kohsuke/github/JsonIssueComments.java | 16 ------- .../java/org/kohsuke/github/JsonIssues.java | 38 ---------------- .../java/org/kohsuke/github/JsonMyself.java | 8 ---- .../org/kohsuke/github/JsonOrganization.java | 8 ---- .../org/kohsuke/github/JsonOrganizations.java | 44 ------------------- .../org/kohsuke/github/JsonRepositories.java | 44 ------------------- .../java/org/kohsuke/github/JsonTeam.java | 13 ------ .../java/org/kohsuke/github/JsonTeams.java | 32 -------------- .../java/org/kohsuke/github/JsonUsers.java | 43 ------------------ .../kohsuke/github/JsonUsersWithDetails.java | 20 --------- 15 files changed, 12 insertions(+), 419 deletions(-) delete mode 100644 src/main/java/org/kohsuke/github/JsonBranch.java delete mode 100644 src/main/java/org/kohsuke/github/JsonBranches.java delete mode 100644 src/main/java/org/kohsuke/github/JsonCollaborators.java delete mode 100644 src/main/java/org/kohsuke/github/JsonIssue.java delete mode 100644 src/main/java/org/kohsuke/github/JsonIssueComments.java delete mode 100644 src/main/java/org/kohsuke/github/JsonIssues.java delete mode 100644 src/main/java/org/kohsuke/github/JsonMyself.java delete mode 100644 src/main/java/org/kohsuke/github/JsonOrganization.java delete mode 100644 src/main/java/org/kohsuke/github/JsonOrganizations.java delete mode 100644 src/main/java/org/kohsuke/github/JsonRepositories.java delete mode 100644 src/main/java/org/kohsuke/github/JsonTeam.java delete mode 100644 src/main/java/org/kohsuke/github/JsonTeams.java delete mode 100644 src/main/java/org/kohsuke/github/JsonUsers.java delete mode 100644 src/main/java/org/kohsuke/github/JsonUsersWithDetails.java diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index 037287911a..8942cdf6ab 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -5,6 +5,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.TreeMap; /** * A team in GitHub organization. @@ -45,33 +46,38 @@ public int getId() { * Retrieves the current members. */ public Set getMembers() throws IOException { - return new HashSet(Arrays.asList(GHUser.wrap(org.root.retrieveWithAuth3(api("/members"),GHUser[].class),org.root))); + return new HashSet(Arrays.asList(GHUser.wrap(org.root.retrieveWithAuth3(api("/members"), GHUser[].class), org.root))); } public Map getRepositories() throws IOException { - return org.root.retrieveWithAuth3(api("/repos"),JsonRepositories.class).wrap(org.root); + GHRepository[] repos = org.root.retrieveWithAuth3(api("/repos"), GHRepository[].class); + Map m = new TreeMap(); + for (GHRepository r : repos) { + m.put(r.getName(),r.wrap(org.root)); + } + return m; } /** * Adds a member to the team. */ public void add(GHUser u) throws IOException { - org.root.retrieveWithAuth3(api("/members/"+u.getLogin()),null, "PUT"); + org.root.retrieveWithAuth3(api("/members/" + u.getLogin()), null, "PUT"); } /** * Removes a member to the team. */ public void remove(GHUser u) throws IOException { - org.root.retrieveWithAuth3(api("/members/"+u.getLogin()),null, "DELETE"); + org.root.retrieveWithAuth3(api("/members/" + u.getLogin()), null, "DELETE"); } public void add(GHRepository r) throws IOException { - org.root.retrieveWithAuth3(api("/repos/"+r.getOwnerName()+'/'+r.getName()),null, "PUT"); + org.root.retrieveWithAuth3(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null, "PUT"); } public void remove(GHRepository r) throws IOException { - org.root.retrieveWithAuth3(api("/repos/"+r.getOwnerName()+'/'+r.getName()),null, "DELETE"); + org.root.retrieveWithAuth3(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null, "DELETE"); } private String api(String tail) { diff --git a/src/main/java/org/kohsuke/github/JsonBranch.java b/src/main/java/org/kohsuke/github/JsonBranch.java deleted file mode 100644 index dd4678ec72..0000000000 --- a/src/main/java/org/kohsuke/github/JsonBranch.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2011, Eric Maupin - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package org.kohsuke.github; - -/** - * @author Eric Maupin - */ -class JsonBranch { - GHBranch branch; - - GHBranch wrap(GHRepository r) { - return branch.wrap(r); - } -} diff --git a/src/main/java/org/kohsuke/github/JsonBranches.java b/src/main/java/org/kohsuke/github/JsonBranches.java deleted file mode 100644 index 57a06bce37..0000000000 --- a/src/main/java/org/kohsuke/github/JsonBranches.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2011, Eric Maupin - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package org.kohsuke.github; - -import java.util.List; - -/** - * @author Eric Maupin - */ -class JsonBranches { - List branches; - - public List wrap(GHRepository owner) { - for (GHBranch branch : branches) - branch.wrap(owner); - return branches; - } -} \ No newline at end of file diff --git a/src/main/java/org/kohsuke/github/JsonCollaborators.java b/src/main/java/org/kohsuke/github/JsonCollaborators.java deleted file mode 100644 index 3d21c77ad2..0000000000 --- a/src/main/java/org/kohsuke/github/JsonCollaborators.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010, Kohsuke Kawaguchi - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.kohsuke.github; - -import java.util.List; - -/** - * @author Kohsuke Kawaguchi - */ -class JsonCollaborators { - List collaborators; -} diff --git a/src/main/java/org/kohsuke/github/JsonIssue.java b/src/main/java/org/kohsuke/github/JsonIssue.java deleted file mode 100644 index 330b4a6ce1..0000000000 --- a/src/main/java/org/kohsuke/github/JsonIssue.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2011, Eric Maupin - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package org.kohsuke.github; - -/** - * @author Eric Maupin - */ -class JsonIssue { - GHIssue issue; - - GHIssue wrap(GHRepository r) { - issue.owner = r; - issue.root = r.root; - return issue; - } -} \ No newline at end of file diff --git a/src/main/java/org/kohsuke/github/JsonIssueComments.java b/src/main/java/org/kohsuke/github/JsonIssueComments.java deleted file mode 100644 index f982708e23..0000000000 --- a/src/main/java/org/kohsuke/github/JsonIssueComments.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.kohsuke.github; - -import java.util.List; - -/** - * @author Kohsuke Kawaguchi - */ -class JsonIssueComments { - List comments; - - List wrap(GHIssue owner) { - for (GHIssueComment c : comments) - c.owner = owner; - return comments; - } -} diff --git a/src/main/java/org/kohsuke/github/JsonIssues.java b/src/main/java/org/kohsuke/github/JsonIssues.java deleted file mode 100644 index 783745f2bd..0000000000 --- a/src/main/java/org/kohsuke/github/JsonIssues.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2011, Eric Maupin - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.kohsuke.github; - -import java.util.List; - -class JsonIssues { - List issues; - - public List wrap(GHRepository owner) { - for (GHIssue issue : issues) { - issue.owner = owner; - issue.root = owner.root; - } - return issues; - } -} diff --git a/src/main/java/org/kohsuke/github/JsonMyself.java b/src/main/java/org/kohsuke/github/JsonMyself.java deleted file mode 100644 index 419d840d49..0000000000 --- a/src/main/java/org/kohsuke/github/JsonMyself.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.kohsuke.github; - -/** - * @author Kohsuke Kawaguchi - */ -class JsonMyself { - GHMyself user; -} diff --git a/src/main/java/org/kohsuke/github/JsonOrganization.java b/src/main/java/org/kohsuke/github/JsonOrganization.java deleted file mode 100644 index 02c7479b84..0000000000 --- a/src/main/java/org/kohsuke/github/JsonOrganization.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.kohsuke.github; - -/** - * @author Kohsuke Kawaguchi - */ -class JsonOrganization { - public GHOrganization organization; -} diff --git a/src/main/java/org/kohsuke/github/JsonOrganizations.java b/src/main/java/org/kohsuke/github/JsonOrganizations.java deleted file mode 100644 index 620e5e68d2..0000000000 --- a/src/main/java/org/kohsuke/github/JsonOrganizations.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010, Kohsuke Kawaguchi - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.kohsuke.github; - -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -/** - * - */ -class JsonOrganizations { - public List organizations; - - public Map wrap(GitHub root) { - Map map = new TreeMap(); - for (GHOrganization o : organizations) { - o.root = root; - map.put(o.getLogin(),o); - } - return map; - } -} diff --git a/src/main/java/org/kohsuke/github/JsonRepositories.java b/src/main/java/org/kohsuke/github/JsonRepositories.java deleted file mode 100644 index 69e0b138c7..0000000000 --- a/src/main/java/org/kohsuke/github/JsonRepositories.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010, Kohsuke Kawaguchi - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.kohsuke.github; - -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -/** - * @author Kohsuke Kawaguchi - */ -class JsonRepositories { - public List repositories; - - public Map wrap(GitHub root) { - Map map = new TreeMap(); - for (GHRepository r : repositories) { - r.root = root; - map.put(r.getName(),r); - } - return map; - } -} diff --git a/src/main/java/org/kohsuke/github/JsonTeam.java b/src/main/java/org/kohsuke/github/JsonTeam.java deleted file mode 100644 index 4949d845c2..0000000000 --- a/src/main/java/org/kohsuke/github/JsonTeam.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.kohsuke.github; - -/** - * @author Kohsuke Kawaguchi - */ -class JsonTeam { - public GHTeam team; - - GHTeam wrap(GHOrganization org) { - team.org = org; - return team; - } -} diff --git a/src/main/java/org/kohsuke/github/JsonTeams.java b/src/main/java/org/kohsuke/github/JsonTeams.java deleted file mode 100644 index 85c6664ead..0000000000 --- a/src/main/java/org/kohsuke/github/JsonTeams.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.kohsuke.github; - -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; - -/** - * @author Kohsuke Kawaguchi - */ -class JsonTeams { - public List teams; - - Map toMap(GHOrganization org) { - Map r = new TreeMap(); - for (GHTeam t : teams) { - t.org = org; - r.put(t.getName(),t); - } - return r; - } - - Set toSet(GHOrganization org) { - Set r = new HashSet(); - for (GHTeam t : teams) { - t.org = org; - r.add(t); - } - return r; - } -} diff --git a/src/main/java/org/kohsuke/github/JsonUsers.java b/src/main/java/org/kohsuke/github/JsonUsers.java deleted file mode 100644 index 60c123e0e3..0000000000 --- a/src/main/java/org/kohsuke/github/JsonUsers.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010, Kohsuke Kawaguchi - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.kohsuke.github; - -import java.io.IOException; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * @author Kohsuke Kawaguchi - */ -class JsonUsers { - public List users; - - public GHPersonSet toSet(GitHub root) throws IOException { - GHPersonSet r = new GHPersonSet(); - for (String u : users) - r.add(root.getUser(u)); - return r; - } -} diff --git a/src/main/java/org/kohsuke/github/JsonUsersWithDetails.java b/src/main/java/org/kohsuke/github/JsonUsersWithDetails.java deleted file mode 100644 index 424e53c9da..0000000000 --- a/src/main/java/org/kohsuke/github/JsonUsersWithDetails.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.kohsuke.github; - -import java.io.IOException; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * @author Kohsuke Kawaguchi - */ -class JsonUsersWithDetails { - public List users; - - public Set toSet(GitHub root) throws IOException { - Set r = new HashSet(); - for (GHUser u : users) - r.add(root.getUser(u)); - return r; - } -} From 82acf4f1074e1106b4ae1df99cd3b23def17c645 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 12 Jun 2012 14:20:52 -0700 Subject: [PATCH 4/7] Now that everything is V3 API, there's no need for such enum. --- .../java/org/kohsuke/github/ApiVersion.java | 23 ----------------- .../java/org/kohsuke/github/GHCommit.java | 6 ++--- .../org/kohsuke/github/GHCommitComment.java | 6 ++--- src/main/java/org/kohsuke/github/GHHook.java | 2 +- src/main/java/org/kohsuke/github/GHIssue.java | 6 ++--- .../org/kohsuke/github/GHOrganization.java | 6 ++--- .../java/org/kohsuke/github/GHPerson.java | 6 +---- .../java/org/kohsuke/github/GHRepository.java | 17 ++++++------- src/main/java/org/kohsuke/github/GHUser.java | 8 ++---- src/main/java/org/kohsuke/github/GitHub.java | 22 ++++++++-------- src/main/java/org/kohsuke/github/Poster.java | 25 +++++-------------- 11 files changed, 36 insertions(+), 91 deletions(-) delete mode 100644 src/main/java/org/kohsuke/github/ApiVersion.java diff --git a/src/main/java/org/kohsuke/github/ApiVersion.java b/src/main/java/org/kohsuke/github/ApiVersion.java deleted file mode 100644 index 9ce1683d25..0000000000 --- a/src/main/java/org/kohsuke/github/ApiVersion.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.kohsuke.github; - -/** - * Different API versions. - * - * @author Kohsuke Kawaguchi - */ -enum ApiVersion { - - V3("https://api.?"); - - final String templateUrl; - - ApiVersion(String templateUrl) { - this.templateUrl = templateUrl; - } - - public String getApiVersionBaseUrl(String githubServer) { - - return templateUrl.replaceFirst("\\?", githubServer); - - } -} diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index 9ba4ca2bd8..3cf7f1437c 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -7,8 +7,6 @@ import java.util.Collections; import java.util.List; -import static org.kohsuke.github.ApiVersion.V3; - /** * A commit in a repository. * @@ -205,7 +203,7 @@ private GHUser resolveUser(User author) throws IOException { public PagedIterable listComments() { return new PagedIterable() { public PagedIterator iterator() { - return new PagedIterator(owner.root.retrievePaged(String.format("/repos/%s/%s/commits/%s/comments",owner.getOwnerName(),owner.getName(),sha),GHCommitComment[].class,false,V3)) { + return new PagedIterator(owner.root.retrievePaged(String.format("/repos/%s/%s/commits/%s/comments",owner.getOwnerName(),owner.getName(),sha),GHCommitComment[].class,false)) { @Override protected void wrapUp(GHCommitComment[] page) { for (GHCommitComment c : page) @@ -222,7 +220,7 @@ protected void wrapUp(GHCommitComment[] page) { * I'm not sure how path/line/position parameters interact with each other. */ public GHCommitComment createComment(String body, String path, Integer line, Integer position) throws IOException { - GHCommitComment r = new Poster(owner.root,V3) + GHCommitComment r = new Poster(owner.root) .with("body",body) .with("path",path) .with("line",line) diff --git a/src/main/java/org/kohsuke/github/GHCommitComment.java b/src/main/java/org/kohsuke/github/GHCommitComment.java index c2364a23d5..f4621c2b01 100644 --- a/src/main/java/org/kohsuke/github/GHCommitComment.java +++ b/src/main/java/org/kohsuke/github/GHCommitComment.java @@ -4,8 +4,6 @@ import java.net.URL; import java.util.Date; -import static org.kohsuke.github.ApiVersion.V3; - /** * A comment attached to a commit (or a specific line in a specific file of a commit.) * @@ -99,7 +97,7 @@ public GHCommit getCommit() throws IOException { * Updates the body of the commit message. */ public void update(String body) throws IOException { - GHCommitComment r = new Poster(owner.root,V3) + GHCommitComment r = new Poster(owner.root) .with("body",body) .withCredential() .to(getApiTail(),GHCommitComment.class,"PATCH"); @@ -110,7 +108,7 @@ public void update(String body) throws IOException { * Deletes this comment. */ public void delete() throws IOException { - new Poster(owner.root,V3).withCredential().to(getApiTail(),null,"DELETE"); + new Poster(owner.root).withCredential().to(getApiTail(),null,"DELETE"); } private String getApiTail() { diff --git a/src/main/java/org/kohsuke/github/GHHook.java b/src/main/java/org/kohsuke/github/GHHook.java index b539cc1dd7..94144e6f07 100644 --- a/src/main/java/org/kohsuke/github/GHHook.java +++ b/src/main/java/org/kohsuke/github/GHHook.java @@ -54,7 +54,7 @@ public int getId() { * Deletes this hook. */ public void delete() throws IOException { - new Poster(repository.root,ApiVersion.V3).withCredential() + new Poster(repository.root).withCredential() .to(String.format("/repos/%s/%s/hooks/%d",repository.getOwnerName(),repository.getName(),id),null,"DELETE"); } } diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index 475a5f7ba2..5037a8dea8 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -32,8 +32,6 @@ import java.util.Date; import java.util.List; -import static org.kohsuke.github.ApiVersion.V3; - /** * Represents an issue on GitHub. * @@ -114,11 +112,11 @@ public Date getUpdatedAt() { * Updates the issue by adding a comment. */ public void comment(String message) throws IOException { - new Poster(root, V3).withCredential().with("body",message).to(getApiRoute()+"/comments",null,"POST"); + new Poster(root).withCredential().with("body",message).to(getApiRoute()+"/comments",null,"POST"); } private void edit(String key, Object value) throws IOException { - new Poster(root,V3).withCredential()._with(key, value) + new Poster(root).withCredential()._with(key, value) .to(getApiRoute(),null,"PATCH"); } diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index 9b2696a873..f7c2b2d496 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -13,8 +13,6 @@ import java.util.Map; import java.util.TreeMap; -import static org.kohsuke.github.ApiVersion.*; - /** * @author Kohsuke Kawaguchi */ @@ -35,7 +33,7 @@ public GHRepository createRepository(String name, String description, String hom public GHRepository createRepository(String name, String description, String homepage, GHTeam team, boolean isPublic) throws IOException { // such API doesn't exist, so fall back to HTML scraping - return new Poster(root,V3).withCredential() + return new Poster(root).withCredential() .with("name", name).with("description", description).with("homepage", homepage) .with("public", isPublic).with("team_id",team.getId()).to("/orgs/"+login+"/repos", GHRepository.class).wrap(root); } @@ -97,7 +95,7 @@ public enum Permission { ADMIN, PUSH, PULL } * Creates a new team and assigns the repositories. */ public GHTeam createTeam(String name, Permission p, Collection repositories) throws IOException { - Poster post = new Poster(root,V3).withCredential().with("name", name).with("permission", p.name().toLowerCase()); + Poster post = new Poster(root).withCredential().with("name", name).with("permission", p.name().toLowerCase()); List repo_names = new ArrayList(); for (GHRepository r : repositories) { repo_names.add(r.getName()); diff --git a/src/main/java/org/kohsuke/github/GHPerson.java b/src/main/java/org/kohsuke/github/GHPerson.java index 3aaa45ba08..5213db8a1d 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -1,7 +1,5 @@ package org.kohsuke.github; -import com.infradna.tool.bridge_method_injector.WithBridgeMethods; - import java.io.FileNotFoundException; import java.io.IOException; import java.util.Arrays; @@ -11,8 +9,6 @@ import java.util.Map; import java.util.TreeMap; -import static org.kohsuke.github.ApiVersion.*; - /** * Common part of {@link GHUser} and {@link GHOrganization}. * @@ -63,7 +59,7 @@ public synchronized Map getRepositories() throws IOExceptio public synchronized Iterable> iterateRepositories(final int pageSize) { return new Iterable>() { public Iterator> iterator() { - final Iterator pager = root.retrievePaged("/users/" + login + "/repos?per_page="+pageSize,GHRepository[].class,false, V3); + final Iterator pager = root.retrievePaged("/users/" + login + "/repos?per_page="+pageSize,GHRepository[].class,false); return new Iterator>() { public boolean hasNext() { diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 87ce6bb95b..420d8923de 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -49,7 +49,6 @@ import java.util.TreeMap; import static java.util.Arrays.*; -import static org.kohsuke.github.ApiVersion.V3; /** * A repository on GitHub. @@ -253,7 +252,7 @@ public void removeCollaborators(Collection users) throws IOException { private void modifyCollaborators(Collection users, String method) throws IOException { verifyMine(); for (GHUser user : users) { - new Poster(root,V3).withCredential().to("/repos/"+owner.login+"/"+name+"/collaborators/"+user.getLogin(),null,method); + new Poster(root).withCredential().to("/repos/"+owner.login+"/"+name+"/collaborators/"+user.getLogin(),null,method); } } @@ -270,7 +269,7 @@ public void setEmailServiceHook(String address) throws IOException { } private void edit(String key, String value) throws IOException { - new Poster(root,V3).withCredential().with(key,value) + new Poster(root).withCredential().with(key,value) .to("/repos/" + owner.login + "/" + name,null,"PATCH"); } @@ -326,7 +325,7 @@ public void delete() throws IOException { * Newly forked repository that belong to you. */ public GHRepository fork() throws IOException { - return new Poster(root,V3).withCredential().to("/repos/" + owner.login + "/" + name + "/forks", GHRepository.class, "POST").wrap(root); + return new Poster(root).withCredential().to("/repos/" + owner.login + "/" + name + "/forks", GHRepository.class, "POST").wrap(root); } /** @@ -336,7 +335,7 @@ public GHRepository fork() throws IOException { * Newly forked repository that belong to you. */ public GHRepository forkTo(GHOrganization org) throws IOException { - new Poster(root, V3).withCredential().to(String.format("/repos/%s/%s/forks?org=%s",owner.login,name,org.getLogin())); + new Poster(root).withCredential().to(String.format("/repos/%s/%s/forks?org=%s",owner.login,name,org.getLogin())); return org.getRepository(name); } @@ -390,7 +389,7 @@ public GHCommit getCommit(String sha1) throws IOException { public PagedIterable listCommits() { return new PagedIterable() { public PagedIterator iterator() { - return new PagedIterator(root.retrievePaged(String.format("/repos/%s/%s/commits",owner.login,name),GHCommit[].class,false,V3)) { + return new PagedIterator(root.retrievePaged(String.format("/repos/%s/%s/commits",owner.login,name),GHCommit[].class,false)) { protected void wrapUp(GHCommit[] page) { for (GHCommit c : page) c.wrapUp(GHRepository.this); @@ -406,7 +405,7 @@ protected void wrapUp(GHCommit[] page) { public PagedIterable listCommitComments() { return new PagedIterable() { public PagedIterator iterator() { - return new PagedIterator(root.retrievePaged(String.format("/repos/%s/%s/comments",owner.login,name),GHCommitComment[].class,false,V3)) { + return new PagedIterator(root.retrievePaged(String.format("/repos/%s/%s/comments",owner.login,name),GHCommitComment[].class,false)) { @Override protected void wrapUp(GHCommitComment[] page) { for (GHCommitComment c : page) @@ -437,7 +436,7 @@ public GHHook createHook(String name, Map config, Collection=0 ?'&':'?') + "access_token=" + oauthAccessToken; } - return new URL(v.getApiVersionBaseUrl(githubServer)+tailApiUrl); + return new URL("https://api."+githubServer+tailApiUrl); } /*package*/ T retrieve3(String tailApiUrl, Class type) throws IOException { - return _retrieve(tailApiUrl, type, "GET", false, V3); + return _retrieve(tailApiUrl, type, "GET", false); } /*package*/ T retrieveWithAuth3(String tailApiUrl, Class type) throws IOException { - return _retrieve(tailApiUrl, type, "GET", true, V3); + return _retrieve(tailApiUrl, type, "GET", true); } /*package*/ T retrieveWithAuth3(String tailApiUrl, Class type, String method) throws IOException { - return _retrieve(tailApiUrl, type, method, true, V3); + return _retrieve(tailApiUrl, type, method, true); } - private T _retrieve(String tailApiUrl, Class type, String method, boolean withAuth, ApiVersion v) throws IOException { + private T _retrieve(String tailApiUrl, Class type, String method, boolean withAuth) throws IOException { while (true) {// loop while API rate limit is hit - HttpURLConnection uc = setupConnection(method, withAuth, getApiURL(v, tailApiUrl)); + HttpURLConnection uc = setupConnection(method, withAuth, getApiURL(tailApiUrl)); try { return parse(uc,type); } catch (IOException e) { @@ -192,7 +190,7 @@ private T _retrieve(String tailApiUrl, Class type, String method, boolean * * Every iterator call reports a new batch. */ - /*package*/ Iterator retrievePaged(final String tailApiUrl, final Class type, final boolean withAuth, final ApiVersion v) { + /*package*/ Iterator retrievePaged(final String tailApiUrl, final Class type, final boolean withAuth) { return new Iterator() { /** * The next batch to be returned from {@link #next()}. @@ -205,7 +203,7 @@ private T _retrieve(String tailApiUrl, Class type, String method, boolean { try { - url = getApiURL(v, tailApiUrl); + url = getApiURL(tailApiUrl); } catch (IOException e) { throw new Error(e); } @@ -452,7 +450,7 @@ public T parseEventPayload(Reader r, Class type) t * Newly created repository. */ public GHRepository createRepository(String name, String description, String homepage, boolean isPublic) throws IOException { - return new Poster(this,V3).withCredential() + return new Poster(this).withCredential() .with("name", name).with("description", description).with("homepage", homepage) .with("public", isPublic ? 1 : 0).to("/user/repos", GHRepository.class,"POST").wrap(this); } diff --git a/src/main/java/org/kohsuke/github/Poster.java b/src/main/java/org/kohsuke/github/Poster.java index b13a0509cb..d18c054b62 100644 --- a/src/main/java/org/kohsuke/github/Poster.java +++ b/src/main/java/org/kohsuke/github/Poster.java @@ -24,19 +24,13 @@ package org.kohsuke.github; import org.apache.commons.io.IOUtils; -import org.codehaus.jackson.JsonNode; -import org.codehaus.jackson.impl.WriterBasedGenerator; -import org.codehaus.jackson.node.ObjectNode; import java.io.IOException; import java.io.InputStreamReader; -import java.io.OutputStreamWriter; import java.io.Reader; -import java.io.UnsupportedEncodingException; import java.lang.reflect.Field; import java.net.HttpURLConnection; import java.net.ProtocolException; -import java.net.URLEncoder; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -54,8 +48,6 @@ class Poster { private final List args = new ArrayList(); private boolean authenticate; - private final ApiVersion v; - private static class Entry { String key; Object value; @@ -66,9 +58,8 @@ private Entry(String key, Object value) { } } - Poster(GitHub root, ApiVersion v) { + Poster(GitHub root) { this.root = root; - this.v = v; } public Poster withCredential() { @@ -124,20 +115,16 @@ public T to(String tailApiUrl, Class type) throws IOException { public T to(String tailApiUrl, Class type, String method) throws IOException { while (true) {// loop while API rate limit is hit - HttpURLConnection uc = (HttpURLConnection) root.getApiURL(v,tailApiUrl).openConnection(); + HttpURLConnection uc = (HttpURLConnection) root.getApiURL(tailApiUrl).openConnection(); uc.setDoOutput(true); uc.setRequestProperty("Content-type","application/x-www-form-urlencoded"); if (authenticate) { - if (v==ApiVersion.V3) { - if (root.oauthAccessToken!=null) { - uc.setRequestProperty("Authorization", "token " + root.oauthAccessToken); - } else { - if (root.password==null) - throw new IllegalArgumentException("V3 API doesn't support API token"); - uc.setRequestProperty("Authorization", "Basic " + root.encodedAuthorization); - } + if (root.oauthAccessToken!=null) { + uc.setRequestProperty("Authorization", "token " + root.oauthAccessToken); } else { + if (root.password==null) + throw new IllegalArgumentException("V3 API doesn't support API token"); uc.setRequestProperty("Authorization", "Basic " + root.encodedAuthorization); } } From 1c15751949553deaad347abd4e1c0775bc3b7ac7 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 12 Jun 2012 14:21:43 -0700 Subject: [PATCH 5/7] Removing pointless '3' suffix in the method names. --- src/main/java/org/kohsuke/github/GHIssue.java | 2 +- .../java/org/kohsuke/github/GHMyself.java | 5 ++-- .../org/kohsuke/github/GHOrganization.java | 8 +++---- .../java/org/kohsuke/github/GHPerson.java | 2 +- .../java/org/kohsuke/github/GHRepository.java | 24 +++++++++---------- src/main/java/org/kohsuke/github/GHTeam.java | 12 +++++----- src/main/java/org/kohsuke/github/GHUser.java | 6 ++--- src/main/java/org/kohsuke/github/GitHub.java | 20 ++++++++-------- 8 files changed, 39 insertions(+), 40 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index 5037a8dea8..961f27edca 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -154,7 +154,7 @@ public void setLabels(String... labels) throws IOException { * Obtains all the comments associated with this issue. */ public List getComments() throws IOException { - GHIssueComment[] r = root.retrieve3(getApiRoute()+"/comments", GHIssueComment[].class); + GHIssueComment[] r = root.retrieve(getApiRoute() + "/comments", GHIssueComment[].class); for (GHIssueComment c : r) c.wrapUp(this); return Arrays.asList(r); diff --git a/src/main/java/org/kohsuke/github/GHMyself.java b/src/main/java/org/kohsuke/github/GHMyself.java index 0214b2056d..ddceccd70f 100644 --- a/src/main/java/org/kohsuke/github/GHMyself.java +++ b/src/main/java/org/kohsuke/github/GHMyself.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.List; @@ -23,7 +22,7 @@ public class GHMyself extends GHUser { * Always non-null. */ public List getEmails() throws IOException { - String[] addresses = root.retrieveWithAuth3("/user/emails",String[].class); + String[] addresses = root.retrieveWithAuth("/user/emails", String[].class); return Collections.unmodifiableList(Arrays.asList(addresses)); } @@ -34,7 +33,7 @@ public List getEmails() throws IOException { * Always non-null. */ public List getPublicKeys() throws IOException { - return Collections.unmodifiableList(Arrays.asList(root.retrieveWithAuth3("/user/keys",GHKey[].class))); + return Collections.unmodifiableList(Arrays.asList(root.retrieveWithAuth("/user/keys", GHKey[].class))); } // public void addEmails(Collection emails) throws IOException { diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index f7c2b2d496..d2c124d4ec 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -42,7 +42,7 @@ public GHRepository createRepository(String name, String description, String hom * Teams by their names. */ public Map getTeams() throws IOException { - GHTeam[] teams = root.retrieveWithAuth3("/orgs/" + login + "/teams", GHTeam[].class); + GHTeam[] teams = root.retrieveWithAuth("/orgs/" + login + "/teams", GHTeam[].class); Map r = new TreeMap(); for (GHTeam t : teams) { r.put(t.getName(),t); @@ -54,7 +54,7 @@ public Map getTeams() throws IOException { * Publicizes the membership. */ public void publicize(GHUser u) throws IOException { - root.retrieveWithAuth3("/orgs/" + login + "/public_members/" + u.getLogin(), null, "PUT"); + root.retrieveWithAuth("/orgs/" + login + "/public_members/" + u.getLogin(), null, "PUT"); } /** @@ -64,7 +64,7 @@ public List getMembers() throws IOException { return new AbstractList() { // these are shallow objects with only some limited values filled out // TODO: it's better to allow objects to fill themselves in later when missing values are requested - final GHUser[] shallow = root.retrieveWithAuth3("/orgs/" + login + "/members", GHUser[].class); + final GHUser[] shallow = root.retrieveWithAuth("/orgs/" + login + "/members", GHUser[].class); @Override public GHUser get(int index) { @@ -86,7 +86,7 @@ public int size() { * Conceals the membership. */ public void conceal(GHUser u) throws IOException { - root.retrieveWithAuth3("/orgs/" + login + "/public_members/" + u.getLogin(), null, "DELETE"); + root.retrieveWithAuth("/orgs/" + login + "/public_members/" + u.getLogin(), null, "DELETE"); } public enum Permission { ADMIN, PUSH, PULL } diff --git a/src/main/java/org/kohsuke/github/GHPerson.java b/src/main/java/org/kohsuke/github/GHPerson.java index 5213db8a1d..1a368d941e 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -88,7 +88,7 @@ public void remove() { */ public GHRepository getRepository(String name) throws IOException { try { - return root.retrieveWithAuth3("/repos/" + login + '/' + name, GHRepository.class).wrap(root); + return root.retrieveWithAuth("/repos/" + login + '/' + name, GHRepository.class).wrap(root); } catch (FileNotFoundException e) { return null; } diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 420d8923de..031a6d65bf 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -140,7 +140,7 @@ public GHUser getOwner() throws IOException { } public List getIssues(GHIssueState state) throws IOException { - return Arrays.asList(GHIssue.wrap(root.retrieve3("/repos/" + owner.login + "/" + name + "/issues?state=" + state.toString().toLowerCase(), GHIssue[].class), this)); + return Arrays.asList(GHIssue.wrap(root.retrieve("/repos/" + owner.login + "/" + name + "/issues?state=" + state.toString().toLowerCase(), GHIssue[].class), this)); } protected String getOwnerName() { @@ -212,7 +212,7 @@ public int getSize() { */ @WithBridgeMethods(Set.class) public GHPersonSet getCollaborators() throws IOException { - return new GHPersonSet(GHUser.wrap(root.retrieve3("/repos/"+owner.login+"/"+name+"/collaborators",GHUser[].class),root)); + return new GHPersonSet(GHUser.wrap(root.retrieve("/repos/" + owner.login + "/" + name + "/collaborators", GHUser[].class),root)); } /** @@ -221,7 +221,7 @@ public GHPersonSet getCollaborators() throws IOException { */ public Set getCollaboratorNames() throws IOException { Set r = new HashSet(); - for (GHUser u : GHUser.wrap(root.retrieve3("/repos/"+owner.login+"/"+name+"/collaborators",GHUser[].class),root)) + for (GHUser u : GHUser.wrap(root.retrieve("/repos/" + owner.login + "/" + name + "/collaborators", GHUser[].class),root)) r.add(u.login); return r; } @@ -230,7 +230,7 @@ public Set getCollaboratorNames() throws IOException { * If this repository belongs to an organization, return a set of teams. */ public Set getTeams() throws IOException { - return Collections.unmodifiableSet(new HashSet(Arrays.asList(GHTeam.wrapUp(root.retrieveWithAuth3("/repos/" + owner.login + "/" + name + "/teams", GHTeam[].class), root.getOrganization(owner.login))))); + return Collections.unmodifiableSet(new HashSet(Arrays.asList(GHTeam.wrapUp(root.retrieveWithAuth("/repos/" + owner.login + "/" + name + "/teams", GHTeam[].class), root.getOrganization(owner.login))))); } public void addCollaborators(GHUser... users) throws IOException { @@ -343,14 +343,14 @@ public GHRepository forkTo(GHOrganization org) throws IOException { * Retrieves a specified pull request. */ public GHPullRequest getPullRequest(int i) throws IOException { - return root.retrieveWithAuth3("/repos/" + owner.login + '/' + name + "/pulls/" + i, GHPullRequest.class).wrapUp(this); + return root.retrieveWithAuth("/repos/" + owner.login + '/' + name + "/pulls/" + i, GHPullRequest.class).wrapUp(this); } /** * Retrieves all the pull requests of a particular state. */ public List getPullRequests(GHIssueState state) throws IOException { - GHPullRequest[] r = root.retrieveWithAuth3("/repos/" + owner.login + '/' + name + "/pulls?state=" + state.name().toLowerCase(Locale.ENGLISH), GHPullRequest[].class); + GHPullRequest[] r = root.retrieveWithAuth("/repos/" + owner.login + '/' + name + "/pulls?state=" + state.name().toLowerCase(Locale.ENGLISH), GHPullRequest[].class); for (GHPullRequest p : r) p.wrapUp(this); return new ArrayList(Arrays.asList(r)); @@ -361,14 +361,14 @@ public List getPullRequests(GHIssueState state) throws IOExceptio */ public List getHooks() throws IOException { List list = new ArrayList(Arrays.asList( - root.retrieveWithAuth3(String.format("/repos/%s/%s/hooks",owner.login,name),GHHook[].class))); + root.retrieveWithAuth(String.format("/repos/%s/%s/hooks", owner.login, name), GHHook[].class))); for (GHHook h : list) h.wrap(this); return list; } public GHHook getHook(int id) throws IOException { - return root.retrieveWithAuth3(String.format("/repos/%s/%s/hooks/%d",owner.login,name,id),GHHook.class).wrap(this); + return root.retrieveWithAuth(String.format("/repos/%s/%s/hooks/%d", owner.login, name, id), GHHook.class).wrap(this); } /** @@ -377,7 +377,7 @@ public GHHook getHook(int id) throws IOException { public GHCommit getCommit(String sha1) throws IOException { GHCommit c = commits.get(sha1); if (c==null) { - c = root.retrieve3(String.format("/repos/%s/%s/commits/%s",owner.login,name,sha1),GHCommit.class).wrapUp(this); + c = root.retrieve(String.format("/repos/%s/%s/commits/%s", owner.login, name, sha1), GHCommit.class).wrapUp(this); commits.put(sha1,c); } return c; @@ -542,7 +542,7 @@ public boolean remove(Object url) { */ public Map getBranches() throws IOException { Map r = new TreeMap(); - for (GHBranch p : root.retrieve3("/repos/"+owner.login+"/"+name+"/branches", GHBranch[].class)) { + for (GHBranch p : root.retrieve("/repos/" + owner.login + "/" + name + "/branches", GHBranch[].class)) { p.wrap(this); r.put(p.getName(),p); } @@ -551,7 +551,7 @@ public Map getBranches() throws IOException { public Map getMilestones() throws IOException { Map milestones = new TreeMap(); - GHMilestone[] ms = root.retrieve3("/repos/"+owner.login+"/"+name+"/milestones", GHMilestone[].class); + GHMilestone[] ms = root.retrieve("/repos/" + owner.login + "/" + name + "/milestones", GHMilestone[].class); for (GHMilestone m : ms) { m.owner = this; m.root = root; @@ -563,7 +563,7 @@ public Map getMilestones() throws IOException { public GHMilestone getMilestone(int number) throws IOException { GHMilestone m = milestones.get(number); if (m == null) { - m = root.retrieve3("/repos/"+owner.login+"/"+name+"/milestones/"+number, GHMilestone.class); + m = root.retrieve("/repos/" + owner.login + "/" + name + "/milestones/" + number, GHMilestone.class); m.owner = this; m.root = root; milestones.put(m.getNumber(), m); diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index 8942cdf6ab..d4bf99d582 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -46,11 +46,11 @@ public int getId() { * Retrieves the current members. */ public Set getMembers() throws IOException { - return new HashSet(Arrays.asList(GHUser.wrap(org.root.retrieveWithAuth3(api("/members"), GHUser[].class), org.root))); + return new HashSet(Arrays.asList(GHUser.wrap(org.root.retrieveWithAuth(api("/members"), GHUser[].class), org.root))); } public Map getRepositories() throws IOException { - GHRepository[] repos = org.root.retrieveWithAuth3(api("/repos"), GHRepository[].class); + GHRepository[] repos = org.root.retrieveWithAuth(api("/repos"), GHRepository[].class); Map m = new TreeMap(); for (GHRepository r : repos) { m.put(r.getName(),r.wrap(org.root)); @@ -62,22 +62,22 @@ public Map getRepositories() throws IOException { * Adds a member to the team. */ public void add(GHUser u) throws IOException { - org.root.retrieveWithAuth3(api("/members/" + u.getLogin()), null, "PUT"); + org.root.retrieveWithAuth(api("/members/" + u.getLogin()), null, "PUT"); } /** * Removes a member to the team. */ public void remove(GHUser u) throws IOException { - org.root.retrieveWithAuth3(api("/members/" + u.getLogin()), null, "DELETE"); + org.root.retrieveWithAuth(api("/members/" + u.getLogin()), null, "DELETE"); } public void add(GHRepository r) throws IOException { - org.root.retrieveWithAuth3(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null, "PUT"); + org.root.retrieveWithAuth(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null, "PUT"); } public void remove(GHRepository r) throws IOException { - org.root.retrieveWithAuth3(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null, "DELETE"); + org.root.retrieveWithAuth(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null, "DELETE"); } private String api(String tail) { diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java index c3bbfc0a6c..07f44f71c4 100644 --- a/src/main/java/org/kohsuke/github/GHUser.java +++ b/src/main/java/org/kohsuke/github/GHUser.java @@ -56,7 +56,7 @@ public void unfollow() throws IOException { */ @WithBridgeMethods(Set.class) public GHPersonSet getFollows() throws IOException { - GHUser[] followers = root.retrieve3("/users/" + login + "/following", GHUser[].class); + GHUser[] followers = root.retrieve("/users/" + login + "/following", GHUser[].class); return new GHPersonSet(Arrays.asList(wrap(followers,root))); } @@ -65,7 +65,7 @@ public GHPersonSet getFollows() throws IOException { */ @WithBridgeMethods(Set.class) public GHPersonSet getFollowers() throws IOException { - GHUser[] followers = root.retrieve3("/users/" + login + "/followers", GHUser[].class); + GHUser[] followers = root.retrieve("/users/" + login + "/followers", GHUser[].class); return new GHPersonSet(Arrays.asList(wrap(followers,root))); } @@ -82,7 +82,7 @@ public GHPersonSet getFollowers() throws IOException { public GHPersonSet getOrganizations() throws IOException { GHPersonSet orgs = new GHPersonSet(); Set names = new HashSet(); - for (GHOrganization o : root.retrieve3("/users/"+login+"/orgs",GHOrganization[].class)) { + for (GHOrganization o : root.retrieve("/users/" + login + "/orgs", GHOrganization[].class)) { if (names.add(o.getLogin())) // I've seen some duplicates in the data orgs.add(root.getOrganization(o.getLogin())); } diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 18bb19f8b7..d6dabd4b51 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -162,15 +162,15 @@ public static GitHub connectAnonymously() { return new URL("https://api."+githubServer+tailApiUrl); } - /*package*/ T retrieve3(String tailApiUrl, Class type) throws IOException { + /*package*/ T retrieve(String tailApiUrl, Class type) throws IOException { return _retrieve(tailApiUrl, type, "GET", false); } - /*package*/ T retrieveWithAuth3(String tailApiUrl, Class type) throws IOException { + /*package*/ T retrieveWithAuth(String tailApiUrl, Class type) throws IOException { return _retrieve(tailApiUrl, type, "GET", true); } - /*package*/ T retrieveWithAuth3(String tailApiUrl, Class type, String method) throws IOException { + /*package*/ T retrieveWithAuth(String tailApiUrl, Class type, String method) throws IOException { return _retrieve(tailApiUrl, type, method, true); } @@ -347,7 +347,7 @@ private InputStream wrapStream(HttpURLConnection uc, InputStream in) throws IOEx * Gets the current rate limit. */ public GHRateLimit getRateLimit() throws IOException { - return retrieveWithAuth3("/rate_limit",JsonRateLimit.class).rate; + return retrieveWithAuth("/rate_limit", JsonRateLimit.class).rate; } /** @@ -357,7 +357,7 @@ public GHRateLimit getRateLimit() throws IOException { public GHMyself getMyself() throws IOException { requireCredential(); - GHMyself u = retrieveWithAuth3("/user", GHMyself.class); + GHMyself u = retrieveWithAuth("/user", GHMyself.class); u.root = this; users.put(u.getLogin(), u); @@ -371,7 +371,7 @@ public GHMyself getMyself() throws IOException { public GHUser getUser(String login) throws IOException { GHUser u = users.get(login); if (u == null) { - u = retrieve3("/users/" + login, GHUser.class); + u = retrieve("/users/" + login, GHUser.class); u.root = this; users.put(u.getLogin(), u); } @@ -394,7 +394,7 @@ protected GHUser getUser(GHUser orig) throws IOException { public GHOrganization getOrganization(String name) throws IOException { GHOrganization o = orgs.get(name); if (o==null) { - o = retrieve3("/orgs/"+name,GHOrganization.class).wrapUp(this); + o = retrieve("/orgs/" + name, GHOrganization.class).wrapUp(this); orgs.put(name,o); } return o; @@ -411,7 +411,7 @@ public GHRepository getRepository(String name) throws IOException { } public Map getMyOrganizations() throws IOException { - GHOrganization[] orgs = retrieveWithAuth3("/user/orgs", GHOrganization[].class); + GHOrganization[] orgs = retrieveWithAuth("/user/orgs", GHOrganization[].class); Map r = new HashMap(); for (GHOrganization o : orgs) { r.put(o.name,o.wrapUp(this)); @@ -424,7 +424,7 @@ public Map getMyOrganizations() throws IOException { */ public List getEvents() throws IOException { // TODO: pagenation - GHEventInfo[] events = retrieve3("/events", GHEventInfo[].class); + GHEventInfo[] events = retrieve("/events", GHEventInfo[].class); for (GHEventInfo e : events) e.wrapUp(this); return Arrays.asList(events); @@ -460,7 +460,7 @@ public GHRepository createRepository(String name, String description, String hom */ public boolean isCredentialValid() throws IOException { try { - retrieveWithAuth3("/user",GHUser.class); + retrieveWithAuth("/user", GHUser.class); return true; } catch (IOException e) { return false; From 4411650c5a79a3adca9104980c25ebd162825a57 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 12 Jun 2012 14:25:08 -0700 Subject: [PATCH 6/7] additional tweaks --- src/main/java/org/kohsuke/github/GitHub.java | 7 ++++++- src/test/java/org/kohsuke/AppTest.java | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index d6dabd4b51..18f9f596aa 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -82,7 +82,12 @@ public class GitHub { private GitHub(String login, String apiToken, String password) { this ("github.com", login, apiToken, password); } - + + /** + * + * @param githubServer + * The host name of the GitHub (or GitHub enterprise) server, such as "github.com". + */ private GitHub(String githubServer, String login, String apiToken, String password) { this.githubServer = githubServer; this.login = login; diff --git a/src/test/java/org/kohsuke/AppTest.java b/src/test/java/org/kohsuke/AppTest.java index 139e905e3b..4ab386a2bd 100644 --- a/src/test/java/org/kohsuke/AppTest.java +++ b/src/test/java/org/kohsuke/AppTest.java @@ -141,7 +141,7 @@ public void testCommitComment() throws Exception { } } - public void tryCreateCommitComment() throws Exception { + public void testCreateCommitComment() throws Exception { GitHub gitHub = GitHub.connect(); GHCommit commit = gitHub.getUser("kohsuke").getRepository("sandbox-ant").getCommit("8ae38db0ea5837313ab5f39d43a6f73de3bd9000"); GHCommitComment c = commit.createComment("[testing](http://kohsuse.org/)"); From 63dd1330e9a0d2b7a298892d04ef7ccff1c15811 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 12 Jun 2012 14:26:25 -0700 Subject: [PATCH 7/7] [maven-release-plugin] prepare release github-api-1.27 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2ac5dad891..7046e9360b 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.27-SNAPSHOT + 1.27 GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java