Skip to content

Commit 71db17e

Browse files
authored
fix: nil check for github.NewClient (#2465)
Fixes #2464
1 parent 7259194 commit 71db17e

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

internal/github/github.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func NewClient(accessToken string, repo *Repository) *Client {
5959

6060
func newClientWithHTTP(accessToken string, repo *Repository, httpClient *http.Client) *Client {
6161
client := github.NewClient(httpClient)
62-
if repo.BaseURL != "" {
62+
if repo != nil && repo.BaseURL != "" {
6363
baseURL, _ := url.Parse(repo.BaseURL)
6464
// Ensure the endpoint URL has a trailing slash.
6565
if !strings.HasSuffix(baseURL.Path, "/") {

internal/github/github_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,3 +1118,42 @@ func TestCreateTag(t *testing.T) {
11181118
})
11191119
}
11201120
}
1121+
1122+
func TestNewClient(t *testing.T) {
1123+
1124+
t.Parallel()
1125+
for _, test := range []struct {
1126+
name string
1127+
token string
1128+
repo *Repository
1129+
}{
1130+
{
1131+
name: "with credentials",
1132+
token: "some-token",
1133+
},
1134+
{
1135+
name: "with custom repo",
1136+
token: "some-token",
1137+
repo: &Repository{
1138+
Owner: "some-owner",
1139+
Name: "some-repo",
1140+
BaseURL: "https://example.com/",
1141+
},
1142+
},
1143+
{
1144+
name: "with repo, without base url",
1145+
token: "some-token",
1146+
repo: &Repository{
1147+
Owner: "some-owner",
1148+
Name: "some-repo",
1149+
},
1150+
},
1151+
} {
1152+
t.Run(test.name, func(t *testing.T) {
1153+
client := NewClient(test.token, nil)
1154+
if client == nil {
1155+
t.Fatalf("expected to create a new client")
1156+
}
1157+
})
1158+
}
1159+
}

0 commit comments

Comments
 (0)