mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-400 Jenkins extracted to new config format
This commit is contained in:
parent
d4558f533a
commit
9b41e6e732
3
main.go
3
main.go
@ -238,7 +238,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
|
||||
settings := ipinfo.NewSettingsFromYAML(wtf.Config)
|
||||
widget = ipinfo.NewWidget(app, settings)
|
||||
case "jenkins":
|
||||
widget = jenkins.NewWidget(app, pages)
|
||||
settings := jenkins.NewSettingsFromYAML(wtf.Config)
|
||||
widget = jenkins.NewWidget(app, pages, settings)
|
||||
case "jira":
|
||||
widget = jira.NewWidget(app, pages)
|
||||
case "logger":
|
||||
|
@ -9,11 +9,9 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
)
|
||||
|
||||
func Create(jenkinsURL string, username string, apiKey string) (*View, error) {
|
||||
func (widget *Widget) Create(jenkinsURL string, username string, apiKey string) (*View, error) {
|
||||
const apiSuffix = "api/json?pretty=true"
|
||||
parsedSuffix, err := url.Parse(apiSuffix)
|
||||
if err != nil {
|
||||
@ -29,10 +27,9 @@ func Create(jenkinsURL string, username string, apiKey string) (*View, error) {
|
||||
req, _ := http.NewRequest("GET", jenkinsAPIURL.String(), nil)
|
||||
req.SetBasicAuth(username, apiKey)
|
||||
|
||||
verifyServerCertificate := wtf.Config.UBool("wtf.mods.jenkins.verifyServerCertificate", true)
|
||||
httpClient := &http.Client{Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: !verifyServerCertificate,
|
||||
InsecureSkipVerify: !widget.settings.verifyServerCertificate,
|
||||
},
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
},
|
||||
|
34
modules/jenkins/settings.go
Normal file
34
modules/jenkins/settings.go
Normal file
@ -0,0 +1,34 @@
|
||||
package jenkins
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/olebedev/config"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
type Settings struct {
|
||||
common *cfg.Common
|
||||
|
||||
apiKey string
|
||||
successBallColor string
|
||||
url string
|
||||
user string
|
||||
verifyServerCertificate bool
|
||||
}
|
||||
|
||||
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||
localConfig, _ := ymlConfig.Get("wtf.mods.jenkins")
|
||||
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||
|
||||
apiKey: localConfig.UString("apiKey", os.Getenv("WTF_JENKINS_API_KEY")),
|
||||
successBallColor: localConfig.UString("successBallColor", "blue"),
|
||||
url: localConfig.UString("url"),
|
||||
user: localConfig.UString("user"),
|
||||
verifyServerCertificate: localConfig.UBool("verifyServerCertificate", true),
|
||||
}
|
||||
|
||||
return &settings
|
||||
}
|
@ -2,11 +2,11 @@ package jenkins
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const HelpText = `
|
||||
@ -27,14 +27,17 @@ type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.TextWidget
|
||||
|
||||
view *View
|
||||
selected int
|
||||
settings *Settings
|
||||
view *View
|
||||
}
|
||||
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
TextWidget: wtf.NewTextWidget(app, "Jenkins", "jenkins", true),
|
||||
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
@ -54,10 +57,10 @@ func (widget *Widget) Refresh() {
|
||||
return
|
||||
}
|
||||
|
||||
view, err := Create(
|
||||
wtf.Config.UString("wtf.mods.jenkins.url"),
|
||||
wtf.Config.UString("wtf.mods.jenkins.user"),
|
||||
widget.apiKey(),
|
||||
view, err := widget.Create(
|
||||
widget.settings.url,
|
||||
widget.settings.user,
|
||||
widget.settings.apiKey,
|
||||
)
|
||||
widget.view = view
|
||||
|
||||
@ -85,13 +88,6 @@ func (widget *Widget) display() {
|
||||
widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight()
|
||||
}
|
||||
|
||||
func (widget *Widget) apiKey() string {
|
||||
return wtf.Config.UString(
|
||||
"wtf.mods.jenkins.apiKey",
|
||||
os.Getenv("WTF_JENKINS_API_KEY"),
|
||||
)
|
||||
}
|
||||
|
||||
func (widget *Widget) contentFrom(view *View) string {
|
||||
var str string
|
||||
for idx, job := range view.Jobs {
|
||||
@ -121,12 +117,7 @@ func (widget *Widget) jobColor(job *Job) string {
|
||||
switch job.Color {
|
||||
case "blue":
|
||||
// Override color if successBallColor boolean param provided in config
|
||||
ballColor := wtf.Config.UString("wtf.mods.jenkins.successBallColor", "blue")
|
||||
if ballColor != "blue" {
|
||||
return ballColor
|
||||
} else {
|
||||
return "blue"
|
||||
}
|
||||
return widget.settings.successBallColor
|
||||
case "red":
|
||||
return "red"
|
||||
default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user