diff --git a/core/section/trello/boards_template.go b/core/section/trello/boards_template.go index 54ff508e..df06079c 100644 --- a/core/section/trello/boards_template.go +++ b/core/section/trello/boards_template.go @@ -12,6 +12,19 @@ package trello const boardsTemplate = ` -All Boards
+ +All Boards
+{{range $b := .Boards}} +
+

There are {{ len $b.Actions }} actions for board {{$b.Board.Name}}.

+
+ {{range $act := $b.Actions}} + {{$act.Date}} {{$act.Type}} {{$act.MemberCreator.FullName}}
+ {{end}} +
+
+{{end}} + +
` diff --git a/core/section/trello/model.go b/core/section/trello/model.go index a81e5092..d79a90a0 100644 --- a/core/section/trello/model.go +++ b/core/section/trello/model.go @@ -31,6 +31,61 @@ func (c *trelloConfig) Clean() { } // Trello objects based upon https://github.com/VojtechVitek/go-trello + +type trelloAction struct { + //client *Client + Id string `json:"id"` + IdMemberCreator string `json:"idMemberCreator"` + Data struct { + DateLastEdited string `json:"dateLastEdited"` + ListBefore struct { + Id string `json:"id"` + Name string `json:"name"` + } `json:"listBefore"` + ListAfter struct { + Id string `json:"id"` + Name string `json:"name"` + } `json:"listAfter"` + CheckItem struct { + Id string `json:"id"` + State string `json:"state"` + Name string `json:"name"` + } `json:"checkItem"` + CheckList struct { + Id string `json:"id"` + Name string `json:"name"` + } `json:"checklist"` + List struct { + Id string `json:"id"` + Name string `json:"name"` + } `json:"list"` + TextData struct { + Emoji struct{} `json:"emoji"` + } `json:"textData"` + Board struct { + Id string `json:"id"` + Name string `json:"name"` + ShortLink string `json:"shortLink"` + } `json:"board"` + Card struct { + Id string `json:"id"` + Name string `json:"name"` + ShortLink string `json:"shortLink"` + IdShort int `json:"idShort"` + } `json:"card"` + Text string `json:"text"` + } `json:"data"` + Type string `json:"type"` + Date string `json:"date"` + MemberCreator struct { + Id string `json:"id"` + AvatarHash string `json:"avatarHash"` + FullName string `json:"fullName"` + Initials string `json:"initials"` + Username string `json:"username"` + } `json:"memberCreator"` +} + type trelloMember struct { ID string `json:"id"` AvatarHash string `json:"avatarHash"` @@ -178,6 +233,7 @@ type trelloListCards struct { type trelloRenderBoard struct { Board trelloBoard + Actions []trelloAction Data []trelloListCards CardCount int ListCount int @@ -195,7 +251,7 @@ type trelloBoardAssignCount struct { } type trelloBoardAssign struct { - AvatarHash string + AvatarHash string MemberName string AssignCounts []trelloBoardAssignCount } diff --git a/core/section/trello/trello.go b/core/section/trello/trello.go index 7e7f6693..7d1f6eeb 100644 --- a/core/section/trello/trello.go +++ b/core/section/trello/trello.go @@ -19,6 +19,7 @@ import ( "io/ioutil" "net/http" "sort" + "time" "github.com/documize/community/core/api/request" "github.com/documize/community/core/log" @@ -205,6 +206,8 @@ func (*Provider) Refresh(ctx *provider.Context, config, data string) string { payload.CardCount += len(list.Cards) } + payload.Actions = fetchBoardActions(&c, &save, board.ID, nil) // TODO pass in date + save.Boards = append(save.Boards, payload) } @@ -220,7 +223,9 @@ func (*Provider) Refresh(ctx *provider.Context, config, data string) string { // Helpers func getBoards(config trelloConfig) (boards []trelloBoard, err error) { - req, err := http.NewRequest("GET", fmt.Sprintf("https://api.trello.com/1/members/me/boards?fields=id,name,url,closed,prefs,idOrganization&key=%s&token=%s", config.AppKey, config.Token), nil) + req, err := http.NewRequest("GET", fmt.Sprintf( + "https://api.trello.com/1/members/me/boards?fields=id,name,url,closed,prefs,idOrganization&key=%s&token=%s", + config.AppKey, config.Token), nil) log.IfErr(err) client := &http.Client{} res, err := client.Do(req) @@ -370,6 +375,41 @@ func fetchMember(config *trelloConfig, render *trelloRender, memberID string) (m return } +func fetchBoardActions(config *trelloConfig, render *trelloRender, boardID string, since *time.Time) (actions []trelloAction) { + + if len(config.AppKey) == 0 { + config.AppKey = request.ConfigString(meta.ConfigHandle(), "appKey") + } + uri := fmt.Sprintf("https://api.trello.com/1/boards/%s/actions?since=2016-08-01&key=%s&token=%s", boardID, config.AppKey, config.Token) + req, err := http.NewRequest("GET", uri, nil) + if err != nil { + log.IfErr(err) + return + } + client := &http.Client{} + res, err := client.Do(req) + if err != nil { + log.IfErr(err) + return + } + + if res.StatusCode != http.StatusOK { + log.ErrorString("Trello fetch board actions HTTP status not OK") + return + } + + defer res.Body.Close() + + dec := json.NewDecoder(res.Body) + err = dec.Decode(&actions) + if err != nil { + log.IfErr(err) + return + } + + return +} + func buildPayloadAnalysis(config *trelloConfig, render *trelloRender) { // pre-process labels @@ -438,7 +478,7 @@ func buildPayloadAnalysis(config *trelloConfig, render *trelloRender) { memInfo := fetchMember(config, render, mem) if mNam == memInfo.FullName { render.MemberBoardAssign = append(render.MemberBoardAssign, trelloBoardAssign{MemberName: mNam, AvatarHash: memInfo.AvatarHash}) - for _, b := range render.Boards { + for _, b := range render.Boards { // these are already in order if count, ok := brdCounts[b.Board.ID]; ok { render.MemberBoardAssign[len(render.MemberBoardAssign)-1].AssignCounts = append(render.MemberBoardAssign[len(render.MemberBoardAssign)-1].AssignCounts,