fix(taskwarrior): parsing and convertion of times and contents

This commit is contained in:
2023-10-22 12:32:53 +02:00
parent ce2a4769c9
commit 5764a32f02
5 changed files with 103 additions and 26 deletions

11
internal/gitw/diff.go Normal file
View File

@@ -0,0 +1,11 @@
package gitw
import "fmt"
func prompt(value, theirs, mine string) string {
// TODO: create tmp file with the corresponding contents
// open tmp file using the $EDITOR environment variable
// parse and return output of tmp file after $EDITOR execution has been completed
fmt.Printf("\tPrompting for value: '%s'\n", value)
return value
}

View File

@@ -3,6 +3,7 @@ package gitw
import (
"errors"
"fmt"
"strings"
"time"
"gitea.yves-biener.de/yves-biener/gitwarrior/internal/gitea"
@@ -48,6 +49,11 @@ func (project *Project) Fetch() error {
}
for _, issue := range issues {
var issue_comments []gitea.Comment
issue_comments = append(issue_comments, gitea.Comment{
Body: strings.ReplaceAll(issue.Body, "\r\n", "\n"),
Created_at: issue.Created_at,
Updated_at: issue.Updated_at,
})
for _, comment := range comments {
if comment.Issue_url == issue.Html_url {
issue_comments = append(issue_comments, comment)
@@ -67,6 +73,7 @@ func (project *Project) merge() error {
var tasks []taskwarrior.Task
var task taskwarrior.Task
var filter taskwarrior.Filter
// NOTE: merge tasks
for _, issue := range project.issues {
filter.Reset()
@@ -104,9 +111,14 @@ func (project *Project) merge() error {
if err := taskwarrior.UpdateTasks(tasks); err != nil {
return err
}
} else {
for _, task := range tasks {
fmt.Printf("\t%#v\n\n", task)
}
}
// TODO: reset tasks after successfully updating the issues
tasks = nil
tasks = nil // NOTE: reset tasks after successfully updating the issues
// TODO: merge milestones
for _, milestone := range project.milestones {
filter.Reset()
@@ -153,6 +165,10 @@ func (project *Project) merge() error {
}
if !dry_run {
return taskwarrior.UpdateTasks(tasks)
} else {
for _, task := range tasks {
fmt.Printf("\t%#v\n\n", task)
}
}
return nil
}
@@ -185,32 +201,64 @@ func (issue *Issue) MergeTask(task taskwarrior.Task) (taskwarrior.Task, error) {
if issue.git_issue.Updated_at.After(last_update) {
// there are changes we need to merge
if taskwarrior.TaskTimeToGoTime(task.Modified).After(last_update) {
// TODO: this means that there are local modifications which are not yet pushed
// NOTE: this means that there are local modifications which are not yet pushed
if task.Description != issue.git_issue.Title {
task.Description = prompt(task.Description, issue.git_issue.Title, task.Description)
}
if task.Status == "completed" || issue.git_issue.State == "closed" {
if !(task.Status == "completed" && issue.git_issue.State == "closed" || task.Status != "completed" && issue.git_issue.State != "closed") {
task.Status = prompt(task.Status, issue.git_issue.State, task.Status)
}
}
if len(task.Annotations) != len(issue.comments)+1 {
var annotations []string
annotations = append(annotations, issue.git_issue.Body)
for _, annotation := range task.Annotations {
annotations = append(annotations, annotation.Description)
}
var comments []string
for _, comment := range issue.comments {
comments = append(comments, comment.Body)
}
// TODO: how should the user manually enter the values?
// TODO: provide options for theirs, mine and manual edit of the task annotations
// annotation_joined := prompt(strings.Join(annotations, "\n\n"), strings.Join(comments, "\n\n"), strings.Join(annotations, "\n\n"))
} else {
for i := range issue.comments {
// check the modification times?
annotation := task.Annotations[i]
comment := issue.comments[i]
modification_time := taskwarrior.TaskTimeToGoTime(annotation.Entry)
if comment.Updated_at.After(modification_time) {
annotation.Description = comment.Body
annotation.Entry = taskwarrior.GoTimeToTaskTime(comment.Updated_at)
} else {
annotation.Description = prompt(annotation.Description, comment.Body, annotation.Description)
}
task.Annotations[i] = annotation
}
}
} else {
// NOTE: there are no modifications between the last received update and the current version, hence we just accept theirs fully
task.Description = issue.git_issue.Title
task.Tags = issue.git_issue.Labels
// NOTE: otherwise do not update the value
if issue.git_issue.State == "closed" {
// otherwise do not update the value
task.Status = "completed"
task.End = taskwarrior.GoTimeToTaskTime(issue.git_issue.Closed_at)
}
}
task.Last_gitw_update = taskwarrior.GoTimeToTaskTime(time.Now())
} else {
// there are changes after the previous update here may be merge conflicts
// TODO: implement merge conflict resolution
}
annotations := len(task.Annotations)
for i, comment := range issue.comments {
if comment.Updated_at.After(last_update) {
if i < annotations {
task.Annotations[i].Description = comment.Body
task.Annotations[i].Entry = taskwarrior.GoTimeToTaskTime(comment.Updated_at)
task.Last_gitw_update = taskwarrior.GoTimeToTaskTime(time.Now())
} else {
task.AppendComment(comment.Body, comment.Updated_at)
annotations := len(task.Annotations)
for i, comment := range issue.comments {
if comment.Updated_at.After(last_update) {
if i < annotations {
task.Annotations[i].Description = comment.Body
task.Annotations[i].Entry = taskwarrior.GoTimeToTaskTime(comment.Updated_at)
} else {
task.AppendComment(comment.Body, comment.Updated_at)
}
}
}
}
task.Last_gitw_update = taskwarrior.GoTimeToTaskTime(time.Now().In(time.Local))
}
// TODO: issue values into task:
// - is the issue more recent than the task?