mirror of
https://github.com/documize/community.git
synced 2025-07-24 23:59:47 +02:00
rough-wip actions
This commit is contained in:
parent
86de669fed
commit
4ccf3ea939
3 changed files with 113 additions and 4 deletions
|
@ -12,6 +12,19 @@
|
|||
package trello
|
||||
|
||||
const boardsTemplate = `
|
||||
All Boards<br>
|
||||
|
||||
<b>All Boards</b><br>
|
||||
{{range $b := .Boards}}
|
||||
<div>
|
||||
<p>There are {{ len $b.Actions }} actions for board <a href="{{ $b.Board.URL }}">{{$b.Board.Name}}.</a></p>
|
||||
<div>
|
||||
{{range $act := $b.Actions}}
|
||||
{{$act.Date}} {{$act.Type}} {{$act.MemberCreator.FullName}} <br>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
|
||||
<br>
|
||||
`
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue