Repository: google/go-github
Pull request #1782 (2021-01-23 09:55:42)

Clean up unnecessary preview headers
Removes unnecessary **mediaTypeRequiredApprovingReviewsPreview** headers as described in #1779 

codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/1782?src=pr&el=h1) Report
> Merging [#1782](https://codecov.io/gh/google/go-github/pull/1782?src=pr&el=desc) (9f82ded) into [master](https://codecov.io/gh/google/go-github/commit/9c17d51325e625ffd986e65a8fee0c807c1215b5?el=desc) (9c17d51) will **decrease** coverage by `0.00%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/google/go-github/pull/1782/graphs/tree.svg?width=650&height=150&src=pr&token=EgYjGjZlI0)](https://codecov.io/gh/google/go-github/pull/1782?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1782      +/-   ##
==========================================
- Coverage   97.54%   97.53%   -0.01%     
==========================================
  Files          98       98              
  Lines        6387     6378       -9     
==========================================
- Hits         6230     6221       -9     
  Misses         85       85              
  Partials       72       72              
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/1782?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [github/repos.go](https://codecov.io/gh/google/go-github/pull/1782/diff?src=pr&el=tree#diff-Z2l0aHViL3JlcG9zLmdv) | `98.70% <ø> (-0.03%)` | :arrow_down: |

------

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


Patch:
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 78082ffe..a3b857ec 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -5580,6 +5580,14 @@ func (k *Key) GetURL() string {
 	return *k.URL
 }
 
+// GetVerified returns the Verified field if it's non-nil, zero value otherwise.
+func (k *Key) GetVerified() bool {
+	if k == nil || k.Verified == nil {
+		return false
+	}
+	return *k.Verified
+}
+
 // GetColor returns the Color field if it's non-nil, zero value otherwise.
 func (l *Label) GetColor() string {
 	if l == nil || l.Color == nil {
diff --git a/github/repos.go b/github/repos.go
index a31ad8ce..22c0f8fa 100644
--- a/github/repos.go
+++ b/github/repos.go
@@ -202,7 +202,7 @@ func (s *RepositoriesService) List(ctx context.Context, user string, opts *Repos
 	}
 
 	// TODO: remove custom Accept headers when APIs fully launch.
-	acceptHeaders := []string{mediaTypeTopicsPreview}
+	acceptHeaders := []string{mediaTypeTopicsPreview, mediaTypeRepositoryVisibilityPreview}
 	req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
 
 	var repos []*Repository
@@ -920,9 +920,6 @@ func (s *RepositoriesService) ListBranches(ctx context.Context, owner string, re
 		return nil, nil, err
 	}
 
-	// TODO: remove custom Accept header when this API fully launches
-	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
-
 	var branches []*Branch
 	resp, err := s.client.Do(ctx, req, &branches)
 	if err != nil {
@@ -942,9 +939,6 @@ func (s *RepositoriesService) GetBranch(ctx context.Context, owner, repo, branch
 		return nil, nil, err
 	}
 
-	// TODO: remove custom Accept header when this API fully launches
-	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
-
 	b := new(Branch)
 	resp, err := s.client.Do(ctx, req, b)
 	if err != nil {
@@ -986,9 +980,6 @@ func (s *RepositoriesService) GetRequiredStatusChecks(ctx context.Context, owner
 		return nil, nil, err
 	}
 
-	// TODO: remove custom Accept header when this API fully launches
-	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
-
 	p := new(RequiredStatusChecks)
 	resp, err := s.client.Do(ctx, req, p)
 	if err != nil {
@@ -1008,9 +999,6 @@ func (s *RepositoriesService) ListRequiredStatusChecksContexts(ctx context.Conte
 		return nil, nil, err
 	}
 
-	// TODO: remove custom Accept header when this API fully launches
-	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
-
 	resp, err = s.client.Do(ctx, req, &contexts)
 	if err != nil {
 		return nil, resp, err
@@ -1051,9 +1039,6 @@ func (s *RepositoriesService) RemoveBranchProtection(ctx context.Context, owner,
 		return nil, err
 	}
 
-	// TODO: remove custom Accept header when this API fully launches
-	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
-
 	return s.client.Do(ctx, req, nil)
 }
 
@@ -1252,9 +1237,6 @@ func (s *RepositoriesService) RemovePullRequestReviewEnforcement(ctx context.Con
 		return nil, err
 	}
 
-	// TODO: remove custom Accept header when this API fully launches
-	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
-
 	return s.client.Do(ctx, req, nil)
 }
 
@@ -1268,9 +1250,6 @@ func (s *RepositoriesService) GetAdminEnforcement(ctx context.Context, owner, re
 		return nil, nil, err
 	}
 
-	// TODO: remove custom Accept header when this API fully launches
-	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
-
 	r := new(AdminEnforcement)
 	resp, err := s.client.Do(ctx, req, r)
 	if err != nil {
@@ -1291,9 +1270,6 @@ func (s *RepositoriesService) AddAdminEnforcement(ctx context.Context, owner, re
 		return nil, nil, err
 	}
 
-	// TODO: remove custom Accept header when this API fully launches
-	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
-
 	r := new(AdminEnforcement)
 	resp, err := s.client.Do(ctx, req, r)
 	if err != nil {
@@ -1313,9 +1289,6 @@ func (s *RepositoriesService) RemoveAdminEnforcement(ctx context.Context, owner,
 		return nil, err
 	}
 
-	// TODO: remove custom Accept header when this API fully launches
-	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
-
 	return s.client.Do(ctx, req, nil)
 }
 
diff --git a/github/users_keys.go b/github/users_keys.go
index 0e855055..b5d4f79d 100644
--- a/github/users_keys.go
+++ b/github/users_keys.go
@@ -17,6 +17,7 @@ type Key struct {
 	URL       *string    `json:"url,omitempty"`
 	Title     *string    `json:"title,omitempty"`
 	ReadOnly  *bool      `json:"read_only,omitempty"`
+	Verified  *bool      `json:"verified,omitempty"`
 	CreatedAt *Timestamp `json:"created_at,omitempty"`
 }
 


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index e2a139be..8b872d8f 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -6520,6 +6520,16 @@ func TestKey_GetURL(tt *testing.T) {
 	k.GetURL()
 }
 
+func TestKey_GetVerified(tt *testing.T) {
+	var zeroValue bool
+	k := &Key{Verified: &zeroValue}
+	k.GetVerified()
+	k = &Key{}
+	k.GetVerified()
+	k = nil
+	k.GetVerified()
+}
+
 func TestLabel_GetColor(tt *testing.T) {
 	var zeroValue string
 	l := &Label{Color: &zeroValue}
diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go
index 2113453f..4e97940a 100644
--- a/github/github-stringify_test.go
+++ b/github/github-stringify_test.go
@@ -671,9 +671,10 @@ func TestKey_String(t *testing.T) {
 		URL:       String(""),
 		Title:     String(""),
 		ReadOnly:  Bool(false),
+		Verified:  Bool(false),
 		CreatedAt: &Timestamp{},
 	}
-	want := `github.Key{ID:0, Key:"", URL:"", Title:"", ReadOnly:false, CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}`
+	want := `github.Key{ID:0, Key:"", URL:"", Title:"", ReadOnly:false, Verified:false, CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}`
 	if got := v.String(); got != want {
 		t.Errorf("Key.String = %v, want %v", got, want)
 	}
diff --git a/github/repos_test.go b/github/repos_test.go
index 0438820d..bbe82ea6 100644
--- a/github/repos_test.go
+++ b/github/repos_test.go
@@ -19,7 +19,7 @@ func TestRepositoriesService_List_authenticatedUser(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()
 
-	wantAcceptHeaders := []string{mediaTypeTopicsPreview}
+	wantAcceptHeaders := []string{mediaTypeTopicsPreview, mediaTypeRepositoryVisibilityPreview}
 	mux.HandleFunc("/user/repos", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
 		testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
@@ -56,7 +56,7 @@ func TestRepositoriesService_List_specifiedUser(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()
 
-	wantAcceptHeaders := []string{mediaTypeTopicsPreview}
+	wantAcceptHeaders := []string{mediaTypeTopicsPreview, mediaTypeRepositoryVisibilityPreview}
 	mux.HandleFunc("/users/u/repos", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
 		testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
@@ -93,7 +93,7 @@ func TestRepositoriesService_List_specifiedUser_type(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()
 
-	wantAcceptHeaders := []string{mediaTypeTopicsPreview}
+	wantAcceptHeaders := []string{mediaTypeTopicsPreview, mediaTypeRepositoryVisibilityPreview}
 	mux.HandleFunc("/users/u/repos", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
 		testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
@@ -841,8 +841,6 @@ func TestRepositoriesService_ListBranches(t *testing.T) {
 
 	mux.HandleFunc("/repos/o/r/branches", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
-		// TODO: remove custom Accept header when this API fully launches
-		testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview)
 		testFormValues(t, r, values{"page": "2"})
 		fmt.Fprint(w, `[{"name":"master", "commit" : {"sha" : "a57781", "url" : "https://api.github.com/repos/o/r/commits/a57781"}}]`)
 	})
@@ -883,8 +881,6 @@ func TestRepositoriesService_GetBranch(t *testing.T) {
 
 	mux.HandleFunc("/repos/o/r/branches/b", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
-		// TODO: remove custom Accept header when this API fully launches
-		testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview)
 		fmt.Fprint(w, `{"name":"n", "commit":{"sha":"s","commit":{"message":"m"}}, "protected":true}`)
 	})
 
@@ -1208,8 +1204,6 @@ func TestRepositoriesService_RemoveBranchProtection(t *testing.T) {
 
 	mux.HandleFunc("/repos/o/r/branches/b/protection", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "DELETE")
-		// TODO: remove custom Accept header when this API fully launches
-		testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview)
 		w.WriteHeader(http.StatusNoContent)
 	})
 
@@ -1294,8 +1288,6 @@ func TestRepositoriesService_GetRequiredStatusChecks(t *testing.T) {
 		json.NewDecoder(r.Body).Decode(v)
 
 		testMethod(t, r, "GET")
-		// TODO: remove custom Accept header when this API fully launches
-		testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview)
 		fmt.Fprint(w, `{"strict": true,"contexts": ["x","y","z"]}`)
 	})
 
@@ -1414,8 +1406,6 @@ func TestRepositoriesService_ListRequiredStatusChecksContexts(t *testing.T) {
 		json.NewDecoder(r.Body).Decode(v)
 
 		testMethod(t, r, "GET")
-		// TODO: remove custom Accept header when this API fully launches
-		testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview)
 		fmt.Fprint(w, `["x", "y", "z"]`)
 	})
 
@@ -1622,7 +1612,6 @@ func TestRepositoriesService_RemovePullRequestReviewEnforcement(t *testing.T) {
 
 	mux.HandleFunc("/repos/o/r/branches/b/protection/required_pull_request_reviews", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "DELETE")
-		testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview)
 		w.WriteHeader(http.StatusNoContent)
 	})
 
@@ -1649,7 +1638,6 @@ func TestRepositoriesService_GetAdminEnforcement(t *testing.T) {
 
 	mux.HandleFunc("/repos/o/r/branches/b/protection/enforce_admins", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
-		testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview)
 		fmt.Fprintf(w, `{"url":"/repos/o/r/branches/b/protection/enforce_admins","enabled":true}`)
 	})
 
@@ -1689,7 +1677,6 @@ func TestRepositoriesService_AddAdminEnforcement(t *testing.T) {
 
 	mux.HandleFunc("/repos/o/r/branches/b/protection/enforce_admins", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "POST")
-		testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview)
 		fmt.Fprintf(w, `{"url":"/repos/o/r/branches/b/protection/enforce_admins","enabled":true}`)
 	})
 
@@ -1728,7 +1715,6 @@ func TestRepositoriesService_RemoveAdminEnforcement(t *testing.T) {
 
 	mux.HandleFunc("/repos/o/r/branches/b/protection/enforce_admins", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "DELETE")
-		testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview)
 		w.WriteHeader(http.StatusNoContent)
 	})