mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-400 TravisCI extracted to new config format
This commit is contained in:
parent
daa422aee4
commit
5593f19e1c
3
main.go
3
main.go
@ -298,7 +298,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
|
|||||||
settings := todoist.NewSettingsFromYAML(wtf.Config)
|
settings := todoist.NewSettingsFromYAML(wtf.Config)
|
||||||
widget = todoist.NewWidget(app, pages, settings)
|
widget = todoist.NewWidget(app, pages, settings)
|
||||||
case "travisci":
|
case "travisci":
|
||||||
widget = travisci.NewWidget(app, pages)
|
settings := travisci.NewSettingsFromYAML(wtf.Config)
|
||||||
|
widget = travisci.NewWidget(app, pages, settings)
|
||||||
case "trello":
|
case "trello":
|
||||||
widget = trello.NewWidget(app)
|
widget = trello.NewWidget(app)
|
||||||
case "twitter":
|
case "twitter":
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
type Settings struct {
|
type Settings struct {
|
||||||
Common *cfg.Common
|
Common *cfg.Common
|
||||||
|
|
||||||
APIKey string
|
apiKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||||
@ -18,7 +18,7 @@ func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
|||||||
|
|
||||||
settings := Settings{
|
settings := Settings{
|
||||||
Common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
Common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||||
APIKey: localConfig.UString("apiKey", os.Getenv("WTF_CIRCLE_API_KEY")),
|
apiKey: localConfig.UString("apiKey", os.Getenv("WTF_CIRCLE_API_KEY")),
|
||||||
}
|
}
|
||||||
|
|
||||||
return &settings
|
return &settings
|
||||||
|
@ -17,7 +17,7 @@ type Widget struct {
|
|||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, "CircleCI", "circleci", false),
|
TextWidget: wtf.NewTextWidget(app, "CircleCI", "circleci", false),
|
||||||
Client: NewClient(settings.APIKey),
|
Client: NewClient(settings.apiKey),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,6 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/wtfutil/wtf/wtf"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var TRAVIS_HOSTS = map[bool]string{
|
var TRAVIS_HOSTS = map[bool]string{
|
||||||
@ -18,13 +15,12 @@ var TRAVIS_HOSTS = map[bool]string{
|
|||||||
true: "travis-ci.com",
|
true: "travis-ci.com",
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildsFor() (*Builds, error) {
|
func BuildsFor(apiKey string, pro bool) (*Builds, error) {
|
||||||
builds := &Builds{}
|
builds := &Builds{}
|
||||||
|
|
||||||
pro := wtf.Config.UBool("wtf.mods.travisci.pro", false)
|
|
||||||
travisAPIURL.Host = "api." + TRAVIS_HOSTS[pro]
|
travisAPIURL.Host = "api." + TRAVIS_HOSTS[pro]
|
||||||
|
|
||||||
resp, err := travisRequest("builds")
|
resp, err := travisRequest(apiKey, "builds")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return builds, err
|
return builds, err
|
||||||
}
|
}
|
||||||
@ -40,7 +36,7 @@ var (
|
|||||||
travisAPIURL = &url.URL{Scheme: "https", Path: "/"}
|
travisAPIURL = &url.URL{Scheme: "https", Path: "/"}
|
||||||
)
|
)
|
||||||
|
|
||||||
func travisRequest(path string) (*http.Response, error) {
|
func travisRequest(apiKey string, path string) (*http.Response, error) {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Add("limit", "10")
|
params.Add("limit", "10")
|
||||||
|
|
||||||
@ -51,7 +47,7 @@ func travisRequest(path string) (*http.Response, error) {
|
|||||||
req.Header.Add("Content-Type", "application/json")
|
req.Header.Add("Content-Type", "application/json")
|
||||||
req.Header.Add("Travis-API-Version", "3")
|
req.Header.Add("Travis-API-Version", "3")
|
||||||
|
|
||||||
bearer := fmt.Sprintf("token %s", apiToken())
|
bearer := fmt.Sprintf("token %s", apiKey)
|
||||||
req.Header.Add("Authorization", bearer)
|
req.Header.Add("Authorization", bearer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -70,13 +66,6 @@ func travisRequest(path string) (*http.Response, error) {
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiToken() string {
|
|
||||||
return wtf.Config.UString(
|
|
||||||
"wtf.mods.travisci.apiKey",
|
|
||||||
os.Getenv("WTF_TRAVIS_API_TOKEN"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseJson(obj interface{}, text io.Reader) {
|
func parseJson(obj interface{}, text io.Reader) {
|
||||||
jsonStream, err := ioutil.ReadAll(text)
|
jsonStream, err := ioutil.ReadAll(text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
28
modules/travisci/settings.go
Normal file
28
modules/travisci/settings.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package travisci
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/olebedev/config"
|
||||||
|
"github.com/wtfutil/wtf/cfg"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Settings struct {
|
||||||
|
Common *cfg.Common
|
||||||
|
|
||||||
|
apiKey string
|
||||||
|
pro bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||||
|
localConfig, _ := ymlConfig.Get("wtf.mods.travisci")
|
||||||
|
|
||||||
|
settings := Settings{
|
||||||
|
Common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||||
|
|
||||||
|
apiKey: localConfig.UString("apiKey", os.Getenv("WTF_TRAVIS_API_TOKEN")),
|
||||||
|
pro: localConfig.UBool("pro", false),
|
||||||
|
}
|
||||||
|
|
||||||
|
return &settings
|
||||||
|
}
|
@ -28,12 +28,15 @@ type Widget struct {
|
|||||||
|
|
||||||
builds *Builds
|
builds *Builds
|
||||||
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, "TravisCI", "travisci", true),
|
TextWidget: wtf.NewTextWidget(app, "TravisCI", "travisci", true),
|
||||||
|
|
||||||
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.HelpfulWidget.SetView(widget.View)
|
widget.HelpfulWidget.SetView(widget.View)
|
||||||
@ -51,7 +54,7 @@ func (widget *Widget) Refresh() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
builds, err := BuildsFor()
|
builds, err := BuildsFor(widget.settings.apiKey, widget.settings.pro)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
widget.View.SetWrap(true)
|
widget.View.SetWrap(true)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user