Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn2011-05-09 22:46:40 +0000
committerCode Review2011-05-09 22:46:40 +0000
commitf4ac39b90e9b8fb341b7063ddbfd1d8f316ea190 (patch)
tree398eb889163e4f8460b03d885b2aed1d9a7e6017 /org.eclipse.mylyn.github.core/src
parentabc07605b064b7454f6b3c168c8d79a8fea19358 (diff)
parent1402bf6cb498a7199a90fedac97b2e93ffbbbe13 (diff)
downloadegit-github-f4ac39b90e9b8fb341b7063ddbfd1d8f316ea190.tar.gz
egit-github-f4ac39b90e9b8fb341b7063ddbfd1d8f316ea190.tar.xz
egit-github-f4ac39b90e9b8fb341b7063ddbfd1d8f316ea190.zip
Merge changes If30795d3,I4e635bea
* changes: Enforce UTF-8 encoding and unix line endings Fix line endings
Diffstat (limited to 'org.eclipse.mylyn.github.core/src')
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRepositoryConnector.java794
1 files changed, 397 insertions, 397 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 5a7a6f29..2757f1a0 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
@@ -1,397 +1,397 @@
-/*******************************************************************************
- * Copyright (c) 2011 Red Hat and others.
- * 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:
- * David Green <david.green@tasktop.com> - initial contribution
- * Christian Trutz <christian.trutz@gmail.com> - initial contribution
- * Chris Aniszczyk <caniszczyk@gmail.com> - initial contribution
- *******************************************************************************/
-package org.eclipse.mylyn.github.internal;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
-import org.eclipse.mylyn.commons.net.AuthenticationType;
-import org.eclipse.mylyn.commons.net.Policy;
-import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
-import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
-import org.eclipse.mylyn.tasks.core.ITask;
-import org.eclipse.mylyn.tasks.core.TaskRepository;
-import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler;
-import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
-import org.eclipse.mylyn.tasks.core.data.TaskData;
-import org.eclipse.mylyn.tasks.core.data.TaskDataCollector;
-import org.eclipse.mylyn.tasks.core.data.TaskMapper;
-import org.eclipse.mylyn.tasks.core.sync.ISynchronizationSession;
-
-/**
- * GitHub connector.
- */
-public class GitHubRepositoryConnector extends AbstractRepositoryConnector {
-
- /**
- * GitHub kind.
- */
- public static final String KIND = GitHub.CONNECTOR_KIND;
-
- /**
- * Create client for repository
- *
- * @param repository
- * @return client
- */
- public static GitHubClient createClient(TaskRepository repository) {
- GitHubClient client = new GitHubClient();
- AuthenticationCredentials credentials = repository
- .getCredentials(AuthenticationType.REPOSITORY);
- if (credentials != null)
- client.setCredentials(credentials.getUserName(),
- credentials.getPassword());
- return client;
- }
-
- /**
- * GitHub specific {@link AbstractTaskDataHandler}.
- */
- private final GitHubTaskDataHandler taskDataHandler;
-
- private final Map<TaskRepository, List<Label>> repositoryLabels = Collections
- .synchronizedMap(new HashMap<TaskRepository, List<Label>>());
-
- private final Map<TaskRepository, List<Milestone>> repositoryMilestones = Collections
- .synchronizedMap(new HashMap<TaskRepository, List<Milestone>>());
-
- /**
- * Create GitHub issue repository connector
- */
- public GitHubRepositoryConnector() {
- taskDataHandler = new GitHubTaskDataHandler(this);
- }
-
- /**
- * Refresh labels for repository
- *
- * @param repository
- * @return labels
- * @throws CoreException
- */
- public List<Label> refreshLabels(TaskRepository repository)
- throws CoreException {
- Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$
- Repository repo = GitHub.getRepository(repository.getRepositoryUrl());
- GitHubClient client = createClient(repository);
- LabelService service = new LabelService(client);
- try {
- List<Label> labels = service.getLabels(repo.getOwner(),
- repo.getName());
- Collections.sort(labels, new LabelComparator());
- this.repositoryLabels.put(repository, labels);
- return labels;
- } catch (IOException e) {
- throw new CoreException(GitHub.createErrorStatus(e));
- }
- }
-
- /**
- * Get labels for task repository.
- *
- * @param repository
- * @return non-null but possibly empty list of labels
- */
- public List<Label> getLabels(TaskRepository repository) {
- Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$
- List<Label> labels = new LinkedList<Label>();
- List<Label> cached = this.repositoryLabels.get(repository);
- if (cached != null) {
- labels.addAll(cached);
- }
- return labels;
- }
-
- /**
- * Are there cached labels for the specified task repository?
- *
- * @param repository
- * @return true if contains labels, false otherwise
- */
- public boolean hasCachedLabels(TaskRepository repository) {
- return this.repositoryLabels.containsKey(repository);
- }
-
- /**
- * Refresh milestones for repository
- *
- * @param repository
- * @return milestones
- * @throws CoreException
- */
- public List<Milestone> refreshMilestones(TaskRepository repository)
- throws CoreException {
- Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$
- Repository repo = GitHub.getRepository(repository.getRepositoryUrl());
- GitHubClient client = createClient(repository);
- MilestoneService service = new MilestoneService(client);
- try {
- List<Milestone> milestones = new LinkedList<Milestone>();
- milestones.addAll(service.getMilestones(repo.getOwner(),
- repo.getName(), IssueService.STATE_OPEN));
- milestones.addAll(service.getMilestones(repo.getOwner(),
- repo.getName(), IssueService.STATE_CLOSED));
- this.repositoryMilestones.put(repository, milestones);
- return milestones;
- } catch (IOException e) {
- throw new CoreException(GitHub.createErrorStatus(e));
- }
- }
-
- /**
- * Get milestones for task repository.
- *
- * @param repository
- * @return non-null but possibly empty list of milestones
- */
- public List<Milestone> getMilestones(TaskRepository repository) {
- Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$
- List<Milestone> milestones = new LinkedList<Milestone>();
- List<Milestone> cached = this.repositoryMilestones.get(repository);
- if (cached != null) {
- milestones.addAll(cached);
- }
- return milestones;
- }
-
- /**
- * Are there cached milestones for the specified task repository?
- *
- * @param repository
- * @return true if contains milestones, false otherwise
- */
- public boolean hasCachedMilestones(TaskRepository repository) {
- return this.repositoryMilestones.containsKey(repository);
- }
-
- /**
- * {@inheritDoc}
- *
- * @return always {@code true}
- */
- @Override
- public boolean canCreateNewTask(TaskRepository repository) {
- return true;
- }
-
- /**
- * {@inheritDoc}
- *
- * @return always {@code true}
- */
- @Override
- public boolean canCreateTaskFromKey(TaskRepository repository) {
- return true;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see #KIND
- */
- @Override
- public String getConnectorKind() {
- return KIND;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getLabel() {
- return Messages.GitHubRepositoryConnector_LabelConnector;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public AbstractTaskDataHandler getTaskDataHandler() {
- return this.taskDataHandler;
- }
-
- @Override
- public IStatus performQuery(TaskRepository repository,
- IRepositoryQuery query, TaskDataCollector collector,
- ISynchronizationSession session, IProgressMonitor monitor) {
- IStatus result = Status.OK_STATUS;
- List<String> statuses = QueryUtils.getAttributes(
- IssueService.FILTER_STATE, query);
-
- monitor.beginTask(Messages.GitHubRepositoryConnector_TaskQuerying,
- statuses.size());
- try {
- Repository repo = GitHub.getRepository(repository
- .getRepositoryUrl());
-
- GitHubClient client = createClient(repository);
- IssueService service = new IssueService(client);
-
- Map<String, String> filterData = new HashMap<String, String>();
- String mentions = query.getAttribute(IssueService.FILTER_MENTIONED);
- if (mentions != null)
- filterData.put(IssueService.FILTER_MENTIONED, mentions);
-
- String assignee = query.getAttribute(IssueService.FILTER_ASSIGNEE);
- if (assignee != null)
- filterData.put(IssueService.FILTER_ASSIGNEE, assignee);
-
- String milestone = query
- .getAttribute(IssueService.FILTER_MILESTONE);
- if (milestone != null)
- filterData.put(IssueService.FILTER_MILESTONE, milestone);
-
- List<String> labels = QueryUtils.getAttributes(
- IssueService.FILTER_LABELS, query);
- if (!labels.isEmpty()) {
- StringBuilder labelsQuery = new StringBuilder();
- for (String label : labels)
- labelsQuery.append(label).append(',');
- filterData.put(IssueService.FILTER_LABELS,
- labelsQuery.toString());
- }
-
- for (String status : statuses) {
- filterData.put(IssueService.FILTER_STATE, status);
- List<Issue> issues = service.getIssues(repo.getOwner(),
- repo.getName(), filterData);
-
- // collect task data
- for (Issue issue : issues) {
- TaskData taskData = taskDataHandler.createTaskData(
- repository, monitor, repo.getOwner(),
- repo.getName(), issue);
- taskData.setPartial(true);
- collector.accept(taskData);
- }
- monitor.worked(1);
- }
-
- result = Status.OK_STATUS;
- } catch (IOException e) {
- result = GitHub.createErrorStatus(e);
- }
-
- monitor.done();
- return result;
- }
-
- @Override
- public TaskData getTaskData(TaskRepository repository, String taskId,
- IProgressMonitor monitor) throws CoreException {
- Repository repo = GitHub.getRepository(repository.getRepositoryUrl());
-
- try {
- GitHubClient client = createClient(repository);
- IssueService service = new IssueService(client);
- Issue issue = service.getIssue(repo.getOwner(), repo.getName(),
- taskId);
- List<Comment> comments = null;
- if (issue.getComments() > 0) {
- comments = service.getComments(repo.getOwner(), repo.getName(),
- taskId);
- }
- TaskData taskData = taskDataHandler.createTaskData(repository,
- monitor, repo.getOwner(), repo.getName(), issue, comments);
-
- return taskData;
- } catch (IOException e) {
- throw new CoreException(GitHub.createErrorStatus(e));
- }
- }
-
- @Override
- public String getRepositoryUrlFromTaskUrl(String taskFullUrl) {
- if (taskFullUrl != null) {
- Matcher matcher = Pattern.compile(
- "(http://.+?)/issues/issue/([^/]+)").matcher(taskFullUrl); //$NON-NLS-1$
- if (matcher.matches()) {
- return matcher.group(1);
- }
- }
- return null;
- }
-
- @Override
- public String getTaskIdFromTaskUrl(String taskFullUrl) {
- if (taskFullUrl != null) {
- Matcher matcher = Pattern
- .compile(".+?/issues/issue/([^/]+)").matcher(taskFullUrl); //$NON-NLS-1$
- if (matcher.matches()) {
- return matcher.group(1);
- }
- }
- return null;
- }
-
- @Override
- public String getTaskUrl(String repositoryUrl, String taskId) {
- return repositoryUrl + "/issues/issue/" + taskId; //$NON-NLS-1$
- }
-
- @Override
- public void updateRepositoryConfiguration(TaskRepository taskRepository,
- IProgressMonitor monitor) throws CoreException {
- monitor = Policy.monitorFor(monitor);
- monitor.beginTask("", 2); //$NON-NLS-1$
- monitor.setTaskName(Messages.GitHubRepositoryConnector_TaskUpdatingLabels);
- refreshLabels(taskRepository);
- monitor.worked(1);
- monitor.setTaskName(Messages.GitHubRepositoryConnector_TaskUpdatingMilestones);
- refreshMilestones(taskRepository);
- monitor.done();
- }
-
- @Override
- public boolean hasTaskChanged(TaskRepository repository, ITask task,
- TaskData taskData) {
- TaskAttribute modAttribute = taskData.getRoot().getAttribute(
- TaskAttribute.DATE_MODIFICATION);
- if (modAttribute == null)
- return false;
-
- boolean changed = true;
- Date modDate = task.getModificationDate();
- if (modDate != null) {
- Date updateDate = taskData.getAttributeMapper().getDateValue(
- modAttribute);
- if (updateDate != null)
- changed = updateDate.after(modDate);
- }
- return changed;
- }
-
- @Override
- public void updateTaskFromTaskData(TaskRepository taskRepository,
- ITask task, TaskData taskData) {
- if (!taskData.isNew()) {
- task.setUrl(getTaskUrl(taskRepository.getUrl(),
- taskData.getTaskId()));
- }
- new TaskMapper(taskData).applyTo(task);
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat and others.
+ * 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:
+ * David Green <david.green@tasktop.com> - initial contribution
+ * Christian Trutz <christian.trutz@gmail.com> - initial contribution
+ * Chris Aniszczyk <caniszczyk@gmail.com> - initial contribution
+ *******************************************************************************/
+package org.eclipse.mylyn.github.internal;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
+import org.eclipse.mylyn.commons.net.AuthenticationType;
+import org.eclipse.mylyn.commons.net.Policy;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+import org.eclipse.mylyn.tasks.core.data.TaskDataCollector;
+import org.eclipse.mylyn.tasks.core.data.TaskMapper;
+import org.eclipse.mylyn.tasks.core.sync.ISynchronizationSession;
+
+/**
+ * GitHub connector.
+ */
+public class GitHubRepositoryConnector extends AbstractRepositoryConnector {
+
+ /**
+ * GitHub kind.
+ */
+ public static final String KIND = GitHub.CONNECTOR_KIND;
+
+ /**
+ * Create client for repository
+ *
+ * @param repository
+ * @return client
+ */
+ public static GitHubClient createClient(TaskRepository repository) {
+ GitHubClient client = new GitHubClient();
+ AuthenticationCredentials credentials = repository
+ .getCredentials(AuthenticationType.REPOSITORY);
+ if (credentials != null)
+ client.setCredentials(credentials.getUserName(),
+ credentials.getPassword());
+ return client;
+ }
+
+ /**
+ * GitHub specific {@link AbstractTaskDataHandler}.
+ */
+ private final GitHubTaskDataHandler taskDataHandler;
+
+ private final Map<TaskRepository, List<Label>> repositoryLabels = Collections
+ .synchronizedMap(new HashMap<TaskRepository, List<Label>>());
+
+ private final Map<TaskRepository, List<Milestone>> repositoryMilestones = Collections
+ .synchronizedMap(new HashMap<TaskRepository, List<Milestone>>());
+
+ /**
+ * Create GitHub issue repository connector
+ */
+ public GitHubRepositoryConnector() {
+ taskDataHandler = new GitHubTaskDataHandler(this);
+ }
+
+ /**
+ * Refresh labels for repository
+ *
+ * @param repository
+ * @return labels
+ * @throws CoreException
+ */
+ public List<Label> refreshLabels(TaskRepository repository)
+ throws CoreException {
+ Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$
+ Repository repo = GitHub.getRepository(repository.getRepositoryUrl());
+ GitHubClient client = createClient(repository);
+ LabelService service = new LabelService(client);
+ try {
+ List<Label> labels = service.getLabels(repo.getOwner(),
+ repo.getName());
+ Collections.sort(labels, new LabelComparator());
+ this.repositoryLabels.put(repository, labels);
+ return labels;
+ } catch (IOException e) {
+ throw new CoreException(GitHub.createErrorStatus(e));
+ }
+ }
+
+ /**
+ * Get labels for task repository.
+ *
+ * @param repository
+ * @return non-null but possibly empty list of labels
+ */
+ public List<Label> getLabels(TaskRepository repository) {
+ Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$
+ List<Label> labels = new LinkedList<Label>();
+ List<Label> cached = this.repositoryLabels.get(repository);
+ if (cached != null) {
+ labels.addAll(cached);
+ }
+ return labels;
+ }
+
+ /**
+ * Are there cached labels for the specified task repository?
+ *
+ * @param repository
+ * @return true if contains labels, false otherwise
+ */
+ public boolean hasCachedLabels(TaskRepository repository) {
+ return this.repositoryLabels.containsKey(repository);
+ }
+
+ /**
+ * Refresh milestones for repository
+ *
+ * @param repository
+ * @return milestones
+ * @throws CoreException
+ */
+ public List<Milestone> refreshMilestones(TaskRepository repository)
+ throws CoreException {
+ Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$
+ Repository repo = GitHub.getRepository(repository.getRepositoryUrl());
+ GitHubClient client = createClient(repository);
+ MilestoneService service = new MilestoneService(client);
+ try {
+ List<Milestone> milestones = new LinkedList<Milestone>();
+ milestones.addAll(service.getMilestones(repo.getOwner(),
+ repo.getName(), IssueService.STATE_OPEN));
+ milestones.addAll(service.getMilestones(repo.getOwner(),
+ repo.getName(), IssueService.STATE_CLOSED));
+ this.repositoryMilestones.put(repository, milestones);
+ return milestones;
+ } catch (IOException e) {
+ throw new CoreException(GitHub.createErrorStatus(e));
+ }
+ }
+
+ /**
+ * Get milestones for task repository.
+ *
+ * @param repository
+ * @return non-null but possibly empty list of milestones
+ */
+ public List<Milestone> getMilestones(TaskRepository repository) {
+ Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$
+ List<Milestone> milestones = new LinkedList<Milestone>();
+ List<Milestone> cached = this.repositoryMilestones.get(repository);
+ if (cached != null) {
+ milestones.addAll(cached);
+ }
+ return milestones;
+ }
+
+ /**
+ * Are there cached milestones for the specified task repository?
+ *
+ * @param repository
+ * @return true if contains milestones, false otherwise
+ */
+ public boolean hasCachedMilestones(TaskRepository repository) {
+ return this.repositoryMilestones.containsKey(repository);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return always {@code true}
+ */
+ @Override
+ public boolean canCreateNewTask(TaskRepository repository) {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return always {@code true}
+ */
+ @Override
+ public boolean canCreateTaskFromKey(TaskRepository repository) {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see #KIND
+ */
+ @Override
+ public String getConnectorKind() {
+ return KIND;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getLabel() {
+ return Messages.GitHubRepositoryConnector_LabelConnector;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public AbstractTaskDataHandler getTaskDataHandler() {
+ return this.taskDataHandler;
+ }
+
+ @Override
+ public IStatus performQuery(TaskRepository repository,
+ IRepositoryQuery query, TaskDataCollector collector,
+ ISynchronizationSession session, IProgressMonitor monitor) {
+ IStatus result = Status.OK_STATUS;
+ List<String> statuses = QueryUtils.getAttributes(
+ IssueService.FILTER_STATE, query);
+
+ monitor.beginTask(Messages.GitHubRepositoryConnector_TaskQuerying,
+ statuses.size());
+ try {
+ Repository repo = GitHub.getRepository(repository
+ .getRepositoryUrl());
+
+ GitHubClient client = createClient(repository);
+ IssueService service = new IssueService(client);
+
+ Map<String, String> filterData = new HashMap<String, String>();
+ String mentions = query.getAttribute(IssueService.FILTER_MENTIONED);
+ if (mentions != null)
+ filterData.put(IssueService.FILTER_MENTIONED, mentions);
+
+ String assignee = query.getAttribute(IssueService.FILTER_ASSIGNEE);
+ if (assignee != null)
+ filterData.put(IssueService.FILTER_ASSIGNEE, assignee);
+
+ String milestone = query
+ .getAttribute(IssueService.FILTER_MILESTONE);
+ if (milestone != null)
+ filterData.put(IssueService.FILTER_MILESTONE, milestone);
+
+ List<String> labels = QueryUtils.getAttributes(
+ IssueService.FILTER_LABELS, query);
+ if (!labels.isEmpty()) {
+ StringBuilder labelsQuery = new StringBuilder();
+ for (String label : labels)
+ labelsQuery.append(label).append(',');
+ filterData.put(IssueService.FILTER_LABELS,
+ labelsQuery.toString());
+ }
+
+ for (String status : statuses) {
+ filterData.put(IssueService.FILTER_STATE, status);
+ List<Issue> issues = service.getIssues(repo.getOwner(),
+ repo.getName(), filterData);
+
+ // collect task data
+ for (Issue issue : issues) {
+ TaskData taskData = taskDataHandler.createTaskData(
+ repository, monitor, repo.getOwner(),
+ repo.getName(), issue);
+ taskData.setPartial(true);
+ collector.accept(taskData);
+ }
+ monitor.worked(1);
+ }
+
+ result = Status.OK_STATUS;
+ } catch (IOException e) {
+ result = GitHub.createErrorStatus(e);
+ }
+
+ monitor.done();
+ return result;
+ }
+
+ @Override
+ public TaskData getTaskData(TaskRepository repository, String taskId,
+ IProgressMonitor monitor) throws CoreException {
+ Repository repo = GitHub.getRepository(repository.getRepositoryUrl());
+
+ try {
+ GitHubClient client = createClient(repository);
+ IssueService service = new IssueService(client);
+ Issue issue = service.getIssue(repo.getOwner(), repo.getName(),
+ taskId);
+ List<Comment> comments = null;
+ if (issue.getComments() > 0) {
+ comments = service.getComments(repo.getOwner(), repo.getName(),
+ taskId);
+ }
+ TaskData taskData = taskDataHandler.createTaskData(repository,
+ monitor, repo.getOwner(), repo.getName(), issue, comments);
+
+ return taskData;
+ } catch (IOException e) {
+ throw new CoreException(GitHub.createErrorStatus(e));
+ }
+ }
+
+ @Override
+ public String getRepositoryUrlFromTaskUrl(String taskFullUrl) {
+ if (taskFullUrl != null) {
+ Matcher matcher = Pattern.compile(
+ "(http://.+?)/issues/issue/([^/]+)").matcher(taskFullUrl); //$NON-NLS-1$
+ if (matcher.matches()) {
+ return matcher.group(1);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public String getTaskIdFromTaskUrl(String taskFullUrl) {
+ if (taskFullUrl != null) {
+ Matcher matcher = Pattern
+ .compile(".+?/issues/issue/([^/]+)").matcher(taskFullUrl); //$NON-NLS-1$
+ if (matcher.matches()) {
+ return matcher.group(1);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public String getTaskUrl(String repositoryUrl, String taskId) {
+ return repositoryUrl + "/issues/issue/" + taskId; //$NON-NLS-1$
+ }
+
+ @Override
+ public void updateRepositoryConfiguration(TaskRepository taskRepository,
+ IProgressMonitor monitor) throws CoreException {
+ monitor = Policy.monitorFor(monitor);
+ monitor.beginTask("", 2); //$NON-NLS-1$
+ monitor.setTaskName(Messages.GitHubRepositoryConnector_TaskUpdatingLabels);
+ refreshLabels(taskRepository);
+ monitor.worked(1);
+ monitor.setTaskName(Messages.GitHubRepositoryConnector_TaskUpdatingMilestones);
+ refreshMilestones(taskRepository);
+ monitor.done();
+ }
+
+ @Override
+ public boolean hasTaskChanged(TaskRepository repository, ITask task,
+ TaskData taskData) {
+ TaskAttribute modAttribute = taskData.getRoot().getAttribute(
+ TaskAttribute.DATE_MODIFICATION);
+ if (modAttribute == null)
+ return false;
+
+ boolean changed = true;
+ Date modDate = task.getModificationDate();
+ if (modDate != null) {
+ Date updateDate = taskData.getAttributeMapper().getDateValue(
+ modAttribute);
+ if (updateDate != null)
+ changed = updateDate.after(modDate);
+ }
+ return changed;
+ }
+
+ @Override
+ public void updateTaskFromTaskData(TaskRepository taskRepository,
+ ITask task, TaskData taskData) {
+ if (!taskData.isNew()) {
+ task.setUrl(getTaskUrl(taskRepository.getUrl(),
+ taskData.getTaskId()));
+ }
+ new TaskMapper(taskData).applyTo(task);
+ }
+
+}

Back to the top