Add support for enterprise repos to github plugin (#6194)
This commit is contained in:
@@ -18,10 +18,11 @@ import (
|
||||
|
||||
// GitHub - plugin main structure
|
||||
type GitHub struct {
|
||||
Repositories []string `toml:"repositories"`
|
||||
AccessToken string `toml:"access_token"`
|
||||
HTTPTimeout internal.Duration `toml:"http_timeout"`
|
||||
githubClient *github.Client
|
||||
Repositories []string `toml:"repositories"`
|
||||
AccessToken string `toml:"access_token"`
|
||||
EnterpriseBaseURL string `toml:"enterprise_base_url"`
|
||||
HTTPTimeout internal.Duration `toml:"http_timeout"`
|
||||
githubClient *github.Client
|
||||
|
||||
obfusticatedToken string
|
||||
|
||||
@@ -36,6 +37,9 @@ const sampleConfig = `
|
||||
|
||||
## Github API access token. Unauthenticated requests are limited to 60 per hour.
|
||||
# access_token = ""
|
||||
|
||||
## Github API enterprise url. Github Enterprise accounts must specify their base url.
|
||||
# enterprise_base_url = ""
|
||||
|
||||
## Timeout for HTTP requests.
|
||||
# http_timeout = "5s"
|
||||
@@ -71,9 +75,16 @@ func (g *GitHub) createGitHubClient(ctx context.Context) (*github.Client, error)
|
||||
|
||||
g.obfusticatedToken = g.AccessToken[0:4] + "..." + g.AccessToken[len(g.AccessToken)-3:]
|
||||
|
||||
return github.NewClient(oauthClient), nil
|
||||
return g.newGithubClient(oauthClient)
|
||||
}
|
||||
|
||||
return g.newGithubClient(httpClient)
|
||||
}
|
||||
|
||||
func (g *GitHub) newGithubClient(httpClient *http.Client) (*github.Client, error) {
|
||||
if g.EnterpriseBaseURL != "" {
|
||||
return github.NewEnterpriseClient(g.EnterpriseBaseURL, "", httpClient)
|
||||
}
|
||||
return github.NewClient(httpClient), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user