Skip to content
Permalink
Browse files

initial backup.

  • Loading branch information...
fiatjaf committed Jul 28, 2018
1 parent f1697fd commit 7715ecbf62d8247b3b4d3ec5b2cf6b05cadc9853
Showing with 106 additions and 2 deletions.
  1. +91 −0 backup.go
  2. +6 −0 methods.go
  3. +1 −1 postgres.sql
  4. +8 −1 types.go
@@ -0,0 +1,91 @@
package main

func initialBackup(board, token string) error {
log.Info().Str("board", board).Msg("performing initial backup")
trello := makeTrelloClient(token)

var b Board
err := trello("get", "/1/boards/"+board+
"?fields=id,shortLink,name"+
"&lists=none"+
"&labels=all&label_fields=id,color,name&labels_limit=1000"+
"&cards=all&card_fields=id,name,shortLink,desc,due,dueComplete,closed,idAttachmentCover,idList,idLabels,idChecklists,idMembers"+
"&card_members=false&card_attachments=true&card_attachment_fields=url,name"+
"&actions=commentCard&actions_limit=1000&actions_fields=date,data&action_member=false&action_memberCreator=true&action_memberCreator_fields=id,username",
nil, &b)

for _, label := range b.Labels {
onAllowed(log, token, Webhook{
Action: Action{
Type: "createLabel",
Data: Data{
Board: b,
Label: label,
},
},
})
}
for _, card := range b.Cards {
onAllowed(log, token, Webhook{
Action: Action{
Type: "createCard",
Data: Data{
Board: b,
Card: card,
},
},
})

for _, att := range card.Attachments {
onAllowed(log, token, Webhook{
Action: Action{
Type: "addAttachmentToCard",
Data: Data{
Board: b,
Card: card,
Attachment: att,
},
},
})
}

var checklists []Checklist
trello("get", "/1/cards/"+card.Id+"/checklists"+
"?checkItems=all&checkItem_fields=name,pos,state&fields=name,pos",
nil, &checklists)

for _, checklist := range checklists {
onAllowed(log, token, Webhook{
Action: Action{
Type: "addChecklistToCard",
Data: Data{
Board: b,
Card: card,
Checklist: checklist,
},
},
})

for _, checkItem := range checklist.CheckItems {
onAllowed(log, token, Webhook{
Action: Action{
Type: "createCheckItem",
Data: Data{
Board: b,
Card: card,
Checklist: checklist,
CheckItem: checkItem,
},
},
})
}
}
}
for _, action := range b.Actions {
onAllowed(log, token, Webhook{
Action: action,
})
}

return err
}
@@ -55,6 +55,12 @@ VALUES ($1, $2, $3, $4)
Msg("failed to set board")
return err
}

// perform initial backup
err = initialBackup(boardId, token)
if err != nil {
return err
}
}

if !enabled {
@@ -12,7 +12,7 @@ CREATE TABLE boards (

CREATE TABLE backups (
id text PRIMARY KEY,
board text,
board text REFERENCES boards (id) ON DELETE CASCADE,
data jsonb NOT NULL,

CHECK (id != ''),
@@ -13,6 +13,14 @@ type Board struct {
ShortLink string `json:"shortLink,omitempty"`
Name string `json:"name,omitempty"`
Memberships []Membership `json:"memberships,omitempty"`
Prefs struct {
Invitations string `json:"invitations,omitempty"` // "admins"
PermissionLevel string `json:"permissionLevel,omitempty"` // "public"
Comments string `json:"comments,omitempty" ` // "public"
} `json:"prefs,omitempty"`
Labels []Label `json:"labels,omitempty"`
Cards []Card `json:"cards,omitempty"`
Actions []Action `json:"actions,omitempty"`

Enabled bool `json:"-"`
Email string `db:"email" json:"email"`
@@ -47,7 +55,6 @@ type Card struct {
IdAttachmentCover string `json:"idAttachmentCover,omitempty"`
IdMembers []string `json:"idMembers,omitempty"`
IdLabels []string `json:"idLabels,omitempty"`
Checklists []Checklist `json:"checklists,omitempty"`
Attachments []Attachment `json:"attachments,omitempty"`
CustomFieldItems []CustomFieldItem `json:"customFieldItems,omitempty"`

0 comments on commit 7715ecb

Please sign in to comment.
You can’t perform that action at this time.