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
1 changed files with 16 additions and 1 deletions

View File

@ -122,16 +122,31 @@ func New(opts Opts) (*Client, error) {
}
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 {
isPublicGithub = true
}
if isPublicGithub {
opts.WebURL = GitHubWebURL
if !strings.HasSuffix(opts.APIURL, "/") {
opts.APIURL += "/"
}
} else {
if opts.WebURL == "" {
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.BaseURL, _ = url.Parse(GitHubAPIURL + "/")
client.BaseURL, _ = url.Parse(opts.APIURL)
return &Client{
client: client,