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/unassign-cards.go
2024-03-04 04:13:58 +01:00

46 lines
993 B
Go

package main
import (
"fmt"
"github.com/adlio/trello"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
)
func unassignCards(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")
me, err := client.GetMyMember(trello.Defaults())
if err != nil {
return fmt.Errorf("cant get member: %w", err)
}
log.Debug().Str("name", me.FullName).Str("id", me.ID).Interface("me", me).Msg("Got User")
cards, err := board.GetCards(trello.Defaults())
if err != nil {
return fmt.Errorf("cant get cards from board: %w", err)
}
for _, card := range cards {
if len(card.IDMembers) > 0 {
continue
}
log.Debug().Interface("card", card).Msg("Add Member to card")
_, err = card.AddMemberID(me.ID)
if err != nil {
return fmt.Errorf("cant add member to card: %w", err)
}
}
return nil
}