Repository: google/go-github
Pull request #2016 (2021-07-20 20:33:00)

Add Client method
Fixes: #1859.
Closes: #2015.

codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/2016?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2016](https://codecov.io/gh/google/go-github/pull/2016?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (e708608) into [master](https://codecov.io/gh/google/go-github/commit/b8294c36e447250ab6493d5f73337eb412be6941?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (b8294c3) will **decrease** coverage by `0.04%`.
> The diff coverage is `0.00%`.

[![Impacted file tree graph](https://codecov.io/gh/google/go-github/pull/2016/graphs/tree.svg?width=650&height=150&src=pr&token=EgYjGjZlI0&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)](https://codecov.io/gh/google/go-github/pull/2016?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)

```diff
@@            Coverage Diff             @@
##           master    #2016      +/-   ##
==========================================
- Coverage   97.86%   97.82%   -0.05%     
==========================================
  Files         107      107              
  Lines        6897     6900       +3     
==========================================
  Hits         6750     6750              
- Misses         81       84       +3     
  Partials       66       66              
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/2016?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Coverage Δ | |
|---|---|---|
| [github/github.go](https://codecov.io/gh/google/go-github/pull/2016/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL2dpdGh1Yi5nbw==) | `96.30% <0.00%> (-0.77%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/go-github/pull/2016?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/google/go-github/pull/2016?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Last update [b8294c3...e708608](https://codecov.io/gh/google/go-github/pull/2016?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).

gmlewis: @bluekeyes and @jeffmendoza - what do you think of this solution?  Feel free to LGTM+Approve if you agree.
gmlewis: @bluekeyes - feel free to LGTM+Approve this and we can get it merged.

Patch:
diff --git a/github/github.go b/github/github.go
index ae0ee08c..2f765365 100644
--- a/github/github.go
+++ b/github/github.go
@@ -188,6 +188,14 @@ type service struct {
 	client *Client
 }
 
+// Client returns the http.Client used by this GitHub client.
+func (c *Client) Client() *http.Client {
+	c.clientMu.Lock()
+	defer c.clientMu.Unlock()
+	clientCopy := *c.client
+	return &clientCopy
+}
+
 // ListOptions specifies the optional parameters to various List methods that
 // support offset pagination.
 type ListOptions struct {


Test patch:
diff --git a/github/github_test.go b/github/github_test.go
index 1eb0dba7..d2240558 100644
--- a/github/github_test.go
+++ b/github/github_test.go
@@ -232,6 +232,14 @@ func TestNewClient(t *testing.T) {
 	}
 }
 
+func TestClient(t *testing.T) {
+	c := NewClient(nil)
+	c2 := c.Client()
+	if c.client == c2 {
+		t.Error("Client returned same http.Client, but should be different")
+	}
+}
+
 func TestNewEnterpriseClient(t *testing.T) {
 	baseURL := "https://custom-url/api/v3/"
 	uploadURL := "https://custom-upload-url/api/uploads/"