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("---")
|
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)
|
// necessary configurations (see config file gitw.json)
|
||||||
// - access code for gitea
|
// - access code for gitea
|
||||||
// - configuration for taskwarrior settings?
|
// - configuration for taskwarrior settings?
|
||||||
|
|||||||
@@ -10,23 +10,31 @@ import (
|
|||||||
/// mentioned in the Status field
|
/// mentioned in the Status field
|
||||||
|
|
||||||
type Task struct {
|
type Task struct {
|
||||||
Id uint
|
Id uint `json:"id,omitempty"`
|
||||||
Project string
|
Project string `json:"project,omitempty"`
|
||||||
Tags []string
|
Tags []string `json:"tags,omitempty"`
|
||||||
Description string
|
Description string `json:"description,omitempty"`
|
||||||
Annotations []Annotation
|
Annotations []Annotation `json:"annotations,omitempty"`
|
||||||
Status string
|
Status string `json:"status,omitempty"`
|
||||||
Due string
|
Due string `json:"due,omitempty"`
|
||||||
Entry string
|
Entry string `json:"entry,omitempty"`
|
||||||
Modified string
|
Modified string `json:"modified,omitempty"`
|
||||||
End string
|
End string `json:"end,omitempty"`
|
||||||
Uuid string
|
Uuid string `json:"uuid,omitempty"`
|
||||||
Urgency float32
|
Urgency float32 `json:"urgency,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Annotation struct {
|
type Annotation struct {
|
||||||
Description string
|
Description string `json:"description,omitempty"`
|
||||||
Entry string
|
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) {
|
func GetTasks(filter Filter) ([]Task, error) {
|
||||||
@@ -44,3 +52,18 @@ func GetTasks(filter Filter) ([]Task, error) {
|
|||||||
}
|
}
|
||||||
return tasks, nil
|
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