Skip to content

Commit

Permalink
fix(github): use BasicAuthTransport
Browse files Browse the repository at this point in the history
  • Loading branch information
Jian Zeng authored and caicloud-bot committed Feb 3, 2021
1 parent 423a0e4 commit c805430
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions pkg/server/biz/scm/github/github.go
Expand Up @@ -22,7 +22,6 @@ import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"reflect"
"regexp"
"strings"
Expand Down Expand Up @@ -427,22 +426,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 @@ -451,7 +447,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
}

// newClientByToken news Github client by token.
Expand Down

0 comments on commit c805430

Please sign in to comment.