mirror of
https://github.com/documize/community.git
synced 2025-07-27 09:09:44 +02:00
rough-cut actions and archived
This commit is contained in:
parent
da6e3b0e11
commit
918a487f43
4 changed files with 123 additions and 35 deletions
|
@ -12,6 +12,27 @@
|
||||||
package trello
|
package trello
|
||||||
|
|
||||||
const archiveTemplate = `
|
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>
|
<br>
|
||||||
`
|
`
|
||||||
|
|
|
@ -14,12 +14,18 @@ package trello
|
||||||
const boardsTemplate = `
|
const boardsTemplate = `
|
||||||
|
|
||||||
<b>All Boards</b><br>
|
<b>All Boards</b><br>
|
||||||
|
Changes since ###1 Aug 2016###.
|
||||||
{{range $b := .Boards}}
|
{{range $b := .Boards}}
|
||||||
<div>
|
<div>
|
||||||
<p>There are {{ len $b.Actions }} actions for board <a href="{{ $b.Board.URL }}">{{$b.Board.Name}}.</a></p>
|
<p>There are {{ len $b.Actions }} actions for board <a href="{{ $b.Board.URL }}">{{$b.Board.Name}}.</a></p>
|
||||||
<div>
|
<div>
|
||||||
{{range $act := $b.Actions}}
|
{{range $idx, $act := $b.ActionSummary}}
|
||||||
{{$act.Date}} {{$act.Type}} {{$act.MemberCreator.FullName}} <br>
|
{{$act}} {{$idx}},
|
||||||
|
{{end}}
|
||||||
|
{{if gt (len $b.Archived) 0}}
|
||||||
|
archiveCard
|
||||||
|
{{len $b.Archived}}.
|
||||||
|
<br>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -33,7 +33,6 @@ func (c *trelloConfig) Clean() {
|
||||||
// Trello objects based upon https://github.com/VojtechVitek/go-trello
|
// Trello objects based upon https://github.com/VojtechVitek/go-trello
|
||||||
|
|
||||||
type trelloAction struct {
|
type trelloAction struct {
|
||||||
//client *Client
|
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
IdMemberCreator string `json:"idMemberCreator"`
|
IdMemberCreator string `json:"idMemberCreator"`
|
||||||
Data struct {
|
Data struct {
|
||||||
|
@ -233,10 +232,12 @@ type trelloListCards struct {
|
||||||
|
|
||||||
type trelloRenderBoard struct {
|
type trelloRenderBoard struct {
|
||||||
Board trelloBoard
|
Board trelloBoard
|
||||||
Actions []trelloAction
|
|
||||||
Data []trelloListCards
|
Data []trelloListCards
|
||||||
CardCount int
|
CardCount int
|
||||||
ListCount int
|
ListCount int
|
||||||
|
Actions []trelloAction
|
||||||
|
ActionSummary map[string]int
|
||||||
|
Archived []trelloCard
|
||||||
}
|
}
|
||||||
|
|
||||||
type trelloSharedLabel struct {
|
type trelloSharedLabel struct {
|
||||||
|
|
|
@ -162,10 +162,19 @@ func (*Provider) Render(ctx *provider.Context, config, data string) string {
|
||||||
t := template.New("trello")
|
t := template.New("trello")
|
||||||
var err error
|
var err error
|
||||||
t, err = t.Parse(renderTemplate)
|
t, err = t.Parse(renderTemplate)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
log.IfErr(err)
|
log.IfErr(err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
buffer := new(bytes.Buffer)
|
buffer := new(bytes.Buffer)
|
||||||
t.Execute(buffer, payload)
|
err = t.Execute(buffer, payload)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.IfErr(err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
}
|
}
|
||||||
|
@ -206,7 +215,7 @@ func (*Provider) Refresh(ctx *provider.Context, config, data string) string {
|
||||||
payload.CardCount += len(list.Cards)
|
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)
|
save.Boards = append(save.Boards, payload)
|
||||||
}
|
}
|
||||||
|
@ -375,12 +384,17 @@ func fetchMember(config *trelloConfig, render *trelloRender, memberID string) (m
|
||||||
return
|
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 {
|
if len(config.AppKey) == 0 {
|
||||||
config.AppKey = request.ConfigString(meta.ConfigHandle(), "appKey")
|
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)
|
|
||||||
|
{
|
||||||
|
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)
|
req, err := http.NewRequest("GET", uri, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.IfErr(err)
|
log.IfErr(err)
|
||||||
|
@ -406,6 +420,44 @@ func fetchBoardActions(config *trelloConfig, render *trelloRender, boardID strin
|
||||||
log.IfErr(err)
|
log.IfErr(err)
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
dec := json.NewDecoder(res.Body)
|
||||||
|
err = dec.Decode(&archived)
|
||||||
|
if err != nil {
|
||||||
|
log.IfErr(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -427,7 +479,7 @@ func buildPayloadAnalysis(config *trelloConfig, render *trelloRender) {
|
||||||
memberBoardCount := make(map[string]map[string]int)
|
memberBoardCount := make(map[string]map[string]int)
|
||||||
|
|
||||||
// main loop
|
// main loop
|
||||||
for _, brd := range render.Boards {
|
for brdIdx, brd := range render.Boards {
|
||||||
for _, lst := range brd.Data {
|
for _, lst := range brd.Data {
|
||||||
for _, crd := range lst.Cards {
|
for _, crd := range lst.Cards {
|
||||||
render.CardTotal++
|
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
|
//post-process labels
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue