diff --git a/plugin/remote/github/helper.go b/plugin/remote/github/helper.go index 5113b2b25..6e2757c65 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