File tree Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -192,6 +192,11 @@ $ brew install git-xargs
192192 export GITHUB_OAUTH_TOKEN=< your-secret-github-oauth-token>
193193 ` ` `
194194
195+ 1. ** Setup authentication with your Github Enterprise server** . To use a Github Enterprise server, set the GITHUB_HOSTNAME environment variable:
196+ ` ` ` bash
197+ export GITHUB_HOSTNAME=< your-ghe-hostname.your-domain.com>
198+ ` ` `
199+
1952001. ** Provide a script or command and target some repos** . Here' s a simple example of running the `touch` command in
196201 every repo in your GitHub organization. Follow the same pattern to start running your own scripts and commands
197202 against your own repos!
@@ -204,6 +209,7 @@ $ brew install git-xargs
204209 touch git-xargs-is-awesome.txt
205210 ```
206211
212+
207213# Reference
208214
209215## How to supply commands or scripts to run
Original file line number Diff line number Diff line change @@ -2,12 +2,12 @@ package auth
22
33import (
44 "context"
5+ "fmt"
56 "os"
67
78 "github.com/google/go-github/v43/github"
89 "github.com/gruntwork-io/git-xargs/types"
910 "github.com/gruntwork-io/go-commons/errors"
10-
1111 "golang.org/x/oauth2"
1212)
1313
@@ -52,8 +52,20 @@ func ConfigureGithubClient() GithubClient {
5252
5353 tc := oauth2 .NewClient (context .Background (), ts )
5454
55+ var githubClient * github.Client
56+
57+ if os .Getenv ("GITHUB_HOSTNAME" ) != "" {
58+ GithubHostname := os .Getenv ("GITHUB_HOSTNAME" )
59+ baseUrl := fmt .Sprintf ("https://%s/" , GithubHostname )
60+
61+ githubClient , _ = github .NewEnterpriseClient (baseUrl , baseUrl , tc )
62+
63+ } else {
64+ githubClient = github .NewClient (tc )
65+ }
66+
5567 // Wrap the go-github client in a GithubClient struct, which is common between production and test code
56- client := NewClient (github . NewClient ( tc ) )
68+ client := NewClient (githubClient )
5769
5870 return client
5971}
Original file line number Diff line number Diff line change @@ -8,11 +8,23 @@ import (
88)
99
1010// TestConfigureGithubClient performs a sanity check that you can configure a production GitHub API client
11+ // If GITHUB_HOSTNAME, use the github.NewEnterpriseClient
1112func TestConfigureGithubClient (t * testing.T ) {
1213 t .Parallel ()
1314
14- client := ConfigureGithubClient ()
15- assert .NotNil (t , client )
15+ t .Run ("returns github client" , func (t * testing.T ) {
16+ client := ConfigureGithubClient ()
17+ assert .NotNil (t , client )
18+ })
19+ t .Run ("returns github client with GithubHostname" , func (t * testing.T ) {
20+ GithubHostname := "ghe.my-domain.com"
21+ os .Setenv ("GITHUB_HOSTNAME" , GithubHostname )
22+
23+ client := ConfigureGithubClient ()
24+ assert .NotNil (t , client )
25+
26+ })
27+
1628}
1729
1830// TestNoGithubOauthTokenPassed temporarily drops the existing GITHUB_OAUTH_TOKEN env var to ensure that the validation
You can’t perform that action at this time.
0 commit comments