Add migrating buckets to converting todoist to vikunja structure
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
This commit is contained in:
parent
1c9eb823c9
commit
cb0e02c103
|
@ -23,6 +23,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -151,6 +152,15 @@ type reminder struct {
|
|||
IsDeleted int64 `json:"is_deleted"`
|
||||
}
|
||||
|
||||
type section struct {
|
||||
ID int64 `json:"id"`
|
||||
DateAdded time.Time `json:"date_added"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
Name string `json:"name"`
|
||||
ProjectID int64 `json:"project_id"`
|
||||
SectionOrder int64 `json:"section_order"`
|
||||
}
|
||||
|
||||
type sync struct {
|
||||
Projects []*project `json:"projects"`
|
||||
Items []*item `json:"items"`
|
||||
|
@ -158,6 +168,7 @@ type sync struct {
|
|||
Notes []*note `json:"notes"`
|
||||
ProjectNotes []*projectNote `json:"project_notes"`
|
||||
Reminders []*reminder `json:"reminders"`
|
||||
Sections []*section `json:"sections"`
|
||||
}
|
||||
|
||||
var todoistColors = map[int64]string{}
|
||||
|
@ -258,6 +269,22 @@ func convertTodoistToVikunja(sync *sync) (fullVikunjaHierachie []*models.Namespa
|
|||
newNamespace.Lists = append(newNamespace.Lists, list)
|
||||
}
|
||||
|
||||
sort.Slice(sync.Sections, func(i, j int) bool {
|
||||
return sync.Sections[i].SectionOrder < sync.Sections[j].SectionOrder
|
||||
})
|
||||
|
||||
for _, section := range sync.Sections {
|
||||
if section.IsDeleted || section.ProjectID == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
lists[section.ProjectID].Buckets = append(lists[section.ProjectID].Buckets, &models.Bucket{
|
||||
ID: section.ID,
|
||||
Title: section.Name,
|
||||
Created: section.DateAdded,
|
||||
})
|
||||
}
|
||||
|
||||
for _, label := range sync.Labels {
|
||||
labels[label.ID] = &models.Label{
|
||||
Title: label.Name,
|
||||
|
@ -267,9 +294,10 @@ func convertTodoistToVikunja(sync *sync) (fullVikunjaHierachie []*models.Namespa
|
|||
|
||||
for _, i := range sync.Items {
|
||||
task := &models.Task{
|
||||
Title: i.Content,
|
||||
Created: i.DateAdded.In(config.GetTimeZone()),
|
||||
Done: i.Checked == 1,
|
||||
Title: i.Content,
|
||||
Created: i.DateAdded.In(config.GetTimeZone()),
|
||||
Done: i.Checked == 1,
|
||||
BucketID: i.SectionID,
|
||||
}
|
||||
|
||||
// Only try to parse the task done at date if the task is actually done
|
||||
|
|
|
@ -143,7 +143,18 @@ func TestConvertTodoistToVikunja(t *testing.T) {
|
|||
makeTestItem(400000106, 396936926, true, true, true),
|
||||
makeTestItem(400000107, 396936926, false, false, true),
|
||||
makeTestItem(400000108, 396936926, false, false, true),
|
||||
makeTestItem(400000109, 396936926, false, false, true),
|
||||
{
|
||||
ID: 400000109,
|
||||
UserID: 1855589,
|
||||
ProjectID: 396936926,
|
||||
Content: "Task400000109",
|
||||
Priority: 1,
|
||||
ChildOrder: 1,
|
||||
Checked: 1,
|
||||
DateAdded: time1,
|
||||
DateCompleted: time3,
|
||||
SectionID: 1234,
|
||||
},
|
||||
|
||||
makeTestItem(400000007, 396936927, true, false, false),
|
||||
makeTestItem(400000008, 396936927, true, false, false),
|
||||
|
@ -311,6 +322,13 @@ func TestConvertTodoistToVikunja(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
Sections: []*section{
|
||||
{
|
||||
ID: 1234,
|
||||
Name: "Some Bucket",
|
||||
ProjectID: 396936926,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
vikunjaLabels := []*models.Label{
|
||||
|
@ -342,6 +360,12 @@ func TestConvertTodoistToVikunja(t *testing.T) {
|
|||
Title: "Project1",
|
||||
Description: "Lorem Ipsum dolor sit amet\nLorem Ipsum dolor sit amet 2\nLorem Ipsum dolor sit amet 3",
|
||||
HexColor: todoistColors[30],
|
||||
Buckets: []*models.Bucket{
|
||||
{
|
||||
ID: 1234,
|
||||
Title: "Some Bucket",
|
||||
},
|
||||
},
|
||||
Tasks: []*models.Task{
|
||||
{
|
||||
Title: "Task400000000",
|
||||
|
@ -434,10 +458,11 @@ func TestConvertTodoistToVikunja(t *testing.T) {
|
|||
DoneAt: time3,
|
||||
},
|
||||
{
|
||||
Title: "Task400000109",
|
||||
Done: true,
|
||||
Created: time1,
|
||||
DoneAt: time3,
|
||||
Title: "Task400000109",
|
||||
Done: true,
|
||||
Created: time1,
|
||||
DoneAt: time3,
|
||||
BucketID: 1234,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue