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.
This commit is contained in:
2023-10-21 11:03:43 +02:00
parent 11c57d3485
commit 3ed3c53854
4 changed files with 171 additions and 55 deletions

View File

@@ -3,7 +3,11 @@ package taskwarrior
import (
"bytes"
"encoding/json"
"fmt"
"os"
"os/exec"
"strings"
"time"
)
/// A task with an Id of 0 is either `completed` or `deleted` which is also
@@ -11,6 +15,8 @@ import (
type Task struct {
Id uint `json:"id,omitempty"`
Git_id float32 `json:"git_id,omitempty"` // uda
Git_type string `json:"git_type,omitempty"` // uda
Project string `json:"project,omitempty"`
Tags []string `json:"tags,omitempty"`
Description string `json:"description,omitempty"`
@@ -29,14 +35,55 @@ type Annotation struct {
Entry string `json:"entry,omitempty"`
}
func NewTask(description string, project string, tags ...string) Task {
func NewTask(description string, project string, git_id uint, git_type Type, tags ...string) Task {
// TODO: update task struct to include the new user defined value, which shall
// also be provided as an argument
return Task{
Project: project,
Tags: tags,
Description: description,
Git_id: float32(git_id),
Git_type: string(git_type),
Tags: tags,
}
}
func TaskTimeToGoTime(t string) time.Time {
// TODO: apply required changes to the string for correct parsing
splits := strings.Split(t, "T")
if len(splits) != 2 {
fmt.Fprintf(os.Stderr, "Expected exactly 2 splits")
os.Exit(-1)
}
date := splits[0]
first := date[0:4]
second := date[4:6]
third := date[6:]
date = strings.Join([]string{first, second, third}, "-")
timestamp := splits[1]
first = timestamp[0:2]
second = timestamp[2:4]
third = timestamp[4 : len(timestamp)-1]
timestamp = strings.Join([]string{first, second, third}, ":")
value := fmt.Sprintf("%sT%s+02:00", date, timestamp)
result, err := time.Parse(time.RFC3339, value)
if err != nil {
fmt.Fprint(os.Stderr, err)
os.Exit(-1)
}
return result
}
func GoTimeToTaskTime(t time.Time) string {
result := t.Format(time.RFC3339)
// TODO: apply changes to the result
// go: 2023-10-10T19:57:22+02:00
// task: 20231010T195722Z
result = strings.Replace(result, "-", "", 2)
result = strings.Replace(result, ":", "", 2)
result = strings.ReplaceAll(result, "+02:00", "Z")
return result
}
func GetTasks(filter Filter) ([]Task, error) {
filter.filter = append(filter.filter, "export")
cmd := exec.Command("task", filter.filter...)