Merge pull request #206 from sgotti/github_use_provided_api_url

github: use the provided api url
This commit is contained in:
Simone Gotti 2020-02-11 15:59:02 +01:00 committed by GitHub
commit 996e2a54ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -122,16 +122,31 @@ func New(opts Opts) (*Client, error) {
} }
httpClient := &http.Client{Transport: &TokenTransport{token: opts.Token, rt: transport}} httpClient := &http.Client{Transport: &TokenTransport{token: opts.Token, rt: transport}}
isPublicGithub := false
// TODO(sgotti) improve detection of public github url (handle also trailing slash)
if opts.APIURL == GitHubAPIURL { if opts.APIURL == GitHubAPIURL {
isPublicGithub = true
}
if isPublicGithub {
opts.WebURL = GitHubWebURL opts.WebURL = GitHubWebURL
if !strings.HasSuffix(opts.APIURL, "/") {
opts.APIURL += "/"
}
} else { } else {
if opts.WebURL == "" { if opts.WebURL == "" {
opts.WebURL = opts.APIURL opts.WebURL = opts.APIURL
} }
if !strings.HasSuffix(opts.APIURL, "/") {
opts.APIURL += "/"
}
if !strings.HasSuffix(opts.APIURL, "/api/v3/") {
opts.APIURL += "api/v3/"
}
} }
client := github.NewClient(httpClient) client := github.NewClient(httpClient)
client.BaseURL, _ = url.Parse(GitHubAPIURL + "/") client.BaseURL, _ = url.Parse(opts.APIURL)
return &Client{ return &Client{
client: client, client: client,