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
31 changes: 31 additions & 0 deletions github/github-iterators.go

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

72 changes: 72 additions & 0 deletions github/github-iterators_test.go

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

26 changes: 26 additions & 0 deletions github/users_emails.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,32 @@ func (s *UsersService) ListEmails(ctx context.Context, opts *ListOptions) ([]*Us
return emails, resp, nil
}

// ListPublicEmails lists public email addresses for the authenticated user.
//
// GitHub API docs: https://docs.github.com/rest/users/emails?apiVersion=2022-11-28#list-public-email-addresses-for-the-authenticated-user
//
//meta:operation GET /user/public_emails
func (s *UsersService) ListPublicEmails(ctx context.Context, opts *ListOptions) ([]*UserEmail, *Response, error) {
u := "user/public_emails"
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}

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

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

return emails, resp, nil
}

// AddEmails adds email addresses of the authenticated user.
//
// GitHub API docs: https://docs.github.com/rest/users/emails?apiVersion=2022-11-28#add-an-email-address-for-the-authenticated-user
Expand Down
37 changes: 37 additions & 0 deletions github/users_emails_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,43 @@ func TestUsersService_ListEmails(t *testing.T) {
})
}

func TestUsersService_ListPublicEmails(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

mux.HandleFunc("/user/public_emails", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{
"email": "user@example.com",
"verified": true,
"primary": true,
"visibility": "public"
}]`)
})

opt := &ListOptions{Page: 2}
ctx := t.Context()
emails, _, err := client.Users.ListPublicEmails(ctx, opt)
if err != nil {
t.Errorf("Users.ListPublicEmails returned error: %v", err)
}

want := []*UserEmail{{Email: new("user@example.com"), Verified: new(true), Primary: new(true), Visibility: new("public")}}
if !cmp.Equal(emails, want) {
t.Errorf("Users.ListPublicEmails returned %+v, want %+v", emails, want)
}

const methodName = "ListPublicEmails"
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Users.ListPublicEmails(ctx, opt)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}

func TestUsersService_AddEmails(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
Expand Down
Loading