Add more logging

This commit is contained in:
kolaente 2020-12-17 01:50:31 +01:00
parent 575c766c32
commit f41df78e73
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 38 additions and 2 deletions

View File

@ -89,27 +89,39 @@ func getTrelloData(token string) (trelloData []*trello.Board, err error) {
client := trello.NewClient(config.MigrationTrelloKey.GetString(), token) client := trello.NewClient(config.MigrationTrelloKey.GetString(), token)
client.Logger = log.GetLogger() client.Logger = log.GetLogger()
log.Debugf("[Trello Migration] Getting boards...")
trelloData, err = client.GetMyBoards(trello.Defaults()) trelloData, err = client.GetMyBoards(trello.Defaults())
if err != nil { if err != nil {
return return
} }
log.Debugf("[Trello Migration] Got %d trello boards", len(trelloData))
for _, board := range trelloData { for _, board := range trelloData {
log.Debugf("[Trello Migration] Getting lists for board %s", board.ID)
board.Lists, err = board.GetLists(trello.Defaults()) board.Lists, err = board.GetLists(trello.Defaults())
if err != nil { if err != nil {
return return
} }
log.Debugf("[Trello Migration] Got %d lists for board %s", len(board.Lists), board.ID)
listMap := make(map[string]*trello.List, len(board.Lists)) listMap := make(map[string]*trello.List, len(board.Lists))
for _, list := range board.Lists { for _, list := range board.Lists {
listMap[list.ID] = list listMap[list.ID] = list
} }
log.Debugf("[Trello Migration] Getting cards for board %s", board.ID)
cards, err := board.GetCards(allArg) cards, err := board.GetCards(allArg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.Debugf("[Trello Migration] Got %d cards for board %s", len(cards), board.ID)
for _, card := range cards { for _, card := range cards {
list, exists := listMap[card.IDList] list, exists := listMap[card.IDList]
if !exists { if !exists {
@ -123,6 +135,8 @@ func getTrelloData(token string) (trelloData []*trello.Board, err error) {
list.Cards = append(list.Cards, card) list.Cards = append(list.Cards, card)
} }
log.Debugf("[Trello Migration] Looked for attachements on all cards of board %s", board.ID)
} }
return return
@ -144,6 +158,9 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
} }
var bucketID int64 = 1 var bucketID int64 = 1
log.Debugf("[Trello Migration] Converting %d boards to vikunja lists", len(trelloData))
for _, board := range trelloData { for _, board := range trelloData {
list := &models.List{ list := &models.List{
Title: board.Name, Title: board.Name,
@ -154,6 +171,7 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
// Background // Background
// We're pretty much abusing the backgroundinformation field here - not sure if this is really better than adding a new property to the list // We're pretty much abusing the backgroundinformation field here - not sure if this is really better than adding a new property to the list
if board.Prefs.BackgroundImage != "" { if board.Prefs.BackgroundImage != "" {
log.Debugf("[Trello Migration] Downloading background %s for board %s", board.Prefs.BackgroundImage, board.ID)
buf, err := migration.DownloadFile(board.Prefs.BackgroundImage) buf, err := migration.DownloadFile(board.Prefs.BackgroundImage)
if err != nil { if err != nil {
return nil, err return nil, err
@ -170,7 +188,12 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
Title: l.Name, Title: l.Name,
} }
log.Debugf("[Trello Migration] Converting %d cards to tasks from board %s", len(l.Cards), board.ID)
for _, card := range l.Cards { for _, card := range l.Cards {
log.Debugf("[Trello Migration] Converting card %s", card.ID)
// The usual stuff: Title, description, position, bucket id // The usual stuff: Title, description, position, bucket id
task := &models.Task{ task := &models.Task{
Title: card.Name, Title: card.Name,
@ -197,6 +220,9 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
task.Description += " " + item.Name task.Description += " " + item.Name
} }
} }
if len(card.Checklists) > 0 {
log.Debugf("[Trello Migration] Converted %d checklists from card %s", len(card.Checklists), card.ID)
}
// Labels // Labels
for _, label := range card.Labels { for _, label := range card.Labels {
@ -210,14 +236,22 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
Title: label.Name, Title: label.Name,
HexColor: color, HexColor: color,
}) })
log.Debugf("[Trello Migration] Converted label %s from card %s", label.ID, card.ID)
} }
// Attachments // Attachments
if len(card.Attachments) > 0 {
log.Debugf("[Trello Migration] Downloading %d card attachments from card %s", len(card.Attachments), card.ID)
}
for _, attachment := range card.Attachments { for _, attachment := range card.Attachments {
if attachment.MimeType == "" { // Attachments can also be not downloadable - the mime type is empty in that case. if attachment.MimeType == "" { // Attachments can also be not downloadable - the mime type is empty in that case.
log.Debugf("[Trello Migration] Attachment %s does not have a mime type, not downloading", attachment.ID)
continue continue
} }
log.Debugf("[Trello Migration] Downloading card attachment %s", attachment.ID)
buf, err := migration.DownloadFile(attachment.URL) buf, err := migration.DownloadFile(attachment.URL)
if err != nil { if err != nil {
return nil, err return nil, err
@ -231,6 +265,8 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
FileContent: buf.Bytes(), FileContent: buf.Bytes(),
}, },
}) })
log.Debugf("[Trello Migration] Downloaded card attachment %s", attachment.ID)
} }
list.Tasks = append(list.Tasks, task) list.Tasks = append(list.Tasks, task)
@ -240,11 +276,11 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
bucketID++ bucketID++
} }
log.Debugf("[Trello Migration] Converted all cards to tasks for board %s", board.ID)
fullVikunjaHierachie[0].Lists = append(fullVikunjaHierachie[0].Lists, list) fullVikunjaHierachie[0].Lists = append(fullVikunjaHierachie[0].Lists, list)
} }
// TODO: More logging
return return
} }