From fbcf3a17b4d1f8a9caaecdf7286b1ff0aa0859c4 Mon Sep 17 00:00:00 2001 From: "y.kokubo" Date: Fri, 13 Jan 2012 10:05:56 +0900 Subject: [PATCH 1/5] implmented milestone api via v3 --- .../java/org/kohsuke/github/GHMilestone.java | 72 +++++++++++++++++++ .../org/kohsuke/github/GHMilestoneState.java | 11 +++ .../java/org/kohsuke/github/GHRepository.java | 31 ++++++++ 3 files changed, 114 insertions(+) create mode 100644 src/main/java/org/kohsuke/github/GHMilestone.java create mode 100644 src/main/java/org/kohsuke/github/GHMilestoneState.java diff --git a/src/main/java/org/kohsuke/github/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java new file mode 100644 index 0000000000..10b9cec909 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -0,0 +1,72 @@ +package org.kohsuke.github; + +import java.util.Date; + +/** + * + * @author Yusuke Kokubo + * + */ +public class GHMilestone { + GitHub root; + GHRepository owner; + + GHUser creator; + private String state, due_on, title, url, created_at, description; + private int closed_issues, open_issues, number; + + public GitHub getRoot() { + return root; + } + + public GHRepository getOwner() { + return owner; + } + + public GHUser getCreator() { + return creator; + } + + public Date getDueOn() { + if (due_on == null) return null; + return GitHub.parseDate(due_on); + } + + public String getTitle() { + return title; + } + + public String getUrl() { + return url; + } + + public Date getCreatedAt() { + return GitHub.parseDate(created_at); + } + + public String getDescription() { + return description; + } + + public int getClosedIssues() { + return closed_issues; + } + + public int getOpenIssues() { + return open_issues; + } + + public int getNumber() { + return number; + } + + public GHMilestoneState getState() { + return Enum.valueOf(GHMilestoneState.class, state); + } + + public GHMilestone wrap(GHRepository repo) { + this.owner = repo; + this.root = repo.root; + return this; + } +} diff --git a/src/main/java/org/kohsuke/github/GHMilestoneState.java b/src/main/java/org/kohsuke/github/GHMilestoneState.java new file mode 100644 index 0000000000..c4c1475672 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHMilestoneState.java @@ -0,0 +1,11 @@ +package org.kohsuke.github; + +/** + * + * @author Yusuke Kokubo + * + */ +public enum GHMilestoneState { + open, + closed +} \ No newline at end of file diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 81b584b4ef..5678c70737 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -42,12 +42,14 @@ import java.util.Collection; import java.util.Collections; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.TreeMap; import static java.util.Arrays.*; import static org.kohsuke.github.ApiVersion.V3; @@ -68,6 +70,7 @@ public class GHRepository { private boolean has_issues, has_wiki, fork, _private, has_downloads; private int watchers,forks,open_issues; private String created_at, pushed_at; + private Map milestones = new HashMap(); public String getDescription() { return description; @@ -436,6 +439,34 @@ public boolean remove(Object url) { return this; } + public Map getMilestones() throws IOException { + Map milestones = new TreeMap(); + GHMilestone[] ms = root.retrieve3("/repos/"+owner.login+"/"+name+"/milestones", GHMilestone[].class); + for (GHMilestone m : ms) { + m.owner = this; + m.root = root; + milestones.put(m.getNumber(), m); + } + return milestones; + } + + 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.owner = this; + m.root = root; + milestones.put(m.getNumber(), m); + } + return m; + } + + public GHMilestone createMilestone(String title, String description) throws IOException { + return new Poster(root,V3).withCredential() + .with("title", title).with("description", description) + .to("/repos/"+owner.login+"/"+name+"/milestones", GHMilestone.class,"POST").wrap(this); + } + @Override public String toString() { return "Repository:"+owner.login+":"+name; From 22bc768868b0c0e733c3bca2c2bcfb2e07ea2c5d Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Sun, 12 Feb 2012 09:30:37 -0800 Subject: [PATCH 2/5] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b8aadaafff..f43ab355fa 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.17 + 1.18-SNAPSHOT GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java From facb5bd13e27f2dd7d4e0eb4e8a40121b9ffdfc0 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 8 Mar 2012 12:47:11 -0800 Subject: [PATCH 3/5] Added API to handle emails. --- .../java/org/kohsuke/github/GHMyself.java | 34 +++++++++++++++++++ src/main/java/org/kohsuke/github/GitHub.java | 20 +++++------ .../java/org/kohsuke/github/JsonMyself.java | 8 +++++ src/test/java/org/kohsuke/AppTest.java | 9 +++-- 4 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 src/main/java/org/kohsuke/github/GHMyself.java create mode 100644 src/main/java/org/kohsuke/github/JsonMyself.java diff --git a/src/main/java/org/kohsuke/github/GHMyself.java b/src/main/java/org/kohsuke/github/GHMyself.java new file mode 100644 index 0000000000..fe00518e96 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHMyself.java @@ -0,0 +1,34 @@ +package org.kohsuke.github; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +/** + * Represents the account that's logging into GitHub. + * + * @author Kohsuke Kawaguchi + */ +public class GHMyself extends GHUser { + /** + * Returns the read-only list of e-mail addresses configured for you. + * + * This corresponds to the stuff you configure in https://github.com/settings/emails, + * and not to be confused with {@link #getEmail()} that shows your public e-mail address + * set in https://github.com/settings/profile + * + * @return + * Always non-null. + */ + public List getEmails() throws IOException { + String[] addresses = root.retrieveWithAuth3("/user/emails",String[].class); + return Collections.unmodifiableList(Arrays.asList(addresses)); + } + +// public void addEmails(Collection emails) throws IOException { +//// new Poster(root,ApiVersion.V3).withCredential().to("/user/emails"); +// root.retrieveWithAuth3() +// } +} diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 8f3c472c58..d95287f243 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -49,6 +49,7 @@ import java.util.Properties; import java.util.TimeZone; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import org.apache.commons.io.IOUtils; import org.codehaus.jackson.map.DeserializationConfig.Feature; import org.codehaus.jackson.map.ObjectMapper; @@ -240,19 +241,16 @@ private T _retrieve(String tailApiUrl, Class type, String method, boolean /** * Gets the {@link GHUser} that represents yourself. */ - public GHUser getMyself() throws IOException { + @WithBridgeMethods(GHUser.class) + public GHMyself getMyself() throws IOException { requireCredential(); - if (oauthAccessToken != null) { - GHUser u = retrieveWithAuth("/user/show", JsonUser.class).user; - - u.root = this; - users.put(u.getLogin(), u); - - return u; - } else { - return getUser(login); - } + GHMyself u = retrieveWithAuth("/user/show", JsonMyself.class).user; + + u.root = this; + users.put(u.getLogin(), u); + + return u; } /** diff --git a/src/main/java/org/kohsuke/github/JsonMyself.java b/src/main/java/org/kohsuke/github/JsonMyself.java new file mode 100644 index 0000000000..419d840d49 --- /dev/null +++ b/src/main/java/org/kohsuke/github/JsonMyself.java @@ -0,0 +1,8 @@ +package org.kohsuke.github; + +/** + * @author Kohsuke Kawaguchi + */ +class JsonMyself { + GHMyself user; +} diff --git a/src/test/java/org/kohsuke/AppTest.java b/src/test/java/org/kohsuke/AppTest.java index 8e49623f93..a9af305266 100644 --- a/src/test/java/org/kohsuke/AppTest.java +++ b/src/test/java/org/kohsuke/AppTest.java @@ -64,8 +64,8 @@ public void tryHook() throws Exception { for (GHHook h : r.getHooks()) h.delete(); } - - public void testApp() throws IOException { + + public void testEventApi() throws Exception { GitHub gitHub = GitHub.connect(); for (GHEventInfo ev : gitHub.getEvents()) { System.out.println(ev); @@ -75,6 +75,11 @@ public void testApp() throws IOException { System.out.println(pr.getPullRequest()); } } + } + + public void testApp() throws IOException { + GitHub gitHub = GitHub.connect(); + System.out.println(gitHub.getMyself().getEmails()); // GHRepository r = gitHub.connect().getOrganization("jenkinsci").createRepository("kktest4", "Kohsuke's test", "http://kohsuke.org/", "Everyone", true); // r.fork(); From 0da4b320f1fa5b44ebc562d56859910f3b93c5ac Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 8 Mar 2012 12:49:36 -0800 Subject: [PATCH 4/5] As per Sun coding convention, using upper case letters for enum constants --- .../java/org/kohsuke/github/GHMilestone.java | 145 +++++++++--------- .../org/kohsuke/github/GHMilestoneState.java | 4 +- 2 files changed, 75 insertions(+), 74 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java index 10b9cec909..e32f13843b 100644 --- a/src/main/java/org/kohsuke/github/GHMilestone.java +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -1,72 +1,73 @@ -package org.kohsuke.github; - -import java.util.Date; - -/** - * - * @author Yusuke Kokubo - * - */ -public class GHMilestone { - GitHub root; - GHRepository owner; - - GHUser creator; - private String state, due_on, title, url, created_at, description; - private int closed_issues, open_issues, number; - - public GitHub getRoot() { - return root; - } - - public GHRepository getOwner() { - return owner; - } - - public GHUser getCreator() { - return creator; - } - - public Date getDueOn() { - if (due_on == null) return null; - return GitHub.parseDate(due_on); - } - - public String getTitle() { - return title; - } - - public String getUrl() { - return url; - } - - public Date getCreatedAt() { - return GitHub.parseDate(created_at); - } - - public String getDescription() { - return description; - } - - public int getClosedIssues() { - return closed_issues; - } - - public int getOpenIssues() { - return open_issues; - } - - public int getNumber() { - return number; - } - - public GHMilestoneState getState() { - return Enum.valueOf(GHMilestoneState.class, state); - } - - public GHMilestone wrap(GHRepository repo) { - this.owner = repo; - this.root = repo.root; - return this; - } -} +package org.kohsuke.github; + +import java.util.Date; +import java.util.Locale; + +/** + * + * @author Yusuke Kokubo + * + */ +public class GHMilestone { + GitHub root; + GHRepository owner; + + GHUser creator; + private String state, due_on, title, url, created_at, description; + private int closed_issues, open_issues, number; + + public GitHub getRoot() { + return root; + } + + public GHRepository getOwner() { + return owner; + } + + public GHUser getCreator() { + return creator; + } + + public Date getDueOn() { + if (due_on == null) return null; + return GitHub.parseDate(due_on); + } + + public String getTitle() { + return title; + } + + public String getUrl() { + return url; + } + + public Date getCreatedAt() { + return GitHub.parseDate(created_at); + } + + public String getDescription() { + return description; + } + + public int getClosedIssues() { + return closed_issues; + } + + public int getOpenIssues() { + return open_issues; + } + + public int getNumber() { + return number; + } + + public GHMilestoneState getState() { + return Enum.valueOf(GHMilestoneState.class, state.toUpperCase(Locale.ENGLISH)); + } + + public GHMilestone wrap(GHRepository repo) { + this.owner = repo; + this.root = repo.root; + return this; + } +} diff --git a/src/main/java/org/kohsuke/github/GHMilestoneState.java b/src/main/java/org/kohsuke/github/GHMilestoneState.java index c4c1475672..92194546cb 100644 --- a/src/main/java/org/kohsuke/github/GHMilestoneState.java +++ b/src/main/java/org/kohsuke/github/GHMilestoneState.java @@ -6,6 +6,6 @@ * */ public enum GHMilestoneState { - open, - closed + OPEN, + CLOSED } \ No newline at end of file From 6898893ffb5efdff700e8dd558ee9770cf50ef28 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 8 Mar 2012 12:51:54 -0800 Subject: [PATCH 5/5] [maven-release-plugin] prepare release github-api-1.18 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f43ab355fa..7675cf7dee 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.18-SNAPSHOT + 1.18 GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java