protected void updateLabels()

in org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueTaskDataHandler.java [279:317]


	protected void updateLabels(String user, String repo, GitHubClient client,
			TaskRepository repository, TaskData data,
			Set<TaskAttribute> oldAttributes, Issue issue) {
		TaskAttribute labelsAttribute = data.getRoot().getAttribute(
				IssueAttribute.LABELS.getMetadata().getId());
		if (oldAttributes.contains(labelsAttribute) || data.isNew()) {
			LabelService labelService = new LabelService(client);

			if (!connector.hasCachedLabels(repository))
				try {
					connector.refreshLabels(repository);
				} catch (CoreException ignore) {
					// Ignore
				}
			List<Label> currentLabels = connector.getLabels(repository);
			List<Label> newLabels = new LinkedList<>();
			List<Label> labels = new LinkedList<>();
			for (String value : labelsAttribute.getValues()) {
				Label label = new Label().setName(value);
				if (!currentLabels.contains(label))
					newLabels.add(label);
				labels.add(label);
			}
			issue.setLabels(labels);
			for (Label label : newLabels)
				try {
					labelService.createLabel(user, repo, label);
				} catch (IOException e) {
					// TODO detect failure and handle label already created
				}

			if (!newLabels.isEmpty())
				try {
					connector.refreshLabels(repository);
				} catch (CoreException ignore) {
					// Ignore
				}
		}
	}