From fbcf3a17b4d1f8a9caaecdf7286b1ff0aa0859c4 Mon Sep 17 00:00:00 2001 From: "y.kokubo" Date: Fri, 13 Jan 2012 10:05:56 +0900 Subject: [PATCH] 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;