add(taskwarrior): update tasks in taskwarrior
The implementation updates the tasks in taskwarrior and/or creates new tasks. WIP for #3.
This commit is contained in:
@@ -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?
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user