Skip to content

Commit

Permalink
[bug]: Fix hostname used with gh CLI for github.com
Browse files Browse the repository at this point in the history
  • Loading branch information
nickfloyd authored Sep 26, 2023
2 parents a844de9 + da42079 commit c917477
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions github/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,13 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
token = appToken
}

isGithubDotCom, err := regexp.MatchString("^"+regexp.QuoteMeta("https://api.github.com"), baseURL)
if err != nil {
return nil, err
}

if token == "" {
ghAuthToken, err := tokenFromGhCli(baseURL)
ghAuthToken, err := tokenFromGhCli(baseURL, isGithubDotCom)
if err != nil {
return nil, fmt.Errorf("gh auth token: %w", err)
}
Expand All @@ -359,11 +364,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
log.Printf("[DEBUG] Setting read_delay_ms to %d", readDelay)

parallelRequests := d.Get("parallel_requests").(bool)
isGithubDotCom, err := regexp.MatchString("^"+regexp.QuoteMeta("https://api.github.com"), baseURL)

if err != nil {
return nil, err
}
if parallelRequests && isGithubDotCom {
return nil, fmt.Errorf("parallel_requests cannot be true when connecting to public github")
}
Expand Down Expand Up @@ -391,13 +392,13 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
}

// See https://github.com/integrations/terraform-provider-github/issues/1822
func tokenFromGhCli(baseURL string) (string, error) {
func tokenFromGhCli(baseURL string, isGithubDotCom bool) (string, error) {
ghCliPath := os.Getenv("GH_PATH")
if ghCliPath == "" {
ghCliPath = "gh"
}
hostname := ""
if baseURL == "" {
if isGithubDotCom {
hostname = "github.com"
} else {
parsedURL, err := url.Parse(baseURL)
Expand Down

0 comments on commit c917477

Please sign in to comment.