Added migration of task description
This commit is contained in:
parent
5eb5407ca4
commit
71b841f2e3
31
main.go
31
main.go
|
@ -4,7 +4,6 @@ import (
|
|||
"bufio"
|
||||
sdk "code.vikunja.io/go-sdk"
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
@ -42,7 +41,6 @@ func main() {
|
|||
|
||||
tasks := make([]*sdk.ModelsTask, 0, len(lines))
|
||||
|
||||
mapByHeadline := make(map[string][]string)
|
||||
var lastHeadline string
|
||||
var notApplicable []string
|
||||
var lastTask *sdk.ModelsTask
|
||||
|
@ -55,7 +53,6 @@ func main() {
|
|||
|
||||
if strings.HasPrefix(l, "#") {
|
||||
lastHeadline = strings.TrimSpace(strings.ReplaceAll(l, "#", ""))
|
||||
mapByHeadline[lastHeadline] = []string{}
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -75,7 +72,7 @@ func main() {
|
|||
if err != nil {
|
||||
log.Fatal("Error creating task: ", err)
|
||||
}
|
||||
log.Printf("Created task %d of %d", in, len(lines))
|
||||
log.Printf("Created task %d of %d with ID %d", in, len(lines), t.Id)
|
||||
|
||||
// Subtask handling
|
||||
lastTask = t
|
||||
|
@ -101,7 +98,7 @@ func main() {
|
|||
if err != nil {
|
||||
log.Fatal("Error creating task: ", err)
|
||||
}
|
||||
log.Printf("Created task %d of %d", in, len(lines))
|
||||
log.Printf("Created task %d of %d with ID %d", in, len(lines), subtask.Id)
|
||||
|
||||
tasks = append(tasks, subtask)
|
||||
taskRelations = append(taskRelations, &sdk.ModelsTaskRelation{
|
||||
|
@ -112,13 +109,35 @@ func main() {
|
|||
continue
|
||||
}
|
||||
|
||||
// If we had a last task, every line which follows now is not a subtask but additional description, so we put it in as description
|
||||
if lastTask != nil {
|
||||
lastTask.Description = lastTask.Description + l + "\n"
|
||||
continue
|
||||
}
|
||||
|
||||
notApplicable = append(notApplicable, l)
|
||||
}
|
||||
|
||||
log.Println("Done migrating tasks.")
|
||||
|
||||
// Update all tasks which have a description
|
||||
for _, t := range tasks {
|
||||
if t.Description == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
*t, _, err = client.TaskApi.TasksIdPost(auth, t.Id, *t)
|
||||
if err != nil {
|
||||
log.Fatal("Error updating task description: ", err)
|
||||
}
|
||||
|
||||
log.Printf("Updated description of task %d", t.Id)
|
||||
}
|
||||
|
||||
// TODO: update all labels afterwards
|
||||
// TODO: create all relations afterwards
|
||||
|
||||
fmt.Println(mapByHeadline)
|
||||
log.Println("Done.")
|
||||
}
|
||||
|
||||
func scanLines(path string) ([]string, error) {
|
||||
|
|
Loading…
Reference in New Issue