From 0987a9ad59f7da3ec1d8c1eb435e29db254dbb54 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 9 Sep 2014 01:37:02 -0700 Subject: [PATCH] verified fix for github enterprise email issues --- plugin/remote/github/helper.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/plugin/remote/github/helper.go b/plugin/remote/github/helper.go index 311d4453c..244b863a4 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" @@ -36,17 +37,21 @@ func GetUserEmail(client *github.Client) (*github.User, error) { return nil, err } - // else we should iterate through the list for _, email := range emails { - if email.Primary == nil { // hack for github enterprise - user.Email = email.Email - return user, nil - } if *email.Primary && *email.Verified { user.Email = email.Email return user, nil } } + + // 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 { + user.Email = emails[0].Email + return user, nil + } + return nil, fmt.Errorf("No verified Email address for GitHub account") }