Skip to content

Commit 1b19345

Browse files
authored
Merge pull request #332 from merico-dev/fix-todolistid-empty
fix: trello card can't be created and adding delete function for trello
2 parents ff40deb + b8ccdbb commit 1b19345

File tree

8 files changed

+54
-15
lines changed

8 files changed

+54
-15
lines changed
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
package trello
22

3-
import "github.com/merico-dev/stream/pkg/util/log"
4-
5-
// Delete does not remove trello board and lists
3+
// Delete delete trello board and lists
64
func Delete(options map[string]interface{}) (bool, error) {
7-
log.Info("Delelte will do nothing, because someone might be using the existing board.")
5+
var opt *Options
6+
var err error
7+
8+
if opt, err = convertMap2Options(options); err != nil {
9+
return false, err
10+
}
11+
if err := validateOptions(opt); err != nil {
12+
return false, err
13+
}
14+
15+
if err = DeleteTrelloBoard(opt); err != nil {
16+
return false, err
17+
}
818
return true, nil
919
}

internal/pkg/plugin/trello/trello.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,12 @@ func CreateTrelloBoard(options *Options) (*TrelloItemId, error) {
7979
doneListId: done,
8080
}, nil
8181
}
82+
83+
// DeleteTrelloBoard delete specified board
84+
func DeleteTrelloBoard(options *Options) error {
85+
c, err := trello.NewClient()
86+
if err != nil {
87+
return err
88+
}
89+
return c.CheckAndDeleteBoard(options.Owner, options.Repo, options.KanbanBoardName)
90+
}

internal/pkg/plugin/trello/update.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ func Update(options map[string]interface{}) (map[string]interface{}, error) {
1414
return nil, err
1515
}
1616

17+
if err = DeleteTrelloBoard(opt); err != nil {
18+
return nil, err
19+
}
20+
1721
trelloIds, err := CreateTrelloBoard(opt)
1822
if err != nil {
1923
return nil, err

internal/pkg/plugin/trellogithub/create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ func Create(options map[string]interface{}) (map[string]interface{}, error) {
1919

2020
trelloItemId := &TrelloItemId{
2121
boardId: tg.options.BoardId,
22-
todoListId: tg.options.todoListId,
23-
doingListId: tg.options.doingListId,
24-
doneListId: tg.options.doneListId,
22+
todoListId: tg.options.TodoListId,
23+
doingListId: tg.options.DoingListId,
24+
doneListId: tg.options.DoneListId,
2525
}
2626

2727
if err := tg.AddTrelloIdSecret(trelloItemId); err != nil {

internal/pkg/plugin/trellogithub/update.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ func Update(options map[string]interface{}) (map[string]interface{}, error) {
2525

2626
trelloItemId := &TrelloItemId{
2727
boardId: tg.options.BoardId,
28-
todoListId: tg.options.todoListId,
29-
doingListId: tg.options.doingListId,
30-
doneListId: tg.options.doneListId,
28+
todoListId: tg.options.TodoListId,
29+
doingListId: tg.options.DoingListId,
30+
doneListId: tg.options.DoneListId,
3131
}
3232

3333
if err := tg.AddTrelloIdSecret(trelloItemId); err != nil {

internal/pkg/plugin/trellogithub/workflow.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type Options struct {
2222
Repo string
2323
Branch string
2424
BoardId string
25-
todoListId string
26-
doingListId string
27-
doneListId string
25+
TodoListId string
26+
DoingListId string
27+
DoneListId string
2828
}

internal/pkg/pluginengine/change.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func execute(smgr statemanager.Manager, changes []*Change) map[string]error {
9090

9191
for i, c := range changes {
9292
log.Separatorf("Processing progress: %d/%d.", i+1, numOfChanges)
93-
log.Infof("Processing: %s(kind: %s) -> %s ...", c.Tool.Name, c.Tool.Plugin.Kind, c.ActionName)
93+
log.Infof("Processing: %s (%s) -> %s ...", c.Tool.Name, c.Tool.Plugin.Kind, c.ActionName)
9494

9595
var succeeded bool
9696
var err error
@@ -166,7 +166,7 @@ func handleResult(smgr statemanager.Manager, change *Change) error {
166166
log.Debugf("Failed to delete state %s: %s.", key, err)
167167
return err
168168
}
169-
log.Successf("Plugin %s/%s delete done.", change.Tool.Name, change.Tool.Plugin.Kind)
169+
log.Successf("Plugin %s (%s) delete done.", change.Tool.Name, change.Tool.Plugin.Kind)
170170
return nil
171171
}
172172

pkg/util/trello/trello.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ func (c *Client) CheckBoardExists(owner, repo, kanbanBoardName string) (bool, er
9393
return false, nil
9494
}
9595

96+
// CheckAndDeleteBoard if the board exists, delete it
97+
func (c *Client) CheckAndDeleteBoard(owner, repo, kanbanBoardName string) error {
98+
bs, err := c.Client.GetMyBoards()
99+
if err != nil {
100+
return err
101+
}
102+
103+
for _, b := range bs {
104+
if checkTargetBoard(owner, repo, kanbanBoardName, b) {
105+
log.Infof("Board will be deleted, name: %s, description: %s.", b.Name, b.Desc)
106+
return b.Delete()
107+
}
108+
}
109+
return nil
110+
}
111+
96112
func checkTargetBoard(owner, repo, kanbanBoardName string, b *trello.Board) bool {
97113
return !b.Closed && b.Name == kanbanBoardName && b.Desc == boardDesc(owner, repo)
98114
}

0 commit comments

Comments
 (0)