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.Logger = log.GetLogger()
log.Debugf("[Trello Migration] Getting boards...")
trelloData, err = client.GetMyBoards(trello.Defaults())
if err != nil {
return
}
log.Debugf("[Trello Migration] Got %d trello boards", len(trelloData))
for _, board := range trelloData {
log.Debugf("[Trello Migration] Getting lists for board %s", board.ID)
board.Lists, err = board.GetLists(trello.Defaults())
if err != nil {
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))
for _, list := range board.Lists {
listMap[list.ID] = list
}
log.Debugf("[Trello Migration] Getting cards for board %s", board.ID)
cards, err := board.GetCards(allArg)
if err != nil {
return nil, err
}
log.Debugf("[Trello Migration] Got %d cards for board %s", len(cards), board.ID)
for _, card := range cards {
list, exists := listMap[card.IDList]
if !exists {
@ -123,6 +135,8 @@ func getTrelloData(token string) (trelloData []*trello.Board, err error) {
list.Cards = append(list.Cards, card)
}
log.Debugf("[Trello Migration] Looked for attachements on all cards of board %s", board.ID)
}
return
@ -144,6 +158,9 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
}
var bucketID int64 = 1
log.Debugf("[Trello Migration] Converting %d boards to vikunja lists", len(trelloData))
for _, board := range trelloData {
list := &models.List{
Title: board.Name,
@ -154,6 +171,7 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
// 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
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)
if err != nil {
return nil, err
@ -170,7 +188,12 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
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 {
log.Debugf("[Trello Migration] Converting card %s", card.ID)
// The usual stuff: Title, description, position, bucket id
task := &models.Task{
Title: card.Name,
@ -197,6 +220,9 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
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
for _, label := range card.Labels {
@ -210,14 +236,22 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
Title: label.Name,
HexColor: color,
})
log.Debugf("[Trello Migration] Converted label %s from card %s", label.ID, card.ID)
}
// 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 {
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
}
log.Debugf("[Trello Migration] Downloading card attachment %s", attachment.ID)
buf, err := migration.DownloadFile(attachment.URL)
if err != nil {
return nil, err
@ -231,6 +265,8 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
FileContent: buf.Bytes(),
},
})
log.Debugf("[Trello Migration] Downloaded card attachment %s", attachment.ID)
}
list.Tasks = append(list.Tasks, task)
@ -240,11 +276,11 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
bucketID++
}
log.Debugf("[Trello Migration] Converted all cards to tasks for board %s", board.ID)
fullVikunjaHierachie[0].Lists = append(fullVikunjaHierachie[0].Lists, list)
}
// TODO: More logging
return
}