aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-10 17:07:53 (EDT)
committerChris Aniszczyk2011-04-10 17:18:11 (EDT)
commit052abaf070d99db240665456da9af53765438173 (patch)
tree40a5437e756433f29903dad972ccfb0330f9221e
parentf3ab380f132fef3b18f94a9be80268c757322200 (diff)
downloadegit-github-052abaf070d99db240665456da9af53765438173.zip
egit-github-052abaf070d99db240665456da9af53765438173.tar.gz
egit-github-052abaf070d99db240665456da9af53765438173.tar.bz2
Add support for creating issues using JSON POST requestrefs/changes/49/3049/4
Change-Id: Ifc25874f66fe153f8629e2375ff476b2a35aabb8 Signed-off-by: Kevin Sawicki <kevin@github.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java13
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java10
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java36
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java43
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java9
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/User.java9
6 files changed, 117 insertions, 3 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java
index fd2d2ea..e9b17da 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubClient.java
@@ -33,6 +33,7 @@ import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.auth.BasicScheme;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.protocol.Protocol;
/**
@@ -196,6 +197,7 @@ public class GitHubClient {
switch (status) {
case 200:
return parseJson(method, type);
+ case 400:
case 404:
case 500:
RequestError error = parseJson(method, RequestError.class);
@@ -223,9 +225,13 @@ public class GitHubClient {
public <V> V post(String uri, Map<String, String> params, Type type)
throws IOException {
PostMethod method = createPost(uri);
- if (params != null && !params.isEmpty())
- for (Entry<String, String> entry : params.entrySet())
- method.addParameter(entry.getKey(), entry.getValue());
+ if (params != null && !params.isEmpty()) {
+ StringBuilder payload = new StringBuilder();
+ this.gson.toJson(params, payload);
+ method.setRequestEntity(new StringRequestEntity(payload.toString(),
+ IGitHubConstants.CONTENT_TYPE_JSON,
+ IGitHubConstants.CHARSET_UTF8));
+ }
try {
int status = this.client.executeMethod(this.hostConfig, method);
@@ -235,6 +241,7 @@ public class GitHubClient {
if (type != null)
return parseJson(method, type);
break;
+ case 400:
case 404:
case 500:
RequestError error = parseJson(method, RequestError.class);
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java
index eab673d..0435edb 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java
@@ -52,4 +52,14 @@ public interface IGitHubConstants {
*/
String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; //$NON-NLS-1$
+ /**
+ * CONTENT_TYPE_JSON
+ */
+ String CONTENT_TYPE_JSON = "application/json"; //$NON-NLS-1$
+
+ /**
+ * CHARSET_UTF8
+ */
+ String CHARSET_UTF8 = "UTF-8"; //$NON-NLS-1$
+
}
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java
index f1947d0..f9528a2 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java
@@ -98,6 +98,15 @@ public class Issue {
}
/**
+ * @param milestone
+ * @return this issue
+ */
+ public Issue setMilestone(Milestone milestone) {
+ this.milestone = milestone;
+ return this;
+ }
+
+ /**
* @return body
*/
public String getBody() {
@@ -105,6 +114,15 @@ public class Issue {
}
/**
+ * @param body
+ * @return this issue
+ */
+ public Issue setBody(String body) {
+ this.body = body;
+ return this;
+ }
+
+ /**
* @return htmlUrl
*/
public String getHtmlUrl() {
@@ -126,6 +144,15 @@ public class Issue {
}
/**
+ * @param title
+ * @return this issue
+ */
+ public Issue setTitle(String title) {
+ this.title = title;
+ return this;
+ }
+
+ /**
* @return url
*/
public String getUrl() {
@@ -140,6 +167,15 @@ public class Issue {
}
/**
+ * @param assignee
+ * @return this issue
+ */
+ public Issue setAssignee(User assignee) {
+ this.assignee = assignee;
+ return this;
+ }
+
+ /**
* @return user
*/
public User getUser() {
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java
index 9e94379..5b2d8e9 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java
@@ -13,6 +13,7 @@ package org.eclipse.mylyn.github.internal;
import com.google.gson.reflect.TypeToken;
import java.io.IOException;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -61,6 +62,16 @@ public class IssueService {
*/
public static final String STATE_CLOSED = "closed";
+ /**
+ * Issue body field name
+ */
+ public static final String FIELD_BODY = "body";
+
+ /**
+ * Issue title field name
+ */
+ public static final String FIELD_TITLE = "title";
+
private GitHubClient client;
/**
@@ -138,4 +149,36 @@ public class IssueService {
issueToken.getType());
}
+ /**
+ * Create issue
+ *
+ * @param user
+ * @param repository
+ * @param issue
+ * @return created issue
+ * @throws IOException
+ */
+ public Issue createIssue(String user, String repository, Issue issue)
+ throws IOException {
+ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ uri.append('/').append(user).append('/').append(repository);
+ uri.append(IGitHubConstants.SEGMENT_ISSUES).append(
+ IGitHubConstants.SUFFIX_JSON);
+
+ Map<String, String> params = new HashMap<String, String>();
+ params.put(FIELD_BODY, issue.getBody());
+ params.put(FIELD_TITLE, issue.getTitle());
+ User assignee = issue.getAssignee();
+ if (assignee != null) {
+ params.put(FILTER_ASSIGNEE, assignee.getName());
+ }
+ Milestone milestone = issue.getMilestone();
+ if (milestone != null) {
+ params.put(FILTER_MILESTONE,
+ Integer.toString(milestone.getNumber()));
+ }
+
+ return this.client.post(uri.toString(), params, Issue.class);
+ }
+
}
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java
index fac305e..31ff4c9 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Milestone.java
@@ -68,6 +68,15 @@ public class Milestone {
}
/**
+ * @param number
+ * @return this milestone
+ */
+ public Milestone setNumber(int number) {
+ this.number = number;
+ return this;
+ }
+
+ /**
* @return openIssues
*/
public int getOpenIssues() {
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/User.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/User.java
index ae00a90..39c63ad 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/User.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/User.java
@@ -85,6 +85,15 @@ public class User {
}
/**
+ * @param name
+ * @return this user
+ */
+ public User setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ /**
* @return type
*/
public String getType() {