adlio / trello

Trello API wrapper for Go
MIT License
220 stars 71 forks source link

Client longevity is not propagated to cards if requested on lists #18

Closed Crevil closed 6 years ago

Crevil commented 6 years ago

When getting lists with cards in the same request, the client is not propagated to the card entities.

Function Board#GetLists only moves the client to the lists, not the cards on the list: https://github.com/adlio/trello/blob/50836c3a16a19f329c4612d3d3ae2e09c49721cc/list.go#L38-L45

func getCardsOnList(board *trello.Board) ([]*trello.Card, error) {
  lists, _ := board.GetLists(args("fields", "name", "cards", "open", "card_fields", "id,name,labels"))
  for _, l := range lists {
    for _, c := range l.Cards {
      // any action on c panics
      c.CopyToList("listid", trello.Defaults())
    }
  }
}

The fix seems simple:

func (b *Board) GetLists(args Arguments) (lists []*List, err error) {
    path := fmt.Sprintf("boards/%s/lists", b.ID)
    err = b.client.Get(path, args, &lists)
    for i := range lists {
        lists[i].client = b.client
        if len(lists[i].Cards) == 0 {
            continue
        }
        for j := range lists[i].Cards {
            lists[i].Cards[j].client = lists[i].client
        }
    }
    return
}

I can provide a PR if this is a bug and should be fixed. If it's expected behaviour I think a note in the documentation is expected.

adlio commented 6 years ago

I'd call that a bug. A PR would be excellent, thank you.