Repository: google/go-github
Pull request #1781 (2021-01-23 09:11:48)

User.Keys: Add verified field
**What type of PR is this?**

feature

**What this PR does / why we need it**:

When calling `Users.ListKeys` (API Method: [List public SSH keys for the authenticated user](https://docs.github.com/en/rest/reference/users#list-public-ssh-keys-for-the-authenticated-user)), the field `verified` is not populated.

This PR enabled adds `visibility` files to the USers.Key structure.

**Special notes for your reviewer**:

None

**Does this PR introduce a user-facing change?**:

None

**Additional documentation e.g., usage docs, etc.**:

- [List public SSH keys for the authenticated user @ GitHub REST API docs](https://docs.github.com/en/rest/reference/users#list-public-ssh-keys-for-the-authenticated-user)

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

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

```diff
@@           Coverage Diff           @@
##           master    #1781   +/-   ##
=======================================
  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/1781?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [github/users\_keys.go](https://codecov.io/gh/google/go-github/pull/1781/diff?src=pr&el=tree#diff-Z2l0aHViL3VzZXJzX2tleXMuZ28=) | `100.00% <ø> (ø)` | |

------

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