summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-12 12:53:39 (EDT)
committerChris Aniszczyk2011-04-12 14:11:43 (EDT)
commit259830869feaa6a1124d3c2a7e29eb7d72f71d40 (patch)
tree4d2a49f5934b7699a5e419632f3a1024968b6656
parent42903ba6de530176385170a0dc98e0054e981a31 (diff)
downloadegit-github-259830869feaa6a1124d3c2a7e29eb7d72f71d40.zip
egit-github-259830869feaa6a1124d3c2a7e29eb7d72f71d40.tar.gz
egit-github-259830869feaa6a1124d3c2a7e29eb7d72f71d40.tar.bz2
Add support for creating comments and issues using new APIrefs/changes/75/3075/2
Change-Id: If51002c9bd11505453d5d2cdfeca708f37ac1568 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/GitHubTaskDataHandler.java81
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Issue.java14
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java84
3 files changed, 129 insertions, 50 deletions
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 ce4fefc..f969052 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
@@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.mylyn.github.internal;
+import java.io.IOException;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@@ -170,16 +171,20 @@ public class GitHubTaskDataHandler extends AbstractTaskDataHandler {
return taskData;
}
- private GitHubIssue createIssue(TaskData taskData) {
- GitHubIssue issue = new GitHubIssue();
+ private Issue createIssue(TaskData taskData) {
+ Issue issue = new Issue();
if (!taskData.isNew()) {
- issue.setNumber(taskData.getTaskId());
+ issue.setNumber(Integer.parseInt(taskData.getTaskId()));
}
issue.setBody(getAttributeValue(taskData, GitHubTaskAttributes.BODY));
issue.setTitle(getAttributeValue(taskData, GitHubTaskAttributes.TITLE));
- issue.setState(getAttributeValue(taskData, GitHubTaskAttributes.STATUS));
- issue.setComment_new(getAttributeValue(taskData,
- GitHubTaskAttributes.COMMENT_NEW));
+
+ String assigneeValue = getAttributeValue(taskData,
+ GitHubTaskAttributes.ASSIGNEE);
+ if (assigneeValue != null) {
+ User assignee = new User().setName(assigneeValue);
+ issue.setAssignee(assignee);
+ }
return issue;
}
@@ -258,56 +263,56 @@ public class GitHubTaskDataHandler extends AbstractTaskDataHandler {
public RepositoryResponse postTaskData(TaskRepository repository,
TaskData taskData, Set<TaskAttribute> oldAttributes,
IProgressMonitor monitor) throws CoreException {
-
- GitHubIssue issue = createIssue(taskData);
+ String taskId = taskData.getTaskId();
+ Issue issue = createIssue(taskData);
String user = GitHub.computeTaskRepositoryUser(repository.getUrl());
String repo = GitHub.computeTaskRepositoryProject(repository.getUrl());
try {
- GitHubService service = connector.getService();
+ GitHubClient client = new GitHubClient();
GitHubCredentials credentials = GitHubCredentials
.create(repository);
+ client.setCredentials(credentials.getUsername(),
+ credentials.getPassword());
+ IssueService service = new IssueService(client);
if (taskData.isNew()) {
- issue = service.openIssue(user, repo, issue, credentials);
+ issue.setState(IssueService.STATE_OPEN);
+ issue = service.createIssue(user, repo, issue);
+ taskId = Integer.toString(issue.getNumber());
} else {
- // handle new comment
- if (issue.getComment_new() != null) {
- if (!"".equals(issue.getComment_new())) {
- service.addComment(user, repo, issue, credentials);
- }
- }
+ // Handle new comment
+ String comment = getAttributeValue(taskData,
+ GitHubTaskAttributes.COMMENT_NEW);
+ if (comment != null && comment.length() > 0)
+ service.createComment(user, repo, taskData.getTaskId(),
+ comment);
+ // Handle state change
TaskAttribute operationAttribute = taskData.getRoot()
.getAttribute(TaskAttribute.OPERATION);
- GitHubTaskOperation operation = null;
if (operationAttribute != null) {
- String opId = operationAttribute.getValue();
- operation = GitHubTaskOperation.fromId(opId);
-
- }
- if (operation != GitHubTaskOperation.LEAVE) {
- service.editIssue(user, repo, issue, credentials);
- switch (operation) {
- case REOPEN:
- service.reopenIssue(user, repo, issue, credentials);
- break;
- case CLOSE:
- service.closeIssue(user, repo, issue, credentials);
- break;
- default:
- throw new IllegalStateException("not implemented: "
- + operation);
- }
- } else {
- service.editIssue(user, repo, issue, credentials);
+ GitHubTaskOperation operation = GitHubTaskOperation
+ .fromId(operationAttribute.getValue());
+ if (operation != GitHubTaskOperation.LEAVE)
+ switch (operation) {
+ case REOPEN:
+ issue.setState(IssueService.STATE_OPEN);
+ break;
+ case CLOSE:
+ issue.setState(IssueService.STATE_CLOSED);
+ break;
+ default:
+ break;
+ }
}
+ service.editIssue(user, repo, issue);
}
return new RepositoryResponse(
taskData.isNew() ? ResponseKind.TASK_CREATED
- : ResponseKind.TASK_UPDATED, issue.getNumber());
- } catch (GitHubServiceException e) {
+ : ResponseKind.TASK_UPDATED, taskId);
+ } catch (IOException e) {
throw new CoreException(GitHub.createErrorStatus(e));
}
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 f9528a2..e669393 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
@@ -84,6 +84,13 @@ public class Issue {
}
/**
+ * @param number
+ */
+ public void setNumber(int number) {
+ this.number = number;
+ }
+
+ /**
* @return labels
*/
public List<Label> getLabels() {
@@ -137,6 +144,13 @@ public class Issue {
}
/**
+ * @param state
+ */
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ /**
* @return title
*/
public String getTitle() {
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 9798259..4f8578d 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
@@ -153,6 +153,28 @@ public class IssueService {
}
/**
+ * Create issue map for issue
+ *
+ * @param issue
+ * @return map
+ */
+ protected Map<String, String> createIssueMap(Issue issue) {
+ 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 params;
+ }
+
+ /**
* Create issue
*
* @param user
@@ -168,20 +190,58 @@ public class IssueService {
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()));
+ Map<String, String> params = createIssueMap(issue);
+ return this.client.post(uri.toString(), params, Issue.class);
+ }
+
+ /**
+ * Edit issue
+ *
+ * @param user
+ * @param repository
+ * @param issue
+ * @return created issue
+ * @throws IOException
+ */
+ public Issue editIssue(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);
+ uri.append('/').append(issue.getNumber())
+ .append(IGitHubConstants.SUFFIX_JSON);
+
+ Map<String, String> params = createIssueMap(issue);
+ String state = issue.getState();
+ if (state != null) {
+ params.put(FILTER_STATE, state);
}
+ return this.client.put(uri.toString(), params, Issue.class);
+ }
- return this.client.post(uri.toString(), params, Issue.class);
+ /**
+ * Create comment on specified issue id
+ *
+ * @param user
+ * @param repository
+ * @param issueId
+ * @param comment
+ * @return created issue
+ * @throws IOException
+ */
+ public Comment createComment(String user, String repository,
+ String issueId, String comment) throws IOException {
+ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS);
+ uri.append('/').append(user).append('/').append(repository);
+ uri.append(IGitHubConstants.SEGMENT_ISSUES);
+ uri.append('/').append(issueId);
+ uri.append(IGitHubConstants.SEGMENT_COMMENTS).append(
+ IGitHubConstants.SUFFIX_JSON);
+
+ Map<String, String> params = new HashMap<String, String>(1, 1);
+ params.put(FIELD_BODY, comment);
+
+ return this.client.post(uri.toString(), params, Comment.class);
}
}