github.com/orangenpresse/up@v0.6.0/reporter/plain/plain.go (about) 1 // Package plain provides plain-text reporting for CI. 2 package plain 3 4 import ( 5 "fmt" 6 "time" 7 8 "github.com/dustin/go-humanize" 9 10 "github.com/apex/up/platform/event" 11 ) 12 13 // Report on events. 14 func Report(events <-chan *event.Event) { 15 r := reporter{ 16 events: events, 17 } 18 19 r.Start() 20 } 21 22 // reporter struct. 23 type reporter struct { 24 events <-chan *event.Event 25 } 26 27 // complete log with duration. 28 func (r *reporter) complete(name, value string, d time.Duration) { 29 duration := fmt.Sprintf("(%s)", d.Round(time.Millisecond)) 30 fmt.Printf(" %s %s %s\n", name+":", value, duration) 31 } 32 33 // log line. 34 func (r *reporter) log(name, value string) { 35 fmt.Printf(" %s %s\n", name+":", value) 36 } 37 38 // error line. 39 func (r *reporter) error(name, value string) { 40 fmt.Printf(" %s %s\n", name+":", value) 41 } 42 43 // Start handling events. 44 func (r *reporter) Start() { 45 for e := range r.events { 46 switch e.Name { 47 case "account.login.verify": 48 r.log("verify", "Check your email for a confirmation link") 49 case "account.login.verified": 50 r.log("verify", "complete") 51 case "hook": 52 r.log("hook", e.String("name")) 53 case "hook.complete": 54 r.complete("hook", e.String("name"), e.Duration("duration")) 55 case "platform.build.zip": 56 s := fmt.Sprintf("%s files, %s", humanize.Comma(e.Int64("files")), humanize.Bytes(uint64(e.Int("size_compressed")))) 57 r.complete("build", s, e.Duration("duration")) 58 case "platform.deploy.complete": 59 s := "complete" 60 if v := e.String("version"); v != "" { 61 s = "version " + v 62 } 63 r.complete("deploy", s, e.Duration("duration")) 64 } 65 } 66 }