mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Add more configuration options to travisci module
This commit is contained in:
parent
c3a54de181
commit
5545e4f220
@ -15,12 +15,12 @@ var TRAVIS_HOSTS = map[bool]string{
|
|||||||
true: "travis-ci.com",
|
true: "travis-ci.com",
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildsFor(apiKey string, pro bool) (*Builds, error) {
|
func BuildsFor(settings *Settings) (*Builds, error) {
|
||||||
builds := &Builds{}
|
builds := &Builds{}
|
||||||
|
|
||||||
travisAPIURL.Host = "api." + TRAVIS_HOSTS[pro]
|
travisAPIURL.Host = "api." + TRAVIS_HOSTS[settings.pro]
|
||||||
|
|
||||||
resp, err := travisRequest(apiKey, "builds")
|
resp, err := travisBuildRequest(settings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return builds, err
|
return builds, err
|
||||||
}
|
}
|
||||||
@ -36,9 +36,11 @@ var (
|
|||||||
travisAPIURL = &url.URL{Scheme: "https", Path: "/"}
|
travisAPIURL = &url.URL{Scheme: "https", Path: "/"}
|
||||||
)
|
)
|
||||||
|
|
||||||
func travisRequest(apiKey string, path string) (*http.Response, error) {
|
func travisBuildRequest(settings *Settings) (*http.Response, error) {
|
||||||
|
var path string = "builds"
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Add("limit", "10")
|
params.Add("limit", settings.limit)
|
||||||
|
params.Add("sort_by", settings.sort_by)
|
||||||
|
|
||||||
requestUrl := travisAPIURL.ResolveReference(&url.URL{Path: path, RawQuery: params.Encode()})
|
requestUrl := travisAPIURL.ResolveReference(&url.URL{Path: path, RawQuery: params.Encode()})
|
||||||
|
|
||||||
@ -47,7 +49,7 @@ func travisRequest(apiKey string, 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", apiKey)
|
bearer := fmt.Sprintf("token %s", settings.apiKey)
|
||||||
req.Header.Add("Authorization", bearer)
|
req.Header.Add("Authorization", bearer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -12,8 +12,11 @@ const defaultTitle = "TravisCI"
|
|||||||
type Settings struct {
|
type Settings struct {
|
||||||
common *cfg.Common
|
common *cfg.Common
|
||||||
|
|
||||||
apiKey string
|
apiKey string
|
||||||
pro bool
|
compact bool
|
||||||
|
limit string
|
||||||
|
pro bool
|
||||||
|
sort_by string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
|
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
|
||||||
@ -21,8 +24,11 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
|
|||||||
settings := Settings{
|
settings := Settings{
|
||||||
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig),
|
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig),
|
||||||
|
|
||||||
apiKey: ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_TRAVIS_API_TOKEN"))),
|
apiKey: ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_TRAVIS_API_TOKEN"))),
|
||||||
pro: ymlConfig.UBool("pro", false),
|
pro: ymlConfig.UBool("pro", false),
|
||||||
|
compact: ymlConfig.UBool("compact", false),
|
||||||
|
limit: ymlConfig.UString("limit", "10"),
|
||||||
|
sort_by: ymlConfig.UString("sort_by", "id:desc"),
|
||||||
}
|
}
|
||||||
|
|
||||||
return &settings
|
return &settings
|
||||||
|
@ -42,7 +42,7 @@ func (widget *Widget) Refresh() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
builds, err := BuildsFor(widget.settings.apiKey, widget.settings.pro)
|
builds, err := BuildsFor(widget.settings)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
widget.err = err
|
widget.err = err
|
||||||
@ -68,10 +68,14 @@ func (widget *Widget) content() (string, string, bool) {
|
|||||||
if widget.err != nil {
|
if widget.err != nil {
|
||||||
str = widget.err.Error()
|
str = widget.err.Error()
|
||||||
} else {
|
} else {
|
||||||
|
var rowFormat = "[%s] [%s] %s-%s (%s) [%s]%s - [blue]%s"
|
||||||
|
if widget.settings.compact != true {
|
||||||
|
rowFormat += "\n"
|
||||||
|
}
|
||||||
for idx, build := range widget.builds.Builds {
|
for idx, build := range widget.builds.Builds {
|
||||||
|
|
||||||
row := fmt.Sprintf(
|
row := fmt.Sprintf(
|
||||||
"[%s] [%s] %s-%s (%s) [%s]%s - [blue]%s\n",
|
rowFormat,
|
||||||
widget.RowColor(idx),
|
widget.RowColor(idx),
|
||||||
buildColor(&build),
|
buildColor(&build),
|
||||||
build.Repository.Name,
|
build.Repository.Name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user