mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
initial implementation to support github enterprise
This commit is contained in:
parent
7545eadaff
commit
df97d6c2d3
@ -26,7 +26,13 @@ wtf/github/
|
|||||||
## Required ENV Variables
|
## 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.
|
<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">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">Key:</span> `WTF_GITHUB_UPLOAD_URL` <br />
|
||||||
|
<span class="caption">Action:</span> Your <a href="https://developer.github.com/enterprise/2.13/v3/enterprise-admin/">Github Enterprise</a> upload URL (often the same as API URL).
|
||||||
|
|
||||||
## Keyboard Commands
|
## Keyboard Commands
|
||||||
|
|
||||||
|
@ -10,7 +10,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type GithubRepo struct {
|
type GithubRepo struct {
|
||||||
apiKey string
|
apiKey string
|
||||||
|
baseURL string
|
||||||
|
uploadURL string
|
||||||
|
|
||||||
Name string
|
Name string
|
||||||
Owner string
|
Owner string
|
||||||
@ -20,9 +22,12 @@ type GithubRepo struct {
|
|||||||
|
|
||||||
func NewGithubRepo(name, owner string) *GithubRepo {
|
func NewGithubRepo(name, owner string) *GithubRepo {
|
||||||
repo := GithubRepo{
|
repo := GithubRepo{
|
||||||
apiKey: os.Getenv("WTF_GITHUB_TOKEN"),
|
apiKey: os.Getenv("WTF_GITHUB_TOKEN"),
|
||||||
Name: name,
|
baseURL: os.Getenv("WTF_GITHUB_BASE_URL"),
|
||||||
Owner: owner,
|
uploadURL: os.Getenv("WTF_GITHUB_UPLOAD_URL"),
|
||||||
|
|
||||||
|
Name: name,
|
||||||
|
Owner: owner,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &repo
|
return &repo
|
||||||
@ -66,6 +71,19 @@ func (repo *GithubRepo) oauthClient() *http.Client {
|
|||||||
return oauth2.NewClient(context.Background(), tokenService)
|
return oauth2.NewClient(context.Background(), tokenService)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ghb.NewClient(oauthClient), nil
|
||||||
|
}
|
||||||
|
|
||||||
// myPullRequests returns a list of pull requests created by username on this repo
|
// myPullRequests returns a list of pull requests created by username on this repo
|
||||||
func (repo *GithubRepo) myPullRequests(username string) []*ghb.PullRequest {
|
func (repo *GithubRepo) myPullRequests(username string) []*ghb.PullRequest {
|
||||||
prs := []*ghb.PullRequest{}
|
prs := []*ghb.PullRequest{}
|
||||||
@ -98,8 +116,11 @@ func (repo *GithubRepo) myReviewRequests(username string) []*ghb.PullRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repo *GithubRepo) loadPullRequests() ([]*ghb.PullRequest, error) {
|
func (repo *GithubRepo) loadPullRequests() ([]*ghb.PullRequest, error) {
|
||||||
oauthClient := repo.oauthClient()
|
github, err := repo.githubClient()
|
||||||
github := ghb.NewClient(oauthClient)
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
opts := &ghb.PullRequestListOptions{}
|
opts := &ghb.PullRequestListOptions{}
|
||||||
|
|
||||||
@ -113,8 +134,11 @@ func (repo *GithubRepo) loadPullRequests() ([]*ghb.PullRequest, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repo *GithubRepo) loadRemoteRepository() (*ghb.Repository, error) {
|
func (repo *GithubRepo) loadRemoteRepository() (*ghb.Repository, error) {
|
||||||
oauthClient := repo.oauthClient()
|
github, err := repo.githubClient()
|
||||||
github := ghb.NewClient(oauthClient)
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
repository, _, err := github.Repositories.Get(context.Background(), repo.Owner, repo.Name)
|
repository, _, err := github.Repositories.Get(context.Background(), repo.Owner, repo.Name)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user