Take closed/starred in account
This commit is contained in:
parent
e596d1650d
commit
d70ae58291
5 changed files with 97 additions and 33 deletions
|
@ -11,32 +11,40 @@ func main() {
|
|||
|
||||
// Get task list as markdown
|
||||
trelloCtx := NewTrello(config.TrelloToken)
|
||||
trelloBoard := trelloCtx.GetBoard(config.TrelloUrl)
|
||||
trelloMarkdown := trelloBoard.ExportToMarkdown()
|
||||
trelloHtml := trelloBoard.ExportToHtml()
|
||||
config.EmailSubject = fmt.Sprintf("Daily mail for %s", trelloBoard.Name)
|
||||
for _, trelloBoard := range trelloCtx.GetBoards() {
|
||||
if !trelloBoard.Starred || trelloBoard.Closed {
|
||||
continue
|
||||
}
|
||||
fmt.Printf("Loading board %s\n", trelloBoard.Name)
|
||||
|
||||
// Create email enveloppe
|
||||
email := NewEmail()
|
||||
email.SetHeaders(EmailConfig{
|
||||
From: config.EmailFrom,
|
||||
To: config.EmailTo,
|
||||
Subject: config.EmailSubject,
|
||||
})
|
||||
email.SetBody(trelloHtml, trelloMarkdown)
|
||||
// trelloBoard := trelloCtx.GetBoard(config.TrelloUrl)
|
||||
trelloMarkdown := trelloBoard.ExportToMarkdown()
|
||||
trelloHtml := trelloBoard.ExportToHtml()
|
||||
config.EmailSubject = fmt.Sprintf("Daily mail for %s", trelloBoard.Name)
|
||||
|
||||
// Connect and send email
|
||||
transport := NewTransport(SmtpConfig{
|
||||
Hostname: config.SmtpHostname,
|
||||
Port: config.SmtpPort,
|
||||
Username: config.SmtpUsername,
|
||||
Password: config.SmtpPassword,
|
||||
AuthType: config.SmtpAuthType,
|
||||
SecurityType: config.SmtpSecurityType,
|
||||
})
|
||||
// Create email enveloppe
|
||||
email := NewEmail()
|
||||
email.SetHeaders(EmailConfig{
|
||||
From: config.EmailFrom,
|
||||
To: config.EmailTo,
|
||||
Subject: config.EmailSubject,
|
||||
})
|
||||
email.SetBody(trelloHtml, trelloMarkdown)
|
||||
|
||||
transport.Dial()
|
||||
transport.Authenticate()
|
||||
transport.Send(email)
|
||||
transport.Quit()
|
||||
// Connect and send email
|
||||
transport := NewTransport(SmtpConfig{
|
||||
Hostname: config.SmtpHostname,
|
||||
Port: config.SmtpPort,
|
||||
Username: config.SmtpUsername,
|
||||
Password: config.SmtpPassword,
|
||||
AuthType: config.SmtpAuthType,
|
||||
SecurityType: config.SmtpSecurityType,
|
||||
})
|
||||
|
||||
transport.Dial()
|
||||
transport.Authenticate()
|
||||
transport.Send(email)
|
||||
transport.Quit()
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,8 @@ package main
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/adlio/trello"
|
||||
// "github.com/adlio/trello"
|
||||
trello "github.com/glenux/contrib-trello"
|
||||
"github.com/russross/blackfriday/v2"
|
||||
"log"
|
||||
"net/url"
|
||||
|
@ -28,9 +29,11 @@ type TrelloCtx struct {
|
|||
}
|
||||
|
||||
type TrelloBoard struct {
|
||||
Ctx *TrelloCtx
|
||||
Ptr *trello.Board
|
||||
Name string
|
||||
Ctx *TrelloCtx
|
||||
Ptr *trello.Board
|
||||
Starred bool
|
||||
Closed bool
|
||||
Name string
|
||||
}
|
||||
|
||||
func runcmd(command string) string {
|
||||
|
@ -73,6 +76,35 @@ func NewTrello(token string) *TrelloCtx {
|
|||
return &ctx
|
||||
}
|
||||
|
||||
func (ctx *TrelloCtx) GetBoards() []TrelloBoard {
|
||||
var result []TrelloBoard
|
||||
|
||||
token, err := ctx.Client.GetToken(ctx.Token, trello.Defaults())
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
member, err := ctx.Client.GetMember(token.IDMember, trello.Defaults())
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
boards, err := member.GetBoards(trello.Defaults())
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
for _, board := range boards {
|
||||
result = append(result, TrelloBoard{
|
||||
Ctx: ctx,
|
||||
Starred: board.Starred,
|
||||
Closed: board.Closed,
|
||||
Ptr: board,
|
||||
Name: board.Name,
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (ctx *TrelloCtx) GetBoard(boardUrl string) TrelloBoard {
|
||||
parsedUrl, err := url.Parse(boardUrl)
|
||||
if err != nil {
|
||||
|
@ -84,7 +116,13 @@ func (ctx *TrelloCtx) GetBoard(boardUrl string) TrelloBoard {
|
|||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
return TrelloBoard{Ctx: ctx, Ptr: board, Name: board.Name}
|
||||
return TrelloBoard{
|
||||
Ctx: ctx,
|
||||
Starred: board.Starred,
|
||||
Closed: board.Closed,
|
||||
Ptr: board,
|
||||
Name: board.Name,
|
||||
}
|
||||
}
|
||||
|
||||
type CardData struct {
|
||||
|
|
6
go.mod
6
go.mod
|
@ -1,11 +1,15 @@
|
|||
module github.com/glenux/trello2mail
|
||||
|
||||
require (
|
||||
github.com/adlio/trello v0.0.0-20180621142300-8a458717123e
|
||||
github.com/BurntSushi/toml v0.3.1 // indirect
|
||||
github.com/glenux/contrib-trello v0.0.0-20181123120736-c8291e6a707a
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
github.com/pkg/errors v0.8.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.0.1
|
||||
github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95 // indirect
|
||||
github.com/spf13/cobra v0.0.3
|
||||
github.com/spf13/pflag v1.0.3 // indirect
|
||||
github.com/spf13/viper v1.2.1
|
||||
github.com/stretchr/testify v1.2.2 // indirect
|
||||
)
|
||||
|
|
16
go.sum
16
go.sum
|
@ -1,10 +1,17 @@
|
|||
github.com/adlio/trello v0.0.0-20180621142300-8a458717123e h1:i5+hZJx4iTPT4+ojV5zi50UIPUxs7CH8r+P3BFB4Ofs=
|
||||
github.com/adlio/trello v0.0.0-20180621142300-8a458717123e/go.mod h1:VjzhFGdnEJGih1AsIWi/yU6y01yZh0DuEWCNAyOJ1WE=
|
||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/glenux/contrib-trello v0.0.0-20181009211147-e4cc07c871d0 h1:u6tAr2/SSBHq+n/0OwkV3PPAph0I2CraybhQd7GdAZ4=
|
||||
github.com/glenux/contrib-trello v0.0.0-20181009211147-e4cc07c871d0/go.mod h1:A69TOILEJYbyfZyLw5gfn5E8hQPzXuBG2Oh36nutIFA=
|
||||
github.com/glenux/contrib-trello v0.0.0-20181123120736-c8291e6a707a h1:Oie4PAFrDkFI+B19wC7jzI87QiFrX/O6EBNiIsp4n0E=
|
||||
github.com/glenux/contrib-trello v0.0.0-20181123120736-c8291e6a707a/go.mod h1:A69TOILEJYbyfZyLw5gfn5E8hQPzXuBG2Oh36nutIFA=
|
||||
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
|
||||
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/mitchellh/mapstructure v1.0.0 h1:vVpGvMXJPqSDh2VYHF7gsfQj8Ncx+Xw5Y1KHeTRY+7I=
|
||||
|
@ -13,6 +20,8 @@ github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181
|
|||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95 h1:/vdW8Cb7EXrkqWGufVMES1OH2sU9gKVb2n9/1y5NMBY=
|
||||
|
@ -30,10 +39,13 @@ github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
|
|||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/spf13/viper v1.2.1 h1:bIcUwXqLseLF3BDAZduuNfekWG87ibtFxi59Bq+oI9M=
|
||||
github.com/spf13/viper v1.2.1/go.mod h1:P4AexN0a+C9tGAnUFNwDMYYZv3pjFuvmeiMyKRaNVlI=
|
||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
golang.org/x/sys v0.0.0-20180906133057-8cf3aee42992 h1:BH3eQWeGbwRU2+wxxuuPOdFBmaiBH81O8BugSjHeTFg=
|
||||
golang.org/x/sys v0.0.0-20180906133057-8cf3aee42992/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# Board {{ .Name }}
|
||||
|
||||
URL: {{ .Url }}
|
||||
|
||||
{{ range .Lists }}{{ if .Cards }}
|
||||
## {{ .Name }}
|
||||
|
||||
|
|
Loading…
Reference in a new issue