From d2aeb7ffe4a9b95abab1b4cdd806aa2b0012f0b8 Mon Sep 17 00:00:00 2001 From: Yves Biener Date: Mon, 23 Oct 2023 14:34:10 +0200 Subject: [PATCH] add(taskwarrior): merge of server side changes for milestones --- internal/{gitw => diff}/diff.go | 4 ++-- internal/gitea/milestone.go | 37 +++++++++++++++++++++++++++++++++ internal/gitw/project.go | 23 +++++++------------- 3 files changed, 46 insertions(+), 18 deletions(-) rename internal/{gitw => diff}/diff.go (81%) diff --git a/internal/gitw/diff.go b/internal/diff/diff.go similarity index 81% rename from internal/gitw/diff.go rename to internal/diff/diff.go index ebb5e64..42ae7c6 100644 --- a/internal/gitw/diff.go +++ b/internal/diff/diff.go @@ -1,8 +1,8 @@ -package gitw +package diff import "fmt" -func prompt(value, theirs, mine string) string { +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 diff --git a/internal/gitea/milestone.go b/internal/gitea/milestone.go index bad864d..c91430b 100644 --- a/internal/gitea/milestone.go +++ b/internal/gitea/milestone.go @@ -7,6 +7,7 @@ import ( "net/http" "time" + "gitea.yves-biener.de/yves-biener/gitwarrior/internal/diff" "gitea.yves-biener.de/yves-biener/gitwarrior/internal/taskwarrior" ) @@ -39,6 +40,42 @@ func (milestone *Milestone) IntoTask(repository Repository) (task taskwarrior.Ta // TODO: implement merge for milestone tasks func (milestone *Milestone) MergeTask(task taskwarrior.Task) taskwarrior.Task { + last_update := taskwarrior.TaskTimeToGoTime(task.Last_gitw_update) + if milestone.Updated_at.After(last_update) { + // there are changes we need to merge + if taskwarrior.TaskTimeToGoTime(task.Modified).After(last_update) { + // NOTE: this means that there are lacal modifications which are not yet pushed + if task.Description != milestone.Title { + task.Description = diff.Prompt(task.Description, milestone.Title, task.Description) + } + if task.Status == "completed" || milestone.State == "closed" { + if !(task.Status == "completed" && milestone.State == "closed" || task.Status != "completed" && milestone.State != "closed") { + task.Status = diff.Prompt(task.Status, milestone.State, task.Status) + } + } + if len(task.Annotations) < 1 { + task.AppendComment(milestone.Description, milestone.Created_at) + } else { + task.Annotations[0].Description = diff.Prompt(task.Annotations[0].Description, milestone.Description, task.Annotations[0].Description) + task.Annotations[0].Entry = taskwarrior.GoTimeToTaskTime(time.Now().In(time.Local)) + } + } else { + // NOTE: there are no modifications between the last received update and the current version, hence we just accept theirs fully + task.Description = milestone.Title + if milestone.State == "closed" { + // otherwise do not update the value + task.Status = "completed" + task.End = taskwarrior.GoTimeToTaskTime(milestone.Closed_at) + } + if len(task.Annotations) == 1 { + task.Annotations[0].Description = milestone.Description + task.Annotations[0].Entry = taskwarrior.GoTimeToTaskTime(milestone.Updated_at) + } else { + task.AppendComment(milestone.Description, milestone.Updated_at) + } + } + task.Last_gitw_update = taskwarrior.GoTimeToTaskTime(time.Now().In(time.Local)) + } return task } diff --git a/internal/gitw/project.go b/internal/gitw/project.go index fc85d92..d35e915 100644 --- a/internal/gitw/project.go +++ b/internal/gitw/project.go @@ -6,6 +6,7 @@ import ( "strings" "time" + "gitea.yves-biener.de/yves-biener/gitwarrior/internal/diff" "gitea.yves-biener.de/yves-biener/gitwarrior/internal/gitea" "gitea.yves-biener.de/yves-biener/gitwarrior/internal/taskwarrior" ) @@ -99,10 +100,7 @@ func (project *Project) merge() error { tasks = append(tasks, task) } else { // NOTE: there is excactly one git_task - task, err = issue.MergeTask(git_tasks[0]) - if err != nil { - return err - } + task = issue.MergeTask(git_tasks[0]) fmt.Printf("\tUpdated task: '%s'\n", task.Description) tasks = append(tasks, task) } @@ -196,18 +194,18 @@ func (issue *Issue) IntoTask(repository gitea.Repository) (task taskwarrior.Task } // TODO: implement merging of git issue or milestone into a taskwarrior task -func (issue *Issue) MergeTask(task taskwarrior.Task) (taskwarrior.Task, error) { +func (issue *Issue) MergeTask(task taskwarrior.Task) taskwarrior.Task { last_update := taskwarrior.TaskTimeToGoTime(task.Last_gitw_update) if issue.git_issue.Updated_at.After(last_update) { // there are changes we need to merge if taskwarrior.TaskTimeToGoTime(task.Modified).After(last_update) { // 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) + task.Description = diff.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) + task.Status = diff.Prompt(task.Status, issue.git_issue.State, task.Status) } } if len(task.Annotations) != len(issue.comments) { @@ -233,7 +231,7 @@ func (issue *Issue) MergeTask(task taskwarrior.Task) (taskwarrior.Task, error) { annotation.Description = comment.Body annotation.Entry = taskwarrior.GoTimeToTaskTime(comment.Updated_at) } else { - annotation.Description = prompt(annotation.Description, comment.Body, annotation.Description) + annotation.Description = diff.Prompt(annotation.Description, comment.Body, annotation.Description) } task.Annotations[i] = annotation } @@ -260,12 +258,5 @@ func (issue *Issue) MergeTask(task taskwarrior.Task) (taskwarrior.Task, error) { } task.Last_gitw_update = taskwarrior.GoTimeToTaskTime(time.Now().In(time.Local)) } - // 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, nil + return task }