Repository: google/go-github
Pull request #1780 (2021-01-22 19:12:52)

Repository.List: Add nebula-preview to receive visibility field
**What type of PR is this?**

feature

**What this PR does / why we need it**:

When calling `Repositories.List` (API Method: [List repositories for the authenticated user](https://docs.github.com/en/rest/reference/repos#list-repositories-for-the-authenticated-user)), the field `visibility` is always `nil`.

The `visibility` was introduced in a developer / API preview controlled by the media accept header. 
This PR enabled the API preview `nebula-preview` for `Repositories.List`, to retrieve the `visibility` of a repository.

**Special notes for your reviewer**:

None

**Does this PR introduce a user-facing change?**:

None

**Additional documentation e.g., usage docs, etc.**:

- [List repositories for the authenticated user @ GitHub REST API docs](https://docs.github.com/en/rest/reference/repos#list-repositories-for-the-authenticated-user): In the response, the `visibility` field is available.
- [API changes to support internal repository visibility (2019-12-03)](https://developer.github.com/changes/2019-12-03-internal-visibility-changes/#repository-visibility-fields)


codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/1780?src=pr&el=h1) Report
> Merging [#1780](https://codecov.io/gh/google/go-github/pull/1780?src=pr&el=desc) (9da8220) into [master](https://codecov.io/gh/google/go-github/commit/9c17d51325e625ffd986e65a8fee0c807c1215b5?el=desc) (9c17d51) will **not change** coverage.
> The diff coverage is `100.00%`.

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

```diff
@@           Coverage Diff           @@
##           master    #1780   +/-   ##
=======================================
  Coverage   97.54%   97.54%           
=======================================
  Files          98       98           
  Lines        6387     6387           
=======================================
  Hits         6230     6230           
  Misses         85       85           
  Partials       72       72           
```


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

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/go-github/pull/1780?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/1780?src=pr&el=footer). Last update [9c17d51...9da8220](https://codecov.io/gh/google/go-github/pull/1780?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..08006bdf 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
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..e0fb6825 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, ", "))