This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
trello-bot/reset-daily-tasks.go

94 lines
1.9 KiB
Go
Raw Normal View History

2024-03-04 02:11:29 +00:00
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 {
2024-03-07 10:39:08 +00:00
log.Debug().Str("name", card.Name).Msg("Check")
2024-03-04 02:11:29 +00:00
foundLabel := false
for _, label := range card.Labels {
if label.ID == dailyLabel.ID {
foundLabel = true
2024-03-07 10:39:08 +00:00
log.Debug().Interface("card", card).Msg("Found daily card")
2024-03-04 02:11:29 +00:00
break
}
}
if !foundLabel {
2024-03-07 10:39:08 +00:00
log.Debug().Str("name", card.Name).Msg("Not match")
continue
2024-03-04 02:11:29 +00:00
}
err = card.MoveToList(todoList.ID, trello.Defaults())
if err != nil {
return fmt.Errorf("cant move card to todo list: %w", err)
}
}
return nil
}