From 804f078860a1bf5dece4022327f742656cf4f9c0 Mon Sep 17 00:00:00 2001 From: Nicolas Chapurlat Date: Mon, 27 Mar 2023 10:38:18 +0200 Subject: [PATCH] Add added_by and last_used fields on keys --- github/github-accessors.go | 16 ++++++++++++++++ github/github-accessors_test.go | 20 ++++++++++++++++++++ github/github-stringify_test.go | 4 +++- github/users_keys.go | 2 ++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index beeb2defce6..3d42907b96c 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -8646,6 +8646,14 @@ func (j *Jobs) GetTotalCount() int { return *j.TotalCount } +// GetAddedBy returns the AddedBy field if it's non-nil, zero value otherwise. +func (k *Key) GetAddedBy() string { + if k == nil || k.AddedBy == nil { + return "" + } + return *k.AddedBy +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (k *Key) GetCreatedAt() Timestamp { if k == nil || k.CreatedAt == nil { @@ -8670,6 +8678,14 @@ func (k *Key) GetKey() string { return *k.Key } +// GetLastUsed returns the LastUsed field if it's non-nil, zero value otherwise. +func (k *Key) GetLastUsed() Timestamp { + if k == nil || k.LastUsed == nil { + return Timestamp{} + } + return *k.LastUsed +} + // GetReadOnly returns the ReadOnly field if it's non-nil, zero value otherwise. func (k *Key) GetReadOnly() bool { if k == nil || k.ReadOnly == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 3cc4001ed4a..20ba7425d7a 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -10130,6 +10130,16 @@ func TestJobs_GetTotalCount(tt *testing.T) { j.GetTotalCount() } +func TestKey_GetAddedBy(tt *testing.T) { + var zeroValue string + k := &Key{AddedBy: &zeroValue} + k.GetAddedBy() + k = &Key{} + k.GetAddedBy() + k = nil + k.GetAddedBy() +} + func TestKey_GetCreatedAt(tt *testing.T) { var zeroValue Timestamp k := &Key{CreatedAt: &zeroValue} @@ -10160,6 +10170,16 @@ func TestKey_GetKey(tt *testing.T) { k.GetKey() } +func TestKey_GetLastUsed(tt *testing.T) { + var zeroValue Timestamp + k := &Key{LastUsed: &zeroValue} + k.GetLastUsed() + k = &Key{} + k.GetLastUsed() + k = nil + k.GetLastUsed() +} + func TestKey_GetReadOnly(tt *testing.T) { var zeroValue bool k := &Key{ReadOnly: &zeroValue} diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index f83ce4ced81..60052554970 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -795,8 +795,10 @@ func TestKey_String(t *testing.T) { ReadOnly: Bool(false), Verified: Bool(false), CreatedAt: &Timestamp{}, + AddedBy: String(""), + LastUsed: &Timestamp{}, } - want := `github.Key{ID:0, Key:"", URL:"", Title:"", ReadOnly:false, Verified: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}, AddedBy:"", LastUsed: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/users_keys.go b/github/users_keys.go index 59d26cdefa9..b49b8e4b4ef 100644 --- a/github/users_keys.go +++ b/github/users_keys.go @@ -19,6 +19,8 @@ type Key struct { ReadOnly *bool `json:"read_only,omitempty"` Verified *bool `json:"verified,omitempty"` CreatedAt *Timestamp `json:"created_at,omitempty"` + AddedBy *string `json:"added_by,omitempty"` + LastUsed *Timestamp `json:"last_used,omitempty"` } func (k Key) String() string {