Repository: google/go-github
Pull request #2686 (2023-03-03 06:19:47)

Support HTTP Proxy from environment
Add the support of http prxoy to `NewClientWithEnvProxy`.

Relates to: #2363.

gmlewis: @hangscer8 - I'm concerned that this change is going to affect current users of this repo who are not expecting this behavior to be the default.

Could we instead add a new `NewClientWithEnvProxy` or something like that?
hangscer8: > @hangscer8 - I'm concerned that this change is going to affect current users of this repo who are not expecting this behavior to be the default.
> 
> Could we instead add a new `NewClientWithEnvProxy` or something like that?

OK, I will fix that. @gmlewis 
codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/2686?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2686](https://codecov.io/gh/google/go-github/pull/2686?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (d56db10) into [master](https://codecov.io/gh/google/go-github/commit/099fae4bf5d6700d159c0b4d12f23ad1194ad713?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (099fae4) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

```diff
@@           Coverage Diff           @@
##           master    #2686   +/-   ##
=======================================
  Coverage   98.05%   98.05%           
=======================================
  Files         131      131           
  Lines       11442    11459   +17     
=======================================
+ Hits        11219    11236   +17     
  Misses        152      152           
  Partials       71       71           
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/2686?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/2686?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL2dpdGh1Yi5nbw==) | `97.94% <100.00%> (+<0.01%)` | :arrow_up: |
| [github/event.go](https://codecov.io/gh/google/go-github/pull/2686?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL2V2ZW50Lmdv) | `100.00% <0.00%> (ø)` | |
| [github/messages.go](https://codecov.io/gh/google/go-github/pull/2686?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL21lc3NhZ2VzLmdv) | `100.00% <0.00%> (ø)` | |
| [github/event\_types.go](https://codecov.io/gh/google/go-github/pull/2686?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL2V2ZW50X3R5cGVzLmdv) | `100.00% <0.00%> (ø)` | |
| [github/teams.go](https://codecov.io/gh/google/go-github/pull/2686?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL3RlYW1zLmdv) | `98.18% <0.00%> (+0.04%)` | :arrow_up: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)


Patch:
diff --git a/github/actions_workflow_runs.go b/github/actions_workflow_runs.go
index 6241dc62..0cda90d4 100644
--- a/github/actions_workflow_runs.go
+++ b/github/actions_workflow_runs.go
@@ -60,6 +60,7 @@ type ListWorkflowRunsOptions struct {
 	Event   string `url:"event,omitempty"`
 	Status  string `url:"status,omitempty"`
 	Created string `url:"created,omitempty"`
+	HeadSHA string `url:"head_sha,omitempty"`
 	ListOptions
 }
 
diff --git a/github/github.go b/github/github.go
index 4e0d2f47..58715b11 100644
--- a/github/github.go
+++ b/github/github.go
@@ -348,6 +348,11 @@ func NewClient(httpClient *http.Client) *Client {
 	return c
 }
 
+// NewClientWithEnvProxy enhances NewClient with the HttpProxy env.
+func NewClientWithEnvProxy() *Client {
+	return NewClient(&http.Client{Transport: &http.Transport{Proxy: http.ProxyFromEnvironment}})
+}
+
 // NewTokenClient returns a new GitHub API client authenticated with the provided token.
 func NewTokenClient(ctx context.Context, token string) *Client {
 	return NewClient(oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})))


Test patch:
diff --git a/github/github_test.go b/github/github_test.go
index 0c969404..4a70649d 100644
--- a/github/github_test.go
+++ b/github/github_test.go
@@ -264,6 +264,13 @@ func TestNewClient(t *testing.T) {
 	}
 }
 
+func TestNewClientWithEnvProxy(t *testing.T) {
+	client := NewClientWithEnvProxy()
+	if got, want := client.BaseURL.String(), defaultBaseURL; got != want {
+		t.Errorf("NewClient BaseURL is %v, want %v", got, want)
+	}
+}
+
 func TestClient(t *testing.T) {
 	c := NewClient(nil)
 	c2 := c.Client()