Skip to content

Commit

Permalink
implmented milestone api via v3
Browse files Browse the repository at this point in the history
  • Loading branch information
y.kokubo committed Jan 13, 2012
1 parent 44f1038 commit fbcf3a1
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/main/java/org/kohsuke/github/GHMilestone.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
11 changes: 11 additions & 0 deletions src/main/java/org/kohsuke/github/GHMilestoneState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.kohsuke.github;

/**
*
* @author Yusuke Kokubo
*
*/
public enum GHMilestoneState {
open,
closed
}
31 changes: 31 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Integer,GHMilestone> milestones = new HashMap<Integer, GHMilestone>();

public String getDescription() {
return description;
Expand Down Expand Up @@ -436,6 +439,34 @@ public boolean remove(Object url) {
return this;
}

public Map<Integer, GHMilestone> getMilestones() throws IOException {
Map<Integer,GHMilestone> milestones = new TreeMap<Integer, GHMilestone>();
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;
Expand Down

0 comments on commit fbcf3a1

Please sign in to comment.