Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
amrnt committed Jun 3, 2018
1 parent df97d6c commit 337eb60
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
9 changes: 7 additions & 2 deletions _site/content/posts/modules/github.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ All open pull requests created by you.
wtf/github/
```

## Required ENV Variables
## Github 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 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">Action:</span> Your <a href="https://developer.github.com/enterprise/2.13/v3/enterprise-admin/">Github Enterprise</a> API URL.
Expand Down
17 changes: 12 additions & 5 deletions github/github_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ func (repo *GithubRepo) StarCount() int {

/* -------------------- 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 {
tokenService := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: repo.apiKey},
Expand All @@ -74,11 +84,8 @@ func (repo *GithubRepo) oauthClient() *http.Client {
func (repo *GithubRepo) githubClient() (*ghb.Client, error) {
oauthClient := repo.oauthClient()

if len(repo.baseURL) > 0 {
if len(repo.uploadURL) == 0 {
repo.uploadURL = repo.baseURL
}
return ghb.NewEnterpriseClient(repo.baseURL, repo.baseURL, oauthClient)
if repo.isGitHubEnterprise() {
return ghb.NewEnterpriseClient(repo.baseURL, repo.uploadURL, oauthClient)
}

return ghb.NewClient(oauthClient), nil
Expand Down

0 comments on commit 337eb60

Please sign in to comment.