82 lines
1.8 KiB
Go
82 lines
1.8 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
"github.com/adlio/trello"
|
||
|
"github.com/rs/zerolog/log"
|
||
|
"github.com/urfave/cli/v2"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func moveBacklogCardWithDate(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 backlogList *trello.List
|
||
|
var todoList *trello.List
|
||
|
|
||
|
for _, list := range lists {
|
||
|
if list.Name == "Backlog" {
|
||
|
backlogList = list
|
||
|
}
|
||
|
if list.Name == "ToDo" {
|
||
|
todoList = list
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if backlogList == nil {
|
||
|
return errors.New("cant find list with the text \"Backlog\"")
|
||
|
}
|
||
|
|
||
|
if todoList == nil {
|
||
|
return errors.New("cant find list with the text \"ToDo\"")
|
||
|
}
|
||
|
|
||
|
cards, err := backlogList.GetCards()
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("cant get card for Backlog list list: %w", err)
|
||
|
}
|
||
|
|
||
|
for _, card := range cards {
|
||
|
log.Debug().Str("name", card.Name).Msg("Found card")
|
||
|
if card.Due == nil {
|
||
|
continue
|
||
|
}
|
||
|
if card.Due.Before(time.Now()) {
|
||
|
err = card.MoveToList(todoList.ID)
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("cant move card to todo list: %w", err)
|
||
|
}
|
||
|
err = card.MoveToTopOfList()
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("cant move card to top of todo list: %w", err)
|
||
|
}
|
||
|
_, err = card.AddComment(fmt.Sprintf("Due Date %v in Backlog reached, moved to todo!", card.Due))
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("cant add comment to card: %w", err)
|
||
|
}
|
||
|
card.Due = nil
|
||
|
err = card.Update(trello.Arguments{"due": "null"})
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("cant update card to remove due date: %w", err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|