Skip to content

Commit

Permalink
fix(github): use BasicAuthTransport (#1564)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jian Zeng authored Jan 28, 2021
1 parent 8bb6f49 commit 0aefcc6
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions pkg/server/biz/scm/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"reflect"
"regexp"
"strings"
Expand Down Expand Up @@ -444,22 +443,19 @@ func (g *Github) GetPullRequestSHA(repoURL string, number int) (string, error) {
// with OAuth token.
// Refer to https://developer.github.com/v3/auth/#basic-authentication
func newClientByBasicAuth(server, username, password string) (*github.Client, error) {
transport := &http.Transport{
Proxy: func(req *http.Request) (*url.URL, error) {
req.SetBasicAuth(username, password)
return nil, nil
},
}

httpClient := &http.Client{
Transport: transport,
}

if !isPublic(server) {
transport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
transport := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
client, err := github.NewEnterpriseClient(server, server, httpClient)
client, err := github.NewEnterpriseClient(server, server, &http.Client{
Transport: &github.BasicAuthTransport{
Username: username,
Password: password,
Transport: transport,
},
})
if err != nil {
log.Error("Fail to new client for enterprise Github as %v", err)
return nil, err
Expand All @@ -468,7 +464,12 @@ func newClientByBasicAuth(server, username, password string) (*github.Client, er
return client, nil
}

return github.NewClient(httpClient), nil
return github.NewClient(&http.Client{
Transport: &github.BasicAuthTransport{
Username: username,
Password: password,
},
}), nil
}

// GetWebhook gets webhook from specified repo.
Expand Down

0 comments on commit 0aefcc6

Please sign in to comment.