mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-400 Rollbar extracted to new config format
This commit is contained in:
parent
d3eef146cb
commit
0403b75fe8
3
main.go
3
main.go
@ -271,7 +271,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
|
|||||||
settings := resourceusage.NewSettingsFromYAML(wtf.Config)
|
settings := resourceusage.NewSettingsFromYAML(wtf.Config)
|
||||||
widget = resourceusage.NewWidget(app, settings)
|
widget = resourceusage.NewWidget(app, settings)
|
||||||
case "rollbar":
|
case "rollbar":
|
||||||
widget = rollbar.NewWidget(app, pages)
|
settings := rollbar.NewSettingsFromYAML(wtf.Config)
|
||||||
|
widget = rollbar.NewWidget(app, pages, settings)
|
||||||
case "security":
|
case "security":
|
||||||
settings := security.NewSettingsFromYAML(wtf.Config)
|
settings := security.NewSettingsFromYAML(wtf.Config)
|
||||||
widget = security.NewWidget(app, settings)
|
widget = security.NewWidget(app, settings)
|
||||||
|
@ -12,10 +12,9 @@ import (
|
|||||||
"github.com/wtfutil/wtf/wtf"
|
"github.com/wtfutil/wtf/wtf"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CurrentActiveItems() (*ActiveItems, error) {
|
func CurrentActiveItems(accessToken string) (*ActiveItems, error) {
|
||||||
items := &ActiveItems{}
|
items := &ActiveItems{}
|
||||||
|
|
||||||
accessToken := wtf.Config.UString("wtf.mods.rollbar.accessToken", "")
|
|
||||||
rollbarAPIURL.Host = "api.rollbar.com"
|
rollbarAPIURL.Host = "api.rollbar.com"
|
||||||
rollbarAPIURL.Path = "/api/1/items"
|
rollbarAPIURL.Path = "/api/1/items"
|
||||||
resp, err := rollbarItemRequest(accessToken)
|
resp, err := rollbarItemRequest(accessToken)
|
||||||
|
34
modules/rollbar/settings.go
Normal file
34
modules/rollbar/settings.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package rollbar
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/olebedev/config"
|
||||||
|
"github.com/wtfutil/wtf/cfg"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Settings struct {
|
||||||
|
common *cfg.Common
|
||||||
|
|
||||||
|
accessToken string
|
||||||
|
activeOnly bool
|
||||||
|
assignedToName string
|
||||||
|
count int
|
||||||
|
projectName string
|
||||||
|
projectOwner string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||||
|
localConfig, _ := ymlConfig.Get("wtf.mods.rollbar")
|
||||||
|
|
||||||
|
settings := Settings{
|
||||||
|
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||||
|
|
||||||
|
accessToken: localConfig.UString("accessToken"),
|
||||||
|
activeOnly: localConfig.UBool("activeOnly"),
|
||||||
|
assignedToName: localConfig.UString("assignedToName"),
|
||||||
|
count: localConfig.UInt("count", 10),
|
||||||
|
projectName: localConfig.UString("projectName", "Items"),
|
||||||
|
projectOwner: localConfig.UString("projectOwner"),
|
||||||
|
}
|
||||||
|
|
||||||
|
return &settings
|
||||||
|
}
|
@ -29,13 +29,17 @@ type Widget struct {
|
|||||||
|
|
||||||
items *Result
|
items *Result
|
||||||
selected int
|
selected int
|
||||||
|
settings *Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, "Rollbar", "rollbar", true),
|
TextWidget: wtf.NewTextWidget(app, "Rollbar", "rollbar", true),
|
||||||
|
|
||||||
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.HelpfulWidget.SetView(widget.View)
|
widget.HelpfulWidget.SetView(widget.View)
|
||||||
widget.unselect()
|
widget.unselect()
|
||||||
|
|
||||||
@ -51,7 +55,7 @@ func (widget *Widget) Refresh() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
items, err := CurrentActiveItems()
|
items, err := CurrentActiveItems(widget.settings.accessToken)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
widget.View.SetWrap(true)
|
widget.View.SetWrap(true)
|
||||||
@ -72,16 +76,14 @@ func (widget *Widget) display() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
widget.View.SetWrap(false)
|
widget.View.SetWrap(false)
|
||||||
projectName := wtf.Config.UString("wtf.mods.rollbar.projectName", "Items")
|
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - %s", widget.Name(), widget.settings.projectName)))
|
||||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - %s", widget.Name(), projectName)))
|
|
||||||
widget.View.SetText(widget.contentFrom(widget.items))
|
widget.View.SetText(widget.contentFrom(widget.items))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(result *Result) string {
|
func (widget *Widget) contentFrom(result *Result) string {
|
||||||
var str string
|
var str string
|
||||||
count := wtf.Config.UInt("wtf.mods.rollbar.count", 10)
|
if len(result.Items) > widget.settings.count {
|
||||||
if len(result.Items) > count {
|
result.Items = result.Items[:widget.settings.count]
|
||||||
result.Items = result.Items[:count]
|
|
||||||
}
|
}
|
||||||
for idx, item := range result.Items {
|
for idx, item := range result.Items {
|
||||||
|
|
||||||
@ -151,12 +153,18 @@ func (widget *Widget) prev() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) openBuild() {
|
func (widget *Widget) openBuild() {
|
||||||
sel := widget.selected
|
if widget.selected >= 0 && widget.items != nil && widget.selected < len(widget.items.Items) {
|
||||||
projectOwner := wtf.Config.UString("wtf.mods.rollbar.projectOwner", "")
|
|
||||||
projectName := wtf.Config.UString("wtf.mods.rollbar.projectName", "")
|
|
||||||
if sel >= 0 && widget.items != nil && sel < len(widget.items.Items) {
|
|
||||||
item := &widget.items.Items[widget.selected]
|
item := &widget.items.Items[widget.selected]
|
||||||
wtf.OpenFile(fmt.Sprintf("https://rollbar.com/%s/%s/%s/%d", projectOwner, projectName, "items", item.ID))
|
|
||||||
|
wtf.OpenFile(
|
||||||
|
fmt.Sprintf(
|
||||||
|
"https://rollbar.com/%s/%s/%s/%d",
|
||||||
|
widget.settings.projectOwner,
|
||||||
|
widget.settings.projectName,
|
||||||
|
"items",
|
||||||
|
item.ID,
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user