aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-07 18:28:38 (EDT)
committerKevin Sawicki2011-04-07 20:05:19 (EDT)
commit89204272ead774d6d82b1a380e6f12ace09cb6f6 (patch)
tree4edbd207e39c7e623c88e2226ca4aa9c00a7dd93
parent7bb025dac9ba6c7275e9bd43c584bfb2ee4933f6 (diff)
downloadegit-github-89204272ead774d6d82b1a380e6f12ace09cb6f6.zip
egit-github-89204272ead774d6d82b1a380e6f12ace09cb6f6.tar.gz
egit-github-89204272ead774d6d82b1a380e6f12ace09cb6f6.tar.bz2
Add ability to view comments on an issue.refs/changes/22/3022/4
Adds service support for getting a list of comments and maps them as task attributes. Bug: 340901 Change-Id: I0210346e20125e50fc28f5be6aa0a9af5f0562f0 Signed-off-by: Kevin Sawicki <kevin@github.com>
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssue.java21
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssueComment.java83
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssueComments.java33
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java9
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java35
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java26
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPage.java5
7 files changed, 204 insertions, 8 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssue.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssue.java
index 0d581a0..f6914b0 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssue.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssue.java
@@ -28,6 +28,8 @@ public class GitHubIssue {
private String comment_new;
+ private int comments;
+
/**
* open, closed
*/
@@ -181,4 +183,23 @@ public class GitHubIssue {
public void setComment_new(String comment_new) {
this.comment_new = comment_new;
}
+
+ /**
+ * Get number of comments issue has
+ *
+ * @return comments
+ */
+ public int getComments() {
+ return this.comments;
+ }
+
+ /**
+ * Set number of comments that issue has
+ *
+ * @param comments
+ */
+ public void setComments(int comments) {
+ this.comments = comments;
+ }
+
}
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssueComment.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssueComment.java
new file mode 100644
index 0000000..9a5ddda
--- /dev/null
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssueComment.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.github.internal;
+
+import java.util.Date;
+
+/**
+ * GitHub issue comment class.
+ *
+ * @author Kevin Sawicki (kevin@github.com)
+ */
+public class GitHubIssueComment {
+
+ private String gravatar_id;
+ private Date created_at;
+ private String body;
+ private Date updated_at;
+ private String id;
+ private String user;
+
+ /**
+ * Get gravatar id
+ *
+ * @return gravatar id
+ */
+ public String getGravatarId() {
+ return this.gravatar_id;
+ }
+
+ /**
+ * Get created at date
+ *
+ * @return created date
+ */
+ public Date getCreatedAt() {
+ return this.created_at;
+ }
+
+ /**
+ * Get body
+ *
+ * @return body
+ */
+ public String getBody() {
+ return this.body;
+ }
+
+ /**
+ * Get updated at date
+ *
+ * @return date
+ */
+ public Date getUpdatedAt() {
+ return this.updated_at;
+ }
+
+ /**
+ * Get id
+ *
+ * @return id
+ */
+ public String getId() {
+ return this.id;
+ }
+
+ /**
+ * Get user
+ *
+ * @return user
+ */
+ public String getUser() {
+ return this.user;
+ }
+
+}
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssueComments.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssueComments.java
new file mode 100644
index 0000000..85079e8
--- /dev/null
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubIssueComments.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.github.internal;
+
+import java.util.List;
+
+/**
+ * GitHub issue comments wrapper class.
+ *
+ * @author Kevin Sawicki (kevin@github.com)
+ */
+public class GitHubIssueComments {
+
+ private List<GitHubIssueComment> comments;
+
+ /**
+ * Get comments
+ *
+ * @return list of comments
+ */
+ public List<GitHubIssueComment> getComments() {
+ return this.comments;
+ }
+
+}
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java
index 681bdb7..8b4b744 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java
@@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.mylyn.github.internal;
+import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -156,7 +157,13 @@ public class GitHubRepositoryConnector extends AbstractRepositoryConnector {
try {
GitHubCredentials credentials = GitHubCredentials.create(repository);
GitHubIssue issue = service.showIssue(user, project, taskId, credentials);
- TaskData taskData = taskDataHandler.createTaskData(repository, monitor, user, project, issue);
+ List<GitHubIssueComment> comments = null;
+ if (issue.getComments() > 0) {
+ comments = service.getComments(user, project, issue,
+ credentials);
+ }
+ TaskData taskData = taskDataHandler.createTaskData(repository,
+ monitor, user, project, issue, comments);
return taskData;
} catch (GitHubServiceException e) {
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java
index 9a5b743..cf89769 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubService.java
@@ -13,7 +13,9 @@
package org.eclipse.mylyn.github.internal;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.Date;
+import java.util.List;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
@@ -62,6 +64,7 @@ public class GitHubService {
private final static String CLOSE = "close/";
private final static String EDIT = "edit/"; // Implemented
private final static String COMMENT = "comment/";
+ private final static String COMMENTS = "comments/";
// private final static String VIEW = "view/";
private final static String SHOW = "show/"; // :user/:repo/:number
private final static String LIST = "list/"; // Implemented
@@ -658,4 +661,36 @@ public class GitHubService {
}
}
}
+
+ /**
+ * Get comments associated with issue
+ *
+ * @param user
+ * @param repo
+ * @param issue
+ * @param credentials
+ * @return collection of comments
+ * @throws GitHubServiceException
+ */
+ public List<GitHubIssueComment> getComments(final String user,
+ final String repo, final GitHubIssue issue,
+ final GitHubCredentials credentials) throws GitHubServiceException {
+ GetMethod method = null;
+ try {
+ method = new GetMethod(gitURLBase + gitIssueRoot + COMMENTS + user
+ + "/" + repo + "/" + issue.getNumber());
+ setCredentials(credentials);
+ executeMethod(method);
+ return this.gson.fromJson(
+ new InputStreamReader(method.getResponseBodyAsStream()),
+ GitHubIssueComments.class).getComments();
+ } catch (IOException e) {
+ throw new GitHubServiceException(e);
+ } finally {
+ if (method != null) {
+ method.releaseConnection();
+ }
+ }
+ }
+
}
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java
index 182b92f..3a54748 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java
@@ -16,6 +16,7 @@ import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.List;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
@@ -28,6 +29,7 @@ import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData;
+import org.eclipse.mylyn.tasks.core.data.TaskCommentMapper;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.core.data.TaskOperation;
@@ -158,10 +160,30 @@ public class GitHubTaskDataHandler extends AbstractTaskDataHandler {
public TaskData createTaskData(TaskRepository repository,
IProgressMonitor monitor, String user, String project,
- GitHubIssue issue) {
- TaskData taskData = createPartialTaskData(repository, monitor, user, project, issue);
+ GitHubIssue issue, List<GitHubIssueComment> comments) {
+ TaskData taskData = createPartialTaskData(repository, monitor, user,
+ project, issue);
taskData.setPartial(false);
+ if (comments != null && !comments.isEmpty()) {
+ int count = 1;
+ TaskAttribute root = taskData.getRoot();
+ for (GitHubIssueComment comment : comments) {
+ TaskCommentMapper commentMapper = new TaskCommentMapper();
+ commentMapper.setAuthor(repository.createPerson(comment
+ .getUser()));
+ commentMapper.setCreationDate(comment.getCreatedAt());
+ commentMapper.setText(comment.getBody());
+ commentMapper.setCommentId(comment.getId());
+ commentMapper.setNumber(count);
+
+ TaskAttribute attribute = root
+ .createAttribute(TaskAttribute.PREFIX_COMMENT + count);
+ commentMapper.applyTo(attribute);
+ count++;
+ }
+ }
+
return taskData;
}
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPage.java
index a24d8cb..993012e 100644
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPage.java
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPage.java
@@ -48,11 +48,6 @@ public class GitHubTaskEditorPage extends AbstractTaskEditorPage {
TaskEditorPartDescriptor partDescriptor = descriptorIt.next();
if (partDescriptor.getId().equals(ID_PART_ATTRIBUTES)) {
descriptorIt.remove();
- } else if (partDescriptor.getId().equals(ID_PART_COMMENTS)) {
- // currently the API doesn't support reading existing comments,
- // though it does allow for creating them. Silly really.
- // see http://support.github.com/discussions/feature-requests/696-issues-api-improvement
- descriptorIt.remove();
}
}
return partDescriptors;