Skip to content
Merged
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
13 changes: 11 additions & 2 deletions scm/driver/github/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (s *userService) FindLogin(ctx context.Context, login string) (*scm.User, *
}

func (s *userService) FindEmail(ctx context.Context) (string, *scm.Response, error) {
user, res, err := s.Find(ctx)
return user.Email, res, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can re-use the ListEmail function here:

func (s *userService) FindEmail(ctx context.Context) (string, *scm.Response, error) {
	out, res, err := s.ListEmails(ctx, scm.ListOptions{})
	return returnPrimaryEmail(out), res, err
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

out, res, err := s.ListEmail(ctx, scm.ListOptions{})
return returnPrimaryEmail(out), res, err
}

func (s *userService) ListEmail(ctx context.Context, opts scm.ListOptions) ([]*scm.Email, *scm.Response, error) {
Expand Down Expand Up @@ -69,6 +69,15 @@ func convertUser(from *user) *scm.User {
}
}

func returnPrimaryEmail(from []*scm.Email) string {
for _, v := range from {
if v.Primary == true {
return v.Value
}
}
return ""
}

// helper function to convert from the github email list to
// the common email structure.
func convertEmailList(from []*email) []*scm.Email {
Expand Down
4 changes: 2 additions & 2 deletions scm/driver/github/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ func TestUserEmailFind(t *testing.T) {
defer gock.Off()

gock.New("https://api.github.com").
Get("/user").
Get("/user/emails").
Reply(200).
Type("application/json").
SetHeader("X-GitHub-Request-Id", "DD0E:6011:12F21A8:1926790:5A2064E2").
SetHeader("X-RateLimit-Limit", "60").
SetHeader("X-RateLimit-Remaining", "59").
SetHeader("X-RateLimit-Reset", "1512076018").
File("testdata/user.json")
File("testdata/emails.json")

client := NewDefault()
result, res, err := client.Users.FindEmail(context.Background())
Expand Down