summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-12 17:09:56 (EDT)
committer Chris Aniszczyk2011-04-12 22:58:53 (EDT)
commit60ab00a54802cc2cad4b90d739eb519a3f5d5fca (patch)
tree584a45ea7a730185a69c31c2bcdd14ee10523876
parent75045fcbd780e5fe5f841013f45d7ce0aadfc342 (diff)
downloadegit-github-60ab00a54802cc2cad4b90d739eb519a3f5d5fca.zip
egit-github-60ab00a54802cc2cad4b90d739eb519a3f5d5fca.tar.gz
egit-github-60ab00a54802cc2cad4b90d739eb519a3f5d5fca.tar.bz2
Add support for setting an issue's milestonerefs/changes/81/3081/2
Change-Id: Ie28ac8c2d252c68e04eb3f9911fac9ee74f2e4a2 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.java73
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IssueService.java11
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Messages.java3
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/messages.properties1
4 files changed, 69 insertions, 19 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 7150deb..59b21cc 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
@@ -33,15 +33,21 @@ import org.eclipse.mylyn.tasks.core.data.TaskCommentMapper;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.core.data.TaskOperation;
+/**
+ * GitHub issue task data handler
+ */
public class GitHubTaskDataHandler extends AbstractTaskDataHandler {
- private static final String DATA_VERSION = "1";
- /**
- *
- */
+ private static final String DATA_VERSION = "1"; //$NON-NLS-1$
+ private static final String MILESTONE_NONE_KEY = "0"; //$NON-NLS-1$
private GitHubTaskAttributeMapper taskAttributeMapper = null;
private final GitHubRepositoryConnector connector;
+ /**
+ * Create GitHub issue task data handler for connector
+ *
+ * @param connector
+ */
public GitHubTaskDataHandler(GitHubRepositoryConnector connector) {
this.connector = connector;
}
@@ -92,25 +98,52 @@ public class GitHubTaskDataHandler extends AbstractTaskDataHandler {
createAttribute(data, GitHubTaskAttributes.ASSIGNEE_GRAVATAR,
assigneeGravatar);
- createAttribute(data, GitHubTaskAttributes.COMMENT_NEW, "");
+ createAttribute(data, GitHubTaskAttributes.COMMENT_NEW);
createAttribute(data, GitHubTaskAttributes.LABELS, issue.getLabels());
+ createMilestone(repository, data, issue);
+
return data;
}
+ private void createMilestone(TaskRepository repository, TaskData data,
+ Issue issue) {
+ Milestone current = issue.getMilestone();
+ String number = current != null ? Integer.toString(current.getNumber())
+ : MILESTONE_NONE_KEY;
+ TaskAttribute milestoneAttribute = createAttribute(data,
+ GitHubTaskAttributes.MILESTONE, number);
+
+ if (!this.connector.hasCachedMilestones(repository))
+ try {
+ this.connector.refreshMilestones(repository);
+ } catch (CoreException ignore) {
+ // Ignored
+ }
+
+ List<Milestone> cachedMilestones = this.connector
+ .getMilestones(repository);
+ milestoneAttribute.putOption(MILESTONE_NONE_KEY,
+ Messages.GitHubTaskDataHandler_MilestoneNone);
+ for (Milestone milestone : cachedMilestones)
+ milestoneAttribute.putOption(
+ Integer.toString(milestone.getNumber()),
+ milestone.getTitle());
+ }
+
private void createOperations(TaskData data, Issue issue) {
TaskAttribute operationAttribute = data.getRoot().createAttribute(
TaskAttribute.OPERATION);
operationAttribute.getMetaData().setType(TaskAttribute.TYPE_OPERATION);
if (!data.isNew()) {
- if (issue.getState() != null) {
+ String state = issue.getState();
+ if (state != null) {
addOperation(data, issue, GitHubTaskOperation.LEAVE, true);
- if (issue.getState().equals("open")) {
+ if (state.equals(IssueService.STATE_OPEN))
addOperation(data, issue, GitHubTaskOperation.CLOSE, false);
- } else if (issue.getState().equals("closed")) {
+ else if (state.equals(IssueService.STATE_CLOSED))
addOperation(data, issue, GitHubTaskOperation.REOPEN, false);
- }
}
}
}
@@ -138,8 +171,8 @@ public class GitHubTaskDataHandler extends AbstractTaskDataHandler {
public TaskData createTaskData(TaskRepository repository,
IProgressMonitor monitor, String user, String project, Issue issue,
List<Comment> comments) {
- TaskData taskData = createTaskData(repository, monitor, user,
- project, issue);
+ TaskData taskData = createTaskData(repository, monitor, user, project,
+ issue);
taskData.setPartial(false);
if (comments != null && !comments.isEmpty()) {
@@ -181,6 +214,14 @@ public class GitHubTaskDataHandler extends AbstractTaskDataHandler {
User assignee = new User().setName(assigneeValue);
issue.setAssignee(assignee);
}
+
+ String milestoneValue = getAttributeValue(taskData,
+ GitHubTaskAttributes.MILESTONE);
+ if (milestoneValue != null) {
+ Milestone milestone = new Milestone().setNumber(Integer
+ .parseInt(milestoneValue));
+ issue.setMilestone(milestone);
+ }
return issue;
}
@@ -200,20 +241,22 @@ public class GitHubTaskDataHandler extends AbstractTaskDataHandler {
return attr;
}
- private void createAttribute(TaskData data, GitHubTaskAttributes attribute,
- String value) {
+ private TaskAttribute createAttribute(TaskData data,
+ GitHubTaskAttributes attribute, String value) {
TaskAttribute attr = createAttribute(data, attribute);
if (value != null) {
data.getAttributeMapper().setValue(attr, value);
}
+ return attr;
}
- private void createAttribute(TaskData data, GitHubTaskAttributes attribute,
- Date value) {
+ private TaskAttribute createAttribute(TaskData data,
+ GitHubTaskAttributes attribute, Date value) {
TaskAttribute attr = createAttribute(data, attribute);
if (value != null) {
data.getAttributeMapper().setDateValue(attr, value);
}
+ return attr;
}
private void createAttribute(TaskData data, GitHubTaskAttributes attribute,
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 4f8578d..6254a57 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
@@ -163,13 +163,16 @@ public class IssueService {
params.put(FIELD_BODY, issue.getBody());
params.put(FIELD_TITLE, issue.getTitle());
User assignee = issue.getAssignee();
- if (assignee != null) {
+ if (assignee != null)
params.put(FILTER_ASSIGNEE, assignee.getName());
- }
+
Milestone milestone = issue.getMilestone();
if (milestone != null) {
- params.put(FILTER_MILESTONE,
- Integer.toString(milestone.getNumber()));
+ int number = milestone.getNumber();
+ if (number > 0)
+ params.put(FILTER_MILESTONE, Integer.toString(number));
+ else
+ params.put(FILTER_MILESTONE, ""); //$NON-NLS-1$
}
return params;
}
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Messages.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Messages.java
index 052fbe1..23d7159 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Messages.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/Messages.java
@@ -73,6 +73,9 @@ public class Messages extends NLS {
/** */
public static String GitHubTaskAttributes_LabelStatus;
+ /** */
+ public static String GitHubTaskDataHandler_MilestoneNone;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/messages.properties b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/messages.properties
index 8ecbd90..942b955 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/messages.properties
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/messages.properties
@@ -16,3 +16,4 @@ GitHubTaskAttributes_LabelModified=Modified:
GitHubTaskAttributes_LabelReporter=Reporter:
GitHubTaskAttributes_LabelReporterGravatar=Reporter
GitHubTaskAttributes_LabelStatus=Status:
+GitHubTaskDataHandler_MilestoneNone=None