Skip to content

Commit

Permalink
Merge pull request #19 from janinko/Issues-19-PagedIterable_dosnt_use…
Browse files Browse the repository at this point in the history
…_authentication

PagedIterable dosn't use authentication
  • Loading branch information
kohsuke committed Sep 13, 2012
2 parents 5210870 + e658a7f commit bd58412
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 43 deletions.
1 change: 0 additions & 1 deletion src/main/java/org/kohsuke/github/GHCommit.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ public GHCommitComment createComment(String body, String path, Integer line, Int
.with("path",path)
.with("line",line)
.with("position",position)
.withCredential()
.to(String.format("/repos/%s/%s/commits/%s/comments",owner.getOwnerName(),owner.getName(),sha),GHCommitComment.class);
return r.wrap(owner);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/kohsuke/github/GHCommitComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ public GHCommit getCommit() throws IOException {
public void update(String body) throws IOException {
GHCommitComment r = new Requester(owner.root)
.with("body", body)
.withCredential().method("PATCH").to(getApiTail(), GHCommitComment.class);
.method("PATCH").to(getApiTail(), GHCommitComment.class);
this.body = body;
}

/**
* Deletes this comment.
*/
public void delete() throws IOException {
new Requester(owner.root).withCredential().method("DELETE").to(getApiTail());
new Requester(owner.root).method("DELETE").to(getApiTail());
}

private String getApiTail() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public int getId() {
* Deletes this hook.
*/
public void delete() throws IOException {
new Requester(repository.root).withCredential().method("DELETE").to(String.format("/repos/%s/%s/hooks/%d", repository.getOwnerName(), repository.getName(), id));
new Requester(repository.root).method("DELETE").to(String.format("/repos/%s/%s/hooks/%d", repository.getOwnerName(), repository.getName(), id));
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/kohsuke/github/GHIssue.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ public URL getApiURL(){
* Updates the issue by adding a comment.
*/
public void comment(String message) throws IOException {
new Requester(root).withCredential().with("body",message).to(getApiRoute() + "/comments");
new Requester(root).with("body",message).to(getApiRoute() + "/comments");
}

private void edit(String key, Object value) throws IOException {
new Requester(root).withCredential()._with(key, value).method("PATCH").to(getApiRoute());
new Requester(root)._with(key, value).method("PATCH").to(getApiRoute());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/kohsuke/github/GHMyself.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class GHMyself extends GHUser {
* Always non-null.
*/
public List<String> getEmails() throws IOException {
String[] addresses = root.retrieve().withCredential().to("/user/emails", String[].class);
String[] addresses = root.retrieve().to("/user/emails", String[].class);
return Collections.unmodifiableList(Arrays.asList(addresses));
}

Expand All @@ -33,7 +33,7 @@ public List<String> getEmails() throws IOException {
* Always non-null.
*/
public List<GHKey> getPublicKeys() throws IOException {
return Collections.unmodifiableList(Arrays.asList(root.retrieve().withCredential().to("/user/keys", GHKey[].class)));
return Collections.unmodifiableList(Arrays.asList(root.retrieve().to("/user/keys", GHKey[].class)));
}

// public void addEmails(Collection<String> emails) throws IOException {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/kohsuke/github/GHOrganization.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,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 Requester(root).withCredential()
return new Requester(root)
.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);
}
Expand All @@ -42,7 +42,7 @@ public GHRepository createRepository(String name, String description, String hom
* Teams by their names.
*/
public Map<String,GHTeam> getTeams() throws IOException {
GHTeam[] teams = root.retrieve().withCredential().to("/orgs/" + login + "/teams", GHTeam[].class);
GHTeam[] teams = root.retrieve().to("/orgs/" + login + "/teams", GHTeam[].class);
Map<String,GHTeam> r = new TreeMap<String, GHTeam>();
for (GHTeam t : teams) {
r.put(t.getName(),t.wrapUp(this));
Expand All @@ -54,7 +54,7 @@ public Map<String,GHTeam> getTeams() throws IOException {
* Publicizes the membership.
*/
public void publicize(GHUser u) throws IOException {
root.retrieve().withCredential().method("PUT").to("/orgs/" + login + "/public_members/" + u.getLogin(), null);
root.retrieve().method("PUT").to("/orgs/" + login + "/public_members/" + u.getLogin(), null);
}

/**
Expand All @@ -64,7 +64,7 @@ public List<GHUser> getMembers() throws IOException {
return new AbstractList<GHUser>() {
// 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.retrieve().withCredential().to("/orgs/" + login + "/members", GHUser[].class);
final GHUser[] shallow = root.retrieve().to("/orgs/" + login + "/members", GHUser[].class);

@Override
public GHUser get(int index) {
Expand All @@ -86,7 +86,7 @@ public int size() {
* Conceals the membership.
*/
public void conceal(GHUser u) throws IOException {
root.retrieve().withCredential().method("DELETE").to("/orgs/" + login + "/public_members/" + u.getLogin(), null);
root.retrieve().method("DELETE").to("/orgs/" + login + "/public_members/" + u.getLogin(), null);
}

public enum Permission { ADMIN, PUSH, PULL }
Expand All @@ -95,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<GHRepository> repositories) throws IOException {
Requester post = new Requester(root).withCredential().with("name", name).with("permission", p.name().toLowerCase());
Requester post = new Requester(root).with("name", name).with("permission", p.name().toLowerCase());
List<String> repo_names = new ArrayList<String>();
for (GHRepository r : repositories) {
repo_names.add(r.getName());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void remove() {
*/
public GHRepository getRepository(String name) throws IOException {
try {
return root.retrieve().withCredential().to("/repos/" + login + '/' + name, GHRepository.class).wrap(root);
return root.retrieve().to("/repos/" + login + '/' + name, GHRepository.class).wrap(root);
} catch (FileNotFoundException e) {
return null;
}
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public Set<String> getCollaboratorNames() throws IOException {
* If this repository belongs to an organization, return a set of teams.
*/
public Set<GHTeam> getTeams() throws IOException {
return Collections.unmodifiableSet(new HashSet<GHTeam>(Arrays.asList(GHTeam.wrapUp(root.retrieve().withCredential().to("/repos/" + owner.login + "/" + name + "/teams", GHTeam[].class), root.getOrganization(owner.login)))));
return Collections.unmodifiableSet(new HashSet<GHTeam>(Arrays.asList(GHTeam.wrapUp(root.retrieve().to("/repos/" + owner.login + "/" + name + "/teams", GHTeam[].class), root.getOrganization(owner.login)))));
}

public void addCollaborators(GHUser... users) throws IOException {
Expand All @@ -253,7 +253,7 @@ public void removeCollaborators(Collection<GHUser> users) throws IOException {
private void modifyCollaborators(Collection<GHUser> users, String method) throws IOException {
verifyMine();
for (GHUser user : users) {
new Requester(root).withCredential().method(method).to("/repos/" + owner.login + "/" + name + "/collaborators/" + user.getLogin());
new Requester(root).method(method).to("/repos/" + owner.login + "/" + name + "/collaborators/" + user.getLogin());
}
}

Expand All @@ -270,7 +270,7 @@ public void setEmailServiceHook(String address) throws IOException {
}

private void edit(String key, String value) throws IOException {
Requester requester = new Requester(root).withCredential();
Requester requester = new Requester(root);
if (!key.equals("name"))
requester.with("name", name); // even when we don't change the name, we need to send it in
requester.with(key, value).method("PATCH").to("/repos/" + owner.login + "/" + name);
Expand Down Expand Up @@ -313,7 +313,7 @@ public void setHomepage(String value) throws IOException {
* Deletes this repository.
*/
public void delete() throws IOException {
new Requester(root).withCredential().method("DELETE").to("/repos/" + owner.login + "/" + name);
new Requester(root).method("DELETE").to("/repos/" + owner.login + "/" + name);
}

/**
Expand All @@ -323,7 +323,7 @@ public void delete() throws IOException {
* Newly forked repository that belong to you.
*/
public GHRepository fork() throws IOException {
return new Requester(root).withCredential().method("POST").to("/repos/" + owner.login + "/" + name + "/forks", GHRepository.class).wrap(root);
return new Requester(root).method("POST").to("/repos/" + owner.login + "/" + name + "/forks", GHRepository.class).wrap(root);
}

/**
Expand All @@ -333,7 +333,7 @@ public GHRepository fork() throws IOException {
* Newly forked repository that belong to you.
*/
public GHRepository forkTo(GHOrganization org) throws IOException {
new Requester(root).withCredential().to(String.format("/repos/%s/%s/forks?org=%s",owner.login,name,org.getLogin()));
new Requester(root).to(String.format("/repos/%s/%s/forks?org=%s",owner.login,name,org.getLogin()));

// this API is asynchronous. we need to wait for a bit
for (int i=0; i<10; i++) {
Expand All @@ -352,7 +352,7 @@ public GHRepository forkTo(GHOrganization org) throws IOException {
* Retrieves a specified pull request.
*/
public GHPullRequest getPullRequest(int i) throws IOException {
return root.retrieve().withCredential().to("/repos/" + owner.login + '/' + name + "/pulls/" + i, GHPullRequest.class).wrapUp(this);
return root.retrieve().to("/repos/" + owner.login + '/' + name + "/pulls/" + i, GHPullRequest.class).wrapUp(this);
}

/**
Expand Down Expand Up @@ -386,14 +386,14 @@ protected void wrapUp(GHPullRequest[] page) {
*/
public List<GHHook> getHooks() throws IOException {
List<GHHook> list = new ArrayList<GHHook>(Arrays.asList(
root.retrieve().withCredential().to(String.format("/repos/%s/%s/hooks", owner.login, name), GHHook[].class)));
root.retrieve().to(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.retrieve().withCredential().to(String.format("/repos/%s/%s/hooks/%d", owner.login, name, id), GHHook.class).wrap(this);
return root.retrieve().to(String.format("/repos/%s/%s/hooks/%d", owner.login, name, id), GHHook.class).wrap(this);
}

/**
Expand Down Expand Up @@ -476,7 +476,6 @@ public GHCommitStatus getLastCommitStatus(String sha1) throws IOException {
*/
public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description) throws IOException {
return new Requester(root)
.withCredential()
.with("state",state.name().toLowerCase(Locale.ENGLISH))
.with("target_url", targetUrl)
.with("description", description)
Expand Down Expand Up @@ -505,7 +504,6 @@ public GHHook createHook(String name, Map<String,String> config, Collection<GHEv
}

return new Requester(root)
.withCredential()
.with("name",name)
.with("active", active)
._with("config", config)
Expand Down Expand Up @@ -640,7 +638,7 @@ public GHMilestone getMilestone(int number) throws IOException {
}

public GHMilestone createMilestone(String title, String description) throws IOException {
return new Requester(root).withCredential()
return new Requester(root)
.with("title", title).with("description", description).method("POST").to("/repos/" + owner.login + "/" + name + "/milestones", GHMilestone.class).wrap(this);
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/kohsuke/github/GHTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public int getId() {
* Retrieves the current members.
*/
public Set<GHUser> getMembers() throws IOException {
return new HashSet<GHUser>(Arrays.asList(GHUser.wrap(org.root.retrieve().withCredential().to(api("/members"), GHUser[].class), org.root)));
return new HashSet<GHUser>(Arrays.asList(GHUser.wrap(org.root.retrieve().to(api("/members"), GHUser[].class), org.root)));
}

public Map<String,GHRepository> getRepositories() throws IOException {
GHRepository[] repos = org.root.retrieve().withCredential().to(api("/repos"), GHRepository[].class);
GHRepository[] repos = org.root.retrieve().to(api("/repos"), GHRepository[].class);
Map<String,GHRepository> m = new TreeMap<String, GHRepository>();
for (GHRepository r : repos) {
m.put(r.getName(),r.wrap(org.root));
Expand All @@ -62,22 +62,22 @@ public Map<String,GHRepository> getRepositories() throws IOException {
* Adds a member to the team.
*/
public void add(GHUser u) throws IOException {
org.root.retrieve().withCredential().method("PUT").to(api("/members/" + u.getLogin()), null);
org.root.retrieve().method("PUT").to(api("/members/" + u.getLogin()), null);
}

/**
* Removes a member to the team.
*/
public void remove(GHUser u) throws IOException {
org.root.retrieve().withCredential().method("DELETE").to(api("/members/" + u.getLogin()), null);
org.root.retrieve().method("DELETE").to(api("/members/" + u.getLogin()), null);
}

public void add(GHRepository r) throws IOException {
org.root.retrieve().withCredential().method("PUT").to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null);
org.root.retrieve().method("PUT").to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null);
}

public void remove(GHRepository r) throws IOException {
org.root.retrieve().withCredential().method("DELETE").to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null);
org.root.retrieve().method("DELETE").to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null);
}

private String api(String tail) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/kohsuke/github/GHUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public class GHUser extends GHPerson {
* Follow this user.
*/
public void follow() throws IOException {
new Requester(root).withCredential().method("PUT").to("/user/following/" + login);
new Requester(root).method("PUT").to("/user/following/" + login);
}

/**
* Unfollow this user.
*/
public void unfollow() throws IOException {
new Requester(root).withCredential().method("DELETE").to("/user/following/" + login);
new Requester(root).method("DELETE").to("/user/following/" + login);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/kohsuke/github/GitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static GitHub connectAnonymously() {
* Gets the current rate limit.
*/
public GHRateLimit getRateLimit() throws IOException {
return retrieve().withCredential().to("/rate_limit", JsonRateLimit.class).rate;
return retrieve().to("/rate_limit", JsonRateLimit.class).rate;
}

/**
Expand All @@ -177,7 +177,7 @@ public GHRateLimit getRateLimit() throws IOException {
public GHMyself getMyself() throws IOException {
requireCredential();

GHMyself u = retrieve().withCredential().to("/user", GHMyself.class);
GHMyself u = retrieve().to("/user", GHMyself.class);

u.root = this;
users.put(u.getLogin(), u);
Expand Down Expand Up @@ -237,7 +237,7 @@ public GHRepository getRepository(String name) throws IOException {
* TODO: make this automatic.
*/
public Map<String, GHOrganization> getMyOrganizations() throws IOException {
GHOrganization[] orgs = retrieve().withCredential().to("/user/orgs", GHOrganization[].class);
GHOrganization[] orgs = retrieve().to("/user/orgs", GHOrganization[].class);
Map<String, GHOrganization> r = new HashMap<String, GHOrganization>();
for (GHOrganization o : orgs) {
// don't put 'o' into orgs because they are shallow
Expand Down Expand Up @@ -277,7 +277,7 @@ public <T extends GHEventPayload> T parseEventPayload(Reader r, Class<T> type) t
* Newly created repository.
*/
public GHRepository createRepository(String name, String description, String homepage, boolean isPublic) throws IOException {
Requester requester = new Requester(this).withCredential()
Requester requester = new Requester(this)
.with("name", name).with("description", description).with("homepage", homepage)
.with("public", isPublic ? 1 : 0);
return requester.method("POST").to("/user/repos", GHRepository.class).wrap(this);
Expand All @@ -288,7 +288,7 @@ public GHRepository createRepository(String name, String description, String hom
*/
public boolean isCredentialValid() throws IOException {
try {
retrieve().withCredential().to("/user", GHUser.class);
retrieve().to("/user", GHUser.class);
return true;
} catch (IOException e) {
return false;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/kohsuke/github/Requester.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
class Requester {
private final GitHub root;
private final List<Entry> args = new ArrayList<Entry>();
private boolean authenticate;

/**
* Request method.
Expand All @@ -79,10 +78,10 @@ private Entry(String key, Object value) {
/**
* Makes a request with authentication credential.
*/
@Deprecated
public Requester withCredential() {
// keeping it inline with retrieveWithAuth not to enforce the check
// root.requireCredential();
authenticate = true;
return this;
}

Expand Down Expand Up @@ -269,7 +268,7 @@ private HttpURLConnection setupConnection(URL url) throws IOException {
// if the authentication is needed but no credential is given, try it anyway (so that some calls
// that do work with anonymous access in the reduced form should still work.)
// if OAuth token is present, it'll be set in the URL, so need to set the Authorization header
if (authenticate && root.encodedAuthorization!=null && root.oauthAccessToken == null)
if (root.encodedAuthorization!=null && root.oauthAccessToken == null)
uc.setRequestProperty("Authorization", "Basic " + root.encodedAuthorization);

try {
Expand Down

0 comments on commit bd58412

Please sign in to comment.