From 1ff56ef51c0134c35e4afd95c6637e35578baf24 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 9 Sep 2014 00:32:47 -0700 Subject: [PATCH] handle github enterprise not supporting verified / primary emails --- plugin/remote/github/helper.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugin/remote/github/helper.go b/plugin/remote/github/helper.go index 5113b2b2..6e2757c6 100644 --- a/plugin/remote/github/helper.go +++ b/plugin/remote/github/helper.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "net/http" "net/url" + "strings" "github.com/drone/drone/plugin/remote/github/oauth" "github.com/google/go-github/github" @@ -35,6 +36,16 @@ func GetUserEmail(client *github.Client) (*github.User, error) { if err != nil { return nil, err } + + // WARNING, HACK + // for out-of-date github enterprise editions the primary + // and verified fields won't exist. + if !strings.HasPrefix(*user.HTMLURL, DefaultURL) && len(emails) != 0 && emails[0].Primary == nil { + user.Email = emails[0].Email + return user, nil + } + + // else we should iterate through the list for _, email := range emails { if *email.Primary && *email.Verified { user.Email = email.Email