1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/modules/newrelic/display.go
Chris Cummer 200dbcc03c
WTF-730 Fix missing color key config error (#738)
* WTF-730 Fix missing color key config error

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-730 Add Subheading color formatting to modules

Users can now set a `subheading` color in their config to change the
color of subheadings in widget display.

Defaults to `red`.

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-730 Fix oustanding color issues

Clean up missing color config changes not addressed in earlier commits.

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Remove unused dependency

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-730 Base cleanup

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-730 Fix a few bugs related to color config changes

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-730 Fix issues with PagerDuty subheading display

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-730 Fix bug with Todo list colour rendering

Signed-off-by: Chris Cummer <chriscummer@me.com>
2019-11-09 11:21:45 -08:00

78 lines
1.6 KiB
Go

package newrelic
import (
"fmt"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/wtf"
nr "github.com/yfronto/newrelic"
)
func (widget *Widget) content() (string, string, bool) {
client := widget.currentData()
if client == nil {
return widget.CommonSettings().Title, " NewRelic data unavailable ", false
}
app, appErr := client.Application()
deploys, depErr := client.Deployments()
appName := "error"
if appErr == nil {
appName = app.Name
}
var content string
title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings().Title, appName)
wrap := false
if depErr != nil {
wrap = true
content = depErr.Error()
} else {
content = widget.contentFrom(deploys)
}
return title, content, wrap
}
func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
str := fmt.Sprintf(
" %s\n",
fmt.Sprintf(
"[%s]Latest Deploys[white]",
widget.settings.common.Colors.Subheading,
),
)
revisions := []string{}
for _, deploy := range deploys {
if (deploy.Revision != "") && utils.DoesNotInclude(revisions, deploy.Revision) {
lineColor := "white"
if wtf.IsToday(deploy.Timestamp) {
lineColor = "lightblue"
}
revLen := 8
if revLen > len(deploy.Revision) {
revLen = len(deploy.Revision)
}
str += fmt.Sprintf(
" [green]%s[%s] %s %-.16s[white]\n",
deploy.Revision[0:revLen],
lineColor,
deploy.Timestamp.Format("Jan 02 15:04 MST"),
utils.NameFromEmail(deploy.User),
)
revisions = append(revisions, deploy.Revision)
if len(revisions) == widget.settings.deployCount {
break
}
}
}
return str
}