Skip to content

Commit a12f9cd

Browse files
authored
Add Client method (#2016)
Fixes: #1859.
1 parent b8294c3 commit a12f9cd

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

github/github.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ type service struct {
188188
client *Client
189189
}
190190

191+
// Client returns the http.Client used by this GitHub client.
192+
func (c *Client) Client() *http.Client {
193+
c.clientMu.Lock()
194+
defer c.clientMu.Unlock()
195+
clientCopy := *c.client
196+
return &clientCopy
197+
}
198+
191199
// ListOptions specifies the optional parameters to various List methods that
192200
// support offset pagination.
193201
type ListOptions struct {

github/github_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,14 @@ func TestNewClient(t *testing.T) {
232232
}
233233
}
234234

235+
func TestClient(t *testing.T) {
236+
c := NewClient(nil)
237+
c2 := c.Client()
238+
if c.client == c2 {
239+
t.Error("Client returned same http.Client, but should be different")
240+
}
241+
}
242+
235243
func TestNewEnterpriseClient(t *testing.T) {
236244
baseURL := "https://custom-url/api/v3/"
237245
uploadURL := "https://custom-upload-url/api/uploads/"

0 commit comments

Comments
 (0)