Skip to content

Commit

Permalink
Support other GitHub host urls (e.g. GHES)
Browse files Browse the repository at this point in the history
Signed-off-by: GitHub <[email protected]>
  • Loading branch information
rajbos authored Mar 24, 2023
1 parent cb12afe commit 6f0c285
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
11 changes: 8 additions & 3 deletions clients/githubrepo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"net/http"
"os"
"strings"
"time"

"github.com/google/go-github/v38/github"
Expand Down Expand Up @@ -127,7 +128,7 @@ func (client *Client) InitRepo(inputRepo clients.Repo, commitSHA string, commitD

// URI implements RepoClient.URI.
func (client *Client) URI() string {
return fmt.Sprintf("%s/%s/%s", r.host, r.owner, r.repo)
return fmt.Sprintf("%s/%s/%s", client.repourl.host, client.repourl.owner, client.repourl.repo)
}

// LocalPath implements RepoClient.LocalPath.
Expand Down Expand Up @@ -267,9 +268,13 @@ func CreateGithubRepoClientWithTransport(ctx context.Context, rt http.RoundTripp
if githubAPIURL := os.Getenv("GITHUB_API_URL"); githubAPIURL != "https://api.github.com" {
// create a new enterprise client with custom URLs
ghithubSERVERURL := os.Getenv("GITHUB_SERVER_URL")
if ghithubSERVERURL == "" {
// load the server url from the api url
ghithubSERVERURL = strings.TrimSuffix(githubAPIURL, "/api/v3")
}
githubGRAPHQLURL := fmt.Sprintf("%s/api/graphql", ghithubSERVERURL)
client, _ = github.NewEnterpriseClient(githubAPIURL, githubAPIURL, httpClient)

client, _ = github.NewEnterpriseClient(githubAPIURL, githubAPIURL, httpClient)
graphClient = githubv4.NewEnterpriseClient(githubGRAPHQLURL, httpClient)
} else {
// use the defaul url values from the github client
Expand Down
6 changes: 0 additions & 6 deletions clients/githubrepo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ func (r *repoURL) String() string {

// IsValid implements Repo.IsValid.
func (r *repoURL) IsValid() error {
switch r.host {
case "github.com":
default:
return sce.WithMessage(sce.ErrorUnsupportedHost, r.host)
}

if strings.TrimSpace(r.owner) == "" || strings.TrimSpace(r.repo) == "" {
return sce.WithMessage(sce.ErrorInvalidURL,
fmt.Sprintf("%v. Expected the full repository url", r.URI()))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
gocloud.dev v0.29.0
golang.org/x/text v0.7.0
golang.org/x/tools v0.6.0
google.golang.org/genproto v0.0.0-20230209215440-0dfe4f8abfcc
google.golang.org/genproto v0.0.0-20230209215440-0dfe4f8abfcc // indirect
google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
Expand Down

0 comments on commit 6f0c285

Please sign in to comment.