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

Adapt for Enterprise version - respect GITHUB ENV variables #52

Merged
merged 1 commit into from
Oct 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,23 @@ func newCommentLoopChannel(ctx context.Context, apprv *approvalEnvironment, clie
return channel
}

func newGithubClient(ctx context.Context) *github.Client {
func newGithubClient(ctx context.Context) (*github.Client, error) {
token := os.Getenv(envVarToken)
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
tc := oauth2.NewClient(ctx, ts)
return github.NewClient(tc)

serverUrl, serverUrlPresent := os.LookupEnv("GITHUB_SERVER_URL")
apiUrl, apiUrlPresent := os.LookupEnv("GITHUB_API_URL")

if serverUrlPresent {
if ! apiUrlPresent {
apiUrl = serverUrl
}
return github.NewEnterpriseClient(apiUrl, serverUrl, tc)
}
return github.NewClient(tc), nil
}

func validateInput() error {
Expand Down Expand Up @@ -148,7 +158,11 @@ func main() {
repoOwner := os.Getenv(envVarRepoOwner)

ctx := context.Background()
client := newGithubClient(ctx)
client, err := newGithubClient(ctx)
if err != nil {
fmt.Printf("error connecting to server: %v\n", err)
os.Exit(1)
}

approvers, err := retrieveApprovers(client, repoOwner)
if err != nil {
Expand Down