mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
support enterprise Travis endpoints
This commit is contained in:
parent
00f56a5f3a
commit
9de738362a
@ -17,6 +17,9 @@ func BuildsFor(settings *Settings) (*Builds, error) {
|
||||
builds := &Builds{}
|
||||
|
||||
travisAPIURL.Host = "api." + TRAVIS_HOSTS[settings.pro]
|
||||
if settings.baseURL != "" {
|
||||
travisAPIURL.Host = settings.baseURL
|
||||
}
|
||||
|
||||
resp, err := travisBuildRequest(settings)
|
||||
if err != nil {
|
||||
@ -39,6 +42,9 @@ var (
|
||||
|
||||
func travisBuildRequest(settings *Settings) (*http.Response, error) {
|
||||
var path string = "builds"
|
||||
if settings.baseURL != "" {
|
||||
travisAPIURL.Path = "/api/"
|
||||
}
|
||||
params := url.Values{}
|
||||
params.Add("limit", settings.limit)
|
||||
params.Add("sort_by", settings.sort_by)
|
||||
@ -46,15 +52,15 @@ func travisBuildRequest(settings *Settings) (*http.Response, error) {
|
||||
requestUrl := travisAPIURL.ResolveReference(&url.URL{Path: path, RawQuery: params.Encode()})
|
||||
|
||||
req, err := http.NewRequest("GET", requestUrl.String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Add("Accept", "application/json")
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
req.Header.Add("Travis-API-Version", "3")
|
||||
|
||||
bearer := fmt.Sprintf("token %s", settings.apiKey)
|
||||
req.Header.Add("Authorization", bearer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
httpClient := &http.Client{}
|
||||
resp, err := httpClient.Do(req)
|
||||
|
@ -16,6 +16,7 @@ type Settings struct {
|
||||
common *cfg.Common
|
||||
|
||||
apiKey string
|
||||
baseURL string `help:"Your TravisCI Enterprise API URL." optional:"true"`
|
||||
compact bool
|
||||
limit string
|
||||
pro bool
|
||||
@ -27,6 +28,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
|
||||
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
|
||||
|
||||
apiKey: ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_TRAVIS_API_TOKEN"))),
|
||||
baseURL: ymlConfig.UString("baseURL", ymlConfig.UString("baseURL", os.Getenv("WTF_TRAVIS_BASE_URL"))),
|
||||
pro: ymlConfig.UBool("pro", false),
|
||||
compact: ymlConfig.UBool("compact", false),
|
||||
limit: ymlConfig.UString("limit", "10"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user