From b314b942b9d3fb58df56c17b5f47d081dc17c4f4 Mon Sep 17 00:00:00 2001 From: kekskurse Date: Mon, 4 Mar 2024 04:13:58 +0100 Subject: [PATCH] stuff --- Readme.md | 4 +++ main.go | 5 ++++ move-backlog-card-with-date.go | 23 ++++++++++++++++- unassign-cards.go | 46 ++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 unassign-cards.go diff --git a/Readme.md b/Readme.md index 89fcc96..a97f767 100644 --- a/Readme.md +++ b/Readme.md @@ -12,9 +12,13 @@ Remove cards from the "Done" list which are older than 7 days ## move-backlog-card-with-date Move all cards in the Backlog where the due date is in the past to the "ToDo" list and remove the due date +## unassign-cards +Assign all card with have no assign user to the user how run the script + # Example Cron setup ``` */5 * * * * /home/pi/trello-bot-pi move-backlog-card-with-date 0 5 * * * /home/pi/trello-bot-pi reset-daily-tasks 0 5 * * * /home/pi/trello-bot-pi remove-done-cards +*/5 * * * * /home/pi/trello-bot-pi unassign-cards ``` \ No newline at end of file diff --git a/main.go b/main.go index 854149e..a754997 100644 --- a/main.go +++ b/main.go @@ -38,6 +38,11 @@ func main() { Usage: "Move all cards from \"Backlog\" to \"ToDo\" where the End Date is in the past and remove the duedate", Action: moveBacklogCardWithDate, }, + { + Name: "unassign-cards", + Usage: "Assign all cards without member to current users", + Action: unassignCards, + }, }, } diff --git a/move-backlog-card-with-date.go b/move-backlog-card-with-date.go index 6d5e249..369ee4b 100644 --- a/move-backlog-card-with-date.go +++ b/move-backlog-card-with-date.go @@ -68,11 +68,32 @@ func moveBacklogCardWithDate(cCtx *cli.Context) error { 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) } + } 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) + } + } + } } diff --git a/unassign-cards.go b/unassign-cards.go new file mode 100644 index 0000000..c77ec19 --- /dev/null +++ b/unassign-cards.go @@ -0,0 +1,46 @@ +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 +}