diff --git a/cmd/gitw/main.go b/cmd/gitw/main.go index 3e5ac69..13c57b1 100644 --- a/cmd/gitw/main.go +++ b/cmd/gitw/main.go @@ -79,6 +79,16 @@ func main() { } fmt.Println("---") + // NOTE: this can be used to add / modify tasks + // var update_tasks []taskwarrior.Task + // task := taskwarrior.NewTask( + // "This is a test task from gitwarrior", + // "gitwarrior", + // "issue", + // ) + // update_tasks = append(update_tasks, task) + // taskwarrior.UpdateTasks(update_tasks) + // necessary configurations (see config file gitw.json) // - access code for gitea // - configuration for taskwarrior settings? diff --git a/internal/taskwarrior/task.go b/internal/taskwarrior/task.go index 3325d4e..e1c6671 100644 --- a/internal/taskwarrior/task.go +++ b/internal/taskwarrior/task.go @@ -10,23 +10,31 @@ import ( /// mentioned in the Status field type Task struct { - Id uint - Project string - Tags []string - Description string - Annotations []Annotation - Status string - Due string - Entry string - Modified string - End string - Uuid string - Urgency float32 + Id uint `json:"id,omitempty"` + Project string `json:"project,omitempty"` + Tags []string `json:"tags,omitempty"` + Description string `json:"description,omitempty"` + Annotations []Annotation `json:"annotations,omitempty"` + Status string `json:"status,omitempty"` + Due string `json:"due,omitempty"` + Entry string `json:"entry,omitempty"` + Modified string `json:"modified,omitempty"` + End string `json:"end,omitempty"` + Uuid string `json:"uuid,omitempty"` + Urgency float32 `json:"urgency,omitempty"` } type Annotation struct { - Description string - Entry string + Description string `json:"description,omitempty"` + Entry string `json:"entry,omitempty"` +} + +func NewTask(description string, project string, tags ...string) Task { + return Task{ + Project: project, + Tags: tags, + Description: description, + } } func GetTasks(filter Filter) ([]Task, error) { @@ -44,3 +52,18 @@ func GetTasks(filter Filter) ([]Task, error) { } return tasks, nil } + +func UpdateTasks(tasks []Task) error { + cmd := exec.Command("task", "import") + value, err := json.Marshal(tasks) + if err != nil { + return err + } + var buffer bytes.Buffer + _, err = buffer.Write(value) + if err != nil { + return err + } + cmd.Stdin = &buffer + return cmd.Run() +}