Skip to content

Commit

Permalink
Various fixes, logging for #33
Browse files Browse the repository at this point in the history
  • Loading branch information
landswellsong committed Oct 13, 2016
1 parent 2b6492a commit ebe10b6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 6 additions & 3 deletions trello/card.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 */
Expand All @@ -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 */
Expand Down
15 changes: 14 additions & 1 deletion trello/checklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ebe10b6

Please sign in to comment.