1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-24 15:49:44 +02:00

rough-cut actions and archived

This commit is contained in:
Elliott Stoneham 2016-09-08 17:17:45 +01:00
parent da6e3b0e11
commit 918a487f43
4 changed files with 123 additions and 35 deletions

View file

@ -12,6 +12,27 @@
package trello
const archiveTemplate = `
Archive?<br>
<b>Deleted and Archived Cards</b><br>
Since ###1st Aug 2016###<br>
{{range $b := .Boards}}
<div>
<p>For board <a href="{{ $b.Board.URL }}">{{$b.Board.Name}}</a>.</p>
<div>
{{range $act := $b.Actions}}
{{if eq $act.Type "deleteCard" }}
Deleted:
{{$act.Data.List.Name}}/{{$act.Data.Card.Name}} - {{$act.Data.Text}}
<br>
{{end}}
{{end}}
{{range $arch := $b.Archived}}
Archived:
{{$arch.Name}} - {{$arch.Desc}}
<br>
{{end}}
</div>
</div>
{{end}}
<br>
`

View file

@ -14,12 +14,18 @@ package trello
const boardsTemplate = `
<b>All Boards</b><br>
Changes since ###1 Aug 2016###.
{{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>
{{range $idx, $act := $b.ActionSummary}}
{{$act}} {{$idx}},
{{end}}
{{if gt (len $b.Archived) 0}}
archiveCard
{{len $b.Archived}}.
<br>
{{end}}
</div>
</div>

View file

@ -33,7 +33,6 @@ 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 {
@ -232,11 +231,13 @@ type trelloListCards struct {
}
type trelloRenderBoard struct {
Board trelloBoard
Actions []trelloAction
Data []trelloListCards
CardCount int
ListCount int
Board trelloBoard
Data []trelloListCards
CardCount int
ListCount int
Actions []trelloAction
ActionSummary map[string]int
Archived []trelloCard
}
type trelloSharedLabel struct {

View file

@ -162,10 +162,19 @@ func (*Provider) Render(ctx *provider.Context, config, data string) string {
t := template.New("trello")
var err error
t, err = t.Parse(renderTemplate)
log.IfErr(err)
if err != nil {
log.IfErr(err)
return ""
}
buffer := new(bytes.Buffer)
t.Execute(buffer, payload)
err = t.Execute(buffer, payload)
if err != nil {
log.IfErr(err)
return ""
}
return buffer.String()
}
@ -206,7 +215,7 @@ 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
payload.Actions, payload.Archived = fetchBoardActions(&c, &save, board.ID, nil) // TODO pass in date
save.Boards = append(save.Boards, payload)
}
@ -375,36 +384,79 @@ func fetchMember(config *trelloConfig, render *trelloRender, memberID string) (m
return
}
func fetchBoardActions(config *trelloConfig, render *trelloRender, boardID string, since *time.Time) (actions []trelloAction) {
func fetchBoardActions(config *trelloConfig, render *trelloRender, boardID string, since *time.Time) (actions []trelloAction, archived []trelloCard) {
sinceString := "2016-08-01" // TODO
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
{
uri := fmt.Sprintf("https://api.trello.com/1/boards/%s/actions?limit=1000&since=%s&key=%s&token=%s", boardID, sinceString, 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
}
}
if res.StatusCode != http.StatusOK {
log.ErrorString("Trello fetch board actions HTTP status not OK")
return
}
{
uri := fmt.Sprintf("https://api.trello.com/1/boards/%s/cards?filter=closed&since=%s&key=%s&token=%s",
boardID, sinceString, 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
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
msg := ""
txt, err := ioutil.ReadAll(res.Body)
if err == nil {
msg = string(txt)
} else {
msg = err.Error()
}
log.ErrorString("Trello fetch board archived HTTP status not OK - " + msg)
return
}
dec := json.NewDecoder(res.Body)
err = dec.Decode(&actions)
if err != nil {
log.IfErr(err)
return
defer res.Body.Close()
dec := json.NewDecoder(res.Body)
err = dec.Decode(&archived)
if err != nil {
log.IfErr(err)
return
}
}
return
@ -427,7 +479,7 @@ func buildPayloadAnalysis(config *trelloConfig, render *trelloRender) {
memberBoardCount := make(map[string]map[string]int)
// main loop
for _, brd := range render.Boards {
for brdIdx, brd := range render.Boards {
for _, lst := range brd.Data {
for _, crd := range lst.Cards {
render.CardTotal++
@ -452,6 +504,14 @@ func buildPayloadAnalysis(config *trelloConfig, render *trelloRender) {
}
}
}
// ActionSummary
if render.Boards[brdIdx].ActionSummary == nil {
render.Boards[brdIdx].ActionSummary = make(map[string]int)
}
for _, act := range brd.Actions {
render.Boards[brdIdx].ActionSummary[act.Type]++
}
}
//post-process labels