1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
This commit is contained in:
Amr Tamimi 2018-06-03 18:28:19 +02:00
parent df97d6c2d3
commit 337eb607fc
2 changed files with 19 additions and 7 deletions

View File

@ -23,10 +23,15 @@ All open pull requests created by you.
wtf/github/ wtf/github/
``` ```
## Required ENV Variables ## Github Required ENV Variables
<span class="caption">Key:</span> `WTF_GITHUB_TOKEN` <br /> <span class="caption">Key:</span> `WTF_GITHUB_TOKEN` <br />
<span class="caption">Action:</span> Your <a href="https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization">Github API</a> token or <a href="https://developer.github.com/enterprise/2.13/v3/enterprise-admin/">Github Enterprise</a> API token. <span class="caption">Action:</span> Your <a href="https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization">Github API</a> token.
## GitHub Enterprise Required ENV Variables
<span class="caption">Key:</span> `WTF_GITHUB_TOKEN` <br />
<span class="caption">Action:</span> Your <a href="https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization">Github API</a> token.
<span class="caption">Key:</span> `WTF_GITHUB_BASE_URL` <br /> <span class="caption">Key:</span> `WTF_GITHUB_BASE_URL` <br />
<span class="caption">Action:</span> Your <a href="https://developer.github.com/enterprise/2.13/v3/enterprise-admin/">Github Enterprise</a> API URL. <span class="caption">Action:</span> Your <a href="https://developer.github.com/enterprise/2.13/v3/enterprise-admin/">Github Enterprise</a> API URL.

View File

@ -63,6 +63,16 @@ func (repo *GithubRepo) StarCount() int {
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
func (repo *GithubRepo) isGitHubEnterprise() bool {
if len(repo.baseURL) > 0 {
if len(repo.uploadURL) == 0 {
repo.uploadURL = repo.baseURL
}
return true
}
return false
}
func (repo *GithubRepo) oauthClient() *http.Client { func (repo *GithubRepo) oauthClient() *http.Client {
tokenService := oauth2.StaticTokenSource( tokenService := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: repo.apiKey}, &oauth2.Token{AccessToken: repo.apiKey},
@ -74,11 +84,8 @@ func (repo *GithubRepo) oauthClient() *http.Client {
func (repo *GithubRepo) githubClient() (*ghb.Client, error) { func (repo *GithubRepo) githubClient() (*ghb.Client, error) {
oauthClient := repo.oauthClient() oauthClient := repo.oauthClient()
if len(repo.baseURL) > 0 { if repo.isGitHubEnterprise() {
if len(repo.uploadURL) == 0 { return ghb.NewEnterpriseClient(repo.baseURL, repo.uploadURL, oauthClient)
repo.uploadURL = repo.baseURL
}
return ghb.NewEnterpriseClient(repo.baseURL, repo.baseURL, oauthClient)
} }
return ghb.NewClient(oauthClient), nil return ghb.NewClient(oauthClient), nil