// Copyright (c) 2021, Fr.Terrot. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. package io.gitea.mylyn.core; import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.List; import java.util.Set; import java.util.regex.Matcher; import org.apache.commons.lang.StringUtils; import org.eclipse.core.internal.registry.OffsetTable; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.mylyn.tasks.core.ITaskMapping; import org.eclipse.mylyn.tasks.core.RepositoryResponse; import org.eclipse.mylyn.tasks.core.RepositoryResponse.ResponseKind; 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.TaskAttributeMapper; import org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData; import org.eclipse.mylyn.tasks.core.data.TaskCommentMapper; import org.eclipse.mylyn.tasks.core.data.TaskData; import org.eclipse.mylyn.tasks.core.data.TaskOperation; import io.gitea.ApiException; import io.gitea.api.IssueApi; import io.gitea.model.Comment; import io.gitea.model.CreateIssueCommentOption; import io.gitea.model.CreateIssueOption; import io.gitea.model.EditIssueOption; import io.gitea.model.GiteaDateTimeUtils; import io.gitea.model.GiteaPriorityLevel; import io.gitea.model.GiteaUser; import io.gitea.model.Issue; import io.gitea.model.IssueAction; import io.gitea.model.IssueLabelsOption; import io.gitea.model.IssueState; import io.gitea.model.IssueType; import io.gitea.model.Label; import io.gitea.model.Milestone; import io.gitea.model.User; import io.gitea.mylyn.core.exceptions.GiteaException; /** * Handles the Issue<=>Task management. Downloads issues to tasks for a specific * repository, update issue and creates new issues. */ public class GiteaTaskDataHandler extends AbstractTaskDataHandler { public GiteaTaskDataHandler() { } @Override public TaskAttributeMapper getAttributeMapper(TaskRepository repository) { try { return ConnectionManager.get(repository).mapper; } catch (CoreException e) { throw new Error(e); } } /** * Initialize Task from local repository. * */ @Override public boolean initializeTaskData(TaskRepository repository, TaskData data, ITaskMapping mapping, IProgressMonitor monitor) throws CoreException { createDefaultAttributes(data, false); GiteaConnection connection = ConnectionManager.get(repository); TaskAttribute root = data.getRoot(); root.getAttribute(GiteaAttribute.PROJECT.getTaskKey()).setValue(connection.repository.getName());// FIXME: not // the // project root.getAttribute(GiteaAttribute.LABELS.getTaskKey()).setValue(""); root.getAttribute(GiteaAttribute.STATUS.getTaskKey()).setValue("open"); root.getAttribute(GiteaAttribute.MILESTONE.getTaskKey()).setValue(""); return true; } /** * Send Update to remote issues repository (create issue when required). * */ @Override public RepositoryResponse postTaskData(TaskRepository repository, TaskData data, Set attributes, IProgressMonitor monitor) throws CoreException { GiteaAttributeMapper attributeMapper = (GiteaAttributeMapper) data.getAttributeMapper(); TaskAttribute root = data.getRoot(); String taskId = data.getTaskId(); // newLabelsList could be null or may content only one 'null' item when no label // is defined for the task List