From d686d417ae16cac8cf488183cf4f1b1f7661c367 Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 9 Apr 2024 12:26:41 +0200 Subject: [PATCH] chore: refactor names and variables --- pkg/modules/migration/trello/trello.go | 24 ++++++++++----------- pkg/modules/migration/trello/trello_test.go | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/modules/migration/trello/trello.go b/pkg/modules/migration/trello/trello.go index e669a4472..861710826 100644 --- a/pkg/modules/migration/trello/trello.go +++ b/pkg/modules/migration/trello/trello.go @@ -120,25 +120,25 @@ func getTrelloBoards(client *trello.Client) (trelloData []*trello.Board, err err return } -func createOrganizationMap(trelloData []*trello.Board) map[string][]*trello.Board { - boardMap := make(map[string][]*trello.Board) +func getTrelloOrganizationsWithBoards(boards []*trello.Board) (boardsByOrg map[string][]*trello.Board) { - for _, board := range trelloData { + boardsByOrg = make(map[string][]*trello.Board) + + for _, board := range boards { // Trello boards without an organization are considered personal boards if board.IDOrganization == "" { board.IDOrganization = "Personal" } - boards, ok := boardMap[board.IDOrganization] - if ok { - boards = append(boards, board) - } else { - boards = []*trello.Board{board} + _, has := boardsByOrg[board.IDOrganization] + if !has { + boardsByOrg[board.IDOrganization] = []*trello.Board{} } - boardMap[board.IDOrganization] = boards + + boardsByOrg[board.IDOrganization] = append(boardsByOrg[board.IDOrganization], board) } - return boardMap + return } func fillCardData(client *trello.Client, board *trello.Board) (err error) { @@ -415,14 +415,14 @@ func (m *Migration) Migrate(u *user.User) (err error) { client := trello.NewClient(config.MigrationTrelloKey.GetString(), m.Token) client.Logger = log.GetLogger() - data, err := getTrelloBoards(client) + boards, err := getTrelloBoards(client) if err != nil { return } log.Debugf("[Trello Migration] Got all trello data for user %d", u.ID) - organizationMap := createOrganizationMap(data) + organizationMap := getTrelloOrganizationsWithBoards(boards) for organizationID, boards := range organizationMap { log.Debugf("[Trello Migration] Getting organization with id %s for user %d", organizationID, u.ID) organization, err := client.GetOrganization(organizationID, trello.Defaults()) diff --git a/pkg/modules/migration/trello/trello_test.go b/pkg/modules/migration/trello/trello_test.go index 7c4e6ead3..9c7bc63ac 100644 --- a/pkg/modules/migration/trello/trello_test.go +++ b/pkg/modules/migration/trello/trello_test.go @@ -452,7 +452,7 @@ func TestConvertTrelloToVikunja(t *testing.T) { }, } - organizationMap := createOrganizationMap(trelloData) + organizationMap := getTrelloOrganizationsWithBoards(trelloData) for organizationID, boards := range organizationMap { hierarchy, err := convertTrelloDataToVikunja(organizationID, boards, "") @@ -467,7 +467,7 @@ func TestConvertTrelloToVikunja(t *testing.T) { func TestCreateOrganizationMap(t *testing.T) { trelloData, _ := getTestBoard(t) - organizationMap := createOrganizationMap(trelloData) + organizationMap := getTrelloOrganizationsWithBoards(trelloData) expectedMap := map[string][]*trello.Board{ "orgid": { trelloData[0],