From 59463944db1ed004b41d80d09918a1f93b089e6d Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Mon, 10 Feb 2020 10:08:02 +0100 Subject: [PATCH] github: use the provided api url we were always setting the public github url in the github client instead of the provided api url. --- internal/gitsources/github/github.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/gitsources/github/github.go b/internal/gitsources/github/github.go index 98e84f3..51a83b0 100644 --- a/internal/gitsources/github/github.go +++ b/internal/gitsources/github/github.go @@ -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,