Repository: google/go-github
File: github/users_emails.go (Go)

Code before:
	var e []*UserEmail
	resp, err := s.client.Do(ctx, req, &e)
	if err != nil {
		return nil, resp, err
	}

	return e, resp, nil
}

// DeleteEmails deletes email addresses from authenticated user.
//
// GitHub API docs: https://docs.github.com/en/rest/users/emails#delete-an-email-address-for-the-authenticated-user
func (s *UsersService) DeleteEmails(ctx context.Context, emails []string) (*Response, error) {
	u := "user/emails"
	req, err := s.client.NewRequest("DELETE", u, emails)
	if err != nil {
		return nil, err
	}

	return s.client.Do(ctx, req, nil)
}

// SetEmailVisibility sets the visibility for the primary email address of the authenticated user.
//
// GitHub API docs: https://docs.github.com/en/rest/users/emails#set-primary-email-visibility-for-the-authenticated-user
func (s *UsersService) SetEmailVisibility(ctx context.Context, updateVisiblilityReq *UserEmail) ([]*UserEmail, *Response, error) {
	u := "user/email/visibility"
	req, err := s.client.NewRequest("PATCH", u, updateVisiblilityReq)
	if err != nil {
		return nil, nil, err
	}

	var e []*UserEmail
	resp, err := s.client.Do(ctx, req, &e)
	if err != nil {
		return nil, resp, err
	}

	return e, resp, nil
}


Review comment (security):
This endpoint only accepts one of the 4 fields of `UserEmail`: `visibility`.
As such, it can be confusing to the user to have to build a `UserEmail` struct for this API call.
Instead, let's please do the following:

```suggestion
// SetEmailVisibility sets the visibility for the primary email address of the authenticated user.
// `visibility` can be "private" or "public".
//
// GitHub API docs: https://docs.github.com/en/rest/users/emails#set-primary-email-visibility-for-the-authenticated-user
func (s *UsersService) SetEmailVisibility(ctx context.Context, visibility string) ([]*UserEmail, *Response, error) {
	updateVisiblilityReq := &UserEmail{Visibility: &visibility}
```

Code after:
	var e []*UserEmail
	resp, err := s.client.Do(ctx, req, &e)
	if err != nil {
		return nil, resp, err
	}

	return e, resp, nil
}

// DeleteEmails deletes email addresses from authenticated user.
//
// GitHub API docs: https://docs.github.com/en/rest/users/emails#delete-an-email-address-for-the-authenticated-user
func (s *UsersService) DeleteEmails(ctx context.Context, emails []string) (*Response, error) {
	u := "user/emails"
	req, err := s.client.NewRequest("DELETE", u, emails)
	if err != nil {
		return nil, err
	}

	return s.client.Do(ctx, req, nil)
}

// SetEmailVisibility sets the visibility for the primary email address of the authenticated user.
// `visibility` can be "private" or "public".
//
// GitHub API docs: https://docs.github.com/en/rest/users/emails#set-primary-email-visibility-for-the-authenticated-user
func (s *UsersService) SetEmailVisibility(ctx context.Context, visibility string) ([]*UserEmail, *Response, error) {
	u := "user/email/visibility"

	updateVisiblilityReq := &UserEmail{
		Visibility: &visibility,
	}

	req, err := s.client.NewRequest("PATCH", u, updateVisiblilityReq)
	if err != nil {
		return nil, nil, err
	}

	var e []*UserEmail
	resp, err := s.client.Do(ctx, req, &e)
	if err != nil {
		return nil, resp, err
	}

	return e, resp, nil
}