|
1 | 1 | package main
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "crypto/tls" |
4 | 5 | "flag"
|
5 | 6 | "fmt"
|
6 | 7 | "log"
|
7 | 8 | "net/http"
|
8 | 9 | "os"
|
| 10 | + "strings" |
9 | 11 |
|
10 | 12 | "github.com/google/go-github/github"
|
11 | 13 | "golang.org/x/net/context"
|
12 | 14 | )
|
13 | 15 |
|
14 | 16 | type roundTripper struct {
|
15 | 17 | accessToken string
|
| 18 | + insecure bool |
16 | 19 | }
|
17 | 20 |
|
18 | 21 | func (rt roundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
|
19 | 22 | 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) |
21 | 25 | }
|
22 | 26 |
|
23 | 27 | func isValidState(state string) bool {
|
|
40 | 44 | ctx = flag.String("context", os.Getenv("GITHUB_CONTEXT"), "Status label. Could be the name of a CI environment")
|
41 | 45 | description = flag.String("description", os.Getenv("GITHUB_DESCRIPTION"), "Short high level summary of the status")
|
42 | 46 | 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") |
43 | 50 | )
|
44 | 51 |
|
45 | 52 | func getUserLogins(users []*github.User) []string {
|
@@ -92,8 +99,21 @@ func main() {
|
92 | 99 | log.Fatal("-repo or GITHUB_REPO required")
|
93 | 100 | }
|
94 | 101 |
|
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 | + } |
97 | 117 |
|
98 | 118 | // Update status of a commit
|
99 | 119 | if *action == "update_state" {
|
|
0 commit comments