fix(migration): import card covers when migrating from Trello
continuous-integration/drone/push Build is passing Details

This commit is contained in:
kolaente 2024-03-10 16:30:01 +01:00
parent 4bb1d5edfc
commit ca0de680ad
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
5 changed files with 48 additions and 4 deletions

2
go.mod
View File

@ -190,3 +190,5 @@ replace github.com/samedi/caldav-go => github.com/kolaente/caldav-go v3.0.1-0.20
go 1.21
toolchain go1.21.2
replace github.com/adlio/trello => github.com/kolaente/trello v1.8.1-0.20240310152004-14ccae2ddc51

4
go.sum
View File

@ -24,8 +24,6 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdko
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/ThreeDotsLabs/watermill v1.3.5 h1:50JEPEhMGZQMh08ct0tfO1PsgMOAOhV3zxK2WofkbXg=
github.com/ThreeDotsLabs/watermill v1.3.5/go.mod h1:O/u/Ptyrk5MPTxSeWM5vzTtZcZfxXfO9PK9eXTYiFZY=
github.com/adlio/trello v1.10.0 h1:ia/rzoBwJJKr4IqnMlrU6n09CVqeyaahSkEVcV5/gPc=
github.com/adlio/trello v1.10.0/go.mod h1:I4Lti4jf2KxjTNgTqs5W3lLuE78QZZdYbbPnQQGwjOo=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
@ -301,6 +299,8 @@ github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZY
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/kolaente/caldav-go v3.0.1-0.20190610114120-2a4eb8b5dcc9+incompatible h1:q7DbyV+sFjEoTuuUdRDNl2nlyfztkZgxVVCV7JhzIkY=
github.com/kolaente/caldav-go v3.0.1-0.20190610114120-2a4eb8b5dcc9+incompatible/go.mod h1:y1UhTNI4g0hVymJrI6yJ5/ohy09hNBeU8iJEZjgdDOw=
github.com/kolaente/trello v1.8.1-0.20240310152004-14ccae2ddc51 h1:R8xiJ/zSWOndiUjG03GmkkIm1O8MDKt2av0SeaIZy/c=
github.com/kolaente/trello v1.8.1-0.20240310152004-14ccae2ddc51/go.mod h1:I4Lti4jf2KxjTNgTqs5W3lLuE78QZZdYbbPnQQGwjOo=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=

View File

@ -267,6 +267,8 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
for _, a := range t.Attachments {
// Check if we have a file to create
if len(a.File.FileContent) > 0 {
oldID := a.ID
a.ID = 0
a.TaskID = t.ID
fr := io.NopCloser(bytes.NewReader(a.File.FileContent))
err = a.NewAttachment(s, fr, a.File.Name, a.File.Size, user)
@ -274,6 +276,14 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
return
}
log.Debugf("[creating structure] Created new attachment %d", a.ID)
if t.CoverImageAttachmentID == oldID {
t.CoverImageAttachmentID = a.ID
err = t.Update(s, user)
if err != nil {
return
}
}
}
}

View File

@ -319,18 +319,49 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board, token string) (fullV
return nil, err
}
task.Attachments = append(task.Attachments, &models.TaskAttachment{
vikunjaAttachment := &models.TaskAttachment{
File: &files.File{
Name: attachment.Name,
Mime: attachment.MimeType,
Size: uint64(buf.Len()),
FileContent: buf.Bytes(),
},
})
}
if card.IDAttachmentCover != "" && card.IDAttachmentCover == attachment.ID {
vikunjaAttachment.ID = 42
task.CoverImageAttachmentID = 42
}
task.Attachments = append(task.Attachments, vikunjaAttachment)
log.Debugf("[Trello Migration] Downloaded card attachment %s", attachment.ID)
}
// When the cover image was set manually, we need to add it as an attachment
if card.ManualCoverAttachment && len(card.Cover.Scaled) > 0 {
cover := card.Cover.Scaled[len(card.Cover.Scaled)-1]
buf, err := migration.DownloadFile(cover.URL)
if err != nil {
return nil, err
}
coverAttachment := &models.TaskAttachment{
ID: 43,
File: &files.File{
Name: cover.ID + ".jpg",
Mime: "image/jpg", // Seems to always return jpg
Size: uint64(buf.Len()),
FileContent: buf.Bytes(),
},
}
task.Attachments = append(task.Attachments, coverAttachment)
task.CoverImageAttachmentID = coverAttachment.ID
}
project.Tasks = append(project.Tasks, &models.TaskWithComments{Task: *task})
}

View File

@ -69,6 +69,7 @@ func TestConvertTrelloToVikunja(t *testing.T) {
},
Attachments: []*trello.Attachment{
{
ID: "5cc71b16f0c7a57bed3c94e9",
Name: "Testimage.jpg",
IsUpload: true,
MimeType: "image/jpg",