diff --git a/.golangci.yml b/.golangci.yml index 8aa45461ef1..802430c1ad6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -227,7 +227,6 @@ linters: - InstallationTokenListRepoOptions - InstallationTokenOptions - IssueImportRequest - - Key - LockIssueOptions - MaintenanceOptions - Organization diff --git a/github/github-accessors.go b/github/github-accessors.go index 85fb14ef0d7..0d04bb70388 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -11414,6 +11414,30 @@ func (c *CreateCustomRepoRoleRequest) GetPermissions() []string { return c.Permissions } +// GetKey returns the Key field. +func (c *CreateDeployKeyRequest) GetKey() string { + if c == nil { + return "" + } + return c.Key +} + +// GetReadOnly returns the ReadOnly field if it's non-nil, zero value otherwise. +func (c *CreateDeployKeyRequest) GetReadOnly() bool { + if c == nil || c.ReadOnly == nil { + return false + } + return *c.ReadOnly +} + +// GetTitle returns the Title field if it's non-nil, zero value otherwise. +func (c *CreateDeployKeyRequest) GetTitle() string { + if c == nil || c.Title == nil { + return "" + } + return *c.Title +} + // GetName returns the Name field. func (c *CreateDeploymentBranchPolicyRequest) GetName() string { if c == nil { @@ -12302,6 +12326,22 @@ func (c *CreateRunnerGroupRequest) GetVisibility() string { return *c.Visibility } +// GetKey returns the Key field. +func (c *CreateSSHSigningKeyRequest) GetKey() string { + if c == nil { + return "" + } + return c.Key +} + +// GetTitle returns the Title field if it's non-nil, zero value otherwise. +func (c *CreateSSHSigningKeyRequest) GetTitle() string { + if c == nil || c.Title == nil { + return "" + } + return *c.Title +} + // GetMessage returns the Message field. func (c *CreateTag) GetMessage() string { if c == nil { @@ -12462,6 +12502,22 @@ func (c *CreateUserImpersonationRequest) GetScopes() []string { return c.Scopes } +// GetKey returns the Key field. +func (c *CreateUserKeyRequest) GetKey() string { + if c == nil { + return "" + } + return c.Key +} + +// GetTitle returns the Title field if it's non-nil, zero value otherwise. +func (c *CreateUserKeyRequest) GetTitle() string { + if c == nil || c.Title == nil { + return "" + } + return *c.Title +} + // GetEmail returns the Email field if it's non-nil, zero value otherwise. func (c *CreateUserRequest) GetEmail() string { if c == nil || c.Email == nil { @@ -22294,6 +22350,14 @@ func (k *Key) GetCreatedAt() Timestamp { return *k.CreatedAt } +// GetEnabled returns the Enabled field if it's non-nil, zero value otherwise. +func (k *Key) GetEnabled() bool { + if k == nil || k.Enabled == nil { + return false + } + return *k.Enabled +} + // GetID returns the ID field if it's non-nil, zero value otherwise. func (k *Key) GetID() int64 { if k == nil || k.ID == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index b84d0561610..5e19d6e2674 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -14454,6 +14454,36 @@ func TestCreateCustomRepoRoleRequest_GetPermissions(tt *testing.T) { c.GetPermissions() } +func TestCreateDeployKeyRequest_GetKey(tt *testing.T) { + tt.Parallel() + c := &CreateDeployKeyRequest{} + c.GetKey() + c = nil + c.GetKey() +} + +func TestCreateDeployKeyRequest_GetReadOnly(tt *testing.T) { + tt.Parallel() + var zeroValue bool + c := &CreateDeployKeyRequest{ReadOnly: &zeroValue} + c.GetReadOnly() + c = &CreateDeployKeyRequest{} + c.GetReadOnly() + c = nil + c.GetReadOnly() +} + +func TestCreateDeployKeyRequest_GetTitle(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreateDeployKeyRequest{Title: &zeroValue} + c.GetTitle() + c = &CreateDeployKeyRequest{} + c.GetTitle() + c = nil + c.GetTitle() +} + func TestCreateDeploymentBranchPolicyRequest_GetName(tt *testing.T) { tt.Parallel() c := &CreateDeploymentBranchPolicyRequest{} @@ -15588,6 +15618,25 @@ func TestCreateRunnerGroupRequest_GetVisibility(tt *testing.T) { c.GetVisibility() } +func TestCreateSSHSigningKeyRequest_GetKey(tt *testing.T) { + tt.Parallel() + c := &CreateSSHSigningKeyRequest{} + c.GetKey() + c = nil + c.GetKey() +} + +func TestCreateSSHSigningKeyRequest_GetTitle(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreateSSHSigningKeyRequest{Title: &zeroValue} + c.GetTitle() + c = &CreateSSHSigningKeyRequest{} + c.GetTitle() + c = nil + c.GetTitle() +} + func TestCreateTag_GetMessage(tt *testing.T) { tt.Parallel() c := &CreateTag{} @@ -15787,6 +15836,25 @@ func TestCreateUserImpersonationRequest_GetScopes(tt *testing.T) { c.GetScopes() } +func TestCreateUserKeyRequest_GetKey(tt *testing.T) { + tt.Parallel() + c := &CreateUserKeyRequest{} + c.GetKey() + c = nil + c.GetKey() +} + +func TestCreateUserKeyRequest_GetTitle(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreateUserKeyRequest{Title: &zeroValue} + c.GetTitle() + c = &CreateUserKeyRequest{} + c.GetTitle() + c = nil + c.GetTitle() +} + func TestCreateUserRequest_GetEmail(tt *testing.T) { tt.Parallel() var zeroValue string @@ -28031,6 +28099,17 @@ func TestKey_GetCreatedAt(tt *testing.T) { k.GetCreatedAt() } +func TestKey_GetEnabled(tt *testing.T) { + tt.Parallel() + var zeroValue bool + k := &Key{Enabled: &zeroValue} + k.GetEnabled() + k = &Key{} + k.GetEnabled() + k = nil + k.GetEnabled() +} + func TestKey_GetID(tt *testing.T) { tt.Parallel() var zeroValue int64 diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index 6a439727b82..3bbdc8a9a61 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -1044,12 +1044,13 @@ func TestKey_String(t *testing.T) { URL: Ptr(""), Title: Ptr(""), ReadOnly: Ptr(false), + Enabled: Ptr(false), Verified: Ptr(false), CreatedAt: &Timestamp{}, AddedBy: Ptr(""), 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}, AddedBy:"", LastUsed:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}` + want := `github.Key{ID:0, Key:"", URL:"", Title:"", ReadOnly:false, Enabled: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/repos_keys.go b/github/repos_keys.go index ec456c4e6b2..1b43379ae0d 100644 --- a/github/repos_keys.go +++ b/github/repos_keys.go @@ -60,12 +60,19 @@ func (s *RepositoriesService) GetKey(ctx context.Context, owner, repo string, id return key, resp, nil } +// CreateDeployKeyRequest represents a request to create a deploy key. +type CreateDeployKeyRequest struct { + Title *string `json:"title,omitempty"` + Key string `json:"key"` + ReadOnly *bool `json:"read_only,omitempty"` +} + // CreateKey adds a deploy key for a repository. // // GitHub API docs: https://docs.github.com/rest/deploy-keys/deploy-keys?apiVersion=2022-11-28#create-a-deploy-key // //meta:operation POST /repos/{owner}/{repo}/keys -func (s *RepositoriesService) CreateKey(ctx context.Context, owner, repo string, body *Key) (*Key, *Response, error) { +func (s *RepositoriesService) CreateKey(ctx context.Context, owner, repo string, body CreateDeployKeyRequest) (*Key, *Response, error) { u := fmt.Sprintf("repos/%v/%v/keys", owner, repo) req, err := s.client.NewRequest(ctx, "POST", u, body) diff --git a/github/repos_keys_test.go b/github/repos_keys_test.go index cee855a828e..02e121a7252 100644 --- a/github/repos_keys_test.go +++ b/github/repos_keys_test.go @@ -107,7 +107,7 @@ func TestRepositoriesService_CreateKey(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := &Key{Key: Ptr("k"), Title: Ptr("t")} + input := CreateDeployKeyRequest{Key: "k", Title: Ptr("t")} mux.HandleFunc("/repos/o/r/keys", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") @@ -146,7 +146,7 @@ func TestRepositoriesService_CreateKey_invalidOwner(t *testing.T) { client, _, _ := setup(t) ctx := t.Context() - _, _, err := client.Repositories.CreateKey(ctx, "%", "%", nil) + _, _, err := client.Repositories.CreateKey(ctx, "%", "%", CreateDeployKeyRequest{}) testURLParseError(t, err) } diff --git a/github/users_keys.go b/github/users_keys.go index c8952fbdb5f..a7a54b44e16 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"` + Enabled *bool `json:"enabled,omitempty"` Verified *bool `json:"verified,omitempty"` CreatedAt *Timestamp `json:"created_at,omitempty"` AddedBy *string `json:"added_by,omitempty"` @@ -27,6 +28,13 @@ func (k Key) String() string { return Stringify(k) } +// CreateUserKeyRequest represents a request to create a public SSH key for the +// authenticated user. +type CreateUserKeyRequest struct { + Title *string `json:"title,omitempty"` + Key string `json:"key"` +} + // ListKeys lists the verified public keys for a user. Passing the empty // string will fetch keys for the authenticated user. // @@ -89,7 +97,7 @@ func (s *UsersService) GetKey(ctx context.Context, id int64) (*Key, *Response, e // GitHub API docs: https://docs.github.com/rest/users/keys?apiVersion=2022-11-28#create-a-public-ssh-key-for-the-authenticated-user // //meta:operation POST /user/keys -func (s *UsersService) CreateKey(ctx context.Context, body *Key) (*Key, *Response, error) { +func (s *UsersService) CreateKey(ctx context.Context, body CreateUserKeyRequest) (*Key, *Response, error) { u := "user/keys" req, err := s.client.NewRequest(ctx, "POST", u, body) diff --git a/github/users_keys_test.go b/github/users_keys_test.go index 245d99516a2..f2cd63807ec 100644 --- a/github/users_keys_test.go +++ b/github/users_keys_test.go @@ -119,7 +119,7 @@ func TestUsersService_CreateKey(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := &Key{Key: Ptr("k"), Title: Ptr("t")} + input := CreateUserKeyRequest{Key: "k", Title: Ptr("t")} mux.HandleFunc("/user/keys", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") diff --git a/github/users_ssh_signing_keys.go b/github/users_ssh_signing_keys.go index a25deabdc21..8df9ac5dcd0 100644 --- a/github/users_ssh_signing_keys.go +++ b/github/users_ssh_signing_keys.go @@ -22,6 +22,13 @@ func (k SSHSigningKey) String() string { return Stringify(k) } +// CreateSSHSigningKeyRequest represents a request to create an SSH signing key +// for the authenticated user. +type CreateSSHSigningKeyRequest struct { + Title *string `json:"title,omitempty"` + Key string `json:"key"` +} + // ListSSHSigningKeys lists the SSH signing keys for a user. Passing an empty // username string will fetch SSH signing keys for the authenticated user. // @@ -84,7 +91,7 @@ func (s *UsersService) GetSSHSigningKey(ctx context.Context, id int64) (*SSHSign // GitHub API docs: https://docs.github.com/rest/users/ssh-signing-keys?apiVersion=2022-11-28#create-a-ssh-signing-key-for-the-authenticated-user // //meta:operation POST /user/ssh_signing_keys -func (s *UsersService) CreateSSHSigningKey(ctx context.Context, body *Key) (*SSHSigningKey, *Response, error) { +func (s *UsersService) CreateSSHSigningKey(ctx context.Context, body CreateSSHSigningKeyRequest) (*SSHSigningKey, *Response, error) { u := "user/ssh_signing_keys" req, err := s.client.NewRequest(ctx, "POST", u, body) diff --git a/github/users_ssh_signing_keys_test.go b/github/users_ssh_signing_keys_test.go index f4c9c7f7a52..b5263dada4b 100644 --- a/github/users_ssh_signing_keys_test.go +++ b/github/users_ssh_signing_keys_test.go @@ -119,7 +119,7 @@ func TestUsersService_CreateSSHSigningKey(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - input := &Key{Key: Ptr("k"), Title: Ptr("t")} + input := CreateSSHSigningKeyRequest{Key: "k", Title: Ptr("t")} mux.HandleFunc("/user/ssh_signing_keys", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") @@ -138,9 +138,9 @@ func TestUsersService_CreateSSHSigningKey(t *testing.T) { t.Errorf("Users.CreateSSHSigningKey returned %+v, want %+v", key, want) } - const methodName = "CreateKey" + const methodName = "CreateSSHSigningKey" testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Users.CreateKey(ctx, input) + got, resp, err := client.Users.CreateSSHSigningKey(ctx, input) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } diff --git a/test/integration/users_test.go b/test/integration/users_test.go index f490f4ac1c1..7baf8e84829 100644 --- a/test/integration/users_test.go +++ b/test/integration/users_test.go @@ -180,9 +180,9 @@ func TestUsers_Keys(t *testing.T) { } // Add new key - _, _, err = client.Users.CreateKey(t.Context(), &github.Key{ + _, _, err = client.Users.CreateKey(t.Context(), github.CreateUserKeyRequest{ Title: github.Ptr("go-github test key"), - Key: &key, + Key: key, }) if err != nil { t.Fatalf("Users.CreateKey() returned error: %v", err)