Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

milestone api via v3 #6

Merged
merged 1 commit into from
Mar 8, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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