Skip to content

Commit

Permalink
Added 3 new options in order to support Github Enterprise and insecur…
Browse files Browse the repository at this point in the history
…e ssl connections (#11)

Co-authored-by: ng6fc5b <[email protected]>
  • Loading branch information
nicolas-lopez and ng6fc5b authored Jun 30, 2020
1 parent 6aa6fef commit 2ce4f11
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
package main

import (
"crypto/tls"
"flag"
"fmt"
"log"
"net/http"
"os"
"strings"

"github.com/google/go-github/github"
"golang.org/x/net/context"
)

type roundTripper struct {
accessToken string
insecure bool
}

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

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

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

http.DefaultClient.Transport = roundTripper{*token}
githubClient := github.NewClient(http.DefaultClient)
http.DefaultClient.Transport = roundTripper{*token, *insecure}
var githubClient *github.Client
if *baseURL != "" || *uploadURL != "" {
if *baseURL == "" {
flag.PrintDefaults()
log.Fatal("-baseURL or GITHUB_BASE_URL required when using -uploadURL or GITHUB_UPLOAD_URL")
}
if *uploadURL == "" {
flag.PrintDefaults()
log.Fatal("-uploadURL or GITHUB_UPLOAD_URL required when using -baseURL or GITHUB_BASE_URL")
}
githubClient, _ = github.NewEnterpriseClient(*baseURL, *uploadURL, http.DefaultClient)
} else {
githubClient = github.NewClient(http.DefaultClient)
}

// Update status of a commit
if *action == "update_state" {
Expand Down

0 comments on commit 2ce4f11

Please sign in to comment.