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"
|
|
|
|
"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)
|
|
|
|
}
|
|
|
|
|
2024-03-04 03:34:57 +00:00
|
|
|
var cardsToMoveToTheEndOfTheList []*trello.Card
|
|
|
|
|
2024-03-04 02:11:29 +00:00
|
|
|
for _, card := range cards {
|
|
|
|
log.Debug().Str("name", card.Name).Msg("Found card")
|
|
|
|
if card.Due == nil {
|
2024-03-04 03:34:57 +00:00
|
|
|
for _, cardToMove := range cardsToMoveToTheEndOfTheList {
|
|
|
|
err = cardToMove.MoveToBottomOfList()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cant move card to end: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cardsToMoveToTheEndOfTheList = []*trello.Card{}
|
2024-03-04 02:11:29 +00:00
|
|
|
continue
|
|
|
|
}
|
2024-03-04 03:34:57 +00:00
|
|
|
cardsToMoveToTheEndOfTheList = append(cardsToMoveToTheEndOfTheList, card)
|
2024-03-04 02:11:29 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
err = card.Update(trello.Arguments{"due": "null"})
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cant update card to remove due date: %w", err)
|
|
|
|
}
|
2024-03-04 03:13:58 +00:00
|
|
|
} else {
|
|
|
|
msg := fmt.Sprintf("Saved for resubmission on %v", card.Due.Format(time.DateTime))
|
|
|
|
comments, err := card.GetCommentActions()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cant get last comments: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
foundComment := false
|
|
|
|
for _, comment := range comments {
|
|
|
|
if comment.Data.Text == msg {
|
|
|
|
foundComment = true
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !foundComment {
|
|
|
|
_, err = card.AddComment(msg)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cant get comment to card: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-04 02:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|