diff options
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 751f8918..3547d24f 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 4b44fa97..bd0fd115 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 6740b661..9ce5d471 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); + } + } |