summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-12 18:28:53 (EDT)
committerChris Aniszczyk2011-04-12 23:00:43 (EDT)
commit86d91f1cf4402459647d49652f005be21301fa07 (patch)
tree643b63b29f4b48918d9239e5a8595978c927e4cf
parent60ab00a54802cc2cad4b90d739eb519a3f5d5fca (diff)
downloadegit-github-86d91f1cf4402459647d49652f005be21301fa07.zip
egit-github-86d91f1cf4402459647d49652f005be21301fa07.tar.gz
egit-github-86d91f1cf4402459647d49652f005be21301fa07.tar.bz2
Add support for creating/setting an issue's labelsrefs/changes/85/3085/2
Change-Id: I557fdbfcc33f9f1e0934cf2d34d20edafb8e4e0e 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.java10
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Label.java22
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/LabelService.java43
3 files changed, 65 insertions, 10 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 751f891..3547d24 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
@@ -236,8 +236,8 @@ public class GitHubClient {
* @throws IOException
*/
protected <V> V sendJson(EntityEnclosingMethod method,
- Map<String, String> params, Type type) throws IOException {
- if (params != null && !params.isEmpty()) {
+ Object params, Type type) throws IOException {
+ if (params != null) {
StringBuilder payload = new StringBuilder();
this.gson.toJson(params, payload);
method.setRequestEntity(new StringRequestEntity(payload.toString(),
@@ -278,8 +278,7 @@ public class GitHubClient {
* @return response
* @throws IOException
*/
- public <V> V post(String uri, Map<String, String> params, Type type)
- throws IOException {
+ public <V> V post(String uri, Object params, Type type) throws IOException {
PostMethod method = createPost(uri);
return sendJson(method, params, type);
}
@@ -294,8 +293,7 @@ public class GitHubClient {
* @return response
* @throws IOException
*/
- public <V> V put(String uri, Map<String, String> params, Type type)
- throws IOException {
+ public <V> V put(String uri, Object params, Type type) throws IOException {
PutMethod method = createPut(uri);
return sendJson(method, params, type);
}
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Label.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Label.java
index 4b44fa9..bd0fd11 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Label.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Label.java
@@ -12,8 +12,6 @@ package org.eclipse.mylyn.github.internal;
/**
* GitHub issue label class.
- *
- * @author Kevin Sawicki (kevin@github.com)
*/
public class Label {
@@ -24,6 +22,17 @@ public class Label {
private String url;
/**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ if (obj == this)
+ return true;
+
+ return obj instanceof Label && this.name != null
+ && this.name.equals(((Label) obj).name);
+ }
+
+ /**
* @return color
*/
public String getColor() {
@@ -38,6 +47,15 @@ public class Label {
}
/**
+ * @param name
+ * @return this label
+ */
+ public Label setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ /**
* @return url
*/
public String getUrl() {
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/LabelService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/LabelService.java
index 6740b66..9ce5d47 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/LabelService.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/LabelService.java
@@ -20,8 +20,6 @@ import org.eclipse.core.runtime.Assert;
/**
* Label service class for listing {@link Label} objects in use for a given user
* and repository.
- *
- * @author Kevin Sawicki (kevin@github.com)
*/
public class LabelService {
@@ -56,4 +54,45 @@ public class LabelService {
return this.client.get(uri.toString(), labelToken.getType());
}
+ /**
+ * Set the labels for an issue
+ *
+ * @param user
+ * @param repository
+ * @param issueId
+ * @param labels
+ * @return list of labels
+ * @throws IOException
+ */
+ public List<Label> setLabels(String user, String repository,
+ String issueId, List<Label> labels) throws IOException {
+ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ uri.append('/').append(user).append('/').append(repository);
+ uri.append(IGitHubConstants.SEGMENT_ISSUES).append('/').append(issueId);
+ uri.append(IGitHubConstants.SEGMENT_LABELS).append(
+ IGitHubConstants.SUFFIX_JSON);
+
+ TypeToken<List<Label>> labelToken = new TypeToken<List<Label>>() {
+ };
+ return this.client.put(uri.toString(), labels, labelToken.getType());
+ }
+
+ /**
+ * Create label
+ *
+ * @param user
+ * @param repository
+ * @param label
+ * @return created label
+ * @throws IOException
+ */
+ public Label createLabel(String user, String repository, Label label)
+ throws IOException {
+ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ uri.append('/').append(user).append('/').append(repository);
+ uri.append(IGitHubConstants.SEGMENT_LABELS).append(
+ IGitHubConstants.SUFFIX_JSON);
+ return this.client.post(uri.toString(), label, Label.class);
+ }
+
}