package main import ( "errors" "fmt" "github.com/adlio/trello" "github.com/rs/zerolog/log" "github.com/urfave/cli/v2" ) func resetDailyTasks(cCtx *cli.Context) error { client := getTrelloClient() board, err := client.GetBoard(trelloBordID, trello.Defaults()) if err != nil { return fmt.Errorf("cant get bord: %w", err) } log.Debug().Interface("bord", board).Msg("get bord") labels, err := board.GetLabels() if err != nil { return fmt.Errorf("cant get labels for bord: %w", err) } log.Debug().Interface("labels", labels).Msg("got labels") var dailyLabel *trello.Label for _, l := range labels { if l.Name == "Daily" { dailyLabel = l break } } if dailyLabel == nil { return errors.New("cant find label with the name \"Daily\"") } log.Debug().Interface("daily label", dailyLabel).Msg("got daily label") lists, err := board.GetLists(trello.Defaults()) if err != nil { return fmt.Errorf("cant get losts for board: %w", err) } log.Debug().Interface("lists", lists).Msg("got lists") var todoList *trello.List for _, list := range lists { if list.Name == "ToDo" { todoList = list break } } if todoList == nil { return errors.New("cant find list with the text \"ToDo\"") } cards, err := board.GetCards() if err != nil { return fmt.Errorf("cant get cards for bord: %w", err) } log.Debug().Int("number of cards", len(cards)).Msg("Get Cards") for _, card := range cards { foundLabel := false for _, label := range card.Labels { if label.ID == dailyLabel.ID { foundLabel = true break } } if !foundLabel { break } err = card.MoveToList(todoList.ID, trello.Defaults()) if err != nil { return fmt.Errorf("cant move card to todo list: %w", err) } } return nil }