Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-12 22:45:05 +0000
committerChris Aniszczyk2011-04-13 03:02:01 +0000
commit47dfb38bcb80afd0b7374602728febb445541197 (patch)
treedc15b444d089a9264ee26d7e2cd25f67d7e3ada2
parent86d91f1cf4402459647d49652f005be21301fa07 (diff)
downloadegit-github-47dfb38bcb80afd0b7374602728febb445541197.tar.gz
egit-github-47dfb38bcb80afd0b7374602728febb445541197.tar.xz
egit-github-47dfb38bcb80afd0b7374602728febb445541197.zip
Add support for updating labels when task data is posted
Change-Id: I264a37768eefd95af8346fd3cc5e4846fc9203b1 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/GitHubRepositoryConnector.java1
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubTaskDataHandler.java86
2 files changed, 81 insertions, 6 deletions
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 b36ab669..d08336cb 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
@@ -104,6 +104,7 @@ public class GitHubRepositoryConnector extends AbstractRepositoryConnector {
LabelService service = new LabelService(client);
try {
List<Label> labels = service.getLabels(user, project);
+ Collections.sort(labels, new LabelComparator());
this.repositoryLabels.put(repository, labels);
return labels;
} catch (IOException e) {
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 59b21cca..36552fb3 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
@@ -99,7 +99,8 @@ public class GitHubTaskDataHandler extends AbstractTaskDataHandler {
assigneeGravatar);
createAttribute(data, GitHubTaskAttributes.COMMENT_NEW);
- createAttribute(data, GitHubTaskAttributes.LABELS, issue.getLabels());
+
+ createLabels(repository, data, issue);
createMilestone(repository, data, issue);
@@ -131,6 +132,23 @@ public class GitHubTaskDataHandler extends AbstractTaskDataHandler {
milestone.getTitle());
}
+ private void createLabels(TaskRepository repository, TaskData data,
+ Issue issue) {
+ TaskAttribute labels = createAttribute(data,
+ GitHubTaskAttributes.LABELS, issue.getLabels());
+
+ if (!this.connector.hasCachedLabels(repository))
+ try {
+ this.connector.refreshLabels(repository);
+ } catch (CoreException ignore) {
+ // Ignored
+ }
+
+ List<Label> cachedLabels = this.connector.getLabels(repository);
+ for (Label label : cachedLabels)
+ labels.putOption(label.getName(), label.getName());
+ }
+
private void createOperations(TaskData data, Issue issue) {
TaskAttribute operationAttribute = data.getRoot().createAttribute(
TaskAttribute.OPERATION);
@@ -270,8 +288,8 @@ public class GitHubTaskDataHandler extends AbstractTaskDataHandler {
}
}
- private void createAttribute(TaskData data, GitHubTaskAttributes attribute,
- List<Label> values) {
+ private TaskAttribute createAttribute(TaskData data,
+ GitHubTaskAttributes attribute, List<Label> values) {
TaskAttribute attr = createAttribute(data, attribute);
if (values != null) {
List<String> labels = new LinkedList<String>();
@@ -280,6 +298,7 @@ public class GitHubTaskDataHandler extends AbstractTaskDataHandler {
}
data.getAttributeMapper().setValues(attr, labels);
}
+ return attr;
}
@Override
@@ -298,6 +317,60 @@ public class GitHubTaskDataHandler extends AbstractTaskDataHandler {
return true;
}
+ /**
+ * Update labels for issue
+ *
+ * @param user
+ * @param repo
+ * @param client
+ * @param repository
+ * @param data
+ * @param oldAttributes
+ * @throws IOException
+ */
+ protected void updateLabels(String user, String repo, GitHubClient client,
+ TaskRepository repository, TaskData data,
+ Set<TaskAttribute> oldAttributes) throws IOException {
+ // Update labels if changed
+ TaskAttribute labelsAttribute = data.getRoot().getAttribute(
+ GitHubTaskAttributes.LABELS.getId());
+ if (oldAttributes.contains(labelsAttribute)) {
+ LabelService labelService = new LabelService(client);
+
+ if (!this.connector.hasCachedLabels(repository))
+ try {
+ this.connector.refreshLabels(repository);
+ } catch (CoreException ignore) {
+ // Ignore
+ }
+ List<Label> currentLabels = this.connector.getLabels(repository);
+ List<Label> newLabels = new LinkedList<Label>();
+ List<Label> labels = new LinkedList<Label>();
+ for (String value : labelsAttribute.getValues()) {
+ Label label = new Label().setName(value);
+ if (!currentLabels.contains(label))
+ newLabels.add(label);
+ labels.add(label);
+ }
+ for (Label label : newLabels)
+ try {
+ labelService.createLabel(user, repo, label);
+ } catch (IOException e) {
+ // TODO detect failure and handle label already created
+ }
+
+ labelService.setLabels(user, repo, data.getTaskId(), labels);
+
+ if (!newLabels.isEmpty())
+ try {
+ this.connector.refreshLabels(repository);
+ } catch (CoreException ignore) {
+ // Ignore
+ }
+
+ }
+ }
+
@Override
public RepositoryResponse postTaskData(TaskRepository repository,
TaskData taskData, Set<TaskAttribute> oldAttributes,
@@ -324,8 +397,10 @@ public class GitHubTaskDataHandler extends AbstractTaskDataHandler {
String comment = getAttributeValue(taskData,
GitHubTaskAttributes.COMMENT_NEW);
if (comment != null && comment.length() > 0)
- service.createComment(user, repo, taskData.getTaskId(),
- comment);
+ service.createComment(user, repo, taskId, comment);
+
+ updateLabels(user, repo, client, repository, taskData,
+ oldAttributes);
// Handle state change
TaskAttribute operationAttribute = taskData.getRoot()
@@ -356,5 +431,4 @@ public class GitHubTaskDataHandler extends AbstractTaskDataHandler {
}
}
-
}

Back to the top