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)
|
settings := ipinfo.NewSettingsFromYAML(wtf.Config)
|
||||||
widget = ipinfo.NewWidget(app, settings)
|
widget = ipinfo.NewWidget(app, settings)
|
||||||
case "jenkins":
|
case "jenkins":
|
||||||
widget = jenkins.NewWidget(app, pages)
|
settings := jenkins.NewSettingsFromYAML(wtf.Config)
|
||||||
|
widget = jenkins.NewWidget(app, pages, settings)
|
||||||
case "jira":
|
case "jira":
|
||||||
widget = jira.NewWidget(app, pages)
|
widget = jira.NewWidget(app, pages)
|
||||||
case "logger":
|
case "logger":
|
||||||
|
@ -9,11 +9,9 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"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"
|
const apiSuffix = "api/json?pretty=true"
|
||||||
parsedSuffix, err := url.Parse(apiSuffix)
|
parsedSuffix, err := url.Parse(apiSuffix)
|
||||||
if err != nil {
|
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, _ := http.NewRequest("GET", jenkinsAPIURL.String(), nil)
|
||||||
req.SetBasicAuth(username, apiKey)
|
req.SetBasicAuth(username, apiKey)
|
||||||
|
|
||||||
verifyServerCertificate := wtf.Config.UBool("wtf.mods.jenkins.verifyServerCertificate", true)
|
|
||||||
httpClient := &http.Client{Transport: &http.Transport{
|
httpClient := &http.Client{Transport: &http.Transport{
|
||||||
TLSClientConfig: &tls.Config{
|
TLSClientConfig: &tls.Config{
|
||||||
InsecureSkipVerify: !verifyServerCertificate,
|
InsecureSkipVerify: !widget.settings.verifyServerCertificate,
|
||||||
},
|
},
|
||||||
Proxy: http.ProxyFromEnvironment,
|
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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/wtfutil/wtf/wtf"
|
"github.com/wtfutil/wtf/wtf"
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const HelpText = `
|
const HelpText = `
|
||||||
@ -27,14 +27,17 @@ type Widget struct {
|
|||||||
wtf.HelpfulWidget
|
wtf.HelpfulWidget
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
view *View
|
|
||||||
selected int
|
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{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, "Jenkins", "jenkins", true),
|
TextWidget: wtf.NewTextWidget(app, "Jenkins", "jenkins", true),
|
||||||
|
|
||||||
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.HelpfulWidget.SetView(widget.View)
|
widget.HelpfulWidget.SetView(widget.View)
|
||||||
@ -54,10 +57,10 @@ func (widget *Widget) Refresh() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
view, err := Create(
|
view, err := widget.Create(
|
||||||
wtf.Config.UString("wtf.mods.jenkins.url"),
|
widget.settings.url,
|
||||||
wtf.Config.UString("wtf.mods.jenkins.user"),
|
widget.settings.user,
|
||||||
widget.apiKey(),
|
widget.settings.apiKey,
|
||||||
)
|
)
|
||||||
widget.view = view
|
widget.view = view
|
||||||
|
|
||||||
@ -85,13 +88,6 @@ func (widget *Widget) display() {
|
|||||||
widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight()
|
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 {
|
func (widget *Widget) contentFrom(view *View) string {
|
||||||
var str string
|
var str string
|
||||||
for idx, job := range view.Jobs {
|
for idx, job := range view.Jobs {
|
||||||
@ -121,12 +117,7 @@ func (widget *Widget) jobColor(job *Job) string {
|
|||||||
switch job.Color {
|
switch job.Color {
|
||||||
case "blue":
|
case "blue":
|
||||||
// Override color if successBallColor boolean param provided in config
|
// Override color if successBallColor boolean param provided in config
|
||||||
ballColor := wtf.Config.UString("wtf.mods.jenkins.successBallColor", "blue")
|
return widget.settings.successBallColor
|
||||||
if ballColor != "blue" {
|
|
||||||
return ballColor
|
|
||||||
} else {
|
|
||||||
return "blue"
|
|
||||||
}
|
|
||||||
case "red":
|
case "red":
|
||||||
return "red"
|
return "red"
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user