diff --git a/main.go b/main.go index 3cdc7f2..2bc022f 100644 --- a/main.go +++ b/main.go @@ -315,6 +315,7 @@ func TrelloFunc(w http.ResponseWriter, r *http.Request) { } case "createCheckItem": card.Checklist.AddToChecklist(event.Action.Data.ChItem) + card.Checklist.EnsureOrder() if checklist := card.Issue.Checklist; checklist != nil && len(card.Checklist.Items) <= len(checklist) { needsUpdate = false } diff --git a/trello/card.go b/trello/card.go index 7b9c458..93c5ceb 100644 --- a/trello/card.go +++ b/trello/card.go @@ -62,8 +62,8 @@ func (card *Card) load() { /* Adds a card to the list with a given name and returns the card id */ func (trello *Trello) AddCard(listid string, name string, desc string) *Card { - data := Card{ trello: trello, Members: NewSet() } - GenPOSTForm(trello, "/cards/", &data, url.Values{ + data := &Card{ trello: trello, Members: NewSet() } + GenPOSTForm(trello, "/cards/", data, url.Values{ "name": { name }, "idList": { listid }, "desc": { desc }, @@ -72,7 +72,7 @@ func (trello *Trello) AddCard(listid string, name string, desc string) *Card { data.cache() // TODO if error - return &data + return data } /* Retrieves the card from the server */ @@ -95,6 +95,9 @@ func (card *Card) attachURL(addr string) { func (card *Card) AttachIssue(issue *github.Issue) { card.attachURL(issue.IssueURL()) + /* We don't have a change to wait until the update, add up instantly */ + card.Issue = issue + card.cache() } /* Move a card to the different list */ diff --git a/trello/checklist.go b/trello/checklist.go index 558c588..7dbb91e 100644 --- a/trello/checklist.go +++ b/trello/checklist.go @@ -30,7 +30,7 @@ func (card *Card) CopyChecklist(checklist *Checklist) { card.Checklist.card = card card.Checklist.Items = make([]CheckItem, len(checklist.Items)) for i, v := range checklist.Items { - card.Checklist.Items[i] = CheckItem{ v.State == "completed", v.Text, v.Id, v.State } + card.Checklist.Items[i] = CheckItem{ v.State == "complete", v.Text, v.Id, v.State } } card.Checklist.Id = checklist.Id card.Checklist.updateLookup() @@ -48,6 +48,18 @@ func (checklist *Checklist) updateLookup() { } } +/* Ensures items are in correct order, fixes out of band delivery of checklist items + That's probably a bad way to do it, but it works for now. TODO: come up with something */ +func (checklist *Checklist) EnsureOrder() { + var data []CheckItem + GenGET(checklist.card.trello, "/checklists/" + checklist.Id + "/checkItems", &data) + for i, v := range checklist.Items { + if data[i].Id != v.Id { + log.Printf("[BUG] Wrong order delivery detected at position %d", i) + } + } +} + /* Add a checklist to the card and return the id */ func (card *Card) AddChecklist() *Checklist { log.Printf("Adding a checklist to the card %s.", card.Id) @@ -104,6 +116,7 @@ func (card *Card) DelChecklist() { /* Add an item to checklist, note must have an Id */ func (checklist *Checklist) AddToChecklist(itm CheckItem) { + itm.Checked = itm.State == "complete" n := len(checklist.Items) checklist.Items = append(checklist.Items, itm) checklist.in2id = append(checklist.in2id, itm.Id)