Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ linters:
- InstallationTokenListRepoOptions
- InstallationTokenOptions
- IssueImportRequest
- Key
- LockIssueOptions
- MaintenanceOptions
- Organization
Expand Down
64 changes: 64 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion github/github-stringify_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion github/repos_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Comment thread
JamBalaya56562 marked this conversation as resolved.
u := fmt.Sprintf("repos/%v/%v/keys", owner, repo)

req, err := s.client.NewRequest(ctx, "POST", u, body)
Expand Down
4 changes: 2 additions & 2 deletions github/repos_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}

Expand Down
10 changes: 9 additions & 1 deletion github/users_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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.
//
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion github/users_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 8 additions & 1 deletion github/users_ssh_signing_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions github/users_ssh_signing_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions test/integration/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading