63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
"github.com/adlio/trello"
|
||
|
"github.com/rs/zerolog/log"
|
||
|
"github.com/urfave/cli/v2"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func removeDoneCArds(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")
|
||
|
|
||
|
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 doneList *trello.List
|
||
|
|
||
|
for _, list := range lists {
|
||
|
if list.Name == "Done" {
|
||
|
doneList = list
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if doneList == nil {
|
||
|
return errors.New("cant find list with the text \"Done\"")
|
||
|
}
|
||
|
|
||
|
cards, err := doneList.GetCards()
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("cant get card for Done list: %w", err)
|
||
|
}
|
||
|
|
||
|
for _, card := range cards {
|
||
|
log.Debug().Str("name", card.Name).Time("date of last activity", *card.DateLastActivity).Msg("Found card")
|
||
|
if !card.DateLastActivity.Before(time.Now().Add(-7 * 24 * time.Hour)) {
|
||
|
log.Debug().Msg("card not old enough,. keep")
|
||
|
continue
|
||
|
}
|
||
|
log.Info().Msg("card old enough, need to be deletet")
|
||
|
|
||
|
err := card.Delete()
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("cant delete card frome done list: %w", err)
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|