Skip to content

Commit 2ce4f11

Browse files
nicolas-lopezng6fc5b
andauthored
Added 3 new options in order to support Github Enterprise and insecure ssl connections (#11)
Co-authored-by: ng6fc5b <nicolas.ni.lopez.external@airbus.com>
1 parent 6aa6fef commit 2ce4f11

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

main.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
package main
22

33
import (
4+
"crypto/tls"
45
"flag"
56
"fmt"
67
"log"
78
"net/http"
89
"os"
10+
"strings"
911

1012
"github.com/google/go-github/github"
1113
"golang.org/x/net/context"
1214
)
1315

1416
type roundTripper struct {
1517
accessToken string
18+
insecure bool
1619
}
1720

1821
func (rt roundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
1922
r.Header.Set("Authorization", fmt.Sprintf("token %s", rt.accessToken))
20-
return http.DefaultTransport.RoundTrip(r)
23+
transport := http.Transport {TLSClientConfig: &tls.Config{InsecureSkipVerify: rt.insecure}}
24+
return transport.RoundTrip(r)
2125
}
2226

2327
func isValidState(state string) bool {
@@ -40,6 +44,9 @@ var (
4044
ctx = flag.String("context", os.Getenv("GITHUB_CONTEXT"), "Status label. Could be the name of a CI environment")
4145
description = flag.String("description", os.Getenv("GITHUB_DESCRIPTION"), "Short high level summary of the status")
4246
url = flag.String("url", os.Getenv("GITHUB_TARGET_URL"), "URL of the page representing the status")
47+
baseURL = flag.String("baseURL", os.Getenv("GITHUB_BASE_URL"), "Base URL of github enterprise")
48+
uploadURL = flag.String("uploadURL", os.Getenv("GITHUB_UPLOAD_URL"), "Upload URL of github enterprise")
49+
insecure = flag.Bool("insecure", strings.ToLower(os.Getenv("GITHUB_INSECURE")) == "true", "Ignore SSL certificate check")
4350
)
4451

4552
func getUserLogins(users []*github.User) []string {
@@ -92,8 +99,21 @@ func main() {
9299
log.Fatal("-repo or GITHUB_REPO required")
93100
}
94101

95-
http.DefaultClient.Transport = roundTripper{*token}
96-
githubClient := github.NewClient(http.DefaultClient)
102+
http.DefaultClient.Transport = roundTripper{*token, *insecure}
103+
var githubClient *github.Client
104+
if *baseURL != "" || *uploadURL != "" {
105+
if *baseURL == "" {
106+
flag.PrintDefaults()
107+
log.Fatal("-baseURL or GITHUB_BASE_URL required when using -uploadURL or GITHUB_UPLOAD_URL")
108+
}
109+
if *uploadURL == "" {
110+
flag.PrintDefaults()
111+
log.Fatal("-uploadURL or GITHUB_UPLOAD_URL required when using -baseURL or GITHUB_BASE_URL")
112+
}
113+
githubClient, _ = github.NewEnterpriseClient(*baseURL, *uploadURL, http.DefaultClient)
114+
} else {
115+
githubClient = github.NewClient(http.DefaultClient)
116+
}
97117

98118
// Update status of a commit
99119
if *action == "update_state" {

0 commit comments

Comments
 (0)