File tree 3 files changed +34
-4
lines changed 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
192
192
export GITHUB_OAUTH_TOKEN=< your-secret-github-oauth-token>
193
193
` ` `
194
194
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
+
195
200
1. ** Provide a script or command and target some repos** . Here' s a simple example of running the `touch` command in
196
201
every repo in your GitHub organization. Follow the same pattern to start running your own scripts and commands
197
202
against your own repos!
@@ -204,6 +209,7 @@ $ brew install git-xargs
204
209
touch git-xargs-is-awesome.txt
205
210
```
206
211
212
+
207
213
# Reference
208
214
209
215
## How to supply commands or scripts to run
Original file line number Diff line number Diff line change @@ -2,12 +2,12 @@ package auth
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
"os"
6
7
7
8
"github.com/google/go-github/v43/github"
8
9
"github.com/gruntwork-io/git-xargs/types"
9
10
"github.com/gruntwork-io/go-commons/errors"
10
-
11
11
"golang.org/x/oauth2"
12
12
)
13
13
@@ -52,8 +52,20 @@ func ConfigureGithubClient() GithubClient {
52
52
53
53
tc := oauth2 .NewClient (context .Background (), ts )
54
54
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
+
55
67
// 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 )
57
69
58
70
return client
59
71
}
Original file line number Diff line number Diff line change @@ -8,11 +8,23 @@ import (
8
8
)
9
9
10
10
// TestConfigureGithubClient performs a sanity check that you can configure a production GitHub API client
11
+ // If GITHUB_HOSTNAME, use the github.NewEnterpriseClient
11
12
func TestConfigureGithubClient (t * testing.T ) {
12
13
t .Parallel ()
13
14
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
+
16
28
}
17
29
18
30
// 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