diff --git a/pom.xml b/pom.xml index f8ac35a431..3ca2bd00c0 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.32 + 1.33 GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index 8069066780..d7bb9492c7 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -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); } diff --git a/src/main/java/org/kohsuke/github/GHCommitComment.java b/src/main/java/org/kohsuke/github/GHCommitComment.java index 9ff07304eb..a5f23877f8 100644 --- a/src/main/java/org/kohsuke/github/GHCommitComment.java +++ b/src/main/java/org/kohsuke/github/GHCommitComment.java @@ -99,7 +99,7 @@ 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; } @@ -107,7 +107,7 @@ public void update(String body) throws IOException { * 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() { diff --git a/src/main/java/org/kohsuke/github/GHHook.java b/src/main/java/org/kohsuke/github/GHHook.java index 8d1e5da027..fa797db933 100644 --- a/src/main/java/org/kohsuke/github/GHHook.java +++ b/src/main/java/org/kohsuke/github/GHHook.java @@ -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)); } } diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index 18f2594e3a..74cb7fedd1 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -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()); } /** @@ -211,7 +211,6 @@ public GHUser getAssignee() { /** * User who submitted the issue. */ - @Deprecated public GHUser getUser() { return user; } diff --git a/src/main/java/org/kohsuke/github/GHIssueBuilder.java b/src/main/java/org/kohsuke/github/GHIssueBuilder.java new file mode 100644 index 0000000000..385fcd04a0 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHIssueBuilder.java @@ -0,0 +1,59 @@ +package org.kohsuke.github; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Kohsuke Kawaguchi + */ +public class GHIssueBuilder { + private final GHRepository repo; + private final Requester builder; + private List labels = new ArrayList(); + + GHIssueBuilder(GHRepository repo, String title) { + this.repo = repo; + this.builder = new Requester(repo.root); + builder.with("title",title); + } + + /** + * Sets the main text of an issue, which is arbitrary multi-line text. + */ + public GHIssueBuilder body(String str) { + builder.with("body",str); + return this; + } + + public GHIssueBuilder assignee(GHUser user) { + if (user!=null) + builder.with("assignee",user.getLogin()); + return this; + } + + public GHIssueBuilder assignee(String user) { + if (user!=null) + builder.with("assignee",user); + return this; + } + + public GHIssueBuilder milestone(GHMilestone milestone) { + if (milestone!=null) + builder.with("milestone",milestone.getNumber()); + return this; + } + + public GHIssueBuilder label(String label) { + if (label!=null) + labels.add(label); + return this; + } + + /** + * Creates a new issue. + */ + public GHIssue create() throws IOException { + return builder.with("labels",labels).to(repo.getApiTailUrl("issues"),GHIssue.class).wrap(repo); + } +} diff --git a/src/main/java/org/kohsuke/github/GHMyself.java b/src/main/java/org/kohsuke/github/GHMyself.java index 2a16abcdad..31be58a707 100644 --- a/src/main/java/org/kohsuke/github/GHMyself.java +++ b/src/main/java/org/kohsuke/github/GHMyself.java @@ -22,7 +22,7 @@ public class GHMyself extends GHUser { * Always non-null. */ public List 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)); } @@ -33,7 +33,7 @@ public List getEmails() throws IOException { * Always non-null. */ public List 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 emails) throws IOException { diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index 8328c72235..188f26d930 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -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); } @@ -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.retrieve().withCredential().to("/orgs/" + login + "/teams", GHTeam[].class); + GHTeam[] teams = root.retrieve().to("/orgs/" + login + "/teams", GHTeam[].class); Map r = new TreeMap(); for (GHTeam t : teams) { r.put(t.getName(),t.wrapUp(this)); @@ -54,7 +54,7 @@ public Map 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); } /** @@ -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.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) { @@ -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 } @@ -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 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 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 71c7c54c6f..7f65277f4f 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -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; } diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 291b616c3a..0260bb888a 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -140,6 +140,14 @@ public GHUser getOwner() throws IOException { return root.getUser(owner.login); // because 'owner' isn't fully populated } + public GHIssue getIssue(int id) throws IOException { + return root.retrieve().to("/repos/" + owner.login + "/" + name + "/issues/" + id, GHIssue.class).wrap(this); + } + + public GHIssueBuilder createIssue(String title) { + return new GHIssueBuilder(this,title); + } + public List getIssues(GHIssueState state) throws IOException { return Arrays.asList(GHIssue.wrap(root.retrieve().to("/repos/" + owner.login + "/" + name + "/issues?state=" + state.toString().toLowerCase(), GHIssue[].class), this)); } @@ -231,7 +239,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.retrieve().withCredential().to("/repos/" + owner.login + "/" + name + "/teams", GHTeam[].class), root.getOrganization(owner.login))))); + return Collections.unmodifiableSet(new HashSet(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 { @@ -253,7 +261,7 @@ public void removeCollaborators(Collection users) throws IOException { private void modifyCollaborators(Collection 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()); } } @@ -270,7 +278,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); @@ -313,7 +321,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); } /** @@ -323,7 +331,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); } /** @@ -333,7 +341,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++) { @@ -352,7 +360,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); } /** @@ -386,14 +394,14 @@ protected void wrapUp(GHPullRequest[] page) { */ public List getHooks() throws IOException { List list = new ArrayList(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); } /** @@ -476,8 +484,7 @@ 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("state", state.name().toLowerCase(Locale.ENGLISH)) .with("target_url", targetUrl) .with("description", description) .to(String.format("/repos/%s/%s/statuses/%s",owner.login,this.name,sha1),GHCommitStatus.class).wrapUp(root); @@ -505,8 +512,7 @@ public GHHook createHook(String name, Map config, Collection getBranches() throws IOException { Map r = new TreeMap(); - for (GHBranch p : root.retrieve().to("/repos/" + owner.login + "/" + name + "/branches", GHBranch[].class)) { + for (GHBranch p : root.retrieve().to(getApiTailUrl("branches"), GHBranch[].class)) { p.wrap(this); r.put(p.getName(),p); } return r; } + /** + * @deprecated + * Use {@link #listMilestones(GHIssueState)} + */ public Map getMilestones() throws IOException { Map milestones = new TreeMap(); - GHMilestone[] ms = root.retrieve().to("/repos/" + owner.login + "/" + name + "/milestones", GHMilestone[].class); - for (GHMilestone m : ms) { - m.owner = this; - m.root = root; + for (GHMilestone m : listMilestones(GHIssueState.OPEN)) { milestones.put(m.getNumber(), m); } return milestones; } + /** + * Lists up all the milestones in this repository. + */ + public PagedIterable listMilestones(final GHIssueState state) { + return new PagedIterable() { + public PagedIterator iterator() { + return new PagedIterator(root.retrieve().asIterator(getApiTailUrl("milestones?state="+state.toString().toLowerCase(Locale.ENGLISH)), GHMilestone[].class)) { + @Override + protected void wrapUp(GHMilestone[] page) { + for (GHMilestone c : page) + c.wrap(GHRepository.this); + } + }; + } + }; + } + public GHMilestone getMilestone(int number) throws IOException { GHMilestone m = milestones.get(number); if (m == null) { - m = root.retrieve().to("/repos/" + owner.login + "/" + name + "/milestones/" + number, GHMilestone.class); + m = root.retrieve().to(getApiTailUrl("milestones/" + number), GHMilestone.class); m.owner = this; m.root = root; milestones.put(m.getNumber(), m); @@ -640,8 +664,8 @@ public GHMilestone getMilestone(int number) throws IOException { } public GHMilestone createMilestone(String title, String description) throws IOException { - return new Requester(root).withCredential() - .with("title", title).with("description", description).method("POST").to("/repos/" + owner.login + "/" + name + "/milestones", GHMilestone.class).wrap(this); + return new Requester(root) + .with("title", title).with("description", description).method("POST").to(getApiTailUrl("milestones"), GHMilestone.class).wrap(this); } @Override @@ -663,4 +687,8 @@ public boolean equals(Object obj) { } return false; } + + String getApiTailUrl(String tail) { + return "/repos/" + owner.login + "/" + name +'/'+tail; + } } diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index dca37e3313..55b2917958 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.retrieve().withCredential().to(api("/members"), GHUser[].class), org.root))); + return new HashSet(Arrays.asList(GHUser.wrap(org.root.retrieve().to(api("/members"), GHUser[].class), org.root))); } public Map 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 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.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) { diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java index 329434f38c..41fe9a24bb 100644 --- a/src/main/java/org/kohsuke/github/GHUser.java +++ b/src/main/java/org/kohsuke/github/GHUser.java @@ -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); } /** diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 886239820b..9e5e970ded 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -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; } /** @@ -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); @@ -237,7 +237,7 @@ public GHRepository getRepository(String name) throws IOException { * TODO: make this automatic. */ public Map getMyOrganizations() throws IOException { - GHOrganization[] orgs = retrieve().withCredential().to("/user/orgs", GHOrganization[].class); + GHOrganization[] orgs = retrieve().to("/user/orgs", GHOrganization[].class); Map r = new HashMap(); for (GHOrganization o : orgs) { // don't put 'o' into orgs because they are shallow @@ -277,7 +277,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 { - 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); @@ -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; diff --git a/src/main/java/org/kohsuke/github/PagedIterator.java b/src/main/java/org/kohsuke/github/PagedIterator.java index 74c197aa2e..9149290911 100644 --- a/src/main/java/org/kohsuke/github/PagedIterator.java +++ b/src/main/java/org/kohsuke/github/PagedIterator.java @@ -3,6 +3,7 @@ import java.util.Arrays; import java.util.Iterator; import java.util.List; +import java.util.NoSuchElementException; /** * Iterator over a pagenated data source. @@ -28,17 +29,24 @@ public abstract class PagedIterator implements Iterator { protected abstract void wrapUp(T[] page); public boolean hasNext() { - return (current!=null && pos args = new ArrayList(); - private boolean authenticate; /** * Request method. @@ -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; } @@ -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 { diff --git a/src/test/java/org/kohsuke/AppTest.java b/src/test/java/org/kohsuke/AppTest.java index ba4a4a4804..b272ee7a4d 100644 --- a/src/test/java/org/kohsuke/AppTest.java +++ b/src/test/java/org/kohsuke/AppTest.java @@ -4,7 +4,6 @@ import org.kohsuke.github.GHCommit; import org.kohsuke.github.GHCommit.File; import org.kohsuke.github.GHCommitComment; -import org.kohsuke.github.GHCommitState; import org.kohsuke.github.GHCommitStatus; import org.kohsuke.github.GHEvent; import org.kohsuke.github.GHEventInfo; @@ -12,8 +11,10 @@ import org.kohsuke.github.GHHook; import org.kohsuke.github.GHBranch; import org.kohsuke.github.GHIssue; +import org.kohsuke.github.GHIssueComment; import org.kohsuke.github.GHIssueState; import org.kohsuke.github.GHKey; +import org.kohsuke.github.GHMilestone; import org.kohsuke.github.GHMyself; import org.kohsuke.github.GHOrganization; import org.kohsuke.github.GHOrganization.Permission; @@ -23,7 +24,6 @@ import org.kohsuke.github.GHUser; import org.kohsuke.github.GitHub; import org.kohsuke.github.PagedIterable; -import org.kohsuke.github.PagedIterator; import java.io.IOException; import java.net.URL; @@ -51,6 +51,26 @@ public void testCredentialValid() throws IOException { assertFalse(GitHub.connect("totally", "bogus").isCredentialValid()); } + public void testIssueWithNoComment() throws IOException { + GHRepository repository = GitHub.connect().getRepository("kohsuke/test"); + List v = repository.getIssue(4).getComments(); + System.out.println(v); + assertTrue(v.isEmpty()); + + v = repository.getIssue(3).getComments(); + System.out.println(v); + assertTrue(v.size()==3); + } + + public void testCreateIssue() throws IOException { + GHUser u = GitHub.connect().getUser("kohsuke"); + GHRepository r = u.getRepository("test"); + GHMilestone someMilestone = r.listMilestones(GHIssueState.CLOSED).iterator().next(); + GHIssue o = r.createIssue("testing").body("this is body").assignee(u).label("bug").label("question").milestone(someMilestone).create(); + System.out.println(o.getUrl()); + o.close(); + } + public void testRateLimit() throws IOException { System.out.println(GitHub.connect().getRateLimit()); }