mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Widgets can inform whether or not they should get tab focus. Widgets that provide additional functionality should return true. Widgets that have no extra capability should return false. This allows the FocusTracker to only tab through and focus on widgets for which it provides value.
92 lines
1.8 KiB
Go
92 lines
1.8 KiB
Go
package newrelic
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/olebedev/config"
|
|
"github.com/senorprogrammer/wtf/wtf"
|
|
nr "github.com/yfronto/newrelic"
|
|
)
|
|
|
|
// Config is a pointer to the global config object
|
|
var Config *config.Config
|
|
|
|
type Widget struct {
|
|
wtf.TextWidget
|
|
}
|
|
|
|
func NewWidget() *Widget {
|
|
widget := Widget{
|
|
TextWidget: wtf.NewTextWidget(" New Relic ", "newrelic", false),
|
|
}
|
|
|
|
return &widget
|
|
}
|
|
|
|
/* -------------------- Exported Functions -------------------- */
|
|
|
|
func (widget *Widget) Refresh() {
|
|
if widget.Disabled() {
|
|
return
|
|
}
|
|
|
|
app, appErr := Application()
|
|
deploys, depErr := Deployments()
|
|
|
|
appName := "error"
|
|
if appErr == nil {
|
|
appName = app.Name
|
|
}
|
|
|
|
widget.View.SetTitle(fmt.Sprintf(" New Relic: [green]%s[white] ", appName))
|
|
|
|
widget.View.Clear()
|
|
|
|
if depErr != nil {
|
|
widget.View.SetWrap(true)
|
|
fmt.Fprintf(widget.View, "%s", depErr)
|
|
} else {
|
|
widget.View.SetWrap(false)
|
|
fmt.Fprintf(widget.View, "%s", widget.contentFrom(deploys))
|
|
}
|
|
|
|
widget.RefreshedAt = time.Now()
|
|
}
|
|
|
|
/* -------------------- Unexported Functions -------------------- */
|
|
|
|
func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
|
|
str := fmt.Sprintf(
|
|
" %s\n",
|
|
"[red]Latest Deploys[white]",
|
|
)
|
|
|
|
revisions := []string{}
|
|
|
|
for _, deploy := range deploys {
|
|
if (deploy.Revision != "") && wtf.Exclude(revisions, deploy.Revision) {
|
|
lineColor := "white"
|
|
if wtf.IsToday(deploy.Timestamp) {
|
|
lineColor = "lightblue"
|
|
}
|
|
|
|
str = str + fmt.Sprintf(
|
|
" [green]%s[%s] %s %-.16s[white]\n",
|
|
deploy.Revision[0:8],
|
|
lineColor,
|
|
deploy.Timestamp.Format("Jan 02, 15:04 MST"),
|
|
wtf.NameFromEmail(deploy.User),
|
|
)
|
|
|
|
revisions = append(revisions, deploy.Revision)
|
|
|
|
if len(revisions) == Config.UInt("wtf.mods.newrelic.deployCount", 5) {
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
return str
|
|
}
|