add(taskwarrior): merge of server side changes for milestones
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
package gitw
|
package diff
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
func prompt(value, theirs, mine string) string {
|
func Prompt(value, theirs, mine string) string {
|
||||||
// TODO: create tmp file with the corresponding contents
|
// TODO: create tmp file with the corresponding contents
|
||||||
// open tmp file using the $EDITOR environment variable
|
// open tmp file using the $EDITOR environment variable
|
||||||
// parse and return output of tmp file after $EDITOR execution has been completed
|
// parse and return output of tmp file after $EDITOR execution has been completed
|
||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gitea.yves-biener.de/yves-biener/gitwarrior/internal/diff"
|
||||||
"gitea.yves-biener.de/yves-biener/gitwarrior/internal/taskwarrior"
|
"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
|
// TODO: implement merge for milestone tasks
|
||||||
func (milestone *Milestone) MergeTask(task taskwarrior.Task) taskwarrior.Task {
|
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
|
return task
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"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/gitea"
|
||||||
"gitea.yves-biener.de/yves-biener/gitwarrior/internal/taskwarrior"
|
"gitea.yves-biener.de/yves-biener/gitwarrior/internal/taskwarrior"
|
||||||
)
|
)
|
||||||
@@ -99,10 +100,7 @@ func (project *Project) merge() error {
|
|||||||
tasks = append(tasks, task)
|
tasks = append(tasks, task)
|
||||||
} else {
|
} else {
|
||||||
// NOTE: there is excactly one git_task
|
// NOTE: there is excactly one git_task
|
||||||
task, err = issue.MergeTask(git_tasks[0])
|
task = issue.MergeTask(git_tasks[0])
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fmt.Printf("\tUpdated task: '%s'\n", task.Description)
|
fmt.Printf("\tUpdated task: '%s'\n", task.Description)
|
||||||
tasks = append(tasks, task)
|
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
|
// 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)
|
last_update := taskwarrior.TaskTimeToGoTime(task.Last_gitw_update)
|
||||||
if issue.git_issue.Updated_at.After(last_update) {
|
if issue.git_issue.Updated_at.After(last_update) {
|
||||||
// there are changes we need to merge
|
// there are changes we need to merge
|
||||||
if taskwarrior.TaskTimeToGoTime(task.Modified).After(last_update) {
|
if taskwarrior.TaskTimeToGoTime(task.Modified).After(last_update) {
|
||||||
// NOTE: 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 {
|
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" {
|
||||||
if !(task.Status == "completed" && issue.git_issue.State == "closed" || 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) {
|
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.Description = comment.Body
|
||||||
annotation.Entry = taskwarrior.GoTimeToTaskTime(comment.Updated_at)
|
annotation.Entry = taskwarrior.GoTimeToTaskTime(comment.Updated_at)
|
||||||
} else {
|
} else {
|
||||||
annotation.Description = prompt(annotation.Description, comment.Body, annotation.Description)
|
annotation.Description = diff.Prompt(annotation.Description, comment.Body, annotation.Description)
|
||||||
}
|
}
|
||||||
task.Annotations[i] = annotation
|
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))
|
task.Last_gitw_update = taskwarrior.GoTimeToTaskTime(time.Now().In(time.Local))
|
||||||
}
|
}
|
||||||
// TODO: issue values into task:
|
return 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
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user