diff --git a/pom.xml b/pom.xml
index a57550ca7c..7046e9360b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
github-api
- 1.26
+ 1.27
GitHub API for Java
http://github-api.kohsuke.org/
GitHub API for 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 922dbe7aa1..0000000000
--- a/src/main/java/org/kohsuke/github/ApiVersion.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package org.kohsuke.github;
-
-/**
- * Different API versions.
- *
- * @author Kohsuke Kawaguchi
- */
-enum ApiVersion {
-
- V2("https://?/api/v2/json"),
- 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 842071b7eb..961f27edca 100644
--- a/src/main/java/org/kohsuke/github/GHIssue.java
+++ b/src/main/java/org/kohsuke/github/GHIssue.java
@@ -26,6 +26,7 @@
import java.io.IOException;
import java.net.URL;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
@@ -46,6 +47,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 +112,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).withCredential().with("body",message).to(getApiRoute()+"/comments",null,"POST");
+ }
+
+ private void edit(String key, Object value) throws IOException {
+ new Poster(root).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.retrieve(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/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 8af52fc0af..d2c124d4ec 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,13 +11,16 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
-
-import static org.kohsuke.github.ApiVersion.*;
+import java.util.TreeMap;
/**
* @author Kohsuke Kawaguchi
*/
public class GHOrganization extends GHPerson {
+ /*package*/ GHOrganization wrapUp(GitHub root) {
+ return (GHOrganization)super.wrapUp(root);
+ }
+
/**
* Creates a new repository.
*
@@ -31,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);
}
@@ -40,14 +42,19 @@ 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.retrieveWithAuth("/orgs/" + login + "/teams", GHTeam[].class);
+ Map r = new TreeMap();
+ for (GHTeam t : teams) {
+ r.put(t.getName(),t);
+ }
+ return r;
}
/**
* 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");
}
/**
@@ -57,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) {
@@ -79,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 }
@@ -88,11 +95,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).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..1a368d941e 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}.
*
@@ -33,6 +29,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.
*/
@@ -58,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() {
@@ -87,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/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 extends T> 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..031a6d65bf 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;
@@ -52,7 +49,6 @@
import java.util.TreeMap;
import static java.util.Arrays.*;
-import static org.kohsuke.github.ApiVersion.V3;
/**
* A repository on GitHub.
@@ -144,7 +140,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.retrieve("/repos/" + owner.login + "/" + name + "/issues?state=" + state.toString().toLowerCase(), GHIssue[].class), this));
}
protected String getOwnerName() {
@@ -216,10 +212,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.retrieve("/repos/" + owner.login + "/" + name + "/collaborators", GHUser[].class),root));
}
/**
@@ -227,16 +220,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.retrieve("/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.retrieveWithAuth("/repos/" + owner.login + "/" + name + "/teams", GHTeam[].class), root.getOrganization(owner.login)))));
}
public void addCollaborators(GHUser... users) throws IOException {
@@ -244,7 +238,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 +246,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).withCredential().to("/repos/"+owner.login+"/"+name+"/collaborators/"+user.getLogin(),null,method);
}
}
@@ -274,31 +268,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).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);
}
/**
@@ -308,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);
}
/**
@@ -318,55 +335,22 @@ 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);
}
- /**
- * 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.
*/
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));
@@ -377,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);
}
/**
@@ -393,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;
@@ -405,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);
@@ -421,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)
@@ -452,7 +436,7 @@ public GHHook createHook(String name, Map config, Collection 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);
}
@@ -567,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;
@@ -579,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);
@@ -588,7 +572,7 @@ public GHMilestone getMilestone(int number) throws IOException {
}
public GHMilestone createMilestone(String title, String description) throws IOException {
- return new Poster(root,V3).withCredential()
+ return new Poster(root).withCredential()
.with("title", title).with("description", description)
.to("/repos/"+owner.login+"/"+name+"/milestones", GHMilestone.class,"POST").wrap(this);
}
diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java
index a9443acb08..d4bf99d582 100644
--- a/src/main/java/org/kohsuke/github/GHTeam.java
+++ b/src/main/java/org/kohsuke/github/GHTeam.java
@@ -1,8 +1,11 @@
package org.kohsuke.github;
import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
/**
* A team in GitHub organization.
@@ -15,6 +18,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,33 +46,38 @@ 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.retrieveWithAuth(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.retrieveWithAuth(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.retrieveWithAuth(api("/members?name="+u.getLogin()),null, "POST");
+ org.root.retrieveWithAuth(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.retrieveWithAuth(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.retrieveWithAuth(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.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 fbf36c0e6d..07f44f71c4 100644
--- a/src/main/java/org/kohsuke/github/GHUser.java
+++ b/src/main/java/org/kohsuke/github/GHUser.java
@@ -23,12 +23,11 @@
*/
package org.kohsuke.github;
-import com.infradna.tool.bridge_method_injector.BridgeMethodsAdded;
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;
/**
@@ -42,14 +41,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).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).withCredential().to("/user/following/"+login,null,"DELETE");
}
/**
@@ -57,7 +56,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.retrieve("/users/" + login + "/following", GHUser[].class);
+ return new GHPersonSet(Arrays.asList(wrap(followers,root)));
}
/**
@@ -65,7 +65,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.retrieve("/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;
}
/**
@@ -75,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 faf1ddc66e..18f9f596aa 100644
--- a/src/main/java/org/kohsuke/github/GitHub.java
+++ b/src/main/java/org/kohsuke/github/GitHub.java
@@ -25,8 +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;
import java.io.FileInputStream;
@@ -54,7 +52,6 @@
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import org.apache.commons.io.IOUtils;
-import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.DeserializationConfig.Feature;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.introspect.VisibilityChecker.Std;
@@ -85,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;
@@ -156,42 +158,30 @@ public static GitHub connectAnonymously() {
throw new IllegalStateException("This operation requires a credential but none is given to the GitHub constructor");
}
- /*package*/ URL getApiURL(ApiVersion v, String tailApiUrl) throws IOException {
+ /*package*/ URL getApiURL(String tailApiUrl) throws IOException {
if (oauthAccessToken != null) {
// append the access token
tailApiUrl = tailApiUrl + (tailApiUrl.indexOf('?')>=0 ?'&':'?') + "access_token=" + oauthAccessToken;
}
- return new URL(v.getApiVersionBaseUrl(githubServer)+tailApiUrl);
+ return new URL("https://api."+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);
+ return _retrieve(tailApiUrl, type, "GET", false);
}
/*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);
+ return _retrieve(tailApiUrl, type, "GET", true);
}
/*package*/ T retrieveWithAuth(String tailApiUrl, Class type, String method) throws IOException {
- return _retrieve(tailApiUrl, type, method, true, V2);
+ return _retrieve(tailApiUrl, type, method, true);
}
- /*package*/ T retrieveWithAuth3(String tailApiUrl, Class type, String method) throws IOException {
- return _retrieve(tailApiUrl, type, method, true, V3);
- }
-
- 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) {
@@ -205,7 +195,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()}.
@@ -218,7 +208,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);
}
@@ -362,7 +352,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;
}
/**
@@ -372,7 +362,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);
@@ -386,7 +376,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);
}
@@ -409,8 +399,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 = retrieve("/orgs/" + name, GHOrganization.class).wrapUp(this);
orgs.put(name,o);
}
return o;
@@ -427,7 +416,12 @@ public GHRepository getRepository(String name) throws IOException {
}
public Map getMyOrganizations() throws IOException {
- return retrieveWithAuth("/organizations",JsonOrganizations.class).wrap(this);
+ GHOrganization[] orgs = retrieveWithAuth("/user/orgs", GHOrganization[].class);
+ Map r = new HashMap();
+ for (GHOrganization o : orgs) {
+ r.put(o.name,o.wrapUp(this));
+ }
+ return r;
}
/**
@@ -435,7 +429,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);
@@ -461,7 +455,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);
}
@@ -471,7 +465,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;
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;
- }
-}
diff --git a/src/main/java/org/kohsuke/github/Poster.java b/src/main/java/org/kohsuke/github/Poster.java
index c07b5ddad3..d18c054b62 100644
--- a/src/main/java/org/kohsuke/github/Poster.java
+++ b/src/main/java/org/kohsuke/github/Poster.java
@@ -24,20 +24,15 @@
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;
import java.util.List;
import java.util.Map;
@@ -53,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;
@@ -63,19 +56,10 @@ 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) {
- this.root = root;
- this.v = v;
}
Poster(GitHub root) {
- this(root,ApiVersion.V2);
+ this.root = root;
}
public Poster withCredential() {
@@ -102,6 +86,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));
@@ -127,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);
}
}
@@ -158,23 +142,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");
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/)");