add(taskwarrior): merge of server side changes for milestones
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user