This repository has been archived on 2025-10-30. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
gitwarrior/internal/gitw/project.go
Yves Biener 3ed3c53854 add(taskwarrior): integrate uda for git integration
This implementation adds the necessary fields for the tasks of
taskwarrior to be synchronized with git. It provides the necessary
conversion of the taskwarrior times and the standard time.Time go
format. WIP for #3.
2023-10-21 11:03:43 +02:00

107 lines
2.5 KiB
Go

package gitw
import (
"errors"
"gitea.yves-biener.de/yves-biener/gitwarrior/internal/gitea"
"gitea.yves-biener.de/yves-biener/gitwarrior/internal/taskwarrior"
)
type Project struct {
server gitea.Gitea
repository gitea.Repository
issues []Issue
milestones []gitea.Milestone
}
func NewProject(server gitea.Gitea, repository gitea.Repository) Project {
return Project{
server: server,
repository: repository,
}
}
func (project *Project) Pull() error {
if err := project.Fetch(); err != nil {
return err
}
if err := project.merge(); err != nil {
return err
}
return nil
}
func (project *Project) Fetch() error {
comments, err := project.server.GetComments(project.repository)
if err != nil {
return err
}
issues, err := project.server.GetIssues(project.repository)
if err != nil {
return err
}
project.milestones, err = project.server.GetMilestones(project.repository)
if err != nil {
return err
}
for _, issue := range issues {
var issue_comments []gitea.Comment
for _, comment := range comments {
if comment.Issue_url == issue.Html_url {
issue_comments = append(issue_comments, comment)
}
}
project.issues = append(project.issues, Issue{
issue: issue,
comments: issue_comments,
})
}
return nil
}
func (project *Project) merge() error {
// TODO: run merge to update the local taskwarrior tasks into the state of the
// issues and milestones
return nil
}
type Issue struct {
issue gitea.Issue
comments []gitea.Comment
}
func (i *Issue) into() (taskwarrior.Task, error) {
// TODO: identify if issue is already an existing task
var filter taskwarrior.Filter
filter.IncludeGitId(i.issue.Id)
filter.IncludeGitType(taskwarrior.ISSUE)
tasks, err := taskwarrior.GetTasks(filter)
if err != nil {
// this means that a task for this issue does not exist yet
return taskwarrior.NewTask(
i.issue.Title,
i.issue.Repository.Name,
i.issue.Id,
taskwarrior.ISSUE,
i.issue.Labels...,
), nil
} else {
// this means that a task exists and it needs to be merged
if len(tasks) != 1 {
return taskwarrior.Task{}, errors.New("Did not find exactly one task for a given issue.Id")
}
return i.merge(tasks[0]), nil
}
}
func (i *Issue) merge(task taskwarrior.Task) taskwarrior.Task {
// TODO: issue values into task:
// - is the issue more recent than the task?
// - apply changes into task
// - in case of merge conflicts ask user for corresponding action:
// 1. use theirs
// 2. use mine
// 3. use provided value
return task
}