feat(migration): include non upload attachments from Trello (#2261)
continuous-integration/drone/push Build is passing Details

This makes the Trello migrator include attachments that are not file uploads. To include them in Vikunja without missing data, their text (usually links) will be appended to the Vikunja description.

Co-authored-by: Elscrux <nickposer2102@gmail.com>
Reviewed-on: #2261
Reviewed-by: konrad <k@knt.li>
Co-authored-by: Elscrux <elscrux@gmail.com>
Co-committed-by: Elscrux <elscrux@gmail.com>
This commit is contained in:
Elscrux 2024-04-10 22:12:06 +00:00 committed by konrad
parent 423558f58a
commit 61ee0bd5e2
2 changed files with 43 additions and 33 deletions

View File

@ -336,37 +336,39 @@ func convertTrelloDataToVikunja(organizationName string, trelloData []*trello.Bo
log.Debugf("[Trello Migration] Downloading %d card attachments from card %s", len(card.Attachments), card.ID)
}
for _, attachment := range card.Attachments {
if !attachment.IsUpload { // There are other types of attachments which are not files. We can only handle files.
log.Debugf("[Trello Migration] Attachment %s does not have a mime type, not downloading", attachment.ID)
if attachment.IsUpload {
// Download file and add it as attachment
log.Debugf("[Trello Migration] Downloading card attachment %s", attachment.ID)
buf, err := migration.DownloadFileWithHeaders(attachment.URL, map[string][]string{
"Authorization": {`OAuth oauth_consumer_key="` + config.MigrationTrelloKey.GetString() + `", oauth_token="` + token + `"`},
})
if err != nil {
return nil, err
}
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)
continue
}
log.Debugf("[Trello Migration] Downloading card attachment %s", attachment.ID)
buf, err := migration.DownloadFileWithHeaders(attachment.URL, map[string][]string{
"Authorization": {`OAuth oauth_consumer_key="` + config.MigrationTrelloKey.GetString() + `", oauth_token="` + token + `"`},
})
if err != nil {
return nil, err
}
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)
// Other links are not attachments in Vikunja, but we can add them to the description
task.Description += `<p><a href="` + attachment.URL + `">` + attachment.Name + "</a></p>\n"
}
// When the cover image was set manually, we need to add it as an attachment

View File

@ -78,6 +78,13 @@ func getTestBoard(t *testing.T) ([]*trello.Board, time.Time) {
MimeType: "image/jpg",
URL: "https://vikunja.io/testimage.jpg",
},
{
ID: "7cc71b16f0c7a57bed3c94e9",
Name: "Website",
IsUpload: false,
MimeType: "",
URL: "https://vikunja.io",
},
},
},
{
@ -265,10 +272,11 @@ func TestConvertTrelloToVikunja(t *testing.T) {
Tasks: []*models.TaskWithComments{
{
Task: models.Task{
Title: "Test Card 1",
Description: "<p>Card Description <strong>bold</strong></p>\n",
BucketID: 1,
DueDate: time1,
Title: "Test Card 1",
Description: "<p>Card Description <strong>bold</strong></p>\n" +
"<p><a href=\"https://vikunja.io\">Website</a></p>\n",
BucketID: 1,
DueDate: time1,
Labels: []*models.Label{
{
Title: "Label 1",
@ -481,6 +489,6 @@ func TestCreateOrganizationMap(t *testing.T) {
},
}
if diff, equal := messagediff.PrettyDiff(organizationMap, expectedMap); !equal {
t.Errorf("converted trello data = %v,\nwant %v,\ndiff: %v", organizationMap, expectedMap, diff)
t.Errorf("converted organization map = %v,\nwant %v,\ndiff: %v", organizationMap, expectedMap, diff)
}
}