Skip to content

Commit

Permalink
pass right base url for ghinstallation (#1584)
Browse files Browse the repository at this point in the history
  • Loading branch information
motatoes authored Jun 20, 2024
1 parent ba2565b commit db110f1
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ee/backend/providers/github/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ func (gh DiggerGithubEEClientProvider) NewClient(netClient *net.Client) (*github
// checking for enterprise state
githubHostname := os.Getenv("DIGGER_GITHUB_HOSTNAME")
if githubHostname != "" {
githubEnterpriseBaseUrl := fmt.Sprintf("https://%v/api/v3/", githubHostname)
githubEnterpriseUploadUrl := fmt.Sprintf("https://%v/api/uploads/", githubHostname)
githubEnterpriseBaseUrl, githubEnterpriseUploadUrl := getGithubEnterpriseUrls(githubHostname)
log.Printf("Info: Using digger enterprise instance: base url: %v", githubEnterpriseBaseUrl)
ghClient, err = ghClient.WithEnterpriseURLs(githubEnterpriseBaseUrl, githubEnterpriseUploadUrl)
if err != nil {
Expand All @@ -31,6 +30,12 @@ func (gh DiggerGithubEEClientProvider) NewClient(netClient *net.Client) (*github
return ghClient, nil
}

func getGithubEnterpriseUrls(githubHostname string) (string, string) {
githubEnterpriseBaseUrl := fmt.Sprintf("https://%v/api/v3/", githubHostname)
githubEnterpriseUploadUrl := fmt.Sprintf("https://%v/api/uploads/", githubHostname)
return githubEnterpriseBaseUrl, githubEnterpriseUploadUrl
}

func (gh DiggerGithubEEClientProvider) Get(githubAppId int64, installationId int64) (*github.Client, *string, error) {
githubAppPrivateKey := ""
githubAppPrivateKeyB64 := os.Getenv("GITHUB_APP_PRIVATE_KEY_BASE64")
Expand Down Expand Up @@ -65,9 +70,9 @@ func (gh DiggerGithubEEClientProvider) Get(githubAppId int64, installationId int
return nil, nil, fmt.Errorf("could not get digger client: %v", err)
}
// checking for enterprise state
useGithubEnterprise := os.Getenv("DIGGER_USE_GITHUB_ENTERPRISE")
if useGithubEnterprise != "" {
githubEnterpriseBaseUrl := os.Getenv("DIGGER_GITHUB_ENTERPRISE_BASE_URL")
githubHostname := os.Getenv("DIGGER_GITHUB_HOSTNAME")
if githubHostname != "" {
githubEnterpriseBaseUrl, _ := getGithubEnterpriseUrls(githubHostname)
itr.BaseURL = githubEnterpriseBaseUrl
}
token, err := itr.Token(context.Background())
Expand Down

0 comments on commit db110f1

Please sign in to comment.