Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix api base handling #16

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions github.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package rcpr

import (
"context"
"fmt"
"net/url"

"github.com/Songmu/gitconfig"
"github.com/google/go-github/v45/github"
"golang.org/x/oauth2"
)

func client(ctx context.Context, token, baseURL string) (*github.Client, error) {
func client(ctx context.Context, token, host string) (*github.Client, error) {
if token == "" {
var err error
token, err = gitconfig.GitHubToken(baseURL)
token, err = gitconfig.GitHubToken(host)
if err != nil {
return nil, err
}
Expand All @@ -21,8 +22,14 @@ func client(ctx context.Context, token, baseURL string) (*github.Client, error)
oauthClient := oauth2.NewClient(ctx, ts)
client := github.NewClient(oauthClient)

if baseURL != "" {
u, err := url.Parse(baseURL)
if host != "" {
if host == "github.com" {
host = "https://api.github.com"
} else {
// ref. https://github.com/google/go-github/issues/958
host = fmt.Sprintf("https://%s/api/v3/", host)
}
u, err := url.Parse(host)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion rcpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func Run(ctx context.Context, argv []string, outStream, errStream io.Writer) err
repo = strings.TrimSuffix(repo, ".git")
}

cli, err := client(ctx, "", fmt.Sprintf("https://%s/", u.Hostname()))
cli, err := client(ctx, "", u.Hostname())
if err != nil {
return err
}
Expand Down